yeshijie 7 лет назад
Родитель
Сommit
5d3040133c

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

@ -44,4 +44,7 @@ public interface PatientDeviceDao extends PagingAndSortingRepository<PatientDevi
            "from PatientDevice a,Patient p where a.userIdcard=p.idcard")
    List<PatientDevice> findWithArrdess();
    @Query("select a from PatientDevice a")
    List<PatientDevice> findAll();
}

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

@ -24,6 +24,7 @@ import com.yihu.wlyy.repository.patient.*;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.health.PatientHealthIndexService;
import com.yihu.wlyy.service.app.team.AdminTeamService;
import com.yihu.wlyy.service.third.iot.IotDeviceService;
import com.yihu.wlyy.service.third.jw.JwSmjkService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
@ -103,6 +104,8 @@ public class PatientDeviceService extends BaseService {
    @Autowired
    private PatientEventDao patientEventDao;
    @Autowired
    private IotDeviceService iotDeviceService;
    @Autowired
    private Icd10DictDao icd10DictDao;
    Map<Integer, String> relations = new HashMap<>();
@ -152,42 +155,41 @@ public class PatientDeviceService extends BaseService {
     * 保存患者设备
     */
    public boolean saveDevice(PatientDevice patientDevice) throws Exception {
        synchronized (patientDevice.getDeviceSn()) {
            //判断sn码是否被使用
            String sn = patientDevice.getDeviceSn();
            String type = patientDevice.getCategoryCode();
            Long deviceId = patientDevice.getDeviceId();
            String userType = patientDevice.getUserType();
            if (userType == null) {
                userType = "-1";
                patientDevice.setUserType("-1");
            }
        //判断sn码是否被使用
        String sn = patientDevice.getDeviceSn();
        String type = patientDevice.getCategoryCode();
        Long deviceId = patientDevice.getDeviceId();
        String userType = patientDevice.getUserType();
        if (userType == null) {
            userType = "-1";
            patientDevice.setUserType("-1");
        }
            boolean needVerify = true;
            //修改操作
            if (patientDevice.getId() != null) {
                PatientDevice deviceOld = patientDeviceDao.findOne(patientDevice.getId());
                if (deviceOld != null) {
                    if (deviceOld.getDeviceSn().equals(sn)) {
                        needVerify = false;
                    }
                } else {
                    throw new Exception("不存在该条记录!");
        boolean needVerify = true;
        //修改操作
        if (patientDevice.getId() != null) {
            PatientDevice deviceOld = patientDeviceDao.findOne(patientDevice.getId());
            if (deviceOld != null) {
                if (deviceOld.getDeviceSn().equals(sn)) {
                    needVerify = false;
                }
            } else {
                throw new Exception("不存在该条记录!");
            }
        }
            //校验sn码是否被使用
            if (needVerify) {
        //校验sn码是否被使用
        if (needVerify) {
//				PatientDevice device = patientDeviceDao.findByDeviceIdAndDeviceSnAndUserType(deviceId, sn, userType);
                PatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(sn, userType);
                if (device != null && !device.getId().equals(patientDevice.getId())) {
                    throw new Exception("sn码" + sn + "已被使用!");
                }
            PatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(sn, userType);
            if (device != null && !device.getId().equals(patientDevice.getId())) {
                throw new Exception("sn码" + sn + "已被使用!");
            }
            patientDevice.setCzrq(clock.getCurrentDate());
            //当前用户的身份证
            Patient patient = patientDao.findByCode(patientDevice.getUser());
            patientDevice.setUserIdcard(patient.getIdcard());
        }
        patientDevice.setCzrq(clock.getCurrentDate());
        //当前用户的身份证
        Patient patient = patientDao.findByCode(patientDevice.getUser());
        patientDevice.setUserIdcard(patient.getIdcard());
//            //注册设备
//            Map<String, String> params = new HashMap<>();
@ -205,15 +207,28 @@ public class PatientDeviceService extends BaseService {
//                String message = json.get("Message").toString();
//                throw new Exception(message);
//            }
            if(checkDeviceSn(sn)){
                patientDeviceDao.save(patientDevice);
            }else {
                String message = "设备不存在";
                throw new Exception(message);
            }
        if(checkDeviceSn(sn)){
//            patientDeviceDao.save(patientDevice);
            savePatientDevice(patientDevice,patient.getAddress(),patient.getName());
        }else {
            String message = "设备不存在";
            throw new Exception(message);
        }
        return true;
    }
            return true;
    /**
     * 设备绑定
     * @param patientDevice
     */
    public void savePatientDevice(PatientDevice patientDevice,String address,String patientName){
        if(iotDeviceService.isUploadIot()){
            iotDeviceService.saveDevice(patientDevice,address,patientName);
        }else {
            patientDeviceDao.save(patientDevice);
        }
    }
    /**
@ -727,6 +742,9 @@ public class PatientDeviceService extends BaseService {
        sql.append("WHERE m.type = 2  ORDER BY m.id desc LIMIT ?,?");
        List<com.alibaba.fastjson.JSONObject> list = myJdbcTemplate.queryJson(sql.toString(),new Object[]{(page-1)*pageSize,pageSize});
        list.forEach(json->{
            json.put("value2Name",getTypeName(json.getString("tz_type"),json.getString("value2")));
        });
        return list;
    }
@ -986,4 +1004,43 @@ public class PatientDeviceService extends BaseService {
        });
        return mapList;
    }
    /**
     * 名字转换
     * @param type
     * @param value
     * @return
     */
    private String getTypeName(String type,String value){
        String name = "";
        //1早餐前、2早餐后、3午餐前、4午餐后、5晚餐前 6晚餐后 7睡前)
        if ("1".equals(type)){
            switch (value){
                case "1":
                    name = "早餐前";
                    break;
                case "2":
                    name = "早餐后";
                    break;
                case "3":
                    name = "午餐前";
                    break;
                case "4":
                    name = "午餐后";
                    break;
                case "5":
                    name = "晚餐前";
                    break;
                case "6":
                    name = "晚餐后";
                    break;
                default:
                    name = "睡前";
                    break;
            }
        }else {
            name = "舒张压";
        }
        return name;
    }
}

+ 44 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/iot/IotDeviceService.java

@ -148,6 +148,34 @@ public class IotDeviceService {
        return response;
    }
    /**
     * 设备绑定
     * @param patientDevice
     * @param address
     * @return
     */
    public String saveDevice(PatientDevice patientDevice,String address,String name){
        JSONObject json = new JSONObject();
        json.put("categoryCode",patientDevice.getCategoryCode());
        json.put("address",address);
        json.put("patient",patientDevice.getUser());
        json.put("patientName",name);
        json.put("idcard",patientDevice.getUserIdcard());
        json.put("deviceId",patientDevice.getDeviceId());
        json.put("deviceName",patientDevice.getDeviceName());
        json.put("deviceSn",patientDevice.getDeviceSn());
        json.put("userType",patientDevice.getUserType());
        json.put("sim",patientDevice.getSim());
        json.put("agent",patientDevice.getAgent());
        json.put("doctor",patientDevice.getDoctor());
        String url = baseUrl+"/patientDevice/addPatientDevice";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("jsonData",json.toString()));
        String response = httpClientUtil.post(url, params, "UTF-8");
        return response;
    }
    /**
     * 数据上传
     * @param json
@ -368,6 +396,22 @@ public class IotDeviceService {
        return response;
    }
    /**
     * 初始化设备绑定数据
     * @return
     */
    public void initPatientDevice(){
        List<PatientDevice> list = patientDeviceDao.findAll();
        list.forEach(patientDevice -> {
            Patient patient = patientDao.findByCode(patientDevice.getUser());
            String response = saveDevice(patientDevice,patient.getAddress(),patient.getName());
            JSONObject re = JSONObject.parseObject(response);
            if(re.getInteger("status")!=200){
                logger.error("id:"+patientDevice.getId()+" "+re.getString("errorMsg"));
            }
        });
    }
    /**
     * 初始化迁移数据
     * @return

+ 12 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/iot/IotDeviceController.java

@ -100,6 +100,18 @@ public class IotDeviceController extends BaseController{
        }
    }
    @RequestMapping(value = "/initPatientDevice",method = RequestMethod.POST)
    @ApiOperation("初始化迁移设备绑定数据")
    public String initPatientDevice(){
        try {
            iotDeviceService.initPatientDevice();
            return success("初始化成功");
        }catch (Exception e){
            error(e);
            return error(-1,e.getMessage());
        }
    }
    @RequestMapping(value = "/findById",method = RequestMethod.GET)
    @ApiOperation("按id查询")
    public String findById(@ApiParam(name = "id",value = "id",defaultValue = "LggM5iaSi6u18TUmeDoaeSnyFxntPMA2NPGXBRyPTwFsg+oRn3bHgg==")