|
|
@@ -7,9 +7,7 @@ import com.malk.boyang.utils.HTTPHelper;
|
|
|
import com.malk.server.common.McR;
|
|
|
import com.malk.server.dingtalk.DDConf;
|
|
|
import com.malk.server.dingtalk.DDR_New;
|
|
|
-import com.malk.service.dingtalk.DDClient;
|
|
|
-import com.malk.service.dingtalk.DDClient_Storage;
|
|
|
-import com.malk.service.dingtalk.DDClient_Workflow;
|
|
|
+import com.malk.service.dingtalk.*;
|
|
|
import com.malk.utils.UtilHttp;
|
|
|
import com.malk.utils.UtilMap;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -20,8 +18,10 @@ import okio.Sink;
|
|
|
import org.apache.commons.codec.binary.Hex;
|
|
|
import org.apache.commons.codec.digest.HmacAlgorithms;
|
|
|
import org.apache.commons.codec.digest.HmacUtils;
|
|
|
+import org.apache.logging.log4j.util.Strings;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.*;
|
|
|
@@ -36,9 +36,15 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
@Autowired
|
|
|
private DDClient ddClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DDConf ddConf;
|
|
|
+
|
|
|
@Autowired
|
|
|
private DDClient_Workflow ddClient_workflow;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DDClient_Personnel ddClient_personnel;
|
|
|
+
|
|
|
@Value("${dingtalk.downloadPath}")
|
|
|
private String downloadPath;
|
|
|
|
|
|
@@ -58,6 +64,7 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
final static String projectId = "1000004";// 应用ID
|
|
|
final static String secret = "96Uh7CR83NkN3TA6";// 应用密钥
|
|
|
final static String businessTypeCode = "889726e889ab84fea3514748d6df565c";// 钉钉对接测试业务模板
|
|
|
+ final static String organizationCode = "b60a9c18b8cc4ecc80e30f36b4267a68";// 宁波博洋家纺集团有限公司
|
|
|
final static String host = "http://122.227.225.202:9011/";// 接口调用域名
|
|
|
final static String intranet_host = "http://11.0.11.62/";// 接口调用域名(内网)
|
|
|
|
|
|
@@ -75,6 +82,7 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
String remark = "";
|
|
|
String url = "https://aflow.dingtalk.com/dingtalk/web/query/pchomepage.htm?from=oflow&op=true&corpid=ding76a1e955807327f7f5bf40eda33b7ba0#/plainapproval?procInstId="+processInstanceId;
|
|
|
List<String> sealTypeCodeList = new ArrayList<>();
|
|
|
+ List<Map> companyList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
for (Map formComponentValue : formComponentValues) {
|
|
|
@@ -100,8 +108,8 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
String fileQty = UtilMap.getString(formComponentValue, "value");
|
|
|
break;
|
|
|
case "DDMultiSelectField_1L3KU3TLX6PS0"://印章所属公司
|
|
|
- String companyStr = UtilMap.getString(formComponentValue, "value");
|
|
|
- List<Map> companyList = (List<Map>) JSONObject.parse(companyStr);
|
|
|
+ String companyStr = UtilMap.getString(formComponentValue, "extValue");
|
|
|
+ companyList = (List<Map>) JSONObject.parse(companyStr);
|
|
|
break;
|
|
|
case "DDMultiSelectField_1FW3TFDTJ6V40"://印章类型
|
|
|
String yzlxStr = UtilMap.getString(formComponentValue, "value");
|
|
|
@@ -150,6 +158,57 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //查询钉钉用户信息
|
|
|
+ String name = "";
|
|
|
+ String mobile = "";
|
|
|
+ String originatorUserId = UtilMap.getString(result, "originatorUserId");
|
|
|
+
|
|
|
+ List<Map> employeeInfos = ddClient_personnel.getEmployeeInfos(ddClient.getAccessToken(), Arrays.asList(originatorUserId), ddConf.getAgentId(), Arrays.asList("sys00-name", "sys00-mobile"));
|
|
|
+ Map employeeInfo = employeeInfos.get(0);
|
|
|
+
|
|
|
+ List<Map> fieldDataList = UtilMap.getList(employeeInfo, "field_data_list");
|
|
|
+
|
|
|
+ for (Map fieldData : fieldDataList) {
|
|
|
+ String fieldCode = UtilMap.getString(fieldData, "field_code");
|
|
|
+ List<Map> fieldValueList = UtilMap.getList(fieldData, "field_value_list");
|
|
|
+
|
|
|
+ switch (fieldCode){
|
|
|
+ case "sys00-name":
|
|
|
+ name = UtilMap.getString(fieldValueList.get(0),"value");
|
|
|
+ break;
|
|
|
+ case "sys00-mobile":
|
|
|
+ mobile = UtilMap.getString(fieldValueList.get(0),"value").replace("+86-","");
|
|
|
+ break;
|
|
|
+ default:break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String eqbUserCode = "";
|
|
|
+
|
|
|
+ //查询钉钉用户在e签宝是否存在
|
|
|
+ Map body = new HashMap();
|
|
|
+ body.put("name", name);
|
|
|
+ body.put("mobile", mobile);
|
|
|
+ List<Map> eqbUsers = (List<Map>) eqbPost(host + "manage/v1/innerUsers/detail", body);
|
|
|
+ if (!eqbUsers.isEmpty()){
|
|
|
+ Map eqbUser = eqbUsers.get(0);
|
|
|
+
|
|
|
+ eqbUserCode = UtilMap.getString(eqbUser, "userCode");
|
|
|
+ }else {
|
|
|
+ //新增e签宝用户
|
|
|
+ Map eqbUser = new HashMap();
|
|
|
+ eqbUser.put("name", name);
|
|
|
+ eqbUser.put("mobile", mobile);
|
|
|
+ eqbUser.put("customAccountNo", mobile);
|
|
|
+ eqbUser.put("mainOrganizationCode", organizationCode);//默认组织账号
|
|
|
+
|
|
|
+ Map map1 = (Map) eqbPost(host + "manage/v1/innerUsers/create",Arrays.asList(eqbUser));
|
|
|
+
|
|
|
+ List<Map> successData = UtilMap.getList(map1, "successData");
|
|
|
+
|
|
|
+ eqbUserCode = UtilMap.getString(successData.get(0), "userCode");
|
|
|
+ }
|
|
|
+
|
|
|
// 创建主Map
|
|
|
Map<String, Object> requestMap = new HashMap<>();
|
|
|
|
|
|
@@ -158,7 +217,7 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
requestMap.put("businessNo", processInstanceId);
|
|
|
requestMap.put("businessTypeCode", businessTypeCode);
|
|
|
requestMap.put("remark", remark);
|
|
|
- requestMap.put("redirectUrl", url);
|
|
|
+// requestMap.put("redirectUrl", url);
|
|
|
|
|
|
// 2. manualConfig 嵌套对象
|
|
|
Map<String, Object> manualConfig = new HashMap<>();
|
|
|
@@ -174,12 +233,12 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
|
|
|
// 3. initiatorInfo 嵌套对象
|
|
|
Map<String, Object> initiatorInfo = new HashMap<>();
|
|
|
- initiatorInfo.put("userCode", "wozy");
|
|
|
- initiatorInfo.put("customAccountNo", "");
|
|
|
+ initiatorInfo.put("userCode", eqbUserCode);
|
|
|
+ /*initiatorInfo.put("customAccountNo", "");
|
|
|
initiatorInfo.put("departmentCode", "");
|
|
|
initiatorInfo.put("customDepartmentNo", "");
|
|
|
- initiatorInfo.put("organizationCode", "b60a9c18b8cc4ecc80e30f36b4267a68");
|
|
|
- initiatorInfo.put("customOrgNo", "");
|
|
|
+ initiatorInfo.put("organizationCode", "");
|
|
|
+ initiatorInfo.put("customOrgNo", "");*/
|
|
|
|
|
|
requestMap.put("initiatorInfo", initiatorInfo);
|
|
|
|
|
|
@@ -201,16 +260,19 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
// 5. signerInfos 列表
|
|
|
List<Map<String, Object>> signerInfos = new ArrayList<>();
|
|
|
|
|
|
- Map<String, Object> signer = new HashMap<>();
|
|
|
- signer.put("userType", "1");
|
|
|
- signer.put("userCode", "wozy");
|
|
|
- signer.put("organizationCode", "b60a9c18b8cc4ecc80e30f36b4267a68");
|
|
|
- signer.put("signNode", 1);
|
|
|
- signer.put("signMode", "0");
|
|
|
- signer.put("signOrder", 1);
|
|
|
-// signer.put("sealTypeCode", String.join(",",sealTypeCodeList));
|
|
|
+ for (int i = 0; i < companyList.size(); i++) {
|
|
|
+ Map<String, Object> signer = new HashMap<>();
|
|
|
+ signer.put("userType", "1");
|
|
|
+ signer.put("userCode", "wangze");
|
|
|
+ signer.put("organizationCode", UtilMap.getString(companyList.get(i),"key"));
|
|
|
+ signer.put("signNode", 1);
|
|
|
+ signer.put("signMode", "0");
|
|
|
+ signer.put("signOrder", i + 1);
|
|
|
+// signer.put("sealTypeCode", String.join(",",sealTypeCodeList));
|
|
|
+
|
|
|
+ signerInfos.add(signer);
|
|
|
+ }
|
|
|
|
|
|
- signerInfos.add(signer);
|
|
|
requestMap.put("signerInfos", signerInfos);
|
|
|
|
|
|
// 打印结果(可选)
|
|
|
@@ -228,14 +290,18 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
|
|
|
String newSigningAreaPageUrl = signingAreaPageUrl.replace(intranet_host,host);
|
|
|
|
|
|
- comment(processInstanceId,"344749020127590108","签署区设置地址:"+newSigningAreaPageUrl,null);
|
|
|
+ comment(processInstanceId,originatorUserId,"签署区设置地址:"+newSigningAreaPageUrl,null);
|
|
|
|
|
|
return McR.success();
|
|
|
}
|
|
|
|
|
|
+ @Async
|
|
|
@Override
|
|
|
public void signed(String processInstanceId,String signFlowId) {
|
|
|
try {
|
|
|
+ Map result = ddClient_workflow.getProcessInstanceId(ddClient.getAccessToken(), processInstanceId);
|
|
|
+ String originatorUserId = UtilMap.getString(result, "originatorUserId");
|
|
|
+
|
|
|
// 获取签署流程进度详情
|
|
|
Map data = (Map) eqbGet(host + "/esign-signs/v1/signFlow/signDetail?signFlowId=" + signFlowId);
|
|
|
List<Map> signFiles = UtilMap.getList(data, "signFiles");
|
|
|
@@ -260,17 +326,19 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
//todo 签署后文件上传到钉盘
|
|
|
Map dentry = uploadDdFile(spaceId, parentDentryUuid, downloadPath + signedFileName, operatorUnionId);
|
|
|
//todo 审批单添加评论
|
|
|
- comment(processInstanceId,operator,"接口测试 "+ fileName + "已签署",Arrays.asList(dentry));
|
|
|
+ comment(processInstanceId,originatorUserId,"接口测试 "+ fileName + "已签署",Arrays.asList(dentry));
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- String msg = MessageFormat.format("请求签名鉴权方式调用接口出现异常: {0}", e.getMessage());
|
|
|
- System.out.println(msg);
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public McR getOrganization(String name) {
|
|
|
+ if (Strings.isBlank(name)){
|
|
|
+ return McR.success(new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
Map body = new HashMap();
|
|
|
body.put("name",name);
|
|
|
List<Map> data = (List<Map>) eqbPost(host + "manage/v1/innerOrganizations/detail",body);
|
|
|
@@ -278,19 +346,37 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
List<Map> options = new ArrayList<>();
|
|
|
|
|
|
for (Map datum : data) {
|
|
|
- String organizationName = UtilMap.getString(datum, "name");
|
|
|
- String organizationCode = UtilMap.getString(datum, "organizationCode");
|
|
|
+ String organizationType = UtilMap.getString(datum, "organizationType");
|
|
|
|
|
|
- Map option = new HashMap();
|
|
|
- option.put("label",organizationName);
|
|
|
- option.put("value",organizationCode);
|
|
|
+ if ("COMPANY".equals(organizationType)){
|
|
|
+ String organizationName = UtilMap.getString(datum, "name");
|
|
|
+ String organizationCode = UtilMap.getString(datum, "organizationCode");
|
|
|
|
|
|
- options.add(option);
|
|
|
+ Map option = new HashMap();
|
|
|
+ option.put("label",organizationName);
|
|
|
+ option.put("value",organizationCode);
|
|
|
+
|
|
|
+ options.add(option);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return McR.success(options);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void start(String processInstanceId, String signPreUrl) {
|
|
|
+ try {
|
|
|
+ Map result = ddClient_workflow.getProcessInstanceId(ddClient.getAccessToken(), processInstanceId);
|
|
|
+ String originatorUserId = UtilMap.getString(result, "originatorUserId");
|
|
|
+
|
|
|
+ //审批单添加评论
|
|
|
+ String signPreUrl2 = signPreUrl.replace(intranet_host, host);
|
|
|
+ comment(processInstanceId,originatorUserId,"签署预览地址:" + signPreUrl2,null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//下载钉钉OA审批单附件
|
|
|
private void downloadDdFile(String processInstanceId,String fileId,String downloadPath){
|
|
|
try {
|
|
|
@@ -534,7 +620,7 @@ public class BoyangServiceImpl implements BoyangService {
|
|
|
}
|
|
|
|
|
|
//e签宝-post请求(application/json)
|
|
|
- private Object eqbPost(String url,Map body){
|
|
|
+ private Object eqbPost(String url,Object body){
|
|
|
try {
|
|
|
// 请求Body体数据
|
|
|
String reqBodyData = JSONObject.toJSONString(body);
|