| | |
| | | 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.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 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 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.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("SafeMaterialDetailService") |
| | |
| | | @Autowired |
| | | private RocketMQTemplateHelper rocketMQTemplateHelper; |
| | | |
| | | @Autowired |
| | | private RedissonClient redissonClient; |
| | | @Override |
| | | public ResultVO save(SafeMaterialDetailAddReq req) { |
| | | //判断物资是否存在 |
| | |
| | | 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()); |
| | |
| | | } |
| | | } |
| | | |
| | | //批量入库 |
| | | 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); |
| | | } |
| | | |
| | |
| | | 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()); |
| | |
| | | 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())) |
| | | .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); |
| | | } |
| | | |
| | |
| | | @Override |
| | | public ResultVO deliveryBatchRandom(MterialRandomDeliveryReq req) { |
| | | UserInfoRPCRespDTO userInfo = getUserInfo(req.getClaimantId()); |
| | | //获取有效数量 |
| | | Integer validStockCount = safeMaterialDetailInfoService.getValidStockCount(req.getSmId()); |
| | | if(req.getCount() > validStockCount){ |
| | | throw new EquipmentException(ResultCodes.CLIENT_PARAM_ILLEGAL,"出库数量不可大于有效库存数量!"); |
| | | List<Long> idList = new ArrayList<>(); |
| | | //加分布式锁,防止重复创建规则 |
| | | 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()); |
| | | |
| | | } |
| | | 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(); |
| | | } |
| | | } |
| | | 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.setCount(req.getCount()); |
| | | detailBO.setClaimantName(userInfo.getUsername()); |
| | | detailBO.setClaimantId(req.getClaimantId()); |
| | | safeMaterialDetailInfoService.deliveryBatchRandom(detailBO); |
| | | return new ResultVO(ResultCodes.OK); |
| | | 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()); |
| | |
| | | */ |
| | | @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.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); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | } |