| | |
| | | import com.gkhy.safePlatform.account.rpc.apimodel.AccountUserService; |
| | | import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.UserInfoRPCRespDTO; |
| | | import com.gkhy.safePlatform.commons.enums.ResultCodes; |
| | | import com.gkhy.safePlatform.commons.exception.BusinessException; |
| | | import com.gkhy.safePlatform.commons.query.PageQuery; |
| | | import com.gkhy.safePlatform.commons.utils.StringUtils; |
| | | import com.gkhy.safePlatform.commons.vo.ResultVO; |
| | |
| | | import com.gkhy.safePlatform.equipment.service.baseService.SafeMaterialInfoService; |
| | | import org.apache.dubbo.config.annotation.DubboReference; |
| | | import org.apache.rocketmq.spring.core.RocketMQTemplate; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | import java.time.ZoneId; |
| | | import java.time.ZonedDateTime; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("SafeMaterialDetailService") |
| | |
| | | @Autowired |
| | | private RocketMQTemplateHelper rocketMQTemplateHelper; |
| | | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | | @Override |
| | | public ResultVO save(SafeMaterialDetailAddReq req) { |
| | | //判断物资是否存在 |
| | |
| | | } |
| | | } |
| | | |
| | | //批量入库 |
| | | safeMaterialDetailInfoService.saveBatch(list); |
| | | //加分布式锁,防止重复创建规则 |
| | | RLock lock = redissonClient.getLock("LOCK_SMD_SAVE"); |
| | | try { |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | //批量入库 |
| | | safeMaterialDetailInfoService.saveBatch(list); |
| | | |
| | | //发送消息 |
| | | if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ |
| | | for(SafeMaterialDetailInfo materialDetailInfo:list){ |
| | | SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); |
| | | safeMaterialMsg.setId(materialDetailInfo.getId()); |
| | | safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime())); |
| | | rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); |
| | | //发送消息 |
| | | if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ |
| | | for(SafeMaterialDetailInfo materialDetailInfo:list){ |
| | | SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); |
| | | safeMaterialMsg.setId(materialDetailInfo.getId()); |
| | | safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime())); |
| | | rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); |
| | | } |
| | | } |
| | | //创建成功,释放锁 |
| | | lock.unlock(); |
| | | }catch (EquipmentException e) { |
| | | e.printStackTrace(); |
| | | throw new EquipmentException(e.getCode(), e.getMessage()); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResultCodes.SERVER_ERROR); |
| | | }finally { |
| | | if(lock.isLocked()){ |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | |
| | | return new ResultVO<>(ResultCodes.OK); |
| | | } |
| | | |
| | |
| | | materialDetailInfo.setMaterialNo(generateMaterialNo(totalCount+i)); |
| | | list.add(materialDetailInfo); |
| | | } |
| | | //批量入库 |
| | | safeMaterialDetailInfoService.saveBatch(list); |
| | | //发送消息 |
| | | if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ |
| | | for(SafeMaterialDetailInfo materialDetailInfo:list){ |
| | | //发送消息 |
| | | SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); |
| | | safeMaterialMsg.setId(materialInfo.getId()); |
| | | safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime())); |
| | | rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); |
| | | //加分布式锁,防止重复创建规则 |
| | | RLock lock = redissonClient.getLock("LOCK_SMD_SAVEBATCH"); |
| | | try { |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | //批量入库 |
| | | safeMaterialDetailInfoService.saveBatch(list); |
| | | //发送消息 |
| | | if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ |
| | | for(SafeMaterialDetailInfo materialDetailInfo:list){ |
| | | //发送消息 |
| | | SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); |
| | | safeMaterialMsg.setId(materialInfo.getId()); |
| | | safeMaterialMsg.setValidTime(conversionTimeType(materialDetailInfo.getValidTime())); |
| | | rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); |
| | | } |
| | | } |
| | | }catch (EquipmentException e) { |
| | | e.printStackTrace(); |
| | | throw new EquipmentException(e.getCode(), e.getMessage()); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResultCodes.SERVER_ERROR); |
| | | }finally { |
| | | if(lock.isLocked()){ |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | return new ResultVO<>(ResultCodes.OK); |
| | |
| | | safeMaterialDetailInfo.setSmId(req.getSmId()); |
| | | safeMaterialDetailInfo.setValidType(req.getValidType()); |
| | | safeMaterialDetailInfo.setValidTime(req.getValidTime()); |
| | | //修改 |
| | | safeMaterialDetailInfoService.updateById(safeMaterialDetailInfo); |
| | | //如果是非常期 |
| | | if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ |
| | | //发送消息 |
| | | SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); |
| | | safeMaterialMsg.setId(req.getId()); |
| | | safeMaterialMsg.setValidTime(conversionTimeType(req.getValidTime())); |
| | | rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); |
| | | //加分布式锁,防止重复创建规则 |
| | | RLock lock = redissonClient.getLock("LOCK_SMD_UPDATE"); |
| | | try { |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | //修改 |
| | | safeMaterialDetailInfoService.updateById(safeMaterialDetailInfo); |
| | | //如果是非常期 |
| | | if(req.getValidType().equals(ValidTypeEnum.SHORT_TERM.getCode()) && null != req.getValidTime()){ |
| | | //发送消息 |
| | | SafeMaterialMsg safeMaterialMsg = new SafeMaterialMsg(); |
| | | safeMaterialMsg.setId(req.getId()); |
| | | safeMaterialMsg.setValidTime(conversionTimeType(req.getValidTime())); |
| | | rocketMQTemplateHelper.syncSend(safeMaterialTopic,safeMaterialMsg); |
| | | } |
| | | }catch (EquipmentException e) { |
| | | e.printStackTrace(); |
| | | throw new EquipmentException(e.getCode(), e.getMessage()); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResultCodes.SERVER_ERROR); |
| | | }finally { |
| | | if(lock.isLocked()){ |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultVO receiptBatch(Long[] ids) { |
| | | if (ids.length == 0) { |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); |
| | | public ResultVO receiptBatch(ParamForm paramForm) { |
| | | //加分布式锁,防止重复创建规则 |
| | | RLock lock = redissonClient.getLock("LOCK_SMD_RECEIPTBATCH"); |
| | | try { |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | //验证 |
| | | List<SafeMaterialDetailInfo> list = safeMaterialDetailInfoService.getListByIds(paramForm.getIds()); |
| | | List<SafeMaterialDetailInfo> selectList = list |
| | | .stream() |
| | | .filter(item -> item.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()) && item.getConsumable().equals(ConsumableEnum.YES.getCode())) |
| | | .collect(Collectors.toList()); |
| | | if(selectList.size() != paramForm.getIds().size()){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"已入库或耗材物资不可重复入库!"); |
| | | } |
| | | //修改为入库状态 |
| | | safeMaterialDetailInfoService.updateReceiptStatusByIds(paramForm.getIds(),IssueReceiptEnum.IN_THE_LIBRARY.getCode()); |
| | | }catch (EquipmentException e) { |
| | | e.printStackTrace(); |
| | | throw new EquipmentException(e.getCode(), e.getMessage()); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResultCodes.SERVER_ERROR); |
| | | }finally { |
| | | if(lock.isLocked()){ |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | List<Long> idList = new ArrayList<>(); |
| | | Collections.addAll(idList,ids); |
| | | //验证 |
| | | List<SafeMaterialDetailInfo> list = safeMaterialDetailInfoService.getListByIds(idList); |
| | | List<SafeMaterialDetailInfo> selectList = list |
| | | .stream() |
| | | .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,"已入库或耗材物资不可重复入库!"); |
| | | } |
| | | //修改为入库状态 |
| | | safeMaterialDetailInfoService.updateReceiptStatusByIds(idList,IssueReceiptEnum.IN_THE_LIBRARY.getCode()); |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResultVO deleteBatch(Long[] ids) { |
| | | if (ids.length == 0) { |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); |
| | | } |
| | | safeMaterialDetailInfoService.deleteBatch(ids); |
| | | public ResultVO deleteBatch(ParamForm paramForm) { |
| | | safeMaterialDetailInfoService.deleteBatch(paramForm.getIds()); |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | |
| | |
| | | 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()); |
| | | //加分布式锁,防止重复创建规则 |
| | | RLock lock = redissonClient.getLock("LOCK_SMD_DELIVERYBATCHRANDOM"); |
| | | try { |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | if(StringUtils.isNotBlank(req.getRfid())){ |
| | | idList = safeMaterialDetailInfoService.getIdListByRfid(req.getCount(),req.getSmId(),req.getRfid()); |
| | | |
| | | }else{ |
| | | idList = safeMaterialDetailInfoService.getRfidNullList(req.getCount(), req.getSmId()); |
| | | }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.setClaimantName(userInfo.getUsername()); |
| | | detailBO.setClaimantId(req.getClaimantId()); |
| | | detailBO.setIds(idList); |
| | | safeMaterialDetailInfoService.updateDeliveryStatusByIds(detailBO); |
| | | }catch (EquipmentException e) { |
| | | e.printStackTrace(); |
| | | throw new EquipmentException(e.getCode(), e.getMessage()); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResultCodes.SERVER_ERROR); |
| | | }finally { |
| | | if(lock.isLocked()){ |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | 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.setClaimantName(userInfo.getUsername()); |
| | | detailBO.setClaimantId(req.getClaimantId()); |
| | | detailBO.setIds(idList); |
| | | safeMaterialDetailInfoService.updateDeliveryStatusByIds(detailBO); |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public ResultVO singleDelivery(SafeMaterialDetailReq req) { |
| | | //获取该条数据 |
| | | SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(req.getId()); |
| | | if(null == vo){ |
| | | throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST); |
| | | //加分布式锁,防止重复创建规则 |
| | | RLock lock = redissonClient.getLock("LOCK_SMD_SINGLEDELIVERY"); |
| | | try { |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | //获取该条数据 |
| | | SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(req.getId()); |
| | | if(null == vo){ |
| | | throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST); |
| | | } |
| | | if(vo.getValidStatus().equals(ValidStatusEnum.NO.getCode())){ |
| | | throw new EquipmentException(EquipmentResultCodes.MATERIAL_INVALID,"无效物资不可出库"); |
| | | } |
| | | if(vo.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode())){ |
| | | throw new EquipmentException(EquipmentResultCodes.MATERIAL_OUT_OF_LIBRARY); |
| | | } |
| | | //检查认领人 |
| | | UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); |
| | | SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo(); |
| | | materialDetailInfo.setId(req.getId()); |
| | | materialDetailInfo.setIrStatus(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()); |
| | | materialDetailInfo.setClaimantId(req.getClaimantId()); |
| | | materialDetailInfo.setClaimantName(userInfo.getUsername()); |
| | | materialDetailInfo.setDeliveryTime(LocalDateTime.now()); |
| | | //修改出入库状态为出库 |
| | | safeMaterialDetailInfoService.updateById(materialDetailInfo); |
| | | }catch (EquipmentException e) { |
| | | e.printStackTrace(); |
| | | throw new EquipmentException(e.getCode(), e.getMessage()); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResultCodes.SERVER_ERROR); |
| | | }finally { |
| | | if(lock.isLocked()){ |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | if(vo.getValidStatus().equals(ValidStatusEnum.NO.getCode())){ |
| | | throw new EquipmentException(EquipmentResultCodes.MATERIAL_INVALID,"无效物资不可出库"); |
| | | } |
| | | if(vo.getIrStatus().equals(IssueReceiptEnum.OUT_OF_LIBRARY.getCode())){ |
| | | throw new EquipmentException(EquipmentResultCodes.MATERIAL_OUT_OF_LIBRARY); |
| | | } |
| | | //检查认领人 |
| | | UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); |
| | | SafeMaterialDetailInfo materialDetailInfo = new SafeMaterialDetailInfo(); |
| | | materialDetailInfo.setId(req.getId()); |
| | | materialDetailInfo.setIrStatus(IssueReceiptEnum.OUT_OF_LIBRARY.getCode()); |
| | | materialDetailInfo.setClaimantId(req.getClaimantId()); |
| | | materialDetailInfo.setClaimantName(userInfo.getUsername()); |
| | | materialDetailInfo.setDeliveryTime(LocalDateTime.now()); |
| | | //修改出入库状态为出库 |
| | | safeMaterialDetailInfoService.updateById(materialDetailInfo); |
| | | return new ResultVO<>(ResultCodes.OK); |
| | | } |
| | | |
| | |
| | | if(null == id){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_NULL); |
| | | } |
| | | //获取该条数据 |
| | | SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(id); |
| | | if(null == vo){ |
| | | throw new EquipmentException(EquipmentResultCodes.DATA_NOT_EXIST); |
| | | //加分布式锁,防止重复创建规则 |
| | | RLock lock = redissonClient.getLock("LOCK_SMD_SINGLERECEIPT"); |
| | | try { |
| | | lock.lock(10, TimeUnit.SECONDS); |
| | | //获取该条数据 |
| | | SafeMaterialDetailInfo vo = safeMaterialDetailInfoService.queryById(id); |
| | | 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); |
| | | } |
| | | //修改出入库状态为入库 |
| | | safeMaterialDetailInfoService.updateReceiptStatus(id,IssueReceiptEnum.IN_THE_LIBRARY.getCode()); |
| | | }catch (EquipmentException e) { |
| | | e.printStackTrace(); |
| | | throw new EquipmentException(e.getCode(), e.getMessage()); |
| | | }catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ResultCodes.SERVER_ERROR); |
| | | }finally { |
| | | if(lock.isLocked()){ |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | //如果是耗材不可重新入库 |
| | | 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); |
| | | } |
| | | //修改出入库状态为入库 |
| | | safeMaterialDetailInfoService.updateReceiptStatus(id,IssueReceiptEnum.IN_THE_LIBRARY.getCode()); |
| | | return new ResultVO<>(ResultCodes.OK); |
| | | } |
| | | |