|
@ -2,12 +2,18 @@ package com.yihu.wlyy.web.patient.device;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.wlyy.entity.device.PatientDevice;
|
|
|
import com.yihu.wlyy.entity.device.PatientHealthTime;
|
|
|
import com.yihu.wlyy.repository.deviece.PatientHealthTimeDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDeviceDao;
|
|
|
import com.yihu.wlyy.service.app.device.PatientDeviceService;
|
|
|
import com.yihu.wlyy.util.HttpClientUtil;
|
|
|
import com.yihu.wlyy.util.SystemConf;
|
|
|
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.lang3.StringUtils;
|
|
|
import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@ -33,6 +39,15 @@ public class PatientDeviceController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
|
private PatientDeviceService patientDeviceService;
|
|
|
@Autowired
|
|
|
private PatientHealthTimeDao patientHealthTimeDao;
|
|
|
@Autowired
|
|
|
private PatientDeviceDao patientDeviceDao;
|
|
|
|
|
|
private String url = SystemConf.getInstance().getYihuOpenPlatformUrl();
|
|
|
private String appid = SystemConf.getInstance().getYihuOpenPlatformAppId();
|
|
|
private String secret = SystemConf.getInstance().getYihuOpenPlatformSecret();
|
|
|
private String registerDevice = "DeviceGateway/DeviceApi/registerDevice";//注册设备
|
|
|
|
|
|
private ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
@ -63,23 +78,62 @@ public class PatientDeviceController extends BaseController {
|
|
|
@RequestParam(required = false) String beforeDinnerEnd,
|
|
|
@RequestParam(required = false) String afterDinnerStart,
|
|
|
@RequestParam(required = false) String afterDinnerEnd,
|
|
|
@RequestParam(required = false)String beforeSleepStart,
|
|
|
@RequestParam(required = false)String beforeSleepEnd,
|
|
|
@RequestParam String deviceSN) {
|
|
|
@RequestParam(required = false) String beforeSleepStart,
|
|
|
@RequestParam(required = false) String beforeSleepEnd,
|
|
|
@RequestParam String deviceSN,
|
|
|
@RequestParam(required = false) String newDeviceSN) {
|
|
|
|
|
|
try {
|
|
|
String user = getUID();
|
|
|
patientDeviceService.setBloodTime(user,deviceSN,fastingStart,fastingEnd,afterBreakfastStart,afterBreakfastEnd,beforeLunchStart,beforeLunchEnd,
|
|
|
afterLunchStart,afterLunchEnd,beforeDinnerStart,beforeDinnerEnd,afterDinnerStart,afterDinnerEnd,beforeSleepStart,beforeSleepEnd);
|
|
|
return write(200,"设置成功!");
|
|
|
|
|
|
if (StringUtils.isNotEmpty(newDeviceSN)) {
|
|
|
// 校验新的sn码 1.是否被占用 2.是否是真的设备码
|
|
|
PatientDevice device = patientDeviceDao.findByDeviceSnAndUserType(newDeviceSN, "-1");
|
|
|
if (device != null) {
|
|
|
throw new Exception("sn码" + newDeviceSN + "已被使用!");
|
|
|
}
|
|
|
|
|
|
//注册设备
|
|
|
Map<String, String> params = new HashMap<>();
|
|
|
params.put("deviceSn", newDeviceSN);
|
|
|
|
|
|
//调用服务
|
|
|
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)) {
|
|
|
// 先修改患者设备绑定表
|
|
|
int rows = patientDeviceService.updatePatientDevice(user,deviceSN,newDeviceSN);
|
|
|
if (rows != 0){
|
|
|
// 只更换设备编码,不更改时间值
|
|
|
// 1.先查询是否自定义时间段,没有则新增,有则修改
|
|
|
PatientHealthTime healthTime = patientHealthTimeDao.findByUserAndSN(user, deviceSN);
|
|
|
if (healthTime == null){
|
|
|
patientDeviceService.setBloodTime(user, newDeviceSN, "null", "null", "null", "null", "null", "null",
|
|
|
"null", "null", "null", "null", "null", "null", "null", "null");
|
|
|
}else {
|
|
|
patientDeviceService.updateDeviceSN(user, deviceSN, newDeviceSN);
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
String message = json.get("Message").toString();
|
|
|
throw new Exception(message);
|
|
|
}
|
|
|
return write(200, "更改sv码成功!");
|
|
|
}
|
|
|
patientDeviceService.setBloodTime(user, deviceSN, fastingStart, fastingEnd, afterBreakfastStart, afterBreakfastEnd, beforeLunchStart, beforeLunchEnd,
|
|
|
afterLunchStart, afterLunchEnd, beforeDinnerStart, beforeDinnerEnd, afterDinnerStart, afterDinnerEnd, beforeSleepStart, beforeSleepEnd);
|
|
|
return write(200, "设置成功!");
|
|
|
} catch (Exception e) {
|
|
|
error(e);
|
|
|
return invalidUserException(e,-1,"设置失败!");
|
|
|
return invalidUserException(e, -1, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设备保存接口 ---要增加血糖时间段保存
|
|
|
* 设备保存接口 ---增加血糖时间段保存 Reece v1.3.3
|
|
|
*/
|
|
|
@ApiOperation("设备保存接口")
|
|
|
@RequestMapping(value = "SavePatientDevice", method = RequestMethod.POST)
|
|
@ -131,9 +185,9 @@ public class PatientDeviceController extends BaseController {
|
|
|
PatientDevice device = patientDeviceService.findById(id);
|
|
|
String deviceSN = device.getDeviceSn();
|
|
|
String user = device.getUser();
|
|
|
Map map = patientDeviceService.getBloodSuggerTime(user,deviceSN);
|
|
|
mapList.put("time",map);
|
|
|
mapList.put("device",device);
|
|
|
Map map = patientDeviceService.getBloodSuggerTime(user, deviceSN);
|
|
|
mapList.put("time", map);
|
|
|
mapList.put("device", device);
|
|
|
return write(200, "查询成功", "data", mapList);
|
|
|
} catch (Exception ex) {
|
|
|
return invalidUserException(ex, -1, ex.getMessage());
|