Pārlūkot izejas kodu

Merge branch 'medicare' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into medicare

wangzhinan 3 gadi atpakaļ
vecāks
revīzija
8b88925729

+ 89 - 33
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -1560,6 +1560,12 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    }
    /**
     * 通过设备id获取设备信息
     * @param deviceId
     * @return
     * @throws Exception
     */
    public JSONObject getOneDeviceInfo(String deviceId) throws Exception{
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(deviceId)){
@ -1575,10 +1581,26 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("device",device);
        jsonObject.put("totalCargo", device.getAisles());   //货道合并/解离
        //货道总数----->写死
        String tempSql = "SELECT\n" +
                "\tcount(distinct(t.layer_no)) as layerNum\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory t\n" +
                "WHERE\n" +
                "\tt.id_device = '"+device.getId()+"'";
        int layerNum = jdbcTemplate.queryForObject(tempSql, Integer.class);
        tempSql = "SELECT\n" +
                "\tcount(distinct(t.wayer_no)) as wayerNum\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory t\n" +
                "WHERE\n" +
                "\tt.id_device = '"+device.getId()+"'\n" +
                "AND t.layer_no = '1'";
        int wayerNum = jdbcTemplate.queryForObject(tempSql, Integer.class);
        jsonObject.put("totalCargo", layerNum * wayerNum);
        //设备容量
        jsonObject.put("deviceCapacity", device.getCapacity());
        String tempSql = "SELECT\n" +
        tempSql = "SELECT\n" +
                "\tIFNULL(\n" +
                "\t\t(\n" +
                "\t\t\tSELECT\n" +
@ -1607,7 +1629,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                "\tt.id_device = '"+ device.getId() +"'\n" +
                "AND (t.state = '1' OR t.state = '21')";
        int outOfStock = jdbcTemplate.queryForObject(tempSql, Integer.class);
        //在架库存数
        //缺货库存
        jsonObject.put("outOfStock", outOfStock);
@ -1635,6 +1657,30 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        //关闭货道
        int closedCargo = jdbcTemplate.queryForObject(tempSql, Integer.class);
        jsonObject.put("closedCargo", closedCargo);
        tempSql = "SELECT\n" +
                "\tCOUNT(DISTINCT(t.id))\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory t\n" +
                "WHERE\n" +
                "\tt.id_device = '" + device.getId() + "'\n" +
                "and t.cargo_state = '1'\n" +
                "AND (t.state = '1'\n" +
                "OR t.state = '21')";
        //关闭货道
        int openedCargo = jdbcTemplate.queryForObject(tempSql, Integer.class);
        jsonObject.put("openedCargo", openedCargo);
        tempSql = "SELECT\n" +
                "\tCOUNT(DISTINCT(t.id))\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory t\n" +
                "WHERE\n" +
                "\tt.id_device = '" + device.getId() + "'\n" +
                "and t.fault_state = '1'\n" +
                "AND (t.state = '1'\n" +
                "OR t.state = '21')";
        //关闭货道
        int faultCargo = jdbcTemplate.queryForObject(tempSql, Integer.class);
        jsonObject.put("faultCargo", faultCargo);
        //1补货,2换货,3上架,4下架
        jsonObject.put("inventoryList",inventoryRecordDao.findMedicineDrugInventoryRecordsByDeviceIdAndEquNumAndType(device.getId(), device.getEquNum(),"1"));
@ -4817,7 +4863,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String setMedicineWarrayRule(Boolean isAll,String equNums, String jsonRules, String userId){
    public String setMedicineWarrayRule(Boolean isAll,String equNums, String jsonRules, String userId) throws Exception {
        JSONObject result = new JSONObject();
        JSONObject jsonObject = JSONObject.parseObject(jsonRules);
        JSONArray ruleArray = jsonObject.getJSONArray("rules");
@ -4826,9 +4872,33 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        List<RuleDO> ruleDOS = new ArrayList<>();
        for (Object obj : ruleArray) {
            RuleDO ruleDO = null;
            try {
                ruleDO = objectMapper.readValue(obj.toString(), RuleDO.class);
            } catch (IOException e) {
                result.put("msg", "convert org jsonObject to RuleDO failed," + e.getCause());
                result.put("response", ConstantUtils.FAIL);
                return result.toJSONString();
            }
            ruleDOS.add(ruleDO);
        }
        ruleDOS = ruleDOS.stream().sorted(Comparator.comparingInt(RuleDO::getLower)).collect(Collectors.toList());
        for (int i = 0; i < ruleDOS.size(); i++) {
            if (i + 1 < ruleDOS.size()) {
                if (ruleDOS.get(i).getUpper() > ruleDOS.get(i+1).getLower()) {
                    result.put("msg", "当前规则有重复,请删除重复规则后重试");
                    result.put("response", ConstantUtils.FAIL);
                    return result.toJSONString();
                }
            }
        }
        UserDO user = userDao.findOne(userId);
        RoleDO role = roleDao.findOne(user.getRoleId());
        if (role==null){
            throw new Exception("角色为空!");
        }
        String belongCommunitys = "";
        String tempSql = "";
        //获取管理员所在社区code字符串
@ -4912,15 +4982,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            }
            List<Mediicinedevice> deviceList = deviceDao.findMediicinedevicesByBelongCommunityInAndDel(belongCommunitys.split(","), "1");
            for (Mediicinedevice mediicinedevice : deviceList) {
                for (Object obj : ruleArray) {
                    RuleDO ruleDO = null;
                    try {
                        ruleDO = objectMapper.readValue(obj.toString(), RuleDO.class);
                    } catch (IOException e) {
                        result.put("msg", "convert org jsonObject to RuleDO failed," + e.getCause());
                        result.put("response", ConstantUtils.FAIL);
                        return result.toJSONString();
                    }
                for (RuleDO ruleDO : ruleDOS) {
                    MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
                    medicineWarrayRule.setDel(1);
                    medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
@ -4934,28 +4996,22 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                    medicineWarrayRule.setCreateUser(userId);
                    medicineWarrayRuleDao.save(medicineWarrayRule);
                }
//                if (!StringUtils.isEmpty(rule1)) {
//                for (Object obj : ruleArray) {
//                    RuleDO ruleDO = null;
//                    try {
//                        ruleDO = objectMapper.readValue(obj.toString(), RuleDO.class);
//                    } catch (IOException e) {
//                        result.put("msg", "convert org jsonObject to RuleDO failed," + e.getCause());
//                        result.put("response", ConstantUtils.FAIL);
//                        return result.toJSONString();
//                    }
//                    MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
//                    medicineWarrayRule.setDel(1);
//                    medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
//                    medicineWarrayRule.setLower(Integer.parseInt(rule1.split(",")[0]));
//                    medicineWarrayRule.setUpper(Integer.parseInt(rule1.split(",")[1]));
//                    medicineWarrayRule.setMatchValue(Integer.parseInt(rule1.split(",")[2]));
//                    medicineWarrayRule.setMatchUnit(rule1.split(",")[3]);
//                    medicineWarrayRule.setUpdateUser(userId);
//                    medicineWarrayRule.setUpdateTime(new Date());
//                    medicineWarrayRule.setCreateTime(new Date());
//                    medicineWarrayRule.setCreateUser(userId);
//                    medicineWarrayRuleDao.save(medicineWarrayRule);
//                }
//                if (!StringUtils.isEmpty(rule2)) {
//                    MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
//                    medicineWarrayRule.setDel(1);
//                    medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
//                    medicineWarrayRule.setLower(Integer.parseInt(rule2.split(",")[0]));
//                    medicineWarrayRule.setUpper(Integer.parseInt(rule2.split(",")[1]));
//                    medicineWarrayRule.setMatchValue(Integer.parseInt(rule2.split(",")[2]));
//                    medicineWarrayRule.setMatchUnit(rule2.split(",")[3]);
//                    medicineWarrayRule.setLower(ruleDO.getLower());
//                    medicineWarrayRule.setUpper(ruleDO.getUpper());
//                    medicineWarrayRule.setMatchValue(ruleDO.getMatchValue());
//                    medicineWarrayRule.setMatchUnit(ruleDO.getMatchUnit());
//                    medicineWarrayRule.setUpdateUser(userId);
//                    medicineWarrayRule.setUpdateTime(new Date());
//                    medicineWarrayRule.setCreateTime(new Date());