|
@@ -1,6 +1,7 @@
|
|
|
package com.malk.shantai.service.impl;
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.malk.server.common.McR;
|
|
|
import com.malk.server.dingtalk.DDR_New;
|
|
@@ -14,12 +15,14 @@ import com.malk.utils.UtilToken;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.MalformedURLException;
|
|
|
import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
@@ -32,11 +35,12 @@ public class StDingProcServiceImpl implements StDingProcService {
|
|
|
@Autowired
|
|
|
private DDClient ddClient;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@Autowired
|
|
|
private StEkbConfig stEkbConfig;
|
|
|
|
|
|
+ @Value("${download.path}")
|
|
|
+ private String filePath;
|
|
|
+
|
|
|
//法人实体
|
|
|
private static Map<String,String> CORPORATION = new HashMap<>();
|
|
|
|
|
@@ -67,35 +71,76 @@ public class StDingProcServiceImpl implements StDingProcService {
|
|
|
Map map=ddClient_workflow.getProcessInstanceId(ddClient.getAccessToken(),procInstId);
|
|
|
log.info("map:{}",map);
|
|
|
Map rule=new HashMap();
|
|
|
- rule.put("TextField-K11U6U5Q","付款事由");// 标题/付款摘要
|
|
|
+ rule.put("DDSelectField_8UJMKRMLWYK0","是否推送到易快报");// 是否推送到易快报
|
|
|
+// rule.put("TextField-K11U6U5Q","付款事由");// 标题/付款事由
|
|
|
+ rule.put("TextField_18XU5XCGC4RK0","付款摘要");// 标题/付款摘要
|
|
|
rule.put("RecipientAccountField-K11U6U5P","收款信息");// 收款信息
|
|
|
rule.put("MoneyField_FMP7OAX3TZ40","付款金额");// 付款金额
|
|
|
rule.put("TextareaField_15PEUHBWFDDS0","备注");// 备注
|
|
|
rule.put("DDMultiSelectField_17IA7RJQYGWW0","付款公司");// 付款公司
|
|
|
Map data=getData(map,rule);
|
|
|
+ if( Objects.isNull(data.get("是否推送到易快报")) || data.get("是否推送到易快报").toString().equals("否")){
|
|
|
+ return;
|
|
|
+ }
|
|
|
data.put("户名", UtilMap.getMap(data,"收款信息").get("name"));// 户名
|
|
|
data.put("银行",UtilMap.getMap(data,"收款信息").get("instName"));// 银行
|
|
|
data.put("支行信息",UtilMap.getMap(data,"收款信息").get("instBranchName"));// 支行信息
|
|
|
data.put("账号",UtilMap.getMap(data,"收款信息").get("cardNo"));// 账号
|
|
|
+ data.put("省份",UtilMap.getMap(data,"收款信息").get("instProvince"));// 省份
|
|
|
+ data.put("城市",UtilMap.getMap(data,"收款信息").get("instCity"));// 城市
|
|
|
log.info("data:{}",JSONObject.toJSONString(data));
|
|
|
- String staffName=map.get("title").toString().substring(0,map.get("title").toString().indexOf("提交"));// 提交人姓名
|
|
|
+
|
|
|
+ //获取发起人userId
|
|
|
+ String userId = map.get("originatorUserId").toString();
|
|
|
+
|
|
|
+ String staffId = "";
|
|
|
+
|
|
|
+ //查询易快报中发起人是否存在
|
|
|
+ Map<String,Object> param3 = new HashMap<>();
|
|
|
+ param3.put("accessToken",getToken());
|
|
|
+
|
|
|
+ Map body3 = new HashMap<>();
|
|
|
+ body3.put("type","USERID");
|
|
|
+ body3.put("conditionIds",Arrays.asList(userId));
|
|
|
+ Map user = (Map) JSONObject.parseObject(UtilHttp.doPost(stEkbConfig.getPreUrl() + "/api/openapi/v1/staffs/getStaffIds", null, param3, body3)).getJSONArray("items").get(0);
|
|
|
+ if (Objects.isNull(user)){
|
|
|
+ log.error("易快报中发起人不存在");
|
|
|
+ staffId = "pQccdcNGsM3U00:16278700718435315";// 李溯
|
|
|
+ }else {
|
|
|
+ staffId = user.get("id").toString();
|
|
|
+ }
|
|
|
|
|
|
//查询易快报中收款账户是否存在
|
|
|
Map result = (Map) JSONObject.parseObject(UtilHttp.doGet(stEkbConfig.getPreUrl() + "/api/openapi/v2/payeeInfos",
|
|
|
null, UtilMap.map("accessToken, start, count, names, cardNos, ids, active, orderBy, orderByType", getToken(), 0, 100, data.get("户名"), data.get("账号"), null, true, "updateTime", "desc"))) ;
|
|
|
- Map account = ((List<Map>) result.get("items")).get(0);
|
|
|
System.out.println(result);
|
|
|
-
|
|
|
+ String payeeId = "";
|
|
|
+ List<Map> items = (List<Map>) result.get("items");
|
|
|
//若不存在则新增收款账户
|
|
|
- if (Objects.isNull(account)){
|
|
|
- Map<String, Object> body = UtilMap.map("sort, type, owner, name, cardNo, bank, branch, province, city, visibility",
|
|
|
- "BANK", "PUBLIC", "CORPORATION", data.get("户名"), data.get("账号"), data.get("账号"), data.get("支行"), data.get("省份"), data.get("城市"), "PUBLIC");
|
|
|
+ if (Objects.isNull(items) || items.isEmpty()){
|
|
|
+ Map<String, Object> body = new HashMap<>();
|
|
|
+ Map visibility = new HashMap();
|
|
|
+ visibility.put("fullVisible",true);
|
|
|
+
|
|
|
+ body.put("sort","BANK");
|
|
|
+ body.put("type","PUBLIC");
|
|
|
+ body.put("owner","CORPORATION");
|
|
|
+ body.put("name",data.get("户名"));
|
|
|
+ body.put("cardNo",data.get("账号"));
|
|
|
+ body.put("bank",data.get("银行"));
|
|
|
+ body.put("branch",data.get("支行信息"));
|
|
|
+ body.put("province",data.get("省份"));
|
|
|
+ body.put("city",data.get("城市"));
|
|
|
+ body.put("visibility",visibility);
|
|
|
+
|
|
|
Map<String,Object> param = new HashMap<>();
|
|
|
param.put("accessToken",getToken());
|
|
|
- String id = JSONObject.parseObject(UtilHttp.doPost(stEkbConfig.getPreUrl() + "/api/openapi/v2.1/payeeInfos", null, param, body)).getString("id");
|
|
|
+ payeeId = JSONObject.parseObject(UtilHttp.doPost(stEkbConfig.getPreUrl() + "/api/openapi/v2.1/payeeInfos", null, param, body)).getString("id");
|
|
|
//再次获取新增后的收款账户
|
|
|
- account = JSONObject.parseObject(UtilHttp.doGet(stEkbConfig.getPreUrl() + "/api/openapi/v2/payeeInfos",
|
|
|
- null, UtilMap.map("accessToken, start, count, names, cardNos, ids, active", getToken(), 0, 100, null, id, null, true))) ;
|
|
|
+/* account = JSONObject.parseObject(UtilHttp.doGet(stEkbConfig.getPreUrl() + "/api/openapi/v2/payeeInfos",
|
|
|
+ null, UtilMap.map("accessToken, start, count, names, cardNos, ids, active", getToken(), 0, 100, null, null, id, true))) ;*/
|
|
|
+ }else {
|
|
|
+ payeeId = items.get(0).get("id").toString();
|
|
|
}
|
|
|
|
|
|
//根据模板ID获取模板信息
|
|
@@ -120,12 +165,12 @@ public class StDingProcServiceImpl implements StDingProcService {
|
|
|
payMoney.put("standardUnit","元");
|
|
|
payMoney.put("standardScale",2);
|
|
|
|
|
|
- form.put("title",data.get("付款事由")); //单据标题
|
|
|
- form.put("submitterId","pQccdcNGsM3U00:153620324221442254"); //提交人ID todo lfx 暂时写死
|
|
|
+ form.put("title",data.get("付款摘要")); //单据标题
|
|
|
+ form.put("submitterId",staffId); //提交人ID
|
|
|
form.put("description",data.get("备注")); //描述
|
|
|
form.put("specificationId",specificationId); //单据模板id
|
|
|
form.put("payMoney",payMoney); //付款金额
|
|
|
- form.put("payeeId",account.get("id"));
|
|
|
+ form.put("payeeId",payeeId);
|
|
|
form.put("u_订单信息",procInstId);
|
|
|
if (CORPORATION.keySet().contains(data.get("付款公司"))){
|
|
|
form.put("法人实体",CORPORATION.get(data.get("付款公司"))); //法人实体
|
|
@@ -136,35 +181,123 @@ public class StDingProcServiceImpl implements StDingProcService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public McR commentSync(String procInstId,String state){
|
|
|
- //todo 获取附件上传到钉盘
|
|
|
-
|
|
|
- File file1 = new File("C:\\Users\\EDY\\Pictures\\1.png");
|
|
|
- File file2 = new File("C:\\Users\\EDY\\Pictures\\2.png");
|
|
|
- File file3 = new File("C:\\Users\\EDY\\Pictures\\3.png");
|
|
|
- File file4 = new File("C:\\Users\\EDY\\Pictures\\4.png");
|
|
|
- List<File> files = new ArrayList<>();
|
|
|
- files.add(file1);
|
|
|
- files.add(file2);
|
|
|
- files.add(file3);
|
|
|
- files.add(file4);
|
|
|
+ public McR commentSync(Map map){
|
|
|
+ //获取提交人
|
|
|
+ String userId = map.get("userId").toString();
|
|
|
+ DDR_New ddrNew = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/v2/user/get", null, ddClient.initTokenParams(), UtilMap.map("userid", userId), DDR_New.class);
|
|
|
+ Map result = (Map) ddrNew.getResult();
|
|
|
+ String unionId = "";
|
|
|
+ if (Objects.nonNull(result)){
|
|
|
+ unionId = result.get("unionid").toString();
|
|
|
+ }else {
|
|
|
+ unionId = "4SLghmRuGL3Gii2DHXENHlwiEiE";//李溯unionId
|
|
|
+ userId = "16278700718435315";//李溯userId
|
|
|
+ }
|
|
|
|
|
|
+ //获取附件上传到钉盘
|
|
|
+ List<String> paths = (List<String>) map.get("paths");
|
|
|
List<Map> dentries = new ArrayList<>();
|
|
|
- for (File file : files) {
|
|
|
+ for (String path : paths) {
|
|
|
+ File file = new File(path);
|
|
|
try{
|
|
|
//上传文件至钉盘
|
|
|
- Map dentry = upload(file);
|
|
|
+ Map dentry = upload(file,unionId);
|
|
|
dentries.add(dentry);
|
|
|
}catch (IOException e){
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- //新增评论 todo 提交人暂定
|
|
|
- comment(dentries,state,"344749020127590108",procInstId);
|
|
|
+
|
|
|
+ String state = map.get("state").toString();
|
|
|
+ String procInstId = map.get("procInstId").toString();
|
|
|
+
|
|
|
+ //新增评论
|
|
|
+ comment(dentries,state,userId,procInstId);
|
|
|
|
|
|
return McR.success();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map getFlowInfo(String flowId) {
|
|
|
+ //根据单据id获取单据信息
|
|
|
+ Map param = new HashMap<>();
|
|
|
+ param.put("accessToken",getToken());
|
|
|
+ param.put("flowId",flowId);
|
|
|
+
|
|
|
+ Map flow = JSONObject.parseObject(UtilHttp.doGet("https://dd2.hosecloud.com/api/openapi/v1.1/flowDetails", null, param)).getJSONObject("value");
|
|
|
+ Map form = (Map) flow.get("form");
|
|
|
+ String procInstId = form.get("u_订单信息").toString();
|
|
|
+ String submitterId = flow.get("submitterId").toString();
|
|
|
+ String userId = submitterId.substring(submitterId.indexOf(':') + 1);
|
|
|
+
|
|
|
+ String state = flow.get("state").toString();
|
|
|
+ log.info("流程状态:{}",state.toUpperCase());
|
|
|
+ if (STATUS.keySet().contains(state.toUpperCase())){
|
|
|
+ state = STATUS.get(state.toUpperCase());
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据单据id获取单据附件信息
|
|
|
+ Map param2 = new HashMap<>();
|
|
|
+ param2.put("accessToken",getToken());
|
|
|
+
|
|
|
+ Map body2 = new HashMap<>();
|
|
|
+ String[] flowIds = {flowId};
|
|
|
+ body2.put("flowIds",flowIds);
|
|
|
+
|
|
|
+ JSONArray items = JSONObject.parseObject(UtilHttp.doPost("https://dd2.hosecloud.com/api/openapi/v1/flowDetails/attachment", null, param2, body2)).getJSONArray("items");
|
|
|
+ Map item = (Map) items.get(0);
|
|
|
+ List<Map> attachmentList = (List<Map>) item.get("attachmentList");
|
|
|
+
|
|
|
+ List<String> paths = new ArrayList<>();
|
|
|
+ if (!attachmentList.isEmpty()){
|
|
|
+ for (Map attachment : attachmentList) {
|
|
|
+ if (attachment.get("type").toString().equals("flow.body")){
|
|
|
+ List<Map> attachmentUrls = (List<Map>) attachment.get("attachmentUrls");
|
|
|
+ for (Map attachmentUrl : attachmentUrls) {
|
|
|
+ //附件下载到本地
|
|
|
+ String url = attachmentUrl.get("url").toString();
|
|
|
+ String fileName = attachmentUrl.get("fileName").toString();
|
|
|
+ String path = filePath + fileName;
|
|
|
+ downloadNet(url, path);
|
|
|
+ //添加到路径列表
|
|
|
+ paths.add(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map result = new HashMap();
|
|
|
+ result.put("state",state);
|
|
|
+ result.put("procInstId",procInstId);
|
|
|
+ result.put("path",paths);
|
|
|
+ result.put("userId",userId);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下载网络文件
|
|
|
+ public void downloadNet(String netUrl, String path){
|
|
|
+ int bytesum = 0;
|
|
|
+ int byteread = 0;
|
|
|
+ try{
|
|
|
+ URL url = new URL(netUrl);
|
|
|
+ URLConnection conn = url.openConnection();
|
|
|
+ InputStream inStream = conn.getInputStream();
|
|
|
+ FileOutputStream fs = new FileOutputStream(path);
|
|
|
+ byte[] buffer = new byte[1204];
|
|
|
+ while ((byteread = inStream.read(buffer)) != -1) {
|
|
|
+ bytesum += byteread;
|
|
|
+ fs.write(buffer, 0, byteread);
|
|
|
+ }
|
|
|
+ } catch (MalformedURLException e){
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void comment(List<Map> dentries, String state, String userId, String procInstId) {
|
|
|
Map body = new HashMap<>();
|
|
|
Map fileMap = new HashMap<>();
|
|
@@ -186,23 +319,23 @@ public class StDingProcServiceImpl implements StDingProcService {
|
|
|
fileMap.put("attachments",attachments);
|
|
|
|
|
|
body.put("processInstanceId",procInstId);
|
|
|
- body.put("text","付款状态:" + STATUS.get(state));
|
|
|
+ body.put("text","付款状态:" + state);
|
|
|
body.put("commentUserId",userId);
|
|
|
body.put("file",fileMap);
|
|
|
|
|
|
UtilHttp.doPost("https://api.dingtalk.com/v1.0/workflow/processInstances/comments",ddClient.initTokenHeader(),null,body);
|
|
|
}
|
|
|
|
|
|
- private Map upload(File file) throws IOException {
|
|
|
+ private Map upload(File file,String unionId) throws IOException {
|
|
|
//获取文件上传信息
|
|
|
- String parentDentryUuid = "ZQYprEoWonmdnzdOFpklzk1a81waOeDk";// poc目录 api测试上传/附件
|
|
|
+// String parentDentryUuid = "ZQYprEoWonmdnzdOFpklzk1a81waOeDk";// poc目录 api测试上传/附件
|
|
|
+ String parentDentryUuid = "YQBnd5ExVEowejBQtZ1v6wO28yeZqMmz";// 杉泰目录 /技术文档/易快报银企直连
|
|
|
Map<String,Object> param1 = new HashMap<>();
|
|
|
- param1.put("unionId","5PK3cMYhiStn7HDoNabweEgiEiE");//wzy
|
|
|
+ param1.put("unionId",unionId);
|
|
|
Map body1 = new HashMap<>();
|
|
|
body1.put("protocol","HEADER_SIGNATURE");
|
|
|
DDR_New ddrNew = (DDR_New) UtilHttp.doPost("https://api.dingtalk.com//v2.0/storage/spaces/files/" + parentDentryUuid + "/uploadInfos/query", ddClient.initTokenHeader(), param1, body1, DDR_New.class);
|
|
|
String uploadKey = ddrNew.getUploadKey();
|
|
|
- String storageDriver = ddrNew.getStorageDriver();
|
|
|
Map headerSignatureInfo = ddrNew.getHeaderSignatureInfo();
|
|
|
Map<String,String> headers = (Map<String,String>) headerSignatureInfo.get("headers");
|
|
|
String resourceUrl = ((List<String>) headerSignatureInfo.get("resourceUrls")).get(0);
|
|
@@ -241,7 +374,7 @@ public class StDingProcServiceImpl implements StDingProcService {
|
|
|
|
|
|
//提交文件
|
|
|
Map<String,Object> param2 = new HashMap<>();
|
|
|
- param2.put("unionId","5PK3cMYhiStn7HDoNabweEgiEiE");//wzy
|
|
|
+ param2.put("unionId",unionId);
|
|
|
Map body2 = new HashMap<>();
|
|
|
body2.put("uploadKey",uploadKey);
|
|
|
body2.put("name",file.getName());
|