suqinyi 1 year ago
parent
commit
c722c06731

+ 28 - 0
business/base-service/src/main/java/com/yihu/jw/device/dao/HmTokenDao.java

@ -0,0 +1,28 @@
package com.yihu.jw.device.dao;
import com.yihu.jw.entity.care.device.HmToken;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/***
 * @ClassName: HmTokenDao
 * @Description:
 * @Auther: shi kejing
 * @Date: 2021/4/14 18:57
 */
public interface HmTokenDao extends PagingAndSortingRepository<HmToken, Long>, JpaSpecificationExecutor<HmToken> {
    @Query("select accessToken from HmToken where patient = ?1")
    String selectToken(String patient);
    @Query(value = "select t.* from hm_token t where t.patient = ?1 order by t.id desc limit 1",nativeQuery = true)
    HmToken selectT(String patient);
    @Query("select a from HmToken a where a.accessToken is null")
    List<HmToken> findAllList();
}

+ 12 - 4
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/Device.java

@ -3,10 +3,7 @@ package com.yihu.jw.entity.care.device;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.iot.gateway.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.*;
import java.util.Date;
/**
@ -30,6 +27,8 @@ public class Device extends IdEntity {
	private String needRegister;//设备是否注册iot(脉搏波血压计)
	private Integer deviceType;//0健康设备 1安防设备
	private String authorizationTime;//华米手表授权到期时间
	@Column(name="category_code")
	public String getCategoryCode() {
		return categoryCode;
@ -138,4 +137,13 @@ public class Device extends IdEntity {
	public void setDeviceType(Integer deviceType) {
		this.deviceType = deviceType;
	}
	@Transient
	public String getAuthorizationTime() {
		return authorizationTime;
	}
	public void setAuthorizationTime(String authorizationTime) {
		this.authorizationTime = authorizationTime;
	}
}

+ 120 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/HmToken.java

@ -0,0 +1,120 @@
package com.yihu.jw.entity.care.device;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/***
 * @ClassName: HmToken
 * @Description:
 * @Auther: shi kejing
 * @Date: 2021/4/14 18:50
 */
@Entity
@Table(name = "hm_token")
public class HmToken extends IdEntity {
    private String patient;
    private String accessToken;
    private String refreshToken;
    private String tokenType;
    private String expiresIn;
    private String createTime;
    private String userId;
    //状态1同步中,0空闲
    private String gender;
    private String nickName;
    //上一次同步时间
    private String avatar;
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    public String getAccessToken() {
        return accessToken;
    }
    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }
    public String getTokenType() {
        return tokenType;
    }
    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }
    public String getExpiresIn() {
        return expiresIn;
    }
    public void setExpiresIn(String expiresIn) {
        this.expiresIn = expiresIn;
    }
    public String getCreateTime() {
        return createTime;
    }
    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public String getNickName() {
        return nickName;
    }
    public void setNickName(String nickName) {
        this.nickName = nickName;
    }
    public String getAvatar() {
        return avatar;
    }
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }
    public String getRefreshToken() {
        return refreshToken;
    }
    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }
}

+ 18 - 0
common/common-util/src/main/java/com/yihu/jw/util/date/DateUtil.java

@ -1651,4 +1651,22 @@ public class DateUtil {
        }
        return list;
    }
    /**
     * 日期加
     * @param strDate
     * @param type 1秒
     * @param add
     * @return
     */
    public static String dateAddByType(String strDate,String type,long add){
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.parse(strDate, formatter);
        // 在当前时间上添加秒数
        LocalDateTime newTime = null;
        if("1".equals(type)){
            newTime = localDateTime.plusSeconds(add);
        }
        return newTime.format(formatter);
    }
}

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

@ -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());
        }
    }
}