| | |
| | | import com.gkhy.safePlatform.equipment.enums.*; |
| | | import com.gkhy.safePlatform.equipment.excepiton.EquipmentException; |
| | | import com.gkhy.safePlatform.equipment.model.dto.req.*; |
| | | import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialClassifyStockDto; |
| | | import com.gkhy.safePlatform.equipment.model.dto.resp.SafeMaterialDetailDto; |
| | | import com.gkhy.safePlatform.equipment.model.dto.resp.SafeRfidMaterialDetailDto; |
| | | import com.gkhy.safePlatform.equipment.mq.msg.SafeMaterialMsg; |
| | | import com.gkhy.safePlatform.equipment.service.SafeMaterialDetailService; |
| | | import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialClassifyInfoService; |
| | |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.ZonedDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("SafeMaterialDetailService") |
| | |
| | | String rfid = "0000000".substring(0,(8 - countStr.length()))+countStr; |
| | | SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo(); |
| | | materialDetailInfo.setId(IdUtil.getSnowflake(0,0).nextId()); |
| | | materialDetailInfo.setMaterialClassifyId(materialInfo.getMaterialClassifyId()); |
| | | materialDetailInfo.setName(materialInfo.getMaterialName()+"(ID"+materialInfo.getId()+")"); |
| | | materialDetailInfo.setBigClassifyId(materialInfo.getBigClassifyId()); |
| | | materialDetailInfo.setSmallClassifyId(materialInfo.getSmallClassifyId()); |
| | | materialDetailInfo.setName(materialInfo.getMaterialName()); |
| | | materialDetailInfo.setSmId(req.getSmId()); |
| | | materialDetailInfo.setConsumable(materialInfo.getConsumable()); |
| | | materialDetailInfo.setValidType(req.getValidType()); |
| | |
| | | for(int i = 0;i < req.getWareHousingCount();i++){ |
| | | SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo(); |
| | | materialDetailInfo.setId(IdUtil.getSnowflake(0,0).nextId()); |
| | | materialDetailInfo.setMaterialClassifyId(materialInfo.getMaterialClassifyId()); |
| | | materialDetailInfo.setName(materialInfo.getMaterialName()+"(ID"+materialInfo.getId()+")"); |
| | | materialDetailInfo.setBigClassifyId(materialInfo.getBigClassifyId()); |
| | | materialDetailInfo.setSmallClassifyId(materialInfo.getSmallClassifyId()); |
| | | materialDetailInfo.setName(materialInfo.getMaterialName()); |
| | | materialDetailInfo.setSmId(req.getSmId()); |
| | | materialDetailInfo.setConsumable(materialInfo.getConsumable()); |
| | | materialDetailInfo.setValidType(req.getValidType()); |
| | |
| | | for(int i = 0;i < req.getWareHousingCount();i++){ |
| | | SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo(); |
| | | materialDetailInfo.setId(IdUtil.getSnowflake(0,0).nextId()); |
| | | materialDetailInfo.setMaterialClassifyId(materialInfo.getMaterialClassifyId()); |
| | | materialDetailInfo.setName(materialInfo.getMaterialName()+"(ID"+materialInfo.getId()+")"); |
| | | materialDetailInfo.setBigClassifyId(materialInfo.getBigClassifyId()); |
| | | materialDetailInfo.setSmallClassifyId(materialInfo.getSmallClassifyId()); |
| | | materialDetailInfo.setName(materialInfo.getMaterialName()); |
| | | materialDetailInfo.setSmId(req.getSmId()); |
| | | materialDetailInfo.setConsumable(materialInfo.getConsumable()); |
| | | materialDetailInfo.setValidType(req.getValidType()); |
| | |
| | | List<SafeMaterialDetailInfo> list = safeMaterialDetailInfoService.getListByIds(idList); |
| | | List<SafeMaterialDetailInfo> selectList = list |
| | | .stream() |
| | | .filter(item -> item.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode())) |
| | | .filter(item -> item.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()) && item.getConsumable().equals(ConsumableEnum.YES.getCode())) |
| | | .collect(Collectors.toList()); |
| | | if(selectList.size() != ids.length){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"已入库物资不可重复入库!"); |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"已入库或耗材物资不可重复入库!"); |
| | | } |
| | | //修改为入库状态 |
| | | safeMaterialDetailInfoService.updateReceiptStatusByIds(idList,IssueReceiptEnum.IN_THE_LIBRARY.getCode()); |
| | |
| | | @Override |
| | | public ResultVO deliveryBatchRandom(MterialRandomDeliveryReq req) { |
| | | UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); |
| | | List<Long> idList = new ArrayList<>(); |
| | | if(StringUtils.isNotBlank(req.getRfid())){ |
| | | idList = safeMaterialDetailInfoService.getIdListByRfid(req.getCount(),req.getSmId(),req.getRfid()); |
| | | |
| | | }else{ |
| | | idList = safeMaterialDetailInfoService.getRfidNullList(req.getCount(), req.getSmId()); |
| | | |
| | | } |
| | | if(idList.size()< req.getCount()){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"有效库存数量不足!"); |
| | | } |
| | | //获取有效数量 |
| | | Integer validStockCount = safeMaterialDetailInfoService.getValidStockCount(req.getSmId()); |
| | | if(req.getCount() > validStockCount){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"出库数量不可大于有效库存数量!"); |
| | | } |
| | | |
| | | SafeMaterialDetailBO detailBO = new SafeMaterialDetailBO(); |
| | | detailBO.setCount(req.getCount()); |
| | | detailBO.setClaimantName(userInfo.getUsername()); |
| | | detailBO.setClaimantId(req.getClaimantId()); |
| | | safeMaterialDetailInfoService.deliveryBatchRandom(detailBO); |
| | | detailBO.setIds(idList); |
| | | safeMaterialDetailInfoService.updateDeliveryStatusByIds(detailBO); |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | |
| | | /** |
| | | * 特殊作业物资出库 |
| | | * @param req |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void deliveryBatchSpw(MaterialSpwReq req) { |
| | | //验证 |
| | | if(null == req.getClaimantId()){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"认领人不可为空!"); |
| | | } |
| | | List<MaterialSpwDeliveryReq> deliveryReqList = req.getDeliveryReqList(); |
| | | if(CollectionUtils.isEmpty(deliveryReqList)){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"出库物资不可为空!"); |
| | | } |
| | | //获取小类物资 |
| | | List<Long> smallClassifyIds = deliveryReqList |
| | | .stream() |
| | | .map(MaterialSpwDeliveryReq::getSmallClassifyId) |
| | | .collect(Collectors.toList()); |
| | | List<Long> depIds = deliveryReqList |
| | | .stream() |
| | | .map(MaterialSpwDeliveryReq::getDepId) |
| | | .collect(Collectors.toList()); |
| | | if(smallClassifyIds.size() == 0 || depIds.size() == 0){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"部门/仓库或者物资类型(小类)不可为空!"); |
| | | } |
| | | |
| | | List<SafeMaterialClassifyStockDO> classifyStockList= safeMaterialDetailInfoService.getSmallClassifyStockByIds(smallClassifyIds); |
| | | //根据物资种类获取有效在库物资 |
| | | List<SafeMaterialDetailDO> listBySmallClassifyIds = safeMaterialDetailInfoService.getListBySmallClassifyIds(smallClassifyIds,depIds); |
| | | |
| | | for(MaterialSpwDeliveryReq deliveryReq:deliveryReqList){ |
| | | if(null == deliveryReq.getDepId()){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"部门或仓库不可为空!"); |
| | | } |
| | | if(null == deliveryReq.getCount()){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"出库数量不可为空!"); |
| | | } |
| | | if(null == deliveryReq.getSmallClassifyId()){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL,"物资类型(小类)不可为空!"); |
| | | } |
| | | List<SafeMaterialClassifyStockDO> collect = classifyStockList |
| | | .stream() |
| | | .filter(cs -> cs.getSmallClassifyId().equals(deliveryReq.getSmallClassifyId()) && cs.getDepId().equals(deliveryReq.getDepId()) && cs.getStockCount() >= deliveryReq.getCount()) |
| | | .collect(Collectors.toList()); |
| | | if(collect.size() == 0){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"库存不足!"); |
| | | } |
| | | } |
| | | UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); |
| | | List<Long> ids = new ArrayList<>(); |
| | | //循环数据 |
| | | for(MaterialSpwDeliveryReq deliveryReq:deliveryReqList){ |
| | | //过滤出rfid存在的数据 |
| | | List<SafeMaterialDetailDO> selectRfidNotNull = listBySmallClassifyIds |
| | | .stream() |
| | | .filter(item -> null != item.getRfid() && item.getSmallClassifyId().equals(deliveryReq.getSmallClassifyId()) && item.getDepId().equals(deliveryReq.getDepId())) |
| | | .collect(Collectors.toList()); |
| | | List<Long> selectIds = new ArrayList<>(); |
| | | if(selectRfidNotNull.size()>0){ |
| | | selectIds = selectRfidNotNull |
| | | .stream() |
| | | .map(SafeMaterialDetailDO::getId) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | if(selectRfidNotNull.size() >= deliveryReq.getCount()){ |
| | | ids.addAll(selectIds.subList(0,deliveryReq.getCount())); |
| | | }else{ |
| | | ids.addAll(selectIds); |
| | | List<SafeMaterialDetailDO> selectRfidIsNull = listBySmallClassifyIds |
| | | .stream() |
| | | .filter(item -> null == item.getRfid() && item.getSmallClassifyId().equals(deliveryReq.getSmallClassifyId()) && item.getDepId().equals(deliveryReq.getDepId())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | List<Long> collect = selectRfidIsNull.subList(0,deliveryReq.getCount()-selectRfidNotNull.size()).stream().map(SafeMaterialDetailDO::getId) |
| | | .collect(Collectors.toList()); |
| | | ids.addAll(collect); |
| | | } |
| | | } |
| | | SafeMaterialDetailBO detailBO = new SafeMaterialDetailBO(); |
| | | detailBO.setClaimantName(userInfo.getUsername()); |
| | | detailBO.setClaimantId(req.getClaimantId()); |
| | | detailBO.setIds(ids); |
| | | safeMaterialDetailInfoService.updateDeliveryStatusByIds(detailBO); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据rfid获取数据信息 |
| | | * @param rfids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<SafeRfidMaterialDetailDto> getListByRfids(List<String> rfids) { |
| | | if(CollectionUtils.isEmpty(rfids)){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); |
| | | } |
| | | List<SafeMaterialDetailInfoDO> listByRfid = safeMaterialDetailInfoService.getListByRfids(rfids); |
| | | List<SafeRfidMaterialDetailDto> rfidMaterialDetailDtoList = new ArrayList<>(); |
| | | for (SafeMaterialDetailInfoDO detailInfoDO:listByRfid){ |
| | | SafeRfidMaterialDetailDto detailDto = new SafeRfidMaterialDetailDto(); |
| | | detailDto.setId(detailInfoDO.getId()); |
| | | detailDto.setName(detailInfoDO.getName()); |
| | | detailDto.setBigClassifyId(detailInfoDO.getBigClassifyId()); |
| | | detailDto.setSmallClassifyId(detailInfoDO.getSmallClassifyId()); |
| | | detailDto.setDepId(detailInfoDO.getDepId()); |
| | | rfidMaterialDetailDtoList.add(detailDto); |
| | | } |
| | | return rfidMaterialDetailDtoList; |
| | | } |
| | | |
| | | @Override |
| | |
| | | materialDetailDto.setValidStatusName(ValidStatusEnum.getByCode(materialDetailInfoDO.getValidStatus()).getValue()); |
| | | materialDetailDto.setValidTypeName(ValidTypeEnum.getByCode(materialDetailInfoDO.getValidType()).getValue()); |
| | | materialDetailDto.setIrStatusName(IssueReceiptEnum.getByCode(materialDetailInfoDO.getIrStatus()).getValue()); |
| | | |
| | | detailDtoList.add(materialDetailDto); |
| | | } |
| | | return new SearchResultVO<>(true, page.getCurrent(),page.getSize(), page.getPages(),page.getTotal(),detailDtoList,ResultCodes.OK); |
| | |
| | | SafeMaterialDetailDto detailDto = new SafeMaterialDetailDto(); |
| | | if(materialDetailInfo != null){ |
| | | SafeMaterialInfo materialInfo = safeMaterialInfoService.queryById(materialDetailInfo.getSmId()); |
| | | SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(materialDetailInfo.getMaterialClassifyId()); |
| | | SafeMaterialClassifyInfo classifyInfo = safeMaterialClassifyInfoService.queryById(materialDetailInfo.getBigClassifyId()); |
| | | BeanUtils.copyProperties(materialDetailInfo,detailDto); |
| | | detailDto.setConsumableName(ConsumableEnum.getByCode(materialDetailInfo.getConsumable()).getValue()); |
| | | detailDto.setValidStatusName(ValidStatusEnum.getByCode(materialDetailInfo.getValidStatus()).getValue()); |
| | |
| | | if(null == vo){ |
| | | throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST); |
| | | } |
| | | //如果是耗材不可重新入库 |
| | | if(vo.getConsumable().equals(ConsumableEnum.YES.getCode())){ |
| | | throw new EquipmentException(EquipmentResultCodes.MATERIAL_CONSUMABLE); |
| | | } |
| | | if(vo.getIrStatus().equals(IssueReceiptEnum.IN_THE_LIBRARY.getCode())){ |
| | | throw new EquipmentException(EquipmentResultCodes.MATERIAL_IN_THE_LIBRARY); |
| | | } |
| | |
| | | } |
| | | |
| | | if(IssueReceiptEnum.IN_THE_LIBRARY.getCode().equals(req.getIrStatus())){ |
| | | //如果是耗材不可重新入库 |
| | | if(vo.getConsumable().equals(ConsumableEnum.YES.getCode())){ |
| | | throw new EquipmentException(EquipmentResultCodes.MATERIAL_CONSUMABLE); |
| | | } |
| | | //重新入库 |
| | | if(vo.getIrStatus().equals(req.getIrStatus())){ |
| | | throw new EquipmentException(EquipmentResultCodes.MATERIAL_IN_THE_LIBRARY); |
| | |
| | | return new ResultVO<>(ResultCodes.OK); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据小类id(物资种类)获取库存数量 |
| | | * @param smallClassifyIds |
| | | * @return |
| | | */ |
| | | public List<SafeMaterialClassifyStockDto> getSmallClassifyStockByIds(List<Long> smallClassifyIds) { |
| | | if(CollectionUtils.isEmpty(smallClassifyIds)){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); |
| | | } |
| | | List<SafeMaterialClassifyStockDO> classifyStockList= safeMaterialDetailInfoService.getSmallClassifyStockByIds(smallClassifyIds); |
| | | List<SafeMaterialClassifyStockDto> classifyStockDtoList = new ArrayList<>(); |
| | | for (SafeMaterialClassifyStockDO classifyStockDO:classifyStockList){ |
| | | SafeMaterialClassifyStockDto classifyStockDto = new SafeMaterialClassifyStockDto(); |
| | | BeanUtils.copyProperties(classifyStockDO,classifyStockDto); |
| | | classifyStockDtoList.add(classifyStockDto); |
| | | } |
| | | return classifyStockDtoList; |
| | | } |
| | | |
| | | |
| | | private UserInfoRPCRespDTO getUserInfo(Long uid) { |
| | |
| | | Date date = Date.from(zdt.toInstant()); |
| | | return date; |
| | | } |
| | | |
| | | } |