Przeglądaj źródła

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

wangzhinan 3 lat temu
rodzic
commit
0a3cedb96c

+ 0 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -3503,7 +3503,6 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        if (StringUtils.isNotBlank(nameKey)) {
        if (StringUtils.isNotBlank(nameKey)) {
            sql += " AND e.name like '%" + nameKey + "%' ";
            sql += " AND e.name like '%" + nameKey + "%' ";
        }
        }
        if (StringUtils.isNotBlank(patientName)) {
        if (StringUtils.isNotBlank(patientName)) {
            sql += " AND o.patient_name like '%" + patientName + "%' ";
            sql += " AND o.patient_name like '%" + patientName + "%' ";
        }
        }

+ 19 - 0
common/common-entity/sql记录

@ -1565,4 +1565,23 @@ CREATE TABLE `base_child_activity_registration` (
  PRIMARY KEY (`id`)
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='幼儿活动报名表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='幼儿活动报名表';
-- 2021-10-20
CREATE TABLE `ys_device` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `device_sn` varchar(50) DEFAULT NULL,
  `config_id` tinyint(2) DEFAULT NULL COMMENT '配置编号',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8mb4;
CREATE TABLE `dm_ys_config` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
  `config_id` tinyint(2) DEFAULT NULL COMMENT '配置编号',
  `app_key` varchar(50) DEFAULT NULL,
  `app_secret` varchar(50) DEFAULT NULL,
  `msg_data_key` varchar(50) DEFAULT NULL COMMENT '推送消息解密密钥',
  `access_token_key` varchar(25) DEFAULT NULL COMMENT 'token Key',
  `iot_access_token_key` varchar(25) DEFAULT NULL COMMENT 'iot token Key',
  `secret_key` varchar(25) DEFAULT NULL COMMENT '设备的解密秘钥 key',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=46 DEFAULT CHARSET=utf8mb4;

+ 78 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/YsConfigDo.java

@ -0,0 +1,78 @@
package com.yihu.jw.entity.care.device;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Bing on 2021/10/20.
 */
@Entity
@Table(name = "dm_ys_config")
public class YsConfigDo extends IdEntity {
    private Integer configId; //配置编号
    private String appKey;
    private String appSecret;
    private String msgDataKey; //推送消息解密密钥
    private String accessTokenKey; //token Key
    private String iotAccessTokenKey; //iot token Key
    private String secretKey; //设备的解密秘钥 key
    public Integer getConfigId() {
        return configId;
    }
    public void setConfigId(Integer configId) {
        this.configId = configId;
    }
    public String getAppKey() {
        return appKey;
    }
    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }
    public String getAppSecret() {
        return appSecret;
    }
    public void setAppSecret(String appSecret) {
        this.appSecret = appSecret;
    }
    public String getMsgDataKey() {
        return msgDataKey;
    }
    public void setMsgDataKey(String msgDataKey) {
        this.msgDataKey = msgDataKey;
    }
    public String getAccessTokenKey() {
        return accessTokenKey;
    }
    public void setAccessTokenKey(String accessTokenKey) {
        this.accessTokenKey = accessTokenKey;
    }
    public String getIotAccessTokenKey() {
        return iotAccessTokenKey;
    }
    public void setIotAccessTokenKey(String iotAccessTokenKey) {
        this.iotAccessTokenKey = iotAccessTokenKey;
    }
    public String getSecretKey() {
        return secretKey;
    }
    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }
}

+ 34 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/care/device/YsDeviceDo.java

@ -0,0 +1,34 @@
package com.yihu.jw.entity.care.device;
import com.yihu.jw.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * Created by Bing on 2021/10/20.
 */
@Entity
@Table(name = "ys_device")
public class YsDeviceDo extends IdEntity {
    private String deviceSn;
    private Integer configId; //配置编号
    public String getDeviceSn() {
        return deviceSn;
    }
    public void setDeviceSn(String deviceSn) {
        this.deviceSn = deviceSn;
    }
    public Integer getConfigId() {
        return configId;
    }
    public void setConfigId(Integer configId) {
        this.configId = configId;
    }
}

+ 6 - 3
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/emergency/EmergencyOrderVO.java

@ -1,6 +1,8 @@
package com.yihu.jw.restmodel.emergency;
package com.yihu.jw.restmodel.emergency;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
import com.yihu.jw.entity.care.contacts.PatientSosContactsDO;
import com.yihu.jw.entity.care.securitymonitoring.BaseEmergencyWarnLogDO;
import com.yihu.jw.entity.care.securitymonitoring.BaseEmergencyWarnLogDO;
import com.yihu.jw.entity.care.securitymonitoring.EmergencyWarnConclusionDO;
import com.yihu.jw.entity.care.securitymonitoring.EmergencyWarnConclusionDO;
@ -54,7 +56,7 @@ public class EmergencyOrderVO {
    private List<PatientSosContactsDO> sosContacts;//紧急联系人
    private List<PatientSosContactsDO> sosContacts;//紧急联系人
    private List<Map<String,Object>> securityDevices;//安防设备列表
    private List<Map<String,Object>> securityDevices;//安防设备列表
    private String overTimeNotResponse;
    private String overTimeNotResponse;
    private Integer orderType;//20紧急 22安防
    private Integer OrderType;//20紧急 22安防
    public String getId() {
    public String getId() {
        return id;
        return id;
@ -296,11 +298,12 @@ public class EmergencyOrderVO {
        this.overTimeNotResponse = overTimeNotResponse;
        this.overTimeNotResponse = overTimeNotResponse;
    }
    }
    @JSONField(name = "OrderType")
    public Integer getOrderType() {
    public Integer getOrderType() {
        return orderType;
        return OrderType;
    }
    }
    public void setOrderType(Integer orderType) {
    public void setOrderType(Integer orderType) {
        this.orderType = orderType;
        OrderType = orderType;
    }
    }
}
}

+ 16 - 7
svr/svr-base/src/main/java/com/yihu/jw/base/config/YsConfig.java

@ -1,15 +1,22 @@
package com.yihu.jw.base.config;
package com.yihu.jw.base.config;
import com.yihu.jw.base.dao.device.YsConfigDao;
import com.yihu.jw.entity.care.device.YsConfigDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
/**
 * Created by Bing on 2021/6/1.
 * Created by Bing on 2021/6/1.
 * 萤石摄像头配置
 * 萤石摄像头配置
 */
 */
@Component
public class YsConfig {
public class YsConfig {
    @Autowired
    private YsConfigDao ysConfigDao;
    //文档地址 https://www.yuque.com/u1400669/kb/lmfp6u
    //文档地址 https://www.yuque.com/u1400669/kb/lmfp6u
    public static final String AppKey="43e44c2071114743925eda34088045f8";
    public static final String Secret="82051725cf0547208f8bc8ae2bff1323";
    public static final String baseUrl = "https://esopen.ys7.com";
    public static final String baseUrl = "https://esopen.ys7.com";
@ -69,10 +76,12 @@ public class YsConfig {
    //录像详情
    //录像详情
    public static final String videoDetail = baseUrl +"/seastart/vod/get";
    public static final String videoDetail = baseUrl +"/seastart/vod/get";
    public static final String redisKey = "ysAssesToken";
    public static final String iotRedisKey = "iotYsAssesToken";
    public static final String secretKey = "secretKey"; //设备的解密秘钥  通过iotAssesToken接口获取的
    public static final String msgDataKey = "HZADP68PNSNVZ4UW"; //消息解密密钥
    public YsConfigDo getConfig(String deviceSn){
        YsConfigDo configDo = ysConfigDao.getYsConfigByDeviceSn(deviceSn);
        if (null==configDo){
            configDo = ysConfigDao.getDefaultConfig(1);
        }
        return configDo;
    }
}
}

+ 18 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/device/YsConfigDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.base.dao.device;
import com.yihu.jw.entity.care.device.YsConfigDo;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Bing on 2021/10/20.
 */
public interface YsConfigDao extends PagingAndSortingRepository<YsConfigDo,Long>, JpaSpecificationExecutor<YsConfigDo> {
    @Query("select c from YsConfigDo c,YsDeviceDo de where c.configId = de.configId and de.deviceSn = ?1")
    YsConfigDo getYsConfigByDeviceSn(String deviceSn);
    @Query("select c from YsConfigDo c where c.configId=?1")
    YsConfigDo getDefaultConfig(Integer configId);
}

+ 36 - 21
svr/svr-base/src/main/java/com/yihu/jw/base/service/device/YsDeviceService.java

@ -2,6 +2,8 @@ package com.yihu.jw.base.service.device;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.base.config.YsConfig;
import com.yihu.jw.base.config.YsConfig;
import com.yihu.jw.base.dao.device.YsConfigDao;
import com.yihu.jw.entity.care.device.YsConfigDo;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.util.http.HttpClientUtil;
import com.yihu.jw.utils.encode.Base64;
import com.yihu.jw.utils.encode.Base64;
import org.slf4j.Logger;
import org.slf4j.Logger;
@ -10,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpMethod;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.LinkedMultiValueMap;
@ -32,25 +35,33 @@ public class YsDeviceService {
    private StringRedisTemplate redisTemplate;
    private StringRedisTemplate redisTemplate;
    @Autowired
    @Autowired
    private HttpClientUtil httpClientUtil;
    private HttpClientUtil httpClientUtil;
    @Autowired
    private YsConfig ysConfig;
    @Autowired
    private YsConfigDao ysConfigDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
    /**
     * 获取萤石设备assesToken
     * 获取萤石设备assesToken
     */
     */
    public String getAccessToken() throws Exception {
        if(redisTemplate.hasKey(YsConfig.redisKey)){
            return redisTemplate.opsForValue().get(YsConfig.redisKey);
    public String getAccessToken(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getAccessTokenKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getAccessTokenKey());
        }
        }
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("appKey",YsConfig.AppKey);
        param.put("appSecret",YsConfig.Secret);
        param.put("appKey",YSCONFIGDO.getAppKey());
        param.put("appSecret",YSCONFIGDO.getAppSecret());
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.saasAssesToken,param, HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.saasAssesToken,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        JSONObject responseBody = response.getBody();
        String assToken = null;
        String assToken = null;
        if (responseBody.getInteger("code")==200){
        if (responseBody.getInteger("code")==200){
            assToken = responseBody.getJSONObject("data").getString("accessToken");
            assToken = responseBody.getJSONObject("data").getString("accessToken");
            Long expireTime = responseBody.getJSONObject("data").getLong("expiresIn");//token有效期
            Long expireTime = responseBody.getJSONObject("data").getLong("expiresIn");//token有效期
            redisTemplate.opsForValue().set(YsConfig.redisKey,assToken,expireTime, TimeUnit.SECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getAccessTokenKey(),assToken,expireTime, TimeUnit.SECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.redisKey);
//            Long ss= redisTemplate.getExpire(YsConfig.redisKey);
//            System.out.println(expireTime+"---"+ss);
//            System.out.println(expireTime+"---"+ss);
@ -66,13 +77,15 @@ public class YsDeviceService {
     * @return
     * @return
     * @throws Exception
     * @throws Exception
     */
     */
    public String getIotAccessToken() throws Exception {
        if(redisTemplate.hasKey(YsConfig.iotRedisKey)){
            return redisTemplate.opsForValue().get(YsConfig.iotRedisKey);
    public String getIotAccessToken(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getIotAccessTokenKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getIotAccessTokenKey());
        }
        }
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("accessToken",getAccessToken());
        param.put("accessToken",getAccessToken(deviceSn));
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        JSONObject responseBody = response.getBody();
        String assToken = null;
        String assToken = null;
@ -82,10 +95,10 @@ public class YsDeviceService {
            Long nowTime = System.currentTimeMillis();
            Long nowTime = System.currentTimeMillis();
            expireTime = expireTime-nowTime;
            expireTime = expireTime-nowTime;
            redisTemplate.opsForValue().set(YsConfig.iotRedisKey,assToken,expireTime, TimeUnit.MILLISECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getIotAccessTokenKey(),assToken,expireTime, TimeUnit.MILLISECONDS);
            //设备解密密钥
            //设备解密密钥
            String secretKey = responseBody.getJSONObject("data").getString("secretKey");
            String secretKey = responseBody.getJSONObject("data").getString("secretKey");
            redisTemplate.opsForValue().set(YsConfig.secretKey,secretKey,expireTime, TimeUnit.MILLISECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getSecretKey(),secretKey,expireTime, TimeUnit.MILLISECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
//            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
//            System.out.println(expireTime+"---"+ss);
//            System.out.println(expireTime+"---"+ss);
        }else {
        }else {
@ -99,13 +112,15 @@ public class YsDeviceService {
     * @return
     * @return
     * @throws Exception
     * @throws Exception
     */
     */
    public String getSecretKey() throws Exception {
        if(redisTemplate.hasKey(YsConfig.secretKey)){
            return redisTemplate.opsForValue().get(YsConfig.secretKey);
    public String getSecretKey(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getSecretKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getSecretKey());
        }
        }
        else {
        else {
            getIotAccessToken();
            return redisTemplate.opsForValue().get(YsConfig.secretKey);
            getIotAccessToken(deviceSn);
            return redisTemplate.opsForValue().get(YSCONFIGDO.getSecretKey());
        }
        }
    }
    }
@ -114,13 +129,13 @@ public class YsDeviceService {
        try {
        try {
            StringBuilder responseStr = new StringBuilder("--"+deviceSn+"-- ");
            StringBuilder responseStr = new StringBuilder("--"+deviceSn+"-- ");
            MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
            MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
            param.add("accessToken",getIotAccessToken());
            param.add("accessToken",getIotAccessToken(deviceSn));
            param.add("source",deviceSn+":"+1);
            param.add("source",deviceSn+":"+1);
            HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.openChannelNo,param, HttpMethod.POST);
            HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.openChannelNo,param, HttpMethod.POST);
            JSONObject responseBody = response.getBody();
            JSONObject responseBody = response.getBody();
            responseStr.append("->开通通道:"+responseBody.getInteger("code"));
            responseStr.append("->开通通道:"+responseBody.getInteger("code"));
            JSONObject param2 = new JSONObject();
            JSONObject param2 = new JSONObject();
            param2.put("accessToken",getAccessToken());
            param2.put("accessToken",getAccessToken(deviceSn));
            param2.put("deviceSerial",deviceSn);
            param2.put("deviceSerial",deviceSn);
            param2.put("channelNo","1");
            param2.put("channelNo","1");
            param2.put("isTrust",0);
            param2.put("isTrust",0);
@ -132,10 +147,10 @@ public class YsDeviceService {
                    JSONObject tmp =  responseBody.getJSONObject("data");
                    JSONObject tmp =  responseBody.getJSONObject("data");
                    String validateCode = tmp.getString("ipcValidateCode");
                    String validateCode = tmp.getString("ipcValidateCode");
                    param2 = new JSONObject();
                    param2 = new JSONObject();
                    param2.put("accessToken",getAccessToken());
                    param2.put("accessToken",getAccessToken(deviceSn));
                    param2.put("deviceSerial",deviceSn);
                    param2.put("deviceSerial",deviceSn);
                    param2.put("isEncrypt","0");
                    param2.put("isEncrypt","0");
                    validateCode = messageDecrypt(validateCode,getSecretKey());
                    validateCode = messageDecrypt(validateCode,getSecretKey(deviceSn));
                    param2.put("validateCode",validateCode);
                    param2.put("validateCode",validateCode);
                    response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceEncrypt,param2,HttpMethod.POST);
                    response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceEncrypt,param2,HttpMethod.POST);
                    responseBody = response.getBody();
                    responseBody = response.getBody();

+ 16 - 7
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/config/YsConfig.java

@ -1,15 +1,22 @@
package com.yihu.jw.care.config;
package com.yihu.jw.care.config;
import com.yihu.jw.care.dao.device.YsConfigDao;
import com.yihu.jw.entity.care.device.YsConfigDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
/**
 * Created by Bing on 2021/6/1.
 * Created by Bing on 2021/6/1.
 * 萤石摄像头配置
 * 萤石摄像头配置
 */
 */
@Component
public class YsConfig {
public class YsConfig {
    @Autowired
    private YsConfigDao ysConfigDao;
    //文档地址 https://www.yuque.com/u1400669/kb/lmfp6u
    //文档地址 https://www.yuque.com/u1400669/kb/lmfp6u
    public static final String AppKey="43e44c2071114743925eda34088045f8";
    public static final String Secret="82051725cf0547208f8bc8ae2bff1323";
    public static final String baseUrl = "https://esopen.ys7.com";
    public static final String baseUrl = "https://esopen.ys7.com";
@ -83,10 +90,12 @@ public class YsConfig {
//    public static final String videoDetail = baseUrl +"/seastart/vod/get";
//    public static final String videoDetail = baseUrl +"/seastart/vod/get";
//
//
    public static final String redisKey = "ysAssesToken";
    public static final String iotRedisKey = "iotYsAssesToken";
    public static final String secretKey = "secretKey"; //设备的解密秘钥  通过iotAssesToken接口获取的
    public static final String msgDataKey = "HZADP68PNSNVZ4UW"; //消息解密密钥
    public YsConfigDo getConfig(String deviceSn){
        YsConfigDo configDo = ysConfigDao.getYsConfigByDeviceSn(deviceSn);
        if (null==configDo){
            configDo = ysConfigDao.getDefaultConfig(1);
        }
        return configDo;
    }
}
}

+ 18 - 0
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/dao/device/YsConfigDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.YsConfigDo;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Bing on 2021/10/20.
 */
public interface YsConfigDao extends PagingAndSortingRepository<YsConfigDo,Long>, JpaSpecificationExecutor<YsConfigDo> {
    @Query("select c from YsConfigDo c,YsDeviceDo de where c.configId = de.configId and de.deviceSn = ?1")
    YsConfigDo getYsConfigByDeviceSn(String deviceSn);
    @Query("select c from YsConfigDo c where c.configId=?1")
    YsConfigDo getDefaultConfig(Integer configId);
}

+ 17 - 19
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/contacts/ContactsService.java

@ -374,26 +374,24 @@ public class ContactsService {
                        if (StringUtils.isNotBlank(response)) {
                        if (StringUtils.isNotBlank(response)) {
                            String[] DelNums = del_num.split("_");
                            String[] DelNums = del_num.split("_");
                            for (String tmp:DelNums){
                            for (String tmp:DelNums){
                                if (!delSuccess.contains(tmp)){//本次已删除过 不再作删除操作
                                    String deviceCode = simTmp.get("device_sn").toString();
                                    JSONObject aqgDeviceInfo = patientDeviceService.getAqgDeviceInfo(deviceCode);
                                    JSONArray aqgDeviceSosNum = aqgDeviceInfo.getJSONArray("sos_numbers");
                                    Integer numIndex=0;
                                    for (int i=0;i<aqgDeviceSosNum.size();i++){
                                        JSONObject aqgTmp = aqgDeviceSosNum.getJSONObject(i);
                                        String aqgNum = aqgTmp.getString("num");
                                        if (aqgNum.equals(tmp)){
                                            numIndex = aqgTmp.getInteger("seqid");
                                            break;
                                        }
                                    }
                                    if (numIndex!=0){
                                      JSONObject response2 =  patientDeviceService.updAqgDeviceSosInfo(deviceCode,numIndex+"",null,null,null,"1");
                                      if (response2.getBoolean("success")){
                                          delSuccess += "_"+tmp;
                                      }
                                String deviceCode = simTmp.get("device_sn").toString();
                                JSONObject aqgDeviceInfo = patientDeviceService.getAqgDeviceInfo(deviceCode);
                                JSONArray aqgDeviceSosNum = aqgDeviceInfo.getJSONArray("sos_numbers");
                                Integer numIndex=0;
                                for (int i=0;i<aqgDeviceSosNum.size();i++){
                                    JSONObject aqgTmp = aqgDeviceSosNum.getJSONObject(i);
                                    String aqgNum = aqgTmp.getString("num");
                                    if (aqgNum.equals(tmp)){
                                        numIndex = aqgTmp.getInteger("seqid");
                                        break;
                                    }
                                    }
                                }
                                }
                                if (numIndex!=0){
                                  JSONObject response2 =  patientDeviceService.updAqgDeviceSosInfo(deviceCode,numIndex+"",null,null,null,"1");
                                  if (response2.getBoolean("success")){
                                      delSuccess += "_"+tmp;
                                  }
                                }
                            }
                            }
                        }
                        }
                    }
                    }
@ -404,7 +402,7 @@ public class ContactsService {
        }
        }
        //保存修改记录
        //保存修改记录
        List<PatientSosContactsDO> modify = new ArrayList<>();
        List<PatientSosContactsDO> modify = new ArrayList<>();
        for (String num:numTmp){
        for(String num:numTmp){
            if (StringUtils.isNotBlank(num)){
            if (StringUtils.isNotBlank(num)){
                PatientSosContactsDO patientSosContactsDO = sosContactsDao.findByPatientAndSosPhone(patient,num);
                PatientSosContactsDO patientSosContactsDO = sosContactsDao.findByPatientAndSosPhone(patient,num);
                patientSosContactsDO.setUpdateTime(new Date());
                patientSosContactsDO.setUpdateTime(new Date());

+ 57 - 35
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/YsDeviceService.java

@ -5,9 +5,11 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.care.config.YsConfig;
import com.yihu.jw.care.config.YsConfig;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.YsConfigDao;
import com.yihu.jw.care.dao.label.WlyyPatientLabelDao;
import com.yihu.jw.care.dao.label.WlyyPatientLabelDao;
import com.yihu.jw.care.util.DeviceUtil;
import com.yihu.jw.care.util.DeviceUtil;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.YsConfigDo;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.date.DateUtil;
@ -20,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpMethod;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.MultiValueMap;
@ -50,25 +53,33 @@ public class YsDeviceService {
    private PatientDeviceDao patientDeviceDao;
    private PatientDeviceDao patientDeviceDao;
    @Autowired
    @Autowired
    private DeviceUtil deviceUtil;
    private DeviceUtil deviceUtil;
    @Autowired
    private YsConfig ysConfig;
    @Autowired
    private YsConfigDao ysConfigDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
    /**
     * 获取萤石设备assesToken
     * 获取萤石设备assesToken
     */
     */
    public String getAccessToken() throws Exception {
        if(redisTemplate.hasKey(YsConfig.redisKey)){
            return redisTemplate.opsForValue().get(YsConfig.redisKey);
    public String getAccessToken(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getAccessTokenKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getAccessTokenKey());
        }
        }
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("appKey",YsConfig.AppKey);
        param.put("appSecret",YsConfig.Secret);
        param.put("appKey",YSCONFIGDO.getAppKey());
        param.put("appSecret",YSCONFIGDO.getAppSecret());
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.saasAssesToken,param, HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.saasAssesToken,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        JSONObject responseBody = response.getBody();
        String assToken = null;
        String assToken = null;
        if (responseBody.getInteger("code")==200){
        if (responseBody.getInteger("code")==200){
            assToken = responseBody.getJSONObject("data").getString("accessToken");
            assToken = responseBody.getJSONObject("data").getString("accessToken");
            Long expireTime = responseBody.getJSONObject("data").getLong("expiresIn");//token有效期
            Long expireTime = responseBody.getJSONObject("data").getLong("expiresIn");//token有效期
            redisTemplate.opsForValue().set(YsConfig.redisKey,assToken,expireTime, TimeUnit.SECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getAccessTokenKey(),assToken,expireTime, TimeUnit.SECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.redisKey);
//            Long ss= redisTemplate.getExpire(YsConfig.redisKey);
//            System.out.println(expireTime+"---"+ss);
//            System.out.println(expireTime+"---"+ss);
@ -84,13 +95,15 @@ public class YsDeviceService {
     * @return
     * @return
     * @throws Exception
     * @throws Exception
     */
     */
    public String getIotAccessToken() throws Exception {
        if(redisTemplate.hasKey(YsConfig.iotRedisKey)){
            return redisTemplate.opsForValue().get(YsConfig.iotRedisKey);
    public String getIotAccessToken(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getIotAccessTokenKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getIotAccessTokenKey());
        }
        }
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("accessToken",getAccessToken());
        param.put("accessToken",getAccessToken(deviceSn));
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        JSONObject responseBody = response.getBody();
        String assToken = null;
        String assToken = null;
@ -100,10 +113,10 @@ public class YsDeviceService {
            Long nowTime = System.currentTimeMillis();
            Long nowTime = System.currentTimeMillis();
            expireTime = expireTime-nowTime;
            expireTime = expireTime-nowTime;
            redisTemplate.opsForValue().set(YsConfig.iotRedisKey,assToken,expireTime, TimeUnit.MILLISECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getIotAccessTokenKey(),assToken,expireTime, TimeUnit.MILLISECONDS);
            //设备解密密钥
            //设备解密密钥
            String secretKey = responseBody.getJSONObject("data").getString("secretKey");
            String secretKey = responseBody.getJSONObject("data").getString("secretKey");
            redisTemplate.opsForValue().set(YsConfig.secretKey,secretKey,expireTime, TimeUnit.MILLISECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getSecretKey(),secretKey,expireTime, TimeUnit.MILLISECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
//            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
//            System.out.println(expireTime+"---"+ss);
//            System.out.println(expireTime+"---"+ss);
        }else {
        }else {
@ -117,13 +130,15 @@ public class YsDeviceService {
     * @return
     * @return
     * @throws Exception
     * @throws Exception
     */
     */
    public String getSecretKey() throws Exception {
        if(redisTemplate.hasKey(YsConfig.secretKey)){
            return redisTemplate.opsForValue().get(YsConfig.secretKey);
    public String getSecretKey(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getSecretKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getSecretKey());
        }
        }
        else {
        else {
            getIotAccessToken();
            return redisTemplate.opsForValue().get(YsConfig.secretKey);
            getIotAccessToken(deviceSn);
            return redisTemplate.opsForValue().get(YSCONFIGDO.getSecretKey());
        }
        }
    }
    }
@ -140,7 +155,7 @@ public class YsDeviceService {
    public JSONObject surveillanceWay(String deviceSerial,Integer channelNo,Integer isTrust,HttpServletRequest request) throws Exception {
    public JSONObject surveillanceWay(String deviceSerial,Integer channelNo,Integer isTrust,HttpServletRequest request) throws Exception {
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("accessToken",getAccessToken());
        param.put("accessToken",getAccessToken(deviceSerial));
        param.put("deviceSerial",deviceSerial);
        param.put("deviceSerial",deviceSerial);
        param.put("channelNo",channelNo);
        param.put("channelNo",channelNo);
        param.put("isTrust",0);
        param.put("isTrust",0);
@ -169,11 +184,11 @@ public class YsDeviceService {
     */
     */
    public JSONObject deviceEncrypt(String deviceSerial,Integer isEncrypt,String validateCode,HttpServletRequest request) throws Exception {
    public JSONObject deviceEncrypt(String deviceSerial,Integer isEncrypt,String validateCode,HttpServletRequest request) throws Exception {
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("accessToken",getAccessToken());
        param.put("accessToken",getAccessToken(deviceSerial));
        param.put("deviceSerial",deviceSerial);
        param.put("deviceSerial",deviceSerial);
        param.put("isEncrypt",isEncrypt);
        param.put("isEncrypt",isEncrypt);
        if (0==isEncrypt){//PU4eJqa7j9GMst8P
        if (0==isEncrypt){//PU4eJqa7j9GMst8P
            validateCode = messageDecrypt(validateCode,getSecretKey());
            validateCode = messageDecrypt(validateCode,getSecretKey(deviceSerial));
            param.put("validateCode",validateCode);
            param.put("validateCode",validateCode);
        }
        }
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceEncrypt,param,HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceEncrypt,param,HttpMethod.POST);
@ -192,7 +207,7 @@ public class YsDeviceService {
     */
     */
    public JSONObject deviceCapture(String deviceSerial,Integer channelNo,HttpServletRequest request) throws Exception {
    public JSONObject deviceCapture(String deviceSerial,Integer channelNo,HttpServletRequest request) throws Exception {
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("accessToken",getAccessToken());
        param.put("accessToken",getAccessToken(deviceSerial));
        param.put("deviceSerial",deviceSerial);
        param.put("deviceSerial",deviceSerial);
        param.put("channelNo",channelNo+"");
        param.put("channelNo",channelNo+"");
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceCapture,param,HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceCapture,param,HttpMethod.POST);
@ -215,7 +230,7 @@ public class YsDeviceService {
            }
            }
        }
        }
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("accessToken",getIotAccessToken(deviceSerial));
        param.add("deviceSerial",deviceSerial);
        param.add("deviceSerial",deviceSerial);
        param.add("channelNo",channelNo+"");
        param.add("channelNo",channelNo+"");
        HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.getDeviceLiveAddress,param,HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.getDeviceLiveAddress,param,HttpMethod.POST);
@ -303,14 +318,14 @@ public class YsDeviceService {
        if (null==type){//查询
        if (null==type){//查询
            url += "?accessToken="+getIotAccessToken()+"&key=Alarm_DetectHumanCar";
            url += "?accessToken="+getIotAccessToken(deviceSerial)+"&key=Alarm_DetectHumanCar";
            MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
            MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
            HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(url,param,HttpMethod.GET);
            HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(url,param,HttpMethod.GET);
            responseBody = response.getBody();
            responseBody = response.getBody();
        }
        }
        else {
        else {
            MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
            MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
            param.add("accessToken",getIotAccessToken());
            param.add("accessToken",getIotAccessToken(deviceSerial));
            param.add("key","Alarm_DetectHumanCar");
            param.add("key","Alarm_DetectHumanCar");
            param.add("value","{\"type\":"+type+"}");
            param.add("value","{\"type\":"+type+"}");
@ -333,7 +348,7 @@ public class YsDeviceService {
     */
     */
    public JSONObject ptzStart(String deviceSerial,Integer channelNo,Integer direction,Integer speed,HttpServletRequest request) throws Exception {
    public JSONObject ptzStart(String deviceSerial,Integer channelNo,Integer direction,Integer speed,HttpServletRequest request) throws Exception {
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("accessToken",getIotAccessToken(deviceSerial));
        param.add("deviceSerial",deviceSerial);
        param.add("deviceSerial",deviceSerial);
        param.add("channelNo",channelNo+"");
        param.add("channelNo",channelNo+"");
        param.add("direction",direction+"");
        param.add("direction",direction+"");
@ -355,7 +370,7 @@ public class YsDeviceService {
     */
     */
    public JSONObject ptzStop(String deviceSerial,Integer channelNo,Integer direction,HttpServletRequest request) throws Exception {
    public JSONObject ptzStop(String deviceSerial,Integer channelNo,Integer direction,HttpServletRequest request) throws Exception {
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("accessToken",getIotAccessToken(deviceSerial));
        param.add("deviceSerial",deviceSerial);
        param.add("deviceSerial",deviceSerial);
        param.add("channelNo",channelNo+"");
        param.add("channelNo",channelNo+"");
        param.add("direction",direction+"");
        param.add("direction",direction+"");
@ -373,11 +388,18 @@ public class YsDeviceService {
     * @throws Exception
     * @throws Exception
     */
     */
    public JSONObject coverVideoSwitch(String is_vod_cover ,HttpServletRequest request) throws Exception {
    public JSONObject coverVideoSwitch(String is_vod_cover ,HttpServletRequest request) throws Exception {
        JSONObject param  = new JSONObject();
        param.put("accessToken",getAccessToken());
        param.put("is_vod_cover",is_vod_cover);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.coverVideoSwitch,param,HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        String sql =" select de.device_sn from dm_ys_config con INNER JOIN ys_device de " +
                " on con.config_id = de.config_id GROUP BY con.config_id";
        List<String> device = jdbcTemplate.queryForList(sql,String.class);
        JSONObject responseBody = new JSONObject();
        for (String deviceSn:device){
            JSONObject param  = new JSONObject();
            param.put("accessToken",getAccessToken(deviceSn));
            param.put("is_vod_cover",is_vod_cover);
            HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.coverVideoSwitch,param,HttpMethod.POST);
            responseBody = response.getBody();
        }
        return responseBody;
        return responseBody;
        //https://www.yuque.com/u1400669/kb/nu22ks
        //https://www.yuque.com/u1400669/kb/nu22ks
    }
    }
@ -404,7 +426,7 @@ public class YsDeviceService {
            }
            }
        }
        }
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("accessToken",getIotAccessToken(deviceSerial));
        param.add("deviceSerial",deviceSerial);
        param.add("deviceSerial",deviceSerial);
        param.add("channelNo",channelNo+"");
        param.add("channelNo",channelNo+"");
@ -514,7 +536,7 @@ public class YsDeviceService {
    public JSONObject deviceVideoUrlByTime(String deviceSerial,Integer channelNo,String protocol,String type,String startTime,String stopTime,Integer expireTime,HttpServletRequest request) throws Exception {
    public JSONObject deviceVideoUrlByTime(String deviceSerial,Integer channelNo,String protocol,String type,String startTime,String stopTime,Integer expireTime,HttpServletRequest request) throws Exception {
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("accessToken",getIotAccessToken(deviceSerial));
        param.add("deviceSerial",deviceSerial);
        param.add("deviceSerial",deviceSerial);
        param.add("channelNo",channelNo+"");
        param.add("channelNo",channelNo+"");
        if (StringUtils.isNotBlank(protocol)){
        if (StringUtils.isNotBlank(protocol)){
@ -634,7 +656,7 @@ public class YsDeviceService {
                                 String gbchannel,HttpServletRequest request) throws Exception {
                                 String gbchannel,HttpServletRequest request) throws Exception {
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("accessToken",getIotAccessToken(deviceSerial));
        if (StringUtils.isBlank(deviceSerial)){
        if (StringUtils.isBlank(deviceSerial)){
            if (StringUtils.isNotBlank(patient)){
            if (StringUtils.isNotBlank(patient)){
                List<DevicePatientDevice> devices = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
                List<DevicePatientDevice> devices = patientDeviceDao.findByUserAndCategoryCode(patient,"12");
@ -692,7 +714,7 @@ public class YsDeviceService {
    public JSONObject fullDayVideo(String deviceSerial,Integer channelNo,Integer enable,HttpServletRequest request) throws Exception {
    public JSONObject fullDayVideo(String deviceSerial,Integer channelNo,Integer enable,HttpServletRequest request) throws Exception {
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        MultiValueMap<String,String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("accessToken",getIotAccessToken(deviceSerial));
        if (StringUtils.isNotBlank(deviceSerial)){
        if (StringUtils.isNotBlank(deviceSerial)){
            param.add("deviceSerial",deviceSerial);
            param.add("deviceSerial",deviceSerial);
        }
        }

+ 16 - 7
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/config/YsConfig.java

@ -1,15 +1,22 @@
package com.yihu.jw.care.config;
package com.yihu.jw.care.config;
import com.yihu.jw.care.dao.device.YsConfigDao;
import com.yihu.jw.entity.care.device.YsConfigDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
/**
 * Created by Bing on 2021/6/1.
 * Created by Bing on 2021/6/1.
 * 萤石摄像头配置
 * 萤石摄像头配置
 */
 */
@Component
public class YsConfig {
public class YsConfig {
    @Autowired
    private YsConfigDao ysConfigDao;
    //文档地址 https://www.yuque.com/u1400669/kb/lmfp6u
    //文档地址 https://www.yuque.com/u1400669/kb/lmfp6u
    public static final String AppKey="43e44c2071114743925eda34088045f8";
    public static final String Secret="82051725cf0547208f8bc8ae2bff1323";
    public static final String baseUrl = "https://esopen.ys7.com";
    public static final String baseUrl = "https://esopen.ys7.com";
@ -69,10 +76,12 @@ public class YsConfig {
    //录像详情
    //录像详情
    public static final String videoDetail = baseUrl +"/seastart/vod/get";
    public static final String videoDetail = baseUrl +"/seastart/vod/get";
    public static final String redisKey = "ysAssesToken";
    public static final String iotRedisKey = "iotYsAssesToken";
    public static final String secretKey = "secretKey"; //设备的解密秘钥  通过iotAssesToken接口获取的
    public static final String msgDataKey = "HZADP68PNSNVZ4UW"; //消息解密密钥
    public YsConfigDo getConfig(String deviceSn){
        YsConfigDo configDo = ysConfigDao.getYsConfigByDeviceSn(deviceSn);
        if (null==configDo){
            configDo = ysConfigDao.getDefaultConfig(1);
        }
        return configDo;
    }
}
}

+ 18 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/dao/device/YsConfigDao.java

@ -0,0 +1,18 @@
package com.yihu.jw.care.dao.device;
import com.yihu.jw.entity.care.device.YsConfigDo;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Bing on 2021/10/20.
 */
public interface YsConfigDao extends PagingAndSortingRepository<YsConfigDo,Long>, JpaSpecificationExecutor<YsConfigDo> {
    @Query("select c from YsConfigDo c,YsDeviceDo de where c.configId = de.configId and de.deviceSn = ?1")
    YsConfigDo getYsConfigByDeviceSn(String deviceSn);
    @Query("select c from YsConfigDo c where c.configId=?1")
    YsConfigDo getDefaultConfig(Integer configId);
}

+ 41 - 22
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/YsDeviceService.java

@ -8,11 +8,13 @@ import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.care.config.YsConfig;
import com.yihu.jw.care.config.YsConfig;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.dao.device.DeviceDetailDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.PatientDeviceDao;
import com.yihu.jw.care.dao.device.YsConfigDao;
import com.yihu.jw.care.util.DeviceDataPushLogUtil;
import com.yihu.jw.care.util.DeviceDataPushLogUtil;
import com.yihu.jw.care.util.SecurityOrderUtil;
import com.yihu.jw.care.util.SecurityOrderUtil;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.device.DeviceDetail;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.DevicePatientDevice;
import com.yihu.jw.entity.care.device.YsConfigDo;
import com.yihu.jw.entity.util.AesEncryptUtils;
import com.yihu.jw.entity.util.AesEncryptUtils;
import com.yihu.jw.exception.business.file_upload.*;
import com.yihu.jw.exception.business.file_upload.*;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientDao;
@ -86,25 +88,31 @@ public class YsDeviceService {
    private DeviceDataPushLogUtil dataPushLogUtil;
    private DeviceDataPushLogUtil dataPushLogUtil;
    @Autowired
    @Autowired
    private DeviceDetailDao deviceDetailDao;
    private DeviceDetailDao deviceDetailDao;
    @Autowired
    private YsConfig ysConfig;
    @Autowired
    private YsConfigDao ysConfigDao;
    /**
    /**
     * 获取萤石设备assesToken
     * 获取萤石设备assesToken
     */
     */
    public String getAccessToken() throws Exception {
        if(redisTemplate.hasKey(YsConfig.redisKey)){
            return redisTemplate.opsForValue().get(YsConfig.redisKey);
    public String getAccessToken(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getAccessTokenKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getAccessTokenKey());
        }
        }
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("appKey",YsConfig.AppKey);
        param.put("appSecret",YsConfig.Secret);
        param.put("appKey",YSCONFIGDO.getAppKey());
        param.put("appSecret",YSCONFIGDO.getAppSecret());
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.saasAssesToken,param, HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.saasAssesToken,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        JSONObject responseBody = response.getBody();
        String assToken = null;
        String assToken = null;
        if (responseBody.getInteger("code")==200){
        if (responseBody.getInteger("code")==200){
            assToken = responseBody.getJSONObject("data").getString("accessToken");
            assToken = responseBody.getJSONObject("data").getString("accessToken");
            Long expireTime = responseBody.getJSONObject("data").getLong("expiresIn");//token有效期
            Long expireTime = responseBody.getJSONObject("data").getLong("expiresIn");//token有效期
            redisTemplate.opsForValue().set(YsConfig.redisKey,assToken,expireTime, TimeUnit.SECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getAccessTokenKey(),assToken,expireTime, TimeUnit.SECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.redisKey);
//            Long ss= redisTemplate.getExpire(YsConfig.redisKey);
//            System.out.println(expireTime+"---"+ss);
//            System.out.println(expireTime+"---"+ss);
@ -120,13 +128,15 @@ public class YsDeviceService {
     * @return
     * @return
     * @throws Exception
     * @throws Exception
     */
     */
    public String getIotAccessToken() throws Exception {
        if(redisTemplate.hasKey(YsConfig.iotRedisKey)){
            return redisTemplate.opsForValue().get(YsConfig.iotRedisKey);
    public String getIotAccessToken(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getIotAccessTokenKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getIotAccessTokenKey());
        }
        }
        JSONObject param = new JSONObject();
        JSONObject param = new JSONObject();
        param.put("accessToken",getAccessToken());
        param.put("accessToken",getAccessToken(deviceSn));
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        JSONObject responseBody = response.getBody();
        String assToken = null;
        String assToken = null;
@ -136,10 +146,10 @@ public class YsDeviceService {
            Long nowTime = System.currentTimeMillis();
            Long nowTime = System.currentTimeMillis();
            expireTime = expireTime-nowTime;
            expireTime = expireTime-nowTime;
            redisTemplate.opsForValue().set(YsConfig.iotRedisKey,assToken,expireTime, TimeUnit.MILLISECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getIotAccessTokenKey(),assToken,expireTime, TimeUnit.MILLISECONDS);
            //设备解密密钥
            //设备解密密钥
            String secretKey = responseBody.getJSONObject("data").getString("secretKey");
            String secretKey = responseBody.getJSONObject("data").getString("secretKey");
            redisTemplate.opsForValue().set(YsConfig.secretKey,secretKey,expireTime, TimeUnit.MILLISECONDS);
            redisTemplate.opsForValue().set(YSCONFIGDO.getSecretKey(),secretKey,expireTime, TimeUnit.MILLISECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
//            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
//            System.out.println(expireTime+"---"+ss);
//            System.out.println(expireTime+"---"+ss);
        }else {
        }else {
@ -153,13 +163,15 @@ public class YsDeviceService {
     * @return
     * @return
     * @throws Exception
     * @throws Exception
     */
     */
    public String getSecretKey() throws Exception {
        if(redisTemplate.hasKey(YsConfig.secretKey)){
            return redisTemplate.opsForValue().get(YsConfig.secretKey);
    public String getSecretKey(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getSecretKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getSecretKey());
        }
        }
        else {
        else {
            getIotAccessToken();
            return redisTemplate.opsForValue().get(YsConfig.secretKey);
            getIotAccessToken(deviceSn);
            return redisTemplate.opsForValue().get(YSCONFIGDO.getSecretKey());
        }
        }
    }
    }
@ -189,7 +201,14 @@ public class YsDeviceService {
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
        try {
        try {
            String decodeStr = messageDecrypt(message,YsConfig.msgDataKey);
            String decodeStr = null;
            try {//由于目前两个账号同时使用 不清楚具体是那个设备的
                YsConfigDo configDo = ysConfigDao.getDefaultConfig(1);
                decodeStr = messageDecrypt(message,configDo.getMsgDataKey());
            }catch (Exception e){
                YsConfigDo configDo = ysConfigDao.getDefaultConfig(2);
                decodeStr = messageDecrypt(message,configDo.getMsgDataKey());
            }
            result = JSONObject.parseObject(decodeStr);
            result = JSONObject.parseObject(decodeStr);
            JSONArray tmpArr = result.getJSONObject("eps").getJSONArray("alert");
            JSONArray tmpArr = result.getJSONObject("eps").getJSONArray("alert");
            boolean fallFlag = false;
            boolean fallFlag = false;
@ -272,13 +291,13 @@ public class YsDeviceService {
    public void videoOpen(String deviceSn,HttpServletRequest request) throws Exception {
    public void videoOpen(String deviceSn,HttpServletRequest request) throws Exception {
        StringBuilder responseStr = new StringBuilder("--"+deviceSn+"-- ");
        StringBuilder responseStr = new StringBuilder("--"+deviceSn+"-- ");
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
        param.add("accessToken",getIotAccessToken());
        param.add("accessToken",getIotAccessToken(deviceSn));
        param.add("source",deviceSn+":"+1);
        param.add("source",deviceSn+":"+1);
        HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.openChannelNo,param, HttpMethod.POST);
        HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.openChannelNo,param, HttpMethod.POST);
        JSONObject responseBody = response.getBody();
        JSONObject responseBody = response.getBody();
        responseStr.append("->开通通道:"+responseBody.getInteger("code"));
        responseStr.append("->开通通道:"+responseBody.getInteger("code"));
        JSONObject param2 = new JSONObject();
        JSONObject param2 = new JSONObject();
        param2.put("accessToken",getAccessToken());
        param2.put("accessToken",getAccessToken(deviceSn));
        param2.put("deviceSerial",deviceSn);
        param2.put("deviceSerial",deviceSn);
        param2.put("channelNo","1");
        param2.put("channelNo","1");
        param2.put("isTrust",0);
        param2.put("isTrust",0);
@ -290,10 +309,10 @@ public class YsDeviceService {
                JSONObject tmp =  responseBody.getJSONObject("data");
                JSONObject tmp =  responseBody.getJSONObject("data");
                String validateCode = tmp.getString("ipcValidateCode");
                String validateCode = tmp.getString("ipcValidateCode");
                param2 = new JSONObject();
                param2 = new JSONObject();
                param2.put("accessToken",getAccessToken());
                param2.put("accessToken",getAccessToken(deviceSn));
                param2.put("deviceSerial",deviceSn);
                param2.put("deviceSerial",deviceSn);
                param2.put("isEncrypt","0");
                param2.put("isEncrypt","0");
                validateCode = messageDecrypt(validateCode,getSecretKey());
                validateCode = messageDecrypt(validateCode,getSecretKey(deviceSn));
                param2.put("validateCode",validateCode);
                param2.put("validateCode",validateCode);
                response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceEncrypt,param2,HttpMethod.POST);
                response = httpClientUtil.assesTokenPostHttp(YsConfig.deviceEncrypt,param2,HttpMethod.POST);
                responseBody = response.getBody();
                responseBody = response.getBody();

+ 1 - 1
svr/svr-cloud-job/src/main/resources/system.properties

@ -18,7 +18,7 @@ CANCEL_PAY_ORDER_OVERTIME_JOB=0 0/3 * * * ?
PATIENT_SOS_CONTACTS_JOB=0 0/2 * * * ?
PATIENT_SOS_CONTACTS_JOB=0 0/2 * * * ?
#\u533B\u517B\u7269\u8054\u7F51\u68C0\u6D4B\u5927\u5C4F\u5931\u8054\u7387
#\u533B\u517B\u7269\u8054\u7F51\u68C0\u6D4B\u5927\u5C4F\u5931\u8054\u7387
DEVICE_LOST_ASSOCIATION_JOB=0 30 23 * * ?
DEVICE_LOST_ASSOCIATION_JOB=0 0 0/2 * * ?
#\u7D27\u6025\u9884\u8B66\u5DE5\u5355\u8D85\u65F6\u672A\u54CD\u5E94\u63A8\u9001\u5F39\u6846
#\u7D27\u6025\u9884\u8B66\u5DE5\u5355\u8D85\u65F6\u672A\u54CD\u5E94\u63A8\u9001\u5F39\u6846
EME_WARNING_OVERTIME_NOT_RESPONSE=0 0 * * * ?
EME_WARNING_OVERTIME_NOT_RESPONSE=0 0 * * * ?