Browse Source

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

wangzhinan 4 years ago
parent
commit
e24cf20455

+ 45 - 2
svr/svr-iot/src/main/java/com/yihu/iot/controller/monitorPlatform/MonitorPlatformController.java

@ -740,8 +740,8 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    @GetMapping(value="/getEquipmentStatistics")
    @ApiOperation("设备库存、使用数、总备案、失联率、物联率")
    public Envelop getEquipmentStatistics(@RequestParam(value = "deviceType",required = false)
                                          @ApiParam(name="deviceType",value = "设备类型,1血糖仪,2血压计,5健康小屋",required = false) String deviceType,
    public Envelop getEquipmentStatistics(@RequestParam(value = "deviceType",required = true,defaultValue = "1,2,5")
                                          @ApiParam(name="deviceType",value = "设备类型,1血糖仪,2血压计,5健康小屋",required = true) String deviceType,
                                          @RequestParam(value="deviceName",required = false,defaultValue = "")
                                          @ApiParam(name="deviceName",value = "设备名称(品牌)",required = false) String deviceName,
                                          @RequestParam(value = "showLevel",defaultValue = "0")
@ -760,4 +760,47 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
        }
    }
    @ApiOperation("获取设备大类")
    @GetMapping(value ="/getDeviceTotalCategory")
    public Envelop getDeviceTotalCategory(){
        try {
            return success(iotSystemDictService.getDeviceTotalCategory());
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/iotAndLostRange",method = RequestMethod.GET)
    @ApiOperation("iot物联率 lost失联率")
    public MixEnvelop iotAndLostRange(
            @ApiParam(name="startTime",value="开始时间YYYY-MM-DD",defaultValue = "")
            @RequestParam(value="startTime",required = false) String startTime,
            @ApiParam(name="endTime",value="结束时间YYYY-MM-DD",defaultValue = "")
            @RequestParam(value="endTime",required = false) String endTime,
            @ApiParam(name="deviceType",value="设备类型",required = true)
            @RequestParam(value="deviceType",required = true,defaultValue = "1,2,5") String deviceType,
            @ApiParam(name="area",value="地区",defaultValue = "")
            @RequestParam(value="area",required = false) String area,
            @ApiParam(name="hospital",value="机构",defaultValue = "")
            @RequestParam(value="hospital",required = false) String hospital,
            @ApiParam(name="quotaCode",value="获取类型,1物联率 2失联率",required = true)
            @RequestParam(value="quotaCode",required = true) String quotaCode){
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.iotAndLostRange(startTime,endTime,deviceType,area,hospital,quotaCode));
        }catch (Exception e){
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @GetMapping(value="/getBrandsDetail")
    @ApiOperation("获取设备品牌列表")
    public Envelop getBrandsDetail(
            @ApiParam(name="deviceType",value ="设备类型",required = true)
            @RequestParam(value="deviceType",required = true,defaultValue = "1,2,5")String deviceType){
        return success(monitorPlatformService.getBrandsDetail(deviceType));
    }
}

+ 10 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/dict/IotSystemDictService.java

@ -148,4 +148,14 @@ public class IotSystemDictService extends BaseJpaService<IotSystemDictDO,IotSyst
        List<IotSystemDictVO> iotSystemDictVOS = convertToModels(listDO, new ArrayList<>(listDO.size()), IotSystemDictVO.class);
        return iotSystemDictVOS;
    }
    /**
     * 获取设备大类
     * @return
     */
    public List<JSONObject> getDeviceTotalCategory(){
        String sql ="select id,`value` from xmiot.iot_system_dict where dict_name = 'DEVICE' and del=1 ORDER BY sort";
        List<JSONObject> list = myJdbcTemplate.queryJson(sql,new Object[]{});
        return list;
    }
}

+ 135 - 9
svr/svr-iot/src/main/java/com/yihu/iot/service/monitorPlatform/MonitorPlatformService.java

@ -1066,19 +1066,28 @@ public class MonitorPlatformService  {
     */
    public JSONObject getBrandsAndManufacturer(){
        try {
            String sql  = "select count(DISTINCT pd.device_name) as total,pd.device_name,wd.device_name,wd.manufacturer from wlyy.wlyy_patient_device pd,device.wlyy_devices wd \n" +
            String sql  = "select count(DISTINCT A.device_name) as total,A.device_name,A.manufacturer from (\n" +
                    "select pd.device_name,wd.manufacturer from wlyy.wlyy_patient_device pd,device.wlyy_devices wd\n" +
                    "where pd.device_sn = wd.device_code \n" +
                    "and wd.manufacturer_code is not null and wd.manufacturer_code <>'' \n" +
                    "group by wd.manufacturer_code \n" +
                    "and wd.manufacturer_code is not null and wd.manufacturer_code <>''\n" +
                    "GROUP BY wd.manufacturer_code,pd.device_name\n" +
                    "UNION\n" +
                    "select '健康小屋' device_name,manufacturer from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name\n" +
                    ")A\n" +
                    "GROUP BY A.manufacturer\n" +
                    "ORDER BY total desc";
            List<Map<String,Object>>Manufacturers = jdbcTemplate.queryForList(sql);
            JSONObject result = new JSONObject();
            JSONArray arr = JSONArray.parseArray(JSON.toJSONString(Manufacturers));
            result.put("Manufacturers",arr);
            sql = "select count(DISTINCT pd.device_name)from wlyy.wlyy_patient_device pd,device.wlyy_devices wd \n" +
            sql = "select count(DISTINCT A.device_name)from (\n" +
                    "select pd.device_name from wlyy.wlyy_patient_device pd,device.wlyy_devices wd\n" +
                    "where pd.device_sn = wd.device_code \n" +
                    "and wd.manufacturer_code is not null and wd.manufacturer_code <>'' \n" +
                    "ORDER BY pd.device_name desc  ";
                    "and wd.manufacturer_code is not null and wd.manufacturer_code <>''\n" +
                    "GROUP BY wd.manufacturer_code,pd.device_name\n" +
                    "UNION\n" +
                    "select '健康小屋' device_name from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name\n" +
                    ")A";
            Integer BrandsCount = jdbcTemplate.queryForObject(sql,Integer.class);
            result.put("Brands",BrandsCount);
@ -1162,8 +1171,8 @@ public class MonitorPlatformService  {
                }
                result.put("deviceInfo",arr);//设备信息统计
                //统计物联率设备,失联设备
                sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ");
                sql.append("where d.device_sn in(select DISTINCT device_sn from device.wlyy_patient_health_index where device_sn<>'') "+sqlCondition+" ");
                sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ,wlyy.wlyy_sign_family f   ");
                sql.append("where  f.`status`>0 and f.patient = d.`user` and d.device_sn in(select DISTINCT device_sn from device.wlyy_patient_health_index where device_sn<>'') "+sqlCondition+" ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                    sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
                }
@ -1184,7 +1193,7 @@ public class MonitorPlatformService  {
                result.put("lostContact",lostContact);
            }
            //deviceType包含小屋且设备名称为空||deviceType包含小屋且设备名称为健康小屋。
          if ((deviceType.contains("5")&&org.apache.commons.lang3.StringUtils.isBlank(deviceName))||(deviceType.contains("5")&&org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)&&"健康小屋".equals(deviceName))){
          if ((deviceType.contains("5")&&org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType))||(deviceType.contains("5")&&org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)&&"健康小屋".equals(deviceName))){
                String sql = "select COUNT(*) from xmiot.iot_equipmet_detail";
                Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
                JSONObject tmp = new JSONObject();
@ -1236,4 +1245,121 @@ public class MonitorPlatformService  {
        return filesize + "%";
    }
    /**
     * 获取物联率与失联率
     * @param startTime
     * @param endTime
     * @param deviceType
     * @param area
     * @param hospital
     * @param quotaCode
     * @return
     */
    public JSONObject iotAndLostRange(String startTime,String endTime,
                                      String deviceType,String area,String hospital,String quotaCode){
        JSONObject result = new JSONObject();
        StringBuffer sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ,wlyy.wlyy_sign_family f WHERE f.`status`>0 and f.patient = d.`user`  ");
        StringBuffer sqlCondition = new StringBuffer(" where 1=1 ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
            sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
        }
        Integer grantCount = jdbcTemplate.queryForObject(sql.toString(),Integer.class);//单体征设备发放总数
        result.put("totalAll",grantCount);
        Integer total=0;
        if("1".equals(quotaCode)){
            //物联
            sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ,wlyy.wlyy_sign_family f ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
                sql.append("LEFT JOIN wlyy.dm_hospital dh on f.hospital = dh.`code` ");
                sqlCondition.append("and dh.town='"+area+"' ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)){
                    sqlCondition.append("and dh.code='"+hospital+"' ");
                }
            }
            sqlCondition.append("and  f.`status`>0 and f.patient = d.`user` and d.device_sn in(select DISTINCT device_sn from device.wlyy_patient_health_index where device_sn<>''  ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)&&org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)){
                sqlCondition.append("and record_date >='"+startTime+" 00:00:00' and record_date<='"+endTime+" 23:59:59'  ");
            }
            sqlCondition.append(" ) and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
            sql.append(sqlCondition);
            total=jdbcTemplate.queryForObject(sql.toString(),Integer.class);
        }
        //失联
        if("2".equals(quotaCode)){
            sql = new StringBuffer("SELECT count(*) from wlyy.wlyy_patient_device d,wlyy.wlyy_sign_family f");
            sqlCondition = new StringBuffer(" where 1=1 ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
                sql.append("LEFT JOIN wlyy.dm_hospital dh on f.hospital = dh.`code` ");
                sqlCondition.append("and dh.town='"+area+"' ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)){
                    sqlCondition.append("and dh.code='"+hospital+"' ");
                }
            }
            sqlCondition.append("and f.`status`>0 and f.patient = d.`user` ");
            sqlCondition.append("  and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
            sqlCondition.append("and d.device_sn not in (select device_sn from ( select device_sn,MAX(record_date) record_date from device.wlyy_patient_health_index where device_sn<>'' GROUP BY device_sn)a ");
            sqlCondition.append("where TIMESTAMPDIFF(DAY,record_date,NOW()) <= 7)");
            sql.append(sqlCondition);
            total=jdbcTemplate.queryForObject(sql.toString(),Integer.class);
        }
        if ((org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)&&deviceType.contains("5"))||org.apache.commons.lang3.StringUtils.isBlank(deviceType)){
            String sqll = "select COUNT(*) from xmiot.iot_equipmet_detail";
            Integer count = jdbcTemplate.queryForObject(sqll,Integer.class);
            result.put("totalAll",grantCount+count);
            count =0;
            if("1".equals(quotaCode)){//小屋物联率
                sql= new StringBuffer("select count(*) from xmiot.iot_equipmet_detail ");
                sqlCondition = new StringBuffer(" where 1=1 ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
                    sqlCondition.append("and belong_are_code='"+area+"' ");
                }
                sqlCondition.append("and device_code in (select DISTINCT sn device_model from xmiot.wlyy_iot_m where 1=1 ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)&&org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)){
                    sqlCondition.append("and create_time >='"+startTime+" 00:00:00' and create_time<='"+endTime+" 23:59:59'  ");
                }
                sql.append(sqlCondition+")");
                count = jdbcTemplate.queryForObject(sql.toString(),Integer.class);
            }
            if("2".equals(quotaCode)){//小屋失联数0
                count=0;
            }
            result.put("total",total+count);//互联设备\失联设备数量
        }
        DecimalFormat df = new DecimalFormat("0.00");
        if (result.getInteger("totalAll") > 0) {
            result.put("totalRange", df.format(result.getDouble("total") > 0.0 ? ((result.getDouble("total")) / (result.getInteger("totalAll") * 1.0000) * 100) : 0.0) );
        } else {
            result.put("totalRange", 0.0 );
        }
        return result;
    }
    /**
     * 获取设备品牌详细
     * @param deviceType
     * @return
     */
    public JSONObject getBrandsDetail(String deviceType){
        try {
            StringBuffer sql = new StringBuffer("select DISTINCT A.device_name from (\n" +
                    "select pd.device_name from wlyy.wlyy_patient_device pd,device.wlyy_devices wd\n" +
                    "where pd.device_sn = wd.device_code \n" +
                    "and wd.manufacturer_code is not null and wd.manufacturer_code <>'' ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                sql.append("and pd.category_code in ('").append(deviceType.replace(",","','")).append("') ");
            }
            sql.append("GROUP BY wd.manufacturer_code,pd.device_name ");
            if ((org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)&&deviceType.contains("5"))||org.apache.commons.lang3.StringUtils.isBlank(deviceType)){
                sql.append("UNION select '健康小屋' device_name from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name");
            }
            sql.append(")A");
            List<String> list = jdbcTemplate.queryForList(sql.toString(),String.class);
            JSONObject result = new JSONObject();
            result.put("brands",list);
            return result;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}