|
|
|
@ -10,13 +10,16 @@ import com.ruoyi.biemo.business.domain.event.CategoryDeleteEvent;
|
|
|
|
|
import com.ruoyi.biemo.business.domain.event.CategorySaveEvent;
|
|
|
|
|
import com.ruoyi.biemo.business.domain.event.ReportDeleteEvent;
|
|
|
|
|
import com.ruoyi.biemo.business.domain.event.ReportSaveEvent;
|
|
|
|
|
import com.ruoyi.biemo.core.MyConstants;
|
|
|
|
|
import com.ruoyi.biemo.core.page.Page;
|
|
|
|
|
import com.ruoyi.biemo.core.response.MyResponseResult;
|
|
|
|
|
import com.ruoyi.biemo.elasticsearch.util.EsService;
|
|
|
|
|
import com.ruoyi.biemo.mongodb.utils.CriteriaAndWrapper;
|
|
|
|
|
import com.ruoyi.biemo.mongodb.utils.MongoHelper;
|
|
|
|
|
import com.ruoyi.biemo.utils.MyObjects;
|
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
|
@ -192,6 +195,21 @@ public class ReportService extends EsService<Report> {
|
|
|
|
|
private String appId = "cb00a3e26b963b25e28cae6e046f1190";
|
|
|
|
|
@Value("${sso.secretKey}")
|
|
|
|
|
private String secretKey = "4ce36bf549d64d44b6cbc48e926abb05";
|
|
|
|
|
|
|
|
|
|
@Value("${report.uploadUrl}")
|
|
|
|
|
private String reportUploadUrl = "http://test.vsp.cqooc.com/open/api/v2/upload/data";
|
|
|
|
|
|
|
|
|
|
@Value("${report.refreshUrl}")
|
|
|
|
|
private String refreshUrl = "http://test.vsp.cqooc.com/open/api/v2/oauth/refresh?token=TOKEN&appid=APPID&signature=SIGNATURE";
|
|
|
|
|
|
|
|
|
|
@Value("${report.validateUrl}")
|
|
|
|
|
private String validateUrl = "http://test.vsp.cqooc.com/open/api/v2/oauth/validate?username=USERNAME&password=PASSWORD&nonce=NONCE&cnonce=CNONCE&appid=APPID&signature=SIGNATURE";
|
|
|
|
|
|
|
|
|
|
@Value("${report.uploadAttachmentUrl}")
|
|
|
|
|
private String uploadAttachmentUrl = "http://test.vsp.cqooc.com/open/api/v2/upload/attachment?access_token=ACCESS_TOKEN&appid=APPID&originId=ORIGINID&filename=FILENAME&title=TITLE&remarks=REMARKS";
|
|
|
|
|
|
|
|
|
|
@Value("${report.getReportListUrl}")
|
|
|
|
|
private String getReportListUrl = "http://test.vsp.cqooc.com/open/api/v2/query/data?appId=APPID&accessToken=ACCESS_TOKEN&signature=SIGNATURE&&originId=ORIGINID";
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisCache redisCache;
|
|
|
|
|
|
|
|
|
@ -213,10 +231,16 @@ public class ReportService extends EsService<Report> {
|
|
|
|
|
userName = data.getString("userName");
|
|
|
|
|
String openId = data.getString("openId");
|
|
|
|
|
String accessToken = data.getString("accessToken");
|
|
|
|
|
MyResponseResult myResponseResult = new MyResponseResult();
|
|
|
|
|
myResponseResult.setAccessToken(accessToken);
|
|
|
|
|
myResponseResult.setOpenId(openId);
|
|
|
|
|
Long createTime = data.getLong("createTime");
|
|
|
|
|
Long expiresTime = data.getLong("expiresTime");
|
|
|
|
|
Long expiresLong = expiresTime-createTime;
|
|
|
|
|
redisCache.setCacheObject(ticket, accessToken, expiresLong.intValue(), TimeUnit.MILLISECONDS);
|
|
|
|
|
Long expiresLong = expiresTime-System.currentTimeMillis();
|
|
|
|
|
redisCache.setCacheObject(MyConstants.TOKEN_PREFIX+userName, myResponseResult, expiresLong.intValue(), TimeUnit.MILLISECONDS);
|
|
|
|
|
if(expiresLong<=0){
|
|
|
|
|
refreshToken(accessToken,userName,myResponseResult);
|
|
|
|
|
}
|
|
|
|
|
//用户名不存在就新建
|
|
|
|
|
SysUser sysUser = new SysUser();
|
|
|
|
|
if(UserConstants.UNIQUE.equals(userService.checkUserNameUnique(userName))){
|
|
|
|
@ -250,6 +274,93 @@ public class ReportService extends EsService<Report> {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//验证用户信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//上报实验结果
|
|
|
|
|
public AjaxResult uploadReport(Report report,String username){
|
|
|
|
|
if(report==null||StringUtils.isBlank(username)){
|
|
|
|
|
return AjaxResult.error("参数不能为空!");
|
|
|
|
|
}
|
|
|
|
|
MyResponseResult myResponseResult = redisCache.getCacheObject(MyConstants.TOKEN_PREFIX+username);
|
|
|
|
|
if(myResponseResult!=null&&myResponseResult.getAccessToken()!=null){
|
|
|
|
|
report.setAccessToken(myResponseResult.getAccessToken());
|
|
|
|
|
String signature = report.getSignature();
|
|
|
|
|
signature = Md5Utils.hash(appId+secretKey+report.getAccessToken()).toUpperCase();
|
|
|
|
|
report.setSignature(signature);
|
|
|
|
|
report.setOpenId(myResponseResult.getOpenId());
|
|
|
|
|
report.setOriginId(username);
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
ResponseEntity<Map> uploadResponseEntity = restTemplate.postForEntity(reportUploadUrl, report, Map.class);
|
|
|
|
|
Map result = uploadResponseEntity.getBody();
|
|
|
|
|
if (result != null && (Integer) result.get("code") == 0) {
|
|
|
|
|
return AjaxResult.success(result.get("data"));
|
|
|
|
|
}else{
|
|
|
|
|
return AjaxResult.error(result.get("message").toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return AjaxResult.error("没有授权或授权到期!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取实验结果
|
|
|
|
|
public Page<Report> getReportList(String username){
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
MyResponseResult myResponseResult = redisCache.getCacheObject(MyConstants.TOKEN_PREFIX+username);
|
|
|
|
|
if(myResponseResult!=null&&StringUtils.isNotBlank(myResponseResult.getAccessToken())){
|
|
|
|
|
String accessToken = myResponseResult.getAccessToken();
|
|
|
|
|
String signature = Md5Utils.hash(appId+secretKey+accessToken).toUpperCase();
|
|
|
|
|
map.put("APPID",appId);
|
|
|
|
|
map.put("ACCESS_TOKEN",accessToken);
|
|
|
|
|
map.put("SIGNATURE",signature);
|
|
|
|
|
map.put("ORIGINID",username);
|
|
|
|
|
ResponseEntity<Map> responseEntity = restTemplate.getForEntity(getReportListUrl,Map.class,map);
|
|
|
|
|
Map body = responseEntity.getBody();
|
|
|
|
|
if(body!=null&&(Integer)body.get("code")==0){
|
|
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(body);
|
|
|
|
|
JSONObject data = jsonObject.getObject("data",JSONObject.class);
|
|
|
|
|
JSONObject meta = jsonObject.getObject("meta",JSONObject.class);
|
|
|
|
|
String total = meta.getString("total");
|
|
|
|
|
String start = meta.getString("start");
|
|
|
|
|
String size = meta.getString("size");
|
|
|
|
|
List<Report> reportList = JSONObject.parseArray(data.getString("data"),Report.class);
|
|
|
|
|
Page<Report> page = new Page<>();
|
|
|
|
|
page.setRows(reportList);
|
|
|
|
|
page.setPageNum(Integer.parseInt(start));
|
|
|
|
|
page.setPageSize(Integer.parseInt(size));
|
|
|
|
|
page.setTotal(Long.valueOf(total));
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Page<Report>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//刷新token方法
|
|
|
|
|
public String refreshToken(String oldToken,String username,MyResponseResult myResponseResult){
|
|
|
|
|
String newToken = "";
|
|
|
|
|
String signature = Md5Utils.hash(appId+secretKey+oldToken).toUpperCase();
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
map.put("APPID",appId);
|
|
|
|
|
map.put("TOKEN",oldToken);
|
|
|
|
|
map.put("SIGNATURE",signature);
|
|
|
|
|
ResponseEntity<Map> responseEntity = restTemplate.getForEntity(refreshUrl,Map.class,map);
|
|
|
|
|
Map responseMap = responseEntity.getBody();
|
|
|
|
|
if(responseMap!=null&&(Integer)responseMap.get("code")==0){
|
|
|
|
|
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(responseMap);
|
|
|
|
|
JSONObject data = jsonObject.getObject("data",JSONObject.class);
|
|
|
|
|
newToken = data.getString("accessToken");
|
|
|
|
|
Long createTime = data.getLong("createTime");
|
|
|
|
|
Long expiresTime = data.getLong("expiresTime");
|
|
|
|
|
Long expiresLong = expiresTime-System.currentTimeMillis();
|
|
|
|
|
myResponseResult.setAccessToken(newToken);
|
|
|
|
|
redisCache.setCacheObject(MyConstants.TOKEN_PREFIX+username,myResponseResult,expiresLong.intValue(),TimeUnit.MILLISECONDS);
|
|
|
|
|
}
|
|
|
|
|
return newToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* "success": true,
|
|
|
|
|
* "code": 0,
|
|
|
|
|