mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 02:39: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='电商-导入数据匹配规则表';
|
||||
|
||||
Reference in New Issue
Block a user