标准分类模块开发
This commit is contained in:
@@ -28,6 +28,12 @@ public class StandardCategoryController {
|
||||
return standardCategoryService.getList(standardCategoryDto);
|
||||
}
|
||||
|
||||
@PostMapping("/tree")
|
||||
public ResponseResult tree(@RequestBody StandardCategoryQueDto standardCategoryDto) {
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
return standardCategoryService.getTree(standardCategoryDto, userId);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseResult add(@RequestBody @Validated StandardCategoryDto standardCategoryDto) {
|
||||
return standardCategoryService.add(standardCategoryDto);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.dc.dc_project.model.vo;
|
||||
|
||||
|
||||
import com.dc.dc_project.model.TreeNode;
|
||||
import com.dc.dc_project.model.pojo.StandardCategory;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class StandardCategoryVo implements TreeNode<StandardCategoryVo> {
|
||||
|
||||
/**
|
||||
* 上级分类ID
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 分类名称(如水利、电力、公路等)
|
||||
*/
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 分类编码(可用于同步外部标准库)
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private Integer sortOrder;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
private List<StandardCategoryVo> children;
|
||||
|
||||
public static StandardCategoryVo poToVo(StandardCategory standardCategory){
|
||||
StandardCategoryVo standardCategoryVo = new StandardCategoryVo();
|
||||
standardCategoryVo.setId(standardCategory.getId());
|
||||
standardCategoryVo.setName(standardCategory.getName());
|
||||
standardCategoryVo.setCode(standardCategory.getCode());
|
||||
standardCategoryVo.setSortOrder(standardCategory.getSortOrder());
|
||||
standardCategoryVo.setRemark(standardCategory.getRemark());
|
||||
standardCategoryVo.setParentId(standardCategory.getParentId());
|
||||
return standardCategoryVo;
|
||||
}
|
||||
}
|
||||
@@ -45,4 +45,13 @@ public interface StandardCategoryService extends IService<StandardCategory> {
|
||||
* @return
|
||||
**/
|
||||
ResponseResult updateStandardCategory(StandardCategoryUpdateDto standardCategoryDto);
|
||||
|
||||
/**
|
||||
* 获取标准分类树
|
||||
* @param standardCategoryDto
|
||||
* @param userId
|
||||
* @
|
||||
* @return
|
||||
**/
|
||||
ResponseResult getTree(StandardCategoryQueDto standardCategoryDto, Long userId);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,15 @@ import com.dc.dc_project.model.dto.StandardCategoryDto;
|
||||
import com.dc.dc_project.model.dto.StandardCategoryQueDto;
|
||||
import com.dc.dc_project.model.dto.StandardCategoryUpdateDto;
|
||||
import com.dc.dc_project.model.pojo.StandardCategory;
|
||||
import com.dc.dc_project.model.vo.StandardCategoryVo;
|
||||
import com.dc.dc_project.service.StandardCategoryService;
|
||||
import com.dc.dc_project.mapper.StandardCategoryMapper;
|
||||
import com.dc.dc_project.utils.TreeUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author ADMIN
|
||||
@@ -106,6 +109,17 @@ public class StandardCategoryServiceImpl extends ServiceImpl<StandardCategoryMap
|
||||
}
|
||||
return ResponseResult.success("修改成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseResult getTree(StandardCategoryQueDto standardCategoryDto, Long userId) {
|
||||
LambdaQueryWrapper<StandardCategory> queryWrapper = new LambdaQueryWrapper<StandardCategory>()
|
||||
.eq(StandardCategory::getIsDeleted, 0)
|
||||
.eq(standardCategoryDto.getId() != null, StandardCategory::getId, standardCategoryDto.getId())
|
||||
.like(standardCategoryDto.getName() != null, StandardCategory::getName, standardCategoryDto.getName());
|
||||
List<StandardCategory> list = this.list(queryWrapper);
|
||||
List<StandardCategoryVo> tree = TreeUtil.buildTree(list.stream().map(StandardCategoryVo::poToVo).collect(Collectors.toList()));
|
||||
return ResponseResult.success(tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user