|
@@ -0,0 +1,585 @@
|
|
|
+package net.yaoyi.gulop.member.auth.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ancun.netsign.client.NetSignClient;
|
|
|
+import com.ancun.netsign.model.*;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.google.common.collect.Table;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import net.yaoyi.gulop.member.auth.constant.enums.ContractStatus;
|
|
|
+import net.yaoyi.gulop.member.auth.entity.*;
|
|
|
+import net.yaoyi.gulop.member.auth.mapper.*;
|
|
|
+import net.yaoyi.gulop.member.auth.service.GigConfigService;
|
|
|
+import net.yaoyi.gulop.member.auth.service.UmsExtApiHisService;
|
|
|
+import net.yaoyi.gulop.member.auth.util.CommonResult;
|
|
|
+import net.yaoyi.gulop.member.auth.util.ContractNumberGenerator;
|
|
|
+import net.yaoyi.gulop.member.auth.util.RemoteFileUtils;
|
|
|
+import org.junit.platform.commons.function.Try;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+@AllArgsConstructor
|
|
|
+public class GigConfigServiceImpl implements GigConfigService {
|
|
|
+
|
|
|
+ private UmsExtConfigMapper umsExtConfigMapper;
|
|
|
+ private final GigConfigMapper configMapper;
|
|
|
+ private final SmartContractMapper contractMapper;
|
|
|
+ private UmsMemberMapper umsMemberMapper;
|
|
|
+ private UmsExtApiHisService umsExtApiHisService;
|
|
|
+
|
|
|
+ // private final MemberOptManager memberOptManager;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<GigConfig> getSignList(Long userId) {
|
|
|
+ // 查询需要签约的配置项
|
|
|
+
|
|
|
+ // 1. 查询需要签约的配置列表
|
|
|
+ LambdaQueryWrapper<GigConfig> configWrapper = new LambdaQueryWrapper<>();
|
|
|
+ configWrapper./*eq(GigConfig::getIsSign, 1).*/eq(GigConfig::getIsFileType,0); // 需要签约的配置
|
|
|
+
|
|
|
+ List<GigConfig> configList = configMapper.selectList(configWrapper);
|
|
|
+
|
|
|
+ // 2. 提取关联条件(假设通过enterprise_account关联)
|
|
|
+ List<Long> configIds = configList.stream()
|
|
|
+ .map(GigConfig::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (configIds.isEmpty()) {
|
|
|
+ return configList;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 查询对应的协议信息
|
|
|
+ LambdaQueryWrapper<SmartContract> contractWrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ contractWrapper.eq(SmartContract::getUserId, userId).in(SmartContract::getConfigId, configIds); // 当前用户的协议
|
|
|
+
|
|
|
+ List<SmartContract> contracts = contractMapper.selectList(contractWrapper);
|
|
|
+
|
|
|
+ // 4. 构建快速查询映射表(ent_code -> 最新签约记录)
|
|
|
+ Map<Long, SmartContract> contractMap = contracts.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ SmartContract::getConfigId,
|
|
|
+ Function.identity(),
|
|
|
+ (oldContract, newContract) -> newContract
|
|
|
+ ));
|
|
|
+
|
|
|
+
|
|
|
+ // 5. 动态挂载签约记录到配置对象
|
|
|
+ configList.forEach(config -> {
|
|
|
+ SmartContract contract = contractMap.get(config.getId());
|
|
|
+ if (contract != null) {
|
|
|
+ config.setContractInfo(contract); // 挂载到虚拟字段
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return configList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //发起协议签约
|
|
|
+ @Override
|
|
|
+ public CommonResult signContract(Long configId, Long userId) throws IOException {
|
|
|
+ SmartContract smartContract = contractMapper.getSignAgreementByConfig(configId,userId);
|
|
|
+ if (smartContract != null ) {
|
|
|
+ if (smartContract.getContractStatus() == ContractStatus.SIGNED) {
|
|
|
+ throw new RuntimeException("该协议已签约");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (smartContract.getContractStatus().getCode() > ContractStatus.SIGNED.getCode()) {
|
|
|
+ //让他签
|
|
|
+ }else{
|
|
|
+ return CommonResult.ok(smartContract);
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ smartContract = new SmartContract();
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取用户信息
|
|
|
+ UmsMember umsMember = umsMemberMapper.findById(userId);
|
|
|
+ if (umsMember.getIsLivenessAuth() != 1) {
|
|
|
+ throw new RuntimeException("请先完成身份信息认证");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (umsMember.getIsFourAuth() != 1) {
|
|
|
+ return CommonResult.failed("请先完成银行卡四要素认证");
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取爱签配置
|
|
|
+ UmsExtConfig config = getConfig();
|
|
|
+ //获取协议
|
|
|
+ GigConfig signAgreemenInfo = configMapper.getSignAgreement(configId);
|
|
|
+ if (signAgreemenInfo == null) {
|
|
|
+ throw new RuntimeException("该协议无需签署");
|
|
|
+ }
|
|
|
+ if(signAgreemenInfo.getIsSign() == 0) {
|
|
|
+ //调用税地
|
|
|
+
|
|
|
+
|
|
|
+ /*Map<net.yaoyi.gulop.common.core.constant.enums.type.GigType.SubjectType, MemberInfo> memberInfoMap = new HashMap<>(4);
|
|
|
+ JSONObject threeAuthInfo = umsMember.getThreeAuthInfo();
|
|
|
+ net.yaoyi.gulop.common.core.constant.enums.type.GigType.SubjectType subjectType = Enum.valueOf(net.yaoyi.gulop.common.core.constant.enums.type.GigType.SubjectType.class, signAgreemenInfo.getSubjectName());
|
|
|
+
|
|
|
+ MemberInfo info = new MemberInfo();
|
|
|
+ info.setRealName(threeAuthInfo.getString("realname"));
|
|
|
+ info.setUsername(umsMember.getPhone());
|
|
|
+ info.setIdCard(threeAuthInfo.getString("idcard"));
|
|
|
+ info.setPayChannel(PayChannel.BANK_CARD);
|
|
|
+ info.setSubjectType(subjectType);
|
|
|
+ info.setIdCardType(MemberIDCardType.ID_CARD);
|
|
|
+ info.setEnterpriseCode(signAgreemenInfo.getEnterpriseCode());
|
|
|
+ info.setEmail("");
|
|
|
+ info.setChannel(Enum.valueOf(net.yaoyi.gulop.common.core.constant.enums.type.GigType.SubjectChannel.class, (String) signAgreemenInfo.getSubjectChannel()));
|
|
|
+ info.setMemberType(MemberType.YAOYI_EXCLUSIVE_PERSONNEL);
|
|
|
+ info.setAddress(threeAuthInfo.getString("address"));
|
|
|
+ info.setRequestId("voWZf9M9x5h9039X");
|
|
|
+ // info.setRequestId("12345789");
|
|
|
+
|
|
|
+ memberInfoMap.put(GigType.SubjectType.TAX_HELPOR, info);
|
|
|
+ log.info("税地请求:{}",JSONObject.toJSON(memberInfoMap));
|
|
|
+ Table<net.yaoyi.gulop.common.core.constant.enums.type.GigType.SubjectType, String, TeaModel> gigSubjectTypeTeaModelMap = memberOptManager.doSignAndCert(memberInfoMap);
|
|
|
+ log.info("税地返回:{}",JSONObject.toJSON(gigSubjectTypeTeaModelMap));
|
|
|
+ return CommonResult.ok(gigSubjectTypeTeaModelMap);*/
|
|
|
+ return CommonResult.ok(null,"这是税地,需要调用税地的接口");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ NetSignClient netSignClient = new NetSignClient("https://prev.asign.cn/", config.getExtId(), config.getExtSecret());
|
|
|
+
|
|
|
+
|
|
|
+ //1.创建待签署文件
|
|
|
+ String contractId = ContractNumberGenerator.generate();
|
|
|
+
|
|
|
+ List<FileDto> files = new ArrayList<>();
|
|
|
+ log.info("签署的本地合同 {}",signAgreemenInfo.getAgreementUrl());
|
|
|
+ FileDto fileDto = RemoteFileUtils.fromUrl(signAgreemenInfo.getAgreementUrl());
|
|
|
+ files.add(fileDto);
|
|
|
+
|
|
|
+
|
|
|
+ //1.创建待签署文件
|
|
|
+ ContractInput contractInput = new ContractInput();
|
|
|
+ contractInput.setContractNo(contractId);
|
|
|
+ contractInput.setContractName(signAgreemenInfo.getSubjectName());
|
|
|
+ contractInput.setContractFiles(files);
|
|
|
+ contractInput.setSignOrder(1);
|
|
|
+ contractInput.setValidityTime(30);
|
|
|
+
|
|
|
+ log.info("创建待签署文件 {}",JSONObject.toJSON(contractInput));
|
|
|
+
|
|
|
+ Long apiHistoryId = umsExtApiHisService.apiHistoryBefore(config.getExtId(), userId, "创建待签署文件", (JSONObject) JSONObject.toJSON(contractInput));
|
|
|
+ ApiRespBody<ContractOutput> apiRespBody = netSignClient.createContract(contractInput);
|
|
|
+
|
|
|
+ log.info("创建待签署文件 返回:{}",JSONObject.toJSON(apiRespBody));
|
|
|
+
|
|
|
+ if (!apiRespBody.success()) {
|
|
|
+ umsExtApiHisService.apiHistoryAfter(apiHistoryId,0, (JSONObject) JSONObject.toJSON(apiRespBody));
|
|
|
+ throw new RuntimeException(apiRespBody.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ umsExtApiHisService.apiHistoryAfter(apiHistoryId,1, (JSONObject) JSONObject.toJSON(apiRespBody.getData()));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //2.添加签署方
|
|
|
+ List < ContractUserInput > contractUserInputs = new ArrayList<>();
|
|
|
+ // ApiRespBody<ContractOutput> contractOutputApiRespBody = netSignClient.addSigner(List < ContractUserInput > contractUserInputs);
|
|
|
+
|
|
|
+ // 2.1添加用户
|
|
|
+ List<UserSignStrategyInput> objects = new ArrayList<>();
|
|
|
+ UserSignStrategyInput userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("乙方签署区");
|
|
|
+ objects.add(userSignStrategyInput);
|
|
|
+
|
|
|
+ userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("乙方签署日期");
|
|
|
+ userSignStrategyInput.setSignType(2);
|
|
|
+ objects.add(userSignStrategyInput);
|
|
|
+
|
|
|
+ ContractUserInput contractUserInput = new ContractUserInput();
|
|
|
+ contractUserInput.setContractNo(contractInput.getContractNo());
|
|
|
+ contractUserInput.setAccount(umsMember.getPhone());
|
|
|
+ contractUserInput.setSignType(2);//2:无感知签约(需要开通权限)
|
|
|
+ contractUserInput.setValidateType(1);//签署方式指定
|
|
|
+ // contractUserInput.setFaceAuthMode(4);//微信小程序
|
|
|
+ contractUserInput.setIsNoticeComplete(1);//签署完成后是否通知用户
|
|
|
+ contractUserInput.setWaterMark(1);//是否在距底部10px中央位置添加日期水印
|
|
|
+ contractUserInput.setCustomSignFlag(0);//签章位置
|
|
|
+ contractUserInput.setSignStrategyList(objects);//签章策略
|
|
|
+
|
|
|
+ contractUserInputs.add(contractUserInput);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 2.2添加企业
|
|
|
+ objects = new ArrayList<>();
|
|
|
+ userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("甲方签署区");
|
|
|
+ objects.add(userSignStrategyInput);
|
|
|
+
|
|
|
+ /*userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("甲方签署日期");
|
|
|
+ userSignStrategyInput.setSignType(2);
|
|
|
+ objects.add(userSignStrategyInput);*/
|
|
|
+
|
|
|
+ ContractUserInput contractUserInput2 = new ContractUserInput();
|
|
|
+ contractUserInput2.setContractNo(contractInput.getContractNo());
|
|
|
+ contractUserInput2.setAccount(signAgreemenInfo.getEnterpriseAccount());
|
|
|
+ contractUserInput2.setSignType(2);
|
|
|
+ contractUserInput2.setValidateType(1);//签署方式指定
|
|
|
+ // contractUserInput2.setFaceAuthMode(2);//h5
|
|
|
+ contractUserInput2.setIsNoticeComplete(1);//签署完成后是否通知用户
|
|
|
+ contractUserInput2.setWaterMark(1);//是否在距底部10px中央位置添加日期水印
|
|
|
+ contractUserInput2.setCustomSignFlag(0);//签章位置
|
|
|
+ contractUserInput2.setSignStrategyList(objects);//签章策略
|
|
|
+ contractUserInputs.add(contractUserInput2);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ log.info("添加签署方 {}",JSONObject.toJSON(contractUserInputs));
|
|
|
+ //准备签署
|
|
|
+
|
|
|
+
|
|
|
+ JSONObject requestData = new JSONObject();
|
|
|
+ requestData.put("",contractUserInputs);
|
|
|
+ apiHistoryId = umsExtApiHisService.apiHistoryBefore(config.getExtId(), userId, "添加签署方", (JSONObject) JSONObject.toJSON(requestData));
|
|
|
+ ApiRespBody<ContractOutput> contractOutputApiRespBody = netSignClient.addSigner(contractUserInputs);
|
|
|
+ log.info("添加签署方 返回:{}",JSONObject.toJSON(contractOutputApiRespBody));
|
|
|
+ if (contractOutputApiRespBody.success()) {
|
|
|
+ ContractOutput data = contractOutputApiRespBody.getData();
|
|
|
+
|
|
|
+ // JSONObject responseData = new JSONObject();
|
|
|
+ /*for (SignUserOutput signUserOutput : data.getSignUser()) {
|
|
|
+ if (Objects.equals(signUserOutput.getAccount(), umsMember.getPhone())) {
|
|
|
+ smartContract.setUserSignUrl(signUserOutput.getSignUrl());
|
|
|
+ // responseData.put("sign_url",signUserOutput.getSignUrl());
|
|
|
+ responseData = (JSONObject) JSONObject.toJSON(signUserOutput);
|
|
|
+ } else if (Objects.equals(signUserOutput.getAccount(), signAgreemenInfo.getEnterpriseAccount())) {
|
|
|
+ smartContract.setEnterpriseSignUrl(signUserOutput.getSignUrl());
|
|
|
+ } else if (Objects.equals(signUserOutput.getAccount(), signAgreemenInfo.getPlatformAccount())) {
|
|
|
+ smartContract.setPlatformSignUrl(signUserOutput.getSignUrl());
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+ //创建用户发起的协议记录
|
|
|
+ smartContract.setConfigId(configId);
|
|
|
+ smartContract.setContractNo(contractInput.getContractNo());
|
|
|
+ smartContract.setContractTitle(contractInput.getContractName());
|
|
|
+ smartContract.setContractContent(signAgreemenInfo.getAgreementUrl());
|
|
|
+ smartContract.setContractContent(signAgreemenInfo.getAgreementUrl());
|
|
|
+ smartContract.setContractStatus(ContractStatus.WAIT_SIGN);
|
|
|
+ smartContract.setUserId(userId);
|
|
|
+ // smartContract.setUserSignStatus(ContractStatus.WAIT_SIGN);
|
|
|
+ // smartContract.setEnterpriseSignStatus(ContractStatus.WAIT_SIGN);
|
|
|
+ // smartContract.setPlatformSignStatus(ContractStatus.WAIT_SIGN);
|
|
|
+ smartContract.setSignInfo((JSONObject) JSONObject.toJSON(data));
|
|
|
+ smartContract.setPreviewUrl(apiRespBody.getData().getPreviewUrl());
|
|
|
+ smartContract.setUserAccount(umsMember.getPhone());
|
|
|
+ smartContract.setEnterpriseAccount(signAgreemenInfo.getEnterpriseAccount());
|
|
|
+ smartContract.setPlatformAccount(signAgreemenInfo.getPlatformAccount());
|
|
|
+ smartContract.setExpireTime(LocalDateTime.now().plusDays(contractInput.getValidityTime()));
|
|
|
+
|
|
|
+ if (smartContract.getContractId() == null) {
|
|
|
+ smartContract.insert();
|
|
|
+ }else{
|
|
|
+ smartContract.updateById();
|
|
|
+ }
|
|
|
+
|
|
|
+ umsExtApiHisService.apiHistoryAfter(apiHistoryId,1, (JSONObject) JSONObject.toJSON(contractOutputApiRespBody));
|
|
|
+
|
|
|
+
|
|
|
+ //通过api查询合同状态
|
|
|
+ this.signCheck(smartContract.getContractId(),userId);
|
|
|
+ // return CommonResult.ok(responseData);
|
|
|
+ return CommonResult.ok(smartContract);
|
|
|
+ }else{
|
|
|
+ log.info("err {}" ,contractOutputApiRespBody.getData());
|
|
|
+ umsExtApiHisService.apiHistoryAfter(apiHistoryId,0, (JSONObject) JSONObject.toJSON(contractOutputApiRespBody));
|
|
|
+ return CommonResult.failed(contractOutputApiRespBody.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //同步状态
|
|
|
+ public CommonResult signCheck(Long contractId, long userId){
|
|
|
+
|
|
|
+ SmartContract smartContract = contractMapper.getSignAgreementById(contractId,userId);
|
|
|
+ if (smartContract != null ) {
|
|
|
+ if (smartContract.getContractStatus() == ContractStatus.SIGNED) {
|
|
|
+ throw new RuntimeException("该协议已签署完成");
|
|
|
+ }
|
|
|
+ if (smartContract.getContractStatus().getCode() >= ContractStatus.SIGNED.getCode()) {
|
|
|
+ throw new RuntimeException("该协议已作废");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("你没有可签署的协议");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //查询状态并同步
|
|
|
+ UmsMember umsMember = umsMemberMapper.findById(userId);
|
|
|
+
|
|
|
+ //获取爱签配置
|
|
|
+ UmsExtConfig config = getConfig();
|
|
|
+ NetSignClient netSignClient = new NetSignClient("https://prev.asign.cn/", config.getExtId(), config.getExtSecret());
|
|
|
+ JSONObject requestData = new JSONObject();
|
|
|
+ requestData.put("contractNo",smartContract.getContractNo());
|
|
|
+ Long apiHistoryId = umsExtApiHisService.apiHistoryBefore(config.getExtId(), userId, "查询合同信息",requestData);
|
|
|
+
|
|
|
+ ApiRespBody contractInfo = netSignClient.getContractInfo(smartContract.getContractNo());
|
|
|
+
|
|
|
+ if (contractInfo.success()) {
|
|
|
+ ContractOutput data = (ContractOutput) contractInfo.getData();
|
|
|
+ log.info("查询签约结果 {}",JSONObject.toJSON(data));
|
|
|
+
|
|
|
+ umsExtApiHisService.apiHistoryAfter(apiHistoryId,1,(JSONObject) JSONObject.toJSON(data));
|
|
|
+ /*for (SignUserOutput item : data.getSignUser()) {
|
|
|
+ if (Objects.equals(item.getAccount(), smartContract.getUserAccount())) {
|
|
|
+ smartContract.setUserSignStatus(ContractStatus.fromCode(item.getSignStatus()));
|
|
|
+ } else if (Objects.equals(item.getAccount(), smartContract.getEnterpriseAccount())) {
|
|
|
+ smartContract.setEnterpriseSignStatus(ContractStatus.fromCode(item.getSignStatus()));
|
|
|
+ } else if (Objects.equals(item.getAccount(), smartContract.getPlatformAccount())) {
|
|
|
+ smartContract.setPlatformSignStatus(ContractStatus.fromCode(item.getSignStatus()));
|
|
|
+ }
|
|
|
+ }*/
|
|
|
+
|
|
|
+
|
|
|
+ smartContract.setContractStatus(ContractStatus.fromCode(data.getStatus()));
|
|
|
+ smartContract.setSignInfo((JSONObject) JSONObject.toJSON(data));
|
|
|
+ smartContract.updateById();
|
|
|
+
|
|
|
+ return CommonResult.ok(smartContract);
|
|
|
+ }
|
|
|
+
|
|
|
+ umsExtApiHisService.apiHistoryAfter(apiHistoryId,0,(JSONObject) JSONObject.toJSON(contractInfo));
|
|
|
+ throw new RuntimeException(contractInfo.getMsg());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ protected UmsExtConfig getConfig() {
|
|
|
+ //todo 获取配置
|
|
|
+ UmsExtConfig asignConfig = umsExtConfigMapper.findByName("asign");
|
|
|
+ if (asignConfig == null) {
|
|
|
+ throw new RuntimeException("没有配置");
|
|
|
+ }
|
|
|
+
|
|
|
+ return asignConfig;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //获取报告列表
|
|
|
+ @Override
|
|
|
+ public List<GigConfig> getReportList() {
|
|
|
+ // 查询需要签约的配置项
|
|
|
+
|
|
|
+ // 1. 查询需要签约的配置列表
|
|
|
+ LambdaQueryWrapper<GigConfig> configWrapper = new LambdaQueryWrapper<>();
|
|
|
+ configWrapper.eq(GigConfig::getIsSign, 1).eq(GigConfig::getIsFileType,1); // 需要签约的配置
|
|
|
+
|
|
|
+ return configMapper.selectList(configWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult getReportDown(Long configId) throws IOException {
|
|
|
+ //获取爱签配置
|
|
|
+ UmsExtConfig config = getConfig();
|
|
|
+ //获取协议
|
|
|
+ GigConfig signAgreemenInfo = configMapper.getSignAgreement(configId);
|
|
|
+ if (signAgreemenInfo == null) {
|
|
|
+ throw new RuntimeException("该协议无需签署");
|
|
|
+ }
|
|
|
+
|
|
|
+ NetSignClient netSignClient = new NetSignClient("https://prev.asign.cn/", config.getExtId(), config.getExtSecret());
|
|
|
+
|
|
|
+
|
|
|
+ //1.创建待签署文件
|
|
|
+ String contractId = ContractNumberGenerator.generate();
|
|
|
+
|
|
|
+ List<FileDto> files = new ArrayList<>();
|
|
|
+ log.info("xx {}",signAgreemenInfo.getAgreementUrl());
|
|
|
+ FileDto fileDto = RemoteFileUtils.fromUrl(signAgreemenInfo.getAgreementUrl());
|
|
|
+ files.add(fileDto);
|
|
|
+
|
|
|
+
|
|
|
+ //1.创建待签署文件
|
|
|
+ ContractInput contractInput = new ContractInput();
|
|
|
+ contractInput.setContractNo(contractId);
|
|
|
+ contractInput.setContractName(signAgreemenInfo.getSubjectName());
|
|
|
+ contractInput.setContractFiles(files);
|
|
|
+ contractInput.setSignOrder(1);
|
|
|
+ contractInput.setValidityTime(30);
|
|
|
+
|
|
|
+ ApiRespBody<ContractOutput> apiRespBody = netSignClient.createContract(contractInput);
|
|
|
+ if (!apiRespBody.success()) {
|
|
|
+ throw new RuntimeException(apiRespBody.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("创建待签署文件 {}",JSONObject.toJSON(apiRespBody.getData()));
|
|
|
+
|
|
|
+ //2.添加签署方
|
|
|
+ List < ContractUserInput > contractUserInputs = new ArrayList<>();
|
|
|
+
|
|
|
+ // 2.1 企业A签署区
|
|
|
+ List<UserSignStrategyInput> objects = new ArrayList<>();
|
|
|
+ UserSignStrategyInput userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("企业A签署区");
|
|
|
+ objects.add(userSignStrategyInput);
|
|
|
+
|
|
|
+ /*userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("企业A签署日期");
|
|
|
+ userSignStrategyInput.setSignType(2);
|
|
|
+ objects.add(userSignStrategyInput);*/
|
|
|
+
|
|
|
+ ContractUserInput contractUserInput = new ContractUserInput();
|
|
|
+ contractUserInput.setContractNo(contractInput.getContractNo());
|
|
|
+ contractUserInput.setAccount(signAgreemenInfo.getEnterpriseAccount());
|
|
|
+ contractUserInput.setSignType(2);//2:无感知签约(需要开通权限)
|
|
|
+ contractUserInput.setValidateType(1);//签署方式指定
|
|
|
+ // contractUserInput.setFaceAuthMode(4);//微信小程序
|
|
|
+ contractUserInput.setIsNoticeComplete(1);//签署完成后是否通知用户
|
|
|
+ contractUserInput.setWaterMark(1);//是否在距底部10px中央位置添加日期水印
|
|
|
+ contractUserInput.setCustomSignFlag(0);//签章位置
|
|
|
+ contractUserInput.setSignStrategyList(objects);//签章策略
|
|
|
+
|
|
|
+ contractUserInputs.add(contractUserInput);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 2.2 企业B签署区
|
|
|
+ objects = new ArrayList<>();
|
|
|
+ userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("企业B签署区");
|
|
|
+ objects.add(userSignStrategyInput);
|
|
|
+
|
|
|
+ /*userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("企业B签署日期");
|
|
|
+ userSignStrategyInput.setSignType(2);
|
|
|
+ objects.add(userSignStrategyInput);*/
|
|
|
+
|
|
|
+ contractUserInput = new ContractUserInput();
|
|
|
+ contractUserInput.setContractNo(contractInput.getContractNo());
|
|
|
+ contractUserInput.setAccount(signAgreemenInfo.getReceptionAccount());
|
|
|
+ contractUserInput.setSignType(2);
|
|
|
+ contractUserInput.setValidateType(1);//签署方式指定
|
|
|
+ // contractUserInput.setFaceAuthMode(2);//h5
|
|
|
+ contractUserInput.setIsNoticeComplete(1);//签署完成后是否通知用户
|
|
|
+ contractUserInput.setWaterMark(1);//是否在距底部10px中央位置添加日期水印
|
|
|
+ contractUserInput.setCustomSignFlag(0);//签章位置
|
|
|
+ contractUserInput.setSignStrategyList(objects);//签章策略
|
|
|
+ contractUserInputs.add(contractUserInput);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //2.3 要易签署区
|
|
|
+ objects = new ArrayList<>();
|
|
|
+ userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("要易签署区");
|
|
|
+ objects.add(userSignStrategyInput);
|
|
|
+
|
|
|
+ /*userSignStrategyInput = new UserSignStrategyInput();
|
|
|
+ userSignStrategyInput.setAttachNo(1);
|
|
|
+ userSignStrategyInput.setLocationMode(3);
|
|
|
+ userSignStrategyInput.setSignKey("要易签署日期");
|
|
|
+ userSignStrategyInput.setSignType(2);
|
|
|
+ objects.add(userSignStrategyInput);*/
|
|
|
+
|
|
|
+
|
|
|
+ //骑缝章
|
|
|
+ List<UserSignStrikeInput> userSignStrikeInputs = new ArrayList<>();
|
|
|
+ UserSignStrikeInput userSignStrikeInput = new UserSignStrikeInput();
|
|
|
+ userSignStrikeInput.setAttachNo(1);
|
|
|
+ userSignStrikeInput.setCrossStyle(6);//右骑缝
|
|
|
+ userSignStrikeInput.setSignPage("42-43");//骑缝章所在页码
|
|
|
+ userSignStrikeInputs.add(userSignStrikeInput);
|
|
|
+
|
|
|
+ contractUserInput = new ContractUserInput();
|
|
|
+ contractUserInput.setContractNo(contractInput.getContractNo());
|
|
|
+ contractUserInput.setAccount(signAgreemenInfo.getPlatformAccount());
|
|
|
+ contractUserInput.setSignType(2);
|
|
|
+ contractUserInput.setValidateType(1);//签署方式指定
|
|
|
+ // contractUserInput.setFaceAuthMode(2);//h5
|
|
|
+ contractUserInput.setIsNoticeComplete(1);//签署完成后是否通知用户
|
|
|
+ contractUserInput.setWaterMark(1);//是否在距底部10px中央位置添加日期水印
|
|
|
+ contractUserInput.setCustomSignFlag(0);//签章位置
|
|
|
+ contractUserInput.setSignStrategyList(objects);//签章策略
|
|
|
+ contractUserInput.setSignStrikeList(userSignStrikeInputs);//签章策略 signStrikeList
|
|
|
+ contractUserInputs.add(contractUserInput);
|
|
|
+
|
|
|
+ log.info("报告签署 :{}",JSONObject.toJSON(contractUserInputs));
|
|
|
+
|
|
|
+ ApiRespBody<ContractOutput> contractOutputApiRespBody = netSignClient.addSigner(contractUserInputs);
|
|
|
+ log.info("报告签署 返回:{}",JSONObject.toJSON(contractOutputApiRespBody));
|
|
|
+ if (contractOutputApiRespBody.success()) {
|
|
|
+ ContractOutput data = contractOutputApiRespBody.getData();
|
|
|
+
|
|
|
+ //TODO 下载合同
|
|
|
+ try{
|
|
|
+
|
|
|
+ log.info("xxx {} {} {}",data.getContractNo(), 1, "P:\\wwwroot\\java\\3000\\"+data.getContractNo()+".pdf");
|
|
|
+ // DownloadContractOutput down = this.down(data.getContractNo(), 1, "P:\\wwwroot\\java\\3000\\"+data.getContractNo()+".pdf");
|
|
|
+ DownloadContractOutput down = this.down(contractUserInput.getContractNo(), 1, "/www/wwwroot/mini.fyang.vip/"+contractUserInput.getContractNo()+".pdf");
|
|
|
+ log.info("下载成功");
|
|
|
+ }catch (Exception e){
|
|
|
+ System.out.println("异常");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return CommonResult.ok(data);
|
|
|
+ }else{
|
|
|
+ log.info("err {}" ,contractOutputApiRespBody.getData());
|
|
|
+ return CommonResult.failed(contractOutputApiRespBody.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public DownloadContractOutput down(String contractNo, int downloadFileType, String outfile){
|
|
|
+
|
|
|
+ //获取爱签配置
|
|
|
+ UmsExtConfig config = getConfig();
|
|
|
+ NetSignClient netSignClient = new NetSignClient("https://prev.asign.cn/", config.getExtId(), config.getExtSecret());
|
|
|
+
|
|
|
+ ApiRespBody<DownloadContractOutput> downloadContractOutputApiRespBody = netSignClient.downloadContract(contractNo, downloadFileType, outfile);
|
|
|
+ if (downloadContractOutputApiRespBody.success()) {
|
|
|
+ return downloadContractOutputApiRespBody.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|