Browse Source

Merge branch 'dev' of chaoren1/wlyy2.0 into medicare

liubing 3 years ago
parent
commit
0675593201

+ 31 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/InventoryDO.java

@ -13,6 +13,12 @@ public class InventoryDO implements Serializable {
    private Integer qty;
    private String drugCode;
    private String orgCode;
    private Integer ratedInventory;
    public InventoryDO() {
    }
@ -39,4 +45,29 @@ public class InventoryDO implements Serializable {
    public void setQty(Integer qty) {
        this.qty = qty;
    }
    public String getDrugCode() {
        return drugCode;
    }
    public void setDrugCode(String drugCode) {
        this.drugCode = drugCode;
    }
    public String getOrgCode() {
        return orgCode;
    }
    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }
    public Integer getRatedInventory() {
        return ratedInventory;
    }
    public void setRatedInventory(Integer ratedInventory) {
        this.ratedInventory = ratedInventory;
    }
}

+ 4 - 2
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -291,8 +291,10 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
            @ApiParam(name = "cargoIds", value = "货道Id字符串", required = true)
            @RequestParam(value = "cargoIds") String cargoIds,
            @ApiParam(name = "isMerge", value = "是否合并,true 合并,false分离", required = true)
            @RequestParam(value = "isMerge") Boolean isMerge) throws Exception {
        String str = deviceService.mergeAndSplitCargo(cargoIds, isMerge);
            @RequestParam(value = "isMerge") Boolean isMerge,
            @ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId) throws Exception {
        String str = deviceService.mergeAndSplitCargo(cargoIds, isMerge, userId);
        JSONObject jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));

+ 95 - 19
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineOrderService.java

@ -844,7 +844,12 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
                    medicineShipmentLog.getLayerNo(),
                    medicineShipmentLog.getWayerNo().split(",")[0]);
            inventory.setQty((Integer.parseInt(inventory.getQty()) - 1<0 ? "0" :String.valueOf((Integer.parseInt(inventory.getQty()) - 1))));
            InventoryDO inventoryDO = new InventoryDO();
            inventoryDO.setDrugCode(inventory.getDrugCode());
            inventoryDO.setOrgCode(inventory.getOrgCode());
            inventoryDO.setQty(Integer.parseInt(inventory.getQty()));
            inventoryDO.setRatedInventory(inventory.getRatedInventory());
            updateDeviceState(inventory.getId(), inventoryDO);
            inventoryDao.save(inventory);
            //绑定订单跟出货设备的关系,
            Mediicineorder mediicineorder = orderDao.findOne(medicineShipmentLog.getOrderId());
@ -853,7 +858,7 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
            mediicineorder.setShippingType(shippingType);
            orderDao.save(mediicineorder);
            //更新设备缺货状态
            updateDeviceState(medicineShipmentLog);
//            updateDeviceState(medicineShipmentLog);
        }
        result.put("msg", ConstantUtils.SUCCESS);
@ -865,45 +870,58 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
     * 更新设备缺货信息
     * @param medicineShipmentLog
     */
    public void updateDeviceState(MedicineShipmentLog medicineShipmentLog) {
    public void updateDeviceState(String cargoId, InventoryDO inventoryDO) {
        //包含原来药品信息
//        MediicinecabinetInventory inventory =  inventoryDao.findOne(cargoId);
        MediicinecabinetInventory inventory =  inventoryDao.findOne(cargoId);
        String sql = "SELECT\n" +
                "\tifnull(sum(qty), 0) AS qty,\n" +
                "\tsum(qty) AS qty,\n" +
                "\tdrug_id AS drugId,\n" +
                "\tdrug_code AS drugCode,\n" +
                "\torg_code AS orgCode,\n" +
                "\tifnull(sum(rated_inventory), 0) AS ratedInventory\n" +
                "\tsum(rated_inventory) AS ratedInventory\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory\n" +
                "WHERE\n" +
                "\tequ_num = '"+medicineShipmentLog.getDeviceId()+"'\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" +
                "\tdrug_code,\n" +
                "\torg_code";
//        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(medicineShipmentLog.getDeviceId(),"1,", "21");
//        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeCondition(inventory.getIdDevice(), "1", "21");
        List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql);
        Iterator<Map<String, Object>> it = collect.iterator();
        while (it.hasNext()) {
            Map<String, Object> stringObjectMap = it.next();
            if (String.valueOf(stringObjectMap.get("drugCode")).equals(medicineShipmentLog.getDrugCode()) &&
                        String.valueOf(stringObjectMap.get("orgCode")).equals(medicineShipmentLog.getOrgCode())) {
                stringObjectMap.put("qty", String.valueOf((int)Double.parseDouble(stringObjectMap.get("qty") + "") - 1));
            }
//        //药品变更,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.findMediicinedeviceByEquNum(medicineShipmentLog.getDeviceId());
        Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
        //该设备库存预警规则
        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(medicineShipmentLog.getDeviceId(), 1);
        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(inventory.getEquNum(), 1);
        //不缺货
        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);
@ -923,6 +941,64 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
        }
        deviceDao.save(mediicinedevice);
    }
//    public void updateDeviceState(MedicineShipmentLog medicineShipmentLog) {
//        //包含原来药品信息
////        MediicinecabinetInventory inventory =  inventoryDao.findOne(cargoId);
//        String sql = "SELECT\n" +
//                "\tifnull(sum(qty), 0) AS qty,\n" +
//                "\tdrug_id AS drugId,\n" +
//                "\tdrug_code AS drugCode,\n" +
//                "\torg_code AS orgCode,\n" +
//                "\tifnull(sum(rated_inventory), 0) AS ratedInventory\n" +
//                "FROM\n" +
//                "\tt_mediicinecabinet_inventory\n" +
//                "WHERE\n" +
//                "\tequ_num = '"+medicineShipmentLog.getDeviceId()+"'\n" +
//                "AND (state = '1' OR state = '21')\n" +
//                "AND drug_code IS NOT NULL\n" +
//                "AND org_code IS NOT NULL\n" +
//                "GROUP BY\n" +
//                "\tdrug_code,\n" +
//                "\torg_code";
////        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(medicineShipmentLog.getDeviceId(),"1,", "21");
//        List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql);
//
//        Iterator<Map<String, Object>> it = collect.iterator();
//        while (it.hasNext()) {
//            Map<String, Object> stringObjectMap = it.next();
//            if (String.valueOf(stringObjectMap.get("drugCode")).equals(medicineShipmentLog.getDrugCode()) &&
//                        String.valueOf(stringObjectMap.get("orgCode")).equals(medicineShipmentLog.getOrgCode())) {
//                stringObjectMap.put("qty", String.valueOf((int)Double.parseDouble(stringObjectMap.get("qty") + "") - 1));
//            }
//        }
//        Mediicinedevice mediicinedevice = deviceDao.findMediicinedeviceByEquNum(medicineShipmentLog.getDeviceId());
//        //该设备库存预警规则
//        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(medicineShipmentLog.getDeviceId(), 1);
//        //不缺货
//        mediicinedevice.setStatus("1");
//        quit:for (MedicineWarrayRule rule : rules) {
//            for (Map<String, Object> stringObjectMap : collect) {
//                Integer ratedInventory = (int) Double.parseDouble(stringObjectMap.get("ratedInventory") + "");
//                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);
//                        if (tempQty <= matchValue) {
//                            mediicinedevice.setStatus("0");
//                            break quit;
//                        }
//                    }
//                    if ("件".equals(rule.getMatchUnit())) {
//                        if (tempQty <= rule.getMatchValue()) {
//                            mediicinedevice.setStatus("0");
//                            break quit;
//                        }
//                    }
//                }
//            }
//        }
//        deviceDao.save(mediicinedevice);
//    }
    public JSONObject checkOrderComplete(String orderId) {

+ 123 - 85
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -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());