diff --git a/ecom-dmb-backend/pom.xml b/ecom-dmb-backend/pom.xml index 842cdba1..1b6ed823 100644 --- a/ecom-dmb-backend/pom.xml +++ b/ecom-dmb-backend/pom.xml @@ -101,6 +101,25 @@ org.aspectj aspectjrt + + + org.springframework.boot + spring-boot-starter-data-redis + + + + org.apache.commons + commons-pool2 + + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/RedisConfig.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/RedisConfig.java new file mode 100644 index 00000000..8d9b7258 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/common/config/RedisConfig.java @@ -0,0 +1,52 @@ +package top.xyquan.ecomdmbbackend.common.config; + +import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * Redis配置类 + */ +@Configuration +public class RedisConfig { + + /** + * 配置RedisTemplate + */ + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(connectionFactory); + + // 使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值 + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); + objectMapper.registerModule(new JavaTimeModule()); + + Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = + new Jackson2JsonRedisSerializer<>(objectMapper, Object.class); + + // 使用StringRedisSerializer来序列化和反序列化redis的key值 + StringRedisSerializer stringRedisSerializer = new StringRedisSerializer(); + + // key采用String的序列化方式 + template.setKeySerializer(stringRedisSerializer); + // hash的key也采用String的序列化方式 + template.setHashKeySerializer(stringRedisSerializer); + // value序列化方式采用jackson + template.setValueSerializer(jackson2JsonRedisSerializer); + // hash的value序列化方式采用jackson + template.setHashValueSerializer(jackson2JsonRedisSerializer); + + template.afterPropertiesSet(); + return template; + } +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/config/ImportTaskQueueConfig.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/config/ImportTaskQueueConfig.java new file mode 100644 index 00000000..74a526c6 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/config/ImportTaskQueueConfig.java @@ -0,0 +1,34 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.config; + +/** + * 导入任务队列配置 + * 定义队列相关的常量 + */ +public class ImportTaskQueueConfig { + + /** + * 导入任务队列前缀 + */ + public static final String IMPORT_TASK_QUEUE_PREFIX = "import:task:queue:"; + + /** + * 商品导入任务队列 + */ + public static final String IMPORT_TASK_QUEUE_PRODUCT = IMPORT_TASK_QUEUE_PREFIX + "product"; + + /** + * 订单导入任务队列 + */ + public static final String IMPORT_TASK_QUEUE_ORDER = IMPORT_TASK_QUEUE_PREFIX + "order"; + + /** + * 根据类型获取队列名称 + * + * @param type 导入类型(product/order) + * @return 队列名称 + */ + public static String getQueueName(String type) { + return IMPORT_TASK_QUEUE_PREFIX + type; + } +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportFieldDefController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportFieldDefController.java new file mode 100644 index 00000000..5fe3184d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportFieldDefController.java @@ -0,0 +1,79 @@ +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 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.importfielddef.CreateImportFieldDefDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.ImportFieldDefFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.UpdateImportFieldDefDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportFieldDefVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportFieldDefService; + +import java.util.List; + +/** + * 导入字段定义管理控制器 + */ +@Tag(name = "电商-导入字段定义管理", description = "导入字段定义的增删改查接口") +@RestController +@RequestMapping("/ec/import-field-def") +public class ImportFieldDefController { + + private final ImportFieldDefService importFieldDefService; + + public ImportFieldDefController(ImportFieldDefService importFieldDefService) { + this.importFieldDefService = importFieldDefService; + } + + @Operation(summary = "创建导入字段定义", description = "创建新的导入字段定义") + @PostMapping("/create") + @RequireRole(description = "创建导入字段定义", allowUser = false) + public ApiResponse createImportFieldDef(@Valid @RequestBody CreateImportFieldDefDTO createImportFieldDefDTO) { + ImportFieldDefVO importFieldDefVO = importFieldDefService.createImportFieldDef(createImportFieldDefDTO); + return ApiResponse.success(importFieldDefVO); + } + + @Operation(summary = "更新导入字段定义", description = "更新现有导入字段定义") + @PutMapping("/update/{id}") + @RequireRole(description = "更新导入字段定义", allowUser = false) + public ApiResponse updateImportFieldDef( + @Valid @RequestBody UpdateImportFieldDefDTO updateImportFieldDefDTO, + @Parameter(description = "字段定义ID") @PathVariable Long id) { + ImportFieldDefVO importFieldDefVO = importFieldDefService.updateImportFieldDef(updateImportFieldDefDTO, id); + return ApiResponse.success(importFieldDefVO); + } + + @Operation(summary = "删除导入字段定义", description = "删除指定导入字段定义") + @DeleteMapping("/delete/{id}") + @RequireRole(description = "删除导入字段定义", allowUser = false) + public ApiResponse deleteImportFieldDef( + @Parameter(description = "字段定义ID") @PathVariable Long id) { + importFieldDefService.deleteImportFieldDef(id); + return ApiResponse.success(); + } + + @Operation(summary = "获取指定类型所有字段列表", description = "根据导入类型获取所有字段定义列表") + @GetMapping("/list-by-type/all/{type}") + @RequireRole(description = "获取字段定义列表", allowUser = true) + public ApiResponse> getFieldDefsByType( + @Parameter(description = "导入类型", example = "product") @PathVariable String type) { + List fieldDefVOs = importFieldDefService.getFieldDefsByType(type); + return ApiResponse.success(fieldDefVOs); + } + + @Operation(summary = "分页查询导入字段定义", description = "分页查询导入字段定义,支持条件过滤") + @PostMapping("/page") + @RequireRole(description = "查询导入字段定义列表", allowUser = true) + public ApiResponse> getImportFieldDefPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = importFieldDefService.getImportFieldDefPage(pageQueryDTO); + return ApiResponse.success(result); + } +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportMappingController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportMappingController.java new file mode 100644 index 00000000..6b5fa686 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportMappingController.java @@ -0,0 +1,68 @@ +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 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.importmapping.CreateImportMappingDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping.ImportMappingFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping.UpdateImportMappingDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportMappingVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportMappingService; + +/** + * 导入映射管理控制器 + */ +@Tag(name = "电商-导入映射管理", description = "导入映射的增删改查接口") +@RestController +@RequestMapping("/ec/import-mapping") +public class ImportMappingController { + + private final ImportMappingService importMappingService; + + public ImportMappingController(ImportMappingService importMappingService) { + this.importMappingService = importMappingService; + } + + @Operation(summary = "创建导入映射模板", description = "创建新的导入映射模板") + @PostMapping("/create") + @RequireRole(description = "创建导入映射", allowUser = false) + public ApiResponse createImportMapping(@Valid @RequestBody CreateImportMappingDTO createImportMappingDTO) { + ImportMappingVO importMappingVO = importMappingService.createImportMapping(createImportMappingDTO); + return ApiResponse.success(importMappingVO); + } + + @Operation(summary = "更新导入映射模板", description = "更新现有导入映射模板") + @PutMapping("/update/{id}") + @RequireRole(description = "更新导入映射", allowUser = false) + public ApiResponse updateImportMapping( + @Valid @RequestBody UpdateImportMappingDTO updateImportMappingDTO, + @Parameter(description = "映射ID") @PathVariable Long id) { + ImportMappingVO importMappingVO = importMappingService.updateImportMapping(updateImportMappingDTO, id); + return ApiResponse.success(importMappingVO); + } + + @Operation(summary = "删除导入映射", description = "删除指定导入映射") + @DeleteMapping("/delete/{id}") + @RequireRole(description = "删除导入映射", allowUser = false) + public ApiResponse deleteImportMapping( + @Parameter(description = "映射ID") @PathVariable Long id) { + importMappingService.deleteImportMapping(id); + return ApiResponse.success(); + } + + @Operation(summary = "分页获取导入映射列表", description = "分页获取导入映射列表,支持条件过滤") + @PostMapping("/page") + @RequireRole(description = "查询导入映射列表", allowUser = true) + public ApiResponse> getImportMappingPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = importMappingService.getImportMappingPage(pageQueryDTO); + return ApiResponse.success(result); + } +} + 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 deleted file mode 100644 index db08a425..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportRuleController.java +++ /dev/null @@ -1,113 +0,0 @@ -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/controller/ImportTaskController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportTaskController.java new file mode 100644 index 00000000..9c11994a --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ImportTaskController.java @@ -0,0 +1,47 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import org.springframework.web.bind.annotation.*; +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.importtask.CreateImportTaskDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importtask.ImportTaskFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportTaskVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportTaskService; + +/** + * 导入任务管理控制器 + */ +@Tag(name = "电商-导入任务管理", description = "导入任务的创建和查询接口") +@RestController +@RequestMapping("/ec/import-task") +public class ImportTaskController { + + private final ImportTaskService importTaskService; + + public ImportTaskController(ImportTaskService importTaskService) { + this.importTaskService = importTaskService; + } + + @Operation(summary = "创建导入任务", description = "创建新的导入任务") + @PostMapping("/create") + @RequireRole(description = "创建导入任务", allowUser = false) + public ApiResponse createImportTask(@Valid @RequestBody CreateImportTaskDTO createImportTaskDTO) { + ImportTaskVO importTaskVO = importTaskService.createImportTask(createImportTaskDTO); + return ApiResponse.success(importTaskVO); + } + + @Operation(summary = "分页获取导入任务列表", description = "分页获取导入任务列表,支持条件过滤") + @PostMapping("/page") + @RequireRole(description = "查询导入任务列表", allowUser = true) + public ApiResponse> getImportTaskPage( + @Valid @RequestBody PageQueryDTO pageQueryDTO) { + PageResultVO result = importTaskService.getImportTaskPage(pageQueryDTO); + return ApiResponse.success(result); + } +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ProductController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ProductController.java index 9f1a698d..02a887b1 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ProductController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/controller/ProductController.java @@ -12,7 +12,6 @@ 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.product.CreateProductDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.CreateProductWithSpecsDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.ProductFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.UpdateProductDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ProductVO; @@ -67,14 +66,6 @@ public class ProductController { return ApiResponse.success(result); } - @Operation(summary = "一键创建商品和规格", description = "一次性创建商品和多个规格") - @PostMapping("/create-with-specs") - @RequireRole(description = "一键创建商品和规格", allowUser = false) - public ApiResponse createProductWithSpecs(@Valid @RequestBody CreateProductWithSpecsDTO createProductWithSpecsDTO) { - ProductVO productVO = productService.createProductWithSpecs(createProductWithSpecsDTO); - return ApiResponse.success(productVO); - } - @Operation(summary = "根据名称精准查询商品", description = "根据商品名称精准查询商品信息,用于数据导入") @GetMapping("/find-by-name/{name}") @RequireRole(description = "根据名称查询商品", allowUser = true) diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportFieldDefMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportFieldDefMapper.java new file mode 100644 index 00000000..c046453d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportFieldDefMapper.java @@ -0,0 +1,13 @@ +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.ImportFieldDefPO; + +/** + * 导入字段定义Mapper接口 + */ +@Mapper +public interface ImportFieldDefMapper extends BaseMapper { +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportMappingMapper.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportMappingMapper.java new file mode 100644 index 00000000..d9e14120 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportMappingMapper.java @@ -0,0 +1,13 @@ +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.ImportMappingPO; + +/** + * 导入映射Mapper接口 + */ +@Mapper +public interface ImportMappingMapper extends BaseMapper { +} + 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/ImportTaskMapper.java similarity index 52% rename from ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportRuleMapper.java rename to ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/mapper/ImportTaskMapper.java index eae314e8..683b433a 100644 --- 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/ImportTaskMapper.java @@ -2,11 +2,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; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportTaskPO; /** - * 导入规则Mapper接口 + * 导入任务Mapper接口 */ @Mapper -public interface ImportRuleMapper extends BaseMapper { +public interface ImportTaskMapper extends BaseMapper { } + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/CreateImportFieldDefDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/CreateImportFieldDefDTO.java new file mode 100644 index 00000000..f2887916 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/CreateImportFieldDefDTO.java @@ -0,0 +1,51 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import lombok.Data; + +/** + * 创建导入字段定义DTO + */ +@Data +@Schema(description = "创建导入字段定义DTO") +public class CreateImportFieldDefDTO { + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product", required = true, allowableValues = {"product", "order"}) + @NotBlank(message = "导入类型不能为空") + @Pattern(regexp = "^(product|order)$", message = "导入类型只能是product或order") + private String type; + + /** + * 数据库字段名,如 name + */ + @Schema(description = "数据库字段名", example = "name", required = true) + @NotBlank(message = "字段名不能为空") + private String fieldName; + + /** + * 中文字段名,如 商品名称 + */ + @Schema(description = "中文字段名", example = "商品名称", required = true) + @NotBlank(message = "字段标签不能为空") + private String fieldLabel; + + /** + * 是否必填 + */ + @Schema(description = "是否必填", example = "true") + @NotNull(message = "是否必填不能为空") + private Boolean required; + + /** + * 数据类型(string, number, date等) + */ + @Schema(description = "数据类型", example = "string", defaultValue = "string") + private String dataType; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/ImportFieldDefFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/ImportFieldDefFilterDTO.java new file mode 100644 index 00000000..e8969a29 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/ImportFieldDefFilterDTO.java @@ -0,0 +1,31 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 导入字段定义过滤DTO + */ +@Data +@Schema(description = "导入字段定义过滤DTO") +public class ImportFieldDefFilterDTO { + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product", allowableValues = {"product", "order"}) + private String type; + + /** + * 字段名(模糊查询) + */ + @Schema(description = "字段名(模糊查询)", example = "name") + private String fieldName; + + /** + * 字段标签(模糊查询) + */ + @Schema(description = "字段标签(模糊查询)", example = "商品") + private String fieldLabel; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/UpdateImportFieldDefDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/UpdateImportFieldDefDTO.java new file mode 100644 index 00000000..6d35a62d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importfielddef/UpdateImportFieldDefDTO.java @@ -0,0 +1,35 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef; + +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 UpdateImportFieldDefDTO { + + /** + * 中文字段名,如 商品名称 + */ + @Schema(description = "中文字段名", example = "商品名称", required = true) + @NotBlank(message = "字段标签不能为空") + private String fieldLabel; + + /** + * 是否必填 + */ + @Schema(description = "是否必填", example = "true") + @NotNull(message = "是否必填不能为空") + private Boolean required; + + /** + * 数据类型(string, number, date等) + */ + @Schema(description = "数据类型", example = "string") + private String dataType; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/CreateImportMappingDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/CreateImportMappingDTO.java new file mode 100644 index 00000000..66cb79f2 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/CreateImportMappingDTO.java @@ -0,0 +1,30 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import lombok.Data; + +/** + * 创建导入映射DTO + */ +@Data +@Schema(description = "创建导入映射DTO") +public class CreateImportMappingDTO { + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product", required = true, allowableValues = {"product", "order"}) + @NotBlank(message = "导入类型不能为空") + @Pattern(regexp = "^(product|order)$", message = "导入类型只能是product或order") + private String type; + + /** + * 字段映射(JSON格式) + */ + @Schema(description = "字段映射(JSON格式)", example = "{\"商品名称\":\"name\",\"价格(元)\":\"price\"}", required = true) + @NotBlank(message = "字段映射不能为空") + private String mapping; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/ImportMappingFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/ImportMappingFilterDTO.java new file mode 100644 index 00000000..e3c38911 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/ImportMappingFilterDTO.java @@ -0,0 +1,19 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 导入映射过滤DTO + */ +@Data +@Schema(description = "导入映射过滤DTO") +public class ImportMappingFilterDTO { + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product", allowableValues = {"product", "order"}) + private String type; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/UpdateImportMappingDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/UpdateImportMappingDTO.java new file mode 100644 index 00000000..ce436909 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importmapping/UpdateImportMappingDTO.java @@ -0,0 +1,21 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; + +/** + * 更新导入映射DTO + */ +@Data +@Schema(description = "更新导入映射DTO") +public class UpdateImportMappingDTO { + + /** + * 字段映射(JSON格式) + */ + @Schema(description = "字段映射(JSON格式)", example = "{\"商品名称\":\"name\",\"价格(元)\":\"price\"}", required = true) + @NotBlank(message = "字段映射不能为空") + private String mapping; +} + 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 deleted file mode 100644 index e25fb6cc..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/CreateImportRuleDTO.java +++ /dev/null @@ -1,73 +0,0 @@ -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 deleted file mode 100644 index 2330e32a..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/ImportRuleFilterDTO.java +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index f9fbbc7f..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importrule/UpdateImportRuleDTO.java +++ /dev/null @@ -1,71 +0,0 @@ -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/dto/importtask/CreateImportTaskDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importtask/CreateImportTaskDTO.java new file mode 100644 index 00000000..0f599c32 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importtask/CreateImportTaskDTO.java @@ -0,0 +1,43 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importtask; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import lombok.Data; + +/** + * 创建导入任务DTO + */ +@Data +@Schema(description = "创建导入任务DTO") +public class CreateImportTaskDTO { + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product", required = true, allowableValues = {"product", "order"}) + @NotBlank(message = "导入类型不能为空") + @Pattern(regexp = "^(product|order)$", message = "导入类型只能是product或order") + private String type; + + /** + * 原始文件名 + */ + @Schema(description = "原始文件名", example = "商品导入.xlsx", required = true) + @NotBlank(message = "文件名不能为空") + private String fileName; + + /** + * 存储路径 + */ + @Schema(description = "存储路径", example = "/uploads/import/2025/01/xxx.xlsx", required = true) + @NotBlank(message = "存储路径不能为空") + private String filePath; + + /** + * 字段映射记录(JSON字符串) + */ + @Schema(description = "字段映射记录", example = "{\"商品名称\":\"name\",\"价格\":\"price\"}") + private String mapping; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importtask/ImportTaskFilterDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importtask/ImportTaskFilterDTO.java new file mode 100644 index 00000000..a9175a4b --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/importtask/ImportTaskFilterDTO.java @@ -0,0 +1,31 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importtask; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 导入任务过滤DTO + */ +@Data +@Schema(description = "导入任务过滤DTO") +public class ImportTaskFilterDTO { + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product", allowableValues = {"product", "order"}) + private String type; + + /** + * 任务状态 + */ + @Schema(description = "任务状态", example = "pending", allowableValues = {"pending", "processing", "success", "failed"}) + private String status; + + /** + * 文件名(模糊查询) + */ + @Schema(description = "文件名(模糊查询)", example = "商品") + private String fileName; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/product/CreateProductDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/product/CreateProductDTO.java index 68971050..ee3b0db3 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/product/CreateProductDTO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/product/CreateProductDTO.java @@ -1,9 +1,14 @@ package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product; import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Data; +import java.math.BigDecimal; +import java.util.List; + /** * 创建商品DTO */ @@ -23,4 +28,39 @@ public class CreateProductDTO { */ @Schema(description = "主图图片ID", example = "1") private Long mainImageId; + + /** + * 商品规格列表(可选) + */ + @Schema(description = "商品规格列表") + @Valid + private List specs; + + /** + * 商品规格DTO + */ + @Data + @Schema(description = "商品规格DTO") + public static class ProductSpecDTO { + + /** + * 规格名称 + */ + @Schema(description = "规格名称", example = "128GB 深空黑色", required = true) + @NotBlank(message = "规格名称不能为空") + private String name; + + /** + * 规格编码 + */ + @Schema(description = "规格编码", example = "IPHONE15PRO-128G-BLACK") + private String specCode; + + /** + * 成本价 + */ + @Schema(description = "成本价", example = "8000.00", required = true) + @NotNull(message = "成本价不能为空") + private BigDecimal costPrice; + } } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/product/CreateProductWithSpecsDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/product/CreateProductWithSpecsDTO.java deleted file mode 100644 index 10db55e4..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/dto/product/CreateProductWithSpecsDTO.java +++ /dev/null @@ -1,68 +0,0 @@ -package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product; - -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.Valid; -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.NotNull; -import lombok.Data; - -import java.math.BigDecimal; -import java.util.List; - -/** - * 一键创建商品和规格DTO - */ -@Data -@Schema(description = "一键创建商品和规格DTO") -public class CreateProductWithSpecsDTO { - - /** - * 商品名称 - */ - @Schema(description = "商品名称", example = "iPhone 15 Pro", required = true) - @NotBlank(message = "商品名称不能为空") - private String name; - - /** - * 主图图片ID - */ - @Schema(description = "主图图片ID", example = "1") - private Long mainImageId; - - /** - * 商品规格列表 - */ - @Schema(description = "商品规格列表", required = true) - @NotEmpty(message = "商品规格列表不能为空") - @Valid - private List specs; - - /** - * 商品规格DTO - */ - @Data - @Schema(description = "商品规格DTO") - public static class ProductSpecDTO { - - /** - * 规格名称 - */ - @Schema(description = "规格名称", example = "128GB 深空黑色", required = true) - @NotBlank(message = "规格名称不能为空") - private String name; - - /** - * 规格编码 - */ - @Schema(description = "规格编码", example = "IPHONE15PRO-128G-BLACK") - private String specCode; - - /** - * 成本价 - */ - @Schema(description = "成本价", example = "8000.00", required = true) - @NotNull(message = "成本价不能为空") - private BigDecimal costPrice; - } -} diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportFieldDefPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportFieldDefPO.java new file mode 100644 index 00000000..78d85953 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportFieldDefPO.java @@ -0,0 +1,65 @@ +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_field_defs") +public class ImportFieldDefPO { + + /** + * 字段定义ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 导入类型(product-商品 order-订单) + */ + @TableField("type") + private String type; + + /** + * 数据库字段名,如 name + */ + @TableField("field_name") + private String fieldName; + + /** + * 中文字段名,如 商品名称 + */ + @TableField("field_label") + private String fieldLabel; + + /** + * 是否必填 + */ + @TableField("required") + private Boolean required; + + /** + * 数据类型(string, number, date等) + */ + @TableField("data_type") + private String dataType; + + /** + * 创建时间 + */ + @TableField(value = "created_at", fill = FieldFill.INSERT) + private LocalDateTime createdAt; + + /** + * 更新时间 + */ + @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE) + private LocalDateTime updatedAt; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportMappingPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportMappingPO.java new file mode 100644 index 00000000..ca3923aa --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportMappingPO.java @@ -0,0 +1,65 @@ +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_mappings") +public class ImportMappingPO { + + /** + * 映射ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 所属公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 导入类型(product-商品 order-订单) + */ + @TableField("type") + private String type; + + /** + * 字段映射(JSON格式) + */ + @TableField("mapping") + private String mapping; + + /** + * 创建时间 + */ + @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/po/ImportRulePO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportRulePO.java deleted file mode 100644 index 0adf5310..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportRulePO.java +++ /dev/null @@ -1,106 +0,0 @@ -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/po/ImportTaskPO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportTaskPO.java new file mode 100644 index 00000000..3a3cfff1 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/po/ImportTaskPO.java @@ -0,0 +1,107 @@ +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_tasks") +public class ImportTaskPO { + + /** + * 主键ID + */ + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + /** + * 所属公司ID + */ + @TableField("company_id") + private Long companyId; + + /** + * 导入类型(product-商品 order-订单) + */ + @TableField("type") + private String type; + + /** + * 原始文件名 + */ + @TableField("file_name") + private String fileName; + + /** + * 存储路径 + */ + @TableField("file_path") + private String filePath; + + /** + * 任务状态(pending-待处理 processing-处理中 success-成功 failed-失败) + */ + @TableField("status") + private String status; + + /** + * 总行数 + */ + @TableField("total_count") + private Integer totalCount; + + /** + * 成功行数 + */ + @TableField("success_count") + private Integer successCount; + + /** + * 失败行数 + */ + @TableField("fail_count") + private Integer failCount; + + /** + * 字段映射记录(JSON) + */ + @TableField("mapping") + private String mapping; + + /** + * 错误信息或备注 + */ + @TableField("message") + private String message; + + /** + * 创建时间 + */ + @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/ImportFieldDefVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportFieldDefVO.java new file mode 100644 index 00000000..03e81160 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportFieldDefVO.java @@ -0,0 +1,63 @@ +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 ImportFieldDefVO { + + /** + * 字段定义ID + */ + @Schema(description = "字段定义ID", example = "1") + private Long id; + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product") + private String type; + + /** + * 数据库字段名,如 name + */ + @Schema(description = "数据库字段名", example = "name") + private String fieldName; + + /** + * 中文字段名,如 商品名称 + */ + @Schema(description = "中文字段名", example = "商品名称") + private String fieldLabel; + + /** + * 是否必填 + */ + @Schema(description = "是否必填", example = "true") + private Boolean required; + + /** + * 数据类型(string, number, date等) + */ + @Schema(description = "数据类型", example = "string") + private String dataType; + + /** + * 创建时间 + */ + @Schema(description = "创建时间", example = "2024-01-01T10:00:00") + private LocalDateTime createdAt; + + /** + * 更新时间 + */ + @Schema(description = "更新时间", example = "2024-01-01T10:00:00") + private LocalDateTime updatedAt; +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportMappingVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportMappingVO.java new file mode 100644 index 00000000..b7b1b01d --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportMappingVO.java @@ -0,0 +1,63 @@ +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 ImportMappingVO { + + /** + * 映射ID + */ + @Schema(description = "映射ID", example = "1") + private Long id; + + /** + * 所属公司ID + */ + @Schema(description = "所属公司ID", example = "1") + private Long companyId; + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product") + private String type; + + /** + * 字段映射(JSON格式) + */ + @Schema(description = "字段映射(JSON格式)", example = "{\"商品名称\":\"name\",\"价格(元)\":\"price\"}") + private String mapping; + + /** + * 创建时间 + */ + @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/model/vo/ImportRuleVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportRuleVO.java deleted file mode 100644 index 3e06db36..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportRuleVO.java +++ /dev/null @@ -1,104 +0,0 @@ -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/model/vo/ImportTaskVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportTaskVO.java new file mode 100644 index 00000000..cca54ad6 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/model/vo/ImportTaskVO.java @@ -0,0 +1,105 @@ +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 ImportTaskVO { + + /** + * 主键ID + */ + @Schema(description = "主键ID", example = "1") + private Long id; + + /** + * 所属公司ID + */ + @Schema(description = "所属公司ID", example = "1") + private Long companyId; + + /** + * 导入类型(product-商品 order-订单) + */ + @Schema(description = "导入类型", example = "product") + private String type; + + /** + * 原始文件名 + */ + @Schema(description = "原始文件名", example = "商品导入.xlsx") + private String fileName; + + /** + * 存储路径 + */ + @Schema(description = "存储路径", example = "/uploads/import/2025/01/xxx.xlsx") + private String filePath; + + /** + * 任务状态 + */ + @Schema(description = "任务状态", example = "pending") + private String status; + + /** + * 总行数 + */ + @Schema(description = "总行数", example = "100") + private Integer totalCount; + + /** + * 成功行数 + */ + @Schema(description = "成功行数", example = "95") + private Integer successCount; + + /** + * 失败行数 + */ + @Schema(description = "失败行数", example = "5") + private Integer failCount; + + /** + * 字段映射记录(JSON字符串) + */ + @Schema(description = "字段映射记录", example = "{\"商品名称\":\"name\",\"价格\":\"price\"}") + private String mapping; + + /** + * 错误信息或备注 + */ + @Schema(description = "错误信息或备注", example = "处理完成") + private String message; + + /** + * 创建时间 + */ + @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/ImportFieldDefService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportFieldDefService.java new file mode 100644 index 00000000..76dd4107 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportFieldDefService.java @@ -0,0 +1,59 @@ +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.importfielddef.CreateImportFieldDefDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.ImportFieldDefFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.UpdateImportFieldDefDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportFieldDefPO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportFieldDefVO; + +import java.util.List; + +/** + * 导入字段定义服务接口 + */ +public interface ImportFieldDefService extends IService { + + /** + * 创建导入字段定义 + * + * @param createImportFieldDefDTO 创建导入字段定义DTO + * @return 导入字段定义VO + */ + ImportFieldDefVO createImportFieldDef(CreateImportFieldDefDTO createImportFieldDefDTO); + + /** + * 更新导入字段定义 + * + * @param updateImportFieldDefDTO 更新导入字段定义DTO + * @param id 字段定义ID + * @return 导入字段定义VO + */ + ImportFieldDefVO updateImportFieldDef(UpdateImportFieldDefDTO updateImportFieldDefDTO, Long id); + + /** + * 删除导入字段定义 + * + * @param id 字段定义ID + */ + void deleteImportFieldDef(Long id); + + /** + * 获取指定类型所有字段列表 + * + * @param type 导入类型 + * @return 字段定义VO列表 + */ + List getFieldDefsByType(String type); + + /** + * 分页查询导入字段定义 + * + * @param pageQueryDTO 分页查询DTO + * @return 分页结果 + */ + PageResultVO getImportFieldDefPage(PageQueryDTO pageQueryDTO); +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportMappingService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportMappingService.java new file mode 100644 index 00000000..656c3e14 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportMappingService.java @@ -0,0 +1,49 @@ +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.importmapping.CreateImportMappingDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping.ImportMappingFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping.UpdateImportMappingDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportMappingPO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportMappingVO; + +/** + * 导入映射服务接口 + */ +public interface ImportMappingService extends IService { + + /** + * 创建导入映射模板 + * + * @param createImportMappingDTO 创建导入映射DTO + * @return 导入映射VO + */ + ImportMappingVO createImportMapping(CreateImportMappingDTO createImportMappingDTO); + + /** + * 更新导入映射模板 + * + * @param updateImportMappingDTO 更新导入映射DTO + * @param id 映射ID + * @return 导入映射VO + */ + ImportMappingVO updateImportMapping(UpdateImportMappingDTO updateImportMappingDTO, Long id); + + /** + * 删除导入映射 + * + * @param id 映射ID + */ + void deleteImportMapping(Long id); + + /** + * 分页获取导入映射列表 + * + * @param pageQueryDTO 分页查询DTO + * @return 分页结果 + */ + PageResultVO getImportMappingPage(PageQueryDTO pageQueryDTO); +} + 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 deleted file mode 100644 index 6bbec230..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportRuleService.java +++ /dev/null @@ -1,90 +0,0 @@ -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/ImportTaskService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportTaskService.java new file mode 100644 index 00000000..52ebdfe3 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ImportTaskService.java @@ -0,0 +1,32 @@ +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.importtask.CreateImportTaskDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importtask.ImportTaskFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportTaskPO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportTaskVO; + +/** + * 导入任务服务接口 + */ +public interface ImportTaskService extends IService { + + /** + * 创建导入任务 + * + * @param createImportTaskDTO 创建导入任务DTO + * @return 导入任务VO + */ + ImportTaskVO createImportTask(CreateImportTaskDTO createImportTaskDTO); + + /** + * 分页获取导入任务列表 + * + * @param pageQueryDTO 分页查询DTO + * @return 分页结果 + */ + PageResultVO getImportTaskPage(PageQueryDTO pageQueryDTO); +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ProductService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ProductService.java index 2448ebe1..a37bd200 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ProductService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/ProductService.java @@ -4,7 +4,6 @@ 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.product.CreateProductDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.CreateProductWithSpecsDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.ProductFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.UpdateProductDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ProductPO; @@ -49,14 +48,6 @@ public interface ProductService extends IService { */ PageResultVO getProductPage(PageQueryDTO pageQueryDTO); - /** - * 一键创建商品和规格 - * - * @param createProductWithSpecsDTO 创建商品和规格DTO - * @return 商品VO - */ - ProductVO createProductWithSpecs(CreateProductWithSpecsDTO createProductWithSpecsDTO); - /** * 根据名称精准查询商品 * diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportFieldDefServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportFieldDefServiceImpl.java new file mode 100644 index 00000000..aac5ea64 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportFieldDefServiceImpl.java @@ -0,0 +1,177 @@ +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.ImportFieldDefMapper; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.CreateImportFieldDefDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.ImportFieldDefFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef.UpdateImportFieldDefDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportFieldDefPO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportFieldDefVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportFieldDefService; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 导入字段定义服务实现类 + */ +@Service +public class ImportFieldDefServiceImpl extends ServiceImpl implements ImportFieldDefService { + + /** + * 创建导入字段定义 + * + * @param createImportFieldDefDTO 创建导入字段定义DTO + * @return 导入字段定义VO + */ + @Override + @Transactional + public ImportFieldDefVO createImportFieldDef(CreateImportFieldDefDTO createImportFieldDefDTO) { + // 验证同一类型、同一字段名是否已存在(根据唯一索引) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportFieldDefPO::getType, createImportFieldDefDTO.getType()) + .eq(ImportFieldDefPO::getFieldName, createImportFieldDefDTO.getFieldName()); + if (this.count(wrapper) > 0) { + throw new BusinessException("该类型的字段定义已存在"); + } + + // 创建导入字段定义 + ImportFieldDefPO importFieldDefPO = new ImportFieldDefPO(); + BeanUtils.copyProperties(createImportFieldDefDTO, importFieldDefPO); + + // 设置默认数据类型 + if (!StringUtils.hasText(importFieldDefPO.getDataType())) { + importFieldDefPO.setDataType("string"); + } + + this.save(importFieldDefPO); + + // 转换为VO返回 + return convertToVO(importFieldDefPO); + } + + /** + * 更新导入字段定义 + * + * @param updateImportFieldDefDTO 更新导入字段定义DTO + * @param id 字段定义ID + * @return 导入字段定义VO + */ + @Override + @Transactional + public ImportFieldDefVO updateImportFieldDef(UpdateImportFieldDefDTO updateImportFieldDefDTO, Long id) { + // 验证字段定义是否存在 + ImportFieldDefPO existingFieldDef = this.getById(id); + if (existingFieldDef == null) { + throw new BusinessException("导入字段定义不存在"); + } + + // 更新字段定义 + ImportFieldDefPO importFieldDefPO = new ImportFieldDefPO(); + BeanUtils.copyProperties(updateImportFieldDefDTO, importFieldDefPO); + importFieldDefPO.setId(id); + + this.updateById(importFieldDefPO); + + // 转换为VO返回 + return convertToVO(this.getById(id)); + } + + /** + * 删除导入字段定义 + * + * @param id 字段定义ID + */ + @Override + @Transactional + public void deleteImportFieldDef(Long id) { + // 验证字段定义是否存在 + ImportFieldDefPO existingFieldDef = this.getById(id); + if (existingFieldDef == null) { + throw new BusinessException("导入字段定义不存在"); + } + + // 删除字段定义 + this.removeById(id); + } + + /** + * 获取指定类型所有字段列表 + * + * @param type 导入类型 + * @return 字段定义VO列表 + */ + @Override + public List getFieldDefsByType(String type) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportFieldDefPO::getType, type) + .orderByAsc(ImportFieldDefPO::getFieldName); + + List fieldDefPOs = this.list(wrapper); + + return fieldDefPOs.stream() + .map(this::convertToVO) + .collect(Collectors.toList()); + } + + /** + * 分页查询导入字段定义 + * + * @param pageQueryDTO 分页查询DTO + * @return 分页结果VO + */ + @Override + public PageResultVO getImportFieldDefPage(PageQueryDTO pageQueryDTO) { + ImportFieldDefFilterDTO filter = pageQueryDTO.getFilters(); + + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + + if (filter != null) { + if (StringUtils.hasText(filter.getType())) { + wrapper.eq(ImportFieldDefPO::getType, filter.getType()); + } + if (StringUtils.hasText(filter.getFieldName())) { + wrapper.like(ImportFieldDefPO::getFieldName, filter.getFieldName()); + } + if (StringUtils.hasText(filter.getFieldLabel())) { + wrapper.like(ImportFieldDefPO::getFieldLabel, filter.getFieldLabel()); + } + } + + // 按类型和字段名排序 + wrapper.orderByAsc(ImportFieldDefPO::getType) + .orderByAsc(ImportFieldDefPO::getFieldName); + + // 分页查询 + 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 PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + } + + /** + * 转换为VO + */ + private ImportFieldDefVO convertToVO(ImportFieldDefPO importFieldDefPO) { + ImportFieldDefVO importFieldDefVO = new ImportFieldDefVO(); + BeanUtils.copyProperties(importFieldDefPO, importFieldDefVO); + return importFieldDefVO; + } +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportMappingServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportMappingServiceImpl.java new file mode 100644 index 00000000..1d753361 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportMappingServiceImpl.java @@ -0,0 +1,171 @@ +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.ImportMappingMapper; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping.CreateImportMappingDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping.ImportMappingFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importmapping.UpdateImportMappingDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportMappingPO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportMappingVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportMappingService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 导入映射服务实现类 + */ +@Service +public class ImportMappingServiceImpl extends ServiceImpl implements ImportMappingService { + + private final CurrentUserContext currentUserContext; + + public ImportMappingServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + /** + * 创建导入映射模板 + * + * @param createImportMappingDTO 创建导入映射DTO + * @return 导入映射VO + */ + @Override + @Transactional + public ImportMappingVO createImportMapping(CreateImportMappingDTO createImportMappingDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 验证同一公司、同一类型是否已存在映射(根据唯一索引) + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportMappingPO::getCompanyId, companyId) + .eq(ImportMappingPO::getType, createImportMappingDTO.getType()); + if (this.count(wrapper) > 0) { + throw new BusinessException("该类型的导入映射已存在,请使用更新接口"); + } + + // 创建导入映射 + ImportMappingPO importMappingPO = new ImportMappingPO(); + BeanUtils.copyProperties(createImportMappingDTO, importMappingPO); + importMappingPO.setCompanyId(companyId); + importMappingPO.setCreateBy(currentUserContext.getCurrentUserId()); + + this.save(importMappingPO); + + // 转换为VO返回 + return convertToVO(importMappingPO); + } + + /** + * 更新导入映射模板 + * + * @param updateImportMappingDTO 更新导入映射DTO + * @param id 映射ID + * @return 导入映射VO + */ + @Override + @Transactional + public ImportMappingVO updateImportMapping(UpdateImportMappingDTO updateImportMappingDTO, Long id) { + // 验证映射是否存在 + ImportMappingPO existingMapping = this.getById(id); + if (existingMapping == null) { + throw new BusinessException("导入映射不存在"); + } + + // 验证公司权限 + Long companyId = currentUserContext.getCurrentCompanyId(); + if (!existingMapping.getCompanyId().equals(companyId)) { + throw new BusinessException("无权限操作此映射"); + } + + // 更新映射 + ImportMappingPO importMappingPO = new ImportMappingPO(); + BeanUtils.copyProperties(updateImportMappingDTO, importMappingPO); + importMappingPO.setId(id); + importMappingPO.setUpdateBy(currentUserContext.getCurrentUserId()); + + this.updateById(importMappingPO); + + // 转换为VO返回 + return convertToVO(this.getById(id)); + } + + /** + * 删除导入映射 + * + * @param id 映射ID + */ + @Override + @Transactional + public void deleteImportMapping(Long id) { + // 验证映射是否存在 + ImportMappingPO existingMapping = this.getById(id); + if (existingMapping == null) { + throw new BusinessException("导入映射不存在"); + } + + // 验证公司权限 + Long companyId = currentUserContext.getCurrentCompanyId(); + if (!existingMapping.getCompanyId().equals(companyId)) { + throw new BusinessException("无权限操作此映射"); + } + + // 删除映射 + this.removeById(id); + } + + /** + * 分页获取导入映射列表 + * + * @param pageQueryDTO 分页查询DTO + * @return 分页结果VO + */ + @Override + public PageResultVO getImportMappingPage(PageQueryDTO pageQueryDTO) { + Long companyId = currentUserContext.getCurrentCompanyId(); + ImportMappingFilterDTO filter = pageQueryDTO.getFilters(); + + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportMappingPO::getCompanyId, companyId); + + if (filter != null && StringUtils.hasText(filter.getType())) { + wrapper.eq(ImportMappingPO::getType, filter.getType()); + } + + // 按创建时间倒序 + wrapper.orderByDesc(ImportMappingPO::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 PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + } + + /** + * 转换为VO + */ + private ImportMappingVO convertToVO(ImportMappingPO importMappingPO) { + ImportMappingVO importMappingVO = new ImportMappingVO(); + BeanUtils.copyProperties(importMappingPO, importMappingVO); + return importMappingVO; + } +} + 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 deleted file mode 100644 index 922dfd3b..00000000 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportRuleServiceImpl.java +++ /dev/null @@ -1,298 +0,0 @@ -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; - } - - /** - * 创建导入规则 - * @param createImportRuleDTO 创建导入规则DTO - * @return 导入规则VO - */ - @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); - } - - /** - * 更新导入规则 - * @param updateImportRuleDTO 更新导入规则DTO - * @param id 导入规则ID - * @return 导入规则VO - */ - @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); - } - - /** - * 删除导入规则 - * @param id 导入规则ID - */ - @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); - } - - /** - * 根据ID查询导入规则 - * @param id 导入规则ID - * @return 导入规则VO - */ - @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); - } - - /** - * 获取导入规则分页列表 - * @param pageQueryDTO 分页查询DTO - * @return 分页结果VO - */ - @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()); - } - - /** - * 根据类型查询导入规则 - * @param ruleType 类型 - * @return 导入规则VO列表 - */ - @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()); - } - - /** - * 获取所有启用的导入规则 - * @return 导入规则VO列表 - */ - @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()); - } - - /** - * 根据类型查询启用的导入规则 - * @param ruleType 类型 - * @return 导入规则VO - */ - @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); - } - - /** - * 切换导入规则状态 - * @param id 导入规则ID - * @param isActive 状态 - * @return 导入规则VO - */ - @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/ImportTaskServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportTaskServiceImpl.java new file mode 100644 index 00000000..ee5fae48 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ImportTaskServiceImpl.java @@ -0,0 +1,115 @@ +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.model.dto.PageQueryDTO; +import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; +import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ImportTaskMapper; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importtask.CreateImportTaskDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importtask.ImportTaskFilterDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ImportTaskPO; +import top.xyquan.ecomdmbbackend.modules.ecom.model.vo.ImportTaskVO; +import top.xyquan.ecomdmbbackend.modules.ecom.service.ImportTaskService; +import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 导入任务服务实现类 + */ +@Service +public class ImportTaskServiceImpl extends ServiceImpl implements ImportTaskService { + + private final CurrentUserContext currentUserContext; + + public ImportTaskServiceImpl(CurrentUserContext currentUserContext) { + this.currentUserContext = currentUserContext; + } + + /** + * 创建导入任务 + * + * @param createImportTaskDTO 创建导入任务DTO + * @return 导入任务VO + */ + @Override + @Transactional + public ImportTaskVO createImportTask(CreateImportTaskDTO createImportTaskDTO) { + // 从token中获取公司ID + Long companyId = currentUserContext.getCurrentCompanyId(); + + // 创建导入任务 + ImportTaskPO importTaskPO = new ImportTaskPO(); + BeanUtils.copyProperties(createImportTaskDTO, importTaskPO); + importTaskPO.setCompanyId(companyId); + importTaskPO.setStatus("pending"); // 初始状态为待处理 + importTaskPO.setTotalCount(0); + importTaskPO.setSuccessCount(0); + importTaskPO.setFailCount(0); + importTaskPO.setCreateBy(currentUserContext.getCurrentUserId()); + + this.save(importTaskPO); + + // 转换为VO返回 + return convertToVO(importTaskPO); + } + + /** + * 分页获取导入任务列表 + * + * @param pageQueryDTO 分页查询DTO + * @return 分页结果VO + */ + @Override + public PageResultVO getImportTaskPage(PageQueryDTO pageQueryDTO) { + Long companyId = currentUserContext.getCurrentCompanyId(); + ImportTaskFilterDTO filter = pageQueryDTO.getFilters(); + + // 构建查询条件 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ImportTaskPO::getCompanyId, companyId); + + if (filter != null) { + if (StringUtils.hasText(filter.getType())) { + wrapper.eq(ImportTaskPO::getType, filter.getType()); + } + if (StringUtils.hasText(filter.getStatus())) { + wrapper.eq(ImportTaskPO::getStatus, filter.getStatus()); + } + if (StringUtils.hasText(filter.getFileName())) { + wrapper.like(ImportTaskPO::getFileName, filter.getFileName()); + } + } + + // 按创建时间倒序 + wrapper.orderByDesc(ImportTaskPO::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 PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); + } + + /** + * 转换为VO + */ + private ImportTaskVO convertToVO(ImportTaskPO importTaskPO) { + ImportTaskVO importTaskVO = new ImportTaskVO(); + BeanUtils.copyProperties(importTaskPO, importTaskVO); + return importTaskVO; + } +} + diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ProductServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ProductServiceImpl.java index 12b86ff1..755e65ea 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ProductServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/service/impl/ProductServiceImpl.java @@ -13,7 +13,6 @@ import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO; import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.modules.ecom.mapper.ProductMapper; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.CreateProductDTO; -import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.CreateProductWithSpecsDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.ProductFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.dto.product.UpdateProductDTO; import top.xyquan.ecomdmbbackend.modules.ecom.model.po.ProductPO; @@ -87,6 +86,22 @@ public class ProductServiceImpl extends ServiceImpl im // 保存商品 this.save(product); + // 如果提供了规格列表,则创建商品规格 + if (createProductDTO.getSpecs() != null && !createProductDTO.getSpecs().isEmpty()) { + List specDTOs = createProductDTO.getSpecs(); + for (CreateProductDTO.ProductSpecDTO specDTO : specDTOs) { + ProductSpecPO productSpec = new ProductSpecPO(); + productSpec.setCompanyId(companyId); + productSpec.setProductId(product.getId()); + productSpec.setName(specDTO.getName()); + productSpec.setSpecCode(specDTO.getSpecCode()); + productSpec.setCostPrice(specDTO.getCostPrice()); + productSpec.setCreateBy(currentUserContext.getCurrentUserId()); + + productSpecService.save(productSpec); + } + } + // 转换为VO并返回 return convertToVO(product); } @@ -204,62 +219,6 @@ public class ProductServiceImpl extends ServiceImpl im return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize()); } - /** - * 创建商品并创建商品规格 - * @param createProductWithSpecsDTO 创建商品并创建商品规格DTO - * @return 商品VO - */ - @Override - @Transactional - public ProductVO createProductWithSpecs(CreateProductWithSpecsDTO createProductWithSpecsDTO) { - // 从token中获取公司ID - Long companyId = currentUserContext.getCurrentCompanyId(); - - // 验证商品名称是否重复 - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(ProductPO::getName, createProductWithSpecsDTO.getName()) - .eq(ProductPO::getCompanyId, companyId); - if (this.count(wrapper) > 0) { - throw new BusinessException("商品名称已存在"); - } - - // 创建商品 - ProductPO product = new ProductPO(); - product.setName(createProductWithSpecsDTO.getName()); - product.setCompanyId(companyId); - - // 处理主图图片关联 - if (createProductWithSpecsDTO.getMainImageId() != null) { - MediaImageVO mainImage = mediaImageService.getImageById(createProductWithSpecsDTO.getMainImageId()); - if (mainImage != null) { - product.setMainImageId(createProductWithSpecsDTO.getMainImageId()); - product.setMainImage(mainImage.getUrl()); // 设置冗余字段 - } - } - - // 设置创建人ID - product.setCreateBy(currentUserContext.getCurrentUserId()); - - // 保存商品 - this.save(product); - - // 创建商品规格 - List specDTOs = createProductWithSpecsDTO.getSpecs(); - for (CreateProductWithSpecsDTO.ProductSpecDTO specDTO : specDTOs) { - ProductSpecPO productSpec = new ProductSpecPO(); - productSpec.setCompanyId(companyId); - productSpec.setProductId(product.getId()); - productSpec.setName(specDTO.getName()); - productSpec.setSpecCode(specDTO.getSpecCode()); - productSpec.setCostPrice(specDTO.getCostPrice()); - productSpec.setCreateBy(currentUserContext.getCurrentUserId()); - - productSpecService.save(productSpec); - } - - // 转换为VO并返回 - return convertToVO(product); - } /** * 转换为VO diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyMenuServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyMenuServiceImpl.java index cbc7d07e..fbede11c 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyMenuServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/CompanyMenuServiceImpl.java @@ -279,51 +279,6 @@ public class CompanyMenuServiceImpl extends ServiceImpl(), 0); } - /** - * 构建菜单树(保留原方法用于其他用途) - */ - private List buildMenuTree(List menuList) { - // 按父ID分组 - Map> parentMap = menuList.stream() - .collect(Collectors.groupingBy(menu -> menu.getParentId() != null ? menu.getParentId() : 0L)); - - // 递归构建树 - return buildTreeRecursive(parentMap, 0L, new ArrayList<>(), 0); - } - - /** - * 递归构建树形结构(带循环引用检测) - */ - private List buildTreeRecursive(Map> parentMap, Long parentId, - List visitedIds, int depth) { - // 防止无限递归,设置最大深度限制 - if (depth > 100) { - throw new BusinessException("菜单层级过深,可能存在循环引用"); - } - - List children = parentMap.get(parentId); - if (children == null) { - return new ArrayList<>(); - } - - for (MenuVO menu : children) { - // 检查是否已经访问过该节点,防止循环引用 - if (visitedIds.contains(menu.getId())) { - throw new BusinessException("检测到菜单循环引用,菜单ID: " + menu.getId()); - } - - // 创建新访问路径,包含当前节点 - List newVisitedIds = new ArrayList<>(visitedIds); - newVisitedIds.add(menu.getId()); - - // 递归构建子菜单 - List childList = buildTreeRecursive(parentMap, menu.getId(), newVisitedIds, depth + 1); - menu.setChildren(childList); - } - - return children; - } - /** * 递归构建公司菜单树形结构(带循环引用检测) */ @@ -376,19 +331,6 @@ public class CompanyMenuServiceImpl extends ServiceImpl permissions = menuMapper.selectPermissionsByMenuId(menu.getId()); - menuVO.setPermissions(permissions); - - return menuVO; - } /** * 转换为VO diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionCompanyMenuServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionCompanyMenuServiceImpl.java index 95f57425..047a424d 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionCompanyMenuServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/org/service/impl/PositionCompanyMenuServiceImpl.java @@ -354,6 +354,7 @@ public class PositionCompanyMenuServiceImpl extends ServiceImpl