wangzhinan 3 years ago
parent
commit
fb64bde7df

+ 1 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -181,6 +181,7 @@ public class BaseRequestMapping {
        public static final String UPDATESALESTATUS  = "/updateSaleStatus";
        public static final String UNBINDDEVICE  = "/unbindDevice";
        public static final String getDeviceListByUserId  = "/getDeviceListByUserId";
        public static final String getDeviceListWithUserId  = "/getDeviceListWithUserId";
        public static final String getUserListByDeviceId  = "/getUserListByDeviceId";
        public static final String getOutOfStockDeviceList  = "/getOutOfStockDeviceList";
        public static final String getOutOfStockDeviceListByUserId  = "/getOutOfStockDeviceListByUserId";

+ 11 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -358,8 +358,19 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
        JSONObject jsonObject = deviceService.getOutOfStockDeviceListByUserId(userId, content);
        return success(jsonObject.getJSONArray("msg"));
    }
    //getDeviceListByUserId
    @GetMapping(value = BaseRequestMapping.BaseDevice.getDeviceListWithUserId)
    @ApiOperation(value = "获取设备列表夹带userId" , notes="获取设备列表")
    public Envelop getDeviceListWithUserId( @ApiParam(name = "userId", value = "用户id")
                                                    @RequestParam(value = "userId", required = true) String userId,
                                                    @ApiParam(name = "content", value = "搜索内容")
                                                    @RequestParam(value = "content", required = false) String content) throws Exception {
        JSONObject jsonObject = deviceService.getDeviceListByUserId(userId, content);
        return success(jsonObject.getJSONArray("msg"));
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.getDetialOutOfStock)
    @ApiOperation(value = "获取缺货信息")

+ 232 - 25
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -996,32 +996,15 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            onlineCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
            sencodSql = "select count(distinct(id)) from t_mediicine_device a where a.del = 1 and a.sale_status = 1 and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
            saleCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
            //获取缺货设备
            sencodSql = "SELECT\n" +
                    "\tcount(DISTINCT(id))\n" +
                    "FROM\n" +
                    "\tt_mediicine_device\n" +
                    "WHERE\n" +
                    "\tdel = 1\n" +
                    "AND `status` = 0 and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
//            sencodSql = "SELECT\n" +
//                    "\tcount(DISTINCT(t.id))\n" +
//                    "FROM\n" +
//                    "\tt_mediicine_device t\n" +
//                    "LEFT JOIN (\n" +
//                    "\tSELECT\n" +
//                    "\t\tid_device,\n" +
//                    "\t\tsum(qty) AS qty\n" +
//                    "\tFROM\n" +
//                    "\t\tt_mediicinecabinet_inventory\n" +
//                    "\tGROUP BY\n" +
//                    "\t\tid_device\n" +
//                    ") AS tmi ON t.id = tmi.id_device\n" +
//                    "WHERE\n" +
//                    "\tt.del = 1\n" +
//                    "AND tmi.qty < (t.capacity * t.ratio) and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
                    "AND `status` = 0 and ',"+ deviceIds +",' LIKE CONCAT('%,',id,',%')";
            outCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
@ -1086,7 +1069,7 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                    "\tt_mediicine_device\n" +
                    "WHERE\n" +
                    "\tdel = 1\n" +
                    "AND `status` = 0  and ',"+ belongCommunitys +",' LIKE CONCAT('%,',a.belong_community,',%')";
                    "AND `status` = 0  and ',"+ belongCommunitys +",' LIKE CONCAT('%,',belong_community,',%')";
            outCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
        }
@ -1383,8 +1366,10 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                    "    t_mediicine_device AS t\n" +
                    "WHERE\n" +
                    "t.del = 1 AND  \n" +
                    "CONCAT(t.equ_num, t.equ_name) like '" + content +"' AND  \n" +
                    "t.`status` = 0 and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
                    "t.`status` = 0 and ',"+ deviceIds +",' LIKE CONCAT('%,',t.id,',%')\n";
            if (!StringUtils.isEmpty(content)) {
                sencodSql += " AND CONCAT(t.equ_num, t.equ_name) like '" + content +"'";
            }
             deviceList = hibenateUtils.createSQLQuery(sencodSql);
        } else {
            String belongCommunitys = "";
@ -1474,8 +1459,10 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                    "    t_mediicine_device AS t\n" +
                    "WHERE\n" +
                    "t.del = 1 AND  \n" +
                    "CONCAT(t.equ_num, t.equ_name) like '" + content +"' AND  \n" +
                    "t.`status` = 0 and ',"+ belongCommunitys +",' LIKE CONCAT('%,',a.belong_community,',%')";
                    "t.`status` = 0 and ',"+ belongCommunitys +",' LIKE CONCAT('%,',t.belong_community,',%')\n";
            if (!StringUtils.isEmpty(content)) {
                sencodSql += " AND CONCAT(t.equ_num, t.equ_name) like '" + content +"'";
            }
            deviceList = hibenateUtils.createSQLQuery(sencodSql);
@ -1514,6 +1501,226 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    }
    /**
     * 获取设备列表,userId, 数据隔离的
     * @param userId
     * @param content
     * @return
     * @throws Exception
     */
    public JSONObject getDeviceListByUserId(String userId, String content) throws Exception {
        JSONObject result = new JSONObject();
        if (StringUtils.isEmpty(userId)) {
            return result;
        }
        UserDO user = userDao.findOne(userId);
        RoleDO role = roleDao.findOne(user.getRoleId());
        List<Map<String, Object>> deviceList = null;
        if ("replenisher".equals(role.getCode())) {
            //补货员所分配的设备
            String sql = "SELECT\n" +
                    "\tdevice_id\n" +
                    "FROM\n" +
                    "\tt_mediicine_device_user\n" +
                    "WHERE\n" +
                    "\tuser_id = '" + userId +"'\n" +
                    "AND del = 1";
            //设备列表
            List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
            String deviceIds = "";
            for (Map<String, Object> stringObjectMap : list) {
                if (stringObjectMap.get("device_id") != null && !StringUtils.isEmpty(stringObjectMap.get("device_id").toString())) {
                    if (StringUtils.isEmpty(deviceIds)) {
                        deviceIds += stringObjectMap.get("device_id").toString();
                    } else {
                        deviceIds += "," +  stringObjectMap.get("device_id").toString();
                    }
                }
            }
            String sencodSql = "SELECT\n" +
                    "    t.id AS id,\n" +
                    "    t.belong_community AS belongCommunity,\n" +
                    "    t.community AS community,\n" +
                    "    t.del AS del,\n" +
                    "    t.delivery_address AS deliveryAddress,\n" +
                    "    t.detail_address AS detailAddress,\n" +
                    "    t.equ_area AS equArea,\n" +
                    "    t.equ_class AS equClass,\n" +
                    "    t.equ_info AS equInfo,\n" +
                    "    t.equ_name AS equName,\n" +
                    "    t.equ_num AS equNum,\n" +
                    "    t.equ_type AS equType,\n" +
                    "    t.fbelong_community AS fbelongCommunity,\n" +
                    "    t.machine_code AS machineCode,\n" +
                    "    t.network_status AS networkStatus,\n" +
                    "    t.poweron_test AS poweronTest,\n" +
                    "    t.reg_date AS regDate,\n" +
                    "    t.sale_status AS saleStatus,\n" +
                    "    t.signalintensity AS signalintensity,\n" +
                    "    t.upgr_adesit AS upgrAdesit,\n" +
                    "    t.`status` AS `status`,\n" +
                    "    t.card_status AS cardStatus,\n" +
                    "    t.operator AS operator,\n" +
                    "    t.pack_age AS packAge,\n" +
                    "    t.usage_flow AS usageFlow,\n" +
                    "    t.flow AS flow,\n" +
                    "    t.create_time AS createTime,\n" +
                    "    t.create_user AS createUser,\n" +
                    "    t.create_user_name AS createUserName,\n" +
                    "    t.update_time AS updateTime,\n" +
                    "    t.update_user AS updateUser,\n" +
                    "    t.update_user_name AS updateUserName,\n" +
                    "    t.aisles AS aisles,\n" +
                    "    t.capacity AS capacity,\n" +
                    "    t.ratio AS ratio,\n" +
                    "    t.cargo_capacity AS cargoCapacity,\n" +
                    "    t.layer AS layer,\n" +
                    "    t.wayer AS wayer\n" +
                    "FROM\n" +
                    "    t_mediicine_device AS t\n" +
                    "WHERE\n" +
                    "t.del = 1 AND  \n" +
                    " and ',"+ deviceIds +",' LIKE CONCAT('%,',t.id,',%')\n";
            if (!StringUtils.isEmpty(content)) {
                sencodSql += " AND CONCAT(t.equ_num, t.equ_name) like '" + content +"'";
            }
            deviceList = hibenateUtils.createSQLQuery(sencodSql);
        } else {
            String belongCommunitys = "";
            String sql = "";
            //市管理员
            if ("saasAdmin".equals(role.getCode())) {
                sql = "SELECT\n" +
                        "\tid\tas community\n" +
                        "FROM\n" +
                        "\tdm_hospital\n" +
                        "WHERE\n" +
                        "\tdel = 1";
            }
            //区域管理员
            if ("regionAdmin".equals(role.getCode())) {
                sql = "SELECT\n" +
                        "\tdh.id AS community\n" +
                        "FROM\n" +
                        "\twlyy_user_area t\n" +
                        "LEFT JOIN dm_hospital dh ON t.town = dh.town\n" +
                        "WHERE\n" +
                        "\tt.user_id = '" + userId + "'\n" +
                        "AND t.del = 1\n" +
                        "AND dh.del = 1";
            }
            //社区管理员
            if ("communityAdmin".equals(role.getCode())) {
                sql = "SELECT\n" +
                        "t.hospital AS community\n" +
                        "FROM\n" +
                        "wlyy_user_area AS t\n" +
                        "WHERE\n" +
                        "t.user_id = '" + userId + "'\n" +
                        "AND t.del = 1";
            }
            List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
            for (Map<String, Object> stringObjectMap : list) {
                if (stringObjectMap.get("community") != null && !StringUtils.isEmpty(stringObjectMap.get("community").toString())) {
                    if (StringUtils.isEmpty(belongCommunitys)) {
                        belongCommunitys += stringObjectMap.get("community").toString();
                    } else {
                        belongCommunitys += "," +  stringObjectMap.get("community").toString();
                    }
                }
            }
            String sencodSql = "SELECT\n" +
                    "    t.id AS id,\n" +
                    "    t.belong_community AS belongCommunity,\n" +
                    "    t.community AS community,\n" +
                    "    t.del AS del,\n" +
                    "    t.delivery_address AS deliveryAddress,\n" +
                    "    t.detail_address AS detailAddress,\n" +
                    "    t.equ_area AS equArea,\n" +
                    "    t.equ_class AS equClass,\n" +
                    "    t.equ_info AS equInfo,\n" +
                    "    t.equ_name AS equName,\n" +
                    "    t.equ_num AS equNum,\n" +
                    "    t.equ_type AS equType,\n" +
                    "    t.fbelong_community AS fbelongCommunity,\n" +
                    "    t.machine_code AS machineCode,\n" +
                    "    t.network_status AS networkStatus,\n" +
                    "    t.poweron_test AS poweronTest,\n" +
                    "    t.reg_date AS regDate,\n" +
                    "    t.sale_status AS saleStatus,\n" +
                    "    t.signalintensity AS signalintensity,\n" +
                    "    t.upgr_adesit AS upgrAdesit,\n" +
                    "    t.`status` AS `status`,\n" +
                    "    t.card_status AS cardStatus,\n" +
                    "    t.operator AS operator,\n" +
                    "    t.pack_age AS packAge,\n" +
                    "    t.usage_flow AS usageFlow,\n" +
                    "    t.flow AS flow,\n" +
                    "    t.create_time AS createTime,\n" +
                    "    t.create_user AS createUser,\n" +
                    "    t.create_user_name AS createUserName,\n" +
                    "    t.update_time AS updateTime,\n" +
                    "    t.update_user AS updateUser,\n" +
                    "    t.update_user_name AS updateUserName,\n" +
                    "    t.aisles AS aisles,\n" +
                    "    t.capacity AS capacity,\n" +
                    "    t.ratio AS ratio,\n" +
                    "    t.cargo_capacity AS cargoCapacity,\n" +
                    "    t.layer AS layer,\n" +
                    "    t.wayer AS wayer\n" +
                    "FROM\n" +
                    "    t_mediicine_device AS t\n" +
                    "WHERE\n" +
                    "t.del = 1 AND  \n" +
                    " and ',"+ belongCommunitys +",' LIKE CONCAT('%,',t.belong_community,',%')\n";
            if (!StringUtils.isEmpty(content)) {
                sencodSql += " AND CONCAT(t.equ_num, t.equ_name) like '" + content +"'";
            }
            deviceList = hibenateUtils.createSQLQuery(sencodSql);
        }
        for (Map<String, Object> stringObjectMap : deviceList) {
            if(!StringUtils.isEmpty(stringObjectMap.get("networkStatus"))){
                if ("1".equals(stringObjectMap.get("networkStatus").toString())) {
                    stringObjectMap.put("networkStatusName", "在线");
                }
                if ("0".equals(stringObjectMap.get("networkStatus").toString())) {
                    stringObjectMap.put("networkStatusName", "离线");
                }
            }
            if(!StringUtils.isEmpty(stringObjectMap.get("saleStatus"))){
                if ("1".equals(stringObjectMap.get("saleStatus").toString())) {
                    stringObjectMap.put("saleStatusName", "在售");
                }
                if ("2".equals(stringObjectMap.get("saleStatus").toString())) {
                    stringObjectMap.put("saleStatusName", "停售");
                }
                if ("3".equals(stringObjectMap.get("saleStatus").toString())) {
                    stringObjectMap.put("saleStatusName", "故障");
                }
            }
            if(!StringUtils.isEmpty(stringObjectMap.get("cardStatus"))){
                if ("1".equals(stringObjectMap.get("cardStatus").toString())) {
                    stringObjectMap.put("cardStatusName", "正常");
                }
                if ("2".equals(stringObjectMap.get("cardStatus").toString())) {
                    stringObjectMap.put("cardStatusName", "到期");
                }
                if ("3".equals(stringObjectMap.get("cardStatus").toString())) {
                    stringObjectMap.put("cardStatusName", "未知");
                }
            }
        }
        result.put("response", ConstantUtils.SUCCESS);
        result.put("msg",deviceList);
        return result;
    }
    /**
     * 获取所属id的缺货信息
     * @param ids