|
@@ -0,0 +1,291 @@
|
|
|
+package com.malk.shantai.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.malk.server.common.McR;
|
|
|
+import com.malk.server.dingtalk.DDR_New;
|
|
|
+import com.malk.shantai.config.StEkbConfig;
|
|
|
+import com.malk.shantai.service.StDingProcService;
|
|
|
+import com.malk.service.dingtalk.DDClient;
|
|
|
+import com.malk.service.dingtalk.DDClient_Workflow;
|
|
|
+import com.malk.utils.UtilHttp;
|
|
|
+import com.malk.utils.UtilMap;
|
|
|
+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.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class StDingProcServiceImpl implements StDingProcService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DDClient_Workflow ddClient_workflow;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DDClient ddClient;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StEkbConfig stEkbConfig;
|
|
|
+
|
|
|
+ //法人实体
|
|
|
+ private static Map<String,String> CORPORATION = new HashMap<>();
|
|
|
+
|
|
|
+ //任务状态
|
|
|
+ private static Map<String,String> STATUS = new HashMap<>();
|
|
|
+
|
|
|
+ static{
|
|
|
+ CORPORATION.put("杉泰健康管理(上海)有限公司","ID01tX0xhMwgbR");
|
|
|
+ CORPORATION.put("上海广慈太保互联网医院有限公司","LY4cw6EvcNZQ00");
|
|
|
+ CORPORATION.put("苏州杉泰大药房有限公司","ID_3IzESoE1lxM");
|
|
|
+ CORPORATION.put("成都杉泰互联网医院有限公司","zsIcw6E-tcIM00");
|
|
|
+ CORPORATION.put("海南杉泰健康科技有限公司","kcwcw6F3esco00");
|
|
|
+ CORPORATION.put("上海杉泰健康科技有限公司","SdEcw6EvcN9U00");
|
|
|
+
|
|
|
+ STATUS.put("APPROVING","待审批");
|
|
|
+ STATUS.put("PAYING","待支付");
|
|
|
+ STATUS.put("PROCESSING","处理中(支付中)");
|
|
|
+ STATUS.put("PROCESSED","已处理(审批完成、已支付)");
|
|
|
+ STATUS.put("CANCELED","待办被取消");
|
|
|
+ STATUS.put("SENDING","待寄送");
|
|
|
+ STATUS.put("RECEIVING","待收单");
|
|
|
+ STATUS.put("RECEIVING_EXCEP","收单异常");
|
|
|
+ STATUS.put("REQUISITION_PAID","临时状态(申请单支付时消息发送)");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void fkdSync(String procInstId) {
|
|
|
+ Map map=ddClient_workflow.getProcessInstanceId(ddClient.getAccessToken(),procInstId);
|
|
|
+ log.info("map:{}",map);
|
|
|
+ Map rule=new HashMap();
|
|
|
+ rule.put("TextField-K11U6U5Q","付款事由");// 标题/付款摘要
|
|
|
+ rule.put("RecipientAccountField-K11U6U5P","收款信息");// 收款信息
|
|
|
+ rule.put("MoneyField_FMP7OAX3TZ40","付款金额");// 付款金额
|
|
|
+ rule.put("TextareaField_15PEUHBWFDDS0","备注");// 备注
|
|
|
+ rule.put("DDMultiSelectField_17IA7RJQYGWW0","付款公司");// 付款公司
|
|
|
+ Map data=getData(map,rule);
|
|
|
+ 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"));// 账号
|
|
|
+ log.info("data:{}",JSONObject.toJSONString(data));
|
|
|
+ String staffName=map.get("title").toString().substring(0,map.get("title").toString().indexOf("提交"));// 提交人姓名
|
|
|
+
|
|
|
+ //查询易快报中收款账户是否存在
|
|
|
+ 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);
|
|
|
+
|
|
|
+ //若不存在则新增收款账户
|
|
|
+ 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");
|
|
|
+ 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");
|
|
|
+ //再次获取新增后的收款账户
|
|
|
+ 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))) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据模板ID获取模板信息
|
|
|
+ String id="ID01yVMv53gDSL";// "对外付款单"模板id
|
|
|
+ Map template = (Map) JSONObject.parseObject(HttpUtil.get(stEkbConfig.getPreUrl().concat("/api/openapi/v2/specifications/byIds/[").concat(id).concat("]"), UtilMap.map("accessToken, type, start, count", getToken(), "payment", 0, 10))).getJSONArray("items").get(0);
|
|
|
+ String specificationId = template.get("id").toString();
|
|
|
+
|
|
|
+ //新增单据
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("accessToken",getToken());
|
|
|
+ param.put("isCommit",true);
|
|
|
+ param.put("isUpdate",true);
|
|
|
+
|
|
|
+ Map<String, Object> body = new HashMap<>();
|
|
|
+ Map<String, Object> form = new HashMap<>();
|
|
|
+ //金额
|
|
|
+ Map<String, Object> payMoney = new HashMap<>();
|
|
|
+ payMoney.put("standard",data.get("付款金额"));
|
|
|
+ payMoney.put("standardStrCode","CNY");
|
|
|
+ payMoney.put("standardNumCode","156");
|
|
|
+ payMoney.put("standardSymbol","¥");
|
|
|
+ payMoney.put("standardUnit","元");
|
|
|
+ payMoney.put("standardScale",2);
|
|
|
+
|
|
|
+ form.put("title",data.get("付款事由")); //单据标题
|
|
|
+ form.put("submitterId","pQccdcNGsM3U00:153620324221442254"); //提交人ID todo lfx 暂时写死
|
|
|
+ form.put("description",data.get("备注")); //描述
|
|
|
+ form.put("specificationId",specificationId); //单据模板id
|
|
|
+ form.put("payMoney",payMoney); //付款金额
|
|
|
+ form.put("payeeId",account.get("id"));
|
|
|
+ form.put("u_订单信息",procInstId);
|
|
|
+ if (CORPORATION.keySet().contains(data.get("付款公司"))){
|
|
|
+ form.put("法人实体",CORPORATION.get(data.get("付款公司"))); //法人实体
|
|
|
+ }
|
|
|
+ body.put("form",form);
|
|
|
+
|
|
|
+ Map document = JSONObject.parseObject(UtilHttp.doPost(stEkbConfig.getPreUrl() + ("/api/openapi/v2.2/flow/data"), null, param, body));
|
|
|
+ }
|
|
|
+
|
|
|
+ @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);
|
|
|
+
|
|
|
+ List<Map> dentries = new ArrayList<>();
|
|
|
+ for (File file : files) {
|
|
|
+ try{
|
|
|
+ //上传文件至钉盘
|
|
|
+ Map dentry = upload(file);
|
|
|
+ dentries.add(dentry);
|
|
|
+ }catch (IOException e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //新增评论 todo 提交人暂定
|
|
|
+ comment(dentries,state,"344749020127590108",procInstId);
|
|
|
+
|
|
|
+ return McR.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void comment(List<Map> dentries, String state, String userId, String procInstId) {
|
|
|
+ Map body = new HashMap<>();
|
|
|
+ Map fileMap = new HashMap<>();
|
|
|
+ List<Map> attachments= new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map dentry : dentries) {
|
|
|
+ Map attachment = new HashMap<>();
|
|
|
+
|
|
|
+ attachment.put("spaceId",dentry.get("spaceId").toString());
|
|
|
+ attachment.put("fileSize",dentry.get("size").toString());
|
|
|
+ attachment.put("fileId",dentry.get("id").toString());
|
|
|
+ attachment.put("fileName",dentry.get("name").toString());
|
|
|
+ attachment.put("fileType",dentry.get("type").toString());
|
|
|
+
|
|
|
+ attachments.add(attachment);
|
|
|
+ }
|
|
|
+
|
|
|
+ fileMap.put("photos",null);
|
|
|
+ fileMap.put("attachments",attachments);
|
|
|
+
|
|
|
+ body.put("processInstanceId",procInstId);
|
|
|
+ body.put("text","付款状态:" + STATUS.get(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 {
|
|
|
+ //获取文件上传信息
|
|
|
+ String parentDentryUuid = "ZQYprEoWonmdnzdOFpklzk1a81waOeDk";// poc目录 api测试上传/附件
|
|
|
+ Map<String,Object> param1 = new HashMap<>();
|
|
|
+ param1.put("unionId","5PK3cMYhiStn7HDoNabweEgiEiE");//wzy
|
|
|
+ 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);
|
|
|
+
|
|
|
+ //使用OSS的header加签方式上传文件
|
|
|
+ URL url = new URL(resourceUrl);
|
|
|
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
|
|
|
+ if (headers != null) {
|
|
|
+ for (Map.Entry<String, String> entry : headers.entrySet()) {
|
|
|
+ connection.setRequestProperty(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ connection.setDoOutput(true);
|
|
|
+ connection.setRequestMethod("PUT");
|
|
|
+ connection.setUseCaches(false);
|
|
|
+ connection.setReadTimeout(10000);
|
|
|
+ connection.setConnectTimeout(10000);
|
|
|
+ connection.connect();
|
|
|
+ OutputStream out = connection.getOutputStream();
|
|
|
+
|
|
|
+ InputStream is = new FileInputStream(file);
|
|
|
+ byte[] b =new byte[1024];
|
|
|
+ int temp;
|
|
|
+ while ((temp=is.read(b))!=-1){
|
|
|
+ out.write(b,0,temp);
|
|
|
+ }
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ int responseCode = connection.getResponseCode();
|
|
|
+ connection.disconnect();
|
|
|
+ if (responseCode == 200) {
|
|
|
+ System.out.println("上传成功");
|
|
|
+ } else {
|
|
|
+ System.out.println("上传失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //提交文件
|
|
|
+ Map<String,Object> param2 = new HashMap<>();
|
|
|
+ param2.put("unionId","5PK3cMYhiStn7HDoNabweEgiEiE");//wzy
|
|
|
+ Map body2 = new HashMap<>();
|
|
|
+ body2.put("uploadKey",uploadKey);
|
|
|
+ body2.put("name",file.getName());
|
|
|
+ Map option = new HashMap<>();
|
|
|
+ option.put("conflictStrategy","OVERWRITE");//文件名称冲突策略:覆盖
|
|
|
+ body2.put("option",option);
|
|
|
+
|
|
|
+ DDR_New ddrNew2 = (DDR_New) UtilHttp.doPost("https://api.dingtalk.com/v2.0/storage/spaces/files/" + parentDentryUuid + "/commit", ddClient.initTokenHeader(), param2, body2, DDR_New.class);
|
|
|
+
|
|
|
+ return ddrNew2.getDentry();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Map getData(Map instance,Map rule){
|
|
|
+ Map resultMap=new HashMap();
|
|
|
+ List<Map> list=(List<Map>) instance.get("formComponentValues");
|
|
|
+ for (Map map:list) {
|
|
|
+ if(rule.containsKey(String.valueOf(map.get("id")))){
|
|
|
+ String componentType=String.valueOf(map.get("componentType"));
|
|
|
+ if(componentType.equals("RecipientAccountField")){
|
|
|
+ resultMap.put(rule.get(String.valueOf(map.get("id"))),JSONObject.parseObject(String.valueOf(map.get("extValue"))));
|
|
|
+ }else if (componentType.equals("DDMultiSelectField")){
|
|
|
+ resultMap.put(rule.get(String.valueOf(map.get("id"))),JSONObject.parseArray(String.valueOf(map.get("value"))).get(0).toString());
|
|
|
+ }else{
|
|
|
+ resultMap.put(rule.get(String.valueOf(map.get("id"))),map.get("value"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getToken(){
|
|
|
+ String accessToken = UtilToken.get("invalid-token-ykb");
|
|
|
+ if (StringUtils.isNotBlank(accessToken)) return accessToken;
|
|
|
+
|
|
|
+
|
|
|
+ Map result = JSONObject.parseObject(HttpUtil.post(stEkbConfig.getPreUrl().concat("/api/openapi/v1/auth/getAccessToken"),JSONObject.toJSONString(UtilMap.map("appKey, appSecurity",stEkbConfig.getAppKey(),stEkbConfig.getAppSecurity()))));
|
|
|
+ String token = ((Map) result.get("value")).get("accessToken").toString();
|
|
|
+ long expireTime = (long) ((Map) result.get("value")).get("expireTime");
|
|
|
+
|
|
|
+ log.info("响应token, {}", token);
|
|
|
+ // token失效自动重置: 重新调用会重置过期时间
|
|
|
+ UtilToken.put("invalid-token-ykb", token, expireTime * 1000L);
|
|
|
+
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+}
|