feat(m6): add BitAnswer ID mapping CRUD

This commit is contained in:
2026-05-25 01:35:25 +08:00
parent 36b6e395c5
commit ae880c47b2
8 changed files with 480 additions and 1 deletions
@@ -1,5 +1,6 @@
package cn.craftlabs.platform.api.integration; package cn.craftlabs.platform.api.integration;
import cn.craftlabs.platform.api.persistence.integration.PlatformBitanswerIdMapping;
import cn.craftlabs.platform.api.service.IntegrationCatalogService; import cn.craftlabs.platform.api.service.IntegrationCatalogService;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentRequest; import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentRequest;
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentResponse; import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentResponse;
@@ -10,6 +11,9 @@ import jakarta.validation.Valid;
import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Min;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@@ -88,4 +92,29 @@ public class IntegrationCatalogController {
public void deleteProductLine(@PathVariable("id") long id) { public void deleteProductLine(@PathVariable("id") long id) {
integrationCatalogService.deleteProductLine(id); integrationCatalogService.deleteProductLine(id);
} }
@GetMapping("/id-mappings")
public ResponseEntity<List<PlatformBitanswerIdMapping>> listIdMappings(
@RequestParam(required = false) Long productLineId,
@RequestParam(required = false) Long environmentId) {
return ResponseEntity.ok(integrationCatalogService.listIdMappings(productLineId, environmentId));
}
@PostMapping("/id-mappings")
public ResponseEntity<PlatformBitanswerIdMapping> createIdMapping(@RequestBody PlatformBitanswerIdMapping body) {
return ResponseEntity.ok(integrationCatalogService.createIdMapping(body));
}
@PutMapping("/id-mappings/{id}")
public ResponseEntity<PlatformBitanswerIdMapping> updateIdMapping(
@PathVariable Long id, @RequestBody PlatformBitanswerIdMapping body) {
PlatformBitanswerIdMapping result = integrationCatalogService.updateIdMapping(id, body);
return result != null ? ResponseEntity.ok(result) : ResponseEntity.notFound().build();
}
@DeleteMapping("/id-mappings/{id}")
public ResponseEntity<Void> deleteIdMapping(@PathVariable Long id) {
integrationCatalogService.deleteIdMapping(id);
return ResponseEntity.ok().build();
}
} }
@@ -0,0 +1,122 @@
package cn.craftlabs.platform.api.persistence.integration;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.OffsetDateTime;
@TableName("platform_bitanswer_id_mapping")
public class PlatformBitanswerIdMapping {
@TableId(type = IdType.AUTO)
private Long id;
@TableField("product_line_id")
private Long productLineId;
@TableField("environment_id")
private Long environmentId;
@TableField("bitanswer_product_id")
private String bitanswerProductId;
@TableField("bitanswer_template_id")
private String bitanswerTemplateId;
@TableField("bitanswer_business_id")
private String bitanswerBusinessId;
@TableField("feature_key")
private String featureKey;
@TableField("bitanswer_feature_id")
private String bitanswerFeatureId;
@TableField("created_at")
private OffsetDateTime createdAt;
@TableField("updated_at")
private OffsetDateTime updatedAt;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getProductLineId() {
return productLineId;
}
public void setProductLineId(Long productLineId) {
this.productLineId = productLineId;
}
public Long getEnvironmentId() {
return environmentId;
}
public void setEnvironmentId(Long environmentId) {
this.environmentId = environmentId;
}
public String getBitanswerProductId() {
return bitanswerProductId;
}
public void setBitanswerProductId(String bitanswerProductId) {
this.bitanswerProductId = bitanswerProductId;
}
public String getBitanswerTemplateId() {
return bitanswerTemplateId;
}
public void setBitanswerTemplateId(String bitanswerTemplateId) {
this.bitanswerTemplateId = bitanswerTemplateId;
}
public String getBitanswerBusinessId() {
return bitanswerBusinessId;
}
public void setBitanswerBusinessId(String bitanswerBusinessId) {
this.bitanswerBusinessId = bitanswerBusinessId;
}
public String getFeatureKey() {
return featureKey;
}
public void setFeatureKey(String featureKey) {
this.featureKey = featureKey;
}
public String getBitanswerFeatureId() {
return bitanswerFeatureId;
}
public void setBitanswerFeatureId(String bitanswerFeatureId) {
this.bitanswerFeatureId = bitanswerFeatureId;
}
public OffsetDateTime getCreatedAt() {
return createdAt;
}
public void setCreatedAt(OffsetDateTime createdAt) {
this.createdAt = createdAt;
}
public OffsetDateTime getUpdatedAt() {
return updatedAt;
}
public void setUpdatedAt(OffsetDateTime updatedAt) {
this.updatedAt = updatedAt;
}
}
@@ -0,0 +1,7 @@
package cn.craftlabs.platform.api.persistence.integration;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PlatformBitanswerIdMappingMapper extends BaseMapper<PlatformBitanswerIdMapping> {}
@@ -1,5 +1,7 @@
package cn.craftlabs.platform.api.service; package cn.craftlabs.platform.api.service;
import cn.craftlabs.platform.api.persistence.integration.PlatformBitanswerIdMapping;
import cn.craftlabs.platform.api.persistence.integration.PlatformBitanswerIdMappingMapper;
import cn.craftlabs.platform.api.persistence.integration.PlatformIntegrationEnvironment; import cn.craftlabs.platform.api.persistence.integration.PlatformIntegrationEnvironment;
import cn.craftlabs.platform.api.persistence.integration.PlatformIntegrationEnvironmentMapper; import cn.craftlabs.platform.api.persistence.integration.PlatformIntegrationEnvironmentMapper;
import cn.craftlabs.platform.api.persistence.integration.PlatformProductLine; import cn.craftlabs.platform.api.persistence.integration.PlatformProductLine;
@@ -24,12 +26,15 @@ public class IntegrationCatalogService {
private final PlatformProductLineMapper productLineMapper; private final PlatformProductLineMapper productLineMapper;
private final PlatformIntegrationEnvironmentMapper environmentMapper; private final PlatformIntegrationEnvironmentMapper environmentMapper;
private final PlatformBitanswerIdMappingMapper idMappingMapper;
public IntegrationCatalogService( public IntegrationCatalogService(
PlatformProductLineMapper productLineMapper, PlatformProductLineMapper productLineMapper,
PlatformIntegrationEnvironmentMapper environmentMapper) { PlatformIntegrationEnvironmentMapper environmentMapper,
PlatformBitanswerIdMappingMapper idMappingMapper) {
this.productLineMapper = productLineMapper; this.productLineMapper = productLineMapper;
this.environmentMapper = environmentMapper; this.environmentMapper = environmentMapper;
this.idMappingMapper = idMappingMapper;
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
@@ -138,6 +143,37 @@ public class IntegrationCatalogService {
environmentMapper.deleteById(id); environmentMapper.deleteById(id);
} }
public List<PlatformBitanswerIdMapping> listIdMappings(Long productLineId, Long environmentId) {
var qw = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<PlatformBitanswerIdMapping>();
if (productLineId != null) qw.eq(PlatformBitanswerIdMapping::getProductLineId, productLineId);
if (environmentId != null) qw.eq(PlatformBitanswerIdMapping::getEnvironmentId, environmentId);
qw.orderByDesc(PlatformBitanswerIdMapping::getCreatedAt);
return idMappingMapper.selectList(qw);
}
@Transactional
public PlatformBitanswerIdMapping createIdMapping(PlatformBitanswerIdMapping mapping) {
mapping.setCreatedAt(java.time.OffsetDateTime.now());
mapping.setUpdatedAt(java.time.OffsetDateTime.now());
idMappingMapper.insert(mapping);
return mapping;
}
@Transactional
public PlatformBitanswerIdMapping updateIdMapping(Long id, PlatformBitanswerIdMapping mapping) {
PlatformBitanswerIdMapping existing = idMappingMapper.selectById(id);
if (existing == null) return null;
mapping.setId(id);
mapping.setUpdatedAt(java.time.OffsetDateTime.now());
idMappingMapper.updateById(mapping);
return idMappingMapper.selectById(id);
}
@Transactional
public void deleteIdMapping(Long id) {
idMappingMapper.deleteById(id);
}
private ProductLineResponse toProductLine(PlatformProductLine row) { private ProductLineResponse toProductLine(PlatformProductLine row) {
ProductLineResponse r = new ProductLineResponse(); ProductLineResponse r = new ProductLineResponse();
r.setId(row.getId()); r.setId(row.getId());
@@ -0,0 +1,16 @@
-- V13__m6_id_mapping.sql
CREATE TABLE platform_bitanswer_id_mapping (
id BIGSERIAL PRIMARY KEY,
product_line_id BIGINT NOT NULL REFERENCES platform_product_line(id),
environment_id BIGINT REFERENCES platform_integration_environment(id),
bitanswer_product_id VARCHAR(128),
bitanswer_template_id VARCHAR(128),
bitanswer_business_id VARCHAR(128),
feature_key VARCHAR(64),
bitanswer_feature_id VARCHAR(128),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_id_mapping_product_line ON platform_bitanswer_id_mapping(product_line_id);
CREATE INDEX idx_id_mapping_environment ON platform_bitanswer_id_mapping(environment_id);
@@ -387,3 +387,17 @@ export function initiateContractChange(id, body) {
export function completeContractChange(id) { export function completeContractChange(id) {
return axios.post(`/api/v1/contracts/${id}/changes/complete`); return axios.post(`/api/v1/contracts/${id}/changes/complete`);
} }
// —— I12 M6 比特 ID 映射 ——————————————————————
export function listIdMappings(params) {
return axios.get('/api/v1/integration/id-mappings', { params });
}
export function createIdMapping(body) {
return axios.post('/api/v1/integration/id-mappings', body);
}
export function updateIdMapping(id, body) {
return axios.put(`/api/v1/integration/id-mappings/${id}`, body);
}
export function deleteIdMapping(id) {
return axios.delete(`/api/v1/integration/id-mappings/${id}`);
}
@@ -80,6 +80,12 @@ const routes = [
component: () => import("../views/IntegrationProductLinesView.vue"), component: () => import("../views/IntegrationProductLinesView.vue"),
meta: { roles: ["SYS_ADMIN", "DEVELOPER", "OPS"], title: "产品线" }, meta: { roles: ["SYS_ADMIN", "DEVELOPER", "OPS"], title: "产品线" },
}, },
{
path: "integration/id-mappings",
name: "integration-id-mappings",
component: () => import("../views/IntegrationIdMappingView.vue"),
meta: { roles: ["SYS_ADMIN", "DEVELOPER"], title: "ID 映射" },
},
{ {
path: "callbacks/:id", path: "callbacks/:id",
name: "callback-inbox-detail", name: "callback-inbox-detail",
@@ -0,0 +1,249 @@
<template>
<el-card shadow="never">
<template #header>
<div class="toolbar">
<span class="title">ID 映射</span>
<div class="actions">
<el-select v-model="filterProductLineId" placeholder="产品线" clearable style="width:160px" @change="load">
<el-option v-for="pl in productLines" :key="pl.id" :label="pl.name" :value="pl.id" />
</el-select>
<el-select v-model="filterEnvironmentId" placeholder="环境" clearable style="width:160px" @change="load">
<el-option v-for="e in environments" :key="e.id" :label="e.name" :value="e.id" />
</el-select>
<el-button type="primary" :loading="loading" @click="load">查询</el-button>
<el-button type="success" @click="openCreate">新建</el-button>
</div>
</div>
</template>
<el-table v-loading="loading" :data="rows" stripe style="width: 100%">
<el-table-column prop="bitanswerProductId" label="比特产品 ID" min-width="140" show-overflow-tooltip />
<el-table-column prop="bitanswerTemplateId" label="比特模板 ID" min-width="140" show-overflow-tooltip />
<el-table-column prop="bitanswerBusinessId" label="比特业务 ID" min-width="140" show-overflow-tooltip />
<el-table-column prop="featureKey" label="特性键" width="120" show-overflow-tooltip />
<el-table-column prop="bitanswerFeatureId" label="比特特性 ID" min-width="140" show-overflow-tooltip />
<el-table-column label="产品线 ID" width="120">
<template #default="{ row }">{{ row.productLineId ?? "—" }}</template>
</el-table-column>
<el-table-column label="环境 ID" width="120">
<template #default="{ row }">{{ row.environmentId ?? "—" }}</template>
</el-table-column>
<el-table-column label="操作" width="160" fixed="right">
<template #default="{ row }">
<el-button type="primary" link @click="openEdit(row)">编辑</el-button>
<el-button type="danger" link @click="onDelete(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-dialog v-model="dialogVisible" :title="dialogTitle" width="560px" destroy-on-close @closed="resetForm">
<el-form ref="formRef" :model="form" :rules="rules" label-width="150px">
<el-form-item label="产品线" prop="productLineId">
<el-select v-model="form.productLineId" placeholder="请选择" style="width:100%">
<el-option v-for="pl in productLines" :key="pl.id" :label="pl.name" :value="pl.id" />
</el-select>
</el-form-item>
<el-form-item label="环境" prop="environmentId">
<el-select v-model="form.environmentId" placeholder="选填" clearable style="width:100%">
<el-option v-for="e in environments" :key="e.id" :label="e.name" :value="e.id" />
</el-select>
</el-form-item>
<el-form-item label="比特产品 ID" prop="bitanswerProductId">
<el-input v-model="form.bitanswerProductId" maxlength="128" placeholder="选填" />
</el-form-item>
<el-form-item label="比特模板 ID" prop="bitanswerTemplateId">
<el-input v-model="form.bitanswerTemplateId" maxlength="128" placeholder="选填" />
</el-form-item>
<el-form-item label="比特业务 ID" prop="bitanswerBusinessId">
<el-input v-model="form.bitanswerBusinessId" maxlength="128" placeholder="选填" />
</el-form-item>
<el-form-item label="特性键" prop="featureKey">
<el-input v-model="form.featureKey" maxlength="64" placeholder="选填" />
</el-form-item>
<el-form-item label="比特特性 ID" prop="bitanswerFeatureId">
<el-input v-model="form.bitanswerFeatureId" maxlength="128" placeholder="选填" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
</template>
</el-dialog>
</el-card>
</template>
<script setup>
import { ref, reactive, computed, onMounted } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { useAuthStore } from "../stores/auth";
import { listIdMappings, createIdMapping, updateIdMapping, deleteIdMapping, listProductLines, listIntegrationEnvironments } from "../api/platform";
import { apiErrorMessage } from "../utils/apiErrorMessage";
const auth = useAuthStore();
const loading = ref(false);
const saving = ref(false);
const rows = ref([]);
const productLines = ref([]);
const environments = ref([]);
const filterProductLineId = ref(null);
const filterEnvironmentId = ref(null);
const dialogVisible = ref(false);
const editingId = ref(null);
const formRef = ref(null);
const form = reactive({
productLineId: null,
environmentId: null,
bitanswerProductId: "",
bitanswerTemplateId: "",
bitanswerBusinessId: "",
featureKey: "",
bitanswerFeatureId: "",
});
const rules = {
productLineId: [{ required: true, message: "请选择产品线", trigger: "change" }],
};
const dialogTitle = computed(() => (editingId.value ? "编辑映射" : "新建映射"));
onMounted(async () => {
auth.restoreAxiosAuth();
await Promise.all([loadProductLines(), loadEnvironments(), load()]);
});
async function loadProductLines() {
try {
const { data } = await listProductLines();
const body = data && typeof data === "object" ? data : {};
productLines.value = Array.isArray(body.content) ? body.content : [];
} catch { productLines.value = []; }
}
async function loadEnvironments() {
try {
const { data } = await listIntegrationEnvironments();
const body = data && typeof data === "object" ? data : {};
environments.value = Array.isArray(body.content) ? body.content : [];
} catch { environments.value = []; }
}
async function load() {
loading.value = true;
try {
const { data } = await listIdMappings({
productLineId: filterProductLineId.value || undefined,
environmentId: filterEnvironmentId.value || undefined,
});
rows.value = Array.isArray(data) ? data : [];
} catch (e) {
ElMessage.error(apiErrorMessage(e, "加载 ID 映射失败"));
rows.value = [];
} finally {
loading.value = false;
}
}
function openCreate() {
editingId.value = null;
resetForm();
dialogVisible.value = true;
}
function openEdit(row) {
editingId.value = row.id;
form.productLineId = row.productLineId ?? null;
form.environmentId = row.environmentId ?? null;
form.bitanswerProductId = row.bitanswerProductId ?? "";
form.bitanswerTemplateId = row.bitanswerTemplateId ?? "";
form.bitanswerBusinessId = row.bitanswerBusinessId ?? "";
form.featureKey = row.featureKey ?? "";
form.bitanswerFeatureId = row.bitanswerFeatureId ?? "";
dialogVisible.value = true;
}
function resetForm() {
form.productLineId = null;
form.environmentId = null;
form.bitanswerProductId = "";
form.bitanswerTemplateId = "";
form.bitanswerBusinessId = "";
form.featureKey = "";
form.bitanswerFeatureId = "";
formRef.value?.resetFields?.();
}
async function submit() {
const f = formRef.value;
if (!f) return;
try {
await f.validate();
} catch {
return;
}
saving.value = true;
const payload = {
productLineId: form.productLineId,
environmentId: form.environmentId || undefined,
bitanswerProductId: form.bitanswerProductId?.trim() || undefined,
bitanswerTemplateId: form.bitanswerTemplateId?.trim() || undefined,
bitanswerBusinessId: form.bitanswerBusinessId?.trim() || undefined,
featureKey: form.featureKey?.trim() || undefined,
bitanswerFeatureId: form.bitanswerFeatureId?.trim() || undefined,
};
try {
if (editingId.value != null) {
await updateIdMapping(editingId.value, payload);
ElMessage.success("已保存");
} else {
await createIdMapping(payload);
ElMessage.success("已创建");
}
dialogVisible.value = false;
await load();
} catch (e) {
ElMessage.error(apiErrorMessage(e, "保存失败"));
} finally {
saving.value = false;
}
}
function onDelete(row) {
ElMessageBox.confirm(`确定删除 ID 映射(ID: ${row.id})吗?`, "提示", {
type: "warning",
confirmButtonText: "删除",
cancelButtonText: "取消",
})
.then(async () => {
try {
await deleteIdMapping(row.id);
ElMessage.success("已删除");
await load();
} catch (e) {
ElMessage.error(apiErrorMessage(e, "删除失败"));
}
})
.catch(() => {});
}
</script>
<style scoped>
.toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.title {
font-weight: 600;
font-size: 16px;
}
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
</style>