wu пре 5 дана
родитељ
комит
5aecedfa3f

+ 102 - 0
src/custom/restcontroller/webmanage/sale/contracttask/ContractTaskUtil.java

@@ -0,0 +1,102 @@
+package restcontroller.webmanage.sale.contracttask;
+
+import com.alibaba.fastjson2.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.data.Row;
+import common.data.Rows;
+import org.apache.commons.lang.StringUtils;
+
+import java.math.BigDecimal;
+
+public class ContractTaskUtil {
+
+    public static void check(Controller controller, Row enterpriseRow, Row agentRow, Row taskmxRow) throws YosException {
+        JSONObject content = controller.content;
+        verifyValue(content.getStringValue("license_name"), "营业执照名称");
+        verifyValue(content.getStringValue("legal_rep"), "法人");
+        verifyValue(content.getStringValue("mobile"), "电话");
+        verifyValue(content.getStringValue("phonenumber"), "手机号");
+        verifyValue(content.getStringValue("taxno"), "税号");
+        verifyValue(content.getStringValue("license_address"), "营业执照地址");
+        verifyValue(content.getStringValue("presalesphonenumber"), "售前电话");
+        verifyValue(content.getStringValue("aftersalesphonenumber"), "售后电话");
+        verifyValue(content.getStringValue("paymans"), "备案汇款人");
+        verifyValue(enterpriseRow.getString("province"), "省");
+        verifyValue(enterpriseRow.getString("city"), "市");
+        verifyValue(enterpriseRow.getString("county"), "县");
+        verifyValue(enterpriseRow.getString("idcard"), "身份证");
+        verifyValue(agentRow.getString("salearea"), "营销区域");
+        verifyValue(agentRow.getString("agentnum"), "经销商编码");
+        verifyValue(taskmxRow.getString("begindate"), "开始期限");
+        verifyValue(taskmxRow.getString("enddate"), "结束期限");
+    }
+
+    public static CompanyInfo getCompanyInfo(Controller controller, Row enterpriseRow, Row agentRow, Row taskmxRow, Long year, BigDecimal securitydeposit, BigDecimal taskmoney) {
+        JSONObject content = controller.content;
+        CompanyInfo companyInfo = new CompanyInfo();
+        companyInfo.setBillno(year + agentRow.getString("agentnum"));
+        companyInfo.setLicensename(content.getStringValue("license_name"));
+        companyInfo.setTaxno(content.getStringValue("taxno"));
+        companyInfo.setLicenseaddress(content.getStringValue("license_address"));
+        companyInfo.setLegalrep(content.getStringValue("legal_rep"));
+        companyInfo.setMobile(content.getStringValue("mobile"));
+        companyInfo.setPhonenumber(content.getStringValue("phonenumber"));
+        companyInfo.setPresalesphonenumber(content.getStringValue("presalesphonenumber"));
+        companyInfo.setAftersalesphonenumber(content.getStringValue("aftersalesphonenumber"));
+        companyInfo.setPaymans(content.getStringValue("paymans"));
+        companyInfo.setProvince(enterpriseRow.getString("province"));
+        companyInfo.setCity(enterpriseRow.getString("city"));
+        companyInfo.setCounty(enterpriseRow.getString("county"));
+        companyInfo.setIdcard(enterpriseRow.getString("idcard"));
+        companyInfo.setBegindate(taskmxRow.getString("begindate"));
+        companyInfo.setEnddate(taskmxRow.getString("enddate"));
+        companyInfo.setAreaname(agentRow.getString("salearea"));
+        companyInfo.setSecuritydeposit(securitydeposit.toPlainString());
+        companyInfo.setTaskmoney(taskmoney.toPlainString());
+        return companyInfo;
+    }
+
+
+    public static void verifyValue(String value, String info) throws YosException {
+        if (StringUtils.isBlank(value)) {
+            throw new YosException(false, info + "不能为空");
+        }
+    }
+
+    public static Row getEnterpriseRow(Controller controller, Long sys_enterpriseid) throws YosException {
+        Rows rows = controller.dbConnect.runSqlQuery("SELECT * from sys_enterprise WHERE sys_enterpriseid =" + sys_enterpriseid + " and siteid='" + controller.siteid + "'");
+        if (rows.isEmpty()) {
+            throw new YosException(false, "企业不存在");
+        }
+        return rows.getRow(0);
+    }
+
+    public static Row getAgentRow(Controller controller, Long sa_agentsid) throws YosException {
+        Rows rows = controller.dbConnect.runSqlQuery("SELECT * from sa_agents WHERE sa_agentsid =" + sa_agentsid + " and siteid='" + controller.siteid + "'");
+        if (rows.isEmpty()) {
+            throw new YosException(false, "经销商不存在");
+        }
+        return rows.getRow(0);
+    }
+
+    //查询保证金
+    public static BigDecimal getSecurityDeposit(Controller controller, Long sys_enterpriseid) throws YosException {
+        Rows rows = controller.dbConnect.runSqlQuery("select t1.balance from sa_accountbalance t1 " +
+                "INNER JOIN sa_accountclass t2 ON t2.sa_accountclassid=t1.sa_accountclassid " +
+                "WHERE t2.accountno='02' and t1.sys_enterpriseid=" + sys_enterpriseid);
+        if (rows.isEmpty()) {
+            throw new YosException(false, "保证金不存在");
+        }
+        return rows.getRow(0).getBigDecimal("balance");
+    }
+
+    public static BigDecimal getTaskMoney(Controller controller, Long sys_enterpriseid, Long year) throws YosException {
+        Rows rows = controller.dbConnect.runSqlQuery("SELECT sum(target_l) taskmoney  from sa_salestarget WHERE sys_enterpriseid=" + sys_enterpriseid + " and type='季' and year='" + year + "' ");
+        if (rows.isEmpty()) {
+            throw new YosException(false, "任务金额不存在");
+        }
+        return rows.getRow(0).getBigDecimal("taskmoney");
+    }
+
+}

+ 48 - 34
src/custom/restcontroller/webmanage/sale/contracttask/EsignContractTaskMX.java

@@ -2,6 +2,7 @@ package restcontroller.webmanage.sale.contracttask;
 
 import beans.attachment.Attachment;
 import beans.datacontrllog.DataContrlLog;
+import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.tencentcloudapi.essbasic.v20210526.models.FlowApproverInfo;
@@ -16,6 +17,7 @@ import org.apache.commons.lang.StringUtils;
 import org.camunda.bpm.container.impl.deployment.Attachments;
 import restcontroller.R;
 
+import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -277,55 +279,57 @@ public class EsignContractTaskMX extends Controller {
     public String edit() throws YosException {
 
         Long sa_esign_contract_taskmxid = content.getLongValue("sa_esign_contract_taskmxid");
-        Rows rows = dbConnect.runSqlQuery("SELECT * FROM sa_esign_contract_taskmx WHERE sa_esign_contract_taskmxid=" + sa_esign_contract_taskmxid);
-
-        if (rows.isEmpty()) {
+        Rows taskmxrows = dbConnect.runSqlQuery("SELECT * FROM sa_esign_contract_taskmx WHERE sa_esign_contract_taskmxid=" + sa_esign_contract_taskmxid);
+        if (taskmxrows.isEmpty()) {
             return getErrReturnObject().setErrMsg("合同不存在").toString();
         }
-        String status = rows.get(0).getString("status");
+        Row taskmxrow = taskmxrows.get(0);
+        Long sa_agentsid = taskmxrow.getLong("sa_agentsid");
+        Long sys_enterpriseid = taskmxrow.getLong("sys_enterpriseid");
+        String status = taskmxrow.getString("status");
+        Long sa_esign_contract_taskid = taskmxrow.getLong("sa_esign_contract_taskid");
+
         String[] statuslist = new String[]{"合同创建", "合同签署中", "合同签署完成", "合同即将过期"};
         if (ArrayUtils.contains(statuslist, status)) {
             return getErrReturnObject().setErrMsg("当前状态不支持确认合同内容").toString();
         }
-        Long sa_esign_contract_taskid = rows.get(0).getLong("sa_esign_contract_taskid");
 
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_esign_contract_template", "*").setTableAlias("t1");
-        querySQL.addJoinTable(JOINTYPE.left, "sa_esign_contract_task", "t2", "t1.sa_esign_contract_templateid=t2.sa_esign_contract_templateid");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_esign_contract_task", "t2", "t1.sa_esign_contract_templateid=t2.sa_esign_contract_templateid",
+                "year");
         querySQL.setWhere("t2.sa_esign_contract_taskid", sa_esign_contract_taskid);
         Rows templaterows = querySQL.query();
         if (templaterows.isEmpty()) {
             return getErrReturnObject().setErrMsg("合同模板不存在").toString();
         }
+        Long year = templaterows.get(0).getLong("year");
+        Row agentRow = ContractTaskUtil.getAgentRow(this, sa_agentsid);
+        Row enterpriseRow = ContractTaskUtil.getEnterpriseRow(this, sys_enterpriseid);
+        //校验参数
+//        ContractTaskUtil.check(this, agentRow, enterpriseRow, taskmxrow);
+        BigDecimal securitydeposit = ContractTaskUtil.getSecurityDeposit(this, sys_enterpriseid);
+        BigDecimal taskmoney = ContractTaskUtil.getTaskMoney(this, sys_enterpriseid, year);
 
         String license_name = content.getStringValue("license_name");
         String legal_rep = content.getStringValue("legal_rep");
-        String mobile = content.getStringValue("mobile");
         String phonenumber = content.getStringValue("phonenumber");
-        String taxno =  content.getStringValue("taxno");
-        String license_address = content.getStringValue("license_address");
 
         //构建需要上传的模板传递的数据
-        CompanyInfo companyInfo = new CompanyInfo();
-        companyInfo.setBillno("");
-        companyInfo.setLicensename(license_name);
-        companyInfo.setTaxno(taxno);
-        companyInfo.setLicenseaddress(license_address);
-        companyInfo.setLegalrep(legal_rep);
-        companyInfo.setMobile(mobile);
-        companyInfo.setPhonenumber(phonenumber);
+        CompanyInfo companyInfo = ContractTaskUtil.getCompanyInfo(this, enterpriseRow, agentRow, taskmxrow, year, securitydeposit, taskmoney);
 
         UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_esign_contract_taskmx");
         updateSQL.setSiteid(siteid);
         updateSQL.setUniqueid(sa_esign_contract_taskmxid);
         updateSQL.setValue("license_name", license_name);
-        updateSQL.setValue("taxno", taxno);
-        updateSQL.setValue("license_address", license_address);
-        updateSQL.setValue("legal_rep", license_address);
-        updateSQL.setValue("mobile", mobile);
+        updateSQL.setValue("legal_rep", legal_rep);
         updateSQL.setValue("phonenumber", phonenumber);
+        updateSQL.setValue("taxno", content.getStringValue("taxno"));
+        updateSQL.setValue("license_address", content.getStringValue("license_address"));
+        updateSQL.setValue("mobile", content.getStringValue("mobile"));
         updateSQL.setValue("presalesphonenumber", content.getStringValue("presalesphonenumber"));
         updateSQL.setValue("aftersalesphonenumber", content.getStringValue("aftersalesphonenumber"));
         updateSQL.setValue("paymans", content.getStringValue("paymans"));
+        updateSQL.setValue("companyinfo", JSON.toJSON(companyInfo));
         updateSQL.update();
         DataContrlLog.createLog(this, "sa_esign_contract_task", sa_esign_contract_taskid, "合同确认", "合同内容确认成功").insert();
 
@@ -340,26 +344,36 @@ public class EsignContractTaskMX extends Controller {
             throw new NullPointerException("签署人不能为空");
         }
         //构造签署人信息
-        FlowApproverInfo[] flowApproverInfos = WeChatByTemplate.BuildApprovers(Arrays.asList(recipients), license_name, legal_rep,phonenumber);
+        FlowApproverInfo[] flowApproverInfos = WeChatByTemplate.BuildApprovers(Arrays.asList(recipients), license_name, legal_rep, phonenumber);
 //        String organizationOpenId = DigestUtils.sha256Hex(license_name);
 
+        ArrayList<String> fileBase64List = new ArrayList<>();
+
+        Rows attachmentRows = Attachment.get(this, "sa_esign_contract_taskmx", sa_esign_contract_taskmxid);
+        for (Row attachmentRow : attachmentRows) {
+            Long attachmentid = attachmentRow.getLong("attachmentid");
+            InputStream inputStream=getAttachmentFileInputStream(attachmentid);
+            String fileBase64 = WeChatContractUtil.convertImageFileToBase64(inputStream);
+            fileBase64List.add(fileBase64);
+        }
+
 
         // 发起合同 样例为BtoC
         Map<String, String[]> resp = wccUtil.createFlowByTemplateDirectly(flowName
-                , templateId, flowApproverInfos,WeChatConfig.SuperProxyOperatorOpenId,companyInfo);
+                , templateId, flowApproverInfos, WeChatConfig.SuperProxyOperatorOpenId, companyInfo, fileBase64List);
         int count = WeChatConfig.COUNT;
         for (int i = 0; i < count; i++) {
-            // 返回合同Id
-            System.out.println("您创建的合同id为:");
-            System.out.println(resp.get("FlowIds")[i]);
-            // 返回签署的链接
-            System.out.println("签署链接为:");
-            System.out.println(resp.get("Urls")[i]);
-            // Step 3 下载合同
-            // 返回合同下载链接
-            String url = WeChatContractUtil.describeFileUrls(resp.get("FlowIds")[i]);
-            System.out.println("请访问以下地址下载您的合同:");
-            System.out.println(url);
+//            // 返回合同Id
+//            System.out.println("您创建的合同id为:");
+//            System.out.println(resp.get("FlowIds")[i]);
+//            // 返回签署的链接
+//            System.out.println("签署链接为:");
+//            System.out.println(resp.get("Urls")[i]);
+//            // Step 3 下载合同
+//            // 返回合同下载链接
+//            String url = WeChatContractUtil.describeFileUrls(resp.get("FlowIds")[i]);
+//            System.out.println("请访问以下地址下载您的合同:");
+//            System.out.println(url);
 
             updateSQL = SQLFactory.createUpdateSQL(this, "sa_esign_contract_taskmx");
             updateSQL.setSiteid(siteid);

+ 88 - 7
src/custom/restcontroller/webmanage/sale/contracttask/WeChatContractUtil.java

@@ -1,18 +1,17 @@
 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 com.tencentcloudapi.tke.v20180525.models.Switch;
-import com.tencentcloudapi.tsf.v20180326.models.TerminateTaskFlowBatchRequest;
-import common.YosException;
 import org.apache.commons.codec.digest.DigestUtils;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Base64;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -237,6 +236,39 @@ public class WeChatContractUtil {
         return urlResp.getFlowResourceUrlInfos()[0].getResourceUrlInfos()[0].getUrl();
     }
 
+    public static UploadFilesResponse uploadFiles(Agent agent, UploadFile[] uploadFile) {
+        try {
+            // 实例化一个认证对象,入参需要传入腾讯云账户SecretId,SecretKey,此处还需注意密钥对的保密
+            // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
+            Credential cred = new Credential(WeChatConfig.SecretId, WeChatConfig.SecretKey);
+            // 实例化一个http选项,可选的,没有特殊需求可以跳过
+            HttpProfile httpProfile = new HttpProfile();
+            httpProfile.setEndpoint(FileServiceEndPoint);
+            // 实例化一个client选项,可选的,没有特殊需求可以跳过
+            ClientProfile clientProfile = new ClientProfile();
+            clientProfile.setHttpProfile(httpProfile);
+            // 实例化要请求产品的client对象,clientProfile是可选的
+            EssbasicClient client = new EssbasicClient(cred, "", clientProfile);
+            // 实例化一个请求对象,每个接口都会对应一个request对象
+            UploadFilesRequest req = new UploadFilesRequest();
+
+
+            req.setAgent(agent);
+
+            req.setFileInfos(uploadFile);
+
+            req.setBusinessType("DOCUMENT");
+
+            // 返回的resp是一个UploadFilesResponse的实例,与请求对象对应
+            UploadFilesResponse resp = client.UploadFiles(req);
+            System.err.println(resp);
+            return resp;
+        } catch (TencentCloudSDKException e) {
+            System.out.println(e.toString());
+        }
+        return null;
+    }
+
     /**
      * 通过文件base64直接发起签署流程
      *
@@ -246,10 +278,27 @@ public class WeChatContractUtil {
      */
     public static Map<String, String[]> createFlowByTemplateDirectly(String flowName,
                                                                      String templateId,
-                                                                     FlowApproverInfo[] flowApproverInfos, String organizationOpenId, CompanyInfo companyInfo) {
+                                                                     FlowApproverInfo[] flowApproverInfos, String organizationOpenId, CompanyInfo companyInfo, ArrayList<String> fileBase64List) {
         Map<String, String[]> resp = new HashMap<>();
         // 设置agent参数
         Agent agent = setAgent(organizationOpenId);
+
+        // 设置uploadFile参数,这里可以修改传入数量
+        UploadFile[] uploadFiles = new UploadFile[fileBase64List.size()];
+        for (int i = 0; i < fileBase64List.size(); i++) {
+            UploadFile file = new UploadFile();
+            file.setFileBody(fileBase64List.get(i));
+            uploadFiles[i] = file;
+        }
+        // 上传文件获取fileId
+        UploadFilesResponse uploadRes = uploadFiles(agent, uploadFiles);
+
+        // fileId
+        assert uploadRes != null;
+        String[] fileId = uploadRes.getFileIds();
+
+        String fileIdsStr = String.join(",", fileId);
+
         // 创建签署流程
         // 签署数量
         int count = WeChatConfig.COUNT;
@@ -276,7 +325,7 @@ public class WeChatContractUtil {
                     BuildFormField("paymans", companyInfo.getPaymans()),
                     BuildFormField("province", companyInfo.getProvince()),
                     BuildFormField("city", companyInfo.getCity()),
-                    BuildFormField("county", companyInfo.getCounty())
+                    BuildFormField("attachment", fileIdsStr)
             });
 
         }
@@ -363,6 +412,38 @@ public class WeChatContractUtil {
         return null;
     }
 
+    /**
+     * 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
+     *
+     * @param filePath 文件路径
+     * @return FlowInfo
+     */
+    public static String convertImageFileToBase64(InputStream inputStream) {
+        byte[] buffer = null;
+        try {
+            int count = 0;
+            while (count == 0) {
+                count = inputStream.available();
+            }
+            buffer = new byte[count];
+            inputStream.read(buffer);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (inputStream != null) {
+                try {
+                    // 关闭inputStream流
+                    inputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        // 对字节数组Base64编码
+        Base64.Encoder encoder = Base64.getEncoder();
+        return encoder.encodeToString(buffer);
+    }
+
     public static String getFlowStatus(String flowStatus) {
 
         switch (flowStatus) {