mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 02:39:19 +08:00
wip: 数据导入
This commit is contained in:
+9
@@ -9,6 +9,7 @@ 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.BatchSortImportFieldDefDTO;
|
||||
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;
|
||||
@@ -75,5 +76,13 @@ public class ImportFieldDefController {
|
||||
PageResultVO<ImportFieldDefVO> result = importFieldDefService.getImportFieldDefPage(pageQueryDTO);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "批量排序导入字段定义", description = "批量更新导入字段定义的排序值")
|
||||
@PostMapping("/batch-sort")
|
||||
@RequireRole(description = "批量排序导入字段定义", allowUser = false)
|
||||
public ApiResponse<Void> batchSortImportFieldDef(@Valid @RequestBody BatchSortImportFieldDefDTO batchSortDTO) {
|
||||
importFieldDefService.batchSortImportFieldDef(batchSortDTO);
|
||||
return ApiResponse.success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ecom.model.dto.importfielddef;
|
||||
|
||||
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 = "排序项列表", required = true)
|
||||
@Valid
|
||||
@NotNull(message = "排序项列表不能为空")
|
||||
private List<FieldDefSortItem> sortItems;
|
||||
|
||||
/**
|
||||
* 字段定义排序项
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "字段定义排序项")
|
||||
public static class FieldDefSortItem {
|
||||
|
||||
/**
|
||||
* 字段定义ID
|
||||
*/
|
||||
@Schema(description = "字段定义ID", example = "1", required = true)
|
||||
@NotNull(message = "字段定义ID不能为空")
|
||||
private Long fieldDefId;
|
||||
|
||||
/**
|
||||
* 排序值
|
||||
*/
|
||||
@Schema(description = "排序值", example = "0", required = true)
|
||||
@NotNull(message = "排序值不能为空")
|
||||
@Min(value = 0, message = "排序值不能小于0")
|
||||
private Integer sort;
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class CreateImportFieldDefDTO {
|
||||
@NotNull(message = "是否必填不能为空")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
|
||||
+6
@@ -26,6 +26,12 @@ public class UpdateImportFieldDefDTO {
|
||||
@NotNull(message = "是否必填不能为空")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
|
||||
+6
@@ -44,6 +44,12 @@ public class ImportFieldDefPO {
|
||||
@TableField("required")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
|
||||
+6
@@ -42,6 +42,12 @@ public class ImportFieldDefVO {
|
||||
@Schema(description = "是否必填", example = "true")
|
||||
private Boolean required;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@Schema(description = "排序", example = "0")
|
||||
private Integer sort;
|
||||
|
||||
/**
|
||||
* 数据类型(string, number, date等)
|
||||
*/
|
||||
|
||||
+8
@@ -3,6 +3,7 @@ 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.BatchSortImportFieldDefDTO;
|
||||
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;
|
||||
@@ -55,5 +56,12 @@ public interface ImportFieldDefService extends IService<ImportFieldDefPO> {
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<ImportFieldDefVO> getImportFieldDefPage(PageQueryDTO<ImportFieldDefFilterDTO> pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 批量排序导入字段定义
|
||||
*
|
||||
* @param batchSortDTO 批量排序DTO
|
||||
*/
|
||||
void batchSortImportFieldDef(BatchSortImportFieldDefDTO batchSortDTO);
|
||||
}
|
||||
|
||||
|
||||
+28
-1
@@ -12,6 +12,7 @@ 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.BatchSortImportFieldDefDTO;
|
||||
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;
|
||||
@@ -53,6 +54,11 @@ public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper,
|
||||
if (!StringUtils.hasText(importFieldDefPO.getDataType())) {
|
||||
importFieldDefPO.setDataType("string");
|
||||
}
|
||||
|
||||
// 设置默认排序值
|
||||
if (importFieldDefPO.getSort() == null) {
|
||||
importFieldDefPO.setSort(0);
|
||||
}
|
||||
|
||||
this.save(importFieldDefPO);
|
||||
|
||||
@@ -115,6 +121,7 @@ public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper,
|
||||
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);
|
||||
@@ -149,8 +156,9 @@ public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper,
|
||||
}
|
||||
}
|
||||
|
||||
// 按类型和字段名排序
|
||||
// 按类型、排序和字段名排序
|
||||
wrapper.orderByAsc(ImportFieldDefPO::getType)
|
||||
.orderByAsc(ImportFieldDefPO::getSort)
|
||||
.orderByAsc(ImportFieldDefPO::getFieldName);
|
||||
|
||||
// 分页查询
|
||||
@@ -165,6 +173,25 @@ public class ImportFieldDefServiceImpl extends ServiceImpl<ImportFieldDefMapper,
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -244,6 +244,7 @@ CREATE TABLE `ec_import_field_defs` (
|
||||
`field_name` varchar(100) NOT NULL COMMENT '数据库字段名,如 name',
|
||||
`field_label` varchar(100) NOT NULL COMMENT '中文字段名,如 商品名称',
|
||||
`required` tinyint(1) DEFAULT 0 COMMENT '是否必填',
|
||||
`sort` int unsigned DEFAULT 0 COMMENT '排序',
|
||||
`data_type` varchar(50) DEFAULT 'string' COMMENT 'string, number, date等',
|
||||
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
Reference in New Issue
Block a user