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