| | |
| | | ResultVO resultVO = null; |
| | | //获取部门信息 |
| | | DepInfoRPCRespDTO depInfo = getDepInfoByDepId(req.getDepId()); |
| | | |
| | | if(null == ConsumableEnum.getByCode(req.getConsumable())){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"耗材类型不合法!"); |
| | | } |
| | | //获取物资类型 |
| | | SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(req.getMaterialClassifyId()); |
| | | SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(req.getSmallClassifyId()); |
| | | if(null == classifyInfo){ |
| | | throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"物资类型不存在!"); |
| | | } |
| | | //判断该部门是否已经创建物资 |
| | | boolean flag = safeMaterialInfoService.checkMaterial(req.getSmallClassifyId(), req.getDepId(), null); |
| | | if(flag){ |
| | | throw new EquipmentException(EquipmentResultCodes.DATA_EXIST,"该种物资已存在不可重复创建"); |
| | | } |
| | | |
| | | //获取数量 |
| | | int safeMaterialTotalCount = safeMaterialInfoService.getTotalCount(); |
| | | SafeMaterialInfo safeMaterialInfo = new SafeMaterialInfo(); |
| | | BeanUtils.copyProperties(req,safeMaterialInfo); |
| | | safeMaterialInfo.setConsumable(req.getConsumable()); |
| | | safeMaterialInfo.setDepId(req.getDepId()); |
| | | safeMaterialInfo.setSmallClassifyId(req.getSmallClassifyId()); |
| | | safeMaterialInfo.setMaterialName(classifyInfo.getMaterialClassifyName()); |
| | | safeMaterialInfo.setDepName(depInfo.getDepName()); |
| | | safeMaterialInfo.setSerialNum(this.generateSerialNum(safeMaterialTotalCount)); |
| | | safeMaterialInfo.setBigClassifyId(req.getBigClassifyId()); |
| | | //插入 |
| | | boolean flag = safeMaterialInfoService.save(safeMaterialInfo); |
| | | if(flag){ |
| | | resultVO = new ResultVO(ResultCodes.OK); |
| | | }else { |
| | | resultVO = new ResultVO(ResultCodes.SERVER_ADD_ERROR); |
| | | } |
| | | safeMaterialInfoService.save(safeMaterialInfo); |
| | | |
| | | return resultVO; |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | |
| | | @Override |
| | |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"耗材类型不合法!"); |
| | | } |
| | | //获取物资类型 |
| | | SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(req.getMaterialClassifyId()); |
| | | SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(req.getSmallClassifyId()); |
| | | if(null == classifyInfo){ |
| | | throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST,"物资类型不存在!"); |
| | | } |
| | | SafeMaterialInfo safeMaterialInfo = new SafeMaterialInfo(); |
| | | BeanUtils.copyProperties(req,safeMaterialInfo); |
| | | safeMaterialInfo.setDepName(depInfo.getDepName()); |
| | | //跟新 |
| | | boolean flag = safeMaterialInfoService.updateById(safeMaterialInfo); |
| | | boolean flag = safeMaterialInfoService.checkMaterial(req.getSmallClassifyId(), req.getDepId(), req.getDepId()); |
| | | if(flag){ |
| | | resultVO = new ResultVO(ResultCodes.OK); |
| | | }else { |
| | | resultVO = new ResultVO(ResultCodes.SERVER_UPDATE_ERROR); |
| | | throw new EquipmentException(EquipmentResultCodes.DATA_EXIST,"该种物资已存在不可重复创建"); |
| | | } |
| | | SafeMaterialInfo safeMaterialInfo = new SafeMaterialInfo(); |
| | | safeMaterialInfo.setConsumable(req.getConsumable()); |
| | | safeMaterialInfo.setDepId(req.getDepId()); |
| | | safeMaterialInfo.setSmallClassifyId(req.getSmallClassifyId()); |
| | | safeMaterialInfo.setMaterialName(classifyInfo.getMaterialClassifyName()); |
| | | safeMaterialInfo.setDepName(depInfo.getDepName()); |
| | | safeMaterialInfo.setBigClassifyId(req.getBigClassifyId()); |
| | | //跟新 |
| | | safeMaterialInfoService.updateById(safeMaterialInfo); |
| | | |
| | | return resultVO; |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | |
| | | @Override |
| | |
| | | SafeMaterialInfo safeMaterialInfo = safeMaterialInfoService.queryById(id); |
| | | SafeMaterialDto safeMaterialDto = new SafeMaterialDto(); |
| | | if(null != safeMaterialInfo){ |
| | | SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(safeMaterialInfo.getMaterialClassifyId()); |
| | | SafeMaterialClassifyDO classifyDO = safeMaterialClassifyInfoService.getBigAndSmallClassify(safeMaterialInfo.getSmallClassifyId()); |
| | | Integer validStockCount = safeMaterialDetailInfoService.getValidStockCount(safeMaterialInfo.getId()); |
| | | BeanUtils.copyProperties(safeMaterialInfo,safeMaterialDto); |
| | | safeMaterialDto.setConsumable(ConsumableEnum.getByCode(safeMaterialInfo.getConsumable()).getCode()); |
| | | if(null != classifyInfo){ |
| | | safeMaterialDto.setMaterialClassifyName(classifyInfo.getMaterialClassifyName()); |
| | | safeMaterialDto.setConsumableName(ConsumableEnum.getByCode(safeMaterialInfo.getConsumable()).getValue()); |
| | | if(null != classifyDO){ |
| | | safeMaterialDto.setBigClassifyName(classifyDO.getBigClassifyName()); |
| | | } |
| | | safeMaterialDto.setValidStockCount(validStockCount); |
| | | |
| | |
| | | List<DepRPCRespDTO> depInfoList = getDepInfoList(); |
| | | //获取所有物资类型 |
| | | List<SafeMaterialClassifyInfo> classifyInfoList = safeMaterialClassifyInfoService.getList(); |
| | | //循环物资分类 |
| | | List<MaterialClassificationDto> classificationDtoList = new ArrayList<>(); |
| | | for (SafeMaterialClassifyInfo classifyInfo:classifyInfoList){ |
| | | MaterialClassificationDto classificationDto = new MaterialClassificationDto(); |
| | | classificationDto.setMaterialClassifyId(classifyInfo.getId()); |
| | | classificationDto.setMaterialClassifyName(classifyInfo.getMaterialClassifyName()); |
| | | //循环部门 |
| | | List<MaterialDepartmentDto> departmentDtoList = new ArrayList<>(); |
| | | for (DepRPCRespDTO dep:depInfoList){ |
| | | //循环部门 |
| | | List<MaterialDepartmentDto> departmentDtoList = new ArrayList<>(); |
| | | recursiveDep(depInfoList,departmentDtoList,materialInfoList,classifyInfoList); |
| | | |
| | | return new ResultVO(ResultCodes.OK,departmentDtoList); |
| | | } |
| | | private void recursiveDep(List<DepRPCRespDTO> depInfoList,List<MaterialDepartmentDto> departmentDtoList,List<SafeMaterialInfo> materialInfoList,List<SafeMaterialClassifyInfo> classifyInfoList){ |
| | | for (DepRPCRespDTO dep:depInfoList){ |
| | | MaterialDepartmentDto materialDepartmentDto = new MaterialDepartmentDto(); |
| | | materialDepartmentDto.setDepId(dep.getDepId()); |
| | | materialDepartmentDto.setDepName(dep.getDepName()); |
| | | List<MaterialClassificationDto> classificationDtoList = new ArrayList<>(); |
| | | for (SafeMaterialClassifyInfo classifyInfo:classifyInfoList) { |
| | | MaterialClassificationDto classificationDto = new MaterialClassificationDto(); |
| | | classificationDto.setMaterialClassifyName(classifyInfo.getMaterialClassifyName()); |
| | | classificationDto.setMaterialClassifyId(classifyInfo.getId()); |
| | | //过滤出物资数据 |
| | | List<SafeMaterialInfo> selectMaterialList = materialInfoList |
| | | .stream() |
| | | .filter(item -> classifyInfo.getId().equals(item.getMaterialClassifyId()) && dep.getDepId().equals(item.getDepId())) |
| | | .filter(item -> classifyInfo.getId().equals(item.getBigClassifyId()) && dep.getDepId().equals(item.getDepId())) |
| | | .collect(Collectors.toList()); |
| | | List<BaseMaterialDto> baseMaterialDtoList = new ArrayList<>(); |
| | | if(selectMaterialList.size()>0){ |
| | | //填充部门数据 |
| | | MaterialDepartmentDto departmentDto = new MaterialDepartmentDto(); |
| | | departmentDto.setDepId(dep.getDepId()); |
| | | departmentDto.setDepName(dep.getDepName()); |
| | | |
| | | List<BaseMaterialDto> baseMaterialDtoList = new ArrayList<>(); |
| | | //循环物资 |
| | | for (SafeMaterialInfo materialInfo:selectMaterialList){ |
| | | //填充基础物资数据 |
| | |
| | | baseMaterialDto.setSmId(materialInfo.getId()); |
| | | baseMaterialDtoList.add(baseMaterialDto); |
| | | } |
| | | departmentDto.setBaseMaterialList(baseMaterialDtoList); |
| | | departmentDtoList.add(departmentDto); |
| | | } |
| | | //子集部门 |
| | | if(!CollectionUtils.isEmpty(dep.getChildren())){ |
| | | this.recursiveDep(dep.getChildren(),departmentDtoList,materialInfoList,classifyInfo.getId()); |
| | | classificationDto.setBaseMaterialList(baseMaterialDtoList); |
| | | classificationDtoList.add(classificationDto); |
| | | } |
| | | } |
| | | classificationDto.setDepartmentList(departmentDtoList); |
| | | classificationDtoList.add(classificationDto); |
| | | } |
| | | |
| | | return new ResultVO(ResultCodes.OK,classificationDtoList); |
| | | } |
| | | private void recursiveDep(List<DepRPCRespDTO> depList,List<MaterialDepartmentDto> departmentDtoList,List<SafeMaterialInfo> materialInfoList,Long classifyId){ |
| | | for(DepRPCRespDTO dep:depList){ |
| | | //过滤出物资数据 |
| | | List<SafeMaterialInfo> selectMaterialList = materialInfoList |
| | | .stream() |
| | | .filter(item -> classifyId.equals(item.getMaterialClassifyId()) && dep.getDepId().equals(item.getDepId())) |
| | | .collect(Collectors.toList()); |
| | | if(selectMaterialList.size()>0){ |
| | | //填充部门数据 |
| | | MaterialDepartmentDto departmentDto = new MaterialDepartmentDto(); |
| | | departmentDto.setDepId(dep.getDepId()); |
| | | departmentDto.setDepName(dep.getDepName()); |
| | | |
| | | List<BaseMaterialDto> baseMaterialDtoList = new ArrayList<>(); |
| | | //循环物资 |
| | | for (SafeMaterialInfo materialInfo:selectMaterialList){ |
| | | //填充基础物资数据 |
| | | BaseMaterialDto baseMaterialDto = new BaseMaterialDto(); |
| | | baseMaterialDto.setMaterialName(materialInfo.getMaterialName()); |
| | | baseMaterialDto.setSmId(materialInfo.getId()); |
| | | baseMaterialDtoList.add(baseMaterialDto); |
| | | } |
| | | departmentDto.setBaseMaterialList(baseMaterialDtoList); |
| | | departmentDtoList.add(departmentDto); |
| | | if(classificationDtoList.size()>0){ |
| | | materialDepartmentDto.setClassificationList(classificationDtoList); |
| | | departmentDtoList.add(materialDepartmentDto); |
| | | } |
| | | //子集 |
| | | //子集部门 |
| | | if(!CollectionUtils.isEmpty(dep.getChildren())){ |
| | | this.recursiveDep(dep.getChildren(),departmentDtoList,materialInfoList,classifyId); |
| | | this.recursiveDep(dep.getChildren(),departmentDtoList,materialInfoList,classifyInfoList); |
| | | } |
| | | } |
| | | } |