| | |
| | | import com.google.common.collect.ImmutableMap; |
| | | import com.nanometer.smartlab.dao.*; |
| | | import com.nanometer.smartlab.entity.*; |
| | | import com.nanometer.smartlab.entity.dto.PersonUseDetail; |
| | | import com.nanometer.smartlab.entity.enumtype.ValidFlag; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.log4j.Logger; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.dao.DataAccessException; |
| | | import org.springframework.dao.DataIntegrityViolationException; |
| | | import org.springframework.dao.DuplicateKeyException; |
| | |
| | | |
| | | @Resource(name = "opeReagentStatusDao") |
| | | OpeReagentStatusDao opeReagentStatusDao; |
| | | |
| | | @Lazy |
| | | @Resource |
| | | private OpeWarehouseReserveService opeWarehouseReserveService; |
| | | @Lazy |
| | | @Resource |
| | | private OpeUseFlowService opeUseFlowService; |
| | | @Resource |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public boolean updateReagentStatus(OpeReagentStatus opeReagentStatus) { |
| | | public boolean updateReagentStatus3(OpeReagentStatus opeReagentStatus) { |
| | | try { |
| | | |
| | | //1.判断->试剂状态是否为在仓库 |
| | | if (isAllowWarehouseUse(opeReagentStatus)) { |
| | | // 减少库存 |
| | | OpeWarehouseReserve opeWarehouseReserve = this.opeWarehouseReserveService.getOpeWarehouseReserve( |
| | | opeReagentStatus.getReagent().getId(), opeReagentStatus.getArticleNumber()); |
| | | opeWarehouseReserve.setReserve(opeWarehouseReserve.getReserve() - 1); |
| | | this.opeWarehouseReserveService.updateOpeWarehouseReserve(opeWarehouseReserve); |
| | | //1.1获得 试剂的库存选择批次 |
| | | List<OpeWarehouseReserve> owrList = this.opeWarehouseReserveService |
| | | .getOpeWarehouseReserveList(opeReagentStatus.getReagent().getId(), opeReagentStatus.getArticleNumber(),opeReagentStatus.getHouseId()); |
| | | //在同一个仓库有相同批次的试剂,根据时间早的,个数少的先扣除库存 |
| | | owrList.get(0).setReserve(owrList.get(0).getReserve() - 1); |
| | | this.opeWarehouseReserveService.updateOpeWarehouseReserve(owrList.get(0)); |
| | | } |
| | | |
| | | //设置 试剂状态->领用待入库 |
| | | opeReagentStatus.setStatus(ArrivalStatus.NOREGISTER); |
| | | |
| | | // opeReagentStatus.setHouseId(null); |
| | | // opeReagentStatus.setContainerId(null); |
| | | int row = this.opeReagentStatusDao.updateOpeReagentStatusDao(opeReagentStatus); |
| | | |
| | | if (row == 0) { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | |
| | | OpeUseFlow opeUseFlow = new OpeUseFlow(); |
| | | opeUseFlow.setReagentCode(opeReagentStatus.getReagentCode()); |
| | |
| | | |
| | | this.opeUseFlowService.insertOpeUseFlow(opeUseFlow); |
| | | |
| | | return true; |
| | | } catch (DuplicateKeyException ex) { |
| | | logger.warn(ex.getMessage(), ex); |
| | | throw new AlarmException(AlarmCode.DATA_DUPLICATE, |
| | | MessageUtil.getMessage(AlarmCode.DATA_DUPLICATE.getCode())); |
| | | } catch (DataIntegrityViolationException ex) { |
| | | logger.warn(ex.getMessage(), ex); |
| | | throw new AlarmException(AlarmCode.DATA_CONFICT, MessageUtil.getMessage(AlarmCode.DATA_CONFICT.getCode())); |
| | | } catch (DataAccessException ex) { |
| | | logger.error(ex.getMessage(), ex); |
| | | throw new BusinessException(ExceptionEnumCode.DB_ERR, |
| | | MessageUtil.getMessageByCode(ExceptionEnumCode.DB_ERR.getCode()), ex); |
| | | } |
| | | } |
| | | |
| | | @Transactional(propagation = Propagation.REQUIRED) |
| | | public boolean updateReagentStatus(OpeReagentStatus opeReagentStatus) { |
| | | try { |
| | | |
| | | if (isAllowWarehouseUse(opeReagentStatus)) { |
| | | // 减少库存 |
| | | OpeWarehouseReserve opeWarehouseReserve = this.opeWarehouseReserveService.getOpeWarehouseReserve( |
| | | opeReagentStatus.getReagent().getId(), opeReagentStatus.getArticleNumber()); |
| | | opeWarehouseReserve.setReserve(opeWarehouseReserve.getReserve() - 1); |
| | | this.opeWarehouseReserveService.updateOpeWarehouseReserve(opeWarehouseReserve); |
| | | } |
| | | opeReagentStatus.setStatus(ArrivalStatus.NOREGISTER); |
| | | int row = this.opeReagentStatusDao.updateOpeReagentStatusDao(opeReagentStatus); |
| | | if (row == 0) { |
| | | return false; |
| | | } |
| | | OpeUseFlow opeUseFlow = new OpeUseFlow(); |
| | | opeUseFlow.setReagentCode(opeReagentStatus.getReagentCode()); |
| | | opeUseFlow.setStatus(opeReagentStatus.getStatus()); |
| | | opeUseFlow.setHouseId(opeReagentStatus.getHouseId()); |
| | | opeUseFlow.setContainerId(opeReagentStatus.getContainerId()); |
| | | opeUseFlow.setUserId(opeReagentStatus.getUserId()); |
| | | opeUseFlow.setPlace(opeReagentStatus.getPlace()); |
| | | opeUseFlow.setRemainder(opeReagentStatus.getRemainder()); |
| | | |
| | | Map<String, String> metaMap = new HashMap<>(); |
| | | metaMap.put("groupId", "operate_status"); |
| | | metaMap.put("metaKey", String.valueOf(OperateStatus.WAREHOUSEOUT.getKey())); |
| | | List<BaseMeta> baseMetaList = baseMetaDao.getBaseMetaList(metaMap); |
| | | opeUseFlow.setOperateState(baseMetaList.get(0).getId()); |
| | | this.opeUseFlowService.insertOpeUseFlow(opeUseFlow); |
| | | return true; |
| | | } catch (DuplicateKeyException ex) { |
| | | logger.warn(ex.getMessage(), ex); |
| | |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void batchUpdateStatusByCode(List<OpeReagentStatus> list) throws Exception { |
| | | if(list == null || list.size() <1){ |
| | | throw new Exception("没有选择试剂"); |
| | | } |
| | | public void batchUpdateStatusByCode(List<PersonUseDetail> applyList) throws Exception { |
| | | |
| | | for (OpeReagentStatus opeReagentStatus : list) { |
| | | |
| | | |
| | | for (PersonUseDetail pu : applyList) { |
| | | |
| | | //变更试剂状态为入库 |
| | | Map<String, Object> params1 = new HashMap<>(); |
| | | String reagentCode = opeReagentStatus.getReagentCode(); |
| | | String reagentCode = pu.getReagentCode(); |
| | | params1.put("code", reagentCode); |
| | | params1.put("status",ArrivalStatus.WAREHOUSE); |
| | | opeReagentStatusDao.updateStatusByCode(params1); |
| | |
| | | |
| | | //增加数据库存 |
| | | Map<String, Object> params3 = new HashMap<>(); |
| | | String reagentId = opeReagentStatus.getReagentId(); |
| | | String articleNumber = opeReagentStatus.getArticleNumber(); |
| | | String reagentId = pu.getReagentId(); |
| | | String articleNumber = pu.getArticleNumber(); |
| | | params3.put("reagentId", reagentId); |
| | | params3.put("articleNumber", articleNumber); |
| | | opeWarehouseReserveDao.updateCount(params3); |
| | |
| | | |
| | | List<String> codeList= new ArrayList<>(); |
| | | //1.做24位的字母判断否则就是纯数字 |
| | | if (startReagentCode2.matches(".*[A-F]+.*")) { |
| | | if (startReagentCode2.matches(".*\\D+.*")) { |
| | | //长度为24并且后5位随机码得是数字 |
| | | if (startReagentCode2.length() == 24 && |
| | | endReagentCode2.length() == 24 && |
| | | startReagentCode2.substring(startReagentCode2.length()-5).matches("/d{5}")) { |
| | | startReagentCode2.matches(".*([A-F]|\\d)+.*") && |
| | | startReagentCode2.substring(startReagentCode2.length()-5).matches("\\d{5}")) { |
| | | //24位指定编码生成 |
| | | Integer randomStart = Integer.valueOf(startReagentCode2.substring(startReagentCode2.length() - 5)); |
| | | Integer randomEnd = Integer.valueOf(endReagentCode2.substring(endReagentCode2.length() - 5)); |
| | |
| | | if (randomEnd - randomStart + 1 != arrivalNum||!regentPrefix2.equals(regentPrefix)) { |
| | | throw new BusinessException(ExceptionEnumCode.PARAM_EXIST,"试剂的开始结束条码有问题"); |
| | | } |
| | | for (int random = randomStart; random < randomEnd; random++) { |
| | | for (int random = randomStart; random <= randomEnd; random++) { |
| | | String random5 = String.format("%0" + 5 + "d", random); |
| | | String reagentCode = regentPrefix + random5; |
| | | OpeReagentStatus opeReagentStatus = this.getOpeReagentStatusByReagentCode(reagentCode); |
| | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<String> generateReagentCode(String startReagentCode2, String endReagentCode2) { |
| | | if (startReagentCode2 == null || startReagentCode2.length() < 1) { |
| | | throw new BusinessException(ExceptionEnumCode.REAGENT_CODE_INVALID,"试剂条码不合法"); |
| | | } |
| | | |
| | | if (endReagentCode2 == null || endReagentCode2.length() < 1) { |
| | | throw new BusinessException(ExceptionEnumCode.REAGENT_CODE_INVALID,"试剂条码不合法"); |
| | | } |
| | | |
| | | |
| | | |
| | | List<String> codeList= new ArrayList<>(); |
| | | //1.做24位的字母判断否则就是纯数字 |
| | | if (startReagentCode2.matches(".*\\D+.*")) { |
| | | //长度为24并且后5位随机码得是数字 |
| | | if (startReagentCode2.length() == 24 && |
| | | endReagentCode2.length() == 24 && |
| | | startReagentCode2.matches(".*([A-F]|\\d)+.*") && |
| | | startReagentCode2.substring(startReagentCode2.length()-5).matches("\\d{5}")) { |
| | | //24位指定编码生成 |
| | | Integer randomStart = Integer.valueOf(startReagentCode2.substring(startReagentCode2.length() - 5)); |
| | | Integer randomEnd = Integer.valueOf(endReagentCode2.substring(endReagentCode2.length() - 5)); |
| | | String regentPrefix = startReagentCode2.substring(0, startReagentCode2.length() - 5); |
| | | |
| | | for (int random = randomStart; random <= randomEnd; random++) { |
| | | String random5 = String.format("%0" + 5 + "d", random); |
| | | String reagentCode = regentPrefix + random5; |
| | | codeList.add(reagentCode); |
| | | } |
| | | return codeList; |
| | | }else{ |
| | | throw new BusinessException(ExceptionEnumCode.REAGENT_CODE_INVALID,"试剂条码不合法"); |
| | | } |
| | | } |
| | | |
| | | //2.纯数字编码列表生成 |
| | | BigInteger reagentCode= new BigInteger(startReagentCode2); |
| | | BigInteger endReagentCode = new BigInteger(endReagentCode2); |
| | | |
| | | while (reagentCode.compareTo(endReagentCode) <= 0) { |
| | | String reagentCodeStr = String.format("%0" + startReagentCode2.length() + "d", reagentCode); |
| | | codeList.add(reagentCodeStr); |
| | | reagentCode = reagentCode.add(BigInteger.ONE); |
| | | } |
| | | |
| | | return codeList; |
| | | } |
| | | |
| | | @Override |
| | | public void updateOpeReagentStatus(OpeReagentStatus opeReagentStatus) { |
| | | opeReagentStatusDao.updateOpeReagentStatusDao(opeReagentStatus); |
| | | } |
| | | |
| | | @Override |
| | | public int getReagentNumInWarehouse(String id, String articleNumber, String warehouseId) { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("reagentId", id); |
| | | params.put("articleNumber", articleNumber); |
| | | params.put("warehouseId", warehouseId); |
| | | return opeReagentStatusDao.countReagentByArticleAndWarehouse(params); |
| | | } |
| | | |
| | | |
| | | } |