wangzhinan 2 years ago
parent
commit
583cdebda3

+ 35 - 86
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -738,27 +738,32 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    /**
     * 合并和分离货道, state《---1单列货道,21合并货道的主货道,20次货道
     * @param cargoIds          需合并的货道id
     * @param isMerge           true,合并,false,分解
     * @param isMerge           true,合并货道,false,分解货道
     * @return
     */
    public String mergeAndSplitCargo(String cargoIds, Boolean isMerge, String userId){
        JSONObject result = new JSONObject();
        //校验货道id
        if(StringUtils.isEmpty(cargoIds)){
            result.put("msg","cargoIds is null");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        //对cargoIds重排
        String[] cargoIdsArray = cargoIds.split(",");
        //100percent,cargoCapacityChanged
        boolean cargoCapacityChanged = true;
        int changedCapacity = 0;
        int changedCargoNumber = 0;
        //通过货道信息获取设备id
        String deviceID = "";
        //true,标识合并货道
        //true,标识当前操作为合并货道操作
        if (isMerge) {
            //合并的所有货道集合
            String[] cargoIdArray = cargoIds.split(",");
            changedCargoNumber = cargoIdArray.length - 1;
            //合并的所有货道列编号--->集合
            String wayerNos = "";
            for (String cargoId : cargoIds.split(",")) {
            for (String cargoId : cargoIdArray) {
                if(!StringUtils.isEmpty(cargoId)){
                    MediicinecabinetInventory inventory = inventoryDao.findOne(cargoId);
                    if (StringUtils.isEmpty(wayerNos)) {
@ -768,9 +773,8 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                    }
                }
            }
            boolean isFirst = true;
            for (String cargoId : cargoIds.split(",")) {
            for (String cargoId : cargoIdArray) {
                if(!StringUtils.isEmpty(cargoId)){
                    MediicinecabinetInventory inventory = inventoryDao.findOne(cargoId);
                    //有药品记录下架操作
@ -791,39 +795,40 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                        inventoryRecordDao.save(inventoryRecord);
                    }
                    deviceID = inventory.getIdDevice();
                    //记录合并列编号
                    inventory.setMerge(wayerNos);
                    //清空药品
                    //清空药品-START
                    inventory.setQty("0");
                    inventory.setDrugId(null);
                    inventory.setDrugName(null);
                    inventory.setDrugCode(null);
                    inventory.setOrgCode(null);
                    inventory.setPrice(null);
                    //bug:13630,新增
                    //副货道内容操作-start-------》bug:13570
                    inventory.setShelfStatus("0");
                    //
                    //内容操作end
                    //额定库存
                    inventory.setRatedInventory(0);
                    //清空药品
                    //清空药品-END
                    if (isFirst) {
//                        changedCapacity -= Integer.parseInt(inventory.getCargoCapacity());
                        inventory.setState("21");
                        isFirst = false;
                    } else {
                        //累计副货道的货道容量
                        //累计副货道的货道容量-------->变动容量
                        changedCapacity += Integer.parseInt(inventory.getCargoCapacity());
                        inventory.setState("20");
                        //副货道内容操作-start-------》bug:13570
                        inventory.setShelfStatus("0");
                        //内容操作end
                    }
                    //保存配置
                    inventoryDao.save(inventory);
                }
            }
        } else {
            //因为拆分,前台就传了主货道的, so就查,主货道id吧,
            MediicinecabinetInventory inventory = inventoryDao.findOne(cargoIds);
            //所有有关分解的货道列表
            List<MediicinecabinetInventory> list = inventoryDao.findMediicinecabinetInventoriesByLayerNoAndMerge(inventory.getLayerNo(), inventory.getMerge());
            changedCargoNumber = list.size() - 1;
            //主货道拆解
            inventory.setMerge(inventory.getWayerNo());
            //有药品记录下架操作
            if (inventory.getOrgCode() != null && inventory.getDrugCode() != null) {
@ -851,92 +856,36 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            inventory.setPrice(null);
            //bug:13630,新增
            inventory.setShelfStatus("0");
            //
            //额定库存
            inventory.setRatedInventory(0);
            //清空药品
            inventory.setState("1");
            inventoryDao.save(inventory);
            boolean jumpFirst = true;
            boolean jumpFirst = false;
            for (MediicinecabinetInventory mediicinecabinetInventory : list) {
                if(jumpFirst) {
                    changedCapacity += Integer.parseInt(mediicinecabinetInventory.getCargoCapacity());
                }
                jumpFirst = false;
                jumpFirst = true;
                mediicinecabinetInventory.setMerge(mediicinecabinetInventory.getWayerNo());
                mediicinecabinetInventory.setState("1");
                inventoryDao.save(mediicinecabinetInventory);
            }
//            for (String deviceId : cargoIds.split(",")) {
//                if(!StringUtils.isEmpty(deviceId)){
//                    MediicinecabinetInventory inventory = inventoryDao.findOne(deviceId);
//                    deviceID = inventory.getIdDevice();
//                    inventory.setMerge(inventory.getWayerNo());
//                    inventory.setState("1");
//                    inventoryDao.save(inventory);
//                }
//            }
        }
        //计算货道数和货道容量
        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceID);
        if (mediicinedevice != null) {
            //重算货道数
            String tempSql = "SELECT\n" +
                    "\tCOUNT(DISTINCT(t.id))\n" +
                    "FROM\n" +
                    "\tt_mediicinecabinet_inventory t\n" +
                    "WHERE\n" +
                    "\tt.id_device = '"+deviceID+"'\n" +
                    "AND (t.state = '1' OR t.state = '21')";
            mediicinedevice.setAisles(String.valueOf(jdbcTemplate.queryForObject(tempSql, Integer.class)));
            //重算货道容量
            Integer noOnlineTotal1 = 0;
            //防止出现问题
            noOnlineTotal1 = Integer.parseInt(mediicinedevice.getCapacity());
            if (cargoCapacityChanged) {
                tempSql = "SELECT\n" +
                        "\tifnull(sum(t.cargo_capacity), 0) as cargoCapacity\n" +
                        "FROM\n" +
                        "\tt_mediicinecabinet_inventory t\n" +
                        "WHERE\n" +
                        "\tt.id_device = '"+mediicinedevice.getId()+"'\n" +
                        "AND t.id not in ('"+cargoIds+"')\n" +
                        "AND (t.state = '1' OR t.state = '21')";
                Map<String,Object> totalMap = jdbcTemplate.queryForMap(tempSql);
                if (totalMap != null){
                    if (totalMap.get("cargoCapacity") != null) {
                        if (isMerge) {
                            //合并货道,搜的是单列 货道,包含了现在要合并的内容,changedCapacity的是没了的
                            noOnlineTotal1 = (int) Double.parseDouble(totalMap.get("cargoCapacity").toString() );
                        } else {
                            //分离货道,主货道,也包含了现在恢复的主货道的容量
                            noOnlineTotal1 = (int) Double.parseDouble(String.valueOf(totalMap.get("cargoCapacity"))) + changedCapacity;
                        }
                    }
                }
//                mediicinedevice.setCapacity(String.valueOf(noOnlineTotal1));
//                deviceDao.save(mediicinedevice);
            if (isMerge) {
                mediicinedevice.setAisles(String.valueOf(Integer.parseInt(mediicinedevice.getAisles()) -  changedCargoNumber));
                mediicinedevice.setCapacity(String.valueOf(Integer.parseInt(mediicinedevice.getCapacity()) - changedCapacity));
            }
            if (!isMerge) {
                mediicinedevice.setAisles(String.valueOf(Integer.parseInt(mediicinedevice.getAisles()) +  changedCargoNumber));
                mediicinedevice.setCapacity(String.valueOf(Integer.parseInt(mediicinedevice.getCapacity()) + changedCapacity));
            }
//            tempSql = "SELECT\n" +
//                    "\tifnull(sum(t.cargo_capacity), 0) as cargoCapacity\n" +
//                    "FROM\n" +
//                    "\tt_mediicinecabinet_inventory t\n" +
//                    "WHERE\n" +
//                    "\tt.id_device = '"+deviceID+"'\n" +
//                    "AND (t.state = '1' OR t.state = '21')";
//
//            Map<String,Object> totalMap = jdbcTemplate.queryForMap(tempSql);
//            Integer noOnlineTotal1 = 0;
//            if (totalMap!=null){
//                if (totalMap.get("cargoCapacity") != null) {
//                    noOnlineTotal1 = (int) Double.parseDouble(totalMap.get("cargoCapacity").toString());
//                }
//            }
            mediicinedevice.setCapacity(String.valueOf(noOnlineTotal1));
            deviceDao.save(mediicinedevice);
        }
        result.put("response",ConstantUtils.SUCCESS);
        return result.toJSONString();
    }