Jelajahi Sumber

设备绑定

zd_123 7 tahun lalu
induk
melakukan
09c1a1a8d8

+ 37 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/device/PatientDevice.java

@ -34,6 +34,14 @@ public class PatientDevice extends IdEntity {
    private String agent;//代绑人代码(家人)
    // 操作时间
    private Date czrq;
    //解绑人
    private String delUser;
    //1-解绑,0-绑定
    private Integer del;
    //设备活动类型
    private String deviceActivityType;
    //========================非表字段======================
    //患者居住地址
    private String address;
@ -65,6 +73,8 @@ public class PatientDevice extends IdEntity {
    //	this.del = del;
    //}
    @Column(name = "device_id")
    public Long getDeviceId() {
        return deviceId;
@ -165,6 +175,33 @@ public class PatientDevice extends IdEntity {
        this.agent = agent;
    }
    @Column(name = "del_user")
    public String getDelUser() {
        return delUser;
    }
    public void setDelUser(String delUser) {
        this.delUser = delUser;
    }
    @Column(name = "del")
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
    @Column(name = "device_activity_type")
    public String getDeviceActivityType() {
        return deviceActivityType;
    }
    public void setDeviceActivityType(String deviceActivityType) {
        this.deviceActivityType = deviceActivityType;
    }
    @Transient
    public String getAddress() {
        return address;

+ 4 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/PatientDeviceDao.java

@ -35,6 +35,9 @@ public interface PatientDeviceDao extends PagingAndSortingRepository<PatientDevi
    PatientDevice findByDeviceSnAndUserType(String deviceSn, String userType);
    @Query("select pd from PatientDevice pd where pd.deviceSn = ?1 and pd.del=0")
    List<PatientDevice> findByDeviceSn(String deviceSn);
    //更换患者绑定的血糖仪
    @Modifying
    @Query("update PatientDevice t set t.deviceSn = ?3 , t.userType = ?4,t.sim=?5 where t.user = ?1 and t.deviceSn = ?2 ")
@ -47,4 +50,5 @@ public interface PatientDeviceDao extends PagingAndSortingRepository<PatientDevi
    @Query("select a from PatientDevice a")
    List<PatientDevice> findAll();
}

+ 16 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/PatientInfoService.java

@ -1742,4 +1742,20 @@ public class PatientInfoService extends BaseService {
            return null;
        }
    }
    public List<Map<String,Object>> getPatientSignByNameOrIdCard(String keyWord,String doctorId,int pageNo,int pageSize){
        Doctor doctor = doctorDao.findByCode(doctorId);
        String hospital = doctor.getHospital();
        int start = (pageNo-1)*pageSize;
        List<Map<String,Object>> patientList = new ArrayList<>();
        String sql = "SELECT p.code,p.name,CASE p.sex WHEN 1 THEN '男' WHEN 2 THEN '女' END sex,p.idcard,d.del,f.doctor_name" +
                " FROM wlyy_patient p  LEFT JOIN wlyy_sign_family f ON p.code = f.patient" +
                " LEFT JOIN wlyy_patient_device d ON p.code = d.user" +
                " WHERE f.status = 1 AND p.name LIKE '%"+keyWord+"%' OR p.idcard LIKE '%"+keyWord+"%' and f.hospital = '"+hospital+"'"+" limit ?,?";
        patientList = jdbcTemplate.queryForList(sql ,new Object[]{start,pageSize});
        for (Map<String,Object> map : patientList){
            map.put("age",IdCardUtil.getAgeForIdcard(String.valueOf(map.get("idcard"))));
        }
        return patientList;
    }
}

+ 87 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/device/PatientDeviceService.java

@ -31,6 +31,7 @@ import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.IdCardUtil;
import com.yihu.wlyy.util.MyJdbcTemplate;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -1153,4 +1154,90 @@ public class PatientDeviceService extends BaseService {
        result.put("list",list);
        return result;
    }
    public Map<String,Object> getDeviceByDeviceSn(String deviceSn)throws Exception {
        Map<String,Object> map  = new HashedMap();
        String sql = "SELECT d.id,d.device_name deviceName,d.device_model deviceMode,d.device_activity_type devityActivityType,e.is_multi_user isMultiUser,e.category_code as deviceType,e.multi_user multiUser FROM device.wlyy_devices d LEFT JOIN wlyy.dm_device e ON d.device_model = e.model WHERE d.device_code='"+deviceSn+"'";
        List<Map<String,Object>> mapSqlList = jdbcTemplate.queryForList(sql);
        if (mapSqlList!=null && mapSqlList.size()>0){
            map = mapSqlList.get(0);
        }
        List<PatientDevice> list = patientDeviceDao.findByDeviceSn(deviceSn);
        List<Map<String,Object>> mapList = new ArrayList<>();
        for (PatientDevice patientDevice : list) {
            Map<String,Object> infoMap = new HashedMap();
            Patient patient = patientDao.findByCode(patientDevice.getUser());
            infoMap.put("patientDeviceId",patientDevice.getId());
            infoMap.put("userCode",patient.getCode());
            infoMap.put("userName",patient.getName());
            infoMap.put("idCard",patient.getIdcard());
            infoMap.put("userType",patientDevice.getUserType());
            mapList.add(infoMap);
        }
        map.put("bindingInfo",mapList);
        return map;
    }
    public boolean isFirstNewBinding(String deviceSn,String patientId){
        boolean flag = true;
        List<PatientDevice> patientDeviceList = patientDeviceDao.findByPatientAndDeviceSn(patientId,deviceSn);
        if (patientDeviceList!=null && patientDeviceList.size()>0){
            flag = false;//已经有绑定记录,不是首绑
        }else {
            String sql = "SELECT device_activity_type as deviceActivityType FROM device.wlyy_devices WHERE device_code= "+deviceSn;
            Map<String,Object> map = jdbcTemplate.queryForMap(sql);
            if (map==null){
                flag = false;//获取不到设备信息
            }else {
                if (map.get("deviceActivityType")==null){
                    flag = false;//不是可以加积分的涉笔
                }
            }
        }
        return flag;
    }
    /**
     * 验证sn码 先调总部接口 未注册才查询本地数据库,如果也没有才不能绑定
     * @param deviceSn
     * @return
     * @throws Exception
     */
    public Map<String,Object> checkBindingDeviceSn(String deviceSn) throws Exception{
        Boolean flag = false;
        String message = "";
        Integer resultCode = 200;
        Map<String, String> params = new HashMap<>();
        params.put("deviceSn", deviceSn);
        //调用服务
        String response = HttpClientUtil.httpPost(url + registerDevice, HttpClientUtil.getSecretParams(params, appid, secret));
        System.out.println("注册设备=" + response);
        JSONObject json = new JSONObject(response);
        String code = json.get("Code").toString();
        //10000注册成功 10001已注册 -10000参数不通过(没传参数) -10001设备不存在 -10002设备未出库
        if ("10000".equals(code) || "10001".equals(code)) {
            flag = true;
        }else {
            String sql ="select * from device.wlyy_devices where device_code = '"+deviceSn+"'";
            Map<String,Object> map  = jdbcTemplate.queryForMap(sql);
            if (map!=null && map.size()>0){
                if (patientDeviceDao.findByDeviceSn(deviceSn)==null){
                    flag = true ;
                    message="设备可以绑定";
                }else {
                    resultCode = -10000;
                    message="已经被绑定了!";
                }
            }else {
                resultCode = -10001;
                message="没有该设备!";
            }
        }
        Map<String,Object> map = new HashedMap();
        map.put("code",resultCode);
        map.put("message",message);
        map.put("flag",flag);
        return map;
    }
}

+ 143 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statisticsES/StatisticsESService.java

@ -929,7 +929,9 @@ public class StatisticsESService {
            for (SaveModel saveModel : saveModels) {
                JSONObject json = new JSONObject();
                String range = null;
                range = df.format(saveModel.getQuotaDate());
                if(saveModel.getQuotaDate()!=null){
                    range = df.format(saveModel.getQuotaDate());
                }
                long amount = saveModel.getResult2().longValue();
                json.put("range", range);
                json.put("amount", amount);
@ -1066,7 +1068,10 @@ public class StatisticsESService {
        if (saveModels != null) {
            // 计算结果
            for (SaveModel saveModel : saveModels) {
                String range = df.format(saveModel.getQuotaDate());
                String range = "";
                if (saveModel.getQuotaDate()!=null){
                    range = df.format(saveModel.getQuotaDate());
                }
                JSONObject json = countResult.get(range);
                if (json != null) {
@ -1184,7 +1189,10 @@ public class StatisticsESService {
        if (saveModels != null) {
            // 计算结果
            for (SaveModel saveModel : saveModels) {
                String range = df.format(saveModel.getQuotaDate());
                String range = "";
                if (saveModel.getQuotaDate()!=null){
                    range = df.format(saveModel.getQuotaDate());
                }
                JSONObject json = countResult.get(range);
                if (json != null) {
@ -5138,4 +5146,136 @@ public class StatisticsESService {
        return saveModel.getResult2().longValue();
    }
    public Map<String,Object> getLevelDeviceAndBinding(String area, int level, int sort, String lowLevel, String year) throws Exception {
        String index_85 = "85";
        String index_86= "86";
        String lastDate = year + "-06-30";
        String timeKey = elasticsearchUtil.getQuotaTime();
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level + 1) : lowLevel);
        List<Map<String, Object>> resultList = new ArrayList<>();
        Map<String,Object> resultMap = new HashedMap();
        //发放量
        List<SaveModel> allAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_85, SaveModel.timeLevel_DDL, "", low_level);
        //绑定量
        List<SaveModel> bindingAmountList = elasticsearchUtil.findDateQuotaLevel0(timeKey, timeKey, area, level, index_86, SaveModel.timeLevel_DDL, "", low_level);
        Integer totalAllNum = allAmountList.get(0).getResult2().intValue();
        Integer totalBindingNum = bindingAmountList.get(0).getResult2().intValue();
        resultMap.put("totalAll",totalAllNum);
        resultMap.put("totalBinding",totalBindingNum);
        resultMap.put("totalRange",getRange(totalBindingNum, totalAllNum, 2));
        Map<String, Integer> allMap = new HashMap<>(); //发放量的的列表转map
        if (allAmountList != null && allAmountList.size() > 0) {
            for (SaveModel saveModel : allAmountList) {
                if ("3".equals(low_level) && saveModel.getTown() != null) {
                    allMap.put(saveModel.getTown(), saveModel.getResult2().intValue());
                } else if ("4".equals(low_level) && saveModel.getHospital() != null) {
                    allMap.put(saveModel.getHospital(), saveModel.getResult2().intValue());
                } else if ("5".equals(low_level) && saveModel.getTeam() != null) {
                    allMap.put(saveModel.getTeam(), saveModel.getResult2().intValue());
                } else {
                    continue;
                }
            }
        }
        //自建结果集
        resultList = getLowLevelMapKey(level, low_level, area);
        if (resultList != null && resultList.size() > 0) {
            Map<String, SaveModel> bingdingMap = new HashMap<>();
            DecimalFormat df = new DecimalFormat("0.0000");
            bindingAmountList.stream().forEach(one -> {
                if ("5".equals(low_level)) {
                    bingdingMap.put(one.getTeam(), one);
                } else if ("4".equals(low_level)) {
                    bingdingMap.put(one.getHospital(), one);
                } else if ("3".equals(low_level)) {
                    bingdingMap.put(one.getTown(), one);
                }
            });
            for (Map<String, Object> reMap : resultList) {
                reMap.put("amount", reMap.get("amount") != null ? Long.valueOf(reMap.get("amount").toString()) : 0L);
                int bindingAmount = 0;
                Integer allAmount = 0;
                //获取绑定数量
                if (bingdingMap != null && bingdingMap.size() > 0) {
                    SaveModel one = bingdingMap.get(reMap.get("code").toString());
                    if (one != null) {
                        bindingAmount = one.getResult2().intValue();
                    }
                }
                if (allMap != null && allMap.size() > 0) {
                    allAmount = allMap.get(reMap.get("code").toString());
                    if (allAmount == null) {
                        allAmount = 0;
                    }
                } else {
                }
                reMap.put("allNum", allAmount);
                reMap.put("bindingNum", bindingAmount);
                reMap.put("rate", getRange(bindingAmount, allAmount, 2));//续签率是 续签量/去年的签约数
            }
            if ((level == 2 && "5".equals(lowLevel)) || (level == 4) || (level == 3 && "5".equals(lowLevel))) {
                translateTeamLeaderName(resultList);
            }
            //对结果进行排序
            Collections.sort(resultList, new Comparator<Map<String, Object>>() {
                public int compare(Map<String, Object> o1, Map<String, Object> o2) {
                    int map1value = (int) o1.get("allNum");
                    int map2value = (int) o2.get("allNum");
                    if (map1value - map2value > 0) {
                        return sort == 1 ? -1 : 1;
                    } else if (map1value - map2value < 0) {
                        return sort == 1 ? 1 : -1;
                    } else {
                        return 0;
                    }
                }
            });
            resultMap.put("list",resultList);
            return resultMap;
        } else {
            return new HashedMap();
        }
    }
    /**
     * 查询签约
     *
     * @param type      0 按周,1 按月
     * @param startDate
     * @param endDate
     * @return
     */
    /*public JSONArray getDeviceLine(String doctor, String type, String startDate, String endDate) throws Exception {
        AdminTeam admin = adminTeamDao.findByLeaderCode(doctor);
        if (admin == null) {
            throw new RuntimeException("未找到团队信息");
        }
        Long id = admin.getId();
        List<SaveModel> allList = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, id + "", Integer.valueOf(SaveModel.teamLevel), "85", SaveModel.timeLevel_ZL, String.valueOf(Integer.valueOf(type) + 1));
        List<SaveModel> bindingList = elasticsearchUtil.findLineChartDateQuotaLevel0(startDate, endDate, id + "", Integer.valueOf(SaveModel.teamLevel), "86", SaveModel.timeLevel_ZL, String.valueOf(Integer.valueOf(type) + 1));
        List<Map<String, Object>> rs = new ArrayList<>();
        for (SaveModel saveModel : list) {
            Map<String, Object> map = new HashMap<>();
            //map.put("applyDate", dateFormat.format(saveModel.getQuotaDate()));
            if ("0".equals(type)) {
                map.put("applyDate", dateFormat.format(saveModel.getQuotaDate()));
            } else {
                map.put("weekOfMonth", DateUtil.getWeekOfMonth(saveModel.getQuotaDate()));
            }
            map.put("signCount", saveModel.getResult2().longValue());
            rs.add(map);
        }
        JSONArray rsJs = new JSONArray(rs);
        return rsJs;
    }*/
}

+ 45 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/device/DoctorDeviceController.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.web.doctor.device;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.aop.ObserverRequired;
import com.yihu.wlyy.entity.device.Device;
import com.yihu.wlyy.entity.device.PatientDevice;
import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
import com.yihu.wlyy.service.app.device.PatientDeviceService;
@ -10,15 +11,15 @@ import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@ -41,6 +42,8 @@ public class DoctorDeviceController extends BaseController {
	private ObjectMapper  objectMapper=new ObjectMapper();
	private JdbcTemplate jdbcTemplate;
	@ApiOperation("设备保存接口--医生端")
	@RequestMapping(value = "SavePatientDevice",method = RequestMethod.POST)
	@ResponseBody
@ -51,9 +54,14 @@ public class DoctorDeviceController extends BaseController {
			PatientDevice device = objectMapper.readValue(data,PatientDevice.class);
			// 设置操作医生标识
			device.setDoctor(getUID());
			//首绑加分判断
			boolean flag = patientDeviceService.isFirstNewBinding(device.getDeviceSn(),device.getUser());
			patientDeviceService.saveDevice(device);
			if (flag){
				//调用增加积分接口
			}
			return success("设备保存成功!");
		}
		catch (Exception ex) {
@ -227,4 +235,36 @@ public class DoctorDeviceController extends BaseController {
			JSONArray objects = patientDeviceService.getDeviceByDeviceSn(deviceSn,type);
			return write(200, "获取设备成功!", "data",objects);
	}
	@ApiOperation("根据sn码获取设备的信息和绑定信息")
	@RequestMapping(value = "/getDeviceInfoByDeviceSn",method = RequestMethod.GET)
	@ResponseBody
	public String getDeviceInfoByDeviceSn(@ApiParam(name="deviceSn",value="设备SN码",defaultValue = "15L000002")
														  @RequestParam(value="deviceSn",required = true) String deviceSn){
		//JSONArray objects = patientDeviceService.getDeviceByDeviceSn(deviceSn);
		try{
			return write(200, "获取设备成功!", "data",patientDeviceService.getDeviceByDeviceSn(deviceSn));
		}catch (Exception e){
			error(e);
			return write(-1,"程序出错!");
		}
	}
	@RequestMapping(value = "/checkIsBinding",method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "根据sn码查询设备是否已经绑定和存在",notes = "绑定设备前的判断")
	public String findDeviceAndBindingBySn(@ApiParam(name = "deviceSn", value = "", defaultValue = "") @RequestParam(value = "deviceSn")String deviceSn){
		if (org.springframework.util.StringUtils.isEmpty(deviceSn)){
			return write(-1,"参数格式错误!");
		}
		try{
			Map<String,Object> map = patientDeviceService.checkBindingDeviceSn(deviceSn);
			return  write(200,String.valueOf(map.get("message")),"data",(Boolean)map.get("flag"));
			//return  write(200,"123","data","111111");
		}catch (Exception e){
			e.printStackTrace();
			return  write(-1,"操作失败!");
		}
	}
}

+ 22 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/PatientInfoController.java

@ -23,6 +23,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -59,6 +60,8 @@ public class PatientInfoController extends BaseController {
    @Autowired
    private SendMessageService sendMessageService;
    private JdbcTemplate jdbcTemplatel;
    private static Logger logger = LoggerFactory.getLogger(PatientInfoController.class);
    /**
@ -514,5 +517,24 @@ public class PatientInfoController extends BaseController {
        }
    }
    @RequestMapping(value = "/getPatientSignByNameOrIdCard",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation("在绑定设备的时候查找患者(带签约信息)")
    public String getPatientSignByNameOrIdCard(@ApiParam(value = "关键搜索词", name = "keyWord") @RequestParam(value = "keyWord",required = true)String keyWord,
                                                @ApiParam(name="page",value="第几页",defaultValue = "1") @RequestParam(value="page",required = true) String page,
                                                @ApiParam(name="pageSize",value="",defaultValue = "10") @RequestParam(value="pageSize",required = true) String pageSize){
        if (StringUtils.isBlank(pageSize)) {
            pageSize = "10";
        }
        if (page.equals("0")){
            page = "1";
        }
        try {
            return  write(200,"查找成功!","data",patientInfoService.getPatientSignByNameOrIdCard(keyWord,getUID(),Integer.valueOf(page),Integer.valueOf(pageSize)));
        } catch (Exception e) {
            error(e);
            return error( -1, "查询失败!");
        }
    }
}

+ 48 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/statistic/EsStatisticsController.java

@ -2165,4 +2165,52 @@ public class EsStatisticsController extends BaseController {
            return error(-1, "查询失败");
        }
    }
    @RequestMapping("/lowlevel_device")
    @ApiOperation("设备绑定统计")
    @ResponseBody
    public String lowlevel_device(
            @RequestParam(required = true) String area,
            @RequestParam(required = true) int level,
            @RequestParam(required = true) int sort,
            @RequestParam(required = false) String lowLevel,
            @RequestParam(required = false) String year) {
        try {
            //如果年度是空,按当前时间计算是年度是属于那个年度
            if (org.springframework.util.StringUtils.isEmpty(year)) {
                year = Constant.getNowYear();
            }
            //lowLevel不传默认是 level-1
            if (org.springframework.util.StringUtils.isEmpty(lowLevel)) {
                lowLevel = level - 1 + "";
            }
            return write(200, "查询成功", "data", statisticsESService.getLevelDeviceAndBinding(area, elasticsearchUtil.changeLevel(level), sort, String.valueOf(elasticsearchUtil.changeLevel(Integer.valueOf(lowLevel))), year));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
    /**
     * 获取绑定和发放量的折线图
     *
     * @param startDate
     * @param endDate
     * @param type      0 按周,1 按月
     * @return
     *//*
    @RequestMapping("/getDeviceLine")
    @ResponseBody
    public String getDeviceLine(@RequestParam(required = true) String startDate,
                                 @RequestParam(required = true) String endDate,
                                 @RequestParam(required = true) String type) {
        try {
            return write(200, "查询成功", "data", statisticsESService.getSignCountLineByType(getUID(), type, startDate, endDate));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }*/
}