LAPTOP-KB9HII50\70708 10 месяцев назад
Родитель
Сommit
005c55b589

+ 114 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/common/StatisticsController.java

@ -0,0 +1,114 @@
package com.yihu.jw.hospital.module.common;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.hospital.module.common.service.StatisticsService;
import com.yihu.jw.hospital.utils.ExportUtl;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
/**
 * Created by yeshijie on 2024/6/3.
 */
@RestController
@RequestMapping("statistics")
@Api(tags = "统计分析")
public class StatisticsController extends EnvelopRestEndpoint {
    @Autowired
    private StatisticsService statisticsService;
    @Autowired
    private ExportUtl exportUtl;
    /**
     * 智能设备分析
     * strJson={"startDate":"2024-01-01","endDate":"2024-05-27","area":"350200","level":2}
     */
    @GetMapping(value = "deviceAnalysis")
    @ApiOperation(value = "智能设备分析")
    public ObjEnvelop deviceAnalysis(@RequestParam(required = false) String startDate,
                                     @RequestParam(required = false) String endDate) {
        try {
            JSONObject json = statisticsService.deviceAnalysis(startDate,endDate);
            return ObjEnvelop.getSuccess("查询成功",json);
        } catch (Exception e) {
            e.printStackTrace();
            return ObjEnvelop.getError("查询失败");
        }
    }
    @GetMapping(value = "deviceUseInfo")
    @ApiOperation(value = "设备使用情况")
    public ObjEnvelop deviceUseInfo(@RequestParam(required = true) String type,
                                    @RequestParam(required = false) String startDate,
                                     @RequestParam(required = false) String endDate) {
        try {
            JSONObject json = statisticsService.deviceUseInfo(type,startDate,endDate);
            return ObjEnvelop.getSuccess("查询成功",json);
        } catch (Exception e) {
            e.printStackTrace();
            return ObjEnvelop.getError("查询失败");
        }
    }
    @GetMapping(value = "deviceUseDetail")
    @ApiOperation(value = "设备使用情况明细")
    public ListEnvelop deviceUseDetail(@RequestParam(required = false) String sort,
                                       @RequestParam(required = false) String startDate,
                                       @RequestParam(required = false) String endDate) {
        try {
            List<Map<String,Object>> list = statisticsService.deviceUseDetail(sort,startDate,endDate);
            return ListEnvelop.getSuccess("查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return ListEnvelop.getError("查询失败");
        }
    }
    //导出设备使用情况明细
    @GetMapping(value="exportExcel/deviceUseDetail")
    public void exportList(
            @RequestParam(required = false) String sort,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            HttpServletResponse response){
        try {
            List<Map<String,Object>> list = statisticsService.deviceUseDetail(sort,startDate,endDate);
            response.setContentType("octets/stream");
            response.setHeader("Content-Disposition", "attachment; filename=deviceUseDetail.xls");
            OutputStream os = response.getOutputStream();
            String header[] = {"科室","血压计数量","血压计绑定次数","血压计上传次数","血糖仪数量","血糖仪绑定次数","血糖仪上传次数"};
            String col[] = {"deptName","xyNum","xyBindNum","xyUseNum","xtNum","xtBindNum","xtUseNum"};
            exportUtl.write(os,list,header,col);
        }catch (Exception ex){
            error(ex);
        }
    }
    @GetMapping(value = "deptRanking")
    @ApiOperation(value = "科室使用情况排名")
    public ListEnvelop deptRanking(@RequestParam(required = true) String type,
                                    @RequestParam(required = false) String startDate,
                                    @RequestParam(required = false) String endDate) {
        try {
            List<Map<String,Object>> list = statisticsService.deptRanking(type,startDate,endDate);
            return ListEnvelop.getSuccess("查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return ListEnvelop.getError("查询失败");
        }
    }
}

+ 244 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/common/service/StatisticsService.java

@ -0,0 +1,244 @@
package com.yihu.jw.hospital.module.common.service;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
/**
 * Created by yeshijie on 2024/6/3.
 */
@Service
public class StatisticsService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 智能设备分析
     * 1、统计智能设备总数、设备上传次数、投放科室数量;
     * 2、智能设备总数:展示添加时间为查询时间内的设备总数,展示各类型的设备数量及占比比例;
     * 3、设备上传次数:展示查询时间段内所有设备的上传次数,展示各类型设备的上传次数及占总数的比例;
     * 4、投放科室数量:展示添加时间为查询时间内的设备分配给科室的科室数量,需去重;
     * 5、设备总数取值:医生PC端—设备信息管理中添加时间为查询时间段内设备数量(已删除的不算在内);
     * 6、上传总数取值:医生PC端—体征数据查询中,上传时间为查询时间段内的记录数量;
     * 7、投放科室数量取值:医生PC端—设备信息管理中已维护的设备中选择的科室的数量,按添加时间进行查询注:(一个科室只计算一次)
     */
    public JSONObject deviceAnalysis(String startDate,String endDate) throws Exception{
        JSONObject json = new JSONObject();
        String filterDevice = "";
        String filterUpload = "";
        String filterDept = "";
        String filterDeptUse = "";
        if(StringUtils.isNotBlank(startDate)){
            filterDevice += " and d.apply_date>='"+startDate+"' ";
            filterDept += " and apply_date>='"+startDate+"' ";
            filterDeptUse += " and d.apply_date>='"+startDate+"' and i.czrq>='"+startDate+"' ";
            filterUpload += " and czrq>='"+startDate+"' ";
        }
        if(StringUtils.isNotBlank(endDate)){
            filterDevice += " and d.apply_date<='"+endDate+" 23:59:59' ";
            filterDept += " and apply_date<='"+endDate+" 23:59:59' ";
            filterDeptUse += " and d.apply_date<='"+endDate+" 23:59:59' and i.czrq<='"+endDate+" 23:59:59' ";
            filterUpload += " and czrq<='"+endDate+" 23:59:59' ";
        }
        //智能设备总数
        int devcieTotal = 0;
        int devcieXt = 0;//血糖仪数
        int devcieXy = 0;//血压计数
        String deviceSql = "SELECT dm.category_code type,COUNT(d.id) num FROM " +
                "wlyy_devices d INNER JOIN dm_device dm ON d.category_code = dm.id " +
                "where 1=1  " + filterDevice +
                "GROUP BY dm.category_code";
        List<Map<String,Object>> deviceList = jdbcTemplate.queryForList(deviceSql);
        for (Map<String,Object> map:deviceList){
            String type = map.get("type")+"";
            if("1".equals(type)){
                devcieXt = Integer.parseInt(map.get("num")+"");
            }
            if("3".equals(type)){
                devcieXy = Integer.parseInt(map.get("num")+"");
            }
        }
        devcieTotal = devcieXt+devcieXy;
        json.put("devcieTotal",devcieTotal);
        json.put("devcieXt",devcieXt);
        json.put("devcieXy",devcieXy);
        //设备上传次数
        int uploadTotal = 0;
        int uploadXt = 0;//
        int uploadXy = 0;//
        String uploadSql = "select type,count(id) num from wlyy_patient_health_index where 1=1 "+filterUpload+" group by type";
        List<Map<String,Object>> uploadList = jdbcTemplate.queryForList(uploadSql);
        for (Map<String,Object> map:uploadList){
            String type = map.get("type")+"";
            if("1".equals(type)){
                uploadXt = Integer.parseInt(map.get("num")+"");
            }
            if("3".equals(type)){
                uploadXy = Integer.parseInt(map.get("num")+"");
            }
        }
        uploadTotal = uploadXt+uploadXy;
        json.put("uploadTotal",uploadTotal);
        json.put("uploadXt",uploadXt);
        json.put("uploadXy",uploadXy);
        //投放科室数量
        String deptSql = "select count(DISTINCT dept) from wlyy_devices where dept is not null "+filterDept;
        String deptUseSql = "SELECT count(DISTINCT d.dept) from wlyy_devices d,wlyy_patient_health_index i " +
                "WHERE d.dept is not null and d.device_code=i.device_sn and i.del=1 "+filterDeptUse;
        int deptTotal = jdbcTemplate.queryForObject(deptSql,Integer.class);
        int deptUse = jdbcTemplate.queryForObject(deptUseSql,Integer.class);
        if(deptUse>deptTotal){
            deptUse = deptTotal;
        }
        int deptUnUse = deptTotal-deptUse;
        json.put("deptTotal",deptTotal);
        json.put("deptUse",deptUse);
        json.put("deptUnUse",deptUnUse);
        return json;
    }
    /**
     * 设备使用情况
     * type 1血糖 2血压
     * 1、图表说明
     * X轴:时间-默认按日期汇总,切换为近半年、今年时,改为按月份汇总支
     * Y轴:次数
     * 2、用不同颜色代表绑定次数及上传次数,鼠标停留在柱形图后,显示该条的具体数据;
     * 3、支持进行血压计、血糖仪的使用情况切换。
     */
    public JSONObject deviceUseInfo(String type,String startDate,String endDate){
        JSONObject json = new JSONObject();
        String bindSql = "SELECT COUNT(*) num,DATE_FORMAT(czrq,'%Y-%m-%d') date from wlyy_patient_device " +
                " where category_code = '"+type+"' ";
        String useSql = "SELECT COUNT(*) num,DATE_FORMAT(czrq,'%Y-%m-%d') date from wlyy_patient_health_index " +
                " where type = '"+type+"' and del=1 ";
        if(StringUtils.isNotBlank(startDate)){
            bindSql += " and czrq>='"+startDate+"' ";
            useSql += " and czrq>='"+startDate+"' ";
        }
        if(StringUtils.isNotBlank(endDate)){
            bindSql += " and czrq<='"+endDate+" 23:59:59' ";
            useSql += " and czrq<='"+endDate+" 23:59:59' ";
        }
        bindSql += " GROUP BY date ORDER BY date ";
        useSql += " GROUP BY date ORDER BY date ";
        List<Map<String,Object>> bindList = jdbcTemplate.queryForList(bindSql);
        List<Map<String,Object>> useList = jdbcTemplate.queryForList(useSql);
        json.put("bindList",bindList);
        json.put("useList",useList);
        return json;
    }
    /**
     * 设备使用情况明细
     * 1、展示查询时间段内各科室的使用情况列表;
     * 2、支持导出该表格;
     * 3、默认按照科室名称的拼音字母进行排序;
     * 4、支持通过点击字段名称旁边的排序符号切换排序规则。
     * 设备数量按最新的投放科室进行统计;绑定次数按绑定时的投放科室进行统计;上传次数按照上传时的投放科室进行统计
     */
    public List<Map<String,Object>> deviceUseDetail(String sort,String startDate,String endDate){
        if(StringUtils.isNotBlank(sort)){
            sort = "deptName";
        }
        String filter = "";
        String filterUse = "";
        String filterBind = "";
        if(StringUtils.isNotBlank(startDate)){
            filter += " and d.apply_date>='"+startDate+"' ";
            filterUse += " and czrq>='"+startDate+"' ";
            filterBind += " and czrq>='"+startDate+"' ";
        }
        if(StringUtils.isNotBlank(endDate)){
            filter += " and d.apply_date<='"+endDate+" 23:59:59' ";
            filterUse += " and czrq<='"+endDate+" 23:59:59' ";
            filterBind += " and czrq<='"+endDate+" 23:59:59' ";
        }
        String sql = "SELECT d.code dept,d.`name` deptName,IFNULL(t1.xtNum,0) xtNum,IFNULL(t1.xyNum,0) xyNum " +
                ",IFNULL(t2.xtUseNum,0) xtUseNum,IFNULL(t2.xyUseNum,0) xyUseNum " +
                ",IFNULL(t3.xtBindNum,0) xtBindNum,IFNULL(t3.xyBindNum,0) xyBindNum from dict_hospital_dept d " +
                "LEFT JOIN (SELECT d.dept,d.dept_name,COUNT(if(dm.category_code=1,1,null)) xtNum,COUNT(if(dm.category_code=2,1,null)) xyNum " +
                " from wlyy_devices d,dm_device dm " +
                "WHERE d.category_code=dm.id " + filter +
                "GROUP BY d.dept) t1 on d.code=t1.dept " +
                "LEFT JOIN (SELECT dept,dept_name,COUNT(if(type=1,1,null)) xtUseNum,COUNT(if(type=2,1,null)) xyUseNum from  " +
                "wlyy_patient_health_index where del=1 " + filterUse +
                "GROUP BY dept) t2 on d.code=t2.dept " +
                "LEFT JOIN (SELECT dept,dept_name,COUNT(if(category_code=1,1,null)) xtBindNum,COUNT(if(category_code=2,1,null)) xyBindNum  " +
                "from wlyy_patient_device where 1=1 " + filterBind+
                "GROUP BY dept) t3 on d.code=t3.dept " +
                "WHERE (xtNum+xyNum+xtUseNum+xyUseNum+xtBindNum+xyBindNum)>0 ORDER BY '"+sort+"' desc";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        return list;
    }
    /**
     * 科室使用情况排名
     * 1、默认展示投放科室排名,展示设备添加时间为查询时间段内,各科室的的血糖仪、血压计数量;
     * 2、使用科室排名,展示所有在查询时间段内,有使用设备的科室排名(有用户绑定、数据上传的科室),展示“绑定次数”、“上传次数”,默认按照上传次数进行倒序排序
     * type 1投放科室 2使用科室
     */
    public List<Map<String,Object>> deptRanking(String type,String startDate,String endDate){
        String filter = "";
        String filterUse = "";
        String filterBind = "";
        if(StringUtils.isNotBlank(startDate)){
            filter += " and d.apply_date>='"+startDate+"' ";
            filterUse += " and czrq>='"+startDate+"' ";
            filterBind += " and czrq>='"+startDate+"' ";
        }
        if(StringUtils.isNotBlank(endDate)){
            filter += " and d.apply_date<='"+endDate+" 23:59:59' ";
            filterUse += " and czrq<='"+endDate+" 23:59:59' ";
            filterBind += " and czrq<='"+endDate+" 23:59:59' ";
        }
        //使用科室排名
        String sql = "SELECT d.dept,d.dept_name,COUNT(if(dm.category_code=1,1,null)) xtNum,COUNT(if(dm.category_code=2,1,null)) xyNum " +
                " from wlyy_devices d,dm_device dm " +
                "WHERE d.category_code=dm.id " + filter +
                "GROUP BY d.dept order by xtNum desc ";
        //投放科室排名
        String sql2 = "SELECT d.code dept,d.`name` deptName,IFNULL(t2.useNum,0) useNum " +
                ",IFNULL(t3.bindNum,0) bindNum from dict_hospital_dept d " +
                "LEFT JOIN (SELECT dept,dept_name,COUNT(id) useNum from  " +
                "wlyy_patient_health_index where del=1 " + filterUse +
                "GROUP BY dept) t2 on d.code=t2.dept " +
                "LEFT JOIN (SELECT dept,dept_name,COUNT(id) bindNum " +
                "from wlyy_patient_device where 1=1 " + filterBind +
                "GROUP BY dept) t3 on d.code=t3.dept " +
                "WHERE (useNum+bindNum)>0 " +
                "ORDER BY useNum desc ";
        List<Map<String,Object>> list = null;
        if("1".equals(type)){
            list = jdbcTemplate.queryForList(sql);
        }else {
            list = jdbcTemplate.queryForList(sql2);
        }
        return list;
    }
    public String getRange(int first, int second) {
        if (second == 0 && first > 0) {
            return "100%";
        } else if (second == 0 && first == 0) {
            return "0%";
        }
        float size = (float) (first * 100) / second;
        DecimalFormat df = new DecimalFormat("0");//格式化小数,不足的补0
        String filesize = df.format(size);
        return filesize + "%";
    }
}

+ 41 - 5
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/controller/DeviceController.java

@ -46,6 +46,39 @@ public class DeviceController extends BaseController {
    private DeviceDetailService deviceDetailService;
    private DeviceDetailService deviceDetailService;
    @Autowired
    @Autowired
    private PatientDeviceLogService patientDeviceLogService;
    private PatientDeviceLogService patientDeviceLogService;
    @Autowired
    private QrcodeUtil qrcodeUtil;
    //设备使用情况列表
    @GetMapping(value="devicePage")
    public PageEnvelop devicePage(
            @RequestParam(value = "name",required = false)String name,
            @RequestParam(value = "type",required = false) String type,
            @RequestParam(value = "dept",required = false) String dept,
            @RequestParam(value = "page",required = false)Integer page,
            @RequestParam(value = "pageSize",required = false)Integer pageSize){
        try {
            return deviceService.devicePage(page, pageSize,name,type,dept);
        }catch (Exception ex){
            ex.printStackTrace();
            return PageEnvelop.getError("查询失败!");
        }
    }
    //绑定记录页
    @GetMapping(value="patientDevicePage")
    public PageEnvelop patientDevicePage(
            @RequestParam(value = "name",required = false)String name,
            @RequestParam(value = "deviceSn",required = false) String deviceSn,
            @RequestParam(value = "page",required = false)Integer page,
            @RequestParam(value = "pageSize",required = false)Integer pageSize){
        try {
            return deviceService.patientDevicePage(page, pageSize,name,deviceSn);
        }catch (Exception ex){
            ex.printStackTrace();
            return PageEnvelop.getError("查询失败!");
        }
    }
    @ApiOperation("获取设备分类")
    @ApiOperation("获取设备分类")
    @RequestMapping(value = "DeviceCategory", method = {RequestMethod.POST, RequestMethod.GET})
    @RequestMapping(value = "DeviceCategory", method = {RequestMethod.POST, RequestMethod.GET})
@ -86,9 +119,6 @@ public class DeviceController extends BaseController {
        }
        }
    }
    }
    @Autowired
    private QrcodeUtil qrcodeUtil;
    @ApiOperation("生成设备的小程序二维码")
    @ApiOperation("生成设备的小程序二维码")
    @PostMapping(value = "setQrcode")
    @PostMapping(value = "setQrcode")
    public Envelop setQrcode(@ApiParam(name = "id", value = "设备ID", defaultValue = "19")
    public Envelop setQrcode(@ApiParam(name = "id", value = "设备ID", defaultValue = "19")
@ -298,6 +328,11 @@ public class DeviceController extends BaseController {
    public Envelop healthIndexlist(
    public Envelop healthIndexlist(
            @RequestParam(value = "deviceSn",required = false) String deviceSn,
            @RequestParam(value = "deviceSn",required = false) String deviceSn,
            @RequestParam(value = "date",required = false) String date,
            @RequestParam(value = "date",required = false) String date,
            @RequestParam(value = "dept",required = false) String dept,
            @RequestParam(value = "startDate",required = false) String startDate,
            @RequestParam(value = "endDate",required = false) String endDate,
            @RequestParam(value = "startRecordDate",required = false) String startRecordDate,
            @RequestParam(value = "endRecordDate",required = false) String endRecordDate,
            @RequestParam(value = "idcard",required = false) String idcard,
            @RequestParam(value = "idcard",required = false) String idcard,
            @RequestParam(value = "userName",required = false) String userName,
            @RequestParam(value = "userName",required = false) String userName,
            @RequestParam(value = "indexType",required = false) String indexType,
            @RequestParam(value = "indexType",required = false) String indexType,
@ -308,7 +343,8 @@ public class DeviceController extends BaseController {
            @RequestParam(value = "page",required = false) Integer page,
            @RequestParam(value = "page",required = false) Integer page,
            @RequestParam(value = "pageSize",required = false) Integer pageSize){
            @RequestParam(value = "pageSize",required = false) Integer pageSize){
        try{
        try{
            return deviceService.healthIndexlist(deviceSn,date, idcard, userName, indexType,page, pageSize,indexTypeMin1, indexTypeMax1, indexTypeMin2,indexTypeMax2);
            return deviceService.healthIndexlist(deviceSn,date, idcard, userName, indexType,page, pageSize,indexTypeMin1,
                    indexTypeMax1, indexTypeMin2,indexTypeMax2,dept,startDate,endDate,startRecordDate,endRecordDate);
        }catch (Exception ex){
        }catch (Exception ex){
            ex.printStackTrace();
            ex.printStackTrace();
            return Envelop.getError("操作失败!");
            return Envelop.getError("操作失败!");
@ -333,7 +369,7 @@ public class DeviceController extends BaseController {
        }
        }
    }
    }
    //设备解绑(记录删除)
    //设备解绑
    @PostMapping(value = "deletePatientDevice")
    @PostMapping(value = "deletePatientDevice")
    public Envelop deletePatientDevice(@RequestParam(value = "id") String id){
    public Envelop deletePatientDevice(@RequestParam(value = "id") String id){
        try {
        try {

+ 2 - 5
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/controller/PatientDeviceController.java

@ -173,7 +173,7 @@ public class PatientDeviceController extends BaseController {
    }
    }
    /**
    /**
     * 设备保存接口  ---增加血糖时间段保存 Reece v1.3.3 06
     * 设备保存接口
     */
     */
    @ApiOperation("设备保存接口")
    @ApiOperation("设备保存接口")
    @RequestMapping(value = "SavePatientDevice", method = RequestMethod.POST)
    @RequestMapping(value = "SavePatientDevice", method = RequestMethod.POST)
@ -204,10 +204,7 @@ public class PatientDeviceController extends BaseController {
            }
            }
            BasePatientDO patient = patientService.findById(patientId).orElse(null);
            BasePatientDO patient = patientService.findById(patientId).orElse(null);
//            if(!getUID().equals(patientId)&&device.getId()==null){
//                device.setAgent(patientId);
//                device.setAgentName(patient.getName());
//            }
            String sn = device.getDeviceSn();
            String sn = device.getDeviceSn();
            synchronized (sn.intern()){
            synchronized (sn.intern()){
                patientDeviceService.saveDevice(device,isScan);
                patientDeviceService.saveDevice(device,isScan);

+ 92 - 3
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/service/DeviceService.java

@ -13,6 +13,7 @@ import com.yihu.jw.hospital.utils.QrcodeUtil;
import com.yihu.jw.restmodel.iot.device.DeviceHealthIndexVO;
import com.yihu.jw.restmodel.iot.device.DeviceHealthIndexVO;
import com.yihu.jw.restmodel.iot.device.WlyyPatientDeviceVO;
import com.yihu.jw.restmodel.iot.device.WlyyPatientDeviceVO;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.util.date.DateTimeUtil;
import com.yihu.jw.util.date.DateTimeUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.StringUtils;
@ -213,6 +214,65 @@ public class DeviceService {
		return deviceDetailDao.findAll(spec);
		return deviceDetailDao.findAll(spec);
	}
	}
	/**
	 * 设备使用情况列表
	 * @param page
	 * @param pageSize
	 * @param name
	 * @param type 类型 1血糖 2血压
	 * @param dept
	 * @return
	 */
	public PageEnvelop devicePage(Integer page,Integer pageSize,String name,String type,String dept){
		if(page == null){
			page = 1;
		}
		if(pageSize == null){
			pageSize = 15;
		}
		String sql = "SELECT p.name patientName,pd.del,pd.applyStatus,dm.category_code type,dm.photo,d.* ";
		String countSql = "select count(*) ";
		String filter = " from wlyy_devices d  " +
				"INNER JOIN dm_device dm on d.category_code=dm.id " +
				"LEFT JOIN (SELECT MAX(pd.id) id,pd.del,pd.user,pd.apply_status applyStatus,d.device_code from wlyy_devices d,wlyy_patient_device pd " +
				"where pd.device_sn=d.device_code and pd.del=0 GROUP BY d.device_code) pd on d.device_code=pd.device_code " +
				"LEFT JOIN base_patient p on p.id=pd.user where 1=1 ";
		if(StringUtils.isNotBlank(name)){
			filter += " and (p.name like '%"+name+"%' or d.device_code like '%"+name+"%') ";
		}
		if(StringUtils.isNotBlank(type)){
			filter += " and dm.category_code = '"+type+"'";
		}
		if(StringUtils.isNotBlank(dept)){
			filter += " and dept = '"+dept+"'";
		}
		String orderBy = " limit "+(page-1)*pageSize+","+pageSize;
		List<DeviceDetail> list = jdbcTemplate.query(sql+filter+orderBy,new BeanPropertyRowMapper<>(DeviceDetail.class));
		Long count = jdbcTemplate.queryForObject(countSql+filter,Long.class);
		return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count);
	}
	//绑定记录页
	public PageEnvelop patientDevicePage(Integer page,Integer pageSize,String name,String deviceSn){
		String sql = "SELECT d.device_sn deviceSn,DATE_FORMAT(d.czrq,'%Y-%m-%d %H:%i:%s') bindDate,DATEDIFF(NOW(), d.czrq) AS bindDays,d.del,d.apply_status applyStatus " +
				",p.id patient,p.`name`,p.sex,p.photo,p.idcard,p.birthday,d.id " ;
		String countSql = "select count(*) ";
		String filter = " from wlyy_patient_device d,base_patient p  WHERE d.device_sn='"+deviceSn+"' and d.`user` =p.id ";
		if(StringUtils.isNotBlank(name)){
			filter += " and p.name like '%"+name+"%' ";
		}
		String orderBy = " ORDER BY d.czrq desc limit "+(page-1)*pageSize+","+pageSize;
		List<Map<String,Object>> list = jdbcTemplate.queryForList(sql+filter+orderBy);
		for (Map<String,Object> map:list){
			String sex = map.get("sex")+"";
			String idcard = map.get("idcard")+"";
			String birthday = map.get("birthday")+"";
			map.put("age", IdCardUtil.getAgeByIdcardOrBirthday(idcard,DateUtil.strToDate(birthday)));
		}
		Long count = jdbcTemplate.queryForObject(countSql+filter,Long.class);
		return PageEnvelop.getSuccessListWithPage("查询成功",list,page,pageSize,count);
	}
	public PageEnvelop searchDeviceList(String deviceName,String deviceCode,String linkman,Integer page,Integer pageSize){
	public PageEnvelop searchDeviceList(String deviceName,String deviceCode,String linkman,Integer page,Integer pageSize){
		if(page == null){
		if(page == null){
			page = 1;
			page = 1;
@ -368,8 +428,19 @@ public class DeviceService {
		return total ;
		return total ;
	}
	}
	/**
	 *
	 * dept 投放科室
	 * startDate 开始上传时间
	 * endDate 结束上传时间
	 * startRecordDate 开始测量时间
	 * endRecordDate	结束测量时间
	 * @return
	 * @throws Exception
	 */
	public PageEnvelop healthIndexlist(String deviceSn, String date, String idcard, String userName, String indexType, Integer page, Integer pageSize,
	public PageEnvelop healthIndexlist(String deviceSn, String date, String idcard, String userName, String indexType, Integer page, Integer pageSize,
									   Double indexTypeMin1, Double indexTypeMax1, Double indexTypeMin2, Double indexTypeMax2)throws Exception{
									   Double indexTypeMin1, Double indexTypeMax1, Double indexTypeMin2, Double indexTypeMax2,String dept,String startDate,
									   String endDate,String startRecordDate,String endRecordDate)throws Exception{
		if (page == null){
		if (page == null){
			page = 1;
			page = 1;
		}
		}
@ -378,8 +449,10 @@ public class DeviceService {
		}
		}
		StringBuilder filter = new StringBuilder();
		StringBuilder filter = new StringBuilder();
		String sql =" SELECT i.* ,s.name userName FROM wlyy_patient_health_index i JOIN base_patient s ON i.user=s.id ";
		String countSql =" SELECT count(1) as num FROM wlyy_patient_health_index i JOIN base_patient s ON i.user=s.id ";
		String sql =" SELECT i.* ,s.name userName,d.dept,d.dept_name FROM wlyy_patient_health_index i JOIN base_patient s ON i.user=s.id " +
				" left join wlyy_devices d on d.device_code=i.device_sn ";
		String countSql =" SELECT count(1) as num FROM wlyy_patient_health_index i JOIN base_patient s ON i.user=s.id " +
				" left join wlyy_devices d on d.device_code=i.device_sn ";
		sql += " WHERE 1=1 ";
		sql += " WHERE 1=1 ";
		countSql += " WHERE 1=1 ";
		countSql += " WHERE 1=1 ";
@ -395,6 +468,9 @@ public class DeviceService {
		if(!StringUtils.isEmpty(idcard)){
		if(!StringUtils.isEmpty(idcard)){
			filter.append(" and i.idcard like '%"+idcard+"%' ");
			filter.append(" and i.idcard like '%"+idcard+"%' ");
		}
		}
		if(!StringUtils.isEmpty(dept)){
			filter.append(" and d.dept = '"+dept+"' ");
		}
		//体征数据创建时间
		//体征数据创建时间
		if(!StringUtils.isEmpty(date)){
		if(!StringUtils.isEmpty(date)){
			Date startTimeTemp  =  DateTimeUtil.simpleDateParse(date);
			Date startTimeTemp  =  DateTimeUtil.simpleDateParse(date);
@ -425,6 +501,18 @@ public class DeviceService {
		if(indexTypeMax2!=null){
		if(indexTypeMax2!=null){
			filter.append(" and value2<="+indexTypeMax2);
			filter.append(" and value2<="+indexTypeMax2);
		}
		}
		if(StringUtils.isNotBlank(startDate)){
			filter.append(" and i.czrq>='"+startDate+"'");
		}
		if(StringUtils.isNotBlank(endDate)){
			filter.append(" and i.czrq<='"+endDate+" 23:59:59'");
		}
		if(StringUtils.isNotBlank(startRecordDate)){
			filter.append(" and i.record_date>='"+startRecordDate+"'");
		}
		if(StringUtils.isNotBlank(endRecordDate)){
			filter.append(" and i.record_date<='"+endRecordDate+" 23:59:59'");
		}
		String f = filter.toString();
		String f = filter.toString();
		List<DeviceHealthIndexVO> resultList = jdbcTemplate.query(sql+f+" order by i.czrq desc "+" limit "+(page-1)*pageSize+","+pageSize,new BeanPropertyRowMapper<>(DeviceHealthIndexVO.class));
		List<DeviceHealthIndexVO> resultList = jdbcTemplate.query(sql+f+" order by i.czrq desc "+" limit "+(page-1)*pageSize+","+pageSize,new BeanPropertyRowMapper<>(DeviceHealthIndexVO.class));
		if(resultList.size()<=0){
		if(resultList.size()<=0){
@ -437,6 +525,7 @@ public class DeviceService {
		long count = jdbcTemplate.queryForObject(countSql+filter,Long.class);
		long count = jdbcTemplate.queryForObject(countSql+filter,Long.class);
		return PageEnvelop.getSuccessListWithPage("查询成功",resultList,page,pageSize,count);
		return PageEnvelop.getSuccessListWithPage("查询成功",resultList,page,pageSize,count);
	}
	}
	public JSONObject gethealthStandard(Integer type, String patientCode) {
	public JSONObject gethealthStandard(Integer type, String patientCode) {
		//血糖校验
		//血糖校验
		JSONObject json = new JSONObject();
		JSONObject json = new JSONObject();

+ 8 - 27
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/service/DeviceUploadService.java

@ -173,33 +173,14 @@ public class DeviceUploadService {
        List<DeviceDetail> deviceDetails = deviceDetailDao.findByDeviceCode(deviceSn);
        List<DeviceDetail> deviceDetails = deviceDetailDao.findByDeviceCode(deviceSn);
        if (deviceDetails != null && deviceDetails.size()>0){
        if (deviceDetails != null && deviceDetails.size()>0){
            deviceDetail = deviceDetails.get(0);
            deviceDetail = deviceDetails.get(0);
            if (deviceDetail.getGrantOrgCode() != null&& deviceDetail.getGrantOrgCode().equals("3502050300")){//
                List<DevicePatientDevice> patientDeviceList =  patientDeviceDao.findByDeviceSnAndCategoryCode(deviceSn, type);
                if (patientDeviceList != null&&patientDeviceList.size()==1) {
                    device = patientDeviceList.get(0);
                }else if(patientDeviceList != null&&patientDeviceList.size()==2){
                    for (int i=0;i<patientDeviceList.size();i++){
                        if(userType.equals(patientDeviceList.get(i).getUserType())){
                            device = patientDeviceList.get(i);
                            break;
                        }
                    }
                }
            }else {
//                device = patientDeviceDao.findByDeviceSnAndCategoryCodeAndUserType(deviceSn, type, userType);
                List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSnAndCategoryCode(deviceSn, type);
                if (devices.size()>0){
                    device = devices.get(0);
                }else {
                    device=null;
                }
            List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSnAndCategoryCode(deviceSn, type);
            if (devices.size()>0){
                device = devices.get(0);
            }
            }
        }
        }
        if (device != null) {
        /*//根据设备获取患者(设备只绑定一个人的时候,不判断按键)
        if (device!=null) {*/
        if (device != null) {
            //设备改成都不判断按键
            /************设备数据重复推送处理 start**********************/
            /************设备数据重复推送处理 start**********************/
            String value1 = data;
            String value1 = data;
            String value2="";
            String value2="";
@ -229,9 +210,6 @@ public class DeviceUploadService {
            if (value1.equals(value2) && value2.equals(value3)){
            if (value1.equals(value2) && value2.equals(value3)){
                return null;
                return null;
            }
            }
//            List<PatientHealthIndex> list = patientHealthIndexDao.findByType(device.getUser(),deviceSn,value1,Integer.parseInt(type),time);
            /*long maxtime = time.getTime()+30*1000;
            long mintime = time.getTime()-30*1000;*/
            Date minDate = DateUtil.getPreDays(time,-3);
            Date minDate = DateUtil.getPreDays(time,-3);
            Date maxDate = DateUtil.getPreDays(time,3);
            Date maxDate = DateUtil.getPreDays(time,3);
            List<DevicePatientHealthIndex> list = ioTfindByType(device.getUser(),deviceSn,value1,value2,value3,Integer.parseInt(type),time,minDate,maxDate);
            List<DevicePatientHealthIndex> list = ioTfindByType(device.getUser(),deviceSn,value1,value2,value3,Integer.parseInt(type),time,minDate,maxDate);
@ -300,6 +278,9 @@ public class DeviceUploadService {
            if(deviceDetail!=null){
            if(deviceDetail!=null){
                obj.setHospital(deviceDetail.getGrantOrgCode());
                obj.setHospital(deviceDetail.getGrantOrgCode());
                obj.setHospitalName(deviceDetail.getOrgName());
                obj.setHospitalName(deviceDetail.getOrgName());
                //设置使用科室
                obj.setDeptName(deviceDetail.getDeptName());
                obj.setDept(deviceDetail.getDept());
            }
            }
            obj = patientHealthIndexDao.save(obj);
            obj = patientHealthIndexDao.save(obj);

+ 18 - 11
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/module/health/service/PatientDeviceService.java

@ -110,7 +110,9 @@ public class PatientDeviceService  {
            if("1".equals(isScan)){
            if("1".equals(isScan)){
                //解绑
                //解绑
                List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSnAndUserType2(sn, userType);
                List<DevicePatientDevice> devices = patientDeviceDao.findByDeviceSnAndUserType2(sn, userType);
                patientDeviceDao.deleteAll(devices);
                if(devices.size()>0){
                    patientDeviceDao.updatePatientDevice(sn);
                }
            }
            }
            DevicePatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(sn, userType);
            DevicePatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(sn, userType);
            if (device != null && !device.getId().equals(patientDevice.getId())) {
            if (device != null && !device.getId().equals(patientDevice.getId())) {
@ -124,17 +126,20 @@ public class PatientDeviceService  {
        BasePatientDO patient = patientDao.findById(patientDevice.getUser()).orElse(null);
        BasePatientDO patient = patientDao.findById(patientDevice.getUser()).orElse(null);
        patientDevice.setUserIdcard(patient.getIdcard());
        patientDevice.setUserIdcard(patient.getIdcard());
        savePatientDevice(patientDevice);
        List<DevicePatientDevice> ownList = patientDeviceDao.findByPatientAndDeviceSn(patientDevice.getUser(),patientDevice.getDeviceSn());
        if(ownList.size()>0){
            patientDeviceDao.deleteAll(ownList);
        }
        return true;
    }
        List<DeviceDetail> deviceDetails = deviceDetailDao.findByDeviceCode(patientDevice.getDeviceSn());
        if(deviceDetails.size()>0){
            patientDevice.setDept(deviceDetails.get(0).getDept());
            patientDevice.setDeptName(deviceDetails.get(0).getDeptName());
        }
    /**
     * 设备绑定
     * @param patientDevice
     */
    public void savePatientDevice(DevicePatientDevice patientDevice){
        patientDeviceDao.save(patientDevice);
        patientDeviceDao.save(patientDevice);
        return true;
    }
    }
@ -154,7 +159,9 @@ public class PatientDeviceService  {
     */
     */
    public List<com.alibaba.fastjson.JSONObject> deleteDevice(String id, String uuid) {
    public List<com.alibaba.fastjson.JSONObject> deleteDevice(String id, String uuid) {
        DevicePatientDevice device = patientDeviceDao.findById(Long.valueOf(id)).orElse(null);
        DevicePatientDevice device = patientDeviceDao.findById(Long.valueOf(id)).orElse(null);
        patientDeviceDao.delete(device);
        device.setDel(1);
        device.setDelUser(uuid);
        patientDeviceDao.save(device);
        List<DevicePatientDevice> patientDevices = patientDeviceDao.findByDeviceSnAndCategoryCode(device.getDeviceSn(), device.getCategoryCode());
        List<DevicePatientDevice> patientDevices = patientDeviceDao.findByDeviceSnAndCategoryCode(device.getDeviceSn(), device.getCategoryCode());
        List<com.alibaba.fastjson.JSONObject> objects = new ArrayList<>();
        List<com.alibaba.fastjson.JSONObject> objects = new ArrayList<>();
        for (DevicePatientDevice patientDevice : patientDevices) {
        for (DevicePatientDevice patientDevice : patientDevices) {
@ -207,7 +214,7 @@ public class PatientDeviceService  {
        PageRequest pageRequest = PageRequest.of(page - 1, pagesize);
        PageRequest pageRequest = PageRequest.of(page - 1, pagesize);
        List<DevicePatientDevice> list = new ArrayList<>();
        List<DevicePatientDevice> list = new ArrayList<>();
        list = patientDeviceDao.findByUser(patientCode, pageRequest);
        list = patientDeviceDao.findByUserAndDel(patientCode,0, pageRequest);
        if (list != null) {
        if (list != null) {
            //获取设备路径,医生姓名
            //获取设备路径,医生姓名
            List<Device> deviceList = deviceDao.findAll();
            List<Device> deviceList = deviceDao.findAll();

+ 71 - 0
svr/svr-visit-behind/src/main/java/com/yihu/jw/hospital/utils/ExportUtl.java

@ -0,0 +1,71 @@
package com.yihu.jw.hospital.utils;
import jxl.write.*;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
/**
 * 导出工具类
 * Created by yeshijie on 2024/6/4.
 */
@Component
public class ExportUtl {
    public void addHeader(WritableSheet ws,String[] header) throws WriteException {
        int i = 0;
        for (String h : header) {
            addCell(ws, 0, i, h);//表名,行,列,header
            i++;
        }
    }
    public void write(WritableWorkbook wwb, List<Map<String,Object>> ls,String[] header,String[] col) throws Exception {
        try {
            WritableSheet ws;
            ws = wwb.createSheet("sheet",1);
            addHeader(ws,header);
            int i = 1;
            for (Map<String,Object> m : ls) {
                for (int j=0;j<col.length;j++){
                    addCell(ws, i, j, m.get(col[j]),"");
                }
                i++;
            }
            wwb.write();
            wwb.close();
        } catch (IOException e) {
            e.printStackTrace();
            if (wwb != null) wwb.close();
            throw e;
        }
    }
    public void write(OutputStream os, List ls,String[] header,String[] col) throws Exception{
        write(jxl.Workbook.createWorkbook(os), ls,header,col);
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
        Label label = new Label(column ,row, data);
        ws.addCell(label);
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, Object obj, String memo) throws WriteException {
        String data = "";
        if(obj!=null){
            data = obj +"";
        }
        if("null".equals(data)){
            data = "";
        }
        Label label = new Label(column ,row, data);
        if(!org.springframework.util.StringUtils.isEmpty(memo)){
            WritableCellFeatures cellFeatures = new WritableCellFeatures();
            cellFeatures.setComment(memo);
            label.setCellFeatures(cellFeatures);
        }
        ws.addCell(label);
    }
}