From 99968f83982943669af3829ea6bc3bbe745cada4 Mon Sep 17 00:00:00 2001
From: zhangfeng <1603559716@qq.com>
Date: 星期一, 21 十一月 2022 08:41:48 +0800
Subject: [PATCH] 安全物资和设备管理相关rpc接口

---
 equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java |  152 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 121 insertions(+), 31 deletions(-)

diff --git a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java
index b71a9eb..c4a001d 100644
--- a/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java
+++ b/equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java
@@ -1,25 +1,27 @@
 package com.gkhy.safePlatform.equipment.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.gkhy.safePlatform.commons.co.ContextCacheUser;
 import com.gkhy.safePlatform.commons.enums.ResultCodes;
-import com.gkhy.safePlatform.commons.utils.StringUtils;
 import com.gkhy.safePlatform.commons.vo.ResultVO;
+import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyDO;
 import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo;
+import com.gkhy.safePlatform.equipment.enums.EquipmentResultCodes;
 import com.gkhy.safePlatform.equipment.excepiton.EquipmentException;
 import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyAddReq;
 import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyModReq;
-import com.gkhy.safePlatform.equipment.model.dto.req.SafeMaterialClassifyQuery;
 import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyDto;
+import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyStockDto;
 import com.gkhy.safePlatform.equipment.service.MaterialClassifyService;
 import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialClassifyInfoService;
 import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialInfoService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service("MaterialClassifyService")
 public class MaterialClassifyServiceImpl implements MaterialClassifyService {
@@ -29,25 +31,50 @@
     private SafeMaterialInfoService safeMaterialInfoService;
 
     @Override
-    public ResultVO<List<SafeMaterialClassifyDto>> list(SafeMaterialClassifyQuery query) {
-        List<SafeMaterialClassifyInfo> list = safeMaterialClassifyInfoService.listByCondition(query);
-        List<SafeMaterialClassifyDto> respList = new ArrayList<>();
-        if(!CollectionUtils.isEmpty(list)){
-            for(SafeMaterialClassifyInfo classifyInfo : list){
-                SafeMaterialClassifyDto respDTO = new SafeMaterialClassifyDto();
-                respDTO.setId(classifyInfo.getId());
-                respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
-                respList.add(respDTO);
+    public List<SafeMaterialClassifyDto> list() {
+        List<SafeMaterialClassifyInfo> list = safeMaterialClassifyInfoService.list();
+        //过滤出父级
+        List<SafeMaterialClassifyInfo> parentList = list
+                .stream()
+                .filter(item -> item.getParentId().equals(0l))
+                .collect(Collectors.toList());
+        List<SafeMaterialClassifyDto> respDTOList = new ArrayList<>();
+        //只有二级不采用递归
+        for (SafeMaterialClassifyInfo classifyInfo:parentList) {
+            SafeMaterialClassifyDto respDTO = new SafeMaterialClassifyDto();
+            respDTO.setId(classifyInfo.getId());
+            respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
+            respDTO.setParentId(classifyInfo.getParentId());
+            List<SafeMaterialClassifyInfo> childList = list
+                    .stream()
+                    .filter(item -> item.getParentId().equals(classifyInfo.getId()))
+                    .collect(Collectors.toList());
+            List<SafeMaterialClassifyDto> childDTOList = new ArrayList<>();
+            for (SafeMaterialClassifyInfo child:childList){
+                SafeMaterialClassifyDto childDTO = new SafeMaterialClassifyDto();
+                childDTO.setId(child.getId());
+                childDTO.setMaterialClassifyName(child.getMaterialClassifyName());
+                childDTO.setParentId(child.getParentId());
+                childDTOList.add(childDTO);
             }
+            respDTO.setChildList(childDTOList);
+            respDTOList.add(respDTO);
         }
-        return new ResultVO<>(ResultCodes.OK,respList);
+
+        return respDTOList;
     }
 
     @Override
     public ResultVO save(ContextCacheUser currentUser, SafeMaterialClassifyAddReq req) {
         ResultVO resultVO = null;
+
         SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
         classifyInfo.setMaterialClassifyName(req.getMaterialClassifyName());
+        if(null != req.getParentId()){
+            classifyInfo.setParentId(req.getParentId());
+        }else{
+            classifyInfo.setParentId(0l);
+        }
         boolean flag = safeMaterialClassifyInfoService.save(classifyInfo);
         if (flag){
             resultVO = new ResultVO(ResultCodes.OK);
@@ -80,35 +107,98 @@
         if(id == null){
             throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
         }
-        ResultVO resultVO = null;
-        //判断是否被绑定
-        int count = safeMaterialInfoService.getCountByClassify(id);
-        if(count > 0){
-            throw new EquipmentException(ResultCodes.SERVER_DEL_ERROR,"该类型已被绑定,不可删除!");
-        }else{
-            //如果没有被绑定,逻辑删除
-            SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
-            classifyInfo.setId(id);
-            classifyInfo.setDelFlag(1);
-            boolean flag = safeMaterialClassifyInfoService.updateById(classifyInfo);
-            if (flag){
-                resultVO = new ResultVO(ResultCodes.OK);
-            }else {
-                resultVO = new ResultVO(ResultCodes.SERVER_DEL_ERROR);
+        SafeMaterialClassifyInfo classify = safeMaterialClassifyInfoService.queryById(id);
+        if(null == classify){
+            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
+        }
+        if(0 == classify.getParentId()){//一级
+            List<SafeMaterialClassifyInfo> childrenList = safeMaterialClassifyInfoService.getListByParentId(id);
+            if (childrenList.size()>0){
+                throw new EquipmentException(ResultCodes.SERVER_DEL_ERROR,"改类型存在小类,不可删除!");
+            }
+        }else {//二级
+            //判断是否被绑定
+            int count = safeMaterialInfoService.getCountBySmallClassifyId(id);
+            if(count > 0){
+                throw new EquipmentException(ResultCodes.SERVER_DEL_ERROR,"该类型已被绑定,不可删除!");
             }
         }
-        return  resultVO;
+        //如果没有被绑定,逻辑删除
+        SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo();
+        classifyInfo.setId(id);
+        classifyInfo.setDelFlag(1);
+        safeMaterialClassifyInfoService.updateById(classifyInfo);
+
+        return new ResultVO(ResultCodes.OK);
     }
 
     @Override
-    public ResultVO<SafeMaterialClassifyDto> queryById(Long id) {
+    public SafeMaterialClassifyDto queryById(Long id) {
         if(id == null){
             throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
         }
         SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(id);
+        if(null == classifyInfo){
+            throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST);
+        }
+        List<SafeMaterialClassifyInfo> childList = new ArrayList<>();
+        if(0l ==  classifyInfo.getParentId()){
+            childList = safeMaterialClassifyInfoService.getListByParentId(id);
+        }
         SafeMaterialClassifyDto respDTO = new SafeMaterialClassifyDto();
         respDTO.setId(classifyInfo.getId());
         respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName());
-        return new ResultVO<>(ResultCodes.OK,respDTO);
+        respDTO.setParentId(classifyInfo.getParentId());
+        List<SafeMaterialClassifyDto> childDtoList = new ArrayList<>();
+        for (SafeMaterialClassifyInfo child:childList){
+            SafeMaterialClassifyDto childDto = new SafeMaterialClassifyDto();
+            childDto.setId(child.getId());
+            childDto.setMaterialClassifyName(child.getMaterialClassifyName());
+            childDto.setParentId(child.getParentId());
+            childDtoList.add(childDto);
+        }
+        respDTO.setChildList(childDtoList);
+        return respDTO;
     }
+
+    /**
+     * 根据小类id获取大小类相关信息
+     * @param smallClassifyId
+     * @return
+     */
+    public SafeMaterialClassifyDO getBigAndSmallClassifyInfo(Long smallClassifyId){
+        if(null == smallClassifyId){
+            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
+        }
+        SafeMaterialClassifyDO classifyDO = safeMaterialClassifyInfoService.getBigAndSmallClassify(smallClassifyId);
+        return classifyDO;
+    }
+    /**
+     * 根据小类ids获取小类相关信息
+     * @param ids
+     * @return
+     */
+    public List<SafeMaterialClassifyDto> getClassifyListByIds(List<Long> ids){
+        if(CollectionUtils.isEmpty(ids)){
+            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
+        }
+        List<SafeMaterialClassifyInfo> list = safeMaterialClassifyInfoService.getClassifyListByIds(ids);
+        List<SafeMaterialClassifyDto> classifyDtoList = new ArrayList<>();
+        for (SafeMaterialClassifyInfo classifyInfo:list){
+            SafeMaterialClassifyDto classifyDto = new SafeMaterialClassifyDto();
+            BeanUtils.copyProperties(classifyInfo,classifyDto);
+            classifyDtoList.add(classifyDto);
+        }
+        return classifyDtoList;
+    }
+
+    @Override
+    public List<SafeMaterialClassifyDO> getTraceabilityClassifyList(List<Long> smallClassifyIds) {
+        if(CollectionUtils.isEmpty(smallClassifyIds)){
+            throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL);
+        }
+        return safeMaterialClassifyInfoService.getTraceabilityClassifyList(smallClassifyIds);
+    }
+
+
 }

--
Gitblit v1.9.2