|
|
@@ -1,9 +1,11 @@
|
|
|
package com.sckw.contract.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sckw.contract.dao.KwcContractLogisticsMapper;
|
|
|
import com.sckw.contract.dao.KwcContractTradeMapper;
|
|
|
+import com.sckw.contract.factory.AsyncFactory;
|
|
|
import com.sckw.contract.model.dto.req.EsignGetFlowReqDto;
|
|
|
import com.sckw.contract.model.dto.res.ESignSubmitResDto;
|
|
|
import com.sckw.contract.model.entity.KwcContractLogistics;
|
|
|
@@ -18,22 +20,24 @@ import com.sckw.order.api.model.ContractSignCompletedParam;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.system.api.model.dto.res.EntCacheResDto;
|
|
|
import com.sckw.system.api.model.dto.res.UserCacheResDto;
|
|
|
+import com.sckw.transport.api.dubbo.TransportDubboService;
|
|
|
+import com.sckw.transport.api.model.param.ContractSignLogisticsParam;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
+import java.io.*;
|
|
|
import java.net.URL;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class CommonBusinessService {
|
|
|
|
|
|
@@ -43,6 +47,9 @@ public class CommonBusinessService {
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
private TradeOrderInfoService tradeOrderInfoService;
|
|
|
|
|
|
+ @DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
+ private TransportDubboService transportDubboService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private KwcContractTradeMapper kwcContractTradeMapper;
|
|
|
|
|
|
@@ -108,63 +115,185 @@ public class CommonBusinessService {
|
|
|
* @author: czh
|
|
|
* @date: 2023/8/14
|
|
|
*/
|
|
|
- private void notifyOrder(Long contractId, Long userId) {
|
|
|
+ public void notifyOrder(Long contractId, Long userId) {
|
|
|
ContractSignCompletedParam contractSignCompletedParam = new ContractSignCompletedParam();
|
|
|
UserCacheResDto userCacheResDto = remoteSystemService.queryUserCacheById(userId);
|
|
|
+ String name = Objects.isNull(userCacheResDto) ? "" : userCacheResDto.getName();
|
|
|
contractSignCompletedParam.setContractId(contractId);
|
|
|
contractSignCompletedParam.setUpdateBy(userId);
|
|
|
- contractSignCompletedParam.setUpdateByName(Objects.isNull(userCacheResDto) ? "" : userCacheResDto.getName());
|
|
|
+ contractSignCompletedParam.setUpdateByName(name);
|
|
|
tradeOrderInfoService.contractSignCompleted(contractSignCompletedParam);
|
|
|
+
|
|
|
+ ContractSignLogisticsParam contractSignLogisticsParam = new ContractSignLogisticsParam();
|
|
|
+ contractSignLogisticsParam.setContractId(contractId);
|
|
|
+ contractSignLogisticsParam.setUpdateBy(userId);
|
|
|
+ contractSignLogisticsParam.setUpdateByName(name);
|
|
|
+ transportDubboService.contractSignLogisticsCompleted(contractSignLogisticsParam);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @param firstAccount 发起方签约电话
|
|
|
- * secondAccount 对方签约电话
|
|
|
- * orgFirst 发起方企业id
|
|
|
- * orgSeconId 对方企业id
|
|
|
- * contractFile 合同文件
|
|
|
- * id 合同id
|
|
|
- * contractName 合同名
|
|
|
+ * secondAccount 对方签约电话
|
|
|
+ * orgFirst 发起方企业id
|
|
|
+ * orgSeconId 对方企业id
|
|
|
+ * contractFile 合同文件
|
|
|
+ * id 合同id
|
|
|
+ * contractName 合同名
|
|
|
* @desc: 调e签宝
|
|
|
* @author: czh
|
|
|
* @date: 2023/8/14
|
|
|
*/
|
|
|
public void postToEsign(String firstAccount, String secondAccount, Long orgFirst, Long orgSeconId, String contractFile, Long id, String contractName) {
|
|
|
- EsignGetFlowReqDto esignGetFlowReqDto = new EsignGetFlowReqDto();
|
|
|
- JSONArray jsonArray = JSONArray.parseArray(contractFile);
|
|
|
- JSONObject jsonObject = jsonArray.getJSONObject(0);
|
|
|
- String fileName = jsonObject.getString("name");
|
|
|
- String url = jsonObject.getString("url");
|
|
|
- File file = getFileByHttpURL(url, fileName);
|
|
|
-
|
|
|
- List<Long> entIds = new ArrayList<>(2);
|
|
|
- entIds.add(orgFirst);
|
|
|
- entIds.add(orgSeconId);
|
|
|
- Map<Long, EntCacheResDto> longListMap = remoteSystemService.queryEntCacheMapByIds(entIds);
|
|
|
-
|
|
|
- esignGetFlowReqDto.setFile(file);
|
|
|
- esignGetFlowReqDto.setSeqId(String.valueOf(id));
|
|
|
- esignGetFlowReqDto.setSignFlowTitle(contractName);
|
|
|
- esignGetFlowReqDto.setOrgFirstName(longListMap.get(orgFirst).getFirmName());
|
|
|
- esignGetFlowReqDto.setPsnFirstAccount(firstAccount);
|
|
|
- esignGetFlowReqDto.setOrgSecondName(longListMap.get(orgSeconId).getFirmName());
|
|
|
- esignGetFlowReqDto.setPsnSecondAccount(secondAccount);
|
|
|
- Map<String, Object> map = BeanUtils.convertToMap(esignGetFlowReqDto);
|
|
|
- String res = OkHttpUtils.doPostUploadFile(eSignUrl, map);
|
|
|
- //todo 解析返参,返参有流程id返回,表需要新加字段来存储
|
|
|
- JSONObject.parseObject(res, ESignSubmitResDto.class);
|
|
|
+ AsyncFactory.execute(new AsyncProcess(firstAccount, secondAccount, orgFirst, orgSeconId, contractFile, id, contractName, remoteSystemService, eSignUrl, kwcContractLogisticsMapper, kwcContractTradeMapper));
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception {
|
|
|
+// String fileName = "车企合同.docx";
|
|
|
+// System.out.println(new String(fileName.getBytes(), StandardCharsets.UTF_8));
|
|
|
+// String url = "https://kaiwu-saas.oss-cn-chengdu.aliyuncs.com/kll/uploads/20230823/67189e3e9284951c9cf434cacef7c4c4.docx";
|
|
|
+// File file = getFileByHttpURL(url, fileName);
|
|
|
+// List<Long> entIds = new ArrayList<>(2);
|
|
|
+// entIds.add(123123L);
|
|
|
+// entIds.add(512414L);
|
|
|
+// EsignGetFlowReqDto esignGetFlowReqDto = new EsignGetFlowReqDto();
|
|
|
+// esignGetFlowReqDto.setFile(file);
|
|
|
+// esignGetFlowReqDto.setSeqId(String.valueOf(11234125L));
|
|
|
+// esignGetFlowReqDto.setSignFlowTitle("测试Title");
|
|
|
+// esignGetFlowReqDto.setOrgFirstName("测试企业2");
|
|
|
+// esignGetFlowReqDto.setPsnFirstAccount("13900001112");
|
|
|
+// esignGetFlowReqDto.setOrgSecondName("测试企业1");
|
|
|
+// esignGetFlowReqDto.setPsnSecondAccount("13900001111");
|
|
|
+// Map<String, Object> map = BeanUtils.convertToMap(esignGetFlowReqDto);
|
|
|
+// String res = OkHttpUtils.doPostUploadFile("http://10.10.10.224:8840/v1/sign/getFlow", map);
|
|
|
+//// String res = OkHttpUtils.doPostUploadFile("http://10.10.10.70:27802/openapi/vehicleLocate/fileUpload", map);
|
|
|
+// log.info("E签宝返参:{}", res);
|
|
|
+ }
|
|
|
+
|
|
|
+ static class AsyncProcess implements Runnable {
|
|
|
+
|
|
|
+ private final String firstAccount;
|
|
|
+ private final String secondAccount;
|
|
|
+ private final Long orgFirst;
|
|
|
+ private final Long orgSeconId;
|
|
|
+ private final String contractFile;
|
|
|
+ private final Long id;
|
|
|
+ private final String contractName;
|
|
|
+
|
|
|
+ private RemoteSystemService remoteSystemService;
|
|
|
+ private String eSignUrl;
|
|
|
+ private KwcContractLogisticsMapper kwcContractLogisticsMapper;
|
|
|
+ private KwcContractTradeMapper kwcContractTradeMapper;
|
|
|
+
|
|
|
+ public AsyncProcess(String firstAccount,
|
|
|
+ String secondAccount,
|
|
|
+ Long orgFirst,
|
|
|
+ Long orgSeconId,
|
|
|
+ String contractFile,
|
|
|
+ Long id,
|
|
|
+ String contractName,
|
|
|
+ RemoteSystemService remoteSystemService,
|
|
|
+ String eSignUrl,
|
|
|
+ KwcContractLogisticsMapper kwcContractLogisticsMapper,
|
|
|
+ KwcContractTradeMapper kwcContractTradeMapper) {
|
|
|
+ this.firstAccount = firstAccount;
|
|
|
+ this.secondAccount = secondAccount;
|
|
|
+ this.orgFirst = orgFirst;
|
|
|
+ this.orgSeconId = orgSeconId;
|
|
|
+ this.contractFile = contractFile;
|
|
|
+ this.id = id;
|
|
|
+ this.contractName = contractName;
|
|
|
+ this.remoteSystemService = remoteSystemService;
|
|
|
+ this.eSignUrl = eSignUrl;
|
|
|
+ this.kwcContractLogisticsMapper = kwcContractLogisticsMapper;
|
|
|
+ this.kwcContractTradeMapper = kwcContractTradeMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ EsignGetFlowReqDto esignGetFlowReqDto = new EsignGetFlowReqDto();
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(contractFile);
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(0);
|
|
|
+ String fileName = jsonObject.getString("name");
|
|
|
+ String url = jsonObject.getString("url");
|
|
|
+ File file = getFileByHttpURL(url, fileName);
|
|
|
+ List<Long> entIds = new ArrayList<>(2);
|
|
|
+ entIds.add(orgFirst);
|
|
|
+ entIds.add(orgSeconId);
|
|
|
+ Map<Long, EntCacheResDto> longListMap = remoteSystemService.queryEntCacheMapByIds(entIds);
|
|
|
+
|
|
|
+ esignGetFlowReqDto.setFile(file);
|
|
|
+ esignGetFlowReqDto.setSeqId(String.valueOf(id));
|
|
|
+ esignGetFlowReqDto.setSignFlowTitle(contractName);
|
|
|
+ esignGetFlowReqDto.setOrgFirstName(longListMap.get(orgFirst).getFirmName());
|
|
|
+ esignGetFlowReqDto.setPsnFirstAccount(firstAccount);
|
|
|
+ esignGetFlowReqDto.setOrgSecondName(longListMap.get(orgSeconId).getFirmName());
|
|
|
+ esignGetFlowReqDto.setPsnSecondAccount(secondAccount);
|
|
|
+ Map<String, Object> map = BeanUtils.convertToMap(esignGetFlowReqDto);
|
|
|
+ log.info("E签宝入参: url:{}, param:{}", eSignUrl, JSON.toJSONString(map));
|
|
|
+ String res = OkHttpUtils.doPostUploadFile(eSignUrl, map);
|
|
|
+ log.info("E签宝返参:{}", res);
|
|
|
+ ESignSubmitResDto eSignSubmitResDto = JSONObject.parseObject(res, ESignSubmitResDto.class);
|
|
|
+ if (eSignSubmitResDto.getStatus()) {
|
|
|
+ String signFlowId = eSignSubmitResDto.getData().getSignFlowId();
|
|
|
+ KwcContractLogistics kwcContractLogistics = kwcContractLogisticsMapper.selectById(id);
|
|
|
+ if (Objects.nonNull(kwcContractLogistics)) {
|
|
|
+ kwcContractLogistics.setBusinessId(signFlowId);
|
|
|
+ kwcContractLogisticsMapper.updateById(kwcContractLogistics);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ KwcContractTrade kwcContractTrade = kwcContractTradeMapper.selectById(id);
|
|
|
+ if (Objects.nonNull(kwcContractTrade)) {
|
|
|
+ kwcContractTrade.setBusinessId(signFlowId);
|
|
|
+ kwcContractTradeMapper.updateById(kwcContractTrade);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static File getFileByHttpURL(String newUrl, String fileName) {
|
|
|
+ //得到最后一个分隔符后的名字
|
|
|
+ File file = null;
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ file = new File(System.getProperty("java.io.tmpdir") + new String(fileName.getBytes("gbk"), StandardCharsets.UTF_8));
|
|
|
+ URL urlFile = new URL(newUrl);
|
|
|
+ inputStream = urlFile.openStream();
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
+
|
|
|
+ int bytesRead = 0;
|
|
|
+ byte[] buffer = new byte[8192];
|
|
|
+ while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ if (null != outputStream) {
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+ if (null != inputStream) {
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return file;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public static File getFileByHttpURL(String newUrl, String fileName) {
|
|
|
- String[] suffix = newUrl.split("/");
|
|
|
//得到最后一个分隔符后的名字
|
|
|
File file = null;
|
|
|
InputStream inputStream = null;
|
|
|
OutputStream outputStream = null;
|
|
|
try {
|
|
|
- file = File.createTempFile("1", fileName);
|
|
|
+ file = new File(System.getProperty("java.io.tmpdir") + new String(fileName.getBytes(), StandardCharsets.UTF_8));
|
|
|
URL urlFile = new URL(newUrl);
|
|
|
inputStream = urlFile.openStream();
|
|
|
outputStream = new FileOutputStream(file);
|
|
|
@@ -191,4 +320,5 @@ public class CommonBusinessService {
|
|
|
}
|
|
|
return file;
|
|
|
}
|
|
|
+
|
|
|
}
|