From f7d2f20365467a834188edd35c464d9fb9349214 Mon Sep 17 00:00:00 2001 From: zhangfeng <1603559716@qq.com> Date: 星期五, 23 十二月 2022 08:53:43 +0800 Subject: [PATCH] 安全物资和设备管理调整v2 --- equipment/equipment-service/src/main/java/com/gkhy/safePlatform/equipment/service/impl/MaterialClassifyServiceImpl.java | 78 ++++++++++++++++++++++++++++++++------ 1 files changed, 65 insertions(+), 13 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 735b542..d7ec1ce 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,5 +1,6 @@ package com.gkhy.safePlatform.equipment.service.impl; +import cn.hutool.core.util.IdUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gkhy.safePlatform.commons.co.ContextCacheUser; import com.gkhy.safePlatform.commons.enums.ResultCodes; @@ -9,9 +10,11 @@ import com.gkhy.safePlatform.commons.vo.SearchResultVO; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyDO; import com.gkhy.safePlatform.equipment.entity.SafeMaterialClassifyInfo; +import com.gkhy.safePlatform.equipment.enums.ConsumableEnum; import com.gkhy.safePlatform.equipment.enums.EquipmentResultCodes; import com.gkhy.safePlatform.equipment.excepiton.EquipmentException; import com.gkhy.safePlatform.equipment.model.dto.req.MaterialClassifyQuery; +import com.gkhy.safePlatform.equipment.model.dto.req.ParamForm; 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.resp.SafeMaterialClassifyDto; @@ -43,6 +46,7 @@ .stream() .filter(item -> item.getParentId().equals(0l)) .collect(Collectors.toList()); + List<SafeMaterialClassifyDto> respDTOList = new ArrayList<>(); //只有二级不采用递归 for (SafeMaterialClassifyInfo classifyInfo:parentList) { @@ -59,6 +63,10 @@ SafeMaterialClassifyDto childDTO = new SafeMaterialClassifyDto(); childDTO.setId(child.getId()); childDTO.setMaterialClassifyName(child.getMaterialClassifyName()); + if(null != child.getConsumable()){ + childDTO.setConsumableName(ConsumableEnum.getByCode(child.getConsumable()).getValue()); + } + childDTO.setConsumable(child.getConsumable()); childDTO.setParentId(child.getParentId()); childDTOList.add(childDTO); } @@ -72,14 +80,25 @@ @Override public ResultVO save(ContextCacheUser currentUser, SafeMaterialClassifyAddReq req) { ResultVO resultVO = null; + if(null != req.getParentId()){ + if(null == req.getConsumable()){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"是否耗材未选择"); + } + if(null == ConsumableEnum.getByCode(req.getConsumable())){ + throw new EquipmentException(EquipmentResultCodes.DATA_ILLEGAL); + } + } SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo(); + classifyInfo.setId(IdUtil.getSnowflake(0,0).nextId()); classifyInfo.setMaterialClassifyName(req.getMaterialClassifyName()); + classifyInfo.setConsumable(req.getConsumable()); if(null != req.getParentId()){ classifyInfo.setParentId(req.getParentId()); }else{ classifyInfo.setParentId(0l); } + boolean flag = safeMaterialClassifyInfoService.save(classifyInfo); if (flag){ resultVO = new ResultVO(ResultCodes.OK); @@ -95,8 +114,19 @@ if(req.getId() == null){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); } + SafeMaterialClassifyInfo safeMaterialClassifyInfo = safeMaterialClassifyInfoService.queryById(req.getId()); + if(safeMaterialClassifyInfo.getParentId() != 0 ){ + if(null == req.getConsumable()){ + throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"是否耗材未选择"); + } + if(null == ConsumableEnum.getByCode(req.getConsumable())){ + throw new EquipmentException(EquipmentResultCodes.DATA_ILLEGAL); + } + } + SafeMaterialClassifyInfo classifyInfo = new SafeMaterialClassifyInfo(); classifyInfo.setMaterialClassifyName(req.getMaterialClassifyName()); + classifyInfo.setConsumable(req.getConsumable()); classifyInfo.setId(req.getId()); boolean flag = safeMaterialClassifyInfoService.updateById(classifyInfo); if (flag){ @@ -108,7 +138,7 @@ } @Override - public ResultVO delete(Long id) { + public ResultVO delete(ContextCacheUser currentUser,Long id) { if(id == null){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); } @@ -138,7 +168,7 @@ } @Override - public SafeMaterialClassifyDto queryById(Long id) { + public SafeMaterialClassifyDto queryById(ContextCacheUser currentUser,Long id) { if(id == null){ throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); } @@ -154,12 +184,18 @@ respDTO.setId(classifyInfo.getId()); respDTO.setMaterialClassifyName(classifyInfo.getMaterialClassifyName()); respDTO.setParentId(classifyInfo.getParentId()); + respDTO.setConsumable(classifyInfo.getConsumable()); + respDTO.setConsumableName(ConsumableEnum.getByCode(classifyInfo.getConsumable()).getValue()); 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()); + childDto.setConsumable(child.getConsumable()); + if(null != child.getConsumable()){ + childDto.setConsumableName(ConsumableEnum.getByCode(child.getConsumable()).getValue()); + } childDtoList.add(childDto); } respDTO.setChildList(childDtoList); @@ -206,25 +242,39 @@ } @Override - public SearchResultVO<List<SafeMaterialClassifyDto>> listByPage(PageQuery<MaterialClassifyQuery> pageQuery) { + public SearchResultVO<List<SafeMaterialClassifyDto>> listByPage(ContextCacheUser currentUser,PageQuery<MaterialClassifyQuery> pageQuery) { Page<SafeMaterialClassifyInfo> page = new Page<>(pageQuery.getPageIndex(),pageQuery.getPageSize()); - List<SafeMaterialClassifyInfo> classifyInfoList = safeMaterialClassifyInfoService.listByPage(page, pageQuery.getSearchParams()); + List<SafeMaterialClassifyInfo> parentList = safeMaterialClassifyInfoService.listByPage(page, pageQuery.getSearchParams()); List<SafeMaterialClassifyInfo> childList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(classifyInfoList)) { - List<Long> parentIdList = classifyInfoList.stream().map(SafeMaterialClassifyInfo::getId).collect(Collectors.toList()); + if(!CollectionUtils.isEmpty(parentList)){ + List<Long> parentIdList = parentList.stream().map(SafeMaterialClassifyInfo::getId).collect(Collectors.toList()); childList = safeMaterialClassifyInfoService.getListByParentIds(parentIdList); } + List<SafeMaterialClassifyDto> respList = new ArrayList<>(); - for(SafeMaterialClassifyInfo classifyInfo:classifyInfoList){ + for(SafeMaterialClassifyInfo parentClassify:parentList){ SafeMaterialClassifyDto classifyDto = new SafeMaterialClassifyDto(); - classifyDto.setId(classifyInfo.getId()); - classifyDto.setMaterialClassifyName(classifyInfo.getMaterialClassifyName()); - classifyDto.setParentId(classifyInfo.getParentId()); + classifyDto.setId(parentClassify.getId()); + classifyDto.setMaterialClassifyName(parentClassify.getMaterialClassifyName()); + classifyDto.setParentId(parentClassify.getParentId()); + //获取子级 - List<SafeMaterialClassifyInfo> selectList = childList.stream().filter(cl -> cl.getParentId().equals(classifyInfo.getId())).collect(Collectors.toList()); + List<SafeMaterialClassifyInfo> selectList = childList + .stream() + .filter(cl -> cl.getParentId().equals(parentClassify.getId())) + .collect(Collectors.toList()); + List<SafeMaterialClassifyDto> childRespList = new ArrayList<>(); - if(selectList.size()>0){ - childRespList = BeanCopyUtils.copyBeanList(selectList,SafeMaterialClassifyDto.class); + for(SafeMaterialClassifyInfo child:selectList){ + SafeMaterialClassifyDto childClassify = new SafeMaterialClassifyDto(); + childClassify.setId(child.getId()); + childClassify.setMaterialClassifyName(child.getMaterialClassifyName()); + childClassify.setParentId(child.getParentId()); + childClassify.setConsumable(child.getConsumable()); + if(null != child.getConsumable()){ + childClassify.setConsumableName(ConsumableEnum.getByCode(child.getConsumable()).getValue()); + } + childRespList.add(childClassify); } classifyDto.setChildList(childRespList); respList.add(classifyDto); @@ -239,4 +289,6 @@ } + + } -- Gitblit v1.9.2