|
|
@@ -0,0 +1,694 @@
|
|
|
+package com.malk.mankalong.service.Impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.malk.mankalong.service.PayService;
|
|
|
+import com.malk.server.aliwork.YDConf;
|
|
|
+import com.malk.server.aliwork.YDParam;
|
|
|
+import com.malk.server.common.McR;
|
|
|
+import com.malk.server.dingtalk.DDConf;
|
|
|
+import com.malk.server.dingtalk.DDR_New;
|
|
|
+import com.malk.service.aliwork.YDClient;
|
|
|
+import com.malk.service.aliwork.YDService;
|
|
|
+import com.malk.service.dingtalk.DDClient;
|
|
|
+import com.malk.service.dingtalk.DDClient_Personnel;
|
|
|
+import com.malk.service.dingtalk.DDClient_Workflow;
|
|
|
+import com.malk.service.dingtalk.DDService;
|
|
|
+import com.malk.utils.UtilFile;
|
|
|
+import com.malk.utils.UtilHttp;
|
|
|
+import com.malk.utils.UtilMap;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.time.Instant;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class PayServiceImpl implements PayService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DDClient ddClient;
|
|
|
+ @Autowired
|
|
|
+ private DDClient_Workflow ddClient_workflow;
|
|
|
+ @Autowired
|
|
|
+ private DDClient_Personnel ddClientPersonnel;
|
|
|
+ @Value(value = "${dingtalk.appKey}")
|
|
|
+ private String APP_EKY;
|
|
|
+ @Value(value = "${dingtalk.appSecret}")
|
|
|
+ private String APP_SECRET;
|
|
|
+ @Value(value = "${dingtalk.agentId}")
|
|
|
+ private Long agentId;
|
|
|
+ @Value(value = "${dingtalk.unionId}")
|
|
|
+ private String unionId;
|
|
|
+ @Value(value = "${dingtalk.spaceId}")
|
|
|
+ private String spaceId;
|
|
|
+ @Value(value = "${dingtalk.parentId}")
|
|
|
+ private String parentId;
|
|
|
+ @Value(value = "${saveFile.path}")
|
|
|
+ private String saveFilePath;
|
|
|
+ @Value(value = "${dingtalk.parentUuid}")
|
|
|
+ private String parentDentryUuid;
|
|
|
+ @Value("${aliwork.appType}")
|
|
|
+ private String appType;
|
|
|
+ @Value("${aliwork.systemToken}")
|
|
|
+ private String systemToken;
|
|
|
+ @Autowired
|
|
|
+ private DDConf ddConf;
|
|
|
+ @Autowired
|
|
|
+ DDService ddService;
|
|
|
+ @Autowired
|
|
|
+ private YDService ydService;
|
|
|
+ @Autowired
|
|
|
+ private YDClient ydClient;
|
|
|
+
|
|
|
+ private static final String API_TOKEN = "/common/unAuth/tokens/generate";
|
|
|
+ private static final String POST_DATA_URL = "/common/document";
|
|
|
+ private static final String FIND_BY_CODES = "/common/users/v2/findByCodes";
|
|
|
+ private static final String FIND_COMPANY = "/common/departments/v2/findByCode";
|
|
|
+ private ConcurrentHashMap<String, LocalDateTime> tokenStore = new ConcurrentHashMap<>();
|
|
|
+ //出差类型枚举
|
|
|
+ private static final Map<String, String> AMOUNT_TYPE = new HashMap<>();
|
|
|
+
|
|
|
+ static {
|
|
|
+ AMOUNT_TYPE.put("收款", "收入");
|
|
|
+ AMOUNT_TYPE.put("付款", "支出");
|
|
|
+ AMOUNT_TYPE.put("不结算", "无金额");
|
|
|
+ AMOUNT_TYPE.put("收支双向", "无金额");
|
|
|
+ }
|
|
|
+ private static final Map<String, String> ATTACHMENT_ENUM = new HashMap<>();
|
|
|
+ static {
|
|
|
+ ATTACHMENT_ENUM.put("attachmentUrl","附件");
|
|
|
+ ATTACHMENT_ENUM.put("contractTextUrl","合同正文");
|
|
|
+ ATTACHMENT_ENUM.put("contractScanUrl","上传生效的合同扫描件");
|
|
|
+ ATTACHMENT_ENUM.put("contractPreApprovalFlow","合同前置审批流程");
|
|
|
+ ATTACHMENT_ENUM.put("procurementResult","oa请示、采购结果");
|
|
|
+ ATTACHMENT_ENUM.put("decisionDocument","决策文件、会议纪要、中标通知书等");
|
|
|
+ }
|
|
|
+ //所有的枚举
|
|
|
+ private static final Map<String, String> ALLENUM = new HashMap<>();
|
|
|
+ static {
|
|
|
+ //签署法人实体
|
|
|
+ ALLENUM.put("option_aoscience_bio_nantong_co_l__c", "澳斯康生物(南通)股份有限公司");
|
|
|
+ ALLENUM.put("option_gansu_jianshun_biotech_co__c", "甘肃健顺生物科技有限公司");
|
|
|
+ ALLENUM.put("option_jianshun_bio_tech_nantong__c", "健顺生物科技(南通)有限公司");
|
|
|
+ ALLENUM.put("option_shanghai_aoskang_bio_pharm__c", "上海澳斯康生物制药有限公司");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从Content-Disposition头获取文件名
|
|
|
+ */
|
|
|
+ private static String getFileNameFromConnection(HttpURLConnection connection) {
|
|
|
+ String contentDisposition = connection.getHeaderField("Content-Disposition");
|
|
|
+ if (contentDisposition != null) {
|
|
|
+ // 查找filename=后面的内容
|
|
|
+ String[] parts = contentDisposition.split(";");
|
|
|
+ for (String part : parts) {
|
|
|
+ if (part.trim().startsWith("filename=")) {
|
|
|
+ String fileName = part.substring(part.indexOf('=') + 1).trim();
|
|
|
+ // 去除引号并解码URL编码
|
|
|
+ fileName = fileName.replace("\"", "");
|
|
|
+ try {
|
|
|
+ return URLDecoder.decode(fileName, StandardCharsets.UTF_8.name());
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //下载宜搭附件
|
|
|
+ private String downloadFile(String fileURL, String contractName, String type, String savePath) throws IOException {
|
|
|
+ //若是宜搭附件url 则需获得附件临时免登地址
|
|
|
+// fileURL = ydClient.convertTemporaryUrl(fileURL);
|
|
|
+
|
|
|
+ URL url = new URL(fileURL);
|
|
|
+ HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
|
|
|
+ httpConn.setRequestMethod("GET");
|
|
|
+ httpConn.setInstanceFollowRedirects(true); // 强制跟随重定向(必加!)
|
|
|
+ httpConn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36");
|
|
|
+ httpConn.setConnectTimeout(10000);
|
|
|
+ httpConn.setReadTimeout(20000);
|
|
|
+ httpConn.setDoInput(true);
|
|
|
+ httpConn.setDoOutput(false);
|
|
|
+ int responseCode = httpConn.getResponseCode();
|
|
|
+
|
|
|
+ // 获取文件名
|
|
|
+// String fileName = getFileNameFromConnection(httpConn);
|
|
|
+ String fileName = contractName + "." + type;
|
|
|
+ // 检查HTTP响应代码是否为200
|
|
|
+ if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
+ InputStream inputStream = httpConn.getInputStream();
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(savePath + fileName);
|
|
|
+
|
|
|
+ byte[] buffer = new byte[8192];
|
|
|
+ int bytesRead = -1;
|
|
|
+
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+
|
|
|
+ outputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+ } else {
|
|
|
+ System.out.println("无法下载文件。HTTP响应代码: " + responseCode);
|
|
|
+ }
|
|
|
+ httpConn.disconnect();
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传文件至钉盘
|
|
|
+ * @param filePath 文件存储地址
|
|
|
+ * @param conflictStrategy 覆盖或其他上传方式
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map uploadToDingTalk(String filePath,String conflictStrategy) {
|
|
|
+ //获取当前时间戳
|
|
|
+ long beginTimestamp = System.currentTimeMillis();
|
|
|
+ System.out.println("开始上传附件:" + DateUtil.format(new Date(beginTimestamp), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+
|
|
|
+ //文件
|
|
|
+ File file = new File(filePath);
|
|
|
+
|
|
|
+ //获取文件上传信息
|
|
|
+ Map param = new HashMap();
|
|
|
+ param.put("unionId",unionId);
|
|
|
+ Map body = new HashMap();
|
|
|
+ body.put("protocol","HEADER_SIGNATURE");
|
|
|
+ body.put("multipart",false);
|
|
|
+
|
|
|
+ DDR_New ddr = (DDR_New) UtilHttp.doPost("https://api.dingtalk.com/v1.0/storage/spaces/" + spaceId + "/files/uploadInfos/query", ddConf.initTokenHeader(ddClient.getAccessToken()), param, body, DDR_New.class);
|
|
|
+ String uploadKey = ddr.getUploadKey();
|
|
|
+ Map headerSignatureInfo = ddr.getHeaderSignatureInfo();
|
|
|
+ Map<String,String> headers = (Map<String,String>) headerSignatureInfo.get("headers");
|
|
|
+ List<String> resourceUrls = (List<String>) headerSignatureInfo.get("resourceUrls");
|
|
|
+ String resourceUrl = resourceUrls.get(0);
|
|
|
+
|
|
|
+ Map dentry = new HashMap();
|
|
|
+ //使用OSS的header加签方式上传文件
|
|
|
+ try {
|
|
|
+ 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 body2 = new HashMap();
|
|
|
+ Map option = new HashMap();
|
|
|
+ option.put("conflictStrategy",conflictStrategy);
|
|
|
+ body2.put("uploadKey",uploadKey);
|
|
|
+ body2.put("name",file.getName());
|
|
|
+ body2.put("option",option);
|
|
|
+ DDR_New ddrNew = (DDR_New) UtilHttp.doPost("https://api.dingtalk.com/v2.0/storage/spaces/files/"+parentDentryUuid+"/commit", ddClient.initTokenHeader(), param, body2, DDR_New.class);
|
|
|
+ dentry = ddrNew.getDentry();
|
|
|
+
|
|
|
+ }catch (IOException e){
|
|
|
+ log.info("上传文件异常:{}",e);
|
|
|
+ }
|
|
|
+
|
|
|
+ long endTimestamp = System.currentTimeMillis();
|
|
|
+ System.out.println("上传文件结束:" + DateUtil.format(new Date(endTimestamp), "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ System.out.println("上传文件耗时:" + (endTimestamp - beginTimestamp)/1000.0 + "s");
|
|
|
+ return dentry;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> convert(Object object) throws Exception {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ Class<?> clazz = object.getClass();
|
|
|
+ for (Field field : clazz.getDeclaredFields()) {
|
|
|
+ field.setAccessible(true);
|
|
|
+ String value = field.get(object) != null ? field.get(object).toString() : "";
|
|
|
+ map.put(field.getName(), value);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取钉钉员工手机号
|
|
|
+ * @param workingEmployeeIds 钉钉人员id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getDeptIdByUserId(List<String> workingEmployeeIds) {
|
|
|
+ log.info("根据钉钉人员id获取员工部门id:{}",workingEmployeeIds.toString());
|
|
|
+ List<String> filterList = new ArrayList<>();
|
|
|
+ filterList.add("sys00-mainDeptId");
|
|
|
+ List<Map> employeeInfos = ddClientPersonnel.getEmployeeInfos(ddClient.getAccessToken(), workingEmployeeIds, agentId, filterList);
|
|
|
+ List<String> personList = new ArrayList<>();
|
|
|
+ employeeInfos.forEach(e -> {
|
|
|
+ List<Map> mapList = (List<Map>) e.get("field_data_list");
|
|
|
+ mapList.forEach(m -> {
|
|
|
+ List<Map> valueList = (List<Map>) m.get("field_value_list");
|
|
|
+ String value = valueList.get(0).get("value").toString();
|
|
|
+ personList.add(value);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return personList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map MATE;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载json
|
|
|
+ */
|
|
|
+ private Map _getMeta() {
|
|
|
+ if (ObjectUtil.isNull(MATE)) {
|
|
|
+ MATE = (Map) UtilFile.readJsonObjectFromResource("json/form.json"); // 本地匹配宜搭组件ID
|
|
|
+// MATE = (Map) UtilFile.readJsonObjectFromResource("static/json/formtest.json"); // 本地匹配宜搭组件ID
|
|
|
+ }
|
|
|
+ return MATE;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 整合传参数据为OA审批 name - value 数据格式
|
|
|
+ * @param code 单据类型
|
|
|
+ * @param data 传参
|
|
|
+ * @param meta json
|
|
|
+ * @param formValue OA审批数据格式
|
|
|
+ */
|
|
|
+ private void IntegrationData(String code, Map data, Map meta, List<Map> formValue) {
|
|
|
+ log.info("开始处理接口参数数据转为OA审批接口数据格式");
|
|
|
+ //json数据列
|
|
|
+ Map<String, ?> component = (Map) ((Map) meta.get(code)).get("compIds");
|
|
|
+ for (String key : component.keySet()) {
|
|
|
+ Map formData = UtilMap.empty();
|
|
|
+ if (key.startsWith("tableField_")) {
|
|
|
+ String[] split = key.split("_");
|
|
|
+ List<Map> rows = UtilMap.getList(data,split[1]);
|
|
|
+ List<List<Map>> lastList = new ArrayList<>();
|
|
|
+ Map<String, String> compIds = (Map) component.get(key);
|
|
|
+ if (rows.size() > 0 ){
|
|
|
+ for (Map row : rows) {
|
|
|
+ List<Map> details = new ArrayList<>();
|
|
|
+ for (String prop : compIds.keySet()) {
|
|
|
+ Map detail = UtilMap.empty();
|
|
|
+ detail.put("value", row.get(compIds.get(prop)));
|
|
|
+ detail.put("name", prop);
|
|
|
+ if (prop.contains("我方主体名称")){
|
|
|
+ detail.put("bizAlias","contract_mine_company_name");
|
|
|
+ } else if (prop.contains("对方主体名称")) {
|
|
|
+ detail.put("bizAlias","contract_opposite_company_name");
|
|
|
+ }
|
|
|
+ details.add(detail);
|
|
|
+ }
|
|
|
+ lastList.add(details);
|
|
|
+ }
|
|
|
+ formData.put( "value", JSON.toJSONString(lastList));
|
|
|
+ formData.put( "name",((Map) meta.get(code)).get(split[1]).toString());
|
|
|
+ }else {
|
|
|
+ List<Map> details = new ArrayList<>();
|
|
|
+ for (String prop : compIds.keySet()) {
|
|
|
+ Map detail = UtilMap.empty();
|
|
|
+ if ("quantity".equals(compIds.get(prop))){
|
|
|
+ detail.put("value", "0");
|
|
|
+ detail.put("name", prop);
|
|
|
+ }else {
|
|
|
+ detail.put("value", "无");
|
|
|
+ detail.put("name", prop);
|
|
|
+ }
|
|
|
+ details.add(detail);
|
|
|
+ }
|
|
|
+ lastList.add(details);
|
|
|
+ formData.put( "value", JSON.toJSONString(lastList));
|
|
|
+ formData.put( "name",((Map) meta.get(code)).get(split[1]).toString());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (data.containsKey(component.get(key))){
|
|
|
+ if (ObjectUtil.isNotNull(data.get(component.get(key)))){
|
|
|
+ Object value = data.get(component.get(key));
|
|
|
+ formData.put("name", key);
|
|
|
+ formData.put("value",value.toString());
|
|
|
+ if ("RelatedReceipt".equals(component.get(key))){
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ ids.add(value.toString());
|
|
|
+ formData.put("name", key);
|
|
|
+ formData.put("value",JSON.toJSONString(ids));
|
|
|
+ }
|
|
|
+ if (ALLENUM.containsKey(value.toString())){
|
|
|
+ formData.put("value",ALLENUM.get(value.toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (formData.size()>0){
|
|
|
+ formValue.add(formData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ final String[] token = {""};
|
|
|
+ final boolean[] isHave = {false};
|
|
|
+ ATTACHMENT_ENUM.forEach((k,v)->{
|
|
|
+ if (data.containsKey(k) && hasValid(data,k)){
|
|
|
+ log.info("开始处理附件上传");
|
|
|
+ List<Map> attachment = (List<Map>) data.get(k);
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
+ attachment.forEach(e->{
|
|
|
+ String[] split = UtilMap.getString(e, "name").split("\\.");
|
|
|
+ String fileName = split[0];
|
|
|
+ if (split.length > 2){
|
|
|
+ for (int i = 1; i < split.length -1; i++) {
|
|
|
+ fileName = fileName + "." + split[i];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String fileType = split[split.length-1];
|
|
|
+ Map map = ddService.uploadFileFormUrlForOverflow(ddClient.getAccessToken(), "603864663125953014", e.get("downloadUrl").toString() + "?token=" + token[0], fileName, fileType);
|
|
|
+// Map map = ddService.uploadFileFormUrlForOverflow(ddClient.getAccessToken(), data.get(((Map) meta.get(code)).get("creator")).toString(), e.get("downloadUrl").toString() + "?token=" + token[0], fileName, fileType);
|
|
|
+ Map<String, Object> result = UtilMap.map("spaceId, fileName, fileSize, fileType, fileId", UtilMap.getString(map, "spaceId"), fileName,
|
|
|
+ UtilMap.getString(map, "size"), UtilMap.getString(map, "extension"), UtilMap.getString(map, "id"));
|
|
|
+ resultList.add(result);
|
|
|
+ });
|
|
|
+ formValue.add(UtilMap.map("name, value",v,JSON.toJSONString(resultList)));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 整合传参及OA数据格式
|
|
|
+ * @param code 单据类型
|
|
|
+ * @param data 传参
|
|
|
+ * @return 流程实例id
|
|
|
+ */
|
|
|
+ private String dataProcessing(String code, Map data){
|
|
|
+ //加载json映射
|
|
|
+ Map meta = _getMeta();
|
|
|
+ //表单字段映射
|
|
|
+ List<Map> formValue = new ArrayList<>();
|
|
|
+ log.info("code:{} ",code);
|
|
|
+ IntegrationData(code, data, meta, formValue);
|
|
|
+ List<String> workingEmployeeIds = new ArrayList<>();
|
|
|
+ workingEmployeeIds.add(data.get(((Map) meta.get(code)).get("creator")).toString());
|
|
|
+ List<String> deptIdByUserId = getDeptIdByUserId(workingEmployeeIds);
|
|
|
+ if (code.startsWith("HTSPD")){
|
|
|
+ formValue.add(UtilMap.map("name, value","发起部门",deptIdByUserId.get(0)));
|
|
|
+ formValue.add(UtilMap.map("name, value","合同编号生成方式, 选择已有合同编号"));
|
|
|
+// formValue.add(UtilMap.map("name, value","合同编号规则, 测试合同编号"));
|
|
|
+ return ddClient_workflow.doProcessInstancesNew(ddClient.getAccessToken(), data.get(((Map) meta.get(code)).get("creator")).toString(),((Map) meta.get(code)).get("processCode").toString(), formValue, deptIdByUserId.get(0));
|
|
|
+// return ddClient_workflow.doProcessInstancesNew(ddClient.getAccessToken(), data.get(((Map) meta.get(code)).get("creator")).toString(), "PROC-B5E48D42-87FA-4C4E-9CD8-9178EEF1F0D3", formValue, deptIdByUserId.get(0));
|
|
|
+ }
|
|
|
+ return ddClient_workflow.doProcessInstancesNew(ddClient.getAccessToken(), data.get(((Map) meta.get(code)).get("creator")).toString(), ((Map) meta.get(code)).get("processCode").toString(), formValue, deptIdByUserId.get(0));
|
|
|
+// return code;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起流程审批
|
|
|
+ * @param code
|
|
|
+ * @param data
|
|
|
+ * @return 流程实例id和地址
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> startProcess(String code, Map data) {
|
|
|
+ String instanceId = dataProcessing(code, data);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(instanceId);
|
|
|
+ if (!ObjectUtil.isNotNull(jsonObject.get("instanceId"))){
|
|
|
+ return UtilMap.map("ddProcessId, dtUrl, reqMsg", jsonObject.get("instanceId"), "error", instanceId);
|
|
|
+ }
|
|
|
+ String url = "https://applink.dingtalk.com/approval/detail?corpId=ding226da4276814d290a1320dcb25e91351&instanceId=" + jsonObject.get("instanceId");
|
|
|
+ return UtilMap.map("ddProcessId, dtUrl, reqMsg", jsonObject.get("instanceId"), url, instanceId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * object附件判空
|
|
|
+ * @param data
|
|
|
+ * @param key
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean hasValid(Map data,String key) {
|
|
|
+
|
|
|
+ Object flowObj = data.get(key);
|
|
|
+ if (ObjectUtil.isNull(flowObj)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!(flowObj instanceof List)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ List<?> flowList = (List<?>) flowObj;
|
|
|
+ if (flowList.isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (Object item : flowList) {
|
|
|
+ if (item instanceof Map) {
|
|
|
+ Map<?, ?> itemMap = (Map<?, ?>) item;
|
|
|
+ Object url = itemMap.get("downloadUrl");
|
|
|
+ if (url != null && !url.toString().trim().isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String startProcess(Map data) {
|
|
|
+ Map formData = ydClient.queryData(YDParam.builder()
|
|
|
+ .appType(appType)
|
|
|
+ .systemToken(systemToken)
|
|
|
+ .formInstanceId(UtilMap.getString(data,"formInstanceId"))
|
|
|
+ .build(),
|
|
|
+ YDConf.FORM_QUERY.retrieve_id).getFormData();
|
|
|
+
|
|
|
+ List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
+ //附件
|
|
|
+ String key = UtilMap.getString(data, "attachmentKey");
|
|
|
+ String value = UtilMap.getString(formData, key);
|
|
|
+
|
|
|
+ //写入OA审批的数据格式
|
|
|
+ List<Map> formValue = new ArrayList<>();
|
|
|
+
|
|
|
+ //处理宜搭附件绑定至OA审批
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(value);
|
|
|
+ jsonArray.forEach(e->{
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(e.toString());
|
|
|
+ String downloadUrl = jsonObject.getString("downloadUrl");
|
|
|
+
|
|
|
+ String fileFullName = jsonObject.getString("name");
|
|
|
+ String url = ydClient.convertTemporaryUrl(downloadUrl, appType, systemToken);
|
|
|
+
|
|
|
+ Map map = ddService.uploadFileFormUrlForOverflow(ddClient.getAccessToken(), "603864663125953014", url, fileFullName, fileFullName.split("\\.")[1]);
|
|
|
+ Map<String, Object> result = UtilMap.map("spaceId, fileName, fileSize, fileType, fileId", UtilMap.getString(map, "spaceId"), fileFullName,
|
|
|
+ UtilMap.getString(map, "size"), UtilMap.getString(map, "extension"), UtilMap.getString(map, "id"));
|
|
|
+ resultList.add(result);
|
|
|
+ });
|
|
|
+ formValue.add(UtilMap.map("name, value","合同正文, " + JSON.toJSONString(resultList)));
|
|
|
+
|
|
|
+ //合同编号生成方式
|
|
|
+ formValue.add(UtilMap.map("name, value","合同编号生成方式, 手动填写"));
|
|
|
+ //印章类型
|
|
|
+ formValue.add(UtilMap.map("name, value","印章类型, 公章"));
|
|
|
+
|
|
|
+ //合同编号
|
|
|
+ key = UtilMap.getString(data, "codeKey");
|
|
|
+ value = UtilMap.getString(formData, key);
|
|
|
+ formValue.add(UtilMap.map("name, value","合同编号, 111111111111" + value));
|
|
|
+
|
|
|
+ //合同名称
|
|
|
+ key = UtilMap.getString(data, "nameKey");
|
|
|
+ value = UtilMap.getString(formData, key);
|
|
|
+ formValue.add(UtilMap.map("name, value","合同名称, " + value));
|
|
|
+
|
|
|
+ //金额类型
|
|
|
+ key = UtilMap.getString(data, "amountType");
|
|
|
+ value = UtilMap.getString(formData, key);
|
|
|
+ formValue.add(UtilMap.map("name, value","金额类型, " + AMOUNT_TYPE.get(value)));
|
|
|
+
|
|
|
+ //合同总额(元)
|
|
|
+ key = UtilMap.getString(data, "totalAmount");
|
|
|
+ value = UtilMap.getString(formData, key);
|
|
|
+ formValue.add(UtilMap.map("name, value","合同总额(元), " + value));
|
|
|
+
|
|
|
+ //固定合同期限类型
|
|
|
+ formValue.add(UtilMap.map("name, value","合同期限类型, 固定期限"));
|
|
|
+
|
|
|
+ //合同期限开始日期
|
|
|
+ key = UtilMap.getString(data, "startTime");
|
|
|
+ List list = UtilMap.getList(formData, key);
|
|
|
+ String startFormat = LocalDateTime.ofInstant(
|
|
|
+ Instant.ofEpochMilli(Long.parseLong(list.get(0).toString())),
|
|
|
+ ZoneId.of("Asia/Shanghai")
|
|
|
+ ).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ formValue.add(UtilMap.map("name, value","合同期限开始日期, " + startFormat));
|
|
|
+
|
|
|
+ //合同期限结束日期
|
|
|
+ String endFormat = LocalDateTime.ofInstant(
|
|
|
+ Instant.ofEpochMilli(Long.parseLong(list.get(1).toString())),
|
|
|
+ ZoneId.of("Asia/Shanghai")
|
|
|
+ ).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ formValue.add(UtilMap.map("name, value","合同期限结束日期, " + endFormat));
|
|
|
+
|
|
|
+ //签署方式
|
|
|
+ formValue.add(UtilMap.map("name, value","签署方式, 电子签署"));
|
|
|
+
|
|
|
+
|
|
|
+ if (data.containsKey("otherAttachment")){
|
|
|
+ //合同附件
|
|
|
+ key = UtilMap.getString(data, "otherAttachment");
|
|
|
+ value = UtilMap.getString(formData, key);
|
|
|
+ resultList.clear();
|
|
|
+
|
|
|
+ //处理宜搭附件绑定至OA审批
|
|
|
+ jsonArray = JSONArray.parseArray(value);
|
|
|
+ jsonArray.forEach(e->{
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(e.toString());
|
|
|
+ String downloadUrl = jsonObject.getString("downloadUrl");
|
|
|
+ String fileFullName = jsonObject.getString("name");
|
|
|
+ String url = ydClient.convertTemporaryUrl(downloadUrl, appType, systemToken);
|
|
|
+
|
|
|
+ Map map = ddService.uploadFileFormUrlForOverflow(ddClient.getAccessToken(), "603864663125953014", url, fileFullName, fileFullName.split("\\.")[1]);
|
|
|
+ Map<String, Object> result = UtilMap.map("spaceId, fileName, fileSize, fileType, fileId", UtilMap.getString(map, "spaceId"), fileFullName,
|
|
|
+ UtilMap.getString(map, "size"), UtilMap.getString(map, "extension"), UtilMap.getString(map, "id"));
|
|
|
+ resultList.add(result);
|
|
|
+ });
|
|
|
+ formValue.add(UtilMap.map("name, value","合同附件, " + JSON.toJSONString(resultList)));
|
|
|
+ }
|
|
|
+
|
|
|
+ //我方主体
|
|
|
+ List<List<Map>> ourLastList = new ArrayList<>();
|
|
|
+ List<Map> ourDetails = new ArrayList<>();
|
|
|
+
|
|
|
+ key = UtilMap.getString(data, "ourDetail");
|
|
|
+ value = UtilMap.getString(formData, key);
|
|
|
+
|
|
|
+ Map ourDetail = UtilMap.empty();
|
|
|
+ ourDetail.put("value", value);
|
|
|
+ ourDetail.put("name", "我方主体名称");
|
|
|
+ ourDetail.put("bizAlias","contract_mine_company_name");
|
|
|
+
|
|
|
+ ourDetails.add(ourDetail);
|
|
|
+// ourDetails.add(UtilMap.map("name, value", "我方负责人, 待补充"));
|
|
|
+ ourLastList.add(ourDetails);
|
|
|
+ formValue.add(UtilMap.map("name, value","我方信息",JSON.toJSONString(ourLastList)));
|
|
|
+
|
|
|
+ //他方主体
|
|
|
+ List<List<Map>> otherLastList = new ArrayList<>();
|
|
|
+ List<Map> otherDetails = new ArrayList<>();
|
|
|
+
|
|
|
+ key = UtilMap.getString(data, "otherDetail");
|
|
|
+ value = UtilMap.getString(formData, key);
|
|
|
+
|
|
|
+ Map otherDetail = UtilMap.empty();
|
|
|
+ otherDetail.put("value", value);
|
|
|
+ otherDetail.put("name", "对方主体名称");
|
|
|
+ otherDetail.put("bizAlias","contract_opposite_company_name");
|
|
|
+
|
|
|
+ otherDetails.add(otherDetail);
|
|
|
+// otherDetails.add(UtilMap.map("name, value", "对方负责人, 待补充"));
|
|
|
+ otherLastList.add(otherDetails);
|
|
|
+ formValue.add(UtilMap.map("name, value","对方信息",JSON.toJSONString(otherLastList)));
|
|
|
+
|
|
|
+
|
|
|
+ List<String> workingEmployeeIds = new ArrayList<>();
|
|
|
+ workingEmployeeIds.add("603864663125953014");
|
|
|
+ List<String> deptIdByUserId = getDeptIdByUserId(workingEmployeeIds);
|
|
|
+
|
|
|
+ return ddClient_workflow.doProcessInstancesNew(ddClient.getAccessToken(), "603864663125953014","PROC-CCD914BE-E89B-4E4B-B5D3-9569BF26AE22", formValue, deptIdByUserId.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public McR createSubjectInfo(Map data) {
|
|
|
+
|
|
|
+ List<Map> dataList = ydService.queryFormData_all(YDParam.builder()
|
|
|
+ .appType(appType)
|
|
|
+ .systemToken(systemToken)
|
|
|
+ .formUuid("FORM-B7DBC8CA2A284FDC9F38E814CC043B17DIMN")
|
|
|
+ .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_mrlipwdt", "332624199910200042424")))
|
|
|
+// .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_mrlipwdt", UtilMap.getString(data,"creditCode"))))
|
|
|
+ .build());
|
|
|
+
|
|
|
+ if (!ObjectUtil.isNotNull(dataList) && dataList.size() == 0){
|
|
|
+ String url = "https://connector.dingtalk.com/webhook/subflow/6f842eadb97994cceaa04991";
|
|
|
+
|
|
|
+ String jsonBody = JSON.toJSONString(data);
|
|
|
+ log.info("发起HTTP请求 URL={}, 请求体={}", url, jsonBody);
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpResponse response = HttpRequest.post(url)
|
|
|
+ .header("Content-Type", "application/json")
|
|
|
+ .body(jsonBody)
|
|
|
+ .execute();
|
|
|
+
|
|
|
+ String responseBody = response.body();
|
|
|
+ int status = response.getStatus();
|
|
|
+ log.info("HTTP响应 URL={}, status={}, 响应体={}", url, status, responseBody);
|
|
|
+
|
|
|
+ if (status == 200) {
|
|
|
+ // 解析远端返回的统一响应结构
|
|
|
+ return McR.success(responseBody);
|
|
|
+ } else {
|
|
|
+ log.error("HTTP请求失败 URL={}, status={}, body={}", url, status, responseBody);
|
|
|
+ return McR.error(String.valueOf(status),responseBody);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("HTTP请求异常 URL={}", url, e);
|
|
|
+ McR.errorParam("HTTP请求异常: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ dataList.forEach(e->{
|
|
|
+ String emp = UtilMap.getString(e, "employeeField_msczhgcx_id");
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(emp);
|
|
|
+ jsonArray.add(UtilMap.getString(data,"staffId"));
|
|
|
+// creatorUserId
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
+ .appType(appType)
|
|
|
+ .systemToken(systemToken)
|
|
|
+ .formInstanceId(UtilMap.getString(e, "formInstanceId"))
|
|
|
+ .useLatestVersion(true)
|
|
|
+ .updateFormDataJson(JSON.toJSONString(UtilMap.map("employeeField_msczhgcx", jsonArray)))
|
|
|
+ .build(), YDConf.FORM_OPERATION.update);
|
|
|
+ });
|
|
|
+ try {
|
|
|
+ Thread.sleep(16000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
+ .appType(appType)
|
|
|
+ .systemToken(systemToken)
|
|
|
+ .processInstanceId(UtilMap.getString(data, "formInstanceId"))
|
|
|
+ .build(), YDConf.FORM_OPERATION.terminate);
|
|
|
+ }
|
|
|
+ return McR.success("该相对方已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|