mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
增加字段匹配模态框
This commit is contained in:
+113
@@ -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<ImportRuleVO> 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<ImportRuleVO> 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<Void> 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<ImportRuleVO> 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<PageResultVO<ImportRuleVO>> getImportRulePage(
|
||||
@Valid @RequestBody PageQueryDTO<ImportRuleFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<ImportRuleVO> result = importRuleService.getImportRulePage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据规则类型获取导入规则列表", description = "根据规则类型获取导入规则列表")
|
||||
@GetMapping("/list-by-type/{ruleType}")
|
||||
@RequireRole(description = "根据类型查询导入规则", allowUser = true)
|
||||
public ApiResponse<List<ImportRuleVO>> getImportRulesByType(
|
||||
@Parameter(description = "规则类型") @PathVariable String ruleType) {
|
||||
List<ImportRuleVO> importRuleVOs = importRuleService.getImportRulesByType(ruleType);
|
||||
return ApiResponse.success(importRuleVOs);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取启用的导入规则列表", description = "获取所有启用的导入规则列表")
|
||||
@GetMapping("/active-list")
|
||||
@RequireRole(description = "查询启用的导入规则", allowUser = true)
|
||||
public ApiResponse<List<ImportRuleVO>> getActiveImportRules() {
|
||||
List<ImportRuleVO> importRuleVOs = importRuleService.getActiveImportRules();
|
||||
return ApiResponse.success(importRuleVOs);
|
||||
}
|
||||
|
||||
@Operation(summary = "根据规则类型获取启用的导入规则", description = "根据规则类型获取启用的导入规则")
|
||||
@GetMapping("/active-by-type/{ruleType}")
|
||||
@RequireRole(description = "根据类型查询启用的导入规则", allowUser = true)
|
||||
public ApiResponse<ImportRuleVO> 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<ImportRuleVO> toggleImportRuleStatus(
|
||||
@Parameter(description = "规则ID") @PathVariable Long id,
|
||||
@Parameter(description = "是否启用") @RequestParam Integer isActive) {
|
||||
ImportRuleVO importRuleVO = importRuleService.toggleImportRuleStatus(id, isActive);
|
||||
return ApiResponse.success(importRuleVO);
|
||||
}
|
||||
}
|
||||
+12
@@ -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<ImportRulePO> {
|
||||
}
|
||||
+73
@@ -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;
|
||||
}
|
||||
+31
@@ -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;
|
||||
}
|
||||
+71
@@ -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;
|
||||
}
|
||||
+106
@@ -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;
|
||||
}
|
||||
+104
@@ -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;
|
||||
}
|
||||
+90
@@ -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<ImportRulePO> {
|
||||
|
||||
/**
|
||||
* 创建导入规则
|
||||
*
|
||||
* @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<ImportRuleVO> getImportRulePage(PageQueryDTO<ImportRuleFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 根据规则类型获取导入规则列表
|
||||
*
|
||||
* @param ruleType 规则类型
|
||||
* @return 导入规则VO列表
|
||||
*/
|
||||
List<ImportRuleVO> getImportRulesByType(String ruleType);
|
||||
|
||||
/**
|
||||
* 获取启用的导入规则列表
|
||||
*
|
||||
* @return 导入规则VO列表
|
||||
*/
|
||||
List<ImportRuleVO> getActiveImportRules();
|
||||
|
||||
/**
|
||||
* 根据规则类型获取启用的导入规则
|
||||
*
|
||||
* @param ruleType 规则类型
|
||||
* @return 导入规则VO
|
||||
*/
|
||||
ImportRuleVO getActiveImportRuleByType(String ruleType);
|
||||
|
||||
/**
|
||||
* 启用/禁用导入规则
|
||||
*
|
||||
* @param id 规则ID
|
||||
* @param isActive 是否启用
|
||||
* @return 导入规则VO
|
||||
*/
|
||||
ImportRuleVO toggleImportRuleStatus(Long id, Integer isActive);
|
||||
}
|
||||
+253
@@ -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<ImportRuleMapper, ImportRulePO> 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<ImportRulePO> 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<ImportRulePO> 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<ImportRuleVO> getImportRulePage(PageQueryDTO<ImportRuleFilterDTO> pageQueryDTO) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
ImportRuleFilterDTO filterDTO = pageQueryDTO.getFilters();
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<ImportRulePO> 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<ImportRulePO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
IPage<ImportRulePO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<ImportRuleVO> voList = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return new PageResultVO<>(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImportRuleVO> getImportRulesByType(String ruleType) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
LambdaQueryWrapper<ImportRulePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImportRulePO::getCompanyId, companyId)
|
||||
.eq(ImportRulePO::getRuleType, ruleType)
|
||||
.orderByAsc(ImportRulePO::getSortOrder)
|
||||
.orderByDesc(ImportRulePO::getCreateTime);
|
||||
|
||||
List<ImportRulePO> poList = this.list(wrapper);
|
||||
return poList.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImportRuleVO> getActiveImportRules() {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
LambdaQueryWrapper<ImportRulePO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImportRulePO::getCompanyId, companyId)
|
||||
.eq(ImportRulePO::getIsActive, 1)
|
||||
.orderByAsc(ImportRulePO::getSortOrder)
|
||||
.orderByDesc(ImportRulePO::getCreateTime);
|
||||
|
||||
List<ImportRulePO> poList = this.list(wrapper);
|
||||
return poList.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImportRuleVO getActiveImportRuleByType(String ruleType) {
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
|
||||
LambdaQueryWrapper<ImportRulePO> 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;
|
||||
}
|
||||
}
|
||||
+3
@@ -151,6 +151,9 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
|
||||
if (filter.getName() != null && !filter.getName().trim().isEmpty()) {
|
||||
wrapper.like(ProductSpecPO::getName, filter.getName());
|
||||
}
|
||||
if(filter.getSpecCode() != null && !filter.getSpecCode().trim().isEmpty()) {
|
||||
wrapper.eq(ProductSpecPO::getSpecCode, filter.getSpecCode());
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
|
||||
@@ -192,4 +192,31 @@ CREATE TABLE `ec_promotion_fee` (
|
||||
CONSTRAINT `fk_ec_promotion_fee_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-推广费记录表';
|
||||
|
||||
-- 注意:推广费类型初始数据现在通过服务层方法按公司插入,不再在此处插入
|
||||
-- 导入数据匹配规则表
|
||||
CREATE TABLE `ec_import_rule` (
|
||||
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '规则ID',
|
||||
`company_id` BIGINT UNSIGNED NOT NULL COMMENT '公司ID',
|
||||
`rule_name` VARCHAR(200) NOT NULL COMMENT '规则名称',
|
||||
`rule_type` VARCHAR(50) NOT NULL COMMENT '规则类型(如:订单导入、商品导入、推广费导入等)',
|
||||
`description` VARCHAR(500) DEFAULT NULL COMMENT '规则描述',
|
||||
`field_mapping_rules` JSON NOT NULL COMMENT '字段映射规则(JSON格式)',
|
||||
`data_validation_rules` JSON DEFAULT NULL COMMENT '数据验证规则(JSON格式)',
|
||||
`data_transformation_rules` JSON DEFAULT NULL COMMENT '数据转换规则(JSON格式)',
|
||||
`default_values` JSON DEFAULT NULL COMMENT '默认值配置(JSON格式)',
|
||||
`is_active` TINYINT NOT NULL DEFAULT 1 COMMENT '是否启用 0禁用 1启用',
|
||||
`sort_order` INT NOT NULL DEFAULT 0 COMMENT '排序',
|
||||
`create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '创建人ID',
|
||||
`update_by` BIGINT UNSIGNED DEFAULT NULL COMMENT '更新人ID',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_company_id` (`company_id`),
|
||||
KEY `idx_rule_type` (`rule_type`),
|
||||
KEY `idx_is_active` (`is_active`),
|
||||
KEY `idx_sort_order` (`sort_order`),
|
||||
KEY `fk_ec_import_rule_creator` (`create_by`),
|
||||
KEY `fk_ec_import_rule_updater` (`update_by`),
|
||||
CONSTRAINT `fk_ec_import_rule_company` FOREIGN KEY (`company_id`) REFERENCES `org_company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_import_rule_creator` FOREIGN KEY (`create_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_ec_import_rule_updater` FOREIGN KEY (`update_by`) REFERENCES `sys_user` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='电商-导入数据匹配规则表';
|
||||
|
||||
+473
@@ -0,0 +1,473 @@
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
title="字段匹配配置"
|
||||
width="1200px"
|
||||
:footer="null"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<div class="field-mapping-container">
|
||||
<!-- 说明信息 -->
|
||||
<div class="mb-4 p-3 bg-blue-50 border border-blue-200 rounded-lg">
|
||||
<div class="flex items-center space-x-2">
|
||||
<InfoIcon class="w-4 h-4 text-blue-500" />
|
||||
<span class="text-sm text-blue-800">
|
||||
请将左侧系统字段与右侧CSV文件字段进行匹配,重新组织数据结构以正确进行实体匹配
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 字段映射区域 -->
|
||||
<div class="grid grid-cols-2 gap-6">
|
||||
<!-- 左侧:系统字段 -->
|
||||
<div class="system-fields">
|
||||
<div class="mb-3">
|
||||
<h3 class="text-lg font-medium text-gray-800">系统字段</h3>
|
||||
<p class="text-sm text-gray-600">系统预定义的订单字段,必须映射</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 max-h-96 overflow-y-auto">
|
||||
<div
|
||||
v-for="field in systemFields"
|
||||
:key="field.key"
|
||||
class="field-item p-3 border rounded-lg"
|
||||
:class="{
|
||||
'border-green-200 bg-green-50': fieldMappings[field.key],
|
||||
'border-gray-200 bg-gray-50': !fieldMappings[field.key]
|
||||
}"
|
||||
>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center space-x-2">
|
||||
<span class="font-medium text-gray-800">{{ field.label }}</span>
|
||||
<span
|
||||
v-if="field.required"
|
||||
class="text-red-500 text-xs"
|
||||
>
|
||||
*
|
||||
</span>
|
||||
</div>
|
||||
<div class="text-xs text-gray-500 mt-1">{{ field.description }}</div>
|
||||
</div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<CheckIcon
|
||||
v-if="fieldMappings[field.key]"
|
||||
class="w-4 h-4 text-green-500"
|
||||
/>
|
||||
<XIcon
|
||||
v-else
|
||||
class="w-4 h-4 text-gray-400"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧:CSV字段映射 -->
|
||||
<div class="csv-fields">
|
||||
<div class="mb-3">
|
||||
<h3 class="text-lg font-medium text-gray-800">CSV字段映射</h3>
|
||||
<p class="text-sm text-gray-600">选择CSV文件中的对应字段</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-3 max-h-96 overflow-y-auto">
|
||||
<div
|
||||
v-for="field in systemFields"
|
||||
:key="field.key"
|
||||
class="field-mapping-item p-3 border rounded-lg"
|
||||
>
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<div class="flex items-center space-x-2">
|
||||
<span class="font-medium text-gray-800">{{ field.label }}</span>
|
||||
<span
|
||||
v-if="field.required"
|
||||
class="text-red-500 text-xs"
|
||||
>
|
||||
*
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex items-center space-x-2">
|
||||
<CheckIcon
|
||||
v-if="fieldMappings[field.key]"
|
||||
class="w-4 h-4 text-green-500"
|
||||
/>
|
||||
<XIcon
|
||||
v-else
|
||||
class="w-4 h-4 text-gray-400"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Select
|
||||
v-model:value="fieldMappings[field.key]"
|
||||
placeholder="请选择CSV字段"
|
||||
style="width: 100%"
|
||||
:options="csvFieldOptions"
|
||||
:filter-option="filterOption"
|
||||
show-search
|
||||
allow-clear
|
||||
@change="(value: any) => handleFieldMappingChange(field.key, value)"
|
||||
>
|
||||
<template #option="{ label, value }">
|
||||
<div class="flex items-center justify-between">
|
||||
<span>{{ label }}</span>
|
||||
<span class="text-xs text-gray-500">{{ value }}</span>
|
||||
</div>
|
||||
</template>
|
||||
</Select>
|
||||
|
||||
<!-- 字段预览 -->
|
||||
<div v-if="fieldMappings[field.key]" class="mt-2">
|
||||
<div class="text-xs text-gray-600 mb-1">数据预览:</div>
|
||||
<div class="text-xs bg-gray-100 p-2 rounded max-h-20 overflow-y-auto">
|
||||
<div v-for="(sample, index) in getFieldSamples(fieldMappings[field.key] || '')" :key="index">
|
||||
{{ sample }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 映射统计 -->
|
||||
<div class="mt-6 p-4 bg-gray-50 border rounded-lg">
|
||||
<div class="grid grid-cols-3 gap-4 text-center">
|
||||
<div>
|
||||
<div class="text-2xl font-bold text-blue-600">{{ systemFields.length }}</div>
|
||||
<div class="text-sm text-gray-600">总字段数</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-2xl font-bold text-green-600">{{ mappedFieldsCount }}</div>
|
||||
<div class="text-sm text-gray-600">已映射</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-2xl font-bold text-red-600">{{ unmappedFieldsCount }}</div>
|
||||
<div class="text-sm text-gray-600">未映射</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex justify-end space-x-3 mt-6">
|
||||
<Button @click="handleCancel">
|
||||
取消
|
||||
</Button>
|
||||
<Button @click="handleReset" type="default">
|
||||
重置
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
@click="handleConfirm"
|
||||
:disabled="unmappedFieldsCount > 0"
|
||||
>
|
||||
确认匹配 ({{ mappedFieldsCount }}/{{ systemFields.length }})
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { Modal, Button, Select } from 'ant-design-vue'
|
||||
import { createIconifyIcon } from '@vben/icons'
|
||||
|
||||
// 创建图标组件
|
||||
const InfoIcon = createIconifyIcon('lucide:info')
|
||||
const CheckIcon = createIconifyIcon('lucide:check')
|
||||
const XIcon = createIconifyIcon('lucide:x')
|
||||
|
||||
interface SystemField {
|
||||
key: string
|
||||
label: string
|
||||
description: string
|
||||
required: boolean
|
||||
dataType: string
|
||||
}
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
csvHeaders: string[]
|
||||
csvData: any[]
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'confirm', mappings: Record<string, string>): void
|
||||
(e: 'cancel'): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
const visible = ref(false)
|
||||
|
||||
// 系统字段定义
|
||||
const systemFields: SystemField[] = [
|
||||
{
|
||||
key: 'shopName',
|
||||
label: '店铺名称',
|
||||
description: '订单所属店铺名称',
|
||||
required: true,
|
||||
dataType: 'string'
|
||||
},
|
||||
{
|
||||
key: 'productName',
|
||||
label: '商品名称',
|
||||
description: '订单商品名称',
|
||||
required: true,
|
||||
dataType: 'string'
|
||||
},
|
||||
{
|
||||
key: 'productSpecName',
|
||||
label: '商品规格',
|
||||
description: '商品规格名称',
|
||||
required: false,
|
||||
dataType: 'string'
|
||||
},
|
||||
{
|
||||
key: 'specCode',
|
||||
label: '规格编码',
|
||||
description: '商品规格编码',
|
||||
required: false,
|
||||
dataType: 'string'
|
||||
},
|
||||
{
|
||||
key: 'orderNumber',
|
||||
label: '订单编号',
|
||||
description: '平台订单编号',
|
||||
required: true,
|
||||
dataType: 'string'
|
||||
},
|
||||
{
|
||||
key: 'orderStatusName',
|
||||
label: '订单状态',
|
||||
description: '订单状态名称',
|
||||
required: true,
|
||||
dataType: 'string'
|
||||
},
|
||||
{
|
||||
key: 'quantity',
|
||||
label: '商品数量',
|
||||
description: '订单商品数量',
|
||||
required: true,
|
||||
dataType: 'number'
|
||||
},
|
||||
{
|
||||
key: 'shopActualAmount',
|
||||
label: '实收金额',
|
||||
description: '商家实际收到金额',
|
||||
required: true,
|
||||
dataType: 'number'
|
||||
},
|
||||
{
|
||||
key: 'unitPrice',
|
||||
label: '销售单价',
|
||||
description: '商品销售单价',
|
||||
required: false,
|
||||
dataType: 'number'
|
||||
},
|
||||
{
|
||||
key: 'costPrice',
|
||||
label: '成本价',
|
||||
description: '商品成本价格',
|
||||
required: false,
|
||||
dataType: 'number'
|
||||
},
|
||||
{
|
||||
key: 'orderDate',
|
||||
label: '下单时间',
|
||||
description: '订单创建时间',
|
||||
required: false,
|
||||
dataType: 'date'
|
||||
},
|
||||
{
|
||||
key: 'shippingFee',
|
||||
label: '运费',
|
||||
description: '订单运费',
|
||||
required: false,
|
||||
dataType: 'number'
|
||||
}
|
||||
]
|
||||
|
||||
// 字段映射状态
|
||||
const fieldMappings = ref<Record<string, string>>({})
|
||||
|
||||
// CSV字段选项
|
||||
const csvFieldOptions = computed(() => {
|
||||
return props.csvHeaders.map(header => ({
|
||||
label: header,
|
||||
value: header
|
||||
}))
|
||||
})
|
||||
|
||||
// 已映射字段数量
|
||||
const mappedFieldsCount = computed(() => {
|
||||
return Object.values(fieldMappings.value).filter(value => value).length
|
||||
})
|
||||
|
||||
// 未映射字段数量
|
||||
const unmappedFieldsCount = computed(() => {
|
||||
return systemFields.length - mappedFieldsCount.value
|
||||
})
|
||||
|
||||
// 监听visible变化
|
||||
watch(() => props.visible, (newVal) => {
|
||||
visible.value = newVal
|
||||
if (newVal) {
|
||||
// 初始化字段映射
|
||||
initializeFieldMappings()
|
||||
}
|
||||
})
|
||||
|
||||
watch(visible, (newVal) => {
|
||||
emit('update:visible', newVal)
|
||||
})
|
||||
|
||||
// 初始化字段映射
|
||||
const initializeFieldMappings = () => {
|
||||
const mappings: Record<string, string> = {}
|
||||
|
||||
// 尝试自动匹配字段
|
||||
systemFields.forEach(field => {
|
||||
const matchedHeader = findBestMatch(field.label, props.csvHeaders)
|
||||
if (matchedHeader) {
|
||||
mappings[field.key] = matchedHeader
|
||||
}
|
||||
})
|
||||
|
||||
fieldMappings.value = mappings
|
||||
}
|
||||
|
||||
// 查找最佳匹配
|
||||
const findBestMatch = (systemFieldLabel: string, csvHeaders: string[]): string | null => {
|
||||
const systemFieldLower = systemFieldLabel.toLowerCase()
|
||||
|
||||
// 精确匹配
|
||||
for (const header of csvHeaders) {
|
||||
if (header.toLowerCase() === systemFieldLower) {
|
||||
return header
|
||||
}
|
||||
}
|
||||
|
||||
// 包含匹配
|
||||
for (const header of csvHeaders) {
|
||||
if (header.toLowerCase().includes(systemFieldLower) ||
|
||||
systemFieldLower.includes(header.toLowerCase())) {
|
||||
return header
|
||||
}
|
||||
}
|
||||
|
||||
// 关键词匹配
|
||||
const keywords = {
|
||||
'店铺名称': ['店铺', 'shop', 'store'],
|
||||
'商品名称': ['商品', 'product', 'item'],
|
||||
'商品规格': ['规格', 'spec', '规格名称'],
|
||||
'规格编码': ['编码', 'code', '规格编码'],
|
||||
'订单编号': ['订单', 'order', '编号', 'number'],
|
||||
'订单状态': ['状态', 'status'],
|
||||
'商品数量': ['数量', 'quantity', 'qty'],
|
||||
'实收金额': ['实收', '金额', 'amount', 'received'],
|
||||
'销售单价': ['单价', 'price', 'unit'],
|
||||
'成本价': ['成本', 'cost'],
|
||||
'下单时间': ['时间', 'date', 'time', '下单'],
|
||||
'运费': ['运费', 'shipping', 'freight']
|
||||
}
|
||||
|
||||
const fieldKeywords = keywords[systemFieldLabel as keyof typeof keywords] || []
|
||||
|
||||
for (const header of csvHeaders) {
|
||||
for (const keyword of fieldKeywords) {
|
||||
if (header.toLowerCase().includes(keyword)) {
|
||||
return header
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
// 下拉框搜索过滤
|
||||
const filterOption = (input: string, option: any) => {
|
||||
return option.label.toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
|
||||
// 处理字段映射变化
|
||||
const handleFieldMappingChange = (fieldKey: string, value: string | undefined) => {
|
||||
fieldMappings.value[fieldKey] = value || ''
|
||||
}
|
||||
|
||||
// 获取字段数据样本
|
||||
const getFieldSamples = (fieldName: string) => {
|
||||
if (!fieldName || !props.csvData.length) return []
|
||||
|
||||
return props.csvData.slice(0, 3).map(row => row[fieldName] || '').filter(val => val !== '')
|
||||
}
|
||||
|
||||
// 处理确认
|
||||
const handleConfirm = () => {
|
||||
if (unmappedFieldsCount.value > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
emit('confirm', { ...fieldMappings.value })
|
||||
visible.value = false
|
||||
}
|
||||
|
||||
// 处理取消
|
||||
const handleCancel = () => {
|
||||
visible.value = false
|
||||
emit('cancel')
|
||||
}
|
||||
|
||||
// 处理重置
|
||||
const handleReset = () => {
|
||||
fieldMappings.value = {}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.field-mapping-container {
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.field-item {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.field-item:hover {
|
||||
border-color: #3b82f6;
|
||||
background-color: #eff6ff;
|
||||
}
|
||||
|
||||
.field-mapping-item {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.field-mapping-item:hover {
|
||||
border-color: #3b82f6;
|
||||
background-color: #eff6ff;
|
||||
}
|
||||
|
||||
/* 滚动条样式 */
|
||||
.overflow-y-auto::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.overflow-y-auto::-webkit-scrollbar-track {
|
||||
background: #f1f1f1;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.overflow-y-auto::-webkit-scrollbar-thumb {
|
||||
background: #c1c1c1;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.overflow-y-auto::-webkit-scrollbar-thumb:hover {
|
||||
background: #a8a8a8;
|
||||
}
|
||||
</style>
|
||||
@@ -35,8 +35,8 @@
|
||||
<Button @click="clearSelection">
|
||||
清空选择
|
||||
</Button>
|
||||
<Button @click="showFieldMapping = true" :disabled="selectedRows.length === 0">
|
||||
配置字段映射 ({{ selectedRows.length }})
|
||||
<Button @click="showFieldMapping = true" :disabled="csvData.length === 0">
|
||||
字段匹配
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
@@ -223,19 +223,13 @@
|
||||
</template>
|
||||
</Grid>
|
||||
<!-- 字段映射弹窗 -->
|
||||
<Modal
|
||||
v-model:open="showFieldMapping"
|
||||
title="字段映射配置"
|
||||
width="1000px"
|
||||
:footer="null"
|
||||
>
|
||||
<FieldMapping
|
||||
:csv-headers="csvHeaders"
|
||||
:csv-data="selectedRows"
|
||||
@confirm="handleFieldMapping"
|
||||
@cancel="showFieldMapping = false"
|
||||
/>
|
||||
</Modal>
|
||||
<FieldMappingModal
|
||||
v-model:visible="showFieldMapping"
|
||||
:csv-headers="csvHeaders"
|
||||
:csv-data="csvData"
|
||||
@confirm="handleFieldMapping"
|
||||
@cancel="showFieldMapping = false"
|
||||
/>
|
||||
|
||||
<!-- 文件上传模态框 -->
|
||||
<FileUploadModal
|
||||
@@ -269,10 +263,10 @@
|
||||
defineOptions({ name: 'DataImport' })
|
||||
|
||||
import { ref } from 'vue'
|
||||
import { message, Progress, Button, Modal, Space } from 'ant-design-vue'
|
||||
import { message, Progress, Button, Space } from 'ant-design-vue'
|
||||
import { Page } from '@vben/common-ui'
|
||||
import { createIconifyIcon } from '@vben/icons'
|
||||
import FieldMapping from '#/views/ecommerce/data-import/components/FieldMapping.vue'
|
||||
import FieldMappingModal from '#/views/ecommerce/data-import/components/FieldMappingModal.vue'
|
||||
import FileUploadArea from './components/FileUploadArea.vue'
|
||||
import FileUploadModal from './components/FileUploadModal.vue'
|
||||
import EntityCreationModal from './components/EntityCreationModal.vue'
|
||||
@@ -497,12 +491,37 @@ const clearData = () => {
|
||||
gridApi.grid?.clearCheckboxRow()
|
||||
}
|
||||
|
||||
// 字段映射处理
|
||||
const handleFieldMapping = (mappedData: any) => {
|
||||
// 字段匹配处理
|
||||
const handleFieldMapping = (fieldMappings: Record<string, string>) => {
|
||||
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} 个字段,正在重新进行实体匹配...`)
|
||||
}
|
||||
|
||||
// 执行实体匹配
|
||||
|
||||
Reference in New Issue
Block a user