|
|
|
@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryListReqVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryListReqVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryRespVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryRespVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategorySaveReqVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategorySaveReqVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryTreeRespVO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.category.ErpProductCategoryTypeGroupRespVO;
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
|
|
|
|
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductCategoryService;
|
|
|
|
import cn.iocoder.yudao.module.erp.service.product.ErpProductCategoryService;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
@ -21,7 +23,10 @@ import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
@ -77,10 +82,28 @@ public class ErpProductCategoryController {
|
|
|
|
return success(BeanUtils.toBean(list, ErpProductCategoryRespVO.class));
|
|
|
|
return success(BeanUtils.toBean(list, ErpProductCategoryRespVO.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/group-tree")
|
|
|
|
|
|
|
|
@Operation(summary = "按类型分组获得产品分类树")
|
|
|
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('erp:product-category:query')")
|
|
|
|
|
|
|
|
public CommonResult<List<ErpProductCategoryTypeGroupRespVO>> getProductCategoryGroupTree(@Valid ErpProductCategoryListReqVO listReqVO) {
|
|
|
|
|
|
|
|
List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO);
|
|
|
|
|
|
|
|
Map<Integer, List<ErpProductCategoryDO>> typeMap = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
for (ErpProductCategoryDO category : list) {
|
|
|
|
|
|
|
|
typeMap.computeIfAbsent(category.getType(), key -> new ArrayList<>()).add(category);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<ErpProductCategoryTypeGroupRespVO> result = new ArrayList<>();
|
|
|
|
|
|
|
|
for (Map.Entry<Integer, List<ErpProductCategoryDO>> entry : typeMap.entrySet()) {
|
|
|
|
|
|
|
|
ErpProductCategoryTypeGroupRespVO group = new ErpProductCategoryTypeGroupRespVO();
|
|
|
|
|
|
|
|
group.setType(entry.getKey());
|
|
|
|
|
|
|
|
group.setChildren(buildCategoryTree(entry.getValue()));
|
|
|
|
|
|
|
|
result.add(group);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return success(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/simple-list")
|
|
|
|
@GetMapping("/simple-list")
|
|
|
|
@Operation(summary = "获得产品分类精简列表", description = "只包含被开启的分类,主要用于前端的下拉选项")
|
|
|
|
@Operation(summary = "获得产品分类精简列表", description = "只包含被开启的分类,主要用于前端的下拉选项")
|
|
|
|
public CommonResult<List<ErpProductCategoryRespVO>> getProductCategorySimpleList(@RequestParam("type") Integer type) {
|
|
|
|
public CommonResult<List<ErpProductCategoryRespVO>> getProductCategorySimpleList(@RequestParam("type") Integer type) {
|
|
|
|
List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(
|
|
|
|
List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(
|
|
|
|
new ErpProductCategoryListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()).setType(type));
|
|
|
|
new ErpProductCategoryListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus()).setType(type));
|
|
|
|
return success(convertList(list, category -> new ErpProductCategoryRespVO()
|
|
|
|
return success(convertList(list, category -> new ErpProductCategoryRespVO()
|
|
|
|
@ -92,11 +115,33 @@ public class ErpProductCategoryController {
|
|
|
|
@PreAuthorize("@ss.hasPermission('erp:product-category:export')")
|
|
|
|
@PreAuthorize("@ss.hasPermission('erp:product-category:export')")
|
|
|
|
@ApiAccessLog(operateType = EXPORT)
|
|
|
|
@ApiAccessLog(operateType = EXPORT)
|
|
|
|
public void exportProductCategoryExcel(@Valid ErpProductCategoryListReqVO listReqVO,
|
|
|
|
public void exportProductCategoryExcel(@Valid ErpProductCategoryListReqVO listReqVO,
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO);
|
|
|
|
List<ErpProductCategoryDO> list = productCategoryService.getProductCategoryList(listReqVO);
|
|
|
|
// 导出 Excel
|
|
|
|
|
|
|
|
ExcelUtils.write(response, "产品分类.xls", "数据", ErpProductCategoryRespVO.class,
|
|
|
|
ExcelUtils.write(response, "产品分类.xls", "数据", ErpProductCategoryRespVO.class,
|
|
|
|
BeanUtils.toBean(list, ErpProductCategoryRespVO.class));
|
|
|
|
BeanUtils.toBean(list, ErpProductCategoryRespVO.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<ErpProductCategoryTreeRespVO> buildCategoryTree(List<ErpProductCategoryDO> categories) {
|
|
|
|
|
|
|
|
Map<Long, ErpProductCategoryTreeRespVO> nodeMap = new LinkedHashMap<>();
|
|
|
|
|
|
|
|
for (ErpProductCategoryDO category : categories) {
|
|
|
|
|
|
|
|
ErpProductCategoryTreeRespVO node = BeanUtils.toBean(category, ErpProductCategoryTreeRespVO.class);
|
|
|
|
|
|
|
|
node.setChildren(new ArrayList<>());
|
|
|
|
|
|
|
|
node.setLeaf(true);
|
|
|
|
|
|
|
|
nodeMap.put(category.getId(), node);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<ErpProductCategoryTreeRespVO> roots = new ArrayList<>();
|
|
|
|
|
|
|
|
for (ErpProductCategoryDO category : categories) {
|
|
|
|
|
|
|
|
ErpProductCategoryTreeRespVO node = nodeMap.get(category.getId());
|
|
|
|
|
|
|
|
Long parentId = category.getParentId();
|
|
|
|
|
|
|
|
ErpProductCategoryTreeRespVO parent = parentId == null ? null : nodeMap.get(parentId);
|
|
|
|
|
|
|
|
if (parent == null || ErpProductCategoryDO.PARENT_ID_ROOT.equals(parentId)) {
|
|
|
|
|
|
|
|
roots.add(node);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
parent.getChildren().add(node);
|
|
|
|
|
|
|
|
parent.setLeaf(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return roots;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|