|
@@ -3,21 +3,27 @@ package nckd.jimin.jyyy.bd.plugin.msg.ecology;
|
|
import com.alibaba.druid.util.StringUtils;
|
|
import com.alibaba.druid.util.StringUtils;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
import kd.bos.dataentity.entity.DynamicObject;
|
|
|
|
+import kd.bos.dataentity.entity.DynamicObjectCollection;
|
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
|
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
|
|
import kd.bos.entity.plugin.args.BeforeOperationArgs;
|
|
import kd.bos.entity.plugin.args.BeforeOperationArgs;
|
|
import kd.bos.exception.KDException;
|
|
import kd.bos.exception.KDException;
|
|
import kd.bos.logging.Log;
|
|
import kd.bos.logging.Log;
|
|
import kd.bos.logging.LogFactory;
|
|
import kd.bos.logging.LogFactory;
|
|
|
|
+import kd.bos.orm.query.QCP;
|
|
|
|
+import kd.bos.orm.query.QFilter;
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
|
import kd.bos.workflow.exception.WFErrorCode;
|
|
import kd.bos.workflow.exception.WFErrorCode;
|
|
|
|
+import kd.bos.workflow.exception.WFMessageServiceException;
|
|
import kd.sdk.plugin.Plugin;
|
|
import kd.sdk.plugin.Plugin;
|
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
public class EcologyOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
|
public class EcologyOpPlugin extends AbstractOperationServicePlugIn implements Plugin {
|
|
private static Log logger = LogFactory.getLog(EcologyOpPlugin.class);
|
|
private static Log logger = LogFactory.getLog(EcologyOpPlugin.class);
|
|
@@ -35,15 +41,33 @@ public class EcologyOpPlugin extends AbstractOperationServicePlugIn implements P
|
|
String operationKey = e.getOperationKey();
|
|
String operationKey = e.getOperationKey();
|
|
if (StringUtils.equals( "sendmsg",operationKey)){
|
|
if (StringUtils.equals( "sendmsg",operationKey)){
|
|
List<DynamicObject> listObj = new ArrayList<>();
|
|
List<DynamicObject> listObj = new ArrayList<>();
|
|
- String selectField = "nckd_ecologyurl, nckd_ecologycode, nckd_ecologmsgcode, nckd_ecologappid, nckd_ecologsecret, nckd_ecologspk, nckd_ecologyurlmsg";
|
|
|
|
- DynamicObject[] commonParams = BusinessDataServiceHelper.load("nckd_commonparams", selectField, null);
|
|
|
|
- String FANWEI_URL = "";
|
|
|
|
- if(commonParams.length > 0){
|
|
|
|
- FANWEI_URL = commonParams[0].getString("nckd_ecologyurl");
|
|
|
|
- } else {
|
|
|
|
|
|
+
|
|
|
|
+ String selectField = "nckd_entryentity.nckd_key, nckd_entryentity.nckd_value";
|
|
|
|
+
|
|
|
|
+ QFilter qFilter = new QFilter("number", QCP.equals, "fanwei");
|
|
|
|
+ DynamicObject commonParam = BusinessDataServiceHelper.loadSingle("nckd_commonparams", selectField, qFilter.toArray());
|
|
|
|
+ if (ObjectUtils.isEmpty(commonParam)) {
|
|
|
|
+ errMsg.append("未配置泛微相关参数nckd_commonparams");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DynamicObjectCollection entryentity = commonParam.getDynamicObjectCollection("nckd_entryentity");
|
|
|
|
+ Map<String, String> mapentity = entryentity.stream().collect(Collectors.toMap(k -> k.getString("nckd_key"), v -> v.getString("nckd_value")));
|
|
|
|
+
|
|
|
|
+ if(mapentity == null ){
|
|
|
|
+ errMsg.append("未配置泛微相关参数nckd_entryentity");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ String sendFlowUrl = mapentity.get("sendflow");
|
|
|
|
+ String secretkey = mapentity.get("secret_key");
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isEmpty(sendFlowUrl) || StringUtils.isEmpty(secretkey)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String token = FanweiCommonUtil.getFanWeiToken(true);
|
|
|
|
+
|
|
for(int i = 0; i < dynamicObjects.length; i++) {
|
|
for(int i = 0; i < dynamicObjects.length; i++) {
|
|
String id = dynamicObjects[i].getPkValue().toString();
|
|
String id = dynamicObjects[i].getPkValue().toString();
|
|
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(id, KEY_ENTITY_LOG);
|
|
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(id, KEY_ENTITY_LOG);
|
|
@@ -58,33 +82,56 @@ public class EcologyOpPlugin extends AbstractOperationServicePlugIn implements P
|
|
}
|
|
}
|
|
|
|
|
|
JSONObject fanweiBodyData = JSONObject.parseObject(dynamicObject.getString("nckd_senddata_tag"));
|
|
JSONObject fanweiBodyData = JSONObject.parseObject(dynamicObject.getString("nckd_senddata_tag"));
|
|
-// FANWEI_URL = dynamicObject.getString("nckd_sendurl");
|
|
|
|
- String url = FANWEI_URL + "/rest/ofs/ReceiveRequestInfoByJson";
|
|
|
|
- JSONObject result = doPostByHttpClient(url, fanweiBodyData);
|
|
|
|
- if (result == null) {
|
|
|
|
- throw new KDException(WFErrorCode.httpRequestWrongResponse(), new Object[]{result != null ? result.toJSONString() : "result is null!"});
|
|
|
|
|
|
+
|
|
|
|
+ String url = sendFlowUrl + "?access_token=" + token + "&secret_key=" + secretkey;
|
|
|
|
+
|
|
|
|
+ JSONObject returnObj = doPostByHttpClient(url, fanweiBodyData);
|
|
|
|
+ if (returnObj == null) {
|
|
|
|
+ throw new KDException(WFErrorCode.httpRequestWrongResponse(), new Object[]{returnObj != null ? returnObj.toJSONString() : "return value is null!"});
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String result = returnObj.toJSONString();
|
|
|
|
+
|
|
|
|
+ if(kd.bos.util.StringUtils.isEmpty(result)){
|
|
|
|
+ logger.info("重发待办异常: 接口返回为空");
|
|
|
|
+ throw new WFMessageServiceException("创建泛微待办异常: 接口返回为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject msgObj = JSONObject.parseObject(result);
|
|
|
|
+ if(msgObj.get("message") == null){
|
|
|
|
+ logger.info("重发待办异常: 接口返回message为空");
|
|
|
|
+ throw new WFMessageServiceException("创建泛微待办异常: 接口返回为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONObject message = msgObj.getJSONObject("message");
|
|
|
|
+
|
|
|
|
+ if(message.get("errcode") == null){
|
|
|
|
+ logger.info("重发待办异常: 接口返回errorcode为空");
|
|
|
|
+ throw new WFMessageServiceException("创建泛微待办异常: 接口返回为空");
|
|
}
|
|
}
|
|
|
|
|
|
String sendStatus = "fail";
|
|
String sendStatus = "fail";
|
|
- //失败
|
|
|
|
- if ("1".equals(result.getString("operResult"))) {
|
|
|
|
|
|
+ String code = message.getString("errcode");
|
|
|
|
+ if(!"200".equals(code)) {
|
|
|
|
+ String errCode = message.getString("errcode") == null ? "" : message.getString("errcode");
|
|
|
|
+ String msg = message.getString("errmsg") == null ? "" : message.getString("errmsg");
|
|
|
|
+
|
|
|
|
+ logger.info("EcologyOpPlugin:待办(" + dynamicObject.getString("number") + ")重发失败" + msg);
|
|
|
|
+ errMsg.append(dynamicObject.getString("number")).append(":").append("重发失败!").append(msg).append("\r\n");
|
|
|
|
+ } else {
|
|
sendStatus = "success";
|
|
sendStatus = "success";
|
|
logger.info("EcologyOpPlugin:待办(" + dynamicObject.getString("number") + ")重发成功!");
|
|
logger.info("EcologyOpPlugin:待办(" + dynamicObject.getString("number") + ")重发成功!");
|
|
errMsg.append(dynamicObject.getString("number")).append(":").append("重发成功!").append("\r\n");
|
|
errMsg.append(dynamicObject.getString("number")).append(":").append("重发成功!").append("\r\n");
|
|
- } else {
|
|
|
|
- logger.info("EcologyOpPlugin:待办(" + dynamicObject.getString("number") + ")重发失败" + result.getString("message"));
|
|
|
|
- errMsg.append(dynamicObject.getString("number")).append(":").append("重发失败!").append("\r\n");
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- String response = result.toJSONString();
|
|
|
|
- if (response.length() < 200) {
|
|
|
|
- dynamicObject.set("nckd_resultdata", response);
|
|
|
|
|
|
+ if (result.length() < 200) {
|
|
|
|
+ dynamicObject.set("nckd_resultdata", result);
|
|
} else {
|
|
} else {
|
|
- dynamicObject.set("nckd_resultdata", response.substring(0, 200) + "...");
|
|
|
|
|
|
+ dynamicObject.set("nckd_resultdata", result.substring(0, 200) + "...");
|
|
}
|
|
}
|
|
- dynamicObject.set("nckd_resultdata_tag", response);
|
|
|
|
|
|
+ dynamicObject.set("nckd_resultdata_tag", result);
|
|
dynamicObject.set("nckd_sendstatus", sendStatus);
|
|
dynamicObject.set("nckd_sendstatus", sendStatus);
|
|
- dynamicObject.set("nckd_sendurl", FANWEI_URL);
|
|
|
|
|
|
+ dynamicObject.set("nckd_sendurl", sendFlowUrl);
|
|
|
|
|
|
listObj.add(dynamicObject);
|
|
listObj.add(dynamicObject);
|
|
|
|
|