|
@@ -1,5 +1,6 @@
|
|
|
package com.kingdee.eas.custom.shuiyou.uitls;
|
|
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -8,7 +9,11 @@ import com.kingdee.bos.dao.IObjectPK;
|
|
|
import com.kingdee.bos.util.BOSUuid;
|
|
|
import com.kingdee.eas.base.permission.UserInfo;
|
|
|
import com.kingdee.eas.common.EASBizException;
|
|
|
+import com.kingdee.eas.custom.shuiyou.RequestStateEnum;
|
|
|
+import com.kingdee.eas.custom.shuiyou.RequestTypeEnum;
|
|
|
import com.kingdee.eas.custom.shuiyou.interfaceiog.LogInfoFactory;
|
|
|
+import com.kingdee.eas.custom.shuiyou.task.TaskFactory;
|
|
|
+import com.kingdee.eas.custom.shuiyou.task.TaskInfo;
|
|
|
import okhttp3.*;
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
@@ -46,7 +51,24 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
{
|
|
|
@Override
|
|
|
protected String _backTask(Context ctx, String url, String requestId, String osfServiceName, String backParam) throws BOSException {
|
|
|
- return super._backTask(ctx, url, requestId, osfServiceName, backParam);
|
|
|
+ super._backTask(ctx, url, requestId, osfServiceName, backParam);
|
|
|
+ TaskInfo taskInfo = new TaskInfo();
|
|
|
+ try{
|
|
|
+ taskInfo.setUrl(url);
|
|
|
+ taskInfo.setRequestId(requestId);
|
|
|
+ taskInfo.setParam(backParam);
|
|
|
+ taskInfo.setOsfServiceName(osfServiceName);
|
|
|
+ taskInfo.setRequestType(RequestTypeEnum.GET);
|
|
|
+ taskInfo.setRequestState(RequestStateEnum.NotStarted);
|
|
|
+ taskInfo.setName("获取反馈");
|
|
|
+ String number = SYUCronTaskUtil.getInstance().getSnowflake().nextIdStr();
|
|
|
+ taskInfo.setNumber(number);
|
|
|
+ IObjectPK pk = TaskFactory.getLocalInstance(ctx).save(taskInfo);
|
|
|
+ taskInfo.setId(BOSUuid.read(pk.toString()));
|
|
|
+ } catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return taskInfo.getId().toString();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -99,18 +121,83 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
}
|
|
|
}catch (IOException e){
|
|
|
e.printStackTrace();
|
|
|
+ logger.error(e);
|
|
|
+ logInfo.setErrorInfo(e.getMessage());//接口地址
|
|
|
}finally {
|
|
|
logInfo.setInterfaceAddress(url);//接口地址
|
|
|
logInfo.setInterfaceName(url);//接口名
|
|
|
logInfo.setInParameter(param);//入参
|
|
|
logInfo.setOutParameter(result);//回参
|
|
|
+ this._log(ctx,logInfo);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected String _get(Context ctx, String url, String param) throws BOSException {
|
|
|
- return super._get(ctx, url, param);
|
|
|
+ super._get(ctx, url, param);
|
|
|
+ String result = "";
|
|
|
+ LogInfoInfo logInfo = new LogInfoInfo();
|
|
|
+ try {
|
|
|
+ //日志
|
|
|
+ logInfo.setEntrance(this.getClass().getName());//入口
|
|
|
+ Long timestampLong = System.currentTimeMillis();
|
|
|
+ UserInfo userInfo = (UserInfo)ctx.get("UserInfo");
|
|
|
+ logInfo.setCreator(userInfo);
|
|
|
+ Timestamp timestamp = new Timestamp(timestampLong);
|
|
|
+ logInfo.setCreateTime(timestamp);
|
|
|
+ logInfo.setLastUpdateTime(timestamp);
|
|
|
+ logInfo.setLastUpdateUser(userInfo);
|
|
|
+ logInfo.setBizDate(timestamp);
|
|
|
+
|
|
|
+ JSONObject paramMap = JSONUtil.parseObj(param);
|
|
|
+ //获取配置文件
|
|
|
+ Map<String,String> propt = this._getConfig(ctx);
|
|
|
+ if(StrUtil.isBlank(paramMap.getStr("timestamp"))){
|
|
|
+
|
|
|
+ paramMap.set("timestamp",String.valueOf(timestampLong));
|
|
|
+ }
|
|
|
+ if(StrUtil.isBlank(paramMap.getStr("xReqNonce"))){
|
|
|
+ String xReqNonce = UUID.randomUUID().toString().replace("-", "");//调用者生成的 UUID(32位),结合时间戳timestamp 防重放
|
|
|
+ paramMap.set("xReqNonce",xReqNonce);
|
|
|
+ }
|
|
|
+ param=JSONUtil.toJsonStr(paramMap);
|
|
|
+ String signature = this._getSignature(ctx,propt,paramMap);
|
|
|
+ Map<String,String> headers = new HashMap<String,String>();
|
|
|
+ headers.put("appKey",propt.get("appKey"));
|
|
|
+ headers.put("timestamp",paramMap.getStr("timestamp"));
|
|
|
+ headers.put("version",propt.get("version"));
|
|
|
+ headers.put("xReqNonce",paramMap.getStr("xReqNonce"));
|
|
|
+ headers.put("signature",signature);
|
|
|
+ OkHttpClient client = new OkHttpClient();
|
|
|
+ HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
|
|
|
+ for(Map.Entry<String,Object> entry : paramMap.entrySet() ){
|
|
|
+ Optional<Object> op = Optional.ofNullable(entry.getValue());
|
|
|
+ urlBuilder.addQueryParameter(entry.getKey(), op.orElse("").toString());
|
|
|
+ }
|
|
|
+ url = urlBuilder.build().toString();
|
|
|
+ Request sYRequest = new Request.Builder()
|
|
|
+ .url(url).headers(Headers.of(headers))
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ Response sYResponse = client.newCall(sYRequest).execute();
|
|
|
+ if (sYResponse.isSuccessful()) {
|
|
|
+ result = sYResponse.body().string();
|
|
|
+ }else {
|
|
|
+ logInfo.setErrorInfo(sYResponse.message());//错误信息
|
|
|
+ }
|
|
|
+ }catch (IOException e){
|
|
|
+ e.printStackTrace();
|
|
|
+ logger.error(e);
|
|
|
+ logInfo.setErrorInfo(e.getMessage());//接口地址
|
|
|
+ }finally {
|
|
|
+ logInfo.setInterfaceAddress(url);//接口地址
|
|
|
+ logInfo.setInterfaceName(url);//接口名
|
|
|
+ logInfo.setInParameter(param);//入参
|
|
|
+ logInfo.setOutParameter(result);//回参
|
|
|
+ this._log(ctx,logInfo);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
private static Logger logger =
|
|
@@ -196,6 +283,7 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
@Override
|
|
|
protected void _initConfig(Context ctx, String filePath) throws BOSException {
|
|
|
super._initConfig(ctx, filePath);
|
|
|
+
|
|
|
SYUConfigUtil.getInstance().initConfig(filePath);
|
|
|
}
|
|
|
|
|
@@ -212,6 +300,12 @@ public class SYUtilsFacadeControllerBean extends AbstractSYUtilsFacadeController
|
|
|
return logInfo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取配置文件
|
|
|
+ * @param ctx
|
|
|
+ * @return
|
|
|
+ * @throws BOSException
|
|
|
+ */
|
|
|
@Override
|
|
|
protected Map _getConfig(Context ctx) throws BOSException {
|
|
|
super._getConfig(ctx);
|