|
@ -0,0 +1,82 @@
|
|
|
|
package com.yihu.jw.hospital.module.health.controller;
|
|
|
|
|
|
|
|
import com.yihu.jw.device.dao.HmTokenDao;
|
|
|
|
import com.yihu.jw.entity.care.device.Device;
|
|
|
|
import com.yihu.jw.entity.care.device.DeviceCategory;
|
|
|
|
import com.yihu.jw.entity.care.device.HmToken;
|
|
|
|
import com.yihu.jw.hospital.module.common.BaseController;
|
|
|
|
import com.yihu.jw.hospital.module.health.service.DeviceService;
|
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
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.RestController;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping(value = "/common/device", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
|
|
@Api(description = "设备管理")
|
|
|
|
public class DeviceController extends BaseController {
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private DeviceService deviceService;
|
|
|
|
@Autowired
|
|
|
|
private HmTokenDao hmTokenDao;
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("获取设备分类")
|
|
|
|
@RequestMapping(value = "DeviceCategory", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
public String getDeviceCategory() {
|
|
|
|
try {
|
|
|
|
List<DeviceCategory> list = deviceService.findAllCategory();
|
|
|
|
return write(200, "获取设备分类成功!", "data", list);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
return invalidUserException(ex, -1, "获取设备分类失败!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("获取设备列表")
|
|
|
|
@RequestMapping(value = "DeviceList", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
public String getDeviceList(@ApiParam(name = "category_code", value = "设备类型代码", defaultValue = "1")
|
|
|
|
@RequestParam(value = "category_code", required = true) String categoryCode) {
|
|
|
|
try {
|
|
|
|
List<Device> list = deviceService.findDeviceByCategory(categoryCode);
|
|
|
|
if("4".equals(categoryCode)){
|
|
|
|
List<Device> list2 = deviceService.findDeviceByCategory("11");
|
|
|
|
list.addAll(list2);
|
|
|
|
}
|
|
|
|
return write(200, "获取设备列表成功!", "data", list);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
return invalidUserException(ex, -1, "获取设备列表失败!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("获取设备信息")
|
|
|
|
@RequestMapping(value = "DeviceInfo", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
public String getDeviceInfo(@ApiParam(name = "id", value = "设备ID", defaultValue = "19")
|
|
|
|
@RequestParam(value = "id", required = true) String id) {
|
|
|
|
try {
|
|
|
|
Device device = deviceService.findById(id);
|
|
|
|
if(device!=null&&"11".equals(device.getCategoryCode())){
|
|
|
|
//华米手表返回 授权到期时间
|
|
|
|
HmToken hmToken = hmTokenDao.selectT(getRepUID());
|
|
|
|
String authorizationTime = null;
|
|
|
|
if(hmToken!=null&& StringUtils.isNotBlank(hmToken.getExpiresIn())){
|
|
|
|
authorizationTime = DateUtil.dateAddByType(hmToken.getCreateTime(),"1",Long.parseLong(hmToken.getExpiresIn()));
|
|
|
|
device.setAuthorizationTime(authorizationTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return write(200, "查询成功", "data", device);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
return invalidUserException(ex, -1, ex.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|