合同文件生成

This commit is contained in:
Jack 2025-03-04 23:04:44 +08:00
parent af5d32dfba
commit 2235be5f92
10 changed files with 393 additions and 41 deletions

View File

@ -32,8 +32,8 @@ public class EsignContractFillingFile implements Serializable {
@ApiModelProperty(value = "自增ID")
private Long id;
@ApiModelProperty(value = "店铺编号")
private String store_id;
@ApiModelProperty(value = "商家注册手机号码")
private String mobile;
@ApiModelProperty(value = "合同编号,自定义生成")
private String contract_number;
@ -53,6 +53,12 @@ public class EsignContractFillingFile implements Serializable {
@ApiModelProperty(value = "未签署合同地址本地下载地址")
private String unsigned_contract_local_url;
@ApiModelProperty(value = "合同排序")
private Integer seq;
@ApiModelProperty(value = "店铺编号")
private String store_id;
@ApiModelProperty(value = "记录状态:1-有效2-无效;")
private Integer status;

View File

@ -89,6 +89,9 @@ public class ShopMerchEntry implements Serializable {
@ApiModelProperty(value = "企业入驻时的营业执照编号")
private String biz_license_number;
@ApiModelProperty(value = "营业执照公司名(或真实公司名)")
private String biz_license_company;
@ApiModelProperty(value = "入驻商家营业执照图片的存储路径")
private String biz_license_image;
@ -134,18 +137,15 @@ public class ShopMerchEntry implements Serializable {
@ApiModelProperty(value = "入驻商家的收款账户号码")
private String account_number;
@ApiModelProperty(value = "入驻商家的收款账户姓名")
private String account_holder_name;
@ApiModelProperty(value = "入驻商家的审批状态1-已通过2-未通过3-待审核;")
private Integer approval_status;
@ApiModelProperty(value = "入驻商家审批时的备注信息")
private String approval_remark;
@ApiModelProperty(value = "该商家入驻记录是否有效0:无效1:有效")
private Integer status;

View File

@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.Date;
@ -253,4 +254,20 @@ public class UploadUtil {
response.setHeader("Access-Control-Expose-Headers", TOKEN_HEADER_NAME);
}
/**
* 将URL地址转换为输入流
*
* @param urlStr
* @return
*/
public static InputStream URLFile2InputStream(String urlStr) {
try (InputStream inputStream = new URL(urlStr).openStream()) {
// inputStream 用完之后记得关闭
return inputStream;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -8,5 +8,31 @@
package com.suisung.mall.shop.esign.service;
import com.suisung.mall.common.modules.esign.EsignContractFillingFile;
public interface EsignContractFillingFileService {
/**
* 根据注册手机号禁用合同
*
* @param mobile
* @return
*/
Boolean disableByMobile(String mobile);
/**
* 根据注册手机号和序号删除合同
*
* @param mobile
* @return
*/
Boolean deleteByMobile(String mobile, Integer seq);
/**
* 尝试删除一条老记录保存一条记录
*
* @param esignContractFillingFile
* @return
*/
Boolean trySaveRecord(EsignContractFillingFile esignContractFillingFile);
}

View File

@ -8,8 +8,6 @@
package com.suisung.mall.shop.esign.service;
import com.suisung.mall.common.modules.esign.EsignContractFillingFile;
public interface FileAndTemplateService {
/**
@ -19,5 +17,5 @@ public interface FileAndTemplateService {
* @param platLicenseNumber 平台方代理商方营业执照号
* @return
*/
EsignContractFillingFile fillDocTemplate(String mchLicenseNumber, String platLicenseNumber);
Boolean fillDocTemplate(String mchLicenseNumber, String platLicenseNumber);
}

View File

@ -8,12 +8,67 @@
package com.suisung.mall.shop.esign.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.suisung.mall.common.constant.CommonConstant;
import com.suisung.mall.common.modules.esign.EsignContractFillingFile;
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
import com.suisung.mall.shop.esign.mapper.EsignContractFillingFileMapper;
import com.suisung.mall.shop.esign.service.EsignContractFillingFileService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class EsignContractFillingFileServiceImpl extends BaseServiceImpl<EsignContractFillingFileMapper, EsignContractFillingFile> implements EsignContractFillingFileService {
/**
* 根据注册手机号禁用合同
*
* @param mobile
* @return
*/
@Override
public Boolean disableByMobile(String mobile) {
UpdateWrapper<EsignContractFillingFile> updateWrapper = new UpdateWrapper();
updateWrapper.eq("mobile", mobile);
updateWrapper.set("status", CommonConstant.Disable2);
return update(updateWrapper);
}
@Override
public Boolean deleteByMobile(String mobile, Integer seq) {
QueryWrapper<EsignContractFillingFile> queryWrapper = new QueryWrapper();
queryWrapper.eq("mobile", mobile).eq("seq", seq).select("id");
List<EsignContractFillingFile> recordList = list(queryWrapper);
if (CollectionUtil.isEmpty(recordList)) {
return false;
}
return remove(recordList.stream().map(EsignContractFillingFile::getId).collect(Collectors.toList()));
}
/**
* 尝试删除一条老记录保存一条记录
*
* @param esignContractFillingFile
* @return
*/
@Transactional
@Override
public Boolean trySaveRecord(EsignContractFillingFile esignContractFillingFile) {
if (esignContractFillingFile == null) {
return false;
}
deleteByMobile(esignContractFillingFile.getMobile(), esignContractFillingFile.getSeq());
if (!save(esignContractFillingFile)) {
throw new RuntimeException("trySaveRecord error");
}
return true;
}
}

View File

@ -8,6 +8,7 @@
package com.suisung.mall.shop.esign.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
@ -16,12 +17,15 @@ import com.suisung.mall.common.constant.CommonConstant;
import com.suisung.mall.common.modules.esign.EsignContractFillingFile;
import com.suisung.mall.common.modules.esign.EsignPlatformInfo;
import com.suisung.mall.common.modules.merch.ShopMerchEntry;
import com.suisung.mall.common.utils.StringUtils;
import com.suisung.mall.shop.esign.service.EsignContractFillingFileService;
import com.suisung.mall.shop.esign.service.EsignPlatformInfoService;
import com.suisung.mall.shop.esign.service.FileAndTemplateService;
import com.suisung.mall.shop.esign.utils.comm.EsignHttpHelper;
import com.suisung.mall.shop.esign.utils.comm.EsignHttpResponse;
import com.suisung.mall.shop.esign.utils.enums.EsignRequestType;
import com.suisung.mall.shop.esign.utils.exception.EsignDemoException;
import com.suisung.mall.shop.page.service.OssService;
import com.suisung.mall.shop.store.service.ShopMerchEntryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@ -29,6 +33,8 @@ import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@ -43,12 +49,21 @@ public class FileAndTemplateServiceImpl implements FileAndTemplateService {
@Value("${esign.app_secret}")
private String appSecret;
@Value("#{accountBaseConfigService.getConfig('tengxun_default_dir')}")
private String TENGXUN_DEFAULT_DIR;
@Resource
private EsignPlatformInfoService esignPlatformInfoService;
@Resource
private ShopMerchEntryService shopMerchEntryService;
@Resource
private EsignContractFillingFileService esignContractFillingFileService;
@Resource
private OssService ossService;
/**
* 填充合同模版生成合同文件地址
*
@ -57,9 +72,9 @@ public class FileAndTemplateServiceImpl implements FileAndTemplateService {
* @return
*/
@Override
public EsignContractFillingFile fillDocTemplate(String mchLicenseNumber, String platLicenseNumber) {
public Boolean fillDocTemplate(String mchLicenseNumber, String platLicenseNumber) {
// 获取平台方的信息
EsignPlatformInfo esignPlatformInfo = null;
EsignPlatformInfo esignPlatformInfo = new EsignPlatformInfo();
if (StrUtil.isNotEmpty(platLicenseNumber)) {
esignPlatformInfo = esignPlatformInfoService.getEsignPlatformInfo(null, platLicenseNumber);
}
@ -82,23 +97,175 @@ public class FileAndTemplateServiceImpl implements FileAndTemplateService {
String apiaddr = "/v3/files/create-by-doc-template";
EsignRequestType requestType = EsignRequestType.POST;
// 获取平台方代理商方合同模版信息
JSONArray templates = JSONUtil.parseArray(esignPlatformInfo.getDoc_template());
if (ObjectUtils.isEmpty(templates)) {
if (ObjectUtils.isEmpty(templates) || templates.size() != 3) {
log.error("缺少平台方(代理商方)合同模版信息");
return null;
}
String today = DateUtil.format(new Date(), "yyyy年MM月dd日");
String mchCompany = shopMerchEntry.getBiz_license_company();
String platCompany = esignPlatformInfo.getLicense_company();
String legalPersonName = shopMerchEntry.getLegal_person_name();
String mchMobile = shopMerchEntry.getLogin_mobile();
String contractNumber = StringUtils.genLklOrderNo(4);
int successCnt = 0;
// 模版文件里有三份合同顺序排列的: 1.平台商户入驻服务框架协议 2.小发同城服务费结算 3.结算授权委托书
for (Object template : templates) {
// 从商家信息里获取模版的信息
JSONObject templateJson = (JSONObject) template;
String templateId = templateJson.getStr("template_id");
String fileName = templateJson.getStr("template_name");
int seq = templateJson.getInt("seq");
// 获取填充模版的数据
JSONObject fillJson = new JSONObject();
fillJson.put("docTemplateId", templateJson.getStr("template_id"))
.put("fileName", templateJson.getStr("template_name"));
fillJson.put("docTemplateId", templateId)
.put("fileName", fileName);
String components = "[{'componentKey':'yf_company','componentValue':'桂平厚德贸易有限公司'},{'componentKey':'sign_date','componentValue':'2025-02-20'}]";
fillJson.put("components", JSONUtil.parseArray(components));
if (seq == 1) {
JSONArray list = new JSONArray();
EsignPlatformInfo finalEsignPlatformInfo = esignPlatformInfo;
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_addr");
put("componentValue", "《平台商户入驻服务框架协议》和《小发同城服务费结算》");
}});
for (int i = 1; i <= 3; i++) {
int finalI = i;
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_name" + finalI);
put("componentValue", legalPersonName);
}});
}
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_id_number");
put("componentValue", shopMerchEntry.getLegal_person_id_number());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_mobile");
put("componentValue", shopMerchEntry.getLegal_person_mobile());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_mobile2");
put("componentValue", shopMerchEntry.getLegal_person_mobile());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_mobile");
put("componentValue", finalEsignPlatformInfo.getLegal_person_mobile());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_email");
put("componentValue", finalEsignPlatformInfo.getEmail());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_sign_date");
put("componentValue", today);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_sign_date");
put("componentValue", today);
}});
for (int i = 1; i <= 14; i++) {
int finalI = i;
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_name" + finalI);
put("componentValue", mchCompany);
}});
}
fillJson.put("components", list);
} else if (seq == 2) {
// 小发同城服务费结算
JSONArray list = new JSONArray();
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_store_name");
put("componentValue", shopMerchEntry.getStore_name());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_name15");
put("componentValue", mchCompany);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_sign_date2");
put("componentValue", today);
}});
fillJson.put("components", list);
} else if (seq == 3) {
JSONArray list = new JSONArray();
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_name1");
put("componentValue", platCompany + "和代理商");
}});
for (int i = 2; i <= 3; i++) {
int finalI = i;
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_name" + finalI);
put("componentValue", platCompany);
}});
}
list.add(new HashMap<String, Object>() {{
put("componentKey", "contracts");
put("componentValue", "《平台商户入驻服务框架协议》和《小发同城服务费结算》");
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "rule_no");
put("componentValue", 3);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_name16");
put("componentValue", "本商户");
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_name17");
put("componentValue", mchCompany);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_ratio");
put("componentValue", shopMerchEntry.getSplit_ratio());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "settlement_method");
put("componentValue", shopMerchEntry.getSettlement_method());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "plat_choice");
put("componentValue", true);
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "legal_person_name4");
put("componentValue", shopMerchEntry.getLegal_person_name());
}});
list.add(new HashMap<String, Object>() {{
put("componentKey", "mch_sign_date3");
put("componentValue", today);
}});
fillJson.put("components", list);
}
String jsonParma = fillJson.toString();
//生成签名鉴权方式的的header
@ -107,24 +274,43 @@ public class FileAndTemplateServiceImpl implements FileAndTemplateService {
header = EsignHttpHelper.signAndBuildSignAndJsonHeader(appId, appSecret, jsonParma, requestType.name(), apiaddr, true);
//发起接口请求
EsignHttpResponse createByDocTemplate = EsignHttpHelper.doCommHttp(serverUrl, apiaddr, requestType, jsonParma, header, true);
log.info("{}", createByDocTemplate);
log.info("合同生成数据:{}", createByDocTemplate);
if (createByDocTemplate.getStatus() != 200) {
return false;
}
EsignContractFillingFile esignContractFillingFile = new EsignContractFillingFile();
esignContractFillingFile.setDoc_template_id("docTemplateId");
esignContractFillingFile.setStore_id("storeId");
JSONObject jsonObject = JSONUtil.parseObj(createByDocTemplate.getBody()).getJSONObject("data");
esignContractFillingFile.setUnsigned_contract_url(jsonObject.getStr("fileDownloadUrl"));
// 把合同文件 url 上传到cos服务器
String cosFileName = TENGXUN_DEFAULT_DIR.concat("/").concat("contract")
.concat("/").concat(mchLicenseNumber).concat("/")
.concat(jsonObject.getStr("fileId")).concat(".pdf");
// 上传到cos服务器
String localFileUrl = ossService.uploadObject4OSS(esignContractFillingFile.getUnsigned_contract_url(), cosFileName);
esignContractFillingFile.setUnsigned_contract_local_url(localFileUrl);
esignContractFillingFile.setDoc_template_id(templateId);
esignContractFillingFile.setContract_number(contractNumber + seq);
esignContractFillingFile.setContract_name(fileName);
esignContractFillingFile.setStore_id(contractNumber);
esignContractFillingFile.setMobile(mchMobile);
esignContractFillingFile.setDoc_template_filling_values(jsonParma);
esignContractFillingFile.setUnsigned_contract_url(createByDocTemplate.getBody());
esignContractFillingFile.setUnsigned_contract_local_url(createByDocTemplate.getBody());
esignContractFillingFile.setStatus(1);
return esignContractFillingFile;
esignContractFillingFile.setSeq(seq);
esignContractFillingFile.setStatus(CommonConstant.Enable);
if (esignContractFillingFileService.trySaveRecord(esignContractFillingFile)) {
successCnt += 1;
}
} catch (EsignDemoException e) {
throw new RuntimeException(e);
}
}
return null;
return successCnt == 3;
}
/**

View File

@ -29,8 +29,17 @@ public interface OssService {
String uploadObject2OSS(File file, String folder, InputStream stream, String file_name, Long file_size);
/**
* oss 腾讯上传
* 腾讯 cos 文件上传
*/
String uploadObject4OSS(File file, String concat);
/**
* 腾讯 cos 文件上传
*
* @param fileUrl
* @param concat
* @return
*/
String uploadObject4OSS(String fileUrl, String concat);
}

View File

@ -43,6 +43,9 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@ -97,6 +100,18 @@ public class OssServiceImpl implements OssService {
@Value("${upload.filepath}")
private String FILEPATH;
/**
* 判断路径是否存在不存在创建
*
* @param dirPath
*/
private static void isChartPathExist(String dirPath) {
File file = new File(dirPath);
if (!file.exists()) {
file.mkdirs();
}
}
/**
* 移动端上传文件
*
@ -288,6 +303,48 @@ public class OssServiceImpl implements OssService {
}
}
/**
* 腾讯 cos 文件上传
*
* @param fileUrl
* @param concat
* @return
*/
@Override
public String uploadObject4OSS(String fileUrl, String concat) {
try {
URL url = new URL(fileUrl);
URLConnection connection = url.openConnection();
// 获取内容长度
int contentLength = connection.getContentLength();
InputStream inputStream = connection.getInputStream();
// 创建 ObjectMetadata 并设置相关信息
com.qcloud.cos.model.ObjectMetadata metadata = new com.qcloud.cos.model.ObjectMetadata();
// 设置内容类型
metadata.setContentType(getContentType(concat));
// 设置内容长度
metadata.setContentLength(contentLength);
PutObjectRequest putObjectRequest = new PutObjectRequest(TENGXUN_BUCKET_NAME, concat, inputStream, metadata);
COSClient cosClient1 = initCOSClient();
PutObjectResult putObjectResult = cosClient1.putObject(putObjectRequest);
// 设置权限(公开读)
cosClient1.setBucketAcl(TENGXUN_BUCKET_NAME, CannedAccessControlList.PublicRead);
inputStream.close();
cosClient1.shutdown();
return TENGXUN_ENDPOINT + "/" + concat;
} catch (Exception e) {
e.printStackTrace();
throw new ApiException(I18nUtil._("文件上传到腾讯云OSS服务器异常") + e.getMessage());
}
}
public COSClient initCOSClient() {
COSCredentials cred = new BasicCOSCredentials(TENGXUN_SECRET_ID, TENGXUN_SECRET_KEY);
Region region = new Region(TENGXUN_REGION_REGION);
@ -388,10 +445,10 @@ public class OssServiceImpl implements OssService {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String dir = ALIYUN_OSS_DIR_PREFIX + sdf.format(new Date());
// 签名有效期
long expireEndTime = System.currentTimeMillis() + ALIYUN_OSS_EXPIRE * 1000;
long expireEndTime = System.currentTimeMillis() + ALIYUN_OSS_EXPIRE * 1000L;
Date expiration = new Date(expireEndTime);
// 文件大小
long maxSize = ALIYUN_OSS_MAX_SIZE * 1024 * 1024;
long maxSize = (long) ALIYUN_OSS_MAX_SIZE * 1024 * 1024;
// 回调
OssCallbackParamDTO callback = new OssCallbackParamDTO();
callback.setCallbackUrl(ALIYUN_OSS_CALLBACK);
@ -404,10 +461,10 @@ public class OssServiceImpl implements OssService {
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, maxSize);
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
String postPolicy = ossClient.generatePostPolicy(expiration, policyConds);
byte[] binaryData = postPolicy.getBytes("utf-8");
byte[] binaryData = postPolicy.getBytes(StandardCharsets.UTF_8);
String policy = BinaryUtil.toBase64String(binaryData);
String signature = ossClient.calculatePostSignature(postPolicy);
String callbackData = BinaryUtil.toBase64String(JSONUtil.parse(callback).toString().getBytes("utf-8"));
String callbackData = BinaryUtil.toBase64String(JSONUtil.parse(callback).toString().getBytes(StandardCharsets.UTF_8));
// 返回结果
result.setAccessKeyId(ossClient.getCredentialsProvider().getCredentials().getAccessKeyId());
result.setPolicy(policy);
@ -511,16 +568,4 @@ public class OssServiceImpl implements OssService {
}
}
}
/**
* 判断路径是否存在不存在创建
*
* @param dirPath
*/
private static void isChartPathExist(String dirPath) {
File file = new File(dirPath);
if (!file.exists()) {
file.mkdirs();
}
}
}

View File

@ -11,6 +11,7 @@ package com.suisung.mall.shop.store.controller.mobile;
import cn.hutool.json.JSONObject;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.service.impl.BaseControllerImpl;
import com.suisung.mall.shop.esign.service.FileAndTemplateService;
import com.suisung.mall.shop.store.service.ShopMerchEntryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -31,6 +32,15 @@ public class ShopMerchEntryController extends BaseControllerImpl {
@Resource
private ShopMerchEntryService shopMerchEntryService;
@Resource
private FileAndTemplateService fileAndTemplateService;
@ApiOperation(value = "测试", notes = "测试")
@RequestMapping(value = "/gencon", method = RequestMethod.POST)
public Object fillDocTemplate() {
return fileAndTemplateService.fillDocTemplate("yyzz787654566543", "91450881MADEQ92533");
}
@ApiOperation(value = "店铺主营分类(类目)", notes = "店铺主营分类(类目)")
@RequestMapping(value = "/business/category", method = RequestMethod.POST)