Przeglądaj źródła

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

# Conflicts:
#	src/custom/restcontroller/webmanage/sale/contracttask/EsignContractTaskMX.java
shenjingwei 1 tydzień temu
rodzic
commit
ac1f67cf2d

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

@@ -7727,6 +7727,26 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2026041715520802 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026041810335702 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026042013062102 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2026042113202402 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 195 - 0
src/custom/restcontroller/webmanage/sale/contracttask/CompanyInfo.java

@@ -0,0 +1,195 @@
+package restcontroller.webmanage.sale.contracttask;
+
+public class CompanyInfo {
+
+    //合同编号
+    private String billno;
+    //营业执照名称
+    private String licensename;
+    //营业执照地址
+    private String licenseaddress;
+    //营销区域
+    private String areaname;
+    //任务金额
+    private String taskmoney;
+    //开始期限
+    private String begindate;
+    //结束期限
+    private String enddate;
+    //保证金
+    private String securitydeposit;
+    //税号
+    private String taxno;
+    //法人
+    private String legalrep;
+    //身份证号
+    private String idcard;
+    //电话
+    private String mobile;
+    //手机
+    private String phonenumber;
+    //售前电话
+    private String presalesphonenumber;
+    //售后电话
+    private String aftersalesphonenumber;
+    //备案汇款人
+    private String paymans;
+    //省
+    private String province;
+    //市
+    private String city;
+    //县
+    private String county;
+
+    public String getBillno() {
+        return billno;
+    }
+
+    public void setBillno(String billno) {
+        this.billno = billno;
+    }
+
+    public String getLicensename() {
+        return licensename;
+    }
+
+    public void setLicensename(String licensename) {
+        this.licensename = licensename;
+    }
+
+    public String getLicenseaddress() {
+        return licenseaddress;
+    }
+
+    public void setLicenseaddress(String licenseaddress) {
+        this.licenseaddress = licenseaddress;
+    }
+
+    public String getAreaname() {
+        return areaname;
+    }
+
+    public void setAreaname(String areaname) {
+        this.areaname = areaname;
+    }
+
+    public String getTaskmoney() {
+        return taskmoney;
+    }
+
+    public void setTaskmoney(String taskmoney) {
+        this.taskmoney = taskmoney;
+    }
+
+    public String getBegindate() {
+        return begindate;
+    }
+
+    public void setBegindate(String begindate) {
+        this.begindate = begindate;
+    }
+
+    public String getEnddate() {
+        return enddate;
+    }
+
+    public void setEnddate(String enddate) {
+        this.enddate = enddate;
+    }
+
+    public String getSecuritydeposit() {
+        return securitydeposit;
+    }
+
+    public void setSecuritydeposit(String securitydeposit) {
+        this.securitydeposit = securitydeposit;
+    }
+
+    public String getTaxno() {
+        return taxno;
+    }
+
+    public void setTaxno(String taxno) {
+        this.taxno = taxno;
+    }
+
+    public String getLegalrep() {
+        return legalrep;
+    }
+
+    public void setLegalrep(String legalrep) {
+        this.legalrep = legalrep;
+    }
+
+    public String getIdcard() {
+        return idcard;
+    }
+
+    public void setIdcard(String idcard) {
+        this.idcard = idcard;
+    }
+
+    public String getMobile() {
+        return mobile;
+    }
+
+    public void setMobile(String mobile) {
+        this.mobile = mobile;
+    }
+
+    public String getPhonenumber() {
+        return phonenumber;
+    }
+
+    public void setPhonenumber(String phonenumber) {
+        this.phonenumber = phonenumber;
+    }
+
+    public String getPresalesphonenumber() {
+        return presalesphonenumber;
+    }
+
+    public void setPresalesphonenumber(String presalesphonenumber) {
+        this.presalesphonenumber = presalesphonenumber;
+    }
+
+    public String getAftersalesphonenumber() {
+        return aftersalesphonenumber;
+    }
+
+    public void setAftersalesphonenumber(String aftersalesphonenumber) {
+        this.aftersalesphonenumber = aftersalesphonenumber;
+    }
+
+    public String getPaymans() {
+        return paymans;
+    }
+
+    public void setPaymans(String paymans) {
+        this.paymans = paymans;
+    }
+
+    public String getProvince() {
+        return province;
+    }
+
+    public void setProvince(String province) {
+        this.province = province;
+    }
+
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getCounty() {
+        return county;
+    }
+
+    public void setCounty(String county) {
+        this.county = county;
+    }
+}

+ 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(content.getStringValue("idcard"), "身份证");
+        verifyValue(enterpriseRow.getString("province"), "省");
+        verifyValue(enterpriseRow.getString("city"), "市");
+        verifyValue(enterpriseRow.getString("county"), "县");
+        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) throws YosException {
+        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.setIdcard(content.getStringValue("idcard"));
+        companyInfo.setProvince(enterpriseRow.getString("province"));
+        companyInfo.setCity(enterpriseRow.getString("city"));
+        companyInfo.setCounty(enterpriseRow.getString("county"));
+        companyInfo.setBegindate(taskmxRow.getString("begindate"));
+        companyInfo.setEnddate(taskmxRow.getString("enddate"));
+        companyInfo.setAreaname(agentRow.getString("salearea"));
+        companyInfo.setSecuritydeposit(securitydeposit.toPlainString());
+        companyInfo.setTaskmoney(getTaskMoney(taskmxRow).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(Row taskmxRow) throws YosException {
+        BigDecimal y1 = taskmxRow.getBigDecimal("y1");
+        if (y1.compareTo(BigDecimal.ZERO) == 0) {
+            throw new YosException(false, "请设置季度任务金额");
+        }
+        return y1;
+    }
+
+}

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

@@ -129,6 +129,18 @@ public class ESignContractTemplate extends Controller {
         return getSucReturnObject().setData(rows).toString();
     }
 
+    @API(title = "电子签合同模板-查询启用的列表", apiversion = R.ID2026042013062102.v1.class)
+    public String list2() throws YosException {
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_esign_contract_template", "*").setTableAlias("t1");
+        querySQL.setSiteid(siteid);
+        querySQL.setWhere("t1.isenable=1");
+        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 {
 

+ 6 - 8
src/custom/restcontroller/webmanage/sale/contracttask/EsignContractTask.java

@@ -10,6 +10,8 @@ import common.data.*;
 import lombok.experimental.Delegate;
 import restcontroller.R;
 
+import java.math.BigDecimal;
+
 /**
  * 电子签合同任务
  */
@@ -122,14 +124,10 @@ public class EsignContractTask extends Controller {
         if (rows1.isNotEmpty()) {
             return getErrReturnObject().setErrMsg("请完善合同期限").toString();
         }
-        Rows rows2 = dbConnect.runSqlQuery("SELECT * from sa_esign_contract_taskmx WHERE sa_esign_contract_taskid=" + sa_esign_contract_taskid);
-        for (Row row : rows2) {
-            Long sys_enterpriseid = row.getLong("sys_enterpriseid");
-            Long year = rows.get(0).getLong("year");
-            Rows targetRows = dbConnect.runSqlQuery("SELECT * from sa_salestarget WHERE year=" + year + " and sys_enterpriseid='" + sys_enterpriseid + "' and type='季'");
-            if (targetRows.isEmpty()) {
-                return getErrReturnObject().setErrMsg("请完善经销商任务值").toString();
-            }
+
+        Rows rows2 = dbConnect.runSqlQuery("SELECT * from sa_esign_contract_taskmx WHERE sa_esign_contract_taskid=" + sa_esign_contract_taskid + " and y1=0");
+        if (rows2.isNotEmpty()) {
+            return getErrReturnObject().setErrMsg("请完善经销商季度任务金额").toString();
         }
 
 

+ 161 - 68
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;
@@ -10,12 +11,15 @@ import common.Controller;
 import common.YosException;
 import common.annotation.API;
 import common.data.*;
-import common.data.db.SQList;
+import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang.ArrayUtils;
 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;
 import java.util.Map;
 
@@ -32,7 +36,7 @@ public class EsignContractTaskMX extends Controller {
         Long sa_esign_contract_taskid = content.getLongValue("sa_esign_contract_taskid");
         JSONArray sa_agentsids = content.getJSONArray("sa_agentsids");
 
-        SQList sqlList = new SQList();
+        ArrayList<String> sqlList = new ArrayList<>();
         for (Object obj : sa_agentsids) {
             Long sa_agentsid = Long.parseLong(obj.toString());
             Rows mxRows = dbConnect.runSqlQuery("SELECT * FROM sa_esign_contract_taskmx WHERE sa_agentsid=" + sa_agentsid + " and sa_esign_contract_taskid=" + sa_esign_contract_taskid);
@@ -67,6 +71,7 @@ public class EsignContractTaskMX extends Controller {
             insertSQL.setValue("license_address", license_address);
             insertSQL.setValue("legal_rep", enterpriseRow.getString("contact"));
             insertSQL.setValue("mobile", enterpriseRow.getString("telephone"));
+            insertSQL.setValue("idcard", enterpriseRow.getString("idcard"));
             insertSQL.setValue("sa_esign_contract_taskid", sa_esign_contract_taskid);
             sqlList.add(insertSQL.getSQL());
             sqlList.add(DataContrlLog.createLog(this, "sa_esign_contract_task", sa_esign_contract_taskid, "添加", "添加经销商【" + enterprisename + "】成功").getSQL());
@@ -115,7 +120,7 @@ public class EsignContractTaskMX extends Controller {
     public String delete() throws YosException {
 
         JSONArray sa_esign_contract_taskmxids = content.getJSONArray("sa_esign_contract_taskmxids");
-        SQList sqlList = new SQList();
+        ArrayList<String> sqlList = new ArrayList<>();
 
         DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_esign_contract_taskmx");
         deleteSQL.setSiteid(siteid);
@@ -145,7 +150,7 @@ public class EsignContractTaskMX extends Controller {
         JSONArray sa_esign_contract_taskmxids = content.getJSONArray("sa_esign_contract_taskmxids");
         String begindate = content.getStringValue("begindate");
         String enddate = content.getStringValue("enddate");
-        SQList sqlList = new SQList();
+        ArrayList<String> sqlList = new ArrayList<>();
 
         UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_esign_contract_taskmx");
         updateSQL.setSiteid(siteid);
@@ -171,19 +176,56 @@ public class EsignContractTaskMX extends Controller {
         return getSucReturnObject().toString();
     }
 
+    @API(title = "电子签合同任务明细-修改季度任务金额", apiversion = R.ID2026042113202402.v1.class)
+    public String changeTaskMoney() throws YosException {
+
+        JSONArray sa_esign_contract_taskmxids = content.getJSONArray("sa_esign_contract_taskmxids");
+        BigDecimal s1 = content.getBigDecimal("s1");
+        BigDecimal s2 = content.getBigDecimal("s2");
+        BigDecimal s3 = content.getBigDecimal("s3");
+        BigDecimal s4 = content.getBigDecimal("s4");
+        BigDecimal y1 = s1.add(s2).add(s3).add(s4);
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_esign_contract_taskmx");
+        updateSQL.setSiteid(siteid);
+        updateSQL.setWhere("sa_esign_contract_taskmxid", sa_esign_contract_taskmxids);
+        updateSQL.setValue("s1", s1);
+        updateSQL.setValue("s2", s2);
+        updateSQL.setValue("s3", s3);
+        updateSQL.setValue("s4", s4);
+        updateSQL.setValue("y1", y1);
+        sqlList.add(updateSQL.getSQL());
+
+        for (Object obj : sa_esign_contract_taskmxids) {
+            Long sa_esign_contract_taskmxid = Long.parseLong(obj.toString());
+            Rows rows = dbConnect.runSqlQuery("SELECT * FROM sa_esign_contract_taskmx WHERE sa_esign_contract_taskmxid=" + sa_esign_contract_taskmxid);
+            if (rows.isNotEmpty()) {
+                Long sa_agentsid = rows.get(0).getLong("sa_agentsid");
+                Long sa_esign_contract_taskid = rows.get(0).getLong("sa_esign_contract_taskid");
+                Rows agentRows = dbConnect.runSqlQuery("SELECT * FROM sv_agents WHERE sa_agentsid=" + sa_agentsid);
+                String enterprisename = agentRows.get(0).getString("enterprisename");
+                sqlList.add(DataContrlLog.createLog(this, "sa_esign_contract_task", sa_esign_contract_taskid, "修改季度任务金额",
+                        "修改经销商【" + enterprisename + "】季度任务金为:第一季度(万元):" + s1 + ",第二季度(万元):" + s2 + ",第三季度(万元):" + s3 + ",第四季度(万元):" + s4).getSQL());
+            }
+        }
+
+        dbConnect.runSqlUpdate(sqlList);
+
+
+        return getSucReturnObject().toString();
+    }
+
 
     @API(title = "电子签合同任务明细-明细列表", apiversion = R.ID2026041315403802.v1.class)
     public String list() throws YosException {
 
         Long sa_esign_contract_taskid = content.getLongValue("sa_esign_contract_taskid");
-        Long year = 0L;
-        Rows taskrows = dbConnect.runSqlQuery("SELECT * FROM sa_esign_contract_task WHERE sa_esign_contract_taskid=" + sa_esign_contract_taskid);
-        if (taskrows.isNotEmpty()) {
-            year = taskrows.get(0).getLong("year");
-        }
 
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_esign_contract_taskmx",
-                "sa_esign_contract_taskmxid", "status", "approvestatus", "license_address", "phonenumber", "legal_rep", "begindate", "enddate", "flowid").setTableAlias("t1");
+                "sa_esign_contract_taskmxid", "status", "approvestatus", "license_address", "phonenumber", "legal_rep", "begindate", "enddate", "flowid",
+                "s1", "s2", "s3", "s4", "y1").setTableAlias("t1");
         querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t2", "t1.siteid = t2.siteid and t1.sa_agentsid=t2.sa_agentsid",
                 "sys_enterpriseid", "agentnum");
         querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t3.siteid = t2.siteid and t3.sys_enterpriseid = t2.sys_enterpriseid",
@@ -195,48 +237,12 @@ public class EsignContractTaskMX extends Controller {
         querySQL.setPage(pageSize, pageNumber);
         Rows rows = querySQL.query();
 
-        QuerySQL targetQuerySQL = SQLFactory.createQuerySQL(this, "sa_salestarget",
-                "sys_enterpriseid", "point", "target_l");
-        targetQuerySQL.setWhere("year", year);
-        targetQuerySQL.setWhere("type='季'");
-        targetQuerySQL.setWhere("sys_enterpriseid", rows.toArrayList("sys_enterpriseid"));
-
-        RowsMap targetRowsMap = targetQuerySQL.query().toRowsMap("sys_enterpriseid");
         for (Row row : rows) {
-            Long sys_enterpriseid = row.getLong("sys_enterpriseid");
-            if (targetRowsMap.containsKey(sys_enterpriseid)) {
-                Rows targetRows = targetRowsMap.get(sys_enterpriseid);
-                BigDecimal y1 = BigDecimal.ZERO;
-                for (Row targetRow : targetRows) {
-                    int point = targetRow.getInteger("point");
-                    y1 = y1.add(targetRow.getBigDecimal("target_l"));
-                    switch (point) {
-                        case 1:
-                            row.put("s1", targetRow.getBigDecimal("target_l"));
-                            break;
-                        case 2:
-                            row.put("s2", targetRow.getBigDecimal("target_l"));
-                            break;
-                        case 3:
-                            row.put("s3", targetRow.getBigDecimal("target_l"));
-                            break;
-                        case 4:
-                            row.put("s4", targetRow.getBigDecimal("target_l"));
-                            break;
-                    }
-                    row.put("y1", y1);
-                }
-            }
             row.putIfAbsent("s1", 0);
             row.putIfAbsent("s2", 0);
             row.putIfAbsent("s3", 0);
             row.putIfAbsent("s4", 0);
             row.putIfAbsent("y1", 0);
-            String flowid = row.getString("flowid");
-            if (!StringUtils.isBlank(flowid)) {
-                row.put("downloadurl", WeChatContractUtil.describeFileUrls(flowid));
-            }
-            row.putIfAbsent("downloadurl", "");
         }
 
         return getSucReturnObject().setData(rows).toString();
@@ -275,38 +281,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);
+
+        String license_name = content.getStringValue("license_name");
+        String legal_rep = content.getStringValue("legal_rep");
+        String phonenumber = content.getStringValue("phonenumber");
+
+        //构建需要上传的模板传递的数据
+        CompanyInfo companyInfo = ContractTaskUtil.getCompanyInfo(this, enterpriseRow, agentRow, taskmxrow, year, securitydeposit);
 
         UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_esign_contract_taskmx");
         updateSQL.setSiteid(siteid);
         updateSQL.setUniqueid(sa_esign_contract_taskmxid);
-        updateSQL.setValue("license_name", content.getStringValue("license_name"));
+        updateSQL.setValue("license_name", license_name);
+        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("legal_rep", content.getStringValue("legal_rep"));
         updateSQL.setValue("mobile", content.getStringValue("mobile"));
-        updateSQL.setValue("phonenumber", content.getStringValue("phonenumber"));
         updateSQL.setValue("presalesphonenumber", content.getStringValue("presalesphonenumber"));
         updateSQL.setValue("aftersalesphonenumber", content.getStringValue("aftersalesphonenumber"));
         updateSQL.setValue("paymans", content.getStringValue("paymans"));
+        updateSQL.setValue("idcard", content.getStringValue("idcard"));
+        updateSQL.setValue("companyinfo", JSON.toJSON(companyInfo));
         updateSQL.update();
         DataContrlLog.createLog(this, "sa_esign_contract_task", sa_esign_contract_taskid, "合同确认", "合同内容确认成功").insert();
 
@@ -321,24 +346,36 @@ public class EsignContractTaskMX extends Controller {
             throw new NullPointerException("签署人不能为空");
         }
         //构造签署人信息
-        FlowApproverInfo[] flowApproverInfos = WeChatByTemplate.BuildApprovers(Arrays.asList(recipients));
+        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);
+                , 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);
@@ -381,5 +418,61 @@ public class EsignContractTaskMX extends Controller {
         return getSucReturnObject().setData(rows).toString();
     }
 
+    @API(title = "区域经理查询自己管辖的经销商合同", apiversion = R.ID2026041715520802.v1.class)
+    public String agentsList2() throws YosException {
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_esign_contract_taskmx", "*").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_esign_contract_task", "t2", "t2.sa_esign_contract_taskid=t1.sa_esign_contract_taskid",
+                "taskname", "year", "senddate", "remarks");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_esign_contract_template", "t3", "t3.sa_esign_contract_templateid=t2.sa_esign_contract_templateid",
+                "name", "type");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_agents", "t4", "t4.sa_agentsid=t1.sa_agentsid",
+                "agentnum");
+        querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t5", "t5.sys_enterpriseid=t4.sys_enterpriseid", "enterprisename", "abbreviation");
+        if (getDepartment(userid).getString("depname").equals("区域经理")) {
+            querySQL.setWhere(" exists(select 1 from  sys_enterprise_tradefield where sa_agentsid=t1.sa_agentsid and hrid=" + hrid + " )");
+        }
+        querySQL.setSiteid(siteid);
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+
+        RowsMap attachmentsMap = Attachment.get(this, "sa_esign_contract_taskmx", rows.toArrayList("sa_esign_contract_taskmxid", new ArrayList<>()));
+        for (Row row : rows) {
+            String flowid = row.getString("flowid");
+            if (!StringUtils.isBlank(flowid)) {
+                row.put("downloadurl", WeChatContractUtil.describeFileUrls(flowid));
+            }
+            row.putIfAbsent("downloadurl", "");
+            Long sa_esign_contract_taskmxid = row.getLong("sa_esign_contract_taskmxid");
+            row.put("attinfos", attachmentsMap.getOrDefault(sa_esign_contract_taskmxid, new Rows()));
+        }
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "经销商档案详情中的合同查询列表", apiversion = R.ID2026041810335702.v1.class)
+    public String agentsList3() throws YosException {
+        Long sa_agentsid = content.getLongValue("sa_agentsid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_esign_contract_taskmx", "sa_esign_contract_taskmxid", "archiveddate").setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_esign_contract_task", "t2", "t2.sa_esign_contract_taskid=t1.sa_esign_contract_taskid",
+                "taskname", "year", "senddate", "remarks");
+        querySQL.addJoinTable(JOINTYPE.inner, "sa_esign_contract_template", "t3", "t3.sa_esign_contract_templateid=t2.sa_esign_contract_templateid",
+                "name", "type");
+        querySQL.setWhere("t1.sa_agentsid", sa_agentsid);
+        querySQL.setSiteid(siteid);
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+
+        RowsMap attachmentsMap = Attachment.get(this, "sa_esign_contract_taskmx", rows.toArrayList("sa_esign_contract_taskmxid", new ArrayList<>()));
+        for (Row row : rows) {
+            Long sa_esign_contract_taskmxid = row.getLong("sa_esign_contract_taskmxid");
+            row.put("attinfos", attachmentsMap.getOrDefault(sa_esign_contract_taskmxid, new Rows()));
+            row.putIfAbsent("archiveddate", "");
+        }
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
 
 }

+ 15 - 10
src/custom/restcontroller/webmanage/sale/contracttask/WeChatByTemplate.java

@@ -4,6 +4,7 @@ import com.tencentcloudapi.essbasic.v20210526.models.DescribeTemplatesResponse;
 import com.tencentcloudapi.essbasic.v20210526.models.FlowApproverInfo;
 import com.tencentcloudapi.essbasic.v20210526.models.FormField;
 import com.tencentcloudapi.essbasic.v20210526.models.Recipient;
+import org.apache.commons.codec.digest.DigestUtils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -11,7 +12,7 @@ import java.util.Optional;
 
 public class WeChatByTemplate {
     // 构造签署人 - 以B2B2C为例, 实际请根据自己的场景构造签署方、控件
-    public static FlowApproverInfo[] BuildApprovers(List<Recipient> recipients) {
+    public static FlowApproverInfo[] BuildApprovers(List<Recipient> recipients, String organizationName, String name, String phonenumber) {
 
         List<FlowApproverInfo> approvers = new ArrayList<>();
 
@@ -20,19 +21,18 @@ public class WeChatByTemplate {
         String personMobile = "*************";
 
         // 企业签署方参数
-        String organizationName = WeChatConfig.ProxyOrganizationName;
-        String organizationOpenId = WeChatConfig.ProxyOrganizationOpenId;
-        String openId = WeChatConfig.SuperProxyOperatorOpenId;
+//        String organizationOpenId = DigestUtils.sha256Hex(organizationName);
+//        String openId = DigestUtils.sha256Hex(name + phonenumber);
 
         for (Recipient recipient : recipients) {
             switch (recipient.getRecipientType()) {
                 case "ENTERPRISE":
                     // 另一家企业签署方
-                    approvers.add(BuildOrganizationApprover(organizationName, organizationOpenId, openId, recipient.getRecipientId()));
+                    approvers.add(BuildOrganizationApprover(organizationName, name, phonenumber, recipient.getRecipientId()));
                     break;
                 case "INDIVIDUAL":
                     // 个人签署方
-                    approvers.add(BuildPersonApprover(personName,personMobile, recipient.getRecipientId()));
+                    approvers.add(BuildPersonApprover(personName, personMobile, recipient.getRecipientId()));
                     break;
 
             }
@@ -61,8 +61,11 @@ public class WeChatByTemplate {
     }
 
     // 打包企业签署方参与者信息
-    public static FlowApproverInfo BuildOrganizationApprover(String organizationName, String organizationOpenId,
-                                                             String openId, String recipientId) {
+    public static FlowApproverInfo BuildOrganizationApprover(String organizationName, String name,
+                                                             String phonenumber, String recipientId) {
+
+        String organizationOpenId = DigestUtils.sha256Hex(organizationName);
+        String openId = DigestUtils.sha256Hex(name + phonenumber);
 
         // 签署参与者信息
         // 企业签署方
@@ -77,6 +80,8 @@ public class WeChatByTemplate {
         flowApproverInfo.setOpenId(openId);
 
         flowApproverInfo.setRecipientId(recipientId);
+        flowApproverInfo.setMobile(phonenumber);
+        flowApproverInfo.setName(name);
 
         return flowApproverInfo;
     }
@@ -99,11 +104,11 @@ public class WeChatByTemplate {
         DescribeTemplatesResponse templatesResponse = WeChatContractUtil.describeTemplates(WeChatContractUtil.setAgent(WeChatConfig.SuperProxyOperatorOpenId),
                 templateId);
 
-        return  Optional.ofNullable(templatesResponse).filter(template -> template.getTemplates().length > 0).
+        return Optional.ofNullable(templatesResponse).filter(template -> template.getTemplates().length > 0).
                 map(DescribeTemplatesResponse::getTemplates).map(rec -> rec[0].getRecipients()).orElse(null);
     }
 
-    public static FormField BuildFormField(String componentName, String componentValue){
+    public static FormField BuildFormField(String componentName, String componentValue) {
         FormField formField = new FormField();
         formField.setComponentName(componentName);
         formField.setComponentValue(componentValue);

+ 111 - 10
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;
 
@@ -96,7 +95,7 @@ public class WeChatContractUtil {
 
 
     //查询模板列表
-    public DescribeTemplatesResponse getTemplateList(String proxyOperatorOpenId) throws TencentCloudSDKException {
+    public static DescribeTemplatesResponse getTemplateList(String proxyOperatorOpenId) throws TencentCloudSDKException {
         EssbasicClient client = initClient();
         //根据姓名和手机号生成唯一的经办人OpenId(SHA256哈希)
         DescribeTemplatesRequest req = new DescribeTemplatesRequest();
@@ -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) {
+                                                                     FlowApproverInfo[] flowApproverInfos, String organizationOpenId, CompanyInfo companyInfo, ArrayList<String> fileBase64List) {
         Map<String, String[]> resp = new HashMap<>();
         // 设置agent参数
-        Agent agent = setAgent(SuperProxyOperatorOpenId);
+        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;
@@ -257,7 +306,27 @@ public class WeChatContractUtil {
         for (int i = 0; i < count; i++) {
             FlowInfos[i] = fillFlowInfo(templateId, flowName, flowApproverInfos);
             // 构建内容控件填充结构(根据自己需求使用)
-            FlowInfos[i].setFormFields(new FormField[]{BuildFormField("htbh", "123456")});
+            FlowInfos[i].setFormFields(new FormField[]{
+                    BuildFormField("billno", companyInfo.getBillno()),
+                    BuildFormField("licensename", companyInfo.getLicensename()),
+                    BuildFormField("licenseaddress", companyInfo.getLicenseaddress()),
+                    BuildFormField("areaname", companyInfo.getAreaname()),
+                    BuildFormField("taskmoney", companyInfo.getTaskmoney()),
+                    BuildFormField("begindate", companyInfo.getBegindate()),
+                    BuildFormField("enddate", companyInfo.getEnddate()),
+                    BuildFormField("securitydeposit", companyInfo.getSecuritydeposit()),
+                    BuildFormField("taxno", companyInfo.getTaxno()),
+                    BuildFormField("legalrep", companyInfo.getLegalrep()),
+                    BuildFormField("idcard", companyInfo.getIdcard()),
+                    BuildFormField("mobile", companyInfo.getMobile()),
+                    BuildFormField("phonenumber", companyInfo.getPhonenumber()),
+                    BuildFormField("presalesphonenumber", companyInfo.getPresalesphonenumber()),
+                    BuildFormField("aftersalesphonenumber", companyInfo.getAftersalesphonenumber()),
+                    BuildFormField("paymans", companyInfo.getPaymans()),
+                    BuildFormField("province", companyInfo.getProvince()),
+                    BuildFormField("city", companyInfo.getCity()),
+                    BuildFormField("attachment", fileIdsStr)
+            });
 
         }
 
@@ -343,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) {
@@ -409,7 +510,7 @@ public class WeChatContractUtil {
     public static void main(String[] args) throws TencentCloudSDKException {
         String[] flowIds = {"yD3g7UUckpmzhmhtU1UyFt71fypQygwg"};
 
-        DescribeFlowDetailInfoResponse res = describeFlowDetailInfo(setAgent(SuperProxyOperatorOpenId), flowIds);
+        DescribeTemplatesResponse res = getTemplateList(SuperProxyOperatorOpenId);
 
         System.err.println(DescribeTemplatesResponse.toJsonString(res));
     }