Browse Source

神玑对接智能财务上线版

CRK 9 months ago
parent
commit
cfda8b433d

+ 6 - 0
mjava-laidi/pom.xml

@@ -24,6 +24,12 @@
             <artifactId>mjava</artifactId>
             <version>${mjava.version}</version>
         </dependency>
+
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>dingtalk</artifactId>
+            <version>2.0.14</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 75 - 0
mjava-laidi/src/main/java/com/malk/laidi/controller/SJController.java

@@ -0,0 +1,75 @@
+package com.malk.laidi.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.malk.laidi.util.HttpUtil;
+import com.malk.laidi.util.ddutil;
+import com.malk.server.common.McR;
+import com.malk.service.h3yun.CYClient;
+import com.malk.utils.UtilMap;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 错误抛出与拦截详见 CatchException
+ */
+@Slf4j
+@RestController
+@RequestMapping("shenji")
+public class SJController {
+
+
+    @Autowired
+    private CYClient cyClient;
+
+
+    /**
+     * 同步氚云 数据到付款单
+     */
+    @PostMapping("h3yun-http")
+    McR http(@RequestBody Map<String, String> data, @RequestParam String code) {
+        //写入付款单
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.putAll(data);
+        try {
+            HttpUtil.post("https://connector.dingtalk.com/webhook/trigger/data/sync?webhookId=10298fc91bbe0bf8e42e000n",null,jsonObject.toJSONString(),null);
+            HashMap<String, String> map = new HashMap<>();
+            map.put("status", "是");
+            return McR.success(map);
+        } catch (Exception exception) {
+            exception.printStackTrace();
+        }
+
+
+        return McR.success(UtilMap.map("status", "否"));
+    }
+
+    /**
+     *
+     */
+    @PostMapping("approved")
+    McR approved(@RequestBody Map<String, String> data) {
+
+        try {
+            JSONObject jsonObject = new JSONObject();
+
+            Date date = new Date();
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            String currentDate = sdf.format(date);
+            System.out.println(currentDate);
+
+            jsonObject.put("FPAYSTATE","已支付");
+            jsonObject.put("FPAYTIME",currentDate);
+            cyClient.updatetForm(ddutil.gettoken(), "D148951Sfsbr88lvzwpxtugt7pc5rl4a6", data.get("h3_objid"),jsonObject.toJSONString() );
+        } catch (Exception exception) {
+            exception.printStackTrace();
+        }
+        return McR.success();
+    }
+}

+ 143 - 0
mjava-laidi/src/main/java/com/malk/laidi/util/HttpUtil.java

@@ -0,0 +1,143 @@
+package com.malk.laidi.util;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.util.Map;
+
+/**
+ * Decription:
+ *
+ * @author hzk
+ * @ClassName HttpUtil
+ * @Date 2022/8/3 17:04
+ */
+public class HttpUtil {
+
+    @Qualifier("permissionRestTemplate")
+    @Autowired
+    private RestTemplate restTemplate;
+
+    public static  String get(String url){
+        RestTemplate restTemplate = new RestTemplate();
+        ResponseEntity<String> stringResponseEntity = restTemplate.getForEntity(url, String.class);
+        return stringResponseEntity.getBody();
+    }
+
+    public static String post(String url,String AcceptType,String body,Map<String,String> headersMap){
+        RestTemplate restTemplate = new RestTemplate();
+
+        HttpHeaders headers = new HttpHeaders();
+        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
+        headers.setContentType(type);
+
+        if(AcceptType == null || AcceptType.equals("")){
+            headers.add("Accept", MediaType.APPLICATION_JSON.toString());
+        }else{
+            headers.add("Accept", AcceptType);
+        }
+        if(headersMap != null) {
+            for (String key : headersMap.keySet()) {
+                headers.add(key, headersMap.get(key));
+            }
+        }
+        //指定格式
+        HttpEntity<String> formEntity = new HttpEntity<String>(body, headers);
+        ResponseEntity<String> stringResponseEntity = null;
+        int index = 0;
+        while (true) {
+            try {
+                stringResponseEntity = restTemplate.postForEntity(url, formEntity, String.class);
+                break;
+            } catch (Exception ex) {
+                index++;
+                if(index > 2)
+                {
+                    break;
+                }
+                continue;
+            }
+        }
+        return stringResponseEntity.getBody();
+    }
+
+
+
+    public static void downloadUsingStream(String urlStr, String file) throws IOException{
+
+        URL url = new URL(urlStr);
+
+        BufferedInputStream bis = new BufferedInputStream(url.openStream());
+
+        FileOutputStream fis = new FileOutputStream(file);
+
+        byte[] buffer = new byte[1024];
+
+        int count=0;
+
+        while((count = bis.read(buffer,0,1024)) != -1)
+
+        {
+
+            fis.write(buffer, 0, count);
+
+        }
+
+        fis.close();
+
+        bis.close();
+
+    }
+
+    public static void downloadUsingNIO(String urlStr, String file) throws IOException {
+
+        URL url = new URL(urlStr);
+
+        ReadableByteChannel rbc = Channels.newChannel(url.openStream());
+
+        FileOutputStream fos = new FileOutputStream(file);
+
+        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
+
+        fos.close();
+
+        rbc.close();
+
+    }
+
+
+    public static String doPostFile2(String url, MultiValueMap<String, Object> param, File file) {
+        ResponseEntity<String> stringResponseEntity = null;
+        try {
+            HttpHeaders headers = new HttpHeaders();
+            headers.add("Accept",MediaType.APPLICATION_JSON.toString());
+            headers.setContentType(MediaType.parseMediaType("multipart/form-data;charset=UTF-8"));
+
+            FileSystemResource resource = new FileSystemResource(file);
+            param.add("img",resource);
+
+            HttpEntity<MultiValueMap<String,Object>> formEntity = new HttpEntity<>(param,headers);
+            stringResponseEntity = new RestTemplate().postForEntity(url, formEntity, String.class);
+        } catch (Exception exception) {
+            exception.printStackTrace();
+        }
+        return stringResponseEntity.getBody();
+    }
+
+
+
+}

+ 98 - 0
mjava-laidi/src/main/java/com/malk/laidi/util/ddutil.java

@@ -0,0 +1,98 @@
+package com.malk.laidi.util;
+
+import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse;
+import com.aliyun.dingtalkworkflow_1_0.Client;
+import com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceHeaders;
+import com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceRequest;
+import com.aliyun.dingtalkworkflow_1_0.models.StartProcessInstanceResponse;
+import com.aliyun.tea.*;
+import com.aliyun.teautil.Common;
+import com.aliyun.teautil.models.RuntimeOptions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ddutil {
+    /**
+     * 使用 Token 初始化账号Client
+     *
+     * @return Client
+     * @throws Exception
+     */
+    public static com.aliyun.dingtalkworkflow_1_0.Client createClient() throws Exception {
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
+        config.protocol = "https";
+        config.regionId = "central";
+        return new com.aliyun.dingtalkworkflow_1_0.Client(config);
+    }
+
+    public static com.aliyun.dingtalkoauth2_1_0.Client createClient2() throws Exception {
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
+        config.protocol = "https";
+        config.regionId = "central";
+        return new com.aliyun.dingtalkoauth2_1_0.Client(config);
+    }
+    public static String gettoken() throws Exception {
+        com.aliyun.dingtalkoauth2_1_0.Client client = ddutil.createClient2();
+        com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest()
+                .setAppKey("dingyt4ywno34wbxafo9")
+                .setAppSecret("pvpAQhLKr3UmZA0nKPQAygycYcFPeR4vmnKKiLuBqFhN2ZU2U6LpOXejT9X-jC5k");
+        try {
+            GetAccessTokenResponse accessToken = client.getAccessToken(getAccessTokenRequest);
+            return accessToken.body.accessToken;
+        } catch (TeaException err) {
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 中含有 code 和 message 属性,可帮助开发定位问题
+            }
+
+        } catch (Exception _err) {
+            TeaException err = new TeaException(_err.getMessage(), _err);
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 中含有 code 和 message 属性,可帮助开发定位问题
+            }
+
+        }
+        return "";
+    }
+    public static String startProcessInstance( String fqr,long fqbm,String fkr,List<StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues> startProcessInstanceRequestFormComponentValues) throws Exception {
+        Client client = ddutil.createClient();
+        StartProcessInstanceHeaders startProcessInstanceHeaders = new StartProcessInstanceHeaders();
+        startProcessInstanceHeaders.xAcsDingtalkAccessToken = gettoken();
+
+
+        List<StartProcessInstanceRequest.StartProcessInstanceRequestTargetSelectActioners> startProcessInstanceRequestTargetSelectActioners = new ArrayList<>();
+        StartProcessInstanceRequest.StartProcessInstanceRequestTargetSelectActioners Actioners1 = new StartProcessInstanceRequest.StartProcessInstanceRequestTargetSelectActioners();
+        Actioners1.setActionerKey("manual_aba6_847d_0790_363d");
+        List<String> userids = new ArrayList<>();
+        userids.add(fkr);//付款人
+        Actioners1.setActionerUserIds(userids);
+        startProcessInstanceRequestTargetSelectActioners.add(Actioners1);
+
+
+
+        StartProcessInstanceRequest startProcessInstanceRequest = new StartProcessInstanceRequest()
+                .setOriginatorUserId(fqr)//发起人
+                .setProcessCode("PROC-9D296C27-EF5A-4594-B32C-5AD47EF5CB7B")//表单编码
+                .setDeptId(fqbm)//发起部门
+                .setTargetSelectActioners(startProcessInstanceRequestTargetSelectActioners)
+                .setFormComponentValues(startProcessInstanceRequestFormComponentValues);
+        try {
+            StartProcessInstanceResponse startProcessInstanceResponse = client.startProcessInstanceWithOptions(startProcessInstanceRequest, startProcessInstanceHeaders, new RuntimeOptions());
+            String instanceId = startProcessInstanceResponse.body.getInstanceId();
+            return instanceId;
+        } catch (TeaException err) {
+            if (!Common.empty(err.code) && !Common.empty(err.message)) {
+                // err 中含有 code 和 message 属性,可帮助开发定位问题
+            }
+
+        } catch (Exception _err) {
+            TeaException err = new TeaException(_err.getMessage(), _err);
+            if (!Common.empty(err.code) && !Common.empty(err.message)) {
+                // err 中含有 code 和 message 属性,可帮助开发定位问题
+            }
+
+        }
+        return "";
+    }
+
+}

+ 6 - 0
mjava/src/main/java/com/malk/server/common/VenR.java

@@ -51,5 +51,11 @@ public class VenR extends BaseDto {
         VenR rsp = UtilHttp.doGet(url, header, param, rClass);
         return rsp;
     }
+    @SneakyThrows
+    public static VenR doPut(String url, Map header, Map param, Map body, String path) {
+        Class rClass = Class.forName(path);
+        VenR rsp = UtilHttp.doPut(url, header, param, body, rClass);
+        return rsp;
+    }
 }
 

+ 3 - 0
mjava/src/main/java/com/malk/server/dingtalk/DDR_New.java

@@ -141,4 +141,7 @@ public class DDR_New<T> extends VenR {
     public static DDR_New doGet(String url, Map header, Map param) {
         return (DDR_New) DDR.doGet(url, header, param, VenR.RC_DD_New);
     }
+    public static DDR_New doPut(String url, Map header, Map param, Map body) {
+        return (DDR_New) DDR.doPut(url, header, param, body, VenR.RC_DD_New);
+    }
 }

+ 1 - 1
mjava/src/main/java/com/malk/service/h3yun/CYClient.java

@@ -46,7 +46,7 @@ public interface CYClient {
      */
     File saveFromTemporaryUrl(String accessToken, Map attachmentId);
 
-
+    Map updatetForm(String accessToken,String schemaCode,String bizObjectId,String bizObjectJson);
     //////////////////////////// 组织架构 ////////////////////////////
 
     /**

+ 6 - 1
mjava/src/main/java/com/malk/service/h3yun/impl/CYImplClient.java

@@ -35,7 +35,12 @@ public class CYImplClient implements CYClient {
         DDR_New cyr = DDR_New.doGet(getRequestUrl("/attachments/temporaryUrls"), DDConf.initTokenHeader(accessToken), param);
         return UtilMap.getString(((Map) cyr.getData()), "attachmentUrl");
     }
-
+    @Override
+    public Map updatetForm(String accessToken,String schemaCode, String bizObjectId, String bizObjectJson) {
+        Map param = UtilMap.map("schemaCode, bizObjectId, bizObjectJson", schemaCode,bizObjectId, bizObjectJson);
+        DDR_New cyr = DDR_New.doPut(getRequestUrl("/forms/instances"), DDConf.initTokenHeader(accessToken),null, param);
+        return UtilMap.map("code, message", cyr.getCode(), cyr.getMessage());
+    }
     @Autowired
     private FilePath filePath;