Przeglądaj źródła

Merge remote-tracking branch 'origin/develop-contract' into develop-test

# Conflicts:
#	src/custom/restcontroller/R.java
wu 3 tygodni temu
rodzic
commit
e1e3044196

+ 6 - 0
pom.xml

@@ -171,6 +171,12 @@
             <version>4.0.0</version>
         </dependency>
 
+        <dependency>
+            <groupId>com.tencentcloudapi</groupId>
+            <artifactId>tencentcloud-sdk-java</artifactId>
+            <version>3.1.1439</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 30 - 0
src/custom/restcontroller/R.java

@@ -7568,6 +7568,36 @@ public class R {
         }
     }
 
+    public static class ID2026041113372302 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026041113380802 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026041113384202 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026041113390502 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026041113403102 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026041113410602 {
+        public static class v1 {
+        }
+    }
+
     public static class ID2026033013211201 {
         public static class v1 {
         }

+ 156 - 0
src/custom/restcontroller/webmanage/sale/contracttask/ESignContractTemplate.java

@@ -0,0 +1,156 @@
+package restcontroller.webmanage.sale.contracttask;
+
+import beans.datacontrllog.DataContrlLog;
+import com.alibaba.fastjson2.JSONObject;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import com.tencentcloudapi.essbasic.v20210526.models.DescribeTemplatesResponse;
+import com.tencentcloudapi.essbasic.v20210526.models.TemplateInfo;
+import common.Controller;
+import common.YosException;
+import common.annotation.API;
+import common.data.*;
+import restcontroller.R;
+
+import static restcontroller.webmanage.sale.contracttask.WeChatConfig.SuperProxyOperatorOpenId;
+
+/**
+ * 电子签合同模板
+ */
+public class ESignContractTemplate extends Controller {
+
+
+    public ESignContractTemplate(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "电子签合同模板-新增", apiversion = R.ID2026041113372302.v1.class)
+    public String insert() throws YosException, TencentCloudSDKException {
+
+        Long sa_esign_contract_templateid = createTableID("sa_esign_contract_template");
+        Boolean isenable = content.getBooleanValue("isenable");
+
+        InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_esign_contract_template");
+        insertSQL.setSiteid(siteid);
+        insertSQL.setUniqueid(sa_esign_contract_templateid);
+        insertSQL.setValue("name", content.getStringValue("name"));
+        insertSQL.setValue("type", content.getStringValue("type"));
+        insertSQL.setValue("isenable", isenable);
+        if (isenable) {
+            insertSQL.setValue("enableby", username);
+            insertSQL.setValue("enabledate", getDateTime_Str());
+        } else {
+            insertSQL.setValue("enableby", "null");
+            insertSQL.setValue("enabledate", "null");
+        }
+        insertSQL.setValue("remarks", content.getStringValue("remarks"));
+        insertSQL.setValue("templateid", content.getStringValue("templateid"));
+        insertSQL.setValue("is_deposit_required", content.getBooleanValue("is_deposit_required"));
+        insertSQL.insert();
+
+        DataContrlLog.createLog(this, "sa_esign_contract_template", sa_esign_contract_templateid, "新增", "新增合同模板");
+
+        content.put("sa_esign_contract_templateid", sa_esign_contract_templateid);
+
+        return detail();
+    }
+
+    @API(title = "电子签合同模板-编辑", apiversion = R.ID2026041113403102.v1.class)
+    public String update() throws YosException, TencentCloudSDKException {
+
+        Long sa_esign_contract_templateid = content.getLong("sa_esign_contract_templateid");
+        boolean isenable = content.getBooleanValue("isenable");
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_esign_contract_template");
+        updateSQL.setSiteid(siteid);
+        updateSQL.setUniqueid(sa_esign_contract_templateid);
+        updateSQL.setValue("remarks", content.getStringValue("remarks"));
+        if (isenable) {
+            updateSQL.setValue("isenable", 1);
+            updateSQL.setValue("enableby", username);
+            updateSQL.setValue("enabledate", getDateTime_Str());
+        } else {
+            updateSQL.setValue("isenable", 0);
+            updateSQL.setValue("enableby", "null");
+            updateSQL.setValue("enabledate", "null");
+        }
+        updateSQL.update();
+        DataContrlLog.createLog(this, "sa_esign_contract_template", sa_esign_contract_templateid, "编辑", "是否启用:" + isenable + ";备注:" + content.getStringValue("remarks"));
+
+        return detail();
+    }
+
+
+    @API(title = "电子签合同模板-删除", apiversion = R.ID2026041113380802.v1.class)
+    public String delete() throws YosException {
+        Long sa_esign_contract_templateid = content.getLong("sa_esign_contract_templateid");
+
+        DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_esign_contract_template");
+        deleteSQL.setSiteid(siteid);
+        deleteSQL.setUniqueid(sa_esign_contract_templateid);
+        deleteSQL.delete();
+
+        DataContrlLog.createLog(this, "sa_esign_contract_template", sa_esign_contract_templateid, "删除", "删除成功");
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "电子签合同模板-详情", apiversion = R.ID2026041113384202.v1.class)
+    public String detail() throws YosException, TencentCloudSDKException {
+        Long sa_esign_contract_templateid = content.getLong("sa_esign_contract_templateid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_esign_contract_template", "*").setTableAlias("t1");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("t1.sa_esign_contract_templateid", sa_esign_contract_templateid);
+        Rows rows = querySQL.query();
+        Row row = rows.isNotEmpty() ? rows.getRow(0) : new Row();
+
+        //获取电子签模板详情
+        WeChatContractUtil wccUtil = new WeChatContractUtil();
+        if (!row.getString("templateid").isEmpty()) {
+            DescribeTemplatesResponse resp = wccUtil.getTemplateDetail(SuperProxyOperatorOpenId, row.getString("templateid"));
+            row.put("templateDetail", resp.getTemplates()[0]);
+        }
+
+        return getSucReturnObject().setData(row).toString();
+    }
+
+    @API(title = "电子签合同模板-列表", apiversion = R.ID2026041113390502.v1.class)
+    public String list() throws YosException {
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_esign_contract_template", "*").setTableAlias("t1");
+        querySQL.setSiteid(siteid);
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "电子签合同模板-选择电子签合同模板列表", apiversion = R.ID2026041113410602.v1.class)
+    public String chooseTemplates() throws YosException, TencentCloudSDKException {
+
+        WeChatContractUtil wccUtil = new WeChatContractUtil();
+        DescribeTemplatesResponse resp = wccUtil.getTemplateList(SuperProxyOperatorOpenId);
+        Rows rows = new Rows();
+        for (TemplateInfo templateInfo : resp.getTemplates()) {
+            Row row = new Row();
+            row.put("templateId", templateInfo.getTemplateId());
+            row.put("templateName", templateInfo.getTemplateName());
+            row.put("description", templateInfo.getDescription());
+            row.put("templateType", templateInfo.getTemplateType());
+            row.put("isPromoter", templateInfo.getIsPromoter());
+            row.put("creator", templateInfo.getCreator());
+            row.put("createdOn", templateInfo.getCreatedOn());
+            row.put("previewUrl", templateInfo.getPreviewUrl());
+            row.put("pdfUrl", templateInfo.getPdfUrl());
+            row.put("channelTemplateId", templateInfo.getChannelTemplateId());
+            row.put("channelTemplateName", templateInfo.getChannelTemplateName());
+            row.put("channelAutoSave", templateInfo.getChannelAutoSave());
+            row.put("templateVersion", templateInfo.getTemplateVersion());
+            row.put("available", templateInfo.getAvailable());
+            row.put("userFlowType", templateInfo.getUserFlowType());
+            rows.add(row);
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+
+}

+ 63 - 0
src/custom/restcontroller/webmanage/sale/contracttask/WeChatConfig.java

@@ -0,0 +1,63 @@
+package restcontroller.webmanage.sale.contracttask;
+
+import org.apache.commons.codec.digest.DigestUtils;
+
+/**
+ * 基础配置,调用API之前必须填充的参数
+ */
+public class WeChatConfig {
+    // SecretId SecretKey 调用云API需要使用的密钥对,是平台企业的密钥对(子客企业无需准备此参数)。
+    // 联调/生产环境都是可以由平台企业电子签控制台应用集成模块自主获取。
+    public static final String SecretId = "AKyD3g9UUckpm7xfldUESaMt9uTigZZ4ym";
+    public static final String SecretKey = "SKLNHCCdOwpGEyobK19Vnntwh5DtnKA6ak";
+
+    // 应用的唯一标识,对应通用参数AppId。不同的业务系统可以采用不同的AppId,
+    // 不同AppId下的数据是隔离的。联调/生产环境都是可以由控制台开发者中心-应用集成自主生成。
+    public static final String AppId = "yD3g9UUckpm7fg9aUE66BdtzqsVl3kQL";
+
+    // 非必需
+    // 在子客企业开通电子签后,会生成唯一的子客应用Id(ProxyAppId)用于代理调用时的鉴权
+    // 在回调与跳转-电子签开通通知里会返回此数据ProxyAppId
+    public static final String ProxyAppId = "";
+
+    // 道子客企业OpenId(OrganizationOpenId):简称OrgOpenId,对应通用参数ProxyOrganizationOpenId。
+    // 是平台企业自定义,对于子客企业的唯一标识。
+    // 一个子客企业主体与子客企业ProxyOrganizationOpenId是一一对应的,不可更改,不可重复使用。
+    //(比如,可以使用企业名称的hash值,或者社会统一信用代码的hash值,或者随机hash值,需要平台企业保存)
+    // 最大64位字符串
+    // 固定为DigestUtils.sha256Hex("浙江美大实业股份有限公司");
+    // public static final String ProxyOrganizationName = "浙江美大实业股份有限公司";
+    //public static final String ProxyOrganizationOpenId = "3049ce2a73196fd18389510e1256d690a11ef0a58e0504f8df06b3dee34596b1";
+
+    public static final String ProxyOrganizationName = "嘉兴市云链信息技术有限公司测试";
+    public static final String ProxyOrganizationOpenId = DigestUtils.sha256Hex(ProxyOrganizationName);
+
+
+    // 子客企业员工/经办人OpenId(OperatorOpenId):简称员工/经办人OpenId。对应通用ProxyOperator中的参数OpenId。
+    // 是平台企业自定义,对子客企业员的唯一标识。
+    // 一个OpenId在一个子客企业内唯一对应一个真实员工,不可在其他子客企业内重复使用。
+    // (比如,可以使用经办人企业名+员工身份证的hash值,需要平台企业保存)
+    // 最大64位字符串
+    //固定为DigestUtils.sha256Hex("吴志根15669363739"); 超级管理员的openid
+    public static final String SuperProxyOperatorOpenId = "9b5a5bf63b08ca186d47dadb2b04180bf917cee4e4b2d539704ae8e85b5933c7";
+
+    // ServerSignSealId 企业方静默签用的印章Id,电子签控制台印章模块获取
+    public static String ServerSignSealId = "****************";
+
+    // ServerSignOrgName 静默签企业名称,电子签控制台企业模块获取
+    public static String ServerSignOrgName = "****************";
+
+    // EndPoint API域名,现网使用 essbasic.tencentcloudapi.com
+    public static String EndPoint = "essbasic.test.ess.tencent.cn";
+
+    // FileServiceEndPoint 文件服务域名,现网使用 file.ess.tencent.cn
+    // UploadFiles 接口使用此域名进行调用
+    public static String FileServiceEndPoint = "file.test.ess.tencent.cn";
+
+    // TemplateId 模板ID,电子签控制台模板模块获取,仅在通过模板发起时使用
+    public static final String TemplateId = "****************";
+
+    // 合同发起数量,可以修改
+    public static final int COUNT = 1;
+}
+

+ 112 - 0
src/custom/restcontroller/webmanage/sale/contracttask/WeChatContractUtil.java

@@ -0,0 +1,112 @@
+package restcontroller.webmanage.sale.contracttask;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import com.tencentcloudapi.common.profile.ClientProfile;
+import com.tencentcloudapi.common.profile.HttpProfile;
+import com.tencentcloudapi.essbasic.v20210526.EssbasicClient;
+import com.tencentcloudapi.essbasic.v20210526.models.*;
+import org.apache.commons.codec.digest.DigestUtils;
+
+import static restcontroller.webmanage.sale.contracttask.WeChatConfig.*;
+
+/**
+ * 微信电子签工具类
+ */
+public class WeChatContractUtil {
+
+    Credential cred;
+    HttpProfile httpProfile;
+    ClientProfile clientProfile;
+    EssbasicClient client;
+
+    public WeChatContractUtil() {
+        this.cred = new Credential(WeChatConfig.SecretId, WeChatConfig.SecretKey);
+        this.httpProfile = new HttpProfile();
+        this.httpProfile.setEndpoint(EndPoint);
+        this.clientProfile = new ClientProfile();
+        this.clientProfile.setHttpProfile(this.httpProfile);
+        this.client = new EssbasicClient(cred, "", clientProfile);
+    }
+
+    public Agent getAgent(String ProxyOperatorOpenId) {
+        // 构建 Agent 对象
+        Agent agent = new Agent();
+        agent.setAppId(WeChatConfig.AppId);
+        agent.setProxyOrganizationOpenId(ProxyOrganizationOpenId);
+        UserInfo userInfo = new UserInfo();
+        userInfo.setOpenId(ProxyOperatorOpenId);
+        agent.setProxyOperator(userInfo);
+        return agent;
+    }
+
+    //生成腾讯云电子签控制台登录URL
+    public String getUserConsoleUrl(String name, String phonenumber) throws TencentCloudSDKException {
+        //根据姓名和手机号生成唯一的经办人OpenId(SHA256哈希)
+        String proxyOperatorOpenId = DigestUtils.sha256Hex(name + phonenumber);
+
+        //构建Agent对象,设置应用ID、子企业OpenId和经办人信息
+        Agent agent = new Agent();
+        agent.setAppId(WeChatConfig.AppId);
+        agent.setProxyOrganizationOpenId(ProxyOrganizationOpenId);
+        UserInfo userInfo = new UserInfo();
+        userInfo.setOpenId(proxyOperatorOpenId);
+        agent.setProxyOperator(userInfo);
+
+        //调用腾讯云API创建控制台登录URL,返回包含登录链接的响应数据
+        CreateConsoleLoginUrlRequest req = new CreateConsoleLoginUrlRequest();
+        req.setAgent(agent);
+        req.setProxyOrganizationName(ProxyOrganizationName);
+        req.setProxyOperatorName(name);
+        req.setProxyOperatorMobile(phonenumber);
+
+        CreateConsoleLoginUrlResponse resp = client.CreateConsoleLoginUrl(req);
+        return CreateConsoleLoginUrlResponse.toJsonString(resp);
+    }
+
+
+    //查询模板列表
+    public DescribeTemplatesResponse getTemplateList(String proxyOperatorOpenId) throws TencentCloudSDKException {
+        //根据姓名和手机号生成唯一的经办人OpenId(SHA256哈希)
+        DescribeTemplatesRequest req = new DescribeTemplatesRequest();
+        // --- 开始构建图片中的 JSON 数据 ---
+        //设置 TemplateName: "西红柿"
+        //req.setTemplateName("西红柿");
+        // 设置 QueryAllComponents: true
+        req.setQueryAllComponents(true);
+        // 将 Agent 设置到请求中
+        req.setAgent(getAgent(proxyOperatorOpenId));
+        // --- JSON 构建结束 ---
+        // 通过client对象调用对应接口
+        DescribeTemplatesResponse resp = client.DescribeTemplates(req);
+        return resp;
+    }
+
+    public DescribeTemplatesResponse getTemplateDetail(String proxyOperatorOpenId, String TemplateId) throws TencentCloudSDKException {
+        //根据姓名和手机号生成唯一的经办人OpenId(SHA256哈希)
+        DescribeTemplatesRequest req = new DescribeTemplatesRequest();
+        req.setTemplateId(TemplateId);
+        // --- 开始构建图片中的 JSON 数据 ---
+        //设置 TemplateName: "西红柿"
+        //req.setTemplateName("西红柿");
+        // 设置 QueryAllComponents: true
+        req.setQueryAllComponents(true);
+        // 将 Agent 设置到请求中
+        req.setAgent(getAgent(proxyOperatorOpenId));
+        // --- JSON 构建结束 ---
+        // 通过client对象调用对应接口
+        DescribeTemplatesResponse resp = client.DescribeTemplates(req);
+        return resp;
+    }
+
+    public static void main(String[] args) throws TencentCloudSDKException {
+
+        WeChatContractUtil wccUtil = new WeChatContractUtil();
+        DescribeTemplatesResponse resp = wccUtil.getTemplateList(SuperProxyOperatorOpenId);
+
+        System.err.println(DescribeTemplatesResponse.toJsonString(resp));
+    }
+
+}