Explorar el Código

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

wangjun hace 4 años
padre
commit
136b403fda

+ 32 - 1
svr/svr-iot/src/main/java/com/yihu/iot/controller/monitorPlatform/MonitorPlatformController.java

@ -2,6 +2,7 @@ package com.yihu.iot.controller.monitorPlatform;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.iot.service.company.IotCompanyService;
import com.yihu.iot.service.device.IotPatientDeviceService;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.iot.service.equipment.IotEqtDetailService;
@ -45,6 +46,8 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    private IotPatientDeviceService iotPatientDeviceService;
    @Autowired
    private IotEqtDetailService iotEqtDetailService;
    @Autowired
    private IotCompanyService iotCompanyService;
    @PostMapping(value = IotRequestMapping.PatientDevice.addPatientDevice)
@ -724,9 +727,37 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    public Envelop getEquipmentDetail(@RequestParam(value = "deviceSn",required = true)
                             @ApiParam(name="deviceSn",value ="设备SN码",required = true)String deviceSn){
        return success(monitorPlatformService.getEquipmentDetail(deviceSn));
    }
    @GetMapping(value ="/getBrandsAndManufacturer")
    @ApiOperation("设备品牌以及商家")
    public Envelop getBrandsAndManufacturer(){
        return success(monitorPlatformService.getBrandsAndManufacturer());
    }
    @GetMapping(value="/getEquipmentStatistics")
    @ApiOperation("设备库存、使用数、总备案、失联率、物联率")
    public Envelop getEquipmentStatistics(@RequestParam(value = "deviceType",required = false)
                                          @ApiParam(name="deviceType",value = "设备类型,1血糖仪,2血压计,5健康小屋",required = false) String deviceType,
                                          @RequestParam(value="deviceName",required = false,defaultValue = "")
                                          @ApiParam(name="deviceName",value = "设备名称(品牌)",required = false) String deviceName,
                                          @RequestParam(value = "showLevel",defaultValue = "0")
                                          @ApiParam(name="showLevel",value ="下转层次,默认0设备大类,1设备类型,2设备品牌") String showLevel){
        return success(monitorPlatformService.getEquipmentStatistics(deviceType, deviceName, showLevel));
    }
    @ApiOperation("大屏应用服务")
    @RequestMapping(value = "/getAppService" , method = RequestMethod.GET)
    public Envelop getAppService() {
        try {
            return success(iotCompanyService.getAppService());
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
}

+ 4 - 3
svr/svr-iot/src/main/java/com/yihu/iot/controller/platform/IotInterfaceController.java

@ -1,5 +1,6 @@
package com.yihu.iot.controller.platform;
import com.yihu.iot.model.AppServiceCount;
import com.yihu.iot.service.company.IotCompanyService;
import com.yihu.iot.service.platform.IotCompanyAppInterfaceService;
import com.yihu.iot.service.platform.IotInterfaceLogService;
@ -10,6 +11,7 @@ import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import com.yihu.jw.restmodel.iot.company.IotCompanyVO;
import com.yihu.jw.restmodel.iot.platform.IotAppInterfacesVO;
import com.yihu.jw.restmodel.iot.platform.IotInterfaceLogVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.iot.IotRequestMapping;
@ -20,6 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
@ -412,7 +416,4 @@ public class IotInterfaceController extends EnvelopRestEndpoint {
    }
}

+ 29 - 0
svr/svr-iot/src/main/java/com/yihu/iot/model/AppServiceCount.java

@ -0,0 +1,29 @@
package com.yihu.iot.model;
/***
 * @ClassName: AppServiceCount
 * @Description:
 * @Auther: shi kejing
 * @Date: 2020/11/18 15:45
 */
public class AppServiceCount {
    private int count;
    private String appName;
    public int getCount() {
        return count;
    }
    public void setCount(int count) {
        this.count = count;
    }
    public String getAppName() {
        return appName;
    }
    public void setAppName(String appName) {
        this.appName = appName;
    }
}

+ 25 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/company/IotCompanyService.java

@ -1,8 +1,10 @@
package com.yihu.iot.service.company;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.company.*;
import com.yihu.iot.dao.platform.IotCompanyAppInterfaceDao;
import com.yihu.iot.dao.platform.IotInterfaceLogDao;
import com.yihu.iot.model.AppServiceCount;
import com.yihu.iot.service.useragent.UserAgent;
import com.yihu.jw.entity.iot.company.*;
import com.yihu.jw.entity.iot.platform.IotCompanyAppInterfaceDO;
@ -1157,4 +1159,27 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
        return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_create);
    }
    public JSONObject getAppService(){
        JSONObject object = new JSONObject();
        String str = "SELECT SUM(b.count) count,b.app_name appName\n" +
                "FROM (SELECT COUNT(id) fali,app_name,interface_name FROM xmiot.iot_interface_log  WHERE state=0 GROUP BY app_name,interface_name) c\n" +
                "RIGHT JOIN (SELECT count(id) count,app_name,interface_name,work_type FROM xmiot.iot_interface_log WHERE app_name IS NOT NULL\n" +
                "GROUP BY app_name,interface_name) b ON c.app_name=b.app_name AND c.interface_name=b.interface_name\n" +
                "GROUP BY b.app_name ORDER BY count DESC";
        String str1 = "SELECT SUM(b.count) count,b.app_name appName\n" +
                "FROM (SELECT COUNT(id) fali,app_name,interface_name FROM xmiot.iot_interface_log  WHERE state=0 GROUP BY app_name,interface_name) c\n" +
                "RIGHT JOIN (SELECT count(id) count,app_name,interface_name,work_type FROM xmiot.iot_interface_log WHERE app_name IS NOT NULL\n" +
                "GROUP BY app_name,interface_name) b ON c.app_name=b.app_name AND c.interface_name=b.interface_name\n" +
                "GROUP BY b.app_name ORDER BY count DESC limit 0,3";
        List<AppServiceCount> counts = jdbcTemplate.query(str,new BeanPropertyRowMapper<>(AppServiceCount.class));
        List<AppServiceCount> counts1 = jdbcTemplate.query(str1,new BeanPropertyRowMapper<>(AppServiceCount.class));
        object.put("appcount",counts.size());
        object.put("sortList",counts1);
        object.put("medicalcount",0);//目前暂无医疗机构接入,默认0家。
        return object;
    }
}

+ 182 - 2
svr/svr-iot/src/main/java/com/yihu/iot/service/monitorPlatform/MonitorPlatformService.java

@ -3,6 +3,7 @@ package com.yihu.iot.service.monitorPlatform;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.yihu.iot.dao.dict.IotSystemDictDao;
import com.yihu.iot.dao.equipment.IotEquipmentDetailDao;
import com.yihu.iot.service.common.MyJdbcTemplate;
@ -16,12 +17,14 @@ import com.yihu.jw.entity.iot.equipment.IotEquipmentDetailDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.util.http.HttpClientUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.util.Json;
import iot.device.LocationDataVO;
import org.apache.http.Consts;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
@ -30,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.DecimalFormat;
import java.time.temporal.Temporal;
import java.util.*;
/**
@ -38,8 +42,8 @@ import java.util.*;
@Service
public class MonitorPlatformService  {
    @Value("${spring.wlyy.url}")
    private String wlyyUrl;
//    @Value("${spring.wlyy.url}")
    private String wlyyUrl = "http://127.0.0.1:8080/";
    @Value("${spring.wlyy.appid}")
    private String appid;
    @Value("${spring.wlyy.appsecret}")
@ -68,6 +72,8 @@ public class MonitorPlatformService  {
    private IotSystemDictDao iotSystemDictDao;
    @Autowired
    private IotInterfaceLogService iotInterfaceLogService;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 获取位置信息
@ -1053,7 +1059,181 @@ public class MonitorPlatformService  {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 获取设备品牌以及商家品牌排行
     */
    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" +
                    "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" +
                    "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" +
                    "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  ";
            Integer BrandsCount = jdbcTemplate.queryForObject(sql,Integer.class);
            result.put("Brands",BrandsCount);
            result.put("manufacturerCount",arr.size());
            return result;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 谁设备库存、使用中、总备案、物联率、失联率
     * @param deviceType
     * @param deviceName
     * @param showLevel
     * @return
     */
    public JSONObject getEquipmentStatistics(String deviceType,String deviceName,String showLevel){
        try {
            JSONObject result = new JSONObject();
            JSONArray arrTmp = new JSONArray();
            result.put("deviceInfo",arrTmp);
            result.put("iotCount",0);
            result.put("grantCount",0);
            result.put("lostContact",0);
            if (deviceType.contains("1")||deviceType.contains("2")) {
                StringBuffer sql = new StringBuffer("SELECT a.category_code type,a.device_name,a.c as 'using',b.c-a.c as 'stock',b.c as 'total' from ( ");
                StringBuffer sqlCondition = new StringBuffer();
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
                    sqlCondition.append("and d.device_name='"+deviceName+"' ");
                }
                sql.append("SELECT d.category_code,d.device_name, COUNT(*) c from wlyy.wlyy_patient_device d,wlyy.wlyy_sign_family f WHERE f.`status`>0 and f.patient = d.`user` "+sqlCondition+" ");
                if ("0".equals(showLevel)){//组合一体机(5健康小屋,取自物联网),单体征测量仪(2血压计、1血糖仪)
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                        sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("'))a, ");
                    }
                    sql.append("(SELECT d.category_code,d.device_name,COUNT(*) c from wlyy.wlyy_patient_device d where 1=1 "+sqlCondition+" ");
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                        sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("'))b ");
                    }
                }
                else if("1".equals(showLevel)){ //血压计,血糖仪。。。
                    sql.append("GROUP BY d.category_code )a, ");
                    sql.append("(SELECT d.category_code,d.device_name,COUNT(*) c from wlyy.wlyy_patient_device d where 1=1 "+sqlCondition+" ");
                    sql.append("GROUP BY d.category_code )b ");
                    sql.append("WHERE a.category_code = b.category_code ");
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                        sql.append("and a.category_code in ('").append(deviceType.replace(",","','")).append("') ");
                    }
                }else if ("2".equals(showLevel)){//XX血压计1,XX血压计1
                    sql.append("GROUP BY d.category_code,d.device_name) a, ");
                    sql.append("(SELECT d.category_code,d.device_name,COUNT(*) c from wlyy.wlyy_patient_device d where 1=1 "+sqlCondition+" ");
                    sql.append("GROUP BY d.category_code,d.device_name) b ");
                    sql.append("WHERE a.category_code = b.category_code and a.device_name = b.device_name ");
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                        sql.append("and a.category_code in ('").append(deviceType.replace(",","','")).append("') ");
                    }
                }
                List<Map<String,Object>> sqlResult = jdbcTemplate.queryForList(sql.toString());
                JSONArray arr = JSONArray.parseArray(JSON.toJSONString(sqlResult));
                for(int i=0;i<arr.size();i++){
                    JSONObject obj = arr.getJSONObject(i);
                    if ("0".equals(showLevel)){
                        obj.put("device_name","单体征测量仪");
                        obj.put("Subdivision",true);//是否可查看下一层次
                    }
                    else if("1".equals(showLevel)){
                        String temp = obj.getString("type");
                        if("1".equals(temp)){
                            obj.put("device_name","血糖仪");
                        }else if("2".equals(temp)){
                            obj.put("device_name","血压计");
                        }
                        obj.put("Subdivision",true);
                    }
                    else{
                        obj.put("Subdivision",false);
                    }
                }
                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+" ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                    sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
                }
                Integer iotCount = jdbcTemplate.queryForObject(sql.toString(),Integer.class);//物联设备数量
                result.put("iotCount",iotCount);
                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` "+sqlCondition+" ");
                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("grantCount",grantCount);
                //失联设备(一周未上传当作失联)
                sql.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 ");
                sql.append("where TIMESTAMPDIFF(DAY,record_date,NOW()) <= 7)");
                Integer lostContact = jdbcTemplate.queryForObject(sql.toString(),Integer.class);
                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))){
                String sql = "select COUNT(*) from xmiot.iot_equipmet_detail";
                Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
                JSONObject tmp = new JSONObject();
                tmp.put("using",count);
                tmp.put("total",count);
                tmp.put("type","5");
                tmp.put("stock",0);
                if("0".equals(showLevel)){
                    tmp.put("device_name","组合一体机");
                    tmp.put("Subdivision",true);
                }else{
                    tmp.put("device_name","健康小屋");
                    tmp.put("Subdivision",false);
                }
                result.getJSONArray("deviceInfo").add(tmp);
                result.put("grantCount",result.getInteger("grantCount")+count);
                //统计健康小屋数据/ 小屋全部统计为正常使用
                sql ="select count(*) from xmiot.iot_equipmet_detail where device_code in (select DISTINCT sn device_model from xmiot.wlyy_iot_m)";
                count = jdbcTemplate.queryForObject(sql,Integer.class);
                result.put("iotCount",result.getInteger("iotCount")+count);//小屋物联
            }
            arrTmp = result.getJSONArray("deviceInfo");
            for (int i=0;i<arrTmp.size();i++){
                JSONObject tmp = arrTmp.getJSONObject(i);
                if (tmp.getInteger("total")==0){
                    arrTmp.remove(tmp);
                }
            }
            result.put("iotRangeString",result.getInteger("iotCount")+"/"+result.getInteger("grantCount"));
            result.put("lostRangeString",result.getInteger("lostContact")+"/"+result.getInteger("grantCount"));
            result.put("iotRange",getRange(result.getInteger("iotCount"),result.getInteger("grantCount"),2));
            result.put("lostRange",getRange(result.getInteger("lostContact"),result.getInteger("grantCount"),2));
            return result;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
    public String getRange(int first, int second, int i) {
        if (second == 0 && first > 0) {
            return "100%";
        } else if (second == 0 && first == 0) {
            return "0.00%";
        }
        float size = (float) (first * 100) / second;
        DecimalFormat df = new DecimalFormat("0.00");//格式化小数,不足的补0
        String filesize = df.format(size);
        return filesize + "%";
    }
}

+ 10 - 3
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/SpecialistScreenResultService.java

@ -140,9 +140,16 @@ public class SpecialistScreenResultService {
            surveyScreenResultVo.setDoctorMobile(String.valueOf(doctorList.get(0).get("mobile")));
        }
        //获取问卷详情
        String templateSql = "select t.is_third from "+basedb+".wlyy_survey_templates t where t.code = '" + templateCode + "' and t.del = 1 ";
        String thirdId = jdbcTemplate.queryForObject(templateSql, String.class);
        surveyScreenResultVo.setIsThird(thirdId);
        String templateSql = "select t.* from "+basedb+".wlyy_survey_templates t where t.code = '" + templateCode + "' and t.del = 1 ";
        List<Map<String, Object>> templateSqlList = jdbcTemplate.queryForList(templateSql);
        if (templateSqlList.size()>0){
            surveyScreenResultVo.setIsThird(templateSqlList.get(0).get("is_third").toString());
        }else {
            surveyScreenResultVo.setIsThird(null);
        }
//        String templateSql = "select t.is_third from "+basedb+".wlyy_survey_templates t where t.code = '" + templateCode + "' and t.del = 1 ";
//        String thirdId = jdbcTemplate.queryForObject(templateSql, String.class);
//        surveyScreenResultVo.setIsThird(thirdId);
        //获取转诊信息
        String reservationSql = "SELECT * FROM " + basedb + ".`wlyy_patient_reservation` r where r.relation_code = '" + code + "' and r.`status` = 1 ";
        List<Map<String, Object>> list = jdbcTemplate.queryForList(reservationSql);