mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
refactor: 删除动态导入字段定义模块(importfielddef),已由 OrderFieldVO 硬编码替代
- 删除后端 importfielddef 整个模块(controller/service/mapper/model) - 删除前端 import-field-def API 模块 - 删除前端 system/field 字段管理 CRUD 页面及路由 - ImportMappingFormModal 改用 getOrderFieldsApi
This commit is contained in:
-87
@@ -1,87 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.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.RequirePermission;
|
||||
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.importfielddef.model.dto.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.UpdateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.vo.ImportFieldDefVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.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")
|
||||
@RequirePermission(value = "data:import", description = "创建导入字段定义", allowSuper = true)
|
||||
public ApiResponse<ImportFieldDefVO> createImportFieldDef(@Valid @RequestBody CreateImportFieldDefDTO createImportFieldDefDTO) {
|
||||
ImportFieldDefVO importFieldDefVO = importFieldDefService.createImportFieldDef(createImportFieldDefDTO);
|
||||
return ApiResponse.success("导入字段定义创建成功", importFieldDefVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新导入字段定义", description = "更新现有导入字段定义")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "data:import", description = "更新导入字段定义", allowSuper = true)
|
||||
public ApiResponse<ImportFieldDefVO> 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}")
|
||||
@RequirePermission(value = "data:import", description = "删除导入字段定义", allowSuper = true)
|
||||
public ApiResponse<Void> deleteImportFieldDef(
|
||||
@Parameter(description = "字段定义ID") @PathVariable Long id) {
|
||||
importFieldDefService.deleteImportFieldDef(id);
|
||||
return ApiResponse.success("导入字段定义删除成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "获取指定类型所有字段列表", description = "根据导入类型获取所有字段定义列表")
|
||||
@GetMapping("/all/{type}")
|
||||
@RequirePermission(value = "data:import", description = "获取字段定义列表", allowSuper = true)
|
||||
public ApiResponse<List<ImportFieldDefVO>> getFieldDefsByType(
|
||||
@Parameter(description = "导入类型", example = "product") @PathVariable String type) {
|
||||
List<ImportFieldDefVO> fieldDefVOs = importFieldDefService.getFieldDefsByType(type);
|
||||
return ApiResponse.success("获取字段定义列表成功", fieldDefVOs);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询导入字段定义", description = "分页查询导入字段定义,支持条件过滤")
|
||||
@PostMapping("/list")
|
||||
@RequirePermission(value = "data:import", description = "查询导入字段定义列表", allowSuper = true)
|
||||
public ApiResponse<PageResultVO<ImportFieldDefVO>> getImportFieldDefPage(
|
||||
@Valid @RequestBody PageQueryDTO<ImportFieldDefFilterDTO> pageQueryDTO) {
|
||||
PageResultVO<ImportFieldDefVO> result = importFieldDefService.getImportFieldDefPage(pageQueryDTO);
|
||||
return ApiResponse.success("获取导入字段定义列表成功", result);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量排序导入字段定义", description = "批量更新导入字段定义的排序值")
|
||||
@PostMapping("/batch-sort")
|
||||
@RequirePermission(value = "data:import", description = "批量排序导入字段定义", allowSuper = true)
|
||||
public ApiResponse<Void> batchSortImportFieldDef(@Valid @RequestBody BatchSortImportFieldDefDTO batchSortDTO) {
|
||||
importFieldDefService.batchSortImportFieldDef(batchSortDTO);
|
||||
return ApiResponse.success("批量排序成功");
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.po.ImportFieldDefPO;
|
||||
|
||||
/**
|
||||
* 导入字段定义Mapper接口
|
||||
*/
|
||||
@Mapper
|
||||
public interface ImportFieldDefMapper extends BaseMapper<ImportFieldDefPO> {
|
||||
}
|
||||
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.Min;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 批量导入字段定义排序DTO
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "批量导入字段定义排序DTO")
|
||||
public class BatchSortImportFieldDefDTO {
|
||||
|
||||
/**
|
||||
* 排序项列表
|
||||
*/
|
||||
@Schema(description = "排序项列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Valid
|
||||
@NotNull(message = "排序项列表不能为空")
|
||||
private List<FieldDefSortItem> sortItems;
|
||||
|
||||
/**
|
||||
* 字段定义排序项
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "字段定义排序项")
|
||||
public static class FieldDefSortItem {
|
||||
|
||||
/**
|
||||
* 字段定义ID
|
||||
*/
|
||||
@Schema(description = "字段定义ID", example = "1", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "字段定义ID不能为空")
|
||||
private Long fieldDefId;
|
||||
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
@Schema(description = "排序值", example = "0", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "排序值不能为空")
|
||||
@Min(value = 0, message = "排序值不能小于0")
|
||||
private Integer sort;
|
||||
}
|
||||
}
|
||||
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto;
|
||||
|
||||
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", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"product", "order"})
|
||||
@NotBlank(message = "导入类型不能为空")
|
||||
@Pattern(regexp = "^(product|order)$", message = "导入类型只能是product或order")
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 数据库字段名,如 name
|
||||
*/
|
||||
@Schema(description = "数据库字段名", example = "name", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "字段名不能为空")
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 中文字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "中文字段名", example = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "字段标签不能为空")
|
||||
private String fieldLabel;
|
||||
|
||||
/**
|
||||
* 文件字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "文件字段名", example = "商品名称")
|
||||
private String fileFieldName;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@Schema(description = "是否必填", example = "true")
|
||||
@NotNull(message = "是否必填不能为空")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
@Schema(description = "数据类型", example = "string", defaultValue = "string")
|
||||
private String dataType;
|
||||
}
|
||||
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto;
|
||||
|
||||
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 = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "字段标签不能为空")
|
||||
private String fieldLabel;
|
||||
|
||||
/**
|
||||
* 文件字段名,如 商品名称
|
||||
*/
|
||||
@Schema(description = "文件字段名", example = "商品名称")
|
||||
private String fileFieldName;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@Schema(description = "是否必填", example = "true")
|
||||
@NotNull(message = "是否必填不能为空")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
@Schema(description = "数据类型", example = "string")
|
||||
private String dataType;
|
||||
}
|
||||
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.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("file_field_name")
|
||||
private String fileFieldName;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@TableField("required")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(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;
|
||||
}
|
||||
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.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 = "商品名称")
|
||||
private String fileFieldName;
|
||||
|
||||
/**
|
||||
* 是否必填
|
||||
*/
|
||||
@Schema(description = "是否必填", example = "true")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(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;
|
||||
}
|
||||
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.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.importfielddef.model.dto.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.UpdateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.po.ImportFieldDefPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.vo.ImportFieldDefVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 导入字段定义服务接口
|
||||
*/
|
||||
public interface ImportFieldDefService extends IService<ImportFieldDefPO> {
|
||||
|
||||
/**
|
||||
* 创建导入字段定义
|
||||
*
|
||||
* @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<ImportFieldDefVO> getFieldDefsByType(String type);
|
||||
|
||||
/**
|
||||
* 分页查询导入字段定义
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<ImportFieldDefVO> getImportFieldDefPage(PageQueryDTO<ImportFieldDefFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 批量排序导入字段定义
|
||||
*
|
||||
* @param batchSortDTO 批量排序DTO
|
||||
*/
|
||||
void batchSortImportFieldDef(BatchSortImportFieldDefDTO batchSortDTO);
|
||||
}
|
||||
|
||||
-204
@@ -1,204 +0,0 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.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.importfielddef.mapper.ImportFieldDefMapper;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.BatchSortImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.CreateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.ImportFieldDefFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.dto.UpdateImportFieldDefDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.po.ImportFieldDefPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.model.vo.ImportFieldDefVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.importfielddef.service.ImportFieldDefService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 导入字段定义服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper, ImportFieldDefPO> implements ImportFieldDefService {
|
||||
|
||||
/**
|
||||
* 创建导入字段定义
|
||||
*
|
||||
* @param createImportFieldDefDTO 创建导入字段定义DTO
|
||||
* @return 导入字段定义VO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public ImportFieldDefVO createImportFieldDef(CreateImportFieldDefDTO createImportFieldDefDTO) {
|
||||
// 验证同一类型、同一字段名是否已存在(根据唯一索引)
|
||||
LambdaQueryWrapper<ImportFieldDefPO> 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");
|
||||
}
|
||||
|
||||
// 设置默认排序值
|
||||
if (importFieldDefPO.getSort() == null) {
|
||||
importFieldDefPO.setSort(0);
|
||||
}
|
||||
|
||||
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<ImportFieldDefVO> getFieldDefsByType(String type) {
|
||||
LambdaQueryWrapper<ImportFieldDefPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ImportFieldDefPO::getType, type)
|
||||
.orderByAsc(ImportFieldDefPO::getSort)
|
||||
.orderByAsc(ImportFieldDefPO::getFieldName);
|
||||
|
||||
List<ImportFieldDefPO> fieldDefPOs = this.list(wrapper);
|
||||
|
||||
return fieldDefPOs.stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询导入字段定义
|
||||
*
|
||||
* @param pageQueryDTO 分页查询DTO
|
||||
* @return 分页结果VO
|
||||
*/
|
||||
@Override
|
||||
public PageResultVO<ImportFieldDefVO> getImportFieldDefPage(PageQueryDTO<ImportFieldDefFilterDTO> pageQueryDTO) {
|
||||
ImportFieldDefFilterDTO filter = pageQueryDTO.getFilters();
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<ImportFieldDefPO> 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::getSort)
|
||||
.orderByAsc(ImportFieldDefPO::getFieldName);
|
||||
|
||||
// 分页查询
|
||||
Page<ImportFieldDefPO> page = new Page<>(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
IPage<ImportFieldDefPO> pageResult = this.page(page, wrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<ImportFieldDefVO> voList = pageResult.getRecords().stream()
|
||||
.map(this::convertToVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return PageResultVO.create(voList, pageResult.getTotal(), pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量排序导入字段定义
|
||||
*
|
||||
* @param batchSortDTO 批量排序DTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void batchSortImportFieldDef(BatchSortImportFieldDefDTO batchSortDTO) {
|
||||
for (BatchSortImportFieldDefDTO.FieldDefSortItem sortItem : batchSortDTO.getSortItems()) {
|
||||
ImportFieldDefPO fieldDefPO = this.getById(sortItem.getFieldDefId());
|
||||
if (fieldDefPO == null) {
|
||||
throw new BusinessException("字段定义不存在,ID:" + sortItem.getFieldDefId());
|
||||
}
|
||||
|
||||
fieldDefPO.setSort(sortItem.getSort());
|
||||
this.updateById(fieldDefPO);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为VO
|
||||
*/
|
||||
private ImportFieldDefVO convertToVO(ImportFieldDefPO importFieldDefPO) {
|
||||
ImportFieldDefVO importFieldDefVO = new ImportFieldDefVO();
|
||||
BeanUtils.copyProperties(importFieldDefPO, importFieldDefVO);
|
||||
return importFieldDefVO;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user