| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769 |
- 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.sql.Array;
- 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(), "02145933103936490950", 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) {
- DDR_New ddr_new = ydClient.queryData(YDParam.builder()
- .appType(appType)
- .systemToken(systemToken)
- .formInstanceId(UtilMap.getString(data, "formInstanceId"))
- .build(),
- YDConf.FORM_QUERY.retrieve_id_new);
- Map formData = ddr_new.getFormData();
- Map originator = ddr_new.getOriginator();
- String userId = UtilMap.getString(originator, "userId");
- //所有附件类型使用
- List<Map<String, Object>> resultList = new ArrayList<>();
- //写入OA审批的数据格式
- List<Map> formValue = new ArrayList<>();
- //附件
- String key = UtilMap.getString(data, "attachmentKey");
- String value = UtilMap.getString(formData, key);
- resultList.add(UtilMap.map("spaceId, fileName, fileSize, fileType, fileId", UtilMap.getString(formData, "textField_msve6for"),
- UtilMap.getString(formData, "textField_msve6fos"), UtilMap.getString(formData, "textField_msve6fot"),
- UtilMap.getString(formData, "textField_msve6fou"), UtilMap.getString(formData, "textField_msve6fox")));
- //处理宜搭附件绑定至OA审批
- JSONArray jsonArray = JSONArray.parseArray(value);
- if (ObjectUtil.isNotNull(jsonArray) && jsonArray.size()>0){
- 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(), userId, 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","合同编号生成方式, 手动填写"));
- key = UtilMap.getString(data, "sealType");
- value = UtilMap.getString(formData, key);
- //印章类型
- formValue.add(UtilMap.map("name, value","印章类型, " + value));
- // formValue.add(UtilMap.map("name, value","印章类型, " + "公章"));
- //合同编号
- key = UtilMap.getString(data, "codeKey");
- value = UtilMap.getString(formData, key);
- formValue.add(UtilMap.map("name, value","合同编号, " + value));
- //合同名称
- key = UtilMap.getString(data, "nameKey");
- value = UtilMap.getString(formData, key);
- formValue.add(UtilMap.map("name, value","合同名称, " + value));
- //金额类型
- key = UtilMap.getString(data, "amountType");
- if ("/".equals(key)){
- formValue.add(UtilMap.map("name, value","金额类型, 无金额"));
- }else {
- value = UtilMap.getString(formData, key);
- formValue.add(UtilMap.map("name, value","金额类型, " + AMOUNT_TYPE.get(value)));
- }
- //合同总额(元)
- key = UtilMap.getString(data, "totalAmount");
- if ("/".equals(key)){
- formValue.add(UtilMap.map("name, value","合同总额(元), 0"));
- }else {
- value = UtilMap.getString(formData, key);
- formValue.add(UtilMap.map("name, value","合同总额(元), " + value));
- }
- //合同期限开始日期
- key = UtilMap.getString(data, "startTime");
- //固定合同期限类型
- if ("/".equals(key)){
- formValue.add(UtilMap.map("name, value","合同期限类型, 非固定期限"));
- }else {
- formValue.add(UtilMap.map("name, value","合同期限类型, 固定期限"));
- value = UtilMap.getString(formData, key);
- // List list = UtilMap.getList(formData, key);
- String startFormat = LocalDateTime.ofInstant(
- // Instant.ofEpochMilli(Long.parseLong(list.get(0).toString())),
- Instant.ofEpochMilli(Long.parseLong(value)),
- ZoneId.of("Asia/Shanghai")
- ).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
- formValue.add(UtilMap.map("name, value","合同期限开始日期, " + startFormat));
- //合同期限结束日期
- key = UtilMap.getString(data, "endTime");
- value = UtilMap.getString(formData, key);
- String endFormat = LocalDateTime.ofInstant(
- Instant.ofEpochMilli(Long.parseLong(value)),
- ZoneId.of("Asia/Shanghai")
- ).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
- formValue.add(UtilMap.map("name, value","合同期限结束日期, " + endFormat));
- }
- //用印形式
- key = UtilMap.getString(data, "useSeal");
- value = UtilMap.getString(formData, key);
- //签署方式
- if("双方物理用印".equals(value)){
- formValue.add(UtilMap.map("name, value","签署方式, 纸质签署"));
- }else {
- formValue.add(UtilMap.map("name, value","签署方式, 电子签署"));
- }
- if (data.containsKey("otherAttachment")){
- //合同附件
- key = UtilMap.getString(data, "otherAttachment");
- value = UtilMap.getString(formData, key);
- //处理宜搭附件绑定至OA审批
- jsonArray = JSONArray.parseArray(value);
- if(ObjectUtil.isNotNull(jsonArray)&& jsonArray.size()>0){
- resultList.clear();
- 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(), userId, 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");
- if ("/".equals(key)){
- Map ourDetail = UtilMap.empty();
- ourDetail.put("value", "/");
- ourDetail.put("name", "我方主体名称");
- ourDetail.put("bizAlias","contract_mine_company_name");
- ourDetails.add(ourDetail);
- }else {
- String[] split = key.split(",");
- for (int i = 0; i < split.length; i++) {
- value = UtilMap.getString(formData, split[i]);
- 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");
- if ("/".equals(key)){
- Map otherDetail = UtilMap.empty();
- otherDetail.put("value", "/");
- otherDetail.put("name", "对方主体名称");
- otherDetail.put("bizAlias", "contract_opposite_company_name");
- otherDetails.add(otherDetail);
- }else {
- String[] split = key.split(",");
- for (int i = 0; i < split.length; i++) {
- value = UtilMap.getString(formData, split[i]);
- 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(userId);
- List<String> deptIdByUserId = getDeptIdByUserId(workingEmployeeIds);
- return ddClient_workflow.doProcessInstancesNew(ddClient.getAccessToken(), userId,"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-DA83FE32D61F49299DA6F8E8F992BCE9CKWE")
- // .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_mrlipwdt", "332624199910200042424")))
- .searchFieldJson(JSON.toJSONString(UtilMap.map("textField_mrlipwdt", UtilMap.getString(data,"creditCode"))))
- .build());
- String staffId = UtilMap.getString(data, "staffId");
- JSONArray array= JSONArray.parseArray(staffId);
- staffId = array.get(0).toString();
- if (dataList.isEmpty()){
- String url = "https://connector.dingtalk.com/webhook/subflow/6f842eadb97994cceaa04991";
- data.put("staffId",staffId);
- 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 {
- String finalStaffId = staffId;
- dataList.forEach(e->{
- String emp = UtilMap.getString(e, "employeeField_msczhgcx_id");
- JSONArray jsonArray = JSONArray.parseArray(emp);
- jsonArray.add(finalStaffId);
- // 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("该相对方已存在");
- }
- }
|