Commit 9cae20b3 authored by ZWT's avatar ZWT

nocommit

parent a525e8f8
package pps.core.prediction.service; package pps.core.prediction.service;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
...@@ -28,7 +29,6 @@ import xstartup.feature.api.annotation.XApiAnonymous; ...@@ -28,7 +29,6 @@ import xstartup.feature.api.annotation.XApiAnonymous;
import xstartup.feature.api.annotation.XApiGet; import xstartup.feature.api.annotation.XApiGet;
import xstartup.feature.api.annotation.XApiPost; import xstartup.feature.api.annotation.XApiPost;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -78,7 +78,7 @@ public class WellheadDailyProductionSituationService { ...@@ -78,7 +78,7 @@ public class WellheadDailyProductionSituationService {
@XApiAnonymous @XApiAnonymous
@XApiPost @XApiPost
public XListResult<QueryWellheadDailyProductionSituationOutput> t(XContext context, QueryWellheadDailyProductionSituationInput input) { public XListResult<QueryWellheadDailyProductionSituationOutput> t(XContext context, QueryWellheadDailyProductionSituationInput input) {
String cqToken = this.getCqToken(context); String cqToken = this.getToken(context);
return XListResult.success(); return XListResult.success();
} }
...@@ -90,7 +90,7 @@ public class WellheadDailyProductionSituationService { ...@@ -90,7 +90,7 @@ public class WellheadDailyProductionSituationService {
String cqToken = ""; String cqToken = "";
String api = ""; String api = "";
try { try {
cqToken = this.getCqToken(context); cqToken = this.getToken(context);
context.getLogger().info("cqToken: " + cqToken); context.getLogger().info("cqToken: " + cqToken);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -139,34 +139,60 @@ public class WellheadDailyProductionSituationService { ...@@ -139,34 +139,60 @@ public class WellheadDailyProductionSituationService {
return XServiceResult.OK; return XServiceResult.OK;
} }
/*----------------------------------- 私有方法 -----------------------------------*/
/** /**
* 获取长庆TOKEN * 获取长庆TOKEN
* *
* @param context 上下文 * @param context 上下文
* @return {@link String} * @return {@link String}
*/ */
private String getCqToken(XContext context) { private String getToken(XContext context) {
String token; String token;
ThirdPartyConfigCache exist = ThirdPartyConfigCache.exist(context, ThirdPartyApiConstant.CQ_TOKEN_CACHE_KEY); ThirdPartyConfigCache exist = ThirdPartyConfigCache.exist(context, ThirdPartyApiConstant.CQ_TOKEN_CACHE_KEY);
if (ObjectUtil.isNull(exist)) { if (ObjectUtil.isNull(exist)) {
token = this.getCqToken();
this.setThirdPartyConfigCache(context, token);
} else {
long between = DateUtil.between(exist.getCurrentDate(), DateUtil.date(), DateUnit.SECOND);
long duration = (long) exist.getDuration();
if (between - duration < 300) {
token = this.getCqToken();
this.setThirdPartyConfigCache(context, token);
}
token = exist.getCode();
}
return token;
}
/**
* 获取长庆Token
*
* @return {@link String}
*/
private String getCqToken() {
String url = XStartup.getCurrent().getProperty("third-party.chang-qing.url"); String url = XStartup.getCurrent().getProperty("third-party.chang-qing.url");
url += ThirdPartyApiConstant.CQ_TOKEN; url += ThirdPartyApiConstant.CQ_TOKEN;
Map<String, String> param = new HashMap<>(4); Map<String, String> param = new HashMap<>(4);
param.put("UserAccount", "PvGroup"); param.put("UserAccount", "PvGroup");
param.put("UserPassWord", "PvGroup@147369"); param.put("UserPassWord", "PvGroup@147369");
String result = XHttpUtils.postAsForm(url, param); String result = XHttpUtils.postAsForm(url, param);
context.getLogger().info("CQ_TOKEN: " + result);
JSONObject jsonObject = JSONUtil.parseObj(result); JSONObject jsonObject = JSONUtil.parseObj(result);
token = jsonObject.getStr("token"); return jsonObject.getStr("token");
}
/**
* 设置缓存
*
* @param context 上下文
* @param token 代币
*/
private void setThirdPartyConfigCache(XContext context, String token) {
ThirdPartyConfigCache cache = new ThirdPartyConfigCache(); ThirdPartyConfigCache cache = new ThirdPartyConfigCache();
cache.setCodeKey(ThirdPartyApiConstant.CQ_TOKEN_CACHE_KEY); cache.setCodeKey(ThirdPartyApiConstant.CQ_TOKEN_CACHE_KEY);
cache.setCode(token); cache.setCode(token);
cache.setValidity(90); cache.setValidity(90);
cache.setCurrentDate(new Date()); cache.setCurrentDate(DateUtil.date());
ThirdPartyConfigCache.set(context, cache); ThirdPartyConfigCache.set(context, cache);
} else {
token = exist.getCode();
}
return token;
} }
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment