liubing 4 vuotta sitten
vanhempi
commit
1f0f374e55

+ 19 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/monitorPlatform/MonitorPlatformController.java

@ -830,4 +830,23 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
        }
    }
    @RequestMapping(value="getDeviceTotalCount",method = RequestMethod.GET)
    @ApiOperation("获取设备使用量、库存量、总备案")
    public Envelop getDeviceTotalCount(@ApiParam(name="startTime",value="开始时间yyyy-MM-dd",defaultValue = "")
                                           @RequestParam(value="startTime",required = false) String startTime,
                                       @ApiParam(name="endTime",value="结束时间",defaultValue = "")
                                       @RequestParam(value="endTime",required = false) String endTime,
                                       @ApiParam(name="deviceType",value="设备类型",defaultValue = "")
                                           @RequestParam(value="deviceType",required = false) String deviceType,
                                       @ApiParam(name="area",value="地区",defaultValue = "")
                                           @RequestParam(value="area",required = false) String area){
        try {
            return success(monitorPlatformService.getDeviceTotalCount(startTime, endTime, deviceType, area));
        }
        catch (Exception e){
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
}

+ 13 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/common/ElasticSearchQueryGenerator.java

@ -4,8 +4,10 @@ package com.yihu.iot.service.common;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonArray;
import com.yihu.elasticsearch.ElasticSearchPool;
import com.yihu.iot.datainput.enums.DataTypeEnum;
import com.yihu.iot.datainput.service.DataStandardConvertService;
@ -427,6 +429,17 @@ public class ElasticSearchQueryGenerator {
                if("null".equals(andOr)) {
                    boolQueryBuilder.must(matchQueryBuilder);
                }
            }
            else if(condition.equals("in")) {
                List<String> list= (List<String>) JSONArray.parse(JSON.toJSONString(param.get("value")));
                String[] tmpString = list.toArray(new String[]{});
                StringBuffer tmp = new StringBuffer(""+list.toString()) ;
                TermsQueryBuilder termsQueryBuilder = QueryBuilders.termsQuery(field,tmpString);
                if("and".equals(andOr)) {
                    boolQueryBuilder.must(termsQueryBuilder);
                }else if("or".equals(andOr)) {
                    boolQueryBuilder.should(termsQueryBuilder);
                }
            }else if(condition.equals("=")) {
                MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery(field, value);
                if("and".equals(andOr)) {

+ 1 - 1
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotPatientDeviceService.java

@ -306,7 +306,7 @@ public class IotPatientDeviceService extends BaseJpaService<IotPatientDeviceDO,
                if (StringUtils.isNotEmpty(idCard)){
                    sql = sql +" and t.idcard = '"+idCard+"'";
                    nameList = jdbcTempalte.queryForList(sql);
                }if (StringUtils.isNotEmpty(snCoed)){
                }if (StringUtils.isNoneBlank(snCoed)){
                    sqlEqt = sqlEqt +" and t.device_code = '"+snCoed+"'";
                    deviceList = jdbcTempalte.queryForList(sqlEqt);
                }

+ 68 - 28
svr/svr-iot/src/main/java/com/yihu/iot/service/monitorPlatform/MonitorPlatformService.java

@ -82,7 +82,6 @@ public class MonitorPlatformService  {
    public MixEnvelop<LocationDataVO, LocationDataVO> findDeviceLocations(Integer diseaseCondition, Integer page, Integer size, String type,String deviceType,String deviceName) throws IOException {
        MixEnvelop<LocationDataVO, LocationDataVO> envelop = new MixEnvelop<>();
        MixEnvelop<LocationDataVO, LocationDataVO> envelopTmp = null;
        JSONArray jsonArray = new JSONArray();
        Integer total = 0;
        if(org.apache.commons.lang.StringUtils.isNotBlank(type)){
            String re = searchpatientdevicesn(type, page, size);
@ -115,38 +114,61 @@ public class MonitorPlatformService  {
            List<LocationDataVO> euipmentList = new ArrayList<>();
            int totalEqCount=0;
            int totalCount=0;
            //查找全部
            if(diseaseCondition!=null){
                JSONObject json = new JSONObject();
                json.put("andOr","and");
                json.put("field","diseaseCondition");
                json.put("condition","=");
                json.put("value",diseaseCondition);
                jsonArray.add(json);
            }
            //小屋总数
            if(deviceType.contains("5")){
               totalEqCount = iotEqtDetailService.getEquipmentCount();
                if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&"健康小屋".equals(deviceName))){
                    totalEqCount = iotEqtDetailService.getEquipmentCount();
                }
            }
            String[] categoryCodes= deviceType.split(",");
            if(categoryCodes.length==1&&"5".equals(deviceType)){
                euipmentList = iotEqtDetailService.getEquipmentLocation(page,size);
                envelop.getDetailModelList().addAll(euipmentList);
                if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&"健康小屋".equals(deviceName))){
                    euipmentList = iotEqtDetailService.getEquipmentLocation(page,size);
                    envelop.getDetailModelList().addAll(euipmentList);
                }
            }
            else{
                if(deviceType.contains("5")){
                    euipmentList = iotEqtDetailService.getEquipmentLocation(page,size);
                    envelop.getDetailModelList().addAll(euipmentList);
                    if (org.apache.commons.lang3.StringUtils.isBlank(deviceName)||(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) &&"健康小屋".equals(deviceName))){
                        euipmentList = iotEqtDetailService.getEquipmentLocation(page,size);
                        envelop.getDetailModelList().addAll(euipmentList);
                    }
                }
                for (String categoryCode:categoryCodes){
                    JSONObject json = new JSONObject();
                    JSONArray jsonArray = new JSONArray();
                    if(diseaseCondition!=null){
                        json.put("andOr","and");
                        json.put("field","diseaseCondition");
                        json.put("condition","=");
                        json.put("value",diseaseCondition);
                        jsonArray.add(json);
                    }
                     if(!"5".equals(categoryCode)){
                         JSONObject json = new JSONObject();
                         json.put("andOr","and");
                         json.put("field","categoryCode");
                         json.put("condition","=");
                         json.put("value",Integer.parseInt(categoryCode));
                         jsonArray.add(json);
                         json = new JSONObject();
                         if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
                             String sql="select DISTINCT device_code from device.wlyy_devices where device_name like '%"+deviceName+"%'";
                             List<String> listTmp = jdbcTemplate.queryForList(sql,String.class);
                             if (listTmp.size()!=0){
                                 StringBuffer tmp = new StringBuffer(listTmp.toString());
                                 tmp =tmp.deleteCharAt(0);
                                 tmp = tmp.deleteCharAt(tmp.length()-1);
                                 json.put("andOr","and");
                                 json.put("field","deviceSn");
                                 json.put("condition","in");
                                 json.put("value",listTmp);
                                 jsonArray.add(json);
                             }
                         }
                         else{
                             json = new JSONObject();
                             json.put("andOr","and");
                             json.put("field","categoryCode");
                             json.put("condition","=");
                             json.put("value",Integer.parseInt(categoryCode));
                             jsonArray.add(json);
                         }
                         JSONObject jsonObject = new JSONObject();
                         jsonObject.put("filter",jsonArray);
                         jsonObject.put("page",page);
@ -156,8 +178,8 @@ public class MonitorPlatformService  {
                         //figureLabelSerachService.getFigureLabelByList(locationDataVOList);
                         envelop.getDetailModelList().addAll(list2);
                         totalCount += iotPatientDeviceService.getESCount(jsonObject.toString());
                         jsonArray.remove(json);
                     }
                     if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)) break;//通过deviceName查询的不过滤categpry(即所有设备中查找符合)
                }
            }
            envelop.setTotalCount(totalCount>totalEqCount?totalCount:totalEqCount);
@ -1249,9 +1271,9 @@ public class MonitorPlatformService  {
    public String getRange(int first, int second, int i) {
        if (second == 0 && first > 0) {
            return "100%";
            return "100";
        } else if (second == 0 && first == 0) {
            return "0.00%";
            return "0.00";
        }
        float size = (float) (first * 100) / second;
        DecimalFormat df = new DecimalFormat("0.00");//格式化小数,不足的补0
@ -1316,9 +1338,10 @@ public class MonitorPlatformService  {
            sql.append(sqlCondition);
            total=jdbcTemplate.queryForObject(sql.toString(),Integer.class);
        }
        Integer count =0;
        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);
             count = jdbcTemplate.queryForObject(sqll,Integer.class);
            result.put("totalAll",grantCount+count);
            count =0;
            if("1".equals(quotaCode)){//小屋物联率
@ -1339,6 +1362,9 @@ public class MonitorPlatformService  {
            }
            result.put("total",total+count);//互联设备\失联设备数量
        }
        else{
            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) );
@ -1377,7 +1403,6 @@ public class MonitorPlatformService  {
        }
    }
    public JSONObject getDeviceData(){
        JSONObject object = new JSONObject();
        //血糖仪数量
@ -1415,7 +1440,7 @@ public class MonitorPlatformService  {
    }
    public JSONArray getSearchTags(){
        String sql = "select id,`value` from xmiot.iot_system_dict where dict_name='DEVICE' and del=1;";
        String sql = "select id,`value` from xmiot.iot_system_dict where dict_name='DEVICE' and (value='组合一体机' or value ='单体征测量仪') and del=1;";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        JSONArray result = new JSONArray();
        for (Map<String,Object> map :list){
@ -1440,4 +1465,19 @@ public class MonitorPlatformService  {
        return  result;
    }
    public JSONObject getDeviceTotalCount(String startTime,String endTime,String deviceType,String area){
        String url = "/wlyygc/iot_monitoring/getDeviceTotalCount";
        Map<String, Object> params = new HashMap<>();
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        String response = sendGet(url,params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
            return json.getJSONObject("data");
        }
        return new JSONObject();
    }
}