| 
					
				 | 
			
			
				@ -737,7 +737,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param isMerge 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String mergeAndSplitCargo(String cargoIds, Boolean isMerge){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String mergeAndSplitCargo(String cargoIds, Boolean isMerge, String userId){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isEmpty(cargoIds)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg","cargoIds is null"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -748,12 +748,13 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String[] cargoIdsArray = cargoIds.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String deviceID = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //true,标识合并货道 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (isMerge) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Boolean isFirst = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //合并的所有货道集合 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String wayerNos = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (String deviceId : cargoIds.split(",")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(!StringUtils.isEmpty(deviceId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    MediicinecabinetInventory inventory = inventoryDao.findOne(deviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (String cargoId : cargoIds.split(",")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(!StringUtils.isEmpty(cargoId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    MediicinecabinetInventory inventory = inventoryDao.findOne(cargoId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (StringUtils.isEmpty(wayerNos)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        wayerNos += inventory.getWayerNo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    }else { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -761,39 +762,50 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            MediicinecabinetInventory copyInventory = new MediicinecabinetInventory(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (String deviceId : cargoIds.split(",")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(!StringUtils.isEmpty(deviceId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            boolean isFirst = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (String cargoId : cargoIds.split(",")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(!StringUtils.isEmpty(cargoId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    MediicinecabinetInventory inventory = inventoryDao.findOne(cargoId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //有药品记录下架操作 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (inventory.getOrgCode() != null && inventory.getDrugCode() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setDeviceId(inventory.getIdDevice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setEquNum(inventory.getEquNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setOldDrugId(inventory.getDrugId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setDrugId(inventory.getDrugId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setLayerNo(inventory.getLayerNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setWayerNo(inventory.getWayerNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setMergeState(inventory.getState()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setMergeCargo(inventory.getMerge()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setOldQuantity(inventory.getQty()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setQuantity("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setCreateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecord.setType("4"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryRecordDao.save(inventoryRecord); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    deviceID = inventory.getIdDevice(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventory.setMerge(wayerNos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //清空药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventory.setQty("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventory.setDrugId(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventory.setDrugName(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventory.setDrugCode(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventory.setOrgCode(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventory.setPrice(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //额定库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventory.setRatedInventory(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //清空药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (isFirst) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        MediicinecabinetInventory inventory = inventoryDao.findOne(deviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        deviceID = inventory.getIdDevice(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        copyInventory = inventory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setMerge(wayerNos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setState("21"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        isFirst = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        MediicinecabinetInventory inventory = inventoryDao.findOne(deviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        deviceID = inventory.getIdDevice(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setMerge(wayerNos); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        inventory.setCargoCapacity(copyInventory.getCargoCapacity()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        inventory.setState(copyInventory.getState()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        inventory.setNum(copyInventory.getNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        inventory.setShelfStatus(copyInventory.getShelfStatus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setState("20"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //副货道内容操作-start-------》bug:13570 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setQty("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setDrugName(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setDrugCode(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setOrgCode(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setPrice(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //额定库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setRatedInventory(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventory.setShelfStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //内容操作end 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -801,6 +813,32 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            MediicinecabinetInventory inventory = inventoryDao.findOne(cargoIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<MediicinecabinetInventory> list = inventoryDao.findMediicinecabinetInventoriesByLayerNoAndMerge(inventory.getLayerNo(), inventory.getMerge()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setMerge(inventory.getWayerNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //有药品记录下架操作 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (inventory.getOrgCode() != null && inventory.getDrugCode() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setDeviceId(inventory.getIdDevice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setEquNum(inventory.getEquNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setOldDrugId(inventory.getDrugId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setDrugId(inventory.getDrugId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setLayerNo(inventory.getLayerNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setWayerNo(inventory.getWayerNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setMergeState(inventory.getState()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setMergeCargo(inventory.getMerge()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setOldQuantity(inventory.getQty()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setQuantity("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setCreateUser(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setType("4"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecordDao.save(inventoryRecord); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //清空药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setQty("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setDrugName(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setDrugCode(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setOrgCode(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setPrice(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //额定库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setRatedInventory(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //清空药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setState("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (MediicinecabinetInventory mediicinecabinetInventory : list) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -818,6 +856,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //重算货道数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (mediicinedevice != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String tempSql = "SELECT\n" + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4024,7 +4063,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MediicinecabinetInventory updateMediicinecabineInventoryById(String id,String drugId,String qty,String userId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        MediicinecabinetInventory inventory = inventoryDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (inventory==null){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4059,6 +4098,17 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryRecordDao.save(inventoryRecord); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Mediicinedrugs mediicinedrugs = mediicinedrugsDao.findOne(drugId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        InventoryDO inventoryDO = new InventoryDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDO.setDrugCode(mediicinedrugs.getDrugCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDO.setOrgCode(mediicinedrugs.getOrgCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDO.setQty(Integer.parseInt(qty)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //换货,原额定库存跟该药品没关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("2".equals(inventoryRecord.getType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventoryDO.setRatedInventory(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventoryDO.setRatedInventory(inventory.getRatedInventory()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventory.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventory.setDrugCode(mediicinedrugs.getDrugCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventory.setOrgCode(mediicinedrugs.getOrgCode()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4078,9 +4128,11 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置额定库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventory.setRatedInventory(Integer.parseInt(qty)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //更改设备缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        updateDeviceState(inventory.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        updateDeviceState(inventory.getId(), inventoryDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //重算设备容量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (cargoCapacityChanged) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4112,7 +4164,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 更新设备缺货状态,cargoId,货道id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param cargoId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void updateDeviceState(String cargoId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void updateDeviceState(String cargoId, InventoryDO inventoryDO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //包含原来药品信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        MediicinecabinetInventory inventory =  inventoryDao.findOne(cargoId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT\n" + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4126,6 +4178,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "WHERE\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\tid_device = '"+inventory.getIdDevice()+"'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "AND (state = '1' OR state = '21')\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "AND id != '"+ cargoId +"'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "AND drug_code IS NOT NULL\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "AND org_code IS NOT NULL\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "GROUP BY\n" + 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4133,56 +4186,18 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "\torg_code"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeCondition(inventory.getIdDevice(), "1", "21"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        //药品变更 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        if (drugChanged) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            //变更的目标药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            Mediicinedrugs mediicinedrugs = mediicinedrugsDao.findOne(drugId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            Iterator<Map<String, Object>> it = collect.iterator(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            //剔除旧药品的数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            while (it.hasNext()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                Map<String, Object> stringObjectMap = it.next(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                if (String.valueOf(stringObjectMap.get("drugCode")).equals(inventory.getDrugCode()) && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        String.valueOf(stringObjectMap.get("orgCode")).equals(inventory.getOrgCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    //说明只有一个货道是该种药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    if (Integer.parseInt(stringObjectMap.get("qty") + "") - Integer.parseInt(inventory.getQty()) == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        it.remove(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        stringObjectMap.put("qty", String.valueOf(Integer.parseInt(stringObjectMap.get("qty") + "") - Integer.parseInt(inventory.getQty()))); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            Map<String, Object> tempMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            tempMap.put("drugCode", mediicinedrugs.getDrugCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            tempMap.put("orgCode", mediicinedrugs.getOrgCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            tempMap.put("qty", qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            tempMap.put("ratedInventory", Integer.parseInt(qty)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            collect.add(tempMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            //数量变更 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            if (qtyChanged) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                Iterator<Map<String, Object>> it = collect.iterator(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                while (it.hasNext()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    Map<String, Object> stringObjectMap = it.next(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    if (String.valueOf(stringObjectMap.get("drugCode")).equals(inventory.getDrugCode()) && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            String.valueOf(stringObjectMap.get("orgCode")).equals(inventory.getOrgCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        //下架 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        if ("0".equals(qty)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            it.remove(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        if (Integer.parseInt(qty) > Integer.parseInt(inventory.getQty())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            stringObjectMap.put("qty", qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            stringObjectMap.put("ratedInventory", Integer.parseInt(qty)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        } else if (Integer.parseInt(qty) < Integer.parseInt(inventory.getQty())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                            it.remove(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        //药品变更,true除当前货道还存在该药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        boolean isExit = collect.stream().filter(m -> m.get("drugCode").toString().equals(inventoryDO.getDrugCode())).findAny().isPresent(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (collect == null || collect.size() == 0 || !isExit) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> tempMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tempMap.put("drugCode", inventoryDO.getDrugCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tempMap.put("orgCode", inventoryDO.getOrgCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tempMap.put("qty", inventoryDO.getQty()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tempMap.put("ratedInventory", inventoryDO.getRatedInventory()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            tempMap.put("drugId", inventoryDO.getDrugId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            collect.add(tempMap); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //该设备库存预警规则 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4191,8 +4206,16 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        mediicinedevice.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        quit:for (MedicineWarrayRule rule : rules) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (isExit) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (inventoryDO.getDrugCode() != null && inventoryDO.getOrgCode() != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (inventoryDO.getDrugCode().equals(stringObjectMap.get("drugCode")) && inventoryDO.getOrgCode().equals(stringObjectMap.get("orgCode"))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            stringObjectMap.put("qty", (int) Double.parseDouble(stringObjectMap.get("qty") + "") + inventoryDO.getQty()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            stringObjectMap.put("ratedInventory", (int) Double.parseDouble(stringObjectMap.get("ratedInventory") + "") + inventoryDO.getRatedInventory()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Integer ratedInventory = (int) Double.parseDouble(stringObjectMap.get("ratedInventory") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (ratedInventory > rule.getLower() && ratedInventory < rule.getUpper()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (ratedInventory >= rule.getLower() && ratedInventory <= rule.getUpper()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("%".equals(rule.getMatchUnit())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4223,9 +4246,16 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status,String userId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        MediicinecabinetInventory inventory =  inventoryDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //更新设备缺货状态的该药品的已变动数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        InventoryDO inventoryDO = new InventoryDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDO.setDrugCode(inventory.getDrugCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDO.setOrgCode(inventory.getOrgCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDO.setRatedInventory(inventory.getRatedInventory()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        boolean cargoCapacityChanged = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //库存变动 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (org.apache.commons.lang3.StringUtils.isNoneBlank(qty)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (Integer.parseInt(qty) > 99) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("库存数量最多99个,请重新设置"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4251,11 +4281,14 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventory.setCargoCapacity(qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setQty(qty); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //库存变更已变更的数量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventoryDO.setQty(Integer.parseInt(qty)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //设置额定库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setRatedInventory(Integer.parseInt(qty)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //更改货道容量-start 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (org.apache.commons.lang3.StringUtils.isNoneBlank(cargoCapacity)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventoryDO.setQty(Integer.parseInt(inventory.getQty())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //2022-01-05-bug:13617-start 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (Integer.parseInt(inventory.getQty()) > Integer.parseInt(cargoCapacity)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //有药品时的补货 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4274,6 +4307,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecord.setType("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryRecordDao.save(inventoryRecord); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventory.setQty(cargoCapacity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryDO.setQty(Integer.parseInt(cargoCapacity)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //设置额定库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventory.setRatedInventory(Integer.parseInt(cargoCapacity)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4285,10 +4319,12 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cargoCapacityChanged = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //更改货道容量-end 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //下架药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (org.apache.commons.lang3.StringUtils.isNoneBlank(status)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //下架时,清空库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("0".equals(status)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventory.setQty("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventoryDO.setQty(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventory.setDrugCode(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventory.setDrugId(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventory.setDrugName(null); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4313,9 +4349,11 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventoryRecordDao.save(inventoryRecord); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventory.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //更改设备缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        updateDeviceState(inventory.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        updateDeviceState(inventory.getId(), inventoryDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //重算设备容量 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (cargoCapacityChanged) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice()); 
			 |