wushilong 3 vuotta sitten
vanhempi
commit
563ed1c6c6

+ 488 - 445
svr/svr-iot/src/main/java/com/yihu/iot/controller/monitorPlatform/MonitorPlatformController.java

@ -1,5 +1,6 @@
package com.yihu.iot.controller.monitorPlatform;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.iot.service.company.IotCompanyService;
@ -9,6 +10,7 @@ import com.yihu.iot.service.equipment.IotEqtDetailService;
import com.yihu.iot.service.monitorPlatform.CopdXeekDeviceService;
import com.yihu.iot.service.monitorPlatform.MonitorPlatformService;
import com.yihu.iot.service.product.IotProductBaseInfoService;
import com.yihu.jw.entity.care.message.BaseServiceNews;
import com.yihu.jw.entity.iot.device.IotPatientDeviceDO;
import com.yihu.jw.entity.iot.dict.IotSystemDictDO;
import com.yihu.jw.restmodel.iot.device.IotPatientDeviceVO;
@ -83,8 +85,8 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
            @RequestParam(value = "dictName", required = true) String dictName) throws Exception {
        try {
            List<IotSystemDictDO> doList = iotSystemDictService.getListByDictName(dictName);
            return MixEnvelop.getSuccessList(IotRequestMapping.Company.message_success_find_functions,doList);
        }catch (Exception e){
            return MixEnvelop.getSuccessList(IotRequestMapping.Company.message_success_find_functions, doList);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
@ -93,14 +95,14 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    @GetMapping(value = IotRequestMapping.Product.findListByCategoryCode)
    @ApiOperation(value = "根据分类查找产品信息")
    public MixEnvelop<JSONObject, JSONObject> findListByCategoryCode(@ApiParam(name = "categoryCode", value = "分类code", defaultValue = "1")
                                                                     @RequestParam(value = "categoryCode", required = true)String categoryCode) {
                                                                     @RequestParam(value = "categoryCode", required = true) String categoryCode) {
        try {
            if(org.apache.commons.lang.StringUtils.isBlank(categoryCode)){
            if (org.apache.commons.lang.StringUtils.isBlank(categoryCode)) {
                return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_find, iotProductBaseInfoService.findListByCategoryCode());
            }else {
                return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_find, iotProductBaseInfoService.findListByCategoryCode("'"+categoryCode.replace(",","','")+"'"));
            } else {
                return MixEnvelop.getSuccess(IotRequestMapping.Common.message_success_find, iotProductBaseInfoService.findListByCategoryCode("'" + categoryCode.replace(",", "','") + "'"));
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("操作失败");
        }
@ -114,335 +116,335 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
            @RequestParam(value = "parentCode", required = true) String parentCode) throws Exception {
        try {
            List<JSONObject> doList = null;
            if(StringUtils.isNoneBlank(parentCode)){
                doList = iotSystemDictService.getListByParentCode("'"+parentCode.replace(",","','")+"'");
            }else{
                doList= iotSystemDictService.getListByParentCode();
            if (StringUtils.isNoneBlank(parentCode)) {
                doList = iotSystemDictService.getListByParentCode("'" + parentCode.replace(",", "','") + "'");
            } else {
                doList = iotSystemDictService.getListByParentCode();
            }
            return MixEnvelop.getSuccessList(IotRequestMapping.Company.message_success_find_functions,doList);
        }catch (Exception e){
            return MixEnvelop.getSuccessList(IotRequestMapping.Company.message_success_find_functions, doList);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/areaDict",method = RequestMethod.GET)
    @RequestMapping(value = "/areaDict", method = RequestMethod.GET)
    @ApiOperation("地区字典")
    public MixEnvelop areaDict(){
    public MixEnvelop areaDict() {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.areaDict());
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.areaDict());
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/hospitalDict",method = RequestMethod.GET)
    @RequestMapping(value = "/hospitalDict", method = RequestMethod.GET)
    @ApiOperation("医院字典")
    public MixEnvelop hospitalDict(@ApiParam(name="town",value="地区",defaultValue = "")
                               @RequestParam(value="town",required = false) String town){
    public MixEnvelop hospitalDict(@ApiParam(name = "town", value = "地区", defaultValue = "")
                                   @RequestParam(value = "town", required = false) String town) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.hospitalDict(town));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.hospitalDict(town));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/smartDeviceDistribution",method = RequestMethod.GET)
    @RequestMapping(value = "/smartDeviceDistribution", method = RequestMethod.GET)
    @ApiOperation("智能设备发放")
    public MixEnvelop smartDeviceDistribution(@ApiParam(name="startTime",value="开始时间",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,
                                              @ApiParam(name="hospital",value="机构",defaultValue = "")
                                                  @RequestParam(value="hospital",required = false) String hospital){
    public MixEnvelop smartDeviceDistribution(@ApiParam(name = "startTime", value = "开始时间", 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,
                                              @ApiParam(name = "hospital", value = "机构", defaultValue = "")
                                              @RequestParam(value = "hospital", required = false) String hospital) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.smartDeviceDistribution(startTime,endTime,deviceType,area,hospital));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.smartDeviceDistribution(startTime, endTime, deviceType, area, hospital));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/datafiltering",method = RequestMethod.GET)
    @RequestMapping(value = "/datafiltering", method = RequestMethod.GET)
    @ApiOperation("数据筛选")
    public MixEnvelop datafiltering(@ApiParam(name="name",value="设备sn码或居民姓名")
                                @RequestParam(value="name",required = false) String name){
    public MixEnvelop datafiltering(@ApiParam(name = "name", value = "设备sn码或居民姓名")
                                    @RequestParam(value = "name", required = false) String name) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.datafiltering(name));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.datafiltering(name));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/deviceUsageAnalysis",method = RequestMethod.GET)
    @RequestMapping(value = "/deviceUsageAnalysis", method = RequestMethod.GET)
    @ApiOperation("设备使用情况分析")
    public MixEnvelop deviceUsageAnalysis(@ApiParam(name="type",value="设备类型")
                                              @RequestParam(value="type",required = false) String type,
                                          @ApiParam(name="name",value="产品名称")
                                              @RequestParam(value="name",required = false) String name){
    public MixEnvelop deviceUsageAnalysis(@ApiParam(name = "type", value = "设备类型")
                                          @RequestParam(value = "type", required = false) String type,
                                          @ApiParam(name = "name", value = "产品名称")
                                          @RequestParam(value = "name", required = false) String name) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.deviceUsageAnalysis(type,name));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.deviceUsageAnalysis(type, name));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/warningInformationAlarm_new",method = RequestMethod.GET)
    @RequestMapping(value = "/warningInformationAlarm_new", method = RequestMethod.GET)
    @ApiOperation("预警信息警报")
    public MixEnvelop warningInformationAlarm_new(
            @ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
            @RequestParam(value="page",required = false) Integer page,
            @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
            @RequestParam(value="pageSize",required = false) Integer pageSize,
            @ApiParam(name="startTime",value="开始时间",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,
            @ApiParam(name="hospital",value="机构",defaultValue = "")
            @RequestParam(value="hospital",required = false) String hospital,
            @ApiParam(name="deviceName",value = "设备名称(品牌)",required = false)
            @RequestParam(value = "deviceName",required = false,defaultValue = "")String deviceName){
            @ApiParam(name = "page", value = "第几页(默认第一页)", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "pageSize", value = "每页几行(默认10条记录)", defaultValue = "10")
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
            @ApiParam(name = "startTime", value = "开始时间", 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,
            @ApiParam(name = "hospital", value = "机构", defaultValue = "")
            @RequestParam(value = "hospital", required = false) String hospital,
            @ApiParam(name = "deviceName", value = "设备名称(品牌)", required = false)
            @RequestParam(value = "deviceName", required = false, defaultValue = "") String deviceName) {
        try {
            if(page==null){
            if (page == null) {
                page = 1;
            }
            if(pageSize==null){
            if (pageSize == null) {
                pageSize = 20;
            }
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.warningInformationAlarm_new(page,pageSize,startTime,endTime,deviceType,area,hospital,monitorPlatformService.getDeviceNameByRequestParam(deviceName)));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.warningInformationAlarm_new(page, pageSize, startTime, endTime, deviceType, area, hospital, monitorPlatformService.getDeviceNameByRequestParam(deviceName)));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/yellowAndRedRange",method = RequestMethod.GET)
    @RequestMapping(value = "/yellowAndRedRange", method = RequestMethod.GET)
    @ApiOperation("红标黄标率")
    public MixEnvelop yellowAndRedRange(
            @ApiParam(name="startTime",value="开始时间",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,
            @ApiParam(name="hospital",value="机构",defaultValue = "")
            @RequestParam(value="hospital",required = false) String hospital){
            @ApiParam(name = "startTime", value = "开始时间", 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,
            @ApiParam(name = "hospital", value = "机构", defaultValue = "")
            @RequestParam(value = "hospital", required = false) String hospital) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.yellowAndRedRange(startTime,endTime,deviceType,area,hospital));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.yellowAndRedRange(startTime, endTime, deviceType, area, hospital));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/deviceUseData",method = RequestMethod.GET)
    @RequestMapping(value = "/deviceUseData", method = RequestMethod.GET)
    @ApiOperation("设备使用数据")
    public MixEnvelop deviceUseData(@ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
                                @RequestParam(value="page",required = false) Integer page,
                                @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
                                @RequestParam(value="pageSize",required = false) Integer pageSize,
                                @ApiParam(name="deviceSn",value="开始时间",defaultValue = "")
                                @RequestParam(value="deviceSn",required = false) String deviceSn){
    public MixEnvelop deviceUseData(@ApiParam(name = "page", value = "第几页(默认第一页)", defaultValue = "1")
                                    @RequestParam(value = "page", required = false) Integer page,
                                    @ApiParam(name = "pageSize", value = "每页几行(默认10条记录)", defaultValue = "10")
                                    @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                    @ApiParam(name = "deviceSn", value = "开始时间", defaultValue = "")
                                    @RequestParam(value = "deviceSn", required = false) String deviceSn) {
        try {
            if(page==null){
            if (page == null) {
                page = 1;
            }
            if(pageSize==null){
            if (pageSize == null) {
                pageSize = 10;
            }
            JSONObject jsonObject = monitorPlatformService.deviceUseData(page,pageSize,deviceSn);
            return MixEnvelop.getSuccess("查询成功",jsonObject.getJSONArray("list"),jsonObject.getInteger("total"));
        }catch (Exception e){
            JSONObject jsonObject = monitorPlatformService.deviceUseData(page, pageSize, deviceSn);
            return MixEnvelop.getSuccess("查询成功", jsonObject.getJSONArray("list"), jsonObject.getInteger("total"));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/deviceInfo",method = RequestMethod.GET)
    @RequestMapping(value = "/deviceInfo", method = RequestMethod.GET)
    @ApiOperation("设备信息")
    public MixEnvelop deviceInfo(@ApiParam(name="deviceSn",value="设备sn码")
                             @RequestParam(value="deviceSn",required = true) String deviceSn,
                             @ApiParam(name="patient",value="居民code")
                             @RequestParam(value="patient",required = true) String patient){
    public MixEnvelop deviceInfo(@ApiParam(name = "deviceSn", value = "设备sn码")
                                 @RequestParam(value = "deviceSn", required = true) String deviceSn,
                                 @ApiParam(name = "patient", value = "居民code")
                                 @RequestParam(value = "patient", required = true) String patient) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.deviceInfo(deviceSn,patient));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.deviceInfo(deviceSn, patient));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/deviceOverhaulList",method = RequestMethod.GET)
    @RequestMapping(value = "/deviceOverhaulList", method = RequestMethod.GET)
    @ApiOperation("质控情况")
    public MixEnvelop deviceOverhaulList(@ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
                                     @RequestParam(value="page",required = false) Integer page,
                                 @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
                                     @RequestParam(value="pageSize",required = false) Integer pageSize,
                                 @ApiParam(name="deviceSn",value="开始时间",defaultValue = "")
                                     @RequestParam(value="deviceSn",required = true) String deviceSn){
    public MixEnvelop deviceOverhaulList(@ApiParam(name = "page", value = "第几页(默认第一页)", defaultValue = "1")
                                         @RequestParam(value = "page", required = false) Integer page,
                                         @ApiParam(name = "pageSize", value = "每页几行(默认10条记录)", defaultValue = "10")
                                         @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                         @ApiParam(name = "deviceSn", value = "开始时间", defaultValue = "")
                                         @RequestParam(value = "deviceSn", required = true) String deviceSn) {
        try {
            if(page==null){
            if (page == null) {
                page = 1;
            }
            if(pageSize==null){
            if (pageSize == null) {
                pageSize = 10;
            }
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.deviceOverhaulList(page,pageSize,deviceSn),monitorPlatformService.deviceOverhaulListTotal(deviceSn));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.deviceOverhaulList(page, pageSize, deviceSn), monitorPlatformService.deviceOverhaulListTotal(deviceSn));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/residentUserType",method = RequestMethod.GET)
    @RequestMapping(value = "/residentUserType", method = RequestMethod.GET)
    @ApiOperation("入住情况")
    public MixEnvelop residentUserType(){
    public MixEnvelop residentUserType() {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.residentUserType());
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.residentUserType());
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/intefaceLogList",method = RequestMethod.GET)
    @RequestMapping(value = "/intefaceLogList", method = RequestMethod.GET)
    @ApiOperation("接口调用情况")
    public MixEnvelop intefaceLogList(@ApiParam(name="startTime",value="开始时间",defaultValue = "2019-01-01")
                                         @RequestParam(value="startTime",required = false) String startTime,
                                         @ApiParam(name="endTime",value="结束时间",defaultValue = "2020-06-01")
                                         @RequestParam(value="endTime",required = false) String endTime,
                                         @ApiParam(name="type",value="统计类型",defaultValue = "month")
                                         @RequestParam(value="type",required = true) String type){
    public MixEnvelop intefaceLogList(@ApiParam(name = "startTime", value = "开始时间", defaultValue = "2019-01-01")
                                      @RequestParam(value = "startTime", required = false) String startTime,
                                      @ApiParam(name = "endTime", value = "结束时间", defaultValue = "2020-06-01")
                                      @RequestParam(value = "endTime", required = false) String endTime,
                                      @ApiParam(name = "type", value = "统计类型", defaultValue = "month")
                                      @RequestParam(value = "type", required = true) String type) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.intefaceLogList(startTime,endTime,type));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.intefaceLogList(startTime, endTime, type));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/totalRange",method = RequestMethod.GET)
    @RequestMapping(value = "/totalRange", method = RequestMethod.GET)
    @ApiOperation("85-发放率,96使用率,86绑定率,88指导率")
    public MixEnvelop totalRange(
            @ApiParam(name="startTime",value="开始时间",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,
            @ApiParam(name="hospital",value="机构",defaultValue = "")
            @RequestParam(value="hospital",required = false) String hospital,
            @ApiParam(name="quotaCode",value="85-发放率,96使用率,86绑定率,88指导率",defaultValue = "")
            @RequestParam(value="quotaCode",required = true) String quotaCode){
            @ApiParam(name = "startTime", value = "开始时间", 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,
            @ApiParam(name = "hospital", value = "机构", defaultValue = "")
            @RequestParam(value = "hospital", required = false) String hospital,
            @ApiParam(name = "quotaCode", value = "85-发放率,96使用率,86绑定率,88指导率", defaultValue = "")
            @RequestParam(value = "quotaCode", required = true) String quotaCode) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.totalRange(startTime,endTime,deviceType,area,hospital,quotaCode));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.totalRange(startTime, endTime, deviceType, area, hospital, quotaCode));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value="getTotalRange",method = RequestMethod.GET)
    @RequestMapping(value = "getTotalRange", method = RequestMethod.GET)
    @ApiOperation("96使用率,86绑定率,88指导率,慢病患者设备使用率,慢病患者设备覆盖率整合")
    public MixEnvelop getTotalRange(@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,
                                    @ApiParam(name="hospital",value="机构",defaultValue = "")
                                        @RequestParam(value="hospital",required = false) String hospital){
    public MixEnvelop getTotalRange(@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,
                                    @ApiParam(name = "hospital", value = "机构", defaultValue = "")
                                    @RequestParam(value = "hospital", required = false) String hospital) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.getTotalRange(startTime,endTime,deviceType,area,hospital));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.getTotalRange(startTime, endTime, deviceType, area, hospital));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/diseaseUseRange",method = RequestMethod.GET)
    @RequestMapping(value = "/diseaseUseRange", method = RequestMethod.GET)
    @ApiOperation("慢病患者设备使用率")
    public MixEnvelop diseaseUseRange(
            @ApiParam(name="startTime",value="开始时间",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,
            @ApiParam(name="hospital",value="机构",defaultValue = "")
            @RequestParam(value="hospital",required = false) String hospital){
            @ApiParam(name = "startTime", value = "开始时间", 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,
            @ApiParam(name = "hospital", value = "机构", defaultValue = "")
            @RequestParam(value = "hospital", required = false) String hospital) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.diseaseUseRange(startTime,endTime,deviceType,area,hospital));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.diseaseUseRange(startTime, endTime, deviceType, area, hospital));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/diseaseRange",method = RequestMethod.GET)
    @RequestMapping(value = "/diseaseRange", method = RequestMethod.GET)
    @ApiOperation("慢病患者设备覆盖率")
    public MixEnvelop diseaseRange(
            @ApiParam(name="startTime",value="开始时间",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,
            @ApiParam(name="hospital",value="机构",defaultValue = "")
            @RequestParam(value="hospital",required = false) String hospital){
            @ApiParam(name = "startTime", value = "开始时间", 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,
            @ApiParam(name = "hospital", value = "机构", defaultValue = "")
            @RequestParam(value = "hospital", required = false) String hospital) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.diseaseRange(startTime,endTime,deviceType,area,hospital));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.diseaseRange(startTime, endTime, deviceType, area, hospital));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/yellowOrRedRange",method = RequestMethod.GET)
    @RequestMapping(value = "/yellowOrRedRange", method = RequestMethod.GET)
    @ApiOperation("红标黄标率")
    public MixEnvelop yellowOrRedRange(
            @ApiParam(name="startTime",value="开始时间",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,
            @ApiParam(name="hospital",value="机构",defaultValue = "")
            @RequestParam(value="hospital",required = false) String hospital,
            @ApiParam(name="diseaseCondition",value="红黄标 黄1,红2",defaultValue = "1")
            @RequestParam(value="diseaseCondition",required = true) Integer diseaseCondition){
            @ApiParam(name = "startTime", value = "开始时间", 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,
            @ApiParam(name = "hospital", value = "机构", defaultValue = "")
            @RequestParam(value = "hospital", required = false) String hospital,
            @ApiParam(name = "diseaseCondition", value = "红黄标 黄1,红2", defaultValue = "1")
            @RequestParam(value = "diseaseCondition", required = true) Integer diseaseCondition) {
        try {
            return MixEnvelop.getSuccess("查询成功",monitorPlatformService.yellowOrRedRange(startTime,endTime,deviceType,area,hospital,diseaseCondition));
        }catch (Exception e){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.yellowOrRedRange(startTime, endTime, deviceType, area, hospital, diseaseCondition));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
@ -450,23 +452,23 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    /*****************************************************************************************************/
    @RequestMapping(value = "/equipmentDistribution",method = RequestMethod.GET)
    @RequestMapping(value = "/equipmentDistribution", method = RequestMethod.GET)
    @ApiOperation("设备发放情况")
    public String equipmentDistribution(@ApiParam(name="startTime",value="开始时间",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,
                                        @ApiParam(name="hospital",value="机构",defaultValue = "")
                                            @RequestParam(value="hospital",required = false) String hospital){
    public String equipmentDistribution(@ApiParam(name = "startTime", value = "开始时间", 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,
                                        @ApiParam(name = "hospital", value = "机构", defaultValue = "")
                                        @RequestParam(value = "hospital", required = false) String hospital) {
        try {
            return monitorPlatformService.equipmentDistribution(startTime,endTime,deviceType, area, hospital);
        }catch (Exception e){
            return monitorPlatformService.equipmentDistribution(startTime, endTime, deviceType, area, hospital);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
@ -474,191 +476,190 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    @ApiOperation(value = "根据idCard查询设备地址", notes = "根据idCard查询设备地址")
    public MixEnvelop<LocationDataVO, LocationDataVO> findDeviceLocationsByIdCard(
            @ApiParam(name = "diseaseCondition", value = "病情:0绿标,1黄标,2红标,-1没有标注的居民", defaultValue = "")
            @RequestParam(value = "diseaseCondition",required = false) Integer diseaseCondition,
            @RequestParam(value = "diseaseCondition", required = false) Integer diseaseCondition,
            @ApiParam(name = "type", value = "1高血压 2糖尿病", defaultValue = "")
            @RequestParam(value = "type",required = false) String type,
            @ApiParam(name="deviceType",value="设备类型 对应设备字典库的DEVICE_TYPE值",required = true)
            @RequestParam(value="deviceType",required = true) String deviceType,
            @ApiParam(name="deviceName",value = "设备名称(品牌)",required = false)
            @RequestParam(value = "deviceName",required = false,defaultValue = " ")String deviceName,
            @ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
            @RequestParam(value="page",required = false) Integer page,
            @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
            @RequestParam(value="pageSize",required = false) Integer pageSize) {
            @RequestParam(value = "type", required = false) String type,
            @ApiParam(name = "deviceType", value = "设备类型 对应设备字典库的DEVICE_TYPE值", required = true)
            @RequestParam(value = "deviceType", required = true) String deviceType,
            @ApiParam(name = "deviceName", value = "设备名称(品牌)", required = false)
            @RequestParam(value = "deviceName", required = false, defaultValue = " ") String deviceName,
            @ApiParam(name = "page", value = "第几页(默认第一页)", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "pageSize", value = "每页几行(默认10条记录)", defaultValue = "10")
            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        try {
            if(page==null){
            if (page == null) {
                page = 1;
            }
            if(pageSize==null){
            if (pageSize == null) {
                pageSize = 10;
            }
            return monitorPlatformService.findDeviceLocations(diseaseCondition,page,pageSize,type,deviceType,monitorPlatformService.getDeviceNameByRequestParam(deviceName));
            return monitorPlatformService.findDeviceLocations(diseaseCondition, page, pageSize, type, deviceType, monitorPlatformService.getDeviceNameByRequestParam(deviceName));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("操作失败");
        }
    }
    @RequestMapping(value = "/chronicDiseaseCount",method = RequestMethod.GET)
    @RequestMapping(value = "/chronicDiseaseCount", method = RequestMethod.GET)
    @ApiOperation("慢病患者情况-统计")
    public String chronicDiseaseCount(
            @ApiParam(name="type",value="类型(2糖尿病,1高血压)",defaultValue = "")
            @RequestParam(value="type",required = false) String type){
            @ApiParam(name = "type", value = "类型(2糖尿病,1高血压)", defaultValue = "")
            @RequestParam(value = "type", required = false) String type) {
        try {
            return monitorPlatformService.chronicDiseaseCount(type);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "/searchPatient",method = RequestMethod.GET)
    @RequestMapping(value = "/searchPatient", method = RequestMethod.GET)
    @ApiOperation("居民 医生搜索")
    public String searchPatient(
            @ApiParam(name="name",value="姓名")
            @RequestParam(value="name",required = false) String name,
            @ApiParam(name="idcards",value="身份证(多个用逗号间隔)")
            @RequestParam(value="idcards",required = false) String idcards,
            @ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
            @RequestParam(value="page",required = false) Integer page,
            @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
            @RequestParam(value="pageSize",required = false) Integer pageSize){
            @ApiParam(name = "name", value = "姓名")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "idcards", value = "身份证(多个用逗号间隔)")
            @RequestParam(value = "idcards", required = false) String idcards,
            @ApiParam(name = "page", value = "第几页(默认第一页)", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "pageSize", value = "每页几行(默认10条记录)", defaultValue = "10")
            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        try {
            if(page==null){
            if (page == null) {
                page = 1;
            }
            if(pageSize==null){
            if (pageSize == null) {
                pageSize = 10;
            }
            return monitorPlatformService.searchPatient(name,page,pageSize,idcards);
        }catch (Exception e){
            return monitorPlatformService.searchPatient(name, page, pageSize, idcards);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "/warningInformationAlarm",method = RequestMethod.GET)
    @RequestMapping(value = "/warningInformationAlarm", method = RequestMethod.GET)
    @ApiOperation("预警信息警报")
    public String warningInformationAlarm(
            @ApiParam(name="page",value="第几页(默认第一页)",defaultValue = "1")
            @RequestParam(value="page",required = false) Integer page,
            @ApiParam(name="pageSize",value="每页几行(默认10条记录)",defaultValue = "10")
            @RequestParam(value="pageSize",required = false) Integer pageSize){
            @ApiParam(name = "page", value = "第几页(默认第一页)", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page,
            @ApiParam(name = "pageSize", value = "每页几行(默认10条记录)", defaultValue = "10")
            @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        try {
            if(page==null){
            if (page == null) {
                page = 1;
            }
            if(pageSize==null){
            if (pageSize == null) {
                pageSize = 10;
            }
            return monitorPlatformService.warningInformationAlarm(page,pageSize);
        }catch (Exception e){
            return monitorPlatformService.warningInformationAlarm(page, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "/deviceBinding",method = RequestMethod.GET)
    @RequestMapping(value = "/deviceBinding", method = RequestMethod.GET)
    @ApiOperation("设备绑定情况")
    public String deviceBinding(
            @ApiParam(name="type",value="设备类型(1血糖仪,2血压计)",defaultValue = "")
            @RequestParam(value="type",required = false) String type){
            @ApiParam(name = "type", value = "设备类型(1血糖仪,2血压计)", defaultValue = "")
            @RequestParam(value = "type", required = false) String type) {
        try {
            return monitorPlatformService.deviceBinding(type);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "/persionalInfo",method = RequestMethod.GET)
    @RequestMapping(value = "/persionalInfo", method = RequestMethod.GET)
    @ApiOperation("个人信息")
    public String persionalInfo(@ApiParam(name="patient",value="居民code",defaultValue = "")
                                @RequestParam(value="patient",required = true) String patient){
    public String persionalInfo(@ApiParam(name = "patient", value = "居民code", defaultValue = "")
                                @RequestParam(value = "patient", required = true) String patient) {
        try {
            return monitorPlatformService.persionalInfo(patient);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "/familyMember",method = RequestMethod.GET)
    @RequestMapping(value = "/familyMember", method = RequestMethod.GET)
    @ApiOperation("家人信息")
    public String familyMember(@ApiParam(name="patient",value="居民code",defaultValue = "")
                               @RequestParam(value="patient",required = true) String patient){
    public String familyMember(@ApiParam(name = "patient", value = "居民code", defaultValue = "")
                               @RequestParam(value = "patient", required = true) String patient) {
        try {
            return monitorPlatformService.familyMember(patient);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "/healthDevice",method = RequestMethod.GET)
    @RequestMapping(value = "/healthDevice", method = RequestMethod.GET)
    @ApiOperation("健康设备")
    public String healthDevice(@ApiParam(name="patient",value="居民code",defaultValue = "")
                               @RequestParam(value="patient",required = true) String patient){
    public String healthDevice(@ApiParam(name = "patient", value = "居民code", defaultValue = "")
                               @RequestParam(value = "patient", required = true) String patient) {
        try {
            return monitorPlatformService.healthDevice(patient);
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "chart", method = RequestMethod.GET)
    @ApiOperation("根据患者标志获取健康指标(图表)")
    public String getHealthIndexChartByPatient(@ApiParam(name="patient",value="居民code",defaultValue = "")
                                               @RequestParam(value="patient",required = true) String patient,
    public String getHealthIndexChartByPatient(@ApiParam(name = "patient", value = "居民code", defaultValue = "")
                                               @RequestParam(value = "patient", required = true) String patient,
                                               @ApiParam(name = "type", value = "指标类型(1血糖,2血压,3体重,4腰围)", defaultValue = "1")
                                               @RequestParam(value = "type", required = true) Integer type,
                                               @ApiParam(name = "gi_type", value = "就餐类型0全部", defaultValue = "1")
                                               @RequestParam(value = "gi_type", required = false) Integer gi_type,
                                               @ApiParam(name="time",value="时间(一周,一月,半年)",defaultValue = "")
                                               @RequestParam(value="time",required = true) String time,
                                               @ApiParam(name = "time", value = "时间(一周,一月,半年)", defaultValue = "")
                                               @RequestParam(value = "time", required = true) String time,
                                               @ApiParam(name = "begin", value = "开始时间", defaultValue = "2017-05-22")
                                               @RequestParam(value = "begin", required = true) String begin,
                                               @ApiParam(name = "end", value = "结束时间", defaultValue = "2018-06-02")
                                               @RequestParam(value = "end", required = true) String end) {
        try {
            return monitorPlatformService.getHealthIndexChartByPatient(patient,type,gi_type,begin,end,time);
            return monitorPlatformService.getHealthIndexChartByPatient(patient, type, gi_type, begin, end, time);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    @RequestMapping(value = "getXeekDeviceData",method = RequestMethod.GET)
    @RequestMapping(value = "getXeekDeviceData", method = RequestMethod.GET)
    @ApiOperation(value = "塞克设备数据获取")
    public ObjEnvelop getXeekDeviceData(@ApiParam(name="deviceSN",value = "设备sn码")
                                    @RequestParam(value = "deviceSN",required = false)String deviceSN,
                                    @ApiParam(name="reportType",value = "测试项目 1=吸气测试;2=呼气测试;6=MVV 测试;7=慢通气测试")
                                    @RequestParam(value = "reportType",required = false)String reportType,
                                    @ApiParam(name="patient",value = "patient")
                                    @RequestParam(value = "patient",required = false)String patient,
                                    @ApiParam(name="parameter",value = "数据指标 inCount,outCount")
                                    @RequestParam(value = "parameter",required = false)String parameter,
                                    @ApiParam(name="time",value = "7 30 90")
                                    @RequestParam(value = "time",required = false)String time,
                                    @ApiParam(name="begin",value = "开始时间 YYYY-MM-DD HH:MM:SS" ,defaultValue = "2021-04-14 00:00:00")
                                    @RequestParam(value = "begin")String begin,
                                    @ApiParam(name="end",value = "结束时间 YYYY-MM-DD HH:MM:SS" ,defaultValue = "2021-04-14 23:59:59" )
                                    @RequestParam(value = "end")String end)
    {
        if (StringUtils.isBlank(patient)&&StringUtils.isBlank(deviceSN)){
    public ObjEnvelop getXeekDeviceData(@ApiParam(name = "deviceSN", value = "设备sn码")
                                        @RequestParam(value = "deviceSN", required = false) String deviceSN,
                                        @ApiParam(name = "reportType", value = "测试项目 1=吸气测试;2=呼气测试;6=MVV 测试;7=慢通气测试")
                                        @RequestParam(value = "reportType", required = false) String reportType,
                                        @ApiParam(name = "patient", value = "patient")
                                        @RequestParam(value = "patient", required = false) String patient,
                                        @ApiParam(name = "parameter", value = "数据指标 inCount,outCount")
                                        @RequestParam(value = "parameter", required = false) String parameter,
                                        @ApiParam(name = "time", value = "7 30 90")
                                        @RequestParam(value = "time", required = false) String time,
                                        @ApiParam(name = "begin", value = "开始时间 YYYY-MM-DD HH:MM:SS", defaultValue = "2021-04-14 00:00:00")
                                        @RequestParam(value = "begin") String begin,
                                        @ApiParam(name = "end", value = "结束时间 YYYY-MM-DD HH:MM:SS", defaultValue = "2021-04-14 23:59:59")
                                        @RequestParam(value = "end") String end) {
        if (StringUtils.isBlank(patient) && StringUtils.isBlank(deviceSN)) {
            return ObjEnvelop.getError("参数错误");
        }
        try {
            return ObjEnvelop.getSuccess("查询成功",copdXeekDeviceService.getDeviceData(patient,deviceSN,reportType,parameter,time,begin,end));
        }catch (Exception e){
            return ObjEnvelop.getSuccess("查询成功", copdXeekDeviceService.getDeviceData(patient, deviceSN, reportType, parameter, time, begin, end));
        } catch (Exception e) {
            e.printStackTrace();
            return ObjEnvelop.getError("查询失败"+e.getMessage());
            return ObjEnvelop.getError("查询失败" + e.getMessage());
        }
    }
@ -676,58 +677,59 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
            return monitorPlatformService.getAllEvent(patient, type, page, pageSize);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    /**
     * 根据患者标志获取健康指标
     *
     * @param idcard 患者指标
     * @param type 健康指标类型(1血糖,2血压,3体重,4腰围)
     * @param type   健康指标类型(1血糖,2血压,3体重,4腰围)
     * @return 操作结果
     */
    @RequestMapping(value = "health_index/listByIdcard",method = RequestMethod.POST)
    @RequestMapping(value = "health_index/listByIdcard", method = RequestMethod.POST)
    @ApiOperation("根据患者标志获取健康指标")
    public String getHealthIndexByIdcard(@ApiParam(name="idcard",value="居民身份证",defaultValue = "P20160901001")
                                         @RequestParam(value="idcard",required = true) String idcard,
                                         @ApiParam(name="type",value="指标类型",defaultValue = "1")
                                         @RequestParam(value="type",required = true) int type,
                                         @ApiParam(name="begin",value="开始时间",defaultValue = "2016-07-23 00:00:00")
                                         @RequestParam(value="begin",required = true) String begin,
                                         @ApiParam(name="end",value="开始时间",defaultValue = "2016-08-23 00:00:00")
                                         @RequestParam(value="end",required = true) String end,
                                         @ApiParam(name="page",value="第几页",defaultValue = "1")
                                         @RequestParam(value="page",required = true) int page,
                                         @ApiParam(name="pagesize",value="每页几行",defaultValue = "10")
                                         @RequestParam(value="pagesize",required = true) int pagesize,HttpServletRequest request) {
    public String getHealthIndexByIdcard(@ApiParam(name = "idcard", value = "居民身份证", defaultValue = "P20160901001")
                                         @RequestParam(value = "idcard", required = true) String idcard,
                                         @ApiParam(name = "type", value = "指标类型", defaultValue = "1")
                                         @RequestParam(value = "type", required = true) int type,
                                         @ApiParam(name = "begin", value = "开始时间", defaultValue = "2016-07-23 00:00:00")
                                         @RequestParam(value = "begin", required = true) String begin,
                                         @ApiParam(name = "end", value = "开始时间", defaultValue = "2016-08-23 00:00:00")
                                         @RequestParam(value = "end", required = true) String end,
                                         @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                                         @RequestParam(value = "page", required = true) int page,
                                         @ApiParam(name = "pagesize", value = "每页几行", defaultValue = "10")
                                         @RequestParam(value = "pagesize", required = true) int pagesize, HttpServletRequest request) {
        try {
            return monitorPlatformService.getHealthIndexByIdcard(idcard, type, begin, end, page, pagesize,request);
            return monitorPlatformService.getHealthIndexByIdcard(idcard, type, begin, end, page, pagesize, request);
        } catch (Exception ex) {
            ex.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    /**
     * 获取居民信息
     */
    @RequestMapping(value = "patientInfo",method = RequestMethod.GET)
    @RequestMapping(value = "patientInfo", method = RequestMethod.GET)
    @ApiOperation("获取居民信息")
    public String patientInfo(@ApiParam(name="idcard",value="居民身份证",defaultValue = "P20160901001")
                              @RequestParam(value="idcard",required = true) String idcard) {
    public String patientInfo(@ApiParam(name = "idcard", value = "居民身份证", defaultValue = "P20160901001")
                              @RequestParam(value = "idcard", required = true) String idcard) {
        try {
            return monitorPlatformService.patientInfo(idcard);
        } catch (Exception ex) {
            ex.printStackTrace();
            return error(-1,"查询失败");
            return error(-1, "查询失败");
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param code 结果码,成功为200
     * @param msg  结果提示信息
     * @return
     */
    public String error(int code, String msg) {
@ -748,69 +750,71 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    @ApiOperation(value = "查询设备和数量")
    public Envelop getCountAndEquipment(
            @ApiParam(name = "startTime", value = "startTime", required = false)
            @RequestParam(value = "startTime", required = false)String startTime,
            @RequestParam(value = "startTime", required = false) String startTime,
            @ApiParam(name = "endTime", value = "endTime", required = false)
            @RequestParam(value = "endTime", required = false)String endTime,
            @RequestParam(value = "endTime", required = false) String endTime,
            @ApiParam(name = "area", value = "area", required = false)
            @RequestParam(value = "area", required = false)String area) throws Exception{
        JSONObject jsonObject =iotEqtDetailService.showJKXW(startTime,endTime,area);
            @RequestParam(value = "area", required = false) String area) throws Exception {
        JSONObject jsonObject = iotEqtDetailService.showJKXW(startTime, endTime, area);
        return success(jsonObject);
    }
    @GetMapping(value = IotRequestMapping.Common.getHospital)
    @ApiOperation(value = "查询医院")
    public Envelop getHospital(
            @ApiParam(name = "name", value = "name", required = false)
            @RequestParam(value = "name", required = false)String name,
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(name = "code", value = "code", required = false)
            @RequestParam(value = "code", required = false)String code,
            @RequestParam(value = "code", required = false) String code,
            @ApiParam(name = "town", value = "town", required = false)
            @RequestParam(value = "town", required = false)String town,
            @RequestParam(value = "town", required = false) String town,
            @ApiParam(name = "city", value = "city", required = false)
            @RequestParam(value = "city", required = false)String city) throws Exception{
            @RequestParam(value = "city", required = false) String city) throws Exception {
        return success( iotEqtDetailService.getHosptital(name, code, town,city));
        return success(iotEqtDetailService.getHosptital(name, code, town, city));
    }
    @GetMapping(value = IotRequestMapping.Common.getNameAndCode)
    @ApiOperation(value = "查询idcard")
    public Envelop getByIdCard(
            @ApiParam(name = "idCard", value = "idCard", required = false)
            @RequestParam(value = "idCard", required = false)String idCard,
            @RequestParam(value = "idCard", required = false) String idCard,
            @ApiParam(name = "snCode", value = "snCode", required = false)
            @RequestParam(value = "snCode", required = false)String snCode) throws Exception{
            @RequestParam(value = "snCode", required = false) String snCode) throws Exception {
        return success( iotPatientDeviceService.getNameAndCode(idCard,snCode));
        return success(iotPatientDeviceService.getNameAndCode(idCard, snCode));
    }
    @GetMapping(value="/getEquipmentDetail")
    @GetMapping(value = "/getEquipmentDetail")
    @ApiOperation("健康小屋详情")
    public Envelop getEquipmentDetail(@RequestParam(value = "deviceSn",required = true)
                             @ApiParam(name="deviceSn",value ="设备SN码",required = true)String deviceSn){
    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")
    @GetMapping(value = "/getBrandsAndManufacturer")
    @ApiOperation("设备品牌以及商家")
    public Envelop getBrandsAndManufacturer(){
    public Envelop getBrandsAndManufacturer() {
        return success(monitorPlatformService.getBrandsAndManufacturer());
    }
    @GetMapping(value="/getEquipmentStatistics")
    @GetMapping(value = "/getEquipmentStatistics")
    @ApiOperation("设备库存、使用数、总备案、失联率、物联率")
    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")
                                          @ApiParam(name="showLevel",value ="下转层次,默认0设备大类,1设备类型,2设备品牌") String showLevel){
    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")
                                          @ApiParam(name = "showLevel", value = "下转层次,默认0设备大类,1设备类型,2设备品牌") String showLevel) {
        return success(monitorPlatformService.getEquipmentStatistics(deviceType, monitorPlatformService.getDeviceNameByRequestParam(deviceName), showLevel));
    }
    @ApiOperation("大屏应用服务")
    @RequestMapping(value = "/getAppService" , method = RequestMethod.GET)
    @RequestMapping(value = "/getAppService", method = RequestMethod.GET)
    public Envelop getAppService() {
        try {
            return success(iotCompanyService.getAppService());
@ -821,8 +825,8 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    }
    @ApiOperation("获取设备大类")
    @GetMapping(value ="/getDeviceTotalCategory")
    public Envelop getDeviceTotalCategory(){
    @GetMapping(value = "/getDeviceTotalCategory")
    public Envelop getDeviceTotalCategory() {
        try {
            return success(iotSystemDictService.getDeviceTotalCategory());
        } catch (Exception e) {
@ -830,143 +834,142 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/iotAndLostRange",method = RequestMethod.GET)
    @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){
            @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){
            return MixEnvelop.getSuccess("查询成功", monitorPlatformService.iotAndLostRange(startTime, endTime, deviceType, area, hospital, quotaCode));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @GetMapping(value="/getBrandsDetail")
    @GetMapping(value = "/getBrandsDetail")
    @ApiOperation("获取设备品牌列表")
    public Envelop getBrandsDetail(
            @ApiParam(name="deviceType",value ="设备类型",required = true)
            @RequestParam(value="deviceType",required = true,defaultValue = "1,2,5")String deviceType){
            @ApiParam(name = "deviceType", value = "设备类型", required = true)
            @RequestParam(value = "deviceType", required = true, defaultValue = "1,2,5") String deviceType) {
        return success(monitorPlatformService.getBrandsDetail(deviceType));
    }
    @RequestMapping(value="/getDeviceData", method = RequestMethod.GET)
    @RequestMapping(value = "/getDeviceData", method = RequestMethod.GET)
    @ApiOperation("物联网大屏实时动态设备")
    public Envelop getDeviceData(){
    public Envelop getDeviceData() {
        try {
            return success(monitorPlatformService.getDeviceData());
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "/getSearchTags",method = RequestMethod.GET)
    @RequestMapping(value = "/getSearchTags", method = RequestMethod.GET)
    @ApiOperation("快速搜索标签")
    public Envelop getSearchTags(){
    public Envelop getSearchTags() {
        try {
            return success(monitorPlatformService.getSearchTags());
        }
        catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value="getDeviceTotalCount",method = RequestMethod.GET)
    @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,
                                       @ApiParam(name="hospital",value="单位",defaultValue = "")
                                           @RequestParam(value="hospital",required = false) String hospital){
    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,
                                       @ApiParam(name = "hospital", value = "单位", defaultValue = "")
                                       @RequestParam(value = "hospital", required = false) String hospital) {
        try {
            return success(monitorPlatformService.getDeviceTotalCount(startTime, endTime, deviceType, area,hospital));
        }
        catch (Exception e){
            return success(monitorPlatformService.getDeviceTotalCount(startTime, endTime, deviceType, area, hospital));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    @RequestMapping(value = "savePatientDeviceLocation",method = RequestMethod.POST)
    public Envelop savePatientDeviceLocation(String categoryCode){
    @RequestMapping(value = "savePatientDeviceLocation", method = RequestMethod.POST)
    public Envelop savePatientDeviceLocation(String categoryCode) {
        try {
            return success(monitorPlatformService.savePatientDeviceLocation(categoryCode));
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("操作失败");
        }
    }
    @ApiOperation("获取运动记录")
    @RequestMapping(value = "getSportRecord",method = {RequestMethod.POST,RequestMethod.GET})
    @RequestMapping(value = "getSportRecord", method = {RequestMethod.POST, RequestMethod.GET})
    public Envelop getSportRecord(
            @ApiParam(name="patient",value="i健康居民code",defaultValue = "0fab4dd67e074e16ac86db6b6c15233e") @RequestParam(value = "patient", required = false)String patient,
            @ApiParam(name="date",value="开始日期,如2020-05-09",defaultValue = "2020-05-09") @RequestParam(value = "date", required = false)String date,
            @ApiParam(name="type",value="大屏选择项",defaultValue = "hear") @RequestParam(value = "type", required = false)String type,
            @ApiParam(name="day",value="周期",defaultValue = "7") @RequestParam(value = "day", required = false)Integer day
    ){
            @ApiParam(name = "patient", value = "i健康居民code", defaultValue = "0fab4dd67e074e16ac86db6b6c15233e") @RequestParam(value = "patient", required = false) String patient,
            @ApiParam(name = "date", value = "开始日期,如2020-05-09", defaultValue = "2020-05-09") @RequestParam(value = "date", required = false) String date,
            @ApiParam(name = "type", value = "大屏选择项", defaultValue = "hear") @RequestParam(value = "type", required = false) String type,
            @ApiParam(name = "day", value = "周期", defaultValue = "7") @RequestParam(value = "day", required = false) Integer day
    ) {
        try {
            JSONObject json = new JSONObject();
            String endDate = getNewDate(date,day);
            if (type.equals("hear") || type.equals("all")){
            String endDate = getNewDate(date, day);
            if (type.equals("hear") || type.equals("all")) {
                //心率
                List<Map<String,Object>> hearDo = monitorPlatformService.getHeartByPatient(patient,date,endDate);
                if (hearDo.size() > 0){
                    json.put("hear",hearDo);//心率
                }else {
                    json.put("hear",0);//心率
                List<Map<String, Object>> hearDo = monitorPlatformService.getHeartByPatient(patient, date, endDate);
                if (hearDo.size() > 0) {
                    json.put("hear", hearDo);//心率
                } else {
                    json.put("hear", 0);//心率
                }
            }
            if (type.equals("score") || type.equals("all")){
            if (type.equals("score") || type.equals("all")) {
                //健康分  retWeekTime("week");  周的健康分
                List<Map<String, Object>> scoreDO = monitorPlatformService.getHealthScoreByPatient(patient,date,endDate);
                if (scoreDO.size() > 0){
                    json.put("score",scoreDO); //健康分值
                }else {
                    json.put("score",0); //健康分值
                List<Map<String, Object>> scoreDO = monitorPlatformService.getHealthScoreByPatient(patient, date, endDate);
                if (scoreDO.size() > 0) {
                    json.put("score", scoreDO); //健康分值
                } else {
                    json.put("score", 0); //健康分值
                }
            }
            if (type.equals("realtime") || type.equals("all")){
            if (type.equals("realtime") || type.equals("all")) {
                // 实时数据
                List<Map<String, Object>> realtimeDateDo = monitorPlatformService.getRealtimeDateByPatient(patient,date);
                if (realtimeDateDo.size() > 0){
                    json.put("realtime",realtimeDateDo.get(0)); //实时心率
                List<Map<String, Object>> realtimeDateDo = monitorPlatformService.getRealtimeDateByPatient(patient, date);
                if (realtimeDateDo.size() > 0) {
                    json.put("realtime", realtimeDateDo.get(0)); //实时心率
//                    Map<String,Object> map = realtimeDateDo.get(0);
//                    json.put("realtimehr",map.get("hr")); //实时心率
//                    json.put("realtimest",map.get("st")); //实时步数,采集开始后的累积步数
//                    json.put("realtimecal",map.get("cal")); //实时卡路里,累积卡路里
                }else {
                    json.put("realtime",0);
                } else {
                    json.put("realtime", 0);
//                    json.put("realtimehr",0); //实时心率
//                    json.put("realtimest",0); //实时步数,采集开始后的累积步数
//                    json.put("realtimecal",0); //实时卡路里,累积卡路里
                }
            }
            if (type.equals("runData") || type.equals("all")){
            if (type.equals("runData") || type.equals("all")) {
                //运动数据  runDate
                List<Map<String , Object>> rundateDo = monitorPlatformService.getRundatePatient(patient,date);
                if (rundateDo.size() > 0){
                    json.put("runData",rundateDo.get(0));
                List<Map<String, Object>> rundateDo = monitorPlatformService.getRundatePatient(patient, date);
                if (rundateDo.size() > 0) {
                    json.put("runData", rundateDo.get(0));
//                    Map<String,Object> map = rundateDo.get(0);
//                    json.put("steps",map.get("steps")); //总步数
//                    json.put("distance",map.get("distance")); //总距离
@ -975,8 +978,8 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
//                    json.put("runTime",map.get("run_time")); //跑步时长
//                    json.put("calories",map.get("calories")); //总燃烧卡路里
//                    json.put("runCalories",map.get("run_calories")); //跑步消耗卡路里
                }else {
                    json.put("runData",0);
                } else {
                    json.put("runData", 0);
//                    json.put("steps",0); //总步数
//                    json.put("distance",0); //总距离
//                    json.put("walkTime",0); //步行时长
@ -986,25 +989,25 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
//                    json.put("runCalories",0); //跑步消耗卡路里
                }
            }
            if (type.equals("pai") || type.equals("all")){
            if (type.equals("pai") || type.equals("all")) {
                //PAI数据
                List<Map<String,Object>> paiDo = monitorPlatformService.getPaiPatient(patient,date);
                if (paiDo.size() > 0){
                    json.put("pai",paiDo.get(0));
                List<Map<String, Object>> paiDo = monitorPlatformService.getPaiPatient(patient, date);
                if (paiDo.size() > 0) {
                    json.put("pai", paiDo.get(0));
//                    Map<String,Object> map = paiDo.get(0);
//                    json.put("totalPai",map.get("total_pai")); //用户本周运动前获得的所有PAI
//                    json.put("dailyPai",map.get("daily_pai")); //用户在当天获得的PAI
                }else {
                    json.put("pai",0);
                } else {
                    json.put("pai", 0);
//                    json.put("totalPai",0); //总
//                    json.put("dailyPai",0); //总距离
                }
            }
            if (type.equals("sleepData") || type.equals("all")){
            if (type.equals("sleepData") || type.equals("all")) {
                //睡眠数据
                List<Map<String , Object>> sleepDo = monitorPlatformService.getSleepByPatient(patient,date);
                if (sleepDo.size() > 0){
                    json.put("sleepData",sleepDo.get(0));
                List<Map<String, Object>> sleepDo = monitorPlatformService.getSleepByPatient(patient, date);
                if (sleepDo.size() > 0) {
                    json.put("sleepData", sleepDo.get(0));
//                    Map<String,Object> map = sleepDo.get(0);
//                    json.put("deepSleepTime",map.get("deep_sleep_time")); //深度睡眠时长,单位为分钟
//                    json.put("shallowSleepTime",map.get("shallow_sleep_time")); //浅度睡眠时长,单位为分钟
@ -1012,8 +1015,8 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
//                    json.put("sleepScore",map.get("sleep_score")); //睡眠评分
//                    json.put("start",map.get("start")); //睡眠开始时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
//                    json.put("stop",map.get("stop")); //睡眠结束时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
                }else {
                    json.put("sleepData",sleepDo.get(0));
                } else {
                    json.put("sleepData", sleepDo.get(0));
//                    json.put("deepSleepTime",0); //深度睡眠时长,单位为分钟
//                    json.put("shallowSleepTime",0); //浅度睡眠时长,单位为分钟
//                    json.put("wakeTime",0); //睡眠期间清醒时长,单位为分钟
@ -1022,14 +1025,14 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
//                    json.put("stop",0); //睡眠结束时间。Amazfit设备为分钟序号(0-1439),mifit设备为时间戳
                }
            }
            return success("查询成功",json);
        }catch (Exception e){
            return success("查询成功", json);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError("查询失败");
        }
    }
    private String getNewDate(String date,Integer day) throws ParseException {
    private String getNewDate(String date, Integer day) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date newDate = sdf.parse(date);
        Calendar calendar = Calendar.getInstance();
@ -1040,28 +1043,68 @@ public class MonitorPlatformController extends EnvelopRestEndpoint {
    }
    @ApiOperation("获取赛客查询指标")
    @RequestMapping(value = "getXeekParameters",method = {RequestMethod.POST,RequestMethod.GET})
    public ObjEnvelop getSportRecord(){
    @RequestMapping(value = "getXeekParameters", method = {RequestMethod.POST, RequestMethod.GET})
    public ObjEnvelop getSportRecord() {
        try {
            String sql = "select value as code,name1 name from xmiot.wlyy_iot_tz_dict where code='COPD_PARAMETER' and del=1";
            List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
            return  ObjEnvelop.getSuccess("查询成功",result);
        }catch (Exception e){
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
            return ObjEnvelop.getSuccess("查询成功", result);
        } catch (Exception e) {
            e.printStackTrace();
            return ObjEnvelop.getError("查询失败"+e.getMessage());
            return ObjEnvelop.getError("查询失败" + e.getMessage());
        }
    }
    @ApiOperation("获取华米手环查询指标")
    @RequestMapping(value = "getHuaMiParameters",method = {RequestMethod.POST,RequestMethod.GET})
    public ObjEnvelop getHuaMiParameters(){
    @RequestMapping(value = "getHuaMiParameters", method = {RequestMethod.POST, RequestMethod.GET})
    public ObjEnvelop getHuaMiParameters() {
        try {
            String sql = "select value as code,name from xmiot.wlyy_iot_tz_dict where code='HuaMiIot' and del=1";
            List<Map<String,Object>> result = jdbcTemplate.queryForList(sql);
            return  ObjEnvelop.getSuccess("查询成功",result);
        }catch (Exception e){
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql);
            return ObjEnvelop.getSuccess("查询成功", result);
        } catch (Exception e) {
            e.printStackTrace();
            return ObjEnvelop.getError("查询失败"+e.getMessage());
            return ObjEnvelop.getError("查询失败" + e.getMessage());
        }
    }
    @ApiOperation("获取药柜列表")
    @RequestMapping(value = "getMedicinecabinet", method = {RequestMethod.GET})
    public ObjEnvelop getMedicinecabinet() {
        List<Map<String, String>> list = monitorPlatformService.getMedicinecabinet();
        return ObjEnvelop.getSuccess("查询成功", list);
    }
    @ApiOperation("获取药柜数量")
    @RequestMapping(value = "getMedicinecabinetCount", method = {RequestMethod.GET})
    public ObjEnvelop getMedicinecabinetCount() {
        Map<String, String> map = monitorPlatformService.getMedicinecabinetCount();
        return ObjEnvelop.getSuccess("查询成功", map);
    }
    @ApiOperation("获取药柜详细信息")
    @RequestMapping(value = "getMedicineCabinetDetails", method = {RequestMethod.GET})
    public ObjEnvelop getMedicineCabinetDetails(@ApiParam(name = "deviceid", defaultValue = "设备id")
                               @RequestParam(value = "deviceid", required = true) String deviceid,
                               @ApiParam(name = "day", defaultValue = "天数")
                               @RequestParam(value = "day", required = true) String day) {
        try {
            /*808080eb7da2717d017da2cdc43e003e*/
            Map<String, List<Map>> getadddd = monitorPlatformService.getadddd(deviceid, day);
            return ObjEnvelop.getSuccess("成功", getadddd, 200);
        } catch (Exception e) {
            return ObjEnvelop.getError("失败" + e.getMessage());
        }
    }
    @ApiOperation("获取药柜地标")
    @RequestMapping(value = "getLongitudeAndLatitude", method = {RequestMethod.GET})
    public ObjEnvelop getLongitudeAndLatitude(){
        try {
            List<Map<String, Object>> longitudeAndLatitude = monitorPlatformService.getLongitudeAndLatitude();
            return ObjEnvelop.getSuccess("成功", longitudeAndLatitude, 200);
        } catch (Exception e) {
            return ObjEnvelop.getError("失败" + e.getMessage());
        }
    }

+ 891 - 676
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.JsonArray;
import com.yihu.iot.dao.dict.IotSystemDictDao;
import com.yihu.iot.dao.equipment.IotEquipmentDetailDao;
import com.yihu.iot.service.analyzer.WlyyIotTzDict;
@ -43,7 +44,7 @@ import java.util.*;
 * Created by yeshijie on 2020/5/11.
 */
@Service
public class MonitorPlatformService  {
public class MonitorPlatformService {
    @Value("${spring.wlyy.url}")
    private String wlyyUrl;
@ -55,7 +56,9 @@ public class MonitorPlatformService  {
    private String wxId;
    @Value("${wechat.flag}")
    private boolean flag;
    public static Map<String,String> tokenMap = new HashMap<>();
    @Value("${hlw.baseUrl}")
    private String baseUrl;
    public static Map<String, String> tokenMap = new HashMap<>();
    @Autowired
    private HttpClientUtil httpClientUtil;
@ -82,26 +85,27 @@ public class MonitorPlatformService  {
    /**
     * 获取位置信息
     *
     * @param diseaseCondition
     * @return
     */
    public MixEnvelop<LocationDataVO, LocationDataVO> findDeviceLocations(Integer diseaseCondition, Integer page, Integer size, String type,String deviceType,String deviceName) throws IOException {
    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;
        Integer total = 0;
        if(org.apache.commons.lang.StringUtils.isNotBlank(type)){
            JSONObject json = iotSearchPatientDeviceSN(type,page,size,deviceName);
        if (org.apache.commons.lang.StringUtils.isNotBlank(type)) {
            JSONObject json = iotSearchPatientDeviceSN(type, page, size, deviceName);
            total = json.getInteger("total");
            JSONArray list = json.getJSONArray("list");
            for(int i=0;i<list.size();i++){
                String sql ="select id, idcard idCard,category_code categoryCode,device_sn deviceSn,location,device_time deviceTime,disease_condition diseaseCondition,\n" +
                        "create_time createTime,device_name equimentName from device.wlyy_patient_device_location where del=0 and  device_sn='"+list.getString(i)+"'";
                List<Map<String,Object>> result = jdbcTemplate.queryForList(sql.toString());
            for (int i = 0; i < list.size(); i++) {
                String sql = "select id, idcard idCard,category_code categoryCode,device_sn deviceSn,location,device_time deviceTime,disease_condition diseaseCondition,\n" +
                        "create_time createTime,device_name equimentName from device.wlyy_patient_device_location where del=0 and  device_sn='" + list.getString(i) + "'";
                List<Map<String, Object>> result = jdbcTemplate.queryForList(sql.toString());
                List<LocationDataVO> locationDataVOList = new ArrayList<>();
                result.forEach(map->{
                result.forEach(map -> {
                    LocationDataVO locationDataVO = new LocationDataVO();
                    JSONObject location = JSONObject.parseObject(map.get("location").toString());
                    GeoPoint geoPoint = new GeoPoint(Double.parseDouble(location.get("lat").toString()),Double.parseDouble(location.get("lon").toString()));
                    GeoPoint geoPoint = new GeoPoint(Double.parseDouble(location.get("lat").toString()), Double.parseDouble(location.get("lon").toString()));
                    locationDataVO.setId(map.get("id").toString());
                    locationDataVO.setIdCard(AesEncryptUtils.decrypt(map.get("idCard").toString()));
                    locationDataVO.setCategoryCode(map.get("categoryCode").toString());
@ -120,50 +124,49 @@ public class MonitorPlatformService  {
            }
            envelop.setTotalCount(total);
            return envelop;
        }else {
        } else {
            List<LocationDataVO> euipmentList = new ArrayList<>();
            int totalEqCount=0;
            int totalCount=0;
            int totalEqCount = 0;
            int totalCount = 0;
            //小屋总数
            String manufacturerCode = deviceType;
            manufacturerCode = manufacturerCode.replace(",","','").replace("5","yituo").replace("10","xeek").replace("11","xiaomi");
            if(deviceType.contains("5")||deviceType.contains("10")||deviceType.contains("11")){
            manufacturerCode = manufacturerCode.replace(",", "','").replace("5", "yituo").replace("10", "xeek").replace("11", "xiaomi");
            if (deviceType.contains("5") || deviceType.contains("10") || deviceType.contains("11")) {
                totalEqCount = iotEqtDetailService.getEquipmentCount(manufacturerCode);
            }
            String[] categoryCodes= deviceType.split(",");
            if(categoryCodes.length==1&&(deviceType.contains("5")||deviceType.contains("10")||deviceType.contains("11"))){
                euipmentList = iotEqtDetailService.getEquipmentLocation(page,size,manufacturerCode);
            String[] categoryCodes = deviceType.split(",");
            if (categoryCodes.length == 1 && (deviceType.contains("5") || deviceType.contains("10") || deviceType.contains("11"))) {
                euipmentList = iotEqtDetailService.getEquipmentLocation(page, size, manufacturerCode);
                envelop.getDetailModelList().addAll(euipmentList);
            }
            else{
                if(deviceType.contains("5")||deviceType.contains("10")||deviceType.contains("11")){
                    euipmentList = iotEqtDetailService.getEquipmentLocation(page,size,manufacturerCode);
            } else {
                if (deviceType.contains("5") || deviceType.contains("10") || deviceType.contains("11")) {
                    euipmentList = iotEqtDetailService.getEquipmentLocation(page, size, manufacturerCode);
                    envelop.getDetailModelList().addAll(euipmentList);
                }
                StringBuffer sql = new StringBuffer("select id,idcard idCard,category_code categoryCode,device_sn deviceSn,location,device_time deviceTime,disease_condition diseaseCondition,\n" +
                        "create_time createTime,device_name equimentName\n" +
                        "from device.wlyy_patient_device_location  ");
                StringBuffer sqlCounts = new StringBuffer("select count(*) from device.wlyy_patient_device_location ");
                StringBuffer sqlCondition  = new StringBuffer("where del=0 ");
                if (diseaseCondition!=null){
                    sqlCondition.append(" and disease_condition ="+diseaseCondition);
                StringBuffer sqlCondition = new StringBuffer("where del=0 ");
                if (diseaseCondition != null) {
                    sqlCondition.append(" and disease_condition =" + diseaseCondition);
                }
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                    sqlCondition.append(" and category_code in('").append(deviceType.replace(",","','")).append("') ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)) {
                    sqlCondition.append(" and category_code in('").append(deviceType.replace(",", "','")).append("') ");
                }
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
                    sqlCondition.append(" and device_name in ('").append(deviceName.replace(",","','")).append("') ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)) {
                    sqlCondition.append(" and device_name in ('").append(deviceName.replace(",", "','")).append("') ");
                }
                sql.append(sqlCondition);
                sqlCounts.append(sqlCondition);
                sql.append( " limit "+(page-1)*size+","+size);
                totalCount = jdbcTemplate.queryForObject(sqlCounts.toString(),Integer.class);
                List<Map<String,Object>> result = jdbcTemplate.queryForList(sql.toString());
                sql.append(" limit " + (page - 1) * size + "," + size);
                totalCount = jdbcTemplate.queryForObject(sqlCounts.toString(), Integer.class);
                List<Map<String, Object>> result = jdbcTemplate.queryForList(sql.toString());
                List<LocationDataVO> locationDataVOList = new ArrayList<>();
                result.forEach(map->{
                result.forEach(map -> {
                    LocationDataVO locationDataVO = new LocationDataVO();
                    JSONObject location = JSONObject.parseObject(map.get("location").toString());
                    GeoPoint geoPoint = new GeoPoint(Double.parseDouble(location.get("lat").toString()),Double.parseDouble(location.get("lon").toString()));
                    GeoPoint geoPoint = new GeoPoint(Double.parseDouble(location.get("lat").toString()), Double.parseDouble(location.get("lon").toString()));
                    locationDataVO.setId(map.get("id").toString());
                    locationDataVO.setIdCard(AesEncryptUtils.decrypt(map.get("idCard").toString()));
                    locationDataVO.setCategoryCode(map.get("categoryCode").toString());
@ -180,45 +183,45 @@ public class MonitorPlatformService  {
                });
                envelop.getDetailModelList().addAll(locationDataVOList);
            }
            envelop.setTotalCount(totalCount>totalEqCount?totalCount:totalEqCount);
            envelop.setTotalCount(totalCount > totalEqCount ? totalCount : totalEqCount);
            return envelop;
        }
    }
    public com.alibaba.fastjson.JSONObject iotSearchPatientDeviceSN(String type,Integer page,Integer pageSize,String deviceName){
    public com.alibaba.fastjson.JSONObject iotSearchPatientDeviceSN(String type, Integer page, Integer pageSize, String deviceName) {
        if(page != 0){
        if (page != 0) {
            page = page - 1;
        }
        StringBuffer sql = new StringBuffer("select t.device_sn from");
        sql.append("  ( SELECT DISTINCT d.* FROM wlyy.wlyy_patient_device d, wlyy.wlyy_sign_family f WHERE f.`status` > 0 AND f.patient = d.`user`  ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
            sql.append("and d.device_name in ('").append(deviceName.replace(",","','")).append("') ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)) {
            sql.append("and d.device_name in ('").append(deviceName.replace(",", "','")).append("') ");
        }
        sql.append("  ) t, wlyy.wlyy_patient p " );
        sql.append("  ) t, wlyy.wlyy_patient p ");
        sql.append("  LEFT JOIN wlyy.wlyy_sign_patient_label_info l on  p. CODE = l.patient");
        sql.append("   and l.`status`=1 AND l.label_type = 3 and l.label='"+type+"'");
        sql.append(" WHERE t.user = p. CODE limit "+page+","+pageSize);
        List<String> list = jdbcTemplate.queryForList(sql.toString(),String.class);
        sql.append("   and l.`status`=1 AND l.label_type = 3 and l.label='" + type + "'");
        sql.append(" WHERE t.user = p. CODE limit " + page + "," + pageSize);
        List<String> list = jdbcTemplate.queryForList(sql.toString(), String.class);
        Integer count = 0;
        StringBuffer countsql = new StringBuffer("select count(t.device_sn) total from");
        countsql.append("  ( SELECT DISTINCT d.* FROM wlyy.wlyy_patient_device d, wlyy.wlyy_sign_family f WHERE f.`status` > 0 AND f.patient = d.`user`  ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)){
            countsql.append("and d.device_name in ('").append(deviceName.replace(",","','")).append("') ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)) {
            countsql.append("and d.device_name in ('").append(deviceName.replace(",", "','")).append("') ");
        }
        countsql.append("   ) t,wlyy.wlyy_patient p " );
        countsql.append("   ) t,wlyy.wlyy_patient p ");
        countsql.append("  LEFT JOIN wlyy.wlyy_sign_patient_label_info l on  p. CODE = l.patient");
        countsql.append("   and l.`status`=1 AND l.label_type = 3 and l.label='"+type+"'");
        countsql.append("   and l.`status`=1 AND l.label_type = 3 and l.label='" + type + "'");
        countsql.append(" WHERE t.user = p. CODE ");
        count = jdbcTemplate.queryForObject(countsql.toString(),Integer.class);
        count = jdbcTemplate.queryForObject(countsql.toString(), Integer.class);
        com.alibaba.fastjson.JSONObject result = new com.alibaba.fastjson.JSONObject();
        result.put("total",count);
        result.put("list",list);
        result.put("total", count);
        result.put("list", list);
        return result;
    }
@ -226,105 +229,106 @@ public class MonitorPlatformService  {
     * 根据病种类型,搜索已绑定设备的居民设备SN码
     * 类型(1高血压 2糖尿病)
     */
    public String searchpatientdevicesn(String type,Integer page,Integer size){
    public String searchpatientdevicesn(String type, Integer page, Integer size) {
        String url = "/wlyygc/iot_monitoring/searchpatientdevicesn";
        Map<String, Object> params = new HashMap<>();
        params.put("type",type);
        params.put("page",page);
        params.put("pageSize",size);
        return sendGet(url,params);
        params.put("type", type);
        params.put("page", page);
        params.put("pageSize", size);
        return sendGet(url, params);
    }
    /**
     * 设备发放情况
     */
    public String equipmentDistribution(String startTime,String endTime,
                                        String deviceType,String area,String hospital){
    public String equipmentDistribution(String startTime, String endTime,
                                        String deviceType, String area, String hospital) {
        String url = "/wlyygc/iot_monitoring/equipmentDistribution";
        Map<String, Object> params = new HashMap<>();
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        params.put("hospital",hospital);
        String anotherResult = sendGet(url,params);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("deviceType", deviceType);
        params.put("area", area);
        params.put("hospital", hospital);
        String anotherResult = sendGet(url, params);
        String sqlAre = dealSql(params);
        List<Map<String, Object>> iotEquip = hibenateUtils.createSQLQuery(sqlAre);
        if(StringUtils.isEmpty(deviceType)){
        if (StringUtils.isEmpty(deviceType)) {
            deviceType = "";
        }
        String[] str =deviceType.split(",");
        String[] str = deviceType.split(",");
        List<String> list = new ArrayList<>();
        for (int i=0;i<str.length;i++){
        for (int i = 0; i < str.length; i++) {
            list.add(str[i]);
        }
        JSONObject jsonObject = JSONObject.parseObject(anotherResult);
        IotSystemDictDO iotSystemDictDO = iotSystemDictDao.findByDictNameAndValueAndDel("DEVICE_TYPE","健康小屋",1);
        if (null!=iotSystemDictDO&&list.size()>1&&list.contains(iotSystemDictDO.getCode())){
            if("200".equals(jsonObject.get("status").toString())){
                JSONArray dataresult= jsonObject.getJSONArray("data");
        IotSystemDictDO iotSystemDictDO = iotSystemDictDao.findByDictNameAndValueAndDel("DEVICE_TYPE", "健康小屋", 1);
        if (null != iotSystemDictDO && list.size() > 1 && list.contains(iotSystemDictDO.getCode())) {
            if ("200".equals(jsonObject.get("status").toString())) {
                JSONArray dataresult = jsonObject.getJSONArray("data");
                JSONArray resultArray = new JSONArray();
                if (dataresult.size()>0){
                    for(int i=0;i<dataresult.size();i++){
                        JSONObject item= JSONObject.parseObject(dataresult.get(i).toString());
                        if(null!=item.get("num")){
                if (dataresult.size() > 0) {
                    for (int i = 0; i < dataresult.size(); i++) {
                        JSONObject item = JSONObject.parseObject(dataresult.get(i).toString());
                        if (null != item.get("num")) {
                            Integer itemCount = Integer.parseInt(item.get("num").toString());
                            for(Map<String, Object> map:iotEquip){
                                if (item.get("code").toString().equals(map.get("belong_are_code"))){
                                    itemCount = Integer.parseInt(map.get("total").toString())+itemCount;
                                    item.put("num",itemCount);
                            for (Map<String, Object> map : iotEquip) {
                                if (item.get("code").toString().equals(map.get("belong_are_code"))) {
                                    itemCount = Integer.parseInt(map.get("total").toString()) + itemCount;
                                    item.put("num", itemCount);
                                }
                            }
                        }
                        resultArray.add(item);
                    }
                }
                jsonObject.replace("data",resultArray);
                jsonObject.replace("data", resultArray);
                System.out.println(jsonObject.toString());
            }
            return jsonObject.toString();
        }else if (list.size()==1&&list.contains(iotSystemDictDO.getCode())){
        } else if (list.size() == 1 && list.contains(iotSystemDictDO.getCode())) {
            List list1 = new ArrayList();
            for (Map<String,Object> mao:iotEquip){
               JSONObject jo = new JSONObject(mao);
               list1.add(jo);
            for (Map<String, Object> mao : iotEquip) {
                JSONObject jo = new JSONObject(mao);
                list1.add(jo);
            }
            jsonObject.replace("data",JSONArray.parse(list1.toString()));
            jsonObject.replace("data", JSONArray.parse(list1.toString()));
            return jsonObject.toString();
        }else {
           return anotherResult;
        } else {
            return anotherResult;
        }
    }
    private String dealSql(Map<String, Object> params){
    private String dealSql(Map<String, Object> params) {
        StringBuffer sql = new StringBuffer();
        sql.append("select count(1) AS \"num\",t.belong_are AS \"name\",t.belong_are_code AS \"code\" from iot_equipmet_detail t ");
        sql.append(" where 1=1 ");
        if (null!=params.get("area")){
            sql.append(" and t.belong_are_code = '"+params.get("area").toString()+"'");
        if (null != params.get("area")) {
            sql.append(" and t.belong_are_code = '" + params.get("area").toString() + "'");
        }
        if (null!=params.get("startTime")) {
        if (null != params.get("startTime")) {
            //sql.append(" and t.update_time > '" + beginTime+"'");//DateUtil.stringToDate(beginTime,"yyyy-MM-dd HH:mm:ss")
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    sql.append( " and t.create_time >= str_to_date('" + params.get("startTime").toString() + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                }else {
                    sql.append(  " and t.create_time >= to_date('" + params.get("startTime").toString() + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                if (flag) {
                    sql.append(" and t.create_time >= str_to_date('" + params.get("startTime").toString() + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                } else {
                    sql.append(" and t.create_time >= to_date('" + params.get("startTime").toString() + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                }
            } else {
                sql.append( " AND t.create_time >='" + params.get("startTime").toString() + " 00:00:00'");
                sql.append(" AND t.create_time >='" + params.get("startTime").toString() + " 00:00:00'");
            }
        }
        if (null!=params.get("endTime")) {
        if (null != params.get("endTime")) {
            //sql.append(" and t.update_time < '" + endTime+"'");//DateUtil.stringToDate(endTime,"yyyy-MM-dd HH:mm:ss")
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    sql.append( " and t.create_time <= str_to_date('" + params.get("endTime").toString() + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                }else {
                    sql.append(  " and t.create_time <= to_date('" + params.get("endTime").toString() + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                if (flag) {
                    sql.append(" and t.create_time <= str_to_date('" + params.get("endTime").toString() + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                } else {
                    sql.append(" and t.create_time <= to_date('" + params.get("endTime").toString() + " 00:00:00','YYYY-MM-DD HH24:MI:SS')");
                }
            } else {
                sql.append( " AND t.create_time <='" + params.get("endTime").toString() + " 00:00:00'");
                sql.append(" AND t.create_time <='" + params.get("endTime").toString() + " 00:00:00'");
            }
        }
        sql.append(" group by t.belong_are_code order by \"total\" desc ");
@ -335,98 +339,105 @@ public class MonitorPlatformService  {
     * 慢病患者情况-统计
     * 类型(2糖尿病,1高血压)
     */
    public String chronicDiseaseCount(String type){
    public String chronicDiseaseCount(String type) {
        String url = "/wlyygc/iot_monitoring/chronicDiseaseCount";
        Map<String, Object> params = new HashMap<>();
        params.put("type",type);
        return sendGet(url,params);
        params.put("type", type);
        return sendGet(url, params);
    }
    /**
     * 预警信息警报
     *
     * @param page
     * @param pageSize
     * @return
     */
    public String warningInformationAlarm(Integer page,Integer pageSize){
    public String warningInformationAlarm(Integer page, Integer pageSize) {
        String url = "/wlyygc/iot_monitoring/warningInformationAlarm";
        Map<String, Object> params = new HashMap<>();
        params.put("page",page);
        params.put("pageSize",pageSize);
        return sendGet(url,params);
        params.put("page", page);
        params.put("pageSize", pageSize);
        return sendGet(url, params);
    }
    /**
     * 居民 医生搜索
     *
     * @param page
     * @param pageSize
     * @return
     */
    public String searchPatient(String name,Integer page,Integer pageSize,String idcards){
    public String searchPatient(String name, Integer page, Integer pageSize, String idcards) {
        String url = "/wlyygc/iot_monitoring/searchPatient";
        Map<String, Object> params = new HashMap<>();
        params.put("name",name);
        params.put("page",page);
        params.put("pageSize",pageSize);
        params.put("idcards",idcards);
        return sendGet(url,params);
        params.put("name", name);
        params.put("page", page);
        params.put("pageSize", pageSize);
        params.put("idcards", idcards);
        return sendGet(url, params);
    }
    /**
     * 设备绑定情况
     *
     * @param type 设备类型(1血糖仪,2血压计
     * @return
     */
    public String deviceBinding(String type){
    public String deviceBinding(String type) {
        String url = "/wlyygc/iot_monitoring/deviceBinding";
        Map<String, Object> params = new HashMap<>();
        params.put("type",type);
        return sendGet(url,params);
        params.put("type", type);
        return sendGet(url, params);
    }
    /**
     * 个人信息
     *
     * @param patient
     * @return
     */
    @RequestMapping(value = "/persionalInfo",method = RequestMethod.GET)
    @RequestMapping(value = "/persionalInfo", method = RequestMethod.GET)
    @ApiOperation("个人信息")
    public String persionalInfo(String patient){
    public String persionalInfo(String patient) {
        String url = "/wlyygc/iot_monitoring/persionalInfo";
        Map<String, Object> params = new HashMap<>();
        params.put("patient",patient);
        return sendGet(url,params);
        params.put("patient", patient);
        return sendGet(url, params);
    }
    /**
     * 家人信息
     *
     * @param patient
     * @return
     */
    public String familyMember(String patient){
    public String familyMember(String patient) {
        String url = "/wlyygc/iot_monitoring/familyMember";
        Map<String, Object> params = new HashMap<>();
        params.put("patient",patient);
        return sendGet(url,params);
        params.put("patient", patient);
        return sendGet(url, params);
    }
    /**
     * 健康设备
     *
     * @param patient
     * @return
     */
    @RequestMapping(value = "/healthDevice",method = RequestMethod.GET)
    @RequestMapping(value = "/healthDevice", method = RequestMethod.GET)
    @ApiOperation("健康设备")
    public String healthDevice(String patient){
    public String healthDevice(String patient) {
        String url = "/wlyygc/iot_monitoring/healthDevice";
        Map<String, Object> params = new HashMap<>();
        params.put("patient",patient);
        return sendGet(url,params);
        params.put("patient", patient);
        return sendGet(url, params);
    }
    /**
     * 体征数据
     *
     * @param patient
     * @param type
     * @param gi_type
@ -434,38 +445,40 @@ public class MonitorPlatformService  {
     * @param end
     * @return
     */
    public String getHealthIndexChartByPatient(String patient, Integer type, Integer gi_type, String begin, String end,String time) {
    public String getHealthIndexChartByPatient(String patient, Integer type, Integer gi_type, String begin, String end, String time) {
        String url = "/wlyygc/iot_monitoring/chart";
        Map<String, Object> params = new HashMap<>();
        params.put("patient",patient);
        params.put("type",type);
        params.put("time",time);
        params.put("begin",begin);
        params.put("end",end);
        params.put("gi_type",gi_type);
        return sendGet(url,params);
        params.put("patient", patient);
        params.put("type", type);
        params.put("time", time);
        params.put("begin", begin);
        params.put("end", end);
        params.put("gi_type", gi_type);
        return sendGet(url, params);
    }
    /**
     * 获取门诊记录/住院记录(基卫+APP)
     *
     * @param patient
     * @param type 类型(1血糖,2血压)
     * @param type     类型(1血糖,2血压)
     * @param page
     * @param pageSize
     * @return
     */
    public String getAllEvent(String patient,String type,String page,String pageSize) {
    public String getAllEvent(String patient, String type, String page, String pageSize) {
        String url = "/wlyygc/iot_monitoring/event";
        Map<String, Object> params = new HashMap<>();
        params.put("patient",patient);
        params.put("type",type);
        params.put("page",page);
        params.put("pageSize",pageSize);
        return sendGet(url,params);
        params.put("patient", patient);
        params.put("type", type);
        params.put("page", page);
        params.put("pageSize", pageSize);
        return sendGet(url, params);
    }
    /**
     * 根据患者标志获取健康指标
     *
     * @param idcard
     * @param type
     * @param begin
@ -474,56 +487,58 @@ public class MonitorPlatformService  {
     * @param pagesize
     * @return
     */
    public String getHealthIndexByIdcard(String idcard,int type, String begin,String end, int page,int pagesize,HttpServletRequest request) {
    public String getHealthIndexByIdcard(String idcard, int type, String begin, String end, int page, int pagesize, HttpServletRequest request) {
        String url = "/wlyygc/iot_monitoring/health_index/listByIdcard";
        Map<String, Object> params = new HashMap<>();
        params.put("idcard",idcard);
        params.put("begin",begin);
        params.put("end",end);
        params.put("type",type);
        params.put("page",page);
        params.put("pagesize",pagesize);
        try{
        params.put("idcard", idcard);
        params.put("begin", begin);
        params.put("end", end);
        params.put("type", type);
        params.put("page", page);
        params.put("pagesize", pagesize);
        try {
            //记录log
            iotInterfaceLogService.saveLog("zy808081724b116c017254d437fe000b",JSONObject.toJSONString(params),null, request,200,"getHealthIndexByIdcard");
        }catch (Exception e){
            iotInterfaceLogService.saveLog("zy808081724b116c017254d437fe000b", JSONObject.toJSONString(params), null, request, 200, "getHealthIndexByIdcard");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sendGet(url,params);
        return sendGet(url, params);
    }
    /**
     * 获取居民信息
     *
     * @param idcard
     * @return
     */
    public String patientInfo(String idcard) {
        String url = "/wlyygc/iot_monitoring/patientInfo";
        Map<String, Object> params = new HashMap<>();
        params.put("idcard",idcard);
        return sendGet(url,params);
        params.put("idcard", idcard);
        return sendGet(url, params);
    }
    /**
     * 质控情况
     *
     * @param page
     * @param pageSize
     * @param deviceSn
     * @return
     */
    public List<JSONObject> deviceOverhaulList(Integer page,Integer pageSize,String deviceSn){
    public List<JSONObject> deviceOverhaulList(Integer page, Integer pageSize, String deviceSn) {
        String sql = "SELECT o.time,o.`status`,o.remark from iot_patient_device d,iot_device_overhaul o" +
                " WHERE d.device_sn = '"+deviceSn+"' and d.id = o.patient_device_id ORDER BY o.time desc limit ?,?";
        return myJdbcTemplate.queryJson(sql.toString(),new Object[]{(page-1)*pageSize,pageSize});
                " WHERE d.device_sn = '" + deviceSn + "' and d.id = o.patient_device_id ORDER BY o.time desc limit ?,?";
        return myJdbcTemplate.queryJson(sql.toString(), new Object[]{(page - 1) * pageSize, pageSize});
    }
    public Integer deviceOverhaulListTotal(String deviceSn){
    public Integer deviceOverhaulListTotal(String deviceSn) {
        String sql = "SELECT count(o.id) c from iot_patient_device d,iot_device_overhaul o" +
                " WHERE d.device_sn = '"+deviceSn+"' and d.id = o.patient_device_id ";
        List<JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{});
        if(list.size()>0){
                " WHERE d.device_sn = '" + deviceSn + "' and d.id = o.patient_device_id ";
        List<JSONObject> list = myJdbcTemplate.queryJson(sql.toString(), new Object[]{});
        if (list.size() > 0) {
            return list.get(0).getInteger("c");
        }
        return 0;
@ -531,18 +546,19 @@ public class MonitorPlatformService  {
    /**
     * 入住情况
     *
     * @return
     */
    public JSONObject residentUserType(){
    public JSONObject residentUserType() {
        String sql = "SELECT IFNULL(enter_type,'0') type,COUNT(id) num from iot_company WHERE del =1 GROUP BY enter_type";
        List<JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{});
        List<JSONObject> list = myJdbcTemplate.queryJson(sql.toString(), new Object[]{});
        int total = 0;
        int manufacturer = 0;//厂商
        int supplier = 0;// 供应商
        int agent = 0;//代理商
        int platform = 0;//接入平台
        for(JSONObject json:list){
            switch (json.getString("type")){
        for (JSONObject json : list) {
            switch (json.getString("type")) {
                case "0":
                    platform = json.getInteger("num");
                    break;
@ -557,25 +573,25 @@ public class MonitorPlatformService  {
                    break;
            }
        }
        total = manufacturer+supplier+agent+platform;
        total = manufacturer + supplier + agent + platform;
        JSONObject json = new JSONObject();
        json.put("total",total);
        json.put("manufacturer",manufacturer);
        json.put("supplier",supplier);
        json.put("agent",agent);
        json.put("platform",platform);
        if(total>0){
        json.put("total", total);
        json.put("manufacturer", manufacturer);
        json.put("supplier", supplier);
        json.put("agent", agent);
        json.put("platform", platform);
        if (total > 0) {
            DecimalFormat df = new DecimalFormat("0.00");
            json.put("manufacturerRange", df.format(manufacturer > 0.0 ? (manufacturer/ (total * 1.0000) * 100) : 0.0) + "%");
            json.put("supplierRange", df.format(supplier > 0.0 ? (supplier/ (total * 1.0000) * 100) : 0.0) + "%");
            json.put("agentRange", df.format(agent > 0.0 ? (agent/ (total * 1.0000) * 100) : 0.0) + "%");
            json.put("platformRange", df.format(platform > 0.0 ? (platform/ (total * 1.0000) * 100) : 0.0) + "%");
        }else {
            json.put("manufacturerRange","0.0%");
            json.put("supplierRange","0.0%");
            json.put("agentRange","0.0%");
            json.put("platformRange","0.0%");
            json.put("manufacturerRange", df.format(manufacturer > 0.0 ? (manufacturer / (total * 1.0000) * 100) : 0.0) + "%");
            json.put("supplierRange", df.format(supplier > 0.0 ? (supplier / (total * 1.0000) * 100) : 0.0) + "%");
            json.put("agentRange", df.format(agent > 0.0 ? (agent / (total * 1.0000) * 100) : 0.0) + "%");
            json.put("platformRange", df.format(platform > 0.0 ? (platform / (total * 1.0000) * 100) : 0.0) + "%");
        } else {
            json.put("manufacturerRange", "0.0%");
            json.put("supplierRange", "0.0%");
            json.put("agentRange", "0.0%");
            json.put("platformRange", "0.0%");
        }
        return json;
@ -583,50 +599,51 @@ public class MonitorPlatformService  {
    /**
     * 接口调用情况
     *
     * @param startTime
     * @param endTime
     * @param type
     * @return
     */
    public List<JSONObject> intefaceLogList(String startTime,String endTime,String type){
    public List<JSONObject> intefaceLogList(String startTime, String endTime, String type) {
        String sql = "SELECT ";
        switch (type){
        switch (type) {
            case "month":
                sql+= " date_format(time,'%m') ";
                sql += " date_format(time,'%m') ";
                break;
            case "year":
                sql+= " date_format(time,'%Y') ";
                sql += " date_format(time,'%Y') ";
                break;
            case "day":
                sql+= " date_format(time,'%Y-%m-%d') ";
                sql += " date_format(time,'%Y-%m-%d') ";
                break;
            case "week":
                sql+= " date_format(time,'%u') ";
                sql += " date_format(time,'%u') ";
                break;
        }
        sql+= " date ,COUNT(*) num from iot_interface_log where 1=1 ";
        if(StringUtils.isEmpty(startTime)){
            sql+= " and time>='"+startTime+"'";
        sql += " date ,COUNT(*) num from iot_interface_log where 1=1 ";
        if (StringUtils.isEmpty(startTime)) {
            sql += " and time>='" + startTime + "'";
        }
        if(StringUtils.isEmpty(endTime)){
            sql+= " and time>='"+endTime+"'";
        if (StringUtils.isEmpty(endTime)) {
            sql += " and time>='" + endTime + "'";
        }
        sql+=" GROUP BY date ";
        sql += " GROUP BY date ";
        return myJdbcTemplate.queryJson(sql.toString(),new Object[]{});
        return myJdbcTemplate.queryJson(sql.toString(), new Object[]{});
    }
    /**
     * 地区字典
     */
    public JSONArray areaDict(){
    public JSONArray areaDict() {
        String url = "/wlyygc/iot_monitoring/areaDict";
        Map<String, Object> params = new HashMap<>();
        String response = sendGet(url,params);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONArray("data");
        }
@ -636,13 +653,13 @@ public class MonitorPlatformService  {
    /**
     * 医院字典
     */
    public JSONArray hospitalDict(String town){
    public JSONArray hospitalDict(String town) {
        String url = "/wlyygc/iot_monitoring/hospitalDict";
        Map<String, Object> params = new HashMap<>();
        params.put("town",town);
        String response = sendGet(url,params);
        params.put("town", town);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONArray("data");
        }
@ -652,89 +669,89 @@ public class MonitorPlatformService  {
    /**
     * 智能设备发放
     */
    public JSONArray smartDeviceDistribution(String startTime,String endTime,
                                             String deviceType,String area,String hospital){
    public JSONArray smartDeviceDistribution(String startTime, String endTime,
                                             String deviceType, String area, String hospital) {
        String url = "/wlyygc/iot_monitoring/smartDeviceDistribution";
        Map<String, Object> params = new HashMap<>();
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        params.put("hospital",hospital);
        String response = sendGet(url,params);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("deviceType", deviceType);
        params.put("area", area);
        params.put("hospital", hospital);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
            IotSystemDictDO iotSystemDictDO = iotSystemDictDao.findByDictNameAndValueAndDel("DEVICE_TYPE","健康小屋",1);
        if (json.getInteger("status") == 200) {
            IotSystemDictDO iotSystemDictDO = iotSystemDictDao.findByDictNameAndValueAndDel("DEVICE_TYPE", "健康小屋", 1);
            JSONArray jsonArray = json.getJSONArray("data");
            String[] str =deviceType.split(",");
            String[] str = deviceType.split(",");
            List<String> list = new ArrayList<>();
            for (int i=0;i<str.length;i++){
            for (int i = 0; i < str.length; i++) {
                list.add(str[i]);
            }
            if (iotSystemDictDO!=null){
                if (!list.contains(iotSystemDictDO.getCode())){
                    for (int i=0;i<jsonArray.size();i++){
            if (iotSystemDictDO != null) {
                if (!list.contains(iotSystemDictDO.getCode())) {
                    for (int i = 0; i < jsonArray.size(); i++) {
                        JSONObject jo = jsonArray.getJSONObject(i);
                        String tmp = jo.getString("type");
                        if("1".equals(tmp)){
                            jo.put("typeName","血糖仪");
                        }else if("2".equals(tmp)){
                            jo.put("typeName","血压计");
                        }else if("3".equals(tmp)){
                            jo.put("typeName","智能药盒");
                        }else if("4".equals(tmp)){
                            jo.put("typeName","智能手表");
                        if ("1".equals(tmp)) {
                            jo.put("typeName", "血糖仪");
                        } else if ("2".equals(tmp)) {
                            jo.put("typeName", "血压计");
                        } else if ("3".equals(tmp)) {
                            jo.put("typeName", "智能药盒");
                        } else if ("4".equals(tmp)) {
                            jo.put("typeName", "智能手表");
                        }
                    }
                }else {
                    if (jsonArray!=null&&jsonArray.size()!=0){
                        for (int i=0;i<jsonArray.size();i++){
                } else {
                    if (jsonArray != null && jsonArray.size() != 0) {
                        for (int i = 0; i < jsonArray.size(); i++) {
                            JSONObject jo = jsonArray.getJSONObject(i);
                            String tmp = jo.getString("type");
                            if("1".equals(tmp)){
                                jo.put("typeName","血糖仪");
                            }else if("2".equals(tmp)){
                                jo.put("typeName","血压计");
                            }else if("3".equals(tmp)){
                                jo.put("typeName","智能药盒");
                            }else if("4".equals(tmp)){
                                jo.put("typeName","智能手表");
                            if ("1".equals(tmp)) {
                                jo.put("typeName", "血糖仪");
                            } else if ("2".equals(tmp)) {
                                jo.put("typeName", "血压计");
                            } else if ("3".equals(tmp)) {
                                jo.put("typeName", "智能药盒");
                            } else if ("4".equals(tmp)) {
                                jo.put("typeName", "智能手表");
                            }
                        }
                        if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)){
                            JSONObject jsonObject= new JSONObject();
                            jsonObject.put("type",iotSystemDictDO.getCode());
                            jsonObject.put("typeName",iotSystemDictDO.getValue());
                            jsonObject.put("signNum",0);
                            jsonObject.put("unSignNum",0);
                        if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)) {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("type", iotSystemDictDO.getCode());
                            jsonObject.put("typeName", iotSystemDictDO.getValue());
                            jsonObject.put("signNum", 0);
                            jsonObject.put("unSignNum", 0);
                            jsonArray.add(jsonObject);
                        }else {
                            Long count = iotEqtDetailService.findCountByHealthHourse(startTime,endTime,area);
                            JSONObject jsonObject= new JSONObject();
                            jsonObject.put("type",iotSystemDictDO.getCode());
                            jsonObject.put("typeName",iotSystemDictDO.getValue());
                            jsonObject.put("signNum",count);
                            jsonObject.put("unSignNum",0);
                        } else {
                            Long count = iotEqtDetailService.findCountByHealthHourse(startTime, endTime, area);
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("type", iotSystemDictDO.getCode());
                            jsonObject.put("typeName", iotSystemDictDO.getValue());
                            jsonObject.put("signNum", count);
                            jsonObject.put("unSignNum", 0);
                            jsonArray.add(jsonObject);
                        }
                    }else {
                        if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)){
                    } else {
                        if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)) {
                            jsonArray = new JSONArray();
                            JSONObject jsonObject= new JSONObject();
                            jsonObject.put("type",iotSystemDictDO.getCode());
                            jsonObject.put("typeName",iotSystemDictDO.getValue());
                            jsonObject.put("signNum",0);
                            jsonObject.put("unSignNum",0);
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("type", iotSystemDictDO.getCode());
                            jsonObject.put("typeName", iotSystemDictDO.getValue());
                            jsonObject.put("signNum", 0);
                            jsonObject.put("unSignNum", 0);
                            jsonArray.add(jsonObject);
                        }else {
                            Long count = iotEqtDetailService.findCountByHealthHourse(startTime,endTime,area);
                        } else {
                            Long count = iotEqtDetailService.findCountByHealthHourse(startTime, endTime, area);
                            jsonArray = new JSONArray();
                            JSONObject jsonObject= new JSONObject();
                            jsonObject.put("type",iotSystemDictDO.getCode());
                            jsonObject.put("typeName",iotSystemDictDO.getValue());
                            jsonObject.put("signNum",count);
                            jsonObject.put("unSignNum",0);
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("type", iotSystemDictDO.getCode());
                            jsonObject.put("typeName", iotSystemDictDO.getValue());
                            jsonObject.put("signNum", count);
                            jsonObject.put("unSignNum", 0);
                            jsonArray.add(jsonObject);
                        }
@ -750,20 +767,21 @@ public class MonitorPlatformService  {
    /**
     * 设备使用数据
     *
     * @param page
     * @param pageSize
     * @param deviceSn
     * @return
     */
    public JSONObject deviceUseData(Integer page,Integer pageSize,String deviceSn){
    public JSONObject deviceUseData(Integer page, Integer pageSize, String deviceSn) {
        String url = "/wlyygc/iot_monitoring/deviceUseData";
        Map<String, Object> params = new HashMap<>();
        params.put("page",page);
        params.put("pageSize",pageSize);
        params.put("deviceSn",deviceSn);
        String response = sendGet(url,params);
        params.put("page", page);
        params.put("pageSize", pageSize);
        params.put("deviceSn", deviceSn);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONObject("data");
        }
@ -772,35 +790,36 @@ public class MonitorPlatformService  {
    /**
     * 设备使用数据
     *
     * @param patient
     * @param deviceSn
     * @return
     */
    public JSONObject deviceInfo(String deviceSn,String patient){
    public JSONObject deviceInfo(String deviceSn, String patient) {
        String url = "/wlyygc/iot_monitoring/deviceInfo";
        Map<String, Object> params = new HashMap<>();
        params.put("patient",patient);
        params.put("deviceSn",deviceSn);
        String response = sendGet(url,params);
        params.put("patient", patient);
        params.put("deviceSn", deviceSn);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            JSONObject tmp = json.getJSONObject("data");
            //查询物联网获取设备信息
            String sql = "SELECT d.device_sn,b.supplier_name supplierName,b.origin_place originPlace,e.product_img productImg" +
                    ",e.description  from iot_device d,iot_product_base_info b,iot_product_extend_info e" +
                    " WHERE d.device_sn = '"+deviceSn+"' and d.product_id = b.id and d.product_id = e.product_id";
            List<JSONObject> list = myJdbcTemplate.queryJson(sql,new Object[]{});
            if(list!=null&&list.size()>0){
                    " WHERE d.device_sn = '" + deviceSn + "' and d.product_id = b.id and d.product_id = e.product_id";
            List<JSONObject> list = myJdbcTemplate.queryJson(sql, new Object[]{});
            if (list != null && list.size() > 0) {
                JSONObject js = list.get(0);
                tmp.put("supplierName",js.getString("supplierName"));
                tmp.put("originPlace",js.getString("originPlace"));
                tmp.put("productImg",js.getString("productImg"));
                tmp.put("description",js.getString("description"));
            }else{
                tmp.put("supplierName","");
                tmp.put("originPlace","");
                tmp.put("productImg","");
                tmp.put("description","");
                tmp.put("supplierName", js.getString("supplierName"));
                tmp.put("originPlace", js.getString("originPlace"));
                tmp.put("productImg", js.getString("productImg"));
                tmp.put("description", js.getString("description"));
            } else {
                tmp.put("supplierName", "");
                tmp.put("originPlace", "");
                tmp.put("productImg", "");
                tmp.put("description", "");
            }
            return tmp;
        }
@ -810,18 +829,19 @@ public class MonitorPlatformService  {
    /**
     * 设备使用情况分析
     *
     * @param type
     * @param name
     * @return
     */
    public JSONObject deviceUsageAnalysis(String type,String name){
    public JSONObject deviceUsageAnalysis(String type, String name) {
        String url = "/wlyygc/iot_monitoring/deviceUsageAnalysis";
        Map<String, Object> params = new HashMap<>();
        params.put("type",type);
        params.put("name",name);
        String response = sendGet(url,params);
        params.put("type", type);
        params.put("name", name);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONObject("data");
        }
@ -830,6 +850,7 @@ public class MonitorPlatformService  {
    /**
     * 85-发放率,96使用率,86绑定率,88指导率
     *
     * @param startTime
     * @param endTime
     * @param deviceType
@ -837,19 +858,19 @@ public class MonitorPlatformService  {
     * @param hospital
     * @return
     */
    public JSONObject totalRange(String startTime,String endTime,
                                 String deviceType,String area,String hospital,String quotaCode){
    public JSONObject totalRange(String startTime, String endTime,
                                 String deviceType, String area, String hospital, String quotaCode) {
        String url = "/wlyygc/iot_monitoring/totalRange";
        Map<String, Object> params = new HashMap<>();
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        params.put("hospital",hospital);
        params.put("quotaCode",quotaCode);
        String response = sendGet(url,params);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("deviceType", deviceType);
        params.put("area", area);
        params.put("hospital", hospital);
        params.put("quotaCode", quotaCode);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONObject("data");
        }
@ -857,20 +878,21 @@ public class MonitorPlatformService  {
    }
    public JSONObject getTotalRange(String startTime, String endTime,
                                  String deviceType, String area, String hospital){
                                    String deviceType, String area, String hospital) {
        JSONObject result = new JSONObject();
        result.put("grant",totalRange(startTime,endTime,deviceType,area,hospital,"85"));
        result.put("binding",totalRange(startTime,endTime,deviceType,area,hospital,"86"));
        result.put("guide",totalRange(startTime,endTime,deviceType,area,hospital,"88"));
        result.put("malfunction",totalRange(startTime,endTime,deviceType,area,hospital,"0"));
        result.put("diseaseUsing",diseaseUseRange(startTime,endTime,deviceType,area,hospital));
        result.put("diseaseCover",diseaseRange(startTime,endTime,deviceType,area,hospital));
        result.put("grant", totalRange(startTime, endTime, deviceType, area, hospital, "85"));
        result.put("binding", totalRange(startTime, endTime, deviceType, area, hospital, "86"));
        result.put("guide", totalRange(startTime, endTime, deviceType, area, hospital, "88"));
        result.put("malfunction", totalRange(startTime, endTime, deviceType, area, hospital, "0"));
        result.put("diseaseUsing", diseaseUseRange(startTime, endTime, deviceType, area, hospital));
        result.put("diseaseCover", diseaseRange(startTime, endTime, deviceType, area, hospital));
        return result;
    }
    /**
     * 慢病患者设备使用率
     *
     * @param startTime
     * @param endTime
     * @param deviceType
@ -878,25 +900,27 @@ public class MonitorPlatformService  {
     * @param hospital
     * @return
     */
    public JSONObject diseaseUseRange(String startTime,String endTime,
                                      String deviceType,String area,String hospital){
    public JSONObject diseaseUseRange(String startTime, String endTime,
                                      String deviceType, String area, String hospital) {
        String url = "/wlyygc/iot_monitoring/diseaseUseRange";
        Map<String, Object> params = new HashMap<>();
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        params.put("hospital",hospital);
        String response = sendGet(url,params);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("deviceType", deviceType);
        params.put("area", area);
        params.put("hospital", hospital);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONObject("data");
        }
        return new JSONObject();
    }
    /**
     * 慢病患者设备覆盖率
     *
     * @param startTime
     * @param endTime
     * @param deviceType
@ -904,18 +928,18 @@ public class MonitorPlatformService  {
     * @param hospital
     * @return
     */
    public JSONObject diseaseRange(String startTime,String endTime,
                                   String deviceType,String area,String hospital){
    public JSONObject diseaseRange(String startTime, String endTime,
                                   String deviceType, String area, String hospital) {
        String url = "/wlyygc/iot_monitoring/diseaseRange";
        Map<String, Object> params = new HashMap<>();
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        params.put("hospital",hospital);
        String response = sendGet(url,params);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("deviceType", deviceType);
        params.put("area", area);
        params.put("hospital", hospital);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONObject("data");
        }
@ -924,6 +948,7 @@ public class MonitorPlatformService  {
    /**
     * 慢病患者设备覆盖率
     *
     * @param startTime
     * @param endTime
     * @param deviceType
@ -931,26 +956,28 @@ public class MonitorPlatformService  {
     * @param hospital
     * @return
     */
    public JSONObject yellowOrRedRange(String startTime,String endTime,
                                       String deviceType,String area,String hospital,Integer diseaseCondition){
    public JSONObject yellowOrRedRange(String startTime, String endTime,
                                       String deviceType, String area, String hospital, Integer diseaseCondition) {
        String url = "/wlyygc/iot_monitoring/yellowOrRedRange";
        Map<String, Object> params = new HashMap<>();
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        params.put("hospital",hospital);
        params.put("diseaseCondition",diseaseCondition);
        String response = sendGet(url,params);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("deviceType", deviceType);
        params.put("area", area);
        params.put("hospital", hospital);
        params.put("diseaseCondition", diseaseCondition);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONObject("data");
        }
        return new JSONObject();
    }
    /**
     * 预警信息警报
     *
     * @param page
     * @param pageSize
     * @param startTime
@ -960,21 +987,21 @@ public class MonitorPlatformService  {
     * @param hospital
     * @return
     */
    public JSONArray warningInformationAlarm_new(Integer page,Integer pageSize,String startTime,String endTime,
                                                 String deviceType,String area,String hospital,String deviceName){
    public JSONArray warningInformationAlarm_new(Integer page, Integer pageSize, String startTime, String endTime,
                                                 String deviceType, String area, String hospital, String deviceName) {
        String url = "/wlyygc/iot_monitoring/warningInformationAlarm_new";
        Map<String, Object> params = new HashMap<>();
        params.put("page",page);
        params.put("pageSize",pageSize);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        params.put("hospital",hospital);
        params.put("deviceName",deviceName);
        String response = sendGet(url,params);
        params.put("page", page);
        params.put("pageSize", pageSize);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("deviceType", deviceType);
        params.put("area", area);
        params.put("hospital", hospital);
        params.put("deviceName", deviceName);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONArray("data");
        }
@ -983,6 +1010,7 @@ public class MonitorPlatformService  {
    /**
     * 预警信息警报
     *
     * @param startTime
     * @param endTime
     * @param deviceType
@ -990,18 +1018,18 @@ public class MonitorPlatformService  {
     * @param hospital
     * @return
     */
    public JSONObject yellowAndRedRange(String startTime,String endTime,
                                        String deviceType,String area,String hospital){
    public JSONObject yellowAndRedRange(String startTime, String endTime,
                                        String deviceType, String area, String hospital) {
        String url = "/wlyygc/iot_monitoring/yellowAndRedRange";
        Map<String, Object> params = new HashMap<>();
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        params.put("deviceType",deviceType);
        params.put("area",area);
        params.put("hospital",hospital);
        String response = sendGet(url,params);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        params.put("deviceType", deviceType);
        params.put("area", area);
        params.put("hospital", hospital);
        String response = sendGet(url, params);
        JSONObject json = JSONObject.parseObject(response);
        if(json.getInteger("status")==200){
        if (json.getInteger("status") == 200) {
            return json.getJSONObject("data");
        }
        return new JSONObject();
@ -1009,29 +1037,30 @@ public class MonitorPlatformService  {
    /**
     * 数据筛选
     *
     * @param name
     * @return
     */
    public JSONArray datafiltering(String name){
    public JSONArray datafiltering(String name) {
        StringBuffer sql = new StringBuffer("SELECT d.category_code as categoryCode,d.id,d.device_sn deviceSn,p.code,p.name,d.device_name deviceName ");
        sql.append("from wlyy.wlyy_patient_device d,wlyy.wlyy_patient p  ");
        sql.append("WHERE d.`user` = p.`code` and d.del=0  ");
        if(org.apache.commons.lang3.StringUtils.isNotBlank(name)){
            sql.append("and (d.device_sn like '%"+name+"%' or p.`name` = '"+ name+"') ");
        if (org.apache.commons.lang3.StringUtils.isNotBlank(name)) {
            sql.append("and (d.device_sn like '%" + name + "%' or p.`name` = '" + name + "') ");
//            sql.append("and (d.device_sn like '%"+name+"%' or p.`name` = '"+ AesEncryptUtils.encrypt(name)+"') ");待i健康加密
        }
        List<JSONObject> jsonArray = myJdbcTemplate.queryJson(sql.toString(),new Object[]{});
        List<JSONObject> jsonArray = myJdbcTemplate.queryJson(sql.toString(), new Object[]{});
//        for (JSONObject obj:jsonArray){
//            obj.put("name",AesEncryptUtils.decrypt(obj.getString("name")));//待i健康加密
//        }
        if(jsonArray.size()==0){
            sql= new StringBuffer(" select '5' as categoryCode, id,device_code as deviceSn,null as code,null as name,'健康小屋' as deviceName from xmiot.iot_equipmet_detail where device_code like '%"+name+"%'");
            jsonArray = myJdbcTemplate.queryJson(sql.toString(),new Object[]{});
        if (jsonArray.size() == 0) {
            sql = new StringBuffer(" select '5' as categoryCode, id,device_code as deviceSn,null as code,null as name,'健康小屋' as deviceName from xmiot.iot_equipmet_detail where device_code like '%" + name + "%'");
            jsonArray = myJdbcTemplate.queryJson(sql.toString(), new Object[]{});
        }
        for (int i=0;i<jsonArray.size();i++){
            com.alibaba.fastjson.JSONObject jsonObj= jsonArray.get(i);
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(jsonObj.getString("name"))){
        for (int i = 0; i < jsonArray.size(); i++) {
            com.alibaba.fastjson.JSONObject jsonObj = jsonArray.get(i);
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(jsonObj.getString("name"))) {
                jsonObj.put("name", ConcealUtil.nameOrAddrConceal(jsonObj.getString("name")));
            }
        }
@ -1043,33 +1072,33 @@ public class MonitorPlatformService  {
//        JSONObject json = JSONObject.parseObject(response);
//        if(json.getInteger("status")==200){
//            JSONArray jsonArray = json.getJSONArray("data");
            for(int i=0;i<jsonArray.size();i++){
                JSONObject data = jsonArray.get(i);
                String deviceSn = data.getString("deviceSn");
                JSONArray jsonArray1 = new JSONArray();
                JSONObject json1 = new JSONObject();
                json1.put("andOr","and");
                json1.put("field","deviceSn");
                json1.put("condition","=");
                json1.put("value",deviceSn);
                jsonArray1.add(json1);
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("filter",jsonArray1);
                jsonObject.put("page",1);
                jsonObject.put("size",5);
                String sqlLocation = "select idcard idCard,category_code categoryCode,device_sn deviceSn,location,device_time deviceTime,disease_condition diseaseCondition,\n" +
                        "create_time createTime,device_name equimentName\n" +
                        "from device.wlyy_patient_device_location where del=0 and  device_sn='"+deviceSn+"' limit 0,5 ";
                try {
                    List<Map<String,Object>> locationDataVOList = jdbcTemplate.queryForList(sqlLocation);
                    JSONObject location = JSONObject.parseObject(locationDataVOList.get(0).get("location").toString());
                    if(locationDataVOList.size()>0){
                        data.put("locationData",location);
                        data.put("diseaseCondition",Integer.parseInt(locationDataVOList.get(0).get("diseaseCondition").toString()));
                    }else{
                        data.put("locationData","{}");
                    }
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject data = jsonArray.get(i);
            String deviceSn = data.getString("deviceSn");
            JSONArray jsonArray1 = new JSONArray();
            JSONObject json1 = new JSONObject();
            json1.put("andOr", "and");
            json1.put("field", "deviceSn");
            json1.put("condition", "=");
            json1.put("value", deviceSn);
            jsonArray1.add(json1);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("filter", jsonArray1);
            jsonObject.put("page", 1);
            jsonObject.put("size", 5);
            String sqlLocation = "select idcard idCard,category_code categoryCode,device_sn deviceSn,location,device_time deviceTime,disease_condition diseaseCondition,\n" +
                    "create_time createTime,device_name equimentName\n" +
                    "from device.wlyy_patient_device_location where del=0 and  device_sn='" + deviceSn + "' limit 0,5 ";
            try {
                List<Map<String, Object>> locationDataVOList = jdbcTemplate.queryForList(sqlLocation);
                JSONObject location = JSONObject.parseObject(locationDataVOList.get(0).get("location").toString());
                if (locationDataVOList.size() > 0) {
                    data.put("locationData", location);
                    data.put("diseaseCondition", Integer.parseInt(locationDataVOList.get(0).get("diseaseCondition").toString()));
                } else {
                    data.put("locationData", "{}");
                }
//                    list = iotPatientDeviceService.findDeviceLocationsBySn(jsonObject.toString());
//                    if(list.size()>0){
//                        data.put("locationData",list.get(0).getLocation());
@ -1077,37 +1106,38 @@ public class MonitorPlatformService  {
//                    }else{
//                        data.put("locationData","{}");
//                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            JSONArray result = new JSONArray();
            result.addAll(jsonArray);
            return result;
        }
        JSONArray result = new JSONArray();
        result.addAll(jsonArray);
        return result;
    }
    /**
     * 访问i健康接口,自带登录信息
     *
     * @param url
     * @return
     */
    private String sendGet(String url,Map<String, Object> params){
    private String sendGet(String url, Map<String, Object> params) {
        String response = null;
        try{
            params.put("accesstoken",getAccessToken());
        try {
            params.put("accesstoken", getAccessToken());
            List<BasicNameValuePair> jsonParams = new ArrayList<>();
            //配置参数
            if(params!=null) {
            if (params != null) {
                for (String key : params.keySet()) {
                    if (!StringUtils.isEmpty(String.valueOf(params.get(key))) && !"null".equals( String.valueOf(params.get(key)))) {
                    if (!StringUtils.isEmpty(String.valueOf(params.get(key))) && !"null".equals(String.valueOf(params.get(key)))) {
                        jsonParams.add(new BasicNameValuePair(key, String.valueOf(params.get(key))));
                    }
                }
            }
            response = httpClientUtil.get(wlyyUrl+url+"?"+ URLEncodedUtils.format(jsonParams, Consts.UTF_8),"utf-8");
        }catch (Exception e){
            response = httpClientUtil.get(wlyyUrl + url + "?" + URLEncodedUtils.format(jsonParams, Consts.UTF_8), "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
@ -1115,15 +1145,16 @@ public class MonitorPlatformService  {
    /**
     * 返回accessToken
     *
     * @return
     * @throws IOException
     */
    private synchronized String getAccessToken(){
    private synchronized String getAccessToken() {
        String token = "";
        if(tokenMap.get("token")!=null){
        if (tokenMap.get("token") != null) {
            token = tokenMap.get("token");
            Long outTime = Long.valueOf(tokenMap.get("outTime"));
            if(new Date().getTime()<outTime){
            if (new Date().getTime() < outTime) {
                return token;
            }
        }
@ -1135,30 +1166,31 @@ public class MonitorPlatformService  {
            String url = "/gc/accesstoken";
            String response = HttpClientUtil.httpPost(wlyyUrl + url, params);
            JSONObject jsonObject = JSON.parseObject(response);
            if(jsonObject.getInteger("status")==10000){
            if (jsonObject.getInteger("status") == 10000) {
                String accesstoken = jsonObject.getJSONObject("result").getString("accesstoken");
                tokenMap.put("token",accesstoken);
                tokenMap.put("outTime", jsonObject.getJSONObject("result").getLong("outTime")+"");
                tokenMap.put("token", accesstoken);
                tokenMap.put("outTime", jsonObject.getJSONObject("result").getLong("outTime") + "");
                return accesstoken;
            }
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 返回健康小屋详情信息
     */
    public JSONObject getEquipmentDetail(String deviceSn){
    public JSONObject getEquipmentDetail(String deviceSn) {
        try {
            IotEquipmentDetailDO iotEquipmentDetailDO= iotEquipmentDetailDao.findByDeviceCode(deviceSn);
            JSONObject obj = (JSONObject)JSONObject.toJSON(iotEquipmentDetailDO);
            if(iotEquipmentDetailDO!=null){
                obj.put("deviceSn",iotEquipmentDetailDO.getDeviceCode());
            IotEquipmentDetailDO iotEquipmentDetailDO = iotEquipmentDetailDao.findByDeviceCode(deviceSn);
            JSONObject obj = (JSONObject) JSONObject.toJSON(iotEquipmentDetailDO);
            if (iotEquipmentDetailDO != null) {
                obj.put("deviceSn", iotEquipmentDetailDO.getDeviceCode());
            }
            return obj;
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
@ -1167,9 +1199,9 @@ public class MonitorPlatformService  {
    /**
     * 获取设备品牌以及商家品牌排行
     */
    public JSONObject getBrandsAndManufacturer(){
    public JSONObject getBrandsAndManufacturer() {
        try {
            String sql  = "select count(DISTINCT A.device_name) as total,A.device_name,A.manufacturer from (\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 and pd.del=0 \n" +
                    "and wd.manufacturer_code is not null and wd.manufacturer_code <>'' and pd.device_name<>'血压计-null' and pd.device_name<>'血糖仪-自助体检一体机'  \n" +
@ -1179,10 +1211,10 @@ public class MonitorPlatformService  {
                    ")A\n" +
                    "GROUP BY A.manufacturer\n" +
                    "ORDER BY total desc";
            List<Map<String,Object>>Manufacturers = jdbcTemplate.queryForList(sql);
            List<Map<String, Object>> Manufacturers = jdbcTemplate.queryForList(sql);
            JSONObject result = new JSONObject();
            JSONArray arr = JSONArray.parseArray(JSON.toJSONString(Manufacturers));
            result.put("Manufacturers",arr);
            result.put("Manufacturers", arr);
            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 and pd.del=0 \n" +
@ -1191,13 +1223,13 @@ public class MonitorPlatformService  {
                    "UNION\n" +
                    "select case device_name when '自助体检一体机' then '健康小屋'  else device_name  end AS device_name from xmiot.iot_equipmet_detail group BY manufacturer_code,device_name\n" +
                    ")A";
            Integer BrandsCount = jdbcTemplate.queryForObject(sql,Integer.class);
            Integer BrandsCount = jdbcTemplate.queryForObject(sql, Integer.class);
            result.put("Brands",BrandsCount);
            result.put("manufacturerCount",arr.size());
            result.put("Brands", BrandsCount);
            result.put("manufacturerCount", arr.size());
            return result;
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
@ -1205,149 +1237,147 @@ public class MonitorPlatformService  {
    /**
     * 谁设备库存、使用中、总备案、物联率、失联率
     *
     * @param deviceType
     * @param deviceName
     * @param showLevel
     * @return
     */
    public JSONObject getEquipmentStatistics(String deviceType,String deviceName,String showLevel){
    public JSONObject getEquipmentStatistics(String deviceType, String deviceName, String showLevel) {
        try {
            WlyyIotTzDict dictObj =wlyyIotTzDictDao.findByCodeAndDel("IOT_LOST_DAY",1);
            WlyyIotTzDict dictObj = wlyyIotTzDictDao.findByCodeAndDel("IOT_LOST_DAY", 1);
            String lost_day = dictObj.getValue();
            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")) {
            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 in ('").append(deviceName.replace(",","','")).append("') ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName)) {
                    sqlCondition.append("and d.device_name in ('").append(deviceName.replace(",", "','")).append("') ");
                }
                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 d.del=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,wlyy.wlyy_sign_family f WHERE f.`status`>0 and d.del=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 ");
                    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)){ //血压计,血糖仪。。。
                } 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("(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("') ");
                    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
                } 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("(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("') ");
                    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());
                List<Map<String, Object>> sqlResult = jdbcTemplate.queryForList(sql.toString());
                JSONArray arr = JSONArray.parseArray(JSON.toJSONString(sqlResult));
                for(int i=0;i<arr.size();i++){
                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);//是否可查看下一层次
                    if ("0".equals(showLevel)) {
                        obj.put("device_name", "单体征测量仪");
                        obj.put("Subdivision", true);//是否可查看下一层次
                        StringBuffer sqlTmp = new StringBuffer("select code from xmiot.iot_system_dict where dict_name='DEVICE_TYPE' and `code` in ('");
                        sqlTmp.append(deviceType.replace(",","','")).append("') ");
                        sqlTmp.append(deviceType.replace(",", "','")).append("') ");
                        sqlTmp.append("and del=1 and parent_code \n" +
                                "in(select id from xmiot.iot_system_dict where dict_name='DEVICE' and `value`='单体征测量仪' and del=1)");
                        List<String> list = jdbcTemplate.queryForList(sqlTmp.toString(),String.class);
                        List<String> list = jdbcTemplate.queryForList(sqlTmp.toString(), String.class);
                        sqlTmp = new StringBuffer();
                        for (String s:list){
                            sqlTmp.append(","+s);
                        for (String s : list) {
                            sqlTmp.append("," + s);
                        }
                        if (list.size()!=0){
                        if (list.size() != 0) {
                            sqlTmp.deleteCharAt(0);
                        }
                        obj.put("type",sqlTmp.toString());
                    }
                    else if("1".equals(showLevel)){
                        obj.put("type", sqlTmp.toString());
                    } 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","血压计");
                        if ("1".equals(temp)) {
                            obj.put("device_name", "血糖仪");
                        } else if ("2".equals(temp)) {
                            obj.put("device_name", "血压计");
                        }
                        obj.put("Subdivision",true);
                        obj.put("Subdivision", true);
                    } else {
                        obj.put("Subdivision", false);
                    }
                    else{
                        obj.put("Subdivision",false);
                    }
                    obj.put("showLevel",Integer.parseInt(showLevel));
                    obj.put("showLevel", Integer.parseInt(showLevel));
                }
                result.put("deviceInfo",arr);//设备信息统计
                result.put("deviceInfo", arr);//设备信息统计
                //统计物联率设备,失联设备
                sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ,wlyy.wlyy_sign_family f   ");
                sql.append("where  f.`status`>0 and d.del=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("') ");
                sql.append("where  f.`status`>0 and d.del=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("') ");
                }
                Integer iotCount = jdbcTemplate.queryForObject(sql.toString(),Integer.class);//物联设备数量
                result.put("iotCount",iotCount);
                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 d.del=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("') ");
                sql = new StringBuffer("select count(*) from wlyy.wlyy_patient_device d ,wlyy.wlyy_sign_family f WHERE f.`status`>0 and d.del=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);
                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()) <= "+lost_day+")");
                Integer lostContact = jdbcTemplate.queryForObject(sql.toString(),Integer.class);
                result.put("lostContact",lostContact);
                sql.append("where TIMESTAMPDIFF(DAY,record_date,NOW()) <= " + lost_day + ")");
                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)&&deviceName.contains("健康小屋"))){
            if ((deviceType.contains("5") && org.apache.commons.lang3.StringUtils.isBlank(deviceName)) || (deviceType.contains("5") && org.apache.commons.lang3.StringUtils.isNoneBlank(deviceName) && deviceName.contains("健康小屋"))) {
                String sql = "select COUNT(*) from xmiot.iot_equipmet_detail";
                Integer count = jdbcTemplate.queryForObject(sql,Integer.class);
                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);
                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);
                }
                tmp.put("showLevel",Integer.parseInt(showLevel));
                tmp.put("showLevel", Integer.parseInt(showLevel));
                result.getJSONArray("deviceInfo").add(tmp);
                result.put("grantCount",result.getInteger("grantCount")+count);
                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);//小屋物联
                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++){
            for (int i = 0; i < arrTmp.size(); i++) {
                JSONObject tmp = arrTmp.getJSONObject(i);
                if (tmp.getInteger("total")==0){
                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));
            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){
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
@ -1367,6 +1397,7 @@ public class MonitorPlatformService  {
    /**
     * 获取物联率与失联率
     *
     * @param startTime
     * @param endTime
     * @param deviceType
@ -1375,178 +1406,177 @@ public class MonitorPlatformService  {
     * @param quotaCode
     * @return
     */
    public JSONObject iotAndLostRange(String startTime,String endTime,
                                      String deviceType,String area,String hospital,String quotaCode){
        WlyyIotTzDict dictObj =wlyyIotTzDictDao.findByCodeAndDel("IOT_LOST_DAY",1);
    public JSONObject iotAndLostRange(String startTime, String endTime,
                                      String deviceType, String area, String hospital, String quotaCode) {
        WlyyIotTzDict dictObj = wlyyIotTzDictDao.findByCodeAndDel("IOT_LOST_DAY", 1);
        String lost_day = dictObj.getValue();
        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 d.del=0 and f.patient = d.`user`  ");
        StringBuffer sqlCondition = new StringBuffer(" ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
            sqlCondition.append(" and f.hospital in (SELECT dh.code from wlyy.dm_hospital dh where dh.town ='"+area+"' and dh.del =1 )  ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)) {
            sqlCondition.append(" and f.hospital in (SELECT dh.code from wlyy.dm_hospital dh where dh.town ='" + area + "' and dh.del =1 )  ");
        }
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)){
            sqlCondition.append(" and d.hospital ="+hospital+"  ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)) {
            sqlCondition.append(" and d.hospital =" + hospital + "  ");
        }
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
            sqlCondition.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)) {
            sqlCondition.append("and d.category_code in ('").append(deviceType.replace(",", "','")).append("') ");
        }
        sql.append(sqlCondition);
        Integer grantCount = jdbcTemplate.queryForObject(sql.toString(),Integer.class);//单体征设备发放总数
        result.put("totalAll",grantCount);
        Integer total=0;
        if("1".equals(quotaCode)){
        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 ");
            sqlCondition = new StringBuffer(" where 1=1 ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
            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 dh.town='" + area + "' ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)) {
                    sqlCondition.append("and dh.code='" + hospital + "' ");
                }
            }
            sqlCondition.append("and  f.`status`>0 and d.del=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'  ");
            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("') ");
            sqlCondition.append(" ) and d.category_code in ('").append(deviceType.replace(",", "','")).append("') ");
            sql.append(sqlCondition);
            total=jdbcTemplate.queryForObject(sql.toString(),Integer.class);
            total = jdbcTemplate.queryForObject(sql.toString(), Integer.class);
        }
        //失联
        if("2".equals(quotaCode)){
        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)){
            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 dh.town='" + area + "' ");
                if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)) {
                    sqlCondition.append("and dh.code='" + hospital + "' ");
                }
            }
            sqlCondition.append("and f.`status`>0 and d.del=0 and f.patient = d.`user` ");
            sqlCondition.append("  and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
            sqlCondition.append("  and d.category_code in ('").append(deviceType.replace(",", "','")).append("') ");
            sqlCondition.append("and d.device_sn not 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'  ");
            }
            else{
                sqlCondition.append("and  TIMESTAMPDIFF(DAY,record_date,NOW()) <= "+lost_day+"  ");
            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'  ");
            } else {
                sqlCondition.append("and  TIMESTAMPDIFF(DAY,record_date,NOW()) <= " + lost_day + "  ");
            }
            sqlCondition.append(")");
            sql.append(sqlCondition);
            total=jdbcTemplate.queryForObject(sql.toString(),Integer.class);
            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)){
        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";
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
                sqll+=" where belong_are_code='"+area+"' ";
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)) {
                sqll += " where belong_are_code='" + area + "' ";
            }
             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 ");
            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+"' ");
                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'  ");
                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);
                sql.append(sqlCondition + ")");
                count = jdbcTemplate.queryForObject(sql.toString(), Integer.class);
            }
            if("2".equals(quotaCode)){//小屋失联数0
                count=0;
            if ("2".equals(quotaCode)) {//小屋失联数0
                count = 0;
            }
            result.put("total",total+count);//互联设备\失联设备数量
        }
        else{
            result.put("total",total+count);//互联设备\失联设备数量
            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) );
            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 );
            result.put("totalRange", 0.0);
        }
        return result;
    }
    /**
     * 获取设备品牌详细
     *
     * @param deviceType
     * @return
     */
    public JSONObject getBrandsDetail(String deviceType){
    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 and pd.del=0 \n" +
                    "and wd.manufacturer_code is not null and wd.manufacturer_code <>'' " +
                    "and pd.device_name<>'血压计-null' and pd.device_name<>'血糖仪-自助体检一体机' ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)){
                sql.append("and pd.category_code in ('").append(deviceType.replace(",","','")).append("') ");
            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)){
            if ((org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType) && deviceType.contains("5")) || org.apache.commons.lang3.StringUtils.isBlank(deviceType)) {
                sql.append("UNION select case device_name when '自助体检一体机' then '健康小屋'  else device_name  end AS 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);
            List<String> list = jdbcTemplate.queryForList(sql.toString(), String.class);
            List<String> reList = new ArrayList<>();
            int i=0;
            for(String tmp:list){
                if ("三诺血糖仪".equals(tmp)||"血糖仪-三诺亲智".equals(tmp)||"三诺亲智".equals(tmp)||"健康之路亲智血糖仪".equals(tmp)||"血糖仪".equals(tmp)||"血糖仪-健康之路亲智血糖仪".equals(tmp)){
                    i=1;
            int i = 0;
            for (String tmp : list) {
                if ("三诺血糖仪".equals(tmp) || "血糖仪-三诺亲智".equals(tmp) || "三诺亲智".equals(tmp) || "健康之路亲智血糖仪".equals(tmp) || "血糖仪".equals(tmp) || "血糖仪-健康之路亲智血糖仪".equals(tmp)) {
                    i = 1;
                    continue;
                }
                reList.add(tmp);
            }
            if (i==1){//上面去除的元素统一返回为三诺血糖仪
            if (i == 1) {//上面去除的元素统一返回为三诺血糖仪
                reList.add("三诺血糖仪");
            }
            JSONObject result = new JSONObject();
            result.put("brands",reList);
            result.put("brands", reList);
            return result;
        }catch (Exception e){
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    public JSONObject getDeviceData(){
    public JSONObject getDeviceData() {
        JSONObject object = new JSONObject();
        //血糖仪数量
        String bloodGlucosemeterCount = "SELECT COUNT(1) FROM wlyy.wlyy_patient_device WHERE category_code = 1 AND del = 0";
        //血压计数量
        String sphygmomanometerCount = "SELECT COUNT(1) FROM wlyy.wlyy_patient_device WHERE category_code = 2 AND del = 0";
        Integer aa = jdbcTemplate.queryForObject(bloodGlucosemeterCount,Integer.class);
        Integer bb = jdbcTemplate.queryForObject(sphygmomanometerCount,Integer.class);
        object.put("homeHealthEquipment",aa+bb);
        Integer aa = jdbcTemplate.queryForObject(bloodGlucosemeterCount, Integer.class);
        Integer bb = jdbcTemplate.queryForObject(sphygmomanometerCount, Integer.class);
        object.put("homeHealthEquipment", aa + bb);
        //血糖仪 血压计 体征数据
        String physicalSignData = "SELECT count(1) from wlyy.wlyy_sign_family s,wlyy.wlyy_patient_device d, device.wlyy_patient_health_index p WHERE s.`status`>0 \n" +
                "and d.`user` = s.patient and p.`user`=d.`user` and p.del=1 and (p.type=1 or p.type=2)";
        Integer cc = jdbcTemplate.queryForObject(physicalSignData,Integer.class);
        object.put("homePhysicalSignData",cc);
        Integer cc = jdbcTemplate.queryForObject(physicalSignData, Integer.class);
        object.put("homePhysicalSignData", cc);
        //异常数据
        String abnormalPhysicalSignData = "SELECT count(1) from wlyy.wlyy_sign_family s,wlyy.wlyy_patient_device d,device.wlyy_patient_health_index p WHERE s.`status`>0 \n" +
                "and d.`user` = s.patient and p.`user`=d.`user` and p.`status`=1 and p.del=1 and (p.type=1 or p.type=2)";
        Integer dd = jdbcTemplate.queryForObject(abnormalPhysicalSignData,Integer.class);
        object.put("homeAbnormalSignData",dd);
        Integer dd = jdbcTemplate.queryForObject(abnormalPhysicalSignData, Integer.class);
        object.put("homeAbnormalSignData", dd);
        //小屋数量
        String cabinCount = "SELECT COUNT(1) FROM xmiot.iot_equipmet_detail";
        Integer ee = jdbcTemplate.queryForObject(cabinCount,Integer.class);
        object.put("medicalInstitutionIquipment",ee);
        Integer ee = jdbcTemplate.queryForObject(cabinCount, Integer.class);
        object.put("medicalInstitutionIquipment", ee);
        //小屋体征数据
        String cabinSignData = "SELECT count(1) FROM xmiot.wlyy_iot_m ";
        Integer ff = jdbcTemplate.queryForObject(cabinSignData,Integer.class);
        object.put("medicalPhysicalSignData",ff);
        Integer ff = jdbcTemplate.queryForObject(cabinSignData, Integer.class);
        object.put("medicalPhysicalSignData", ff);
        //小屋异常体征数据
        String abnormalSignDataOfCabin = "select count(1)\n" +
                "from  xmiot.wlyy_iot_d d \n" +
@ -1555,136 +1585,137 @@ public class MonitorPlatformService  {
                "(d.`code`='HighPressure' and (d.`value` not BETWEEN 90.0 and 140))\n" +
                "or (d.`code`='LowPressure' and (d.`value` not BETWEEN 60.0 and 90))\n" +
                ");";
        Integer gg = jdbcTemplate.queryForObject(abnormalSignDataOfCabin,Integer.class);
        object.put("medicalAbnormalSignData",gg);
        Integer gg = jdbcTemplate.queryForObject(abnormalSignDataOfCabin, Integer.class);
        object.put("medicalAbnormalSignData", gg);
        return object;
    }
    public JSONArray getSearchTags(){
    public JSONArray getSearchTags() {
        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);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        JSONArray result = new JSONArray();
        for (Map<String,Object> map :list){
            sql="select `code`,`value` from xmiot.iot_system_dict where dict_name='DEVICE_TYPE' and del=1 and code!=10 and code!=11  and parent_code='"+map.get("id").toString()+"'";
        for (Map<String, Object> map : list) {
            sql = "select `code`,`value` from xmiot.iot_system_dict where dict_name='DEVICE_TYPE' and del=1 and code!=10 and code!=11  and parent_code='" + map.get("id").toString() + "'";
            StringBuffer buffer = new StringBuffer();
            List<Map<String,Object>> reList = jdbcTemplate.queryForList(sql);
            for (Map<String,Object> reMap:reList){
            List<Map<String, Object>> reList = jdbcTemplate.queryForList(sql);
            for (Map<String, Object> reMap : reList) {
                JSONObject tmp = new JSONObject();
                tmp.put("name",reMap.get("value").toString());
                tmp.put("code",reMap.get("code").toString());
                buffer.append(","+reMap.get("code").toString());
                tmp.put("name", reMap.get("value").toString());
                tmp.put("code", reMap.get("code").toString());
                buffer.append("," + reMap.get("code").toString());
                result.add(tmp);
            }
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(buffer.toString())){
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(buffer.toString())) {
                buffer.deleteCharAt(0);
                JSONObject tmp = new JSONObject();
                tmp.put("name",map.get("value").toString());
                tmp.put("code",buffer.toString());
                tmp.put("name", map.get("value").toString());
                tmp.put("code", buffer.toString());
                result.add(tmp);
            }
        }
        return  result;
        return result;
    }
    public JSONObject getDeviceTotalCount(String startTime,String endTime,String deviceType,String area,String hospital){
        Integer totalAll=0;
        Integer grant=0;
        if (deviceType.contains("5")){
    public JSONObject getDeviceTotalCount(String startTime, String endTime, String deviceType, String area, String hospital) {
        Integer totalAll = 0;
        Integer grant = 0;
        if (deviceType.contains("5")) {
            StringBuffer sql = new StringBuffer("select count(*) from xmiot.iot_equipmet_detail where 1=1 ");
            if(org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
                sql.append("and belong_are_code='"+area+"' ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)) {
                sql.append("and belong_are_code='" + area + "' ");
            }
            Integer tmp = jdbcTemplate.queryForObject(sql.toString(),Integer.class);
            totalAll +=tmp;
            grant +=tmp;
            Integer tmp = jdbcTemplate.queryForObject(sql.toString(), Integer.class);
            totalAll += tmp;
            grant += tmp;
        }
        String allCountSql = "SELECT COUNT(*) FROM device.wlyy_devices d where 1=1 ";
        int i = 0;
        if(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)&&deviceType.contains("1")){
            allCountSql+= "   ";
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType) && deviceType.contains("1")) {
            allCountSql += "   ";
            i = 1;
        }
        if(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)&&deviceType.contains("2")){
            if(i==1){
                allCountSql+= " or device_name like '%血压计%'";
            }else{
                allCountSql+= " and ( device_name like '%血压计%' ";
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType) && deviceType.contains("2")) {
            if (i == 1) {
                allCountSql += " or device_name like '%血压计%'";
            } else {
                allCountSql += " and ( device_name like '%血压计%' ";
            }
        }
        allCountSql+= " ) ";
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
            allCountSql+=" and grant_org_code in (SELECT dh.code from wlyy.dm_hospital dh where dh.town ='"+area+"' and dh.del =1 )";
        allCountSql += " ) ";
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)) {
            allCountSql += " and grant_org_code in (SELECT dh.code from wlyy.dm_hospital dh where dh.town ='" + area + "' and dh.del =1 )";
        }
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)){
            allCountSql+=" and grant_org_code ="+hospital+"  ";
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)) {
            allCountSql += " and grant_org_code =" + hospital + "  ";
        }
        if(org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType)&&(deviceType.contains("1")||deviceType.contains("2"))){
        if (org.apache.commons.lang3.StringUtils.isNoneBlank(deviceType) && (deviceType.contains("1") || deviceType.contains("2"))) {
            Integer allCount = jdbcTemplate.queryForObject(allCountSql, Integer.class);//单体征总数
            totalAll+=allCount;
            totalAll += allCount;
            StringBuffer sql = new StringBuffer("SELECT COUNT(*) from wlyy.wlyy_patient_device d,wlyy.wlyy_sign_family f  WHERE 1=1 and f.`status`>0 and d.del=0 and f.patient = d.`user` ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)){
                sql.append(" and f.hospital in (SELECT dh.code from wlyy.dm_hospital dh where dh.town ='"+area+"' and dh.del =1 )  ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(area)) {
                sql.append(" and f.hospital in (SELECT dh.code from wlyy.dm_hospital dh where dh.town ='" + area + "' and dh.del =1 )  ");
            }
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)){
                sql.append(" and d.hospital ="+hospital+"  ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(hospital)) {
                sql.append(" and d.hospital =" + hospital + "  ");
            }
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(startTime)&& org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)){
                sql.append(" and d.czrq <='"+endTime+" 23:59:59'  ");
            if (org.apache.commons.lang3.StringUtils.isNoneBlank(startTime) && org.apache.commons.lang3.StringUtils.isNoneBlank(endTime)) {
                sql.append(" and d.czrq <='" + endTime + " 23:59:59'  ");
            }
            sql.append("and d.category_code in ('").append(deviceType.replace(",","','")).append("') ");
            Integer count = jdbcTemplate.queryForObject(sql.toString(),Integer.class);//发放总数
            grant +=count;
            sql.append("and d.category_code in ('").append(deviceType.replace(",", "','")).append("') ");
            Integer count = jdbcTemplate.queryForObject(sql.toString(), Integer.class);//发放总数
            grant += count;
        }
        JSONObject result = new JSONObject();
        result.put("totalAll",totalAll);
        result.put("using",grant);
        result.put("stock",totalAll-grant);
        result.put("totalAll", totalAll);
        result.put("using", grant);
        result.put("stock", totalAll - grant);
        return result;
    }
    /**
     * deviceName处理
     *
     * @param deviceName
     * @return
     */
    public String getDeviceNameByRequestParam(String deviceName){
        if (deviceName.contains("三诺血糖仪")){
            return deviceName.replace("三诺血糖仪","三诺血糖仪,血糖仪-三诺亲智,三诺亲智,健康之路亲智血糖仪,血糖仪,血糖仪-健康之路亲智血糖仪");
    public String getDeviceNameByRequestParam(String deviceName) {
        if (deviceName.contains("三诺血糖仪")) {
            return deviceName.replace("三诺血糖仪", "三诺血糖仪,血糖仪-三诺亲智,三诺亲智,健康之路亲智血糖仪,血糖仪,血糖仪-健康之路亲智血糖仪");
        }
        return deviceName;
    }
    public JSONObject savePatientDeviceLocation(String categoryCode){
    public JSONObject savePatientDeviceLocation(String categoryCode) {
        String sql = "select DISTINCT pd.category_code ,pd.czrq create_time,pd.device_sn ,pd.device_name, p.disease_condition ,p.`code`,p.idcard ,p.address,sf.hospital_name\n" +
                "from  wlyy.wlyy_patient_device pd \n" +
                "INNER JOIN wlyy.wlyy_sign_family sf on pd.`user` = sf.patient and sf.type=2 \n" +
                "INNER JOIN wlyy.wlyy_patient p on p.idcard = sf.idcard and p.`status`=1\n" +
                "where  pd.del=0 and pd.category_code in ("+categoryCode+")";
                "where  pd.del=0 and pd.category_code in (" + categoryCode + ")";
//                "where  pd.del=0 and pd.category_code in (1,2)";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        list.forEach(map->{
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        list.forEach(map -> {
            try {
                if(map.get("disease_condition")==null){
                if (map.get("disease_condition") == null) {
                    //未定标的居民设置成-1
                    map.put("disease_condition","-1");
                    map.put("disease_condition", "-1");
                }
                Map<String, String> json = null;
                if (map.get("address")!=null){
                if (map.get("address") != null) {
                    if (org.apache.commons.lang3.StringUtils.isNoneBlank(map.get("address").toString())) {
                        json = LatitudeUtils.getGeocoderLatitude(("福建省厦门市"+map.get("address").toString()).replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
                        json = LatitudeUtils.getGeocoderLatitude(("福建省厦门市" + map.get("address").toString()).replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
                    }
                }
                if (json==null||map.get("address")==null){
                    if (map.get("hospital_name")!=null){
                if (json == null || map.get("address") == null) {
                    if (map.get("hospital_name") != null) {
                        if (org.apache.commons.lang3.StringUtils.isNoneBlank(map.get("hospital_name").toString())) {
                            json = LatitudeUtils.getGeocoderLatitude(("福建省厦门市"+map.get("hospital_name").toString()).replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
                            json = LatitudeUtils.getGeocoderLatitude(("福建省厦门市" + map.get("hospital_name").toString()).replace("G.", "").replace("(糖友网)", "").replace("(高友网)", ""));
                        }
                    }
                }
                if (json !=null) {
                if (json != null) {
                    JSONObject location = new JSONObject();
                    location.put("lat", Double.valueOf(json.get("lat")));
                    location.put("lon", Double.valueOf(json.get("lng")));
@ -1694,53 +1725,237 @@ public class MonitorPlatformService  {
                            "'" + map.get("category_code").toString() + "','" + map.get("create_time") + "','" + map.get("create_time").toString() + "','" + location.toJSONString() + "')\n";
                    jdbcTemplate.execute(insertSql);
                }
            }catch (Exception e){
                System.out.println(map.get("device_sn").toString()+"-----"+map.get("idcard").toString());
            } catch (Exception e) {
                System.out.println(map.get("device_sn").toString() + "-----" + map.get("idcard").toString());
                e.printStackTrace();
            }
        });
        return null;
    }
    public List<Map<String, Object>> getHealthScoreByPatient(String patient,String date,String endDate){
    public List<Map<String, Object>> getHealthScoreByPatient(String patient, String date, String endDate) {
        String sql = "SELECT chhs.device_sn deviceSn,chhs.export_key exportKey,chhs.export_time exportTime,chhs.name name,chhs.score score,chhs.total total,chhs.date date FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_health_score chhs,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chhs.device_sn and chhs.date > '"+endDate+"' and chhs.date < '"+date+"' ORDER BY export_time DESC ";
                "WHERE t.patient = '" + patient + "' AND t.patient = chd.patient AND chd.device_sn = chhs.device_sn and chhs.date > '" + endDate + "' and chhs.date < '" + date + "' ORDER BY export_time DESC ";
        List<Map<String, Object>> scoreDO = jdbcTemplate.queryForList(sql);
        return scoreDO;
    }
    public List<Map<String,Object>> getRealtimeDateByPatient(String patient,String date){
    public List<Map<String, Object>> getRealtimeDateByPatient(String patient, String date) {
        String sql = "SELECT chrd.device_sn deviceSn,chrd.hr hr,chrd.st st,chrd.cal cal,chrd.date date FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_realtime_date chrd,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chrd.device_sn and chrd.date = '"+date+"' ORDER BY chrd.`date` DESC";
                "WHERE t.patient = '" + patient + "' AND t.patient = chd.patient AND chd.device_sn = chrd.device_sn and chrd.date = '" + date + "' ORDER BY chrd.`date` DESC";
        List<Map<String, Object>> realtimeDateDo = jdbcTemplate.queryForList(sql);
        return realtimeDateDo;
    }
    public List<Map<String,Object>> getRundatePatient(String patient,String date){
    public List<Map<String, Object>> getRundatePatient(String patient, String date) {
        String sql = "SELECT chr.device_sn deviceSn,chr.date date,chr.last_sync_time lastSyncTime,chr.steps steps,chr.distance distance,chr.run_distance runDistance,chr.run_time runTime,chr.walk_time walkTime,chr.calories calories,chr.run_calories runCalories,chr.hour hour FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_rundate chr,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chr.device_sn and chr.date = '"+date+"' ORDER BY chr.`date` DESC";
                "WHERE t.patient = '" + patient + "' AND t.patient = chd.patient AND chd.device_sn = chr.device_sn and chr.date = '" + date + "' ORDER BY chr.`date` DESC";
        List<Map<String, Object>> rundataDo = jdbcTemplate.queryForList(sql);
        return rundataDo;
    }
    public List<Map<String,Object>> getPaiPatient(String patient,String date){
    public List<Map<String, Object>> getPaiPatient(String patient, String date) {
        String sql = "SELECT chp.device_sn deviceSn,chp.calendar_day calendarDay,chp.timestamp timestamp,chp.total_pai totalPai,chp.daily_pai dailyPai,chp.date date FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_pai chp,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chp.device_sn and chp.date = '"+date+"' ORDER BY chp.`timestamp` DESC";
                "WHERE t.patient = '" + patient + "' AND t.patient = chd.patient AND chd.device_sn = chp.device_sn and chp.date = '" + date + "' ORDER BY chp.`timestamp` DESC";
        List<Map<String, Object>> paiDo = jdbcTemplate.queryForList(sql);
        return paiDo;
    }
    public List<Map<String,Object>> getSleepByPatient(String patient,String date){
    public List<Map<String, Object>> getSleepByPatient(String patient, String date) {
        String sql = "SELECT chs.device_sn deviceSn,chs.date date,chs.last_sync_time lastSyncTime,chs.deep_sleep_time deepSleepTime,chs.shallow_sleep_time shallowSleepTime,chs.wake_time wakeTime,chs.sleep_score sleepScore,chs.start start,chs.stop stop,chs.mode mode FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_sleep chs,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chs.device_sn and chs.date = '"+date+"' ORDER BY chs.`last_sync_time` DESC";
                "WHERE t.patient = '" + patient + "' AND t.patient = chd.patient AND chd.device_sn = chs.device_sn and chs.date = '" + date + "' ORDER BY chs.`last_sync_time` DESC";
        List<Map<String, Object>> paiDo = jdbcTemplate.queryForList(sql);
        return paiDo;
    }
    public List<Map<String , Object>> getHeartByPatient(String patient,String date,String endDate){
    public List<Map<String, Object>> getHeartByPatient(String patient, String date, String endDate) {
        String sql = "SELECT chh.device_sn deviceSn,chh.date date,chh.minute minute,chh.last_sync_time lastSyncTime,chh.timestamp timestamp,chh.heart_rate_data heartRateData,chh.measure_type measureType FROM xmiot.wlyy_copd_huami_device chd,xmiot.wlyy_copd_huami_heart chh,wlyy.hm_token t\n" +
                "WHERE t.patient = '"+patient+"' AND t.patient = chd.patient AND chd.device_sn = chh.device_sn and chh.`date` > '"+endDate+"' and chh.`date` < '"+date+"' ORDER BY chh.`date` DESC";
                "WHERE t.patient = '" + patient + "' AND t.patient = chd.patient AND chd.device_sn = chh.device_sn and chh.`date` > '" + endDate + "' and chh.`date` < '" + date + "' ORDER BY chh.`date` DESC";
        List<Map<String, Object>> heartDo = jdbcTemplate.queryForList(sql);
        return heartDo;
    }
    /*获取药柜所有设备信息  地址  编号  名字*/
    public List<Map<String,String>> getMedicinecabinet() {
        JSONArray resultArr = new JSONArray();
        List<Map<String, String>> list = new ArrayList<>();
        try {
            JSONObject resultObject = getUrl("/open/noLogin/getDeviceList", null);
            resultArr = resultObject.getJSONArray("usedDeviceList");
            for (int i = 0; i < resultArr.size(); i++) {
                Map<String, String> resultMap = new HashMap<>();
                JSONObject jsonObject = resultArr.getJSONObject(i);
                /*获取设备名称*/
                String equName = jsonObject.getString("equName");
                resultMap.put("equName", equName);
                /*获取设备地址*/
                String deliveryAddress = jsonObject.getString("deliveryAddress");
                resultMap.put("deliveryAddress;", deliveryAddress);
                /*获取设备编号*/
                String equNum = jsonObject.getString("equNum");
                resultMap.put("equNum", equNum);
                /*获取设备编号*/
                String id = jsonObject.getString("id");
                resultMap.put("id", id);
                list.add(resultMap);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /*总数*/
    public Map<String, String> getMedicinecabinetCount() {
        Map resultMap = new HashMap<>();
        JSONObject jsonObject = getUrl("/open/noLogin/getDeviceList", null);
        //设备总数
        String total = jsonObject.get("total").toString();
        //库存量
        String notUsedTotal = jsonObject.get("notUsedTotal").toString();
        //使用中
        String usedTotal = jsonObject.get("usedTotal").toString();
        resultMap.put("total", total);
        resultMap.put("notUsedTotal", notUsedTotal);
        resultMap.put("usedTotal", usedTotal);
        return resultMap;
    }
    /*获取药柜详细信息*/
    public Map<String, List<Map>> getadddd(String deviceid, String day) throws Exception {
        //返回参数
        Map<String, List<Map>> resoultMap = new HashMap<>();
        //参数加密
        Map parameterMap = new HashMap<String, String>();
        parameterMap.put("deviceId", deviceid);
        parameterMap.put("day", day);
        String content = com.alibaba.fastjson.JSONObject.toJSONString(parameterMap);
        String params = AesEncryptUtils.agEncrypt(content);
        JSONObject jsonObject = getUrl("/open/noLogin/getDeviceInfo", params);
        //医保曲线
        JSONArray yibaoArray = jsonObject.getJSONArray("yibaoList");
        /*for (int i = 0; i < yibaoList.size(); i++) {
            Map listMap = new HashMap<>();
            JSONObject yibaoListJSONObject = yibaoList.getJSONObject(i);
            String date = yibaoListJSONObject.getString("date");
            String avg = yibaoListJSONObject.getString("avg");
            String count = yibaoListJSONObject.getString("count");
            listMap.put("date",date);
            listMap.put("avg",avg);
            listMap.put("count",count);
            yibaoListMap.add(listMap);
        }
        */
        List<Map> yibaoList = JSONObject.parseArray(yibaoArray.toJSONString(), Map.class);
        //扫码曲线获取
        JSONArray saomaArray = jsonObject.getJSONArray("saomaList");
        List<Map> saomaList = JSONObject.parseArray(yibaoArray.toJSONString(), Map.class);
        //取药列表获取
        List<Map> mediicineorderListMap = new ArrayList<>();
        JSONArray mediicineorderList = jsonObject.getJSONArray("mediicineorderList");
        for (int i = 0; i < mediicineorderList.size(); i++) {
            Map listMap = new HashMap<>();
            JSONObject quyaoQbject = mediicineorderList.getJSONObject(i);
            //取药方式(1、扫码,2、医保卡)
            String shippingType = quyaoQbject.getString("shippingType");
            String payTime = quyaoQbject.getString("payTime");
            String name = quyaoQbject.getString("name");
            listMap.put("shippingType", shippingType);
            listMap.put("payTime", payTime);
            listMap.put("name", name);
            mediicineorderListMap.add(listMap);
        }
        //设备信息获取
        List<Map> deviceListMap = new ArrayList<>();
        JSONObject deviceObject = jsonObject.getJSONObject("device");
        Map deviceListMapObject = new HashMap<>();
        //设备名称
        deviceListMapObject.put("equName", deviceObject.getString("equName"));
        //设备地址
        deviceListMapObject.put("detailAddress", deviceObject.getString("detailAddress"));
        //设备编号
        deviceListMapObject.put("equNum", deviceObject.getString("equNum"));
        //湿度
        deviceListMapObject.put("humidity", deviceObject.getString("humidity"));
        //温度
        deviceListMapObject.put("temperature", deviceObject.getString("temperature"));
        deviceListMap.add(deviceListMapObject);
        //取药方式获取
        JSONArray shippingTypeArray = jsonObject.getJSONArray("shippingTypeTotal");
        List<Map> shippingTypeList = JSONObject.parseArray(shippingTypeArray.toJSONString(), Map.class);
        //医保曲线存放
        resoultMap.put("yibaoList", yibaoList);
        //扫码曲线存放
        resoultMap.put("saomaListMap", saomaList);
        //取药列表存放
        resoultMap.put("mediicineorderListMap", mediicineorderListMap);
        //设备信息存放
        resoultMap.put("deviceList", deviceListMap);
        //取药方式存放
        resoultMap.put("shippingTypeListMap", shippingTypeList);
        return resoultMap;
    }
    /*药柜地标*/
    public List<Map<String,Object>> getLongitudeAndLatitude(){
        JSONArray resultArr = new JSONArray();
        List<Map<String, Object>> list = new ArrayList<>();
        try {
            JSONObject resultObject = getUrl("/open/noLogin/getDeviceList", null);
            resultArr = resultObject.getJSONArray("usedDeviceList");
            for (int i = 0; i < resultArr.size(); i++) {
                Map<String, Object> resultMap = new HashMap<>();
                JSONObject jsonObject = resultArr.getJSONObject(i);
                /*投放经度*/
                String lng = jsonObject.getString("lng");
                resultMap.put("lng", lng);
                /*投放纬度*/
                String lat = jsonObject.getString("lat");
                resultMap.put("lat;", lat);
                list.add(resultMap);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /*请求接口*/
    public JSONObject getUrl(String url, String parame) {
        JSONObject resultObj = new JSONObject();
        List<Map<String, String>> list = new ArrayList<>();
        try {
            //药柜请求地址
            String urlResult = httpClientUtil.getBodyRawForm(baseUrl + url, parame);
            JSONObject resultObject = JSONObject.parseObject(urlResult);
            if (resultObject.get("status").equals("200")) {
                JSONObject jsonObjectData = JSONObject.parseObject(AesEncryptUtils.agDecrypt(resultObject.get("data").toString()));
                if (jsonObjectData.get("status").equals(200)) {
                    resultObj = jsonObjectData.getJSONObject("obj");
                }
            }
            return resultObj;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}

+ 10 - 1
svr/svr-iot/src/main/resources/application.yml

@ -192,7 +192,8 @@ spring:
    url: http://ehr.yihu.com/wlyy/
    appid: 915d0345-5b1d-11e6-8344-fa163e8aee62
    appsecret: 915d0345-5b1d-11e6-8344-fa163e8aee62
hlw:
  baseUrl: http://ehr.yihu.com/hlwyy/cityihealth/base
es:
  pwflag: 1 # 1需要密码,2不需要密码
  index:
@ -230,6 +231,8 @@ spring:
    url: http://ehr.yihu.com/wlyy/
    appid: 915d0345-5b1d-11e6-8344-fa163e8aee62
    appsecret: 915d0345-5b1d-11e6-8344-fa163e8aee62
hlw:
  baseUrl: http://ehr.yihu.com/hlwyy/cityihealth/base
fast-dfs:
  tracker-server: 172.26.0.110:22122 #服务器地址
fastDFS:
@ -254,6 +257,8 @@ spring:
    url: http://www.xmtyw.cn/wlyy/
    appid: 915d0345-5b1d-11e6-8344-fa163e8aee61
    appsecret: 915d0345-5b1d-11e6-8344-fa163e8aee57
hlw:
  baseUrl: http://ehr.yihu.com/hlwyy/cityihealth/base
fast-dfs:
  tracker-server: 10.95.22.139:22122 #服务器地址
fastDFS:
@ -277,6 +282,8 @@ spring:
    url: http://www.xmtyw.cn/wlyy/
    appid: 915d0345-5b1d-11e6-8344-fa163e8aee61
    appsecret: 915d0345-5b1d-11e6-8344-fa163e8aee57
hlw:
  baseUrl: http://ehr.yihu.com/hlwyy/cityihealth/base
fast-dfs:
  tracker-server: 10.95.22.139:22122 #服务器地址
fastDFS:
@ -300,6 +307,8 @@ spring:
    url: http://www.xmtyw.cn/wlyytest/
    appid: 915d0345-5b1d-11e6-8344-fa163e8aee62
    appsecret: 915d0345-5b1d-11e6-8344-fa163e8aee62
hlw:
  baseUrl: http://ehr.yihu.com/hlwyy/cityihealth/base
es:
  pwflag: 1 # 1需要密码,2不需要密码
  host:  http://10.90.32.3:20011