diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportRuleController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportRuleController.java new file mode 100644 index 00000000..db08a425 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportRuleController.java @@ -0,0 +1,113 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import top.xyquan.ecomdmbbackend.common.annotation.RequireRole; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.common.response.ApiResponse; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.CreateImportRuleDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.ImportRuleFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.UpdateImportRuleDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportRuleVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportRuleService; + +/** + * 导入规则管理控制器 + */ +@Tag(name = "电商-导入规则管理", description = "导入规则的增删改查接口") +@RestController +@RequestMapping("/ec/import-rule") +public class ImportRuleController { + + private final ImportRuleService importRuleService; + + public ImportRuleController(ImportRuleService importRuleService) { + this.importRuleService = importRuleService; + } + + @Operation(summary = "创建导入规则", description = "创建新的导入规则") + @PostMapping("/create") + @RequireRole(description = "创建导入规则", allowUser = false) + public ApiResponse createImportRule(@Valid @RequestBody CreateImportRuleDTO createImportRuleDTO) { + ImportRuleVO importRuleVO = importRuleService.createImportRule(createImportRuleDTO); + return ApiResponse.success(importRuleVO); + } + + @Operation(summary = "更新导入规则", description = "更新现有导入规则信息") + @PutMapping("/update/{id}") + @RequireRole(description = "更新导入规则", allowUser = false) + public ApiResponse updateImportRule(@Valid @RequestBody UpdateImportRuleDTO updateImportRuleDTO, + @Parameter(description = "规则ID") @PathVariable Long id) { + ImportRuleVO importRuleVO = importRuleService.updateImportRule(updateImportRuleDTO, id); + return ApiResponse.success(importRuleVO); + } + + @Operation(summary = "删除导入规则", description = "删除指定导入规则") + @DeleteMapping("/delete/{id}") + @RequireRole(description = "删除导入规则", allowUser = false) + public ApiResponse deleteImportRule( + @Parameter(description = "规则ID") @PathVariable Long id) { + importRuleService.deleteImportRule(id); + return ApiResponse.success(); + } + + @Operation(summary = "根据ID获取导入规则", description = "根据规则ID获取导入规则详情") + @GetMapping("/get/{id}") + @RequireRole(description = "查看导入规则", allowUser = true) + public ApiResponse getImportRuleById( + @Parameter(description = "规则ID") @PathVariable Long id) { + ImportRuleVO importRuleVO = importRuleService.getImportRuleById(id); + return ApiResponse.success(importRuleVO); + } + + @Operation(summary = "分页获取导入规则列表", description = "分页获取导入规则列表,支持条件过滤") + @PostMapping("/page") + @RequireRole(description = "查询导入规则列表", allowUser = true) + public ApiResponse> getImportRulePage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = importRuleService.getImportRulePage(pageQueryDTO); + return ApiResponse.success(result); + } + + @Operation(summary = "根据规则类型获取导入规则列表", description = "根据规则类型获取导入规则列表") + @GetMapping("/list-by-type/{ruleType}") + @RequireRole(description = "根据类型查询导入规则", allowUser = true) + public ApiResponse> getImportRulesByType( + @Parameter(description = "规则类型") @PathVariable String ruleType) { + List importRuleVOs = importRuleService.getImportRulesByType(ruleType); + return ApiResponse.success(importRuleVOs); + } + + @Operation(summary = "获取启用的导入规则列表", description = "获取所有启用的导入规则列表") + @GetMapping("/active-list") + @RequireRole(description = "查询启用的导入规则", allowUser = true) + public ApiResponse> getActiveImportRules() { + List importRuleVOs = importRuleService.getActiveImportRules(); + return ApiResponse.success(importRuleVOs); + } + + @Operation(summary = "根据规则类型获取启用的导入规则", description = "根据规则类型获取启用的导入规则") + @GetMapping("/active-by-type/{ruleType}") + @RequireRole(description = "根据类型查询启用的导入规则", allowUser = true) + public ApiResponse getActiveImportRuleByType( + @Parameter(description = "规则类型") @PathVariable String ruleType) { + ImportRuleVO importRuleVO = importRuleService.getActiveImportRuleByType(ruleType); + return ApiResponse.success(importRuleVO); + } + + @Operation(summary = "启用/禁用导入规则", description = "启用或禁用指定的导入规则") + @PutMapping("/toggle-status/{id}") + @RequireRole(description = "启用/禁用导入规则", allowUser = false) + public ApiResponse toggleImportRuleStatus( + @Parameter(description = "规则ID") @PathVariable Long id, + @Parameter(description = "是否启用") @RequestParam Integer isActive) { + ImportRuleVO importRuleVO = importRuleService.toggleImportRuleStatus(id, isActive); + return ApiResponse.success(importRuleVO); + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportRuleMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportRuleMapper.java new file mode 100644 index 00000000..eae314e8 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportRuleMapper.java @@ -0,0 +1,12 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportRulePO; + +/** + * 导入规则Mapper接口 + */ +@Mapper +public interface ImportRuleMapper extends BaseMapper { +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/CreateImportRuleDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/CreateImportRuleDTO.java new file mode 100644 index 00000000..e25fb6cc --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/CreateImportRuleDTO.java @@ -0,0 +1,73 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * 创建导入规则DTO + */ +@Data +@Schema(description = "创建导入规则DTO") +public class CreateImportRuleDTO { + + /** + * 规则名称 + */ + @Schema(description = "规则名称", example = "订单导入规则", required = true) + @NotBlank(message = "规则名称不能为空") + private String ruleName; + + /** + * 规则类型 + */ + @Schema(description = "规则类型", example = "订单导入", required = true, + allowableValues = {"订单导入", "商品导入", "推广费导入", "店铺导入"}) + @NotBlank(message = "规则类型不能为空") + private String ruleType; + + /** + * 规则描述 + */ + @Schema(description = "规则描述", example = "用于处理订单数据的导入规则") + private String description; + + /** + * 字段映射规则(JSON格式) + */ + @Schema(description = "字段映射规则", example = "{\"excel_column_a\":\"product_name\",\"excel_column_b\":\"cost_price\"}", required = true) + @NotBlank(message = "字段映射规则不能为空") + private String fieldMappingRules; + + /** + * 数据验证规则(JSON格式) + */ + @Schema(description = "数据验证规则", example = "{\"product_name\":{\"required\":true,\"max_length\":255}}") + private String dataValidationRules; + + /** + * 数据转换规则(JSON格式) + */ + @Schema(description = "数据转换规则", example = "{\"cost_price\":{\"type\":\"decimal\",\"precision\":2}}") + private String dataTransformationRules; + + /** + * 默认值配置(JSON格式) + */ + @Schema(description = "默认值配置", example = "{\"platform\":\"淘宝\",\"status\":\"待处理\"}") + private String defaultValues; + + /** + * 是否启用 + */ + @Schema(description = "是否启用", example = "1", allowableValues = {"0", "1"}) + @NotNull(message = "是否启用不能为空") + private Integer isActive; + + /** + * 排序 + */ + @Schema(description = "排序", example = "0") + private Integer sortOrder; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/ImportRuleFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/ImportRuleFilterDTO.java new file mode 100644 index 00000000..2330e32a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/ImportRuleFilterDTO.java @@ -0,0 +1,31 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 导入规则过滤DTO + */ +@Data +@Schema(description = "导入规则过滤DTO") +public class ImportRuleFilterDTO { + + /** + * 规则名称(模糊查询) + */ + @Schema(description = "规则名称", example = "订单") + private String ruleName; + + /** + * 规则类型 + */ + @Schema(description = "规则类型", example = "订单导入", + allowableValues = {"订单导入", "商品导入", "推广费导入", "店铺导入"}) + private String ruleType; + + /** + * 是否启用 + */ + @Schema(description = "是否启用", example = "1", allowableValues = {"0", "1"}) + private Integer isActive; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/UpdateImportRuleDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/UpdateImportRuleDTO.java new file mode 100644 index 00000000..f9fbbc7f --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/UpdateImportRuleDTO.java @@ -0,0 +1,71 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 更新导入规则DTO + */ +@Data +@Schema(description = "更新导入规则DTO") +public class UpdateImportRuleDTO { + + /** + * 规则名称 + */ + @Schema(description = "规则名称", example = "订单导入规则") + @NotBlank(message = "规则名称不能为空") + private String ruleName; + + /** + * 规则类型 + */ + @Schema(description = "规则类型", example = "订单导入", + allowableValues = {"订单导入", "商品导入", "推广费导入", "店铺导入"}) + @NotBlank(message = "规则类型不能为空") + private String ruleType; + + /** + * 规则描述 + */ + @Schema(description = "规则描述", example = "用于处理订单数据的导入规则") + private String description; + + /** + * 字段映射规则(JSON格式) + */ + @Schema(description = "字段映射规则", example = "{\"excel_column_a\":\"product_name\",\"excel_column_b\":\"cost_price\"}") + @NotBlank(message = "字段映射规则不能为空") + private String fieldMappingRules; + + /** + * 数据验证规则(JSON格式) + */ + @Schema(description = "数据验证规则", example = "{\"product_name\":{\"required\":true,\"max_length\":255}}") + private String dataValidationRules; + + /** + * 数据转换规则(JSON格式) + */ + @Schema(description = "数据转换规则", example = "{\"cost_price\":{\"type\":\"decimal\",\"precision\":2}}") + private String dataTransformationRules; + + /** + * 默认值配置(JSON格式) + */ + @Schema(description = "默认值配置", example = "{\"platform\":\"淘宝\",\"status\":\"待处理\"}") + private String defaultValues; + + /** + * 是否启用 + */ + @Schema(description = "是否启用", example = "1", allowableValues = {"0", "1"}) + private Integer isActive; + + /** + * 排序 + */ + @Schema(description = "排序", example = "0") + private Integer sortOrder; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportRulePO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportRulePO.java new file mode 100644 index 00000000..0adf5310 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportRulePO.java @@ -0,0 +1,106 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.po; + +import com.baomidou.mybatisplus.annotation.*; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +/** + * 电商-导入规则实体 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@TableName("ec_import_rule") +public class ImportRulePO { + + /** + * 规则ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 规则名称 + */ + @TableField("rule_name") + private String ruleName; + + /** + * 规则类型(如:订单导入、商品导入、推广费导入等) + */ + @TableField("rule_type") + private String ruleType; + + /** + * 规则描述 + */ + @TableField("description") + private String description; + + /** + * 字段映射规则(JSON格式) + */ + @TableField("field_mapping_rules") + private String fieldMappingRules; + + /** + * 数据验证规则(JSON格式) + */ + @TableField("data_validation_rules") + private String dataValidationRules; + + /** + * 数据转换规则(JSON格式) + */ + @TableField("data_transformation_rules") + private String dataTransformationRules; + + /** + * 默认值配置(JSON格式) + */ + @TableField("default_values") + private String defaultValues; + + /** + * 是否启用 0禁用 1启用 + */ + @TableField("is_active") + private Integer isActive; + + /** + * 排序 + */ + @TableField("sort_order") + private Integer sortOrder; + + /** + * 创建时间 + */ + @TableField(value = "create_time", fill = FieldFill.INSERT) + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updateTime; + + /** + * 创建人ID + */ + @TableField("create_by") + private Long createBy; + + /** + * 更新人ID + */ + @TableField("update_by") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportRuleVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportRuleVO.java new file mode 100644 index 00000000..3e06db36 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportRuleVO.java @@ -0,0 +1,104 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 导入规则VO + */ +@Data +@Schema(description = "导入规则VO") +public class ImportRuleVO { + + /** + * 规则ID + */ + @Schema(description = "规则ID", example = "1") + private Long id; + + /** + * 公司ID + */ + @Schema(description = "公司ID", example = "1") + private Long companyId; + + /** + * 规则名称 + */ + @Schema(description = "规则名称", example = "订单导入规则") + private String ruleName; + + /** + * 规则类型 + */ + @Schema(description = "规则类型", example = "订单导入") + private String ruleType; + + /** + * 规则描述 + */ + @Schema(description = "规则描述", example = "用于处理订单数据的导入规则") + private String description; + + /** + * 字段映射规则(JSON格式) + */ + @Schema(description = "字段映射规则", example = "{\"excel_column_a\":\"product_name\",\"excel_column_b\":\"cost_price\"}") + private String fieldMappingRules; + + /** + * 数据验证规则(JSON格式) + */ + @Schema(description = "数据验证规则", example = "{\"product_name\":{\"required\":true,\"max_length\":255}}") + private String dataValidationRules; + + /** + * 数据转换规则(JSON格式) + */ + @Schema(description = "数据转换规则", example = "{\"cost_price\":{\"type\":\"decimal\",\"precision\":2}}") + private String dataTransformationRules; + + /** + * 默认值配置(JSON格式) + */ + @Schema(description = "默认值配置", example = "{\"platform\":\"淘宝\",\"status\":\"待处理\"}") + private String defaultValues; + + /** + * 是否启用 + */ + @Schema(description = "是否启用", example = "1") + private Integer isActive; + + /** + * 排序 + */ + @Schema(description = "排序", example = "0") + private Integer sortOrder; + + /** + * 创建时间 + */ + @Schema(description = "创建时间", example = "2024-01-01T10:00:00") + private LocalDateTime createTime; + + /** + * 更新时间 + */ + @Schema(description = "更新时间", example = "2024-01-01T10:00:00") + private LocalDateTime updateTime; + + /** + * 创建人ID + */ + @Schema(description = "创建人ID", example = "1") + private Long createBy; + + /** + * 更新人ID + */ + @Schema(description = "更新人ID", example = "1") + private Long updateBy; +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportRuleService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportRuleService.java new file mode 100644 index 00000000..6bbec230 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportRuleService.java @@ -0,0 +1,90 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.CreateImportRuleDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.ImportRuleFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.UpdateImportRuleDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportRulePO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportRuleVO; + +import java.util.List; + +/** + * 导入规则服务接口 + */ +public interface ImportRuleService extends IService { + + /** + * 创建导入规则 + * + * @param createImportRuleDTO 创建导入规则DTO + * @return 导入规则VO + */ + ImportRuleVO createImportRule(CreateImportRuleDTO createImportRuleDTO); + + /** + * 更新导入规则 + * + * @param updateImportRuleDTO 更新导入规则DTO + * @param id 规则ID + * @return 导入规则VO + */ + ImportRuleVO updateImportRule(UpdateImportRuleDTO updateImportRuleDTO, Long id); + + /** + * 删除导入规则 + * + * @param id 规则ID + */ + void deleteImportRule(Long id); + + /** + * 根据ID获取导入规则 + * + * @param id 规则ID + * @return 导入规则VO + */ + ImportRuleVO getImportRuleById(Long id); + + /** + * 分页获取导入规则列表 + * + * @param pageQueryDTO 分页查询DTO + * @return 分页结果 + */ + PageResultVO getImportRulePage(PageQueryDTO pageQueryDTO); + + /** + * 根据规则类型获取导入规则列表 + * + * @param ruleType 规则类型 + * @return 导入规则VO列表 + */ + List getImportRulesByType(String ruleType); + + /** + * 获取启用的导入规则列表 + * + * @return 导入规则VO列表 + */ + List getActiveImportRules(); + + /** + * 根据规则类型获取启用的导入规则 + * + * @param ruleType 规则类型 + * @return 导入规则VO + */ + ImportRuleVO getActiveImportRuleByType(String ruleType); + + /** + * 启用/禁用导入规则 + * + * @param id 规则ID + * @param isActive 是否启用 + * @return 导入规则VO + */ + ImportRuleVO toggleImportRuleStatus(Long id, Integer isActive); +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportRuleServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportRuleServiceImpl.java new file mode 100644 index 00000000..95af4351 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportRuleServiceImpl.java @@ -0,0 +1,253 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; +import top.xyquan.ecomdmbbackend.common.exception.BusinessException; +import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ImportRuleMapper; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.CreateImportRuleDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.ImportRuleFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importrule.UpdateImportRuleDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportRulePO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportRuleVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportRuleService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 导入规则服务实现类 + */ +@Service +public class ImportRuleServiceImpl extends ServiceImpl implements ImportRuleService { + + private final CurrentUserContext currentUserContext; + + public ImportRuleServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + @Override + @Transactional + public ImportRuleVO createImportRule(CreateImportRuleDTO createImportRuleDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 验证规则名称是否重复 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportRulePO::getCompanyId, companyId) + .eq(ImportRulePO::getRuleName, createImportRuleDTO.getRuleName()); + if (this.count(wrapper) > 0) { + throw new BusinessException("规则名称已存在"); + } + + // 创建导入规则 + ImportRulePO importRulePO = new ImportRulePO(); + BeanUtils.copyProperties(createImportRuleDTO, importRulePO); + importRulePO.setCompanyId(companyId); + importRulePO.setCreateBy(currentUserContext.getCurrentUserId()); + + this.save(importRulePO); + + // 转换为VO返回 + return convertToVO(importRulePO); + } + + @Override + @Transactional + public ImportRuleVO updateImportRule(UpdateImportRuleDTO updateImportRuleDTO, Long id) { + // 检查规则是否存在 + ImportRulePO importRulePO = this.getById(id); + if (importRulePO == null) { + throw new BusinessException("导入规则不存在"); + } + + // 验证公司权限 + Long companyId = currentUserContext.getCurrentCompanyId(); + if (!importRulePO.getCompanyId().equals(companyId)) { + throw new BusinessException("无权限操作此规则"); + } + + // 验证规则名称是否重复(排除自己) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportRulePO::getCompanyId, companyId) + .eq(ImportRulePO::getRuleName, updateImportRuleDTO.getRuleName()) + .ne(ImportRulePO::getId, id); + if (this.count(wrapper) > 0) { + throw new BusinessException("规则名称已存在"); + } + + // 更新导入规则 + BeanUtils.copyProperties(updateImportRuleDTO, importRulePO); + importRulePO.setUpdateBy(currentUserContext.getCurrentUserId()); + + this.updateById(importRulePO); + + // 转换为VO返回 + return convertToVO(importRulePO); + } + + @Override + @Transactional + public void deleteImportRule(Long id) { + // 检查规则是否存在 + ImportRulePO importRulePO = this.getById(id); + if (importRulePO == null) { + throw new BusinessException("导入规则不存在"); + } + + // 验证公司权限 + Long companyId = currentUserContext.getCurrentCompanyId(); + if (!importRulePO.getCompanyId().equals(companyId)) { + throw new BusinessException("无权限操作此规则"); + } + + // 删除规则 + this.removeById(id); + } + + @Override + public ImportRuleVO getImportRuleById(Long id) { + ImportRulePO importRulePO = this.getById(id); + if (importRulePO == null) { + throw new BusinessException("导入规则不存在"); + } + + // 验证公司权限 + Long companyId = currentUserContext.getCurrentCompanyId(); + if (!importRulePO.getCompanyId().equals(companyId)) { + throw new BusinessException("无权限查看此规则"); + } + + return convertToVO(importRulePO); + } + + @Override + public PageResultVO getImportRulePage(PageQueryDTO pageQueryDTO) { + Long companyId = currentUserContext.getCurrentCompanyId(); + ImportRuleFilterDTO filterDTO = pageQueryDTO.getFilters(); + + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportRulePO::getCompanyId, companyId); + + if (filterDTO != null) { + if (StringUtils.hasText(filterDTO.getRuleName())) { + wrapper.like(ImportRulePO::getRuleName, filterDTO.getRuleName()); + } + if (StringUtils.hasText(filterDTO.getRuleType())) { + wrapper.eq(ImportRulePO::getRuleType, filterDTO.getRuleType()); + } + if (filterDTO.getIsActive() != null) { + wrapper.eq(ImportRulePO::getIsActive, filterDTO.getIsActive()); + } + } + + // 按排序字段和创建时间排序 + wrapper.orderByAsc(ImportRulePO::getSortOrder) + .orderByDesc(ImportRulePO::getCreateTime); + + // 分页查询 + Page page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + IPage pageResult = this.page(page, wrapper); + + // 转换为VO + List voList = pageResult.getRecords().stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + + return new PageResultVO<>(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + } + + @Override + public List getImportRulesByType(String ruleType) { + Long companyId = currentUserContext.getCurrentCompanyId(); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportRulePO::getCompanyId, companyId) + .eq(ImportRulePO::getRuleType, ruleType) + .orderByAsc(ImportRulePO::getSortOrder) + .orderByDesc(ImportRulePO::getCreateTime); + + List poList = this.list(wrapper); + return poList.stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + } + + @Override + public List getActiveImportRules() { + Long companyId = currentUserContext.getCurrentCompanyId(); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportRulePO::getCompanyId, companyId) + .eq(ImportRulePO::getIsActive, 1) + .orderByAsc(ImportRulePO::getSortOrder) + .orderByDesc(ImportRulePO::getCreateTime); + + List poList = this.list(wrapper); + return poList.stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + } + + @Override + public ImportRuleVO getActiveImportRuleByType(String ruleType) { + Long companyId = currentUserContext.getCurrentCompanyId(); + + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportRulePO::getCompanyId, companyId) + .eq(ImportRulePO::getRuleType, ruleType) + .eq(ImportRulePO::getIsActive, 1) + .orderByAsc(ImportRulePO::getSortOrder) + .orderByDesc(ImportRulePO::getCreateTime) + .last("LIMIT 1"); + + ImportRulePO importRulePO = this.getOne(wrapper); + if (importRulePO == null) { + throw new BusinessException("未找到启用的" + ruleType + "规则"); + } + + return convertToVO(importRulePO); + } + + @Override + @Transactional + public ImportRuleVO toggleImportRuleStatus(Long id, Integer isActive) { + // 检查规则是否存在 + ImportRulePO importRulePO = this.getById(id); + if (importRulePO == null) { + throw new BusinessException("导入规则不存在"); + } + + // 验证公司权限 + Long companyId = currentUserContext.getCurrentCompanyId(); + if (!importRulePO.getCompanyId().equals(companyId)) { + throw new BusinessException("无权限操作此规则"); + } + + // 更新状态 + importRulePO.setIsActive(isActive); + importRulePO.setUpdateBy(currentUserContext.getCurrentUserId()); + this.updateById(importRulePO); + + return convertToVO(importRulePO); + } + + /** + * 转换为VO + */ + private ImportRuleVO convertToVO(ImportRulePO importRulePO) { + ImportRuleVO importRuleVO = new ImportRuleVO(); + BeanUtils.copyProperties(importRulePO, importRuleVO); + return importRuleVO; + } +} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ProductSpecServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ProductSpecServiceImpl.java index fe9c6ae1..1395eba4 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ProductSpecServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ProductSpecServiceImpl.java @@ -151,6 +151,9 @@ public class ProductSpecServiceImpl extends ServiceImpl + +
+ +
+
+ + + 请将左侧系统字段与右侧CSV文件字段进行匹配,重新组织数据结构以正确进行实体匹配 + +
+
+ + +
+ +
+
+

系统字段

+

系统预定义的订单字段,必须映射

+
+ +
+
+
+
+
+ {{ field.label }} + + * + +
+
{{ field.description }}
+
+
+ + +
+
+
+
+
+ + +
+
+

CSV字段映射

+

选择CSV文件中的对应字段

+
+ +
+
+
+
+ {{ field.label }} + + * + +
+
+ + +
+
+ + + + +
+
数据预览:
+
+
+ {{ sample }} +
+
+
+
+
+
+
+ + +
+
+
+
{{ systemFields.length }}
+
总字段数
+
+
+
{{ mappedFieldsCount }}
+
已映射
+
+
+
{{ unmappedFieldsCount }}
+
未映射
+
+
+
+ + +
+ + + +
+
+
+ + + + + diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/data-import/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/data-import/index.vue index 8b9d15fd..f5a307e0 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/data-import/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/data-import/index.vue @@ -35,8 +35,8 @@ - @@ -223,19 +223,13 @@ - - - + { gridApi.grid?.clearCheckboxRow() } -// 字段映射处理 -const handleFieldMapping = (mappedData: any) => { +// 字段匹配处理 +const handleFieldMapping = (fieldMappings: Record) => { showFieldMapping.value = false - // 这里可以处理映射后的数据 - console.log('映射后的数据:', mappedData) - message.success('字段映射配置完成') + + // 应用字段匹配到CSV数据 + const matchedCsvData = csvData.value.map(row => { + const matchedRow: any = {} + + // 根据字段匹配重新组织数据 + Object.entries(fieldMappings).forEach(([systemField, csvField]) => { + if (csvField && row[csvField] !== undefined) { + matchedRow[systemField] = row[csvField] + } + }) + + // 保留原始ID + matchedRow.id = row.id + + return matchedRow + }) + + // 更新CSV数据 + csvData.value = matchedCsvData + + // 更新表格显示 + updateTableData() + + // 重新进行实体匹配 + performEntityMatching() + + message.success(`字段匹配完成,已匹配 ${Object.keys(fieldMappings).length} 个字段,正在重新进行实体匹配...`) } // 执行实体匹配