|
@ -1,12 +1,20 @@
|
|
|
package com.yihu.jw.entrance.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
|
|
|
import com.yihu.jw.entity.iot.gateway.GcToken;
|
|
|
import com.yihu.jw.entrance.util.zysoft.SDKRunnerService;
|
|
|
import com.yihu.jw.entrance.util.zysoft.ZysoftBaseService;
|
|
|
import com.yihu.jw.gateway.dao.GcTokenDao;
|
|
|
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@ -25,13 +33,17 @@ public class IotDeviceService {
|
|
|
private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
|
|
|
@Autowired
|
|
|
private SDKRunnerService sdkRunnerService;
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
@Autowired
|
|
|
private GcTokenDao gcTokenDao;
|
|
|
|
|
|
/**
|
|
|
* 获取accesstoken
|
|
|
* 获取accesstoken,i健康写法暂时不能用
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public String getAccessToken() throws Exception{
|
|
|
public String getAccessToken_bak() throws Exception{
|
|
|
Map<String,String> header = new HashMap<>();
|
|
|
List<WlyyHospitalSysDictDO> dictDOList = wlyyHospitalSysDictDao.findByDictName("zy_iot");
|
|
|
Map<String,String> dictMap = dictDOList.stream().collect(Collectors.toMap(WlyyHospitalSysDictDO::getDictCode,WlyyHospitalSysDictDO::getDictValue));
|
|
@ -46,15 +58,78 @@ public class IotDeviceService {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
public String getAccessToken2(){
|
|
|
//设备状态信息上传
|
|
|
public String uploadDeviceInfo(){
|
|
|
Map<String,String> header = new HashMap<>();
|
|
|
String jsonData = "{\"deviceSn\":\"xty_test\",\"deviceModel\":\"测试\",\"name\":\"血糖仪TEST\",\"hospital\":\"350211A1004\",\"hospitalName\":\"厦门市第三医院\",\"categoryCode\":\"2\",\"categoryName\":\" 血糖仪\",\"commonName\":\" 血糖仪\",\"combinationMethod\":\"1\",\"networkTransmission\":\" 11\",\"deviceUse\":\"2\",\"dropLocation\":\"2\",\"dataAcquisition\":\"IoT_equipment_blood_glucose_mete\",\"companyName\":\"血糖仪厂商名称\",\"companyType\":\"3\"}";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("jsonData",jsonData);
|
|
|
params.put("accesstoken",getAccessToken());
|
|
|
String response = sdkRunnerService.post("wlw/uploadDeviceInfo","设备状态信息上传",params,header,true,true);
|
|
|
return response;
|
|
|
}
|
|
|
//设备业务数据信息上传
|
|
|
public String uploadDeviceData(){
|
|
|
Map<String,String> header = new HashMap<>();
|
|
|
String jsonData = "{\"deviceSn\":\"xty_test\",\"deviceModel\":\"测试\",\"name\":\"血糖仪TEST\",\"hospital\":\"350211A1004\",\"hospitalName\":\"厦门市第三医院\",\"categoryCode\":\"2\",\"categoryName\":\" 血糖仪\",\"commonName\":\" 血糖仪\",\"combinationMethod\":\"1\",\"networkTransmission\":\" 11\",\"deviceUse\":\"2\",\"dropLocation\":\"2\",\"dataAcquisition\":\"IoT_equipment_blood_glucose_mete\",\"companyName\":\"血糖仪厂商名称\",\"companyType\":\"3\"}";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("jsonData",jsonData);
|
|
|
params.put("accesstoken",getAccessToken());
|
|
|
String response = sdkRunnerService.post("wlw/uploadDeviceData","设备业务数据信息上传",params,header,true,true);
|
|
|
return response;
|
|
|
}
|
|
|
//设备相关基础信息注册
|
|
|
public String deviceRegistration(){
|
|
|
Map<String,String> header = new HashMap<>();
|
|
|
String jsonData = "{\"deviceSn\":\"xty_test\",\"deviceModel\":\"测试\",\"name\":\"血糖仪TEST\",\"hospital\":\"350211A1004\",\"hospitalName\":\"厦门市第三医院\",\"categoryCode\":\"2\",\"categoryName\":\" 血糖仪\",\"commonName\":\" 血糖仪\",\"combinationMethod\":\"1\",\"networkTransmission\":\" 11\",\"deviceUse\":\"2\",\"dropLocation\":\"2\",\"dataAcquisition\":\"IoT_equipment_blood_glucose_mete\",\"companyName\":\"血糖仪厂商名称\",\"companyType\":\"3\"}";
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("jsonData",jsonData);
|
|
|
params.put("accesstoken",getAccessToken());
|
|
|
String response = sdkRunnerService.post("wlw/deviceRegistration","设备相关基础信息注册",params,header,true,true);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取accesstoken
|
|
|
* @return
|
|
|
*/
|
|
|
public synchronized String getAccessToken(){
|
|
|
//新增accesstoken 缓存
|
|
|
Map<String,String> header = new HashMap<>();
|
|
|
List<WlyyHospitalSysDictDO> dictDOList = wlyyHospitalSysDictDao.findByDictName("zy_iot");
|
|
|
Map<String,String> dictMap = dictDOList.stream().collect(Collectors.toMap(WlyyHospitalSysDictDO::getDictCode,WlyyHospitalSysDictDO::getDictValue));
|
|
|
|
|
|
String appid = dictMap.get("appid");
|
|
|
String appSecret = dictMap.get("appSecret");
|
|
|
Map<String,String> params = new HashMap<>();
|
|
|
params.put("appid",dictMap.get("appid"));
|
|
|
params.put("appSecret",dictMap.get("appSecret"));
|
|
|
String response = sdkRunnerService.post("wlw/accesstoken",params,header,true,true);
|
|
|
return response;
|
|
|
params.put("appid",appid);
|
|
|
params.put("appSecret",appSecret);
|
|
|
String sql = "SELECT * from gc_token WHERE appid='"+appid+"' and del='1' and out_time>='"+DateUtil.getStringDate()+"' ORDER BY id desc LIMIT 1";
|
|
|
List<GcToken> gcTokenList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(GcToken.class));
|
|
|
if(gcTokenList.size()>0){
|
|
|
//缓存未失效前直接读缓存
|
|
|
return gcTokenList.get(0).getAccesstoken();
|
|
|
}
|
|
|
String response = sdkRunnerService.post("wlw/accesstoken","获取accesstoken",params,header,true,true);
|
|
|
JSONObject json = JSON.parseObject(response);
|
|
|
if(json.getInteger("status")==10000){
|
|
|
JSONObject result = json.getJSONObject("result");
|
|
|
String accesstoken = result.getString("accesstoken");
|
|
|
//两个小时超时
|
|
|
long createTime = result.getLong("createTime");
|
|
|
long outTime = result.getLong("outTime");
|
|
|
outTime = outTime - Math.abs(System.currentTimeMillis()-createTime)-1000;
|
|
|
//把该用户之前有效的token设置为无效
|
|
|
gcTokenDao.updateDel(appid);
|
|
|
GcToken gc = new GcToken();
|
|
|
gc.setAppid(appid);
|
|
|
gc.setCreateTime(new Date());
|
|
|
gc.setOutTime(DateUtil.longToDate(outTime));
|
|
|
gc.setAccesstoken(accesstoken);
|
|
|
gc.setDel(1);
|
|
|
gcTokenDao.save(gc);
|
|
|
return accesstoken;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
}
|