mirror of
https://github.com/hpd840321/craftlabs-authorization-sdk.git
synced 2026-06-09 10:00:30 +08:00
feat(m2): add SKU mapping between contract lines and license features
This commit is contained in:
+26
@@ -8,6 +8,8 @@ import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentResponse;
|
||||
import cn.craftlabs.platform.api.web.dto.PageResponse;
|
||||
import cn.craftlabs.platform.api.web.dto.ProductLineRequest;
|
||||
import cn.craftlabs.platform.api.web.dto.ProductLineResponse;
|
||||
import cn.craftlabs.platform.api.web.dto.SkuMappingRequest;
|
||||
import cn.craftlabs.platform.api.web.dto.SkuMappingResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
@@ -147,4 +149,28 @@ public class IntegrationCatalogController {
|
||||
integrationCatalogService.deleteJsonTemplate(id);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@GetMapping("/sku-mappings")
|
||||
public ResponseEntity<List<SkuMappingResponse>> listSkuMappings(
|
||||
@RequestParam(required = false) Long contractLineId) {
|
||||
return ResponseEntity.ok(integrationCatalogService.listSkuMappings(contractLineId));
|
||||
}
|
||||
|
||||
@PostMapping("/sku-mappings")
|
||||
public ResponseEntity<SkuMappingResponse> createSkuMapping(
|
||||
@RequestParam Long contractLineId, @Valid @RequestBody SkuMappingRequest body) {
|
||||
return ResponseEntity.ok(integrationCatalogService.createSkuMapping(contractLineId, body));
|
||||
}
|
||||
|
||||
@PutMapping("/sku-mappings/{id}")
|
||||
public ResponseEntity<SkuMappingResponse> updateSkuMapping(
|
||||
@PathVariable Long id, @Valid @RequestBody SkuMappingRequest body) {
|
||||
return ResponseEntity.ok(integrationCatalogService.updateSkuMapping(id, body));
|
||||
}
|
||||
|
||||
@DeleteMapping("/sku-mappings/{id}")
|
||||
public ResponseEntity<Void> deleteSkuMapping(@PathVariable Long id) {
|
||||
integrationCatalogService.deleteSkuMapping(id);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
+122
@@ -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_sku_mapping")
|
||||
public class PlatformSkuMapping {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@TableField("contract_line_id")
|
||||
private Long contractLineId;
|
||||
|
||||
@TableField("sku_code")
|
||||
private String skuCode;
|
||||
|
||||
@TableField("sku_name")
|
||||
private String skuName;
|
||||
|
||||
@TableField("bitanswer_product_id")
|
||||
private String bitanswerProductId;
|
||||
|
||||
@TableField("bitanswer_template_id")
|
||||
private String bitanswerTemplateId;
|
||||
|
||||
@TableField("bitanswer_feature_id")
|
||||
private String bitanswerFeatureId;
|
||||
|
||||
@TableField
|
||||
private Integer quantity;
|
||||
|
||||
@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 getContractLineId() {
|
||||
return contractLineId;
|
||||
}
|
||||
|
||||
public void setContractLineId(Long contractLineId) {
|
||||
this.contractLineId = contractLineId;
|
||||
}
|
||||
|
||||
public String getSkuCode() {
|
||||
return skuCode;
|
||||
}
|
||||
|
||||
public void setSkuCode(String skuCode) {
|
||||
this.skuCode = skuCode;
|
||||
}
|
||||
|
||||
public String getSkuName() {
|
||||
return skuName;
|
||||
}
|
||||
|
||||
public void setSkuName(String skuName) {
|
||||
this.skuName = skuName;
|
||||
}
|
||||
|
||||
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 getBitanswerFeatureId() {
|
||||
return bitanswerFeatureId;
|
||||
}
|
||||
|
||||
public void setBitanswerFeatureId(String bitanswerFeatureId) {
|
||||
this.bitanswerFeatureId = bitanswerFeatureId;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
+7
@@ -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 PlatformSkuMappingMapper extends BaseMapper<PlatformSkuMapping> {}
|
||||
+71
-1
@@ -8,11 +8,15 @@ import cn.craftlabs.platform.api.persistence.integration.PlatformJsonTemplate;
|
||||
import cn.craftlabs.platform.api.persistence.integration.PlatformJsonTemplateMapper;
|
||||
import cn.craftlabs.platform.api.persistence.integration.PlatformProductLine;
|
||||
import cn.craftlabs.platform.api.persistence.integration.PlatformProductLineMapper;
|
||||
import cn.craftlabs.platform.api.persistence.integration.PlatformSkuMapping;
|
||||
import cn.craftlabs.platform.api.persistence.integration.PlatformSkuMappingMapper;
|
||||
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentRequest;
|
||||
import cn.craftlabs.platform.api.web.dto.IntegrationEnvironmentResponse;
|
||||
import cn.craftlabs.platform.api.web.dto.PageResponse;
|
||||
import cn.craftlabs.platform.api.web.dto.ProductLineRequest;
|
||||
import cn.craftlabs.platform.api.web.dto.ProductLineResponse;
|
||||
import cn.craftlabs.platform.api.web.dto.SkuMappingRequest;
|
||||
import cn.craftlabs.platform.api.web.dto.SkuMappingResponse;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -30,16 +34,19 @@ public class IntegrationCatalogService {
|
||||
private final PlatformIntegrationEnvironmentMapper environmentMapper;
|
||||
private final PlatformBitanswerIdMappingMapper idMappingMapper;
|
||||
private final PlatformJsonTemplateMapper jsonTemplateMapper;
|
||||
private final PlatformSkuMappingMapper skuMappingMapper;
|
||||
|
||||
public IntegrationCatalogService(
|
||||
PlatformProductLineMapper productLineMapper,
|
||||
PlatformIntegrationEnvironmentMapper environmentMapper,
|
||||
PlatformBitanswerIdMappingMapper idMappingMapper,
|
||||
PlatformJsonTemplateMapper jsonTemplateMapper) {
|
||||
PlatformJsonTemplateMapper jsonTemplateMapper,
|
||||
PlatformSkuMappingMapper skuMappingMapper) {
|
||||
this.productLineMapper = productLineMapper;
|
||||
this.environmentMapper = environmentMapper;
|
||||
this.idMappingMapper = idMappingMapper;
|
||||
this.jsonTemplateMapper = jsonTemplateMapper;
|
||||
this.skuMappingMapper = skuMappingMapper;
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@@ -215,6 +222,55 @@ public class IntegrationCatalogService {
|
||||
jsonTemplateMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<SkuMappingResponse> listSkuMappings(Long contractLineId) {
|
||||
var qw = new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<PlatformSkuMapping>();
|
||||
if (contractLineId != null) qw.eq(PlatformSkuMapping::getContractLineId, contractLineId);
|
||||
qw.orderByDesc(PlatformSkuMapping::getCreatedAt);
|
||||
return skuMappingMapper.selectList(qw).stream().map(this::toSkuMapping).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public SkuMappingResponse createSkuMapping(Long contractLineId, SkuMappingRequest req) {
|
||||
PlatformSkuMapping row = new PlatformSkuMapping();
|
||||
row.setContractLineId(contractLineId);
|
||||
row.setSkuCode(req.getSkuCode());
|
||||
row.setSkuName(req.getSkuName());
|
||||
row.setBitanswerProductId(req.getBitanswerProductId());
|
||||
row.setBitanswerTemplateId(req.getBitanswerTemplateId());
|
||||
row.setBitanswerFeatureId(req.getBitanswerFeatureId());
|
||||
row.setQuantity(req.getQuantity() != null ? req.getQuantity() : 1);
|
||||
row.setCreatedAt(java.time.OffsetDateTime.now());
|
||||
row.setUpdatedAt(java.time.OffsetDateTime.now());
|
||||
skuMappingMapper.insert(row);
|
||||
return toSkuMapping(row);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public SkuMappingResponse updateSkuMapping(Long id, SkuMappingRequest req) {
|
||||
PlatformSkuMapping row = skuMappingMapper.selectById(id);
|
||||
if (row == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "sku mapping not found");
|
||||
}
|
||||
row.setSkuCode(req.getSkuCode());
|
||||
row.setSkuName(req.getSkuName());
|
||||
row.setBitanswerProductId(req.getBitanswerProductId());
|
||||
row.setBitanswerTemplateId(req.getBitanswerTemplateId());
|
||||
row.setBitanswerFeatureId(req.getBitanswerFeatureId());
|
||||
row.setQuantity(req.getQuantity() != null ? req.getQuantity() : 1);
|
||||
row.setUpdatedAt(java.time.OffsetDateTime.now());
|
||||
skuMappingMapper.updateById(row);
|
||||
return toSkuMapping(row);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteSkuMapping(Long id) {
|
||||
if (skuMappingMapper.selectById(id) == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "sku mapping not found");
|
||||
}
|
||||
skuMappingMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private ProductLineResponse toProductLine(PlatformProductLine row) {
|
||||
ProductLineResponse r = new ProductLineResponse();
|
||||
r.setId(row.getId());
|
||||
@@ -239,4 +295,18 @@ public class IntegrationCatalogService {
|
||||
r.setUpdatedAt(row.getUpdatedAt());
|
||||
return r;
|
||||
}
|
||||
|
||||
private SkuMappingResponse toSkuMapping(PlatformSkuMapping row) {
|
||||
SkuMappingResponse r = new SkuMappingResponse();
|
||||
r.setId(row.getId());
|
||||
r.setContractLineId(row.getContractLineId());
|
||||
r.setSkuCode(row.getSkuCode());
|
||||
r.setSkuName(row.getSkuName());
|
||||
r.setBitanswerProductId(row.getBitanswerProductId());
|
||||
r.setBitanswerTemplateId(row.getBitanswerTemplateId());
|
||||
r.setBitanswerFeatureId(row.getBitanswerFeatureId());
|
||||
r.setQuantity(row.getQuantity());
|
||||
r.setCreatedAt(row.getCreatedAt());
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package cn.craftlabs.platform.api.web.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public class SkuMappingRequest {
|
||||
|
||||
@NotBlank
|
||||
@Size(max = 64)
|
||||
private String skuCode;
|
||||
|
||||
@Size(max = 256)
|
||||
private String skuName;
|
||||
|
||||
@Size(max = 128)
|
||||
private String bitanswerProductId;
|
||||
|
||||
@Size(max = 128)
|
||||
private String bitanswerTemplateId;
|
||||
|
||||
@Size(max = 128)
|
||||
private String bitanswerFeatureId;
|
||||
|
||||
@Min(1)
|
||||
private Integer quantity;
|
||||
|
||||
public String getSkuCode() {
|
||||
return skuCode;
|
||||
}
|
||||
|
||||
public void setSkuCode(String skuCode) {
|
||||
this.skuCode = skuCode;
|
||||
}
|
||||
|
||||
public String getSkuName() {
|
||||
return skuName;
|
||||
}
|
||||
|
||||
public void setSkuName(String skuName) {
|
||||
this.skuName = skuName;
|
||||
}
|
||||
|
||||
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 getBitanswerFeatureId() {
|
||||
return bitanswerFeatureId;
|
||||
}
|
||||
|
||||
public void setBitanswerFeatureId(String bitanswerFeatureId) {
|
||||
this.bitanswerFeatureId = bitanswerFeatureId;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package cn.craftlabs.platform.api.web.dto;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
public class SkuMappingResponse {
|
||||
|
||||
private Long id;
|
||||
private Long contractLineId;
|
||||
private String skuCode;
|
||||
private String skuName;
|
||||
private String bitanswerProductId;
|
||||
private String bitanswerTemplateId;
|
||||
private String bitanswerFeatureId;
|
||||
private Integer quantity;
|
||||
private OffsetDateTime createdAt;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getContractLineId() {
|
||||
return contractLineId;
|
||||
}
|
||||
|
||||
public void setContractLineId(Long contractLineId) {
|
||||
this.contractLineId = contractLineId;
|
||||
}
|
||||
|
||||
public String getSkuCode() {
|
||||
return skuCode;
|
||||
}
|
||||
|
||||
public void setSkuCode(String skuCode) {
|
||||
this.skuCode = skuCode;
|
||||
}
|
||||
|
||||
public String getSkuName() {
|
||||
return skuName;
|
||||
}
|
||||
|
||||
public void setSkuName(String skuName) {
|
||||
this.skuName = skuName;
|
||||
}
|
||||
|
||||
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 getBitanswerFeatureId() {
|
||||
return bitanswerFeatureId;
|
||||
}
|
||||
|
||||
public void setBitanswerFeatureId(String bitanswerFeatureId) {
|
||||
this.bitanswerFeatureId = bitanswerFeatureId;
|
||||
}
|
||||
|
||||
public Integer getQuantity() {
|
||||
return quantity;
|
||||
}
|
||||
|
||||
public void setQuantity(Integer quantity) {
|
||||
this.quantity = quantity;
|
||||
}
|
||||
|
||||
public OffsetDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(OffsetDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE platform_sku_mapping (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
contract_line_id BIGINT REFERENCES platform_contract_line(id),
|
||||
sku_code VARCHAR(64) NOT NULL,
|
||||
sku_name VARCHAR(256),
|
||||
bitanswer_product_id VARCHAR(128),
|
||||
bitanswer_template_id VARCHAR(128),
|
||||
bitanswer_feature_id VARCHAR(128),
|
||||
quantity INT NOT NULL DEFAULT 1,
|
||||
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_sku_contract_line ON platform_sku_mapping(contract_line_id);
|
||||
@@ -438,6 +438,12 @@ export function deleteJsonTemplate(id) {
|
||||
return axios.delete(`/api/v1/integration/json-templates/${id}`);
|
||||
}
|
||||
|
||||
// —— I15-T2 M2-F08 SKU 映射 ——————————————————————————
|
||||
export function listSkuMappings(params) { return axios.get('/api/v1/integration/sku-mappings', { params }); }
|
||||
export function createSkuMapping(contractLineId, body) { return axios.post(`/api/v1/integration/sku-mappings?contractLineId=${contractLineId}`, body); }
|
||||
export function updateSkuMapping(id, body) { return axios.put(`/api/v1/integration/sku-mappings/${id}`, body); }
|
||||
export function deleteSkuMapping(id) { return axios.delete(`/api/v1/integration/sku-mappings/${id}`); }
|
||||
|
||||
export function listStakeholders(projectId) {
|
||||
return axios.get(`/api/v1/projects/${projectId}/stakeholders`);
|
||||
}
|
||||
|
||||
@@ -86,6 +86,12 @@ const routes = [
|
||||
component: () => import("../views/IntegrationIdMappingView.vue"),
|
||||
meta: { roles: ["SYS_ADMIN", "SALES"], title: "ID 映射" },
|
||||
},
|
||||
{
|
||||
path: "integration/sku-mappings",
|
||||
name: "integration-sku-mappings",
|
||||
component: () => import("../views/IntegrationSkuMappingView.vue"),
|
||||
meta: { roles: ["SYS_ADMIN"], title: "SKU 映射" },
|
||||
},
|
||||
{
|
||||
path: "integration/json-templates",
|
||||
name: "integration-json-templates",
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
<template>
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<div class="toolbar">
|
||||
<span class="title">SKU 映射</span>
|
||||
<div class="actions">
|
||||
<el-select v-model="filterContractLineId" placeholder="合同行" clearable filterable style="width:240px" @change="load">
|
||||
<el-option v-for="cl in contractLines" :key="cl.id" :label="cl.name || `ID:${cl.id}`" :value="cl.id" />
|
||||
</el-select>
|
||||
<el-button type="primary" :loading="loading" @click="load">查询</el-button>
|
||||
<el-button type="success" :disabled="!filterContractLineId" @click="openCreate">新建</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" :data="rows" stripe style="width: 100%">
|
||||
<el-table-column prop="contractLineId" label="合同行 ID" width="120" />
|
||||
<el-table-column prop="skuCode" label="SKU 编码" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="skuName" label="SKU 名称" min-width="160" show-overflow-tooltip />
|
||||
<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="bitanswerFeatureId" label="比特特性 ID" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="quantity" label="数量" width="80" />
|
||||
<el-table-column prop="createdAt" label="创建时间" width="180" />
|
||||
<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="合同行 ID">
|
||||
<el-input :model-value="filterContractLineId || form.contractLineId" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="SKU 编码" prop="skuCode">
|
||||
<el-input v-model="form.skuCode" maxlength="64" placeholder="请输入 SKU 编码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="SKU 名称" prop="skuName">
|
||||
<el-input v-model="form.skuName" maxlength="256" placeholder="选填" />
|
||||
</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="bitanswerFeatureId">
|
||||
<el-input v-model="form.bitanswerFeatureId" maxlength="128" placeholder="选填" />
|
||||
</el-form-item>
|
||||
<el-form-item label="数量" prop="quantity">
|
||||
<el-input-number v-model="form.quantity" :min="1" style="width:100%" />
|
||||
</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 { listSkuMappings, createSkuMapping, updateSkuMapping, deleteSkuMapping, listContracts } from "../api/platform";
|
||||
import { apiErrorMessage } from "../utils/apiErrorMessage";
|
||||
|
||||
const auth = useAuthStore();
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const rows = ref([]);
|
||||
const contractLines = ref([]);
|
||||
const filterContractLineId = ref(null);
|
||||
|
||||
const dialogVisible = ref(false);
|
||||
const editingId = ref(null);
|
||||
const formRef = ref(null);
|
||||
const form = reactive({
|
||||
contractLineId: null,
|
||||
skuCode: "",
|
||||
skuName: "",
|
||||
bitanswerProductId: "",
|
||||
bitanswerTemplateId: "",
|
||||
bitanswerFeatureId: "",
|
||||
quantity: 1,
|
||||
});
|
||||
|
||||
const rules = {
|
||||
skuCode: [{ required: true, message: "请输入 SKU 编码", trigger: "blur" }],
|
||||
};
|
||||
|
||||
const dialogTitle = computed(() => (editingId.value ? "编辑 SKU 映射" : "新建 SKU 映射"));
|
||||
|
||||
onMounted(async () => {
|
||||
auth.restoreAxiosAuth();
|
||||
await Promise.all([loadContractLines(), load()]);
|
||||
});
|
||||
|
||||
async function loadContractLines() {
|
||||
try {
|
||||
const { data } = await listContracts({ size: 200 });
|
||||
const body = data && typeof data === "object" ? data : {};
|
||||
contractLines.value = Array.isArray(body.content) ? body.content : [];
|
||||
} catch { contractLines.value = []; }
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const { data } = await listSkuMappings({
|
||||
contractLineId: filterContractLineId.value || undefined,
|
||||
});
|
||||
rows.value = Array.isArray(data) ? data : [];
|
||||
} catch (e) {
|
||||
ElMessage.error(apiErrorMessage(e, "加载 SKU 映射失败"));
|
||||
rows.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openCreate() {
|
||||
editingId.value = null;
|
||||
resetForm();
|
||||
form.contractLineId = filterContractLineId.value;
|
||||
dialogVisible.value = true;
|
||||
}
|
||||
|
||||
function openEdit(row) {
|
||||
editingId.value = row.id;
|
||||
form.contractLineId = row.contractLineId;
|
||||
form.skuCode = row.skuCode ?? "";
|
||||
form.skuName = row.skuName ?? "";
|
||||
form.bitanswerProductId = row.bitanswerProductId ?? "";
|
||||
form.bitanswerTemplateId = row.bitanswerTemplateId ?? "";
|
||||
form.bitanswerFeatureId = row.bitanswerFeatureId ?? "";
|
||||
form.quantity = row.quantity ?? 1;
|
||||
dialogVisible.value = true;
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
form.contractLineId = null;
|
||||
form.skuCode = "";
|
||||
form.skuName = "";
|
||||
form.bitanswerProductId = "";
|
||||
form.bitanswerTemplateId = "";
|
||||
form.bitanswerFeatureId = "";
|
||||
form.quantity = 1;
|
||||
formRef.value?.resetFields?.();
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
const f = formRef.value;
|
||||
if (!f) return;
|
||||
try {
|
||||
await f.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
const payload = {
|
||||
skuCode: form.skuCode?.trim(),
|
||||
skuName: form.skuName?.trim() || undefined,
|
||||
bitanswerProductId: form.bitanswerProductId?.trim() || undefined,
|
||||
bitanswerTemplateId: form.bitanswerTemplateId?.trim() || undefined,
|
||||
bitanswerFeatureId: form.bitanswerFeatureId?.trim() || undefined,
|
||||
quantity: form.quantity || 1,
|
||||
};
|
||||
try {
|
||||
if (editingId.value != null) {
|
||||
await updateSkuMapping(editingId.value, payload);
|
||||
ElMessage.success("已保存");
|
||||
} else {
|
||||
await createSkuMapping(form.contractLineId, payload);
|
||||
ElMessage.success("已创建");
|
||||
}
|
||||
dialogVisible.value = false;
|
||||
await load();
|
||||
} catch (e) {
|
||||
ElMessage.error(apiErrorMessage(e, "保存失败"));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function onDelete(row) {
|
||||
ElMessageBox.confirm(`确定删除 SKU 映射(ID: ${row.id})吗?`, "提示", {
|
||||
type: "warning",
|
||||
confirmButtonText: "删除",
|
||||
cancelButtonText: "取消",
|
||||
})
|
||||
.then(async () => {
|
||||
try {
|
||||
await deleteSkuMapping(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>
|
||||
Reference in New Issue
Block a user