| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | .stream() |
| | | .filter(item -> item.getParentId().equals(0l)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<SafeMaterialClassifyDto> respDTOList = new ArrayList<>(); |
| | | //只有二级不采用递归 |
| | | for (SafeMaterialClassifyInfo classifyInfo:parentList) { |
| | |
| | | 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); |
| | | } |
| | |
| | | @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); |
| | |
| | | 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){ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResultVO delete(Long id) { |
| | | public ResultVO delete(ContextCacheUser currentUser,Long id) { |
| | | if(id == null){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public SafeMaterialClassifyDto queryById(Long id) { |
| | | public SafeMaterialClassifyDto queryById(ContextCacheUser currentUser,Long id) { |
| | | if(id == null){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); |
| | | } |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | @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); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |