| 
					
				 | 
			
			
				@ -4273,7 +4273,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MediicinecabinetInventory updateMediicinecabineInventoryById(String id,String drugId,String qty,String userId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MediicinecabinetInventory updateMediicinecabineInventoryById(String id,String drugId,String qty,Boolean refreshStatus,String userId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        MediicinecabinetInventory inventory = inventoryDao.findOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (inventory==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception("不存在改货道!"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4336,9 +4336,17 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //设置额定库存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventory.setRatedInventory(Integer.parseInt(qty)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //更改设备缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        updateDeviceState(inventory.getId(), inventoryDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //true直接设置设备为不缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (refreshStatus) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            mediicinedevice.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            deviceDao.save(mediicinedevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //默认false,通过规则判断是否缺货 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!refreshStatus) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //更改设备缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            updateDeviceState(inventory.getId(), inventoryDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4442,6 +4450,31 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (rules == null || rules.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int isZeroNum = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (tempQty == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                isZeroNum++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    mediicinedevice.setStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } /*else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mediicinedevice.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (isZeroNum == collect.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            mediicinedevice.setStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        deviceDao.save(mediicinedevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4477,19 +4510,19 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //不缺货 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        mediicinedevice.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //bug:13663 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (rules == null || rules.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            int isZeroNum = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (tempQty == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    isZeroNum++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (isZeroNum == collect.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                mediicinedevice.setStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            deviceDao.save(mediicinedevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        if (rules == null || rules.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            int isZeroNum = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                if (tempQty == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    isZeroNum++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            if (isZeroNum == collect.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                mediicinedevice.setStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            deviceDao.save(mediicinedevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //bug:end 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        quit:for (MedicineWarrayRule rule : rules) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4512,6 +4545,19 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int isZeroNum = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Map<String, Object> stringObjectMap : collect) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (tempQty == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                isZeroNum++; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                    mediicinedevice.setStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } /*else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mediicinedevice.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (isZeroNum == collect.size()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            mediicinedevice.setStatus("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        deviceDao.save(mediicinedevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4526,7 +4572,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status,String userId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status,Boolean refreshStatus,String userId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (id.contains(",")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String str[] = id.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            MediicinecabinetInventory mediicinecabinetInventory = new MediicinecabinetInventory(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4633,8 +4679,17 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                inventory.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //更改设备缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                updateDeviceState(inventory.getId(), inventoryDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //true直接设置设备为不缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (refreshStatus) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mediicinedevice.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    deviceDao.save(mediicinedevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //默认false,通过规则判断是否缺货 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (!refreshStatus) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //更改设备缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updateDeviceState(inventory.getId(), inventoryDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                mediicinecabinetInventory = inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //重算设备容量 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -4763,8 +4818,17 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventory.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //更改设备缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            updateDeviceState(inventory.getId(), inventoryDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //true直接设置设备为不缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (refreshStatus) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                mediicinedevice.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                deviceDao.save(mediicinedevice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //默认false,通过规则判断是否缺货 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (!refreshStatus) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //更改设备缺货状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                updateDeviceState(inventory.getId(), inventoryDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            inventoryDao.save(inventory); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //重算设备容量 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -5532,7 +5596,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String batchAddInventory(String json, String userId,String outDetailId) throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String batchAddInventory(String json, String userId,String outDetailId, Boolean refreshStatus) throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = JSONObject.parseObject(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray cargoList = jsonObject.getJSONArray("list"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -5559,7 +5623,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (mediicinecabinetInventory.getOrgCode() != null && !StringUtils.isEmpty(mediicinecabinetInventory.getOrgCode()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        && mediicinecabinetInventory.getDrugCode() != null && !StringUtils.isEmpty(mediicinecabinetInventory.getDrugCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //下架商品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updateMediicinecabineInventoryInfoById(inventoryDO.getCargoId(), null, null, "0", userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updateMediicinecabineInventoryInfoById(inventoryDO.getCargoId(), null, null, "0", refreshStatus, userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -5567,15 +5631,15 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (mediicinecabinetInventory.getDrugCode() == null && mediicinecabinetInventory.getDrugCode() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //新增药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                updateMediicinecabineInventoryById(inventoryDO.getCargoId(), inventoryDO.getDrugId(), inventoryDO.getQty() + "", userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                updateMediicinecabineInventoryById(inventoryDO.getCargoId(), inventoryDO.getDrugId(), inventoryDO.getQty() + "", refreshStatus,  userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Mediicinedrugs mediicinedrugs = mediicinedrugsDao.findOne(inventoryDO.getDrugId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //更换前后药品相同 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (mediicinecabinetInventory.getDrugCode().equals(mediicinedrugs.getDrugCode()) && mediicinecabinetInventory.getOrgCode().equals(mediicinedrugs.getOrgCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updateMediicinecabineInventoryInfoById(inventoryDO.getCargoId(), inventoryDO.getQty() + "", null, null, userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updateMediicinecabineInventoryInfoById(inventoryDO.getCargoId(), inventoryDO.getQty() + "", null, null,refreshStatus,  userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //更换药品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updateMediicinecabineInventoryById(inventoryDO.getCargoId(), inventoryDO.getDrugId(), inventoryDO.getQty() + "", userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    updateMediicinecabineInventoryById(inventoryDO.getCargoId(), inventoryDO.getDrugId(), inventoryDO.getQty() + "", refreshStatus, userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 |