|
|
@@ -0,0 +1,245 @@
|
|
|
+package restcontroller.webmanage.sale.contracttask;
|
|
|
+
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.*;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.lang.reflect.Array;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 电子签合同任务明细
|
|
|
+ */
|
|
|
+public class EsignContractTaskMX extends Controller {
|
|
|
+ public EsignContractTaskMX(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "电子签合同任务明细-添加经销商", apiversion = R.ID2026041315394702.v1.class)
|
|
|
+ public String addAgents() throws YosException {
|
|
|
+ Long sa_esign_contract_taskid = content.getLongValue("sa_esign_contract_taskid");
|
|
|
+ JSONArray sa_agentsids = content.getJSONArray("sa_agentsids");
|
|
|
+
|
|
|
+ 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);
|
|
|
+ if (mxRows.isNotEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Rows agentRows = dbConnect.runSqlQuery("SELECT * FROM sa_agents WHERE sa_agentsid=" + sa_agentsid);
|
|
|
+ if (agentRows.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Row agentRow = agentRows.getRow(0);
|
|
|
+ Long sys_enterpriseid = agentRow.getLong("sys_enterpriseid");
|
|
|
+ Rows enterpriseRows = dbConnect.runSqlQuery("SELECT * FROM sys_enterprise WHERE sys_enterpriseid=" + sys_enterpriseid);
|
|
|
+ if (enterpriseRows.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Row enterpriseRow = enterpriseRows.getRow(0);
|
|
|
+ String enterprisename = enterpriseRow.getString("enterprisename");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_esign_contract_taskmx");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(createTableID("sa_esign_contract_taskmx"));
|
|
|
+ insertSQL.setValue("sa_agentsid", sa_agentsid);
|
|
|
+ insertSQL.setValue("sa_esign_contract_taskid", sa_esign_contract_taskid);
|
|
|
+ insertSQL.setValue("paymans", agentRow.getString("paymans"));
|
|
|
+ insertSQL.setValue("aftersalesphonenumber", agentRow.getString("aftersalesphonenumber"));
|
|
|
+ insertSQL.setValue("presalesphonenumber", agentRow.getString("presalesphonenumber"));
|
|
|
+ insertSQL.setValue("taxno", enterpriseRow.getString("taxno"));
|
|
|
+ insertSQL.setValue("phonenumber", enterpriseRow.getString("phonenumber"));
|
|
|
+ insertSQL.setValue("license_name", enterpriseRow.getString("enterprisename"));
|
|
|
+ String license_address = enterpriseRow.getString("province") + enterpriseRow.getString("city") + enterpriseRow.getString("county") + enterpriseRow.getString("address");
|
|
|
+ insertSQL.setValue("license_address", license_address);
|
|
|
+ insertSQL.setValue("legal_rep", enterpriseRow.getString("contact"));
|
|
|
+ insertSQL.setValue("mobile", enterpriseRow.getString("telephone"));
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "电子签合同任务明细-选择经销商列表", apiversion = R.ID2026041315545602.v1.class)
|
|
|
+ public String chooseAgents() throws YosException {
|
|
|
+ Long sa_esign_contract_taskid = content.getLongValue("sa_esign_contract_taskid");
|
|
|
+ Rows templaterows = dbConnect.runSqlQuery("SELECT is_deposit_required from sa_esign_contract_template t1 " +
|
|
|
+ "INNER JOIN sa_esign_contract_task t2 ON t2.sa_esign_contract_templateid=t1.sa_esign_contract_templateid " +
|
|
|
+ "WHERE t2.sa_esign_contract_taskid=" + sa_esign_contract_taskid);
|
|
|
+ //验证是否需要保证金
|
|
|
+ boolean is_deposit_required = true;
|
|
|
+ if (templaterows.isNotEmpty()) {
|
|
|
+ is_deposit_required = templaterows.getRow(0).getBoolean("is_deposit_required");
|
|
|
+ }
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_agents", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t2", "t1.sys_enterpriseid=t2.sys_enterpriseid"
|
|
|
+ , "enterprisename", "abbreviation");
|
|
|
+ if (is_deposit_required) {
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_accountbalance", "t3", "t1.sys_enterpriseid=t3.sys_enterpriseid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_accountclass", "t4", "t3.sa_accountclassid=t4.sa_accountclassid");
|
|
|
+ querySQL.setWhere("t3.balance>0");
|
|
|
+ querySQL.setWhere("t4.accountno='02'");
|
|
|
+ }
|
|
|
+ if (getDepartment(userid).getString("depname").equals("区域经理")) {
|
|
|
+ querySQL.setWhere("t1.sys_enterpriseid in (SELECT sys_enterpriseid FROM sys_enterprise_tradefield WHERE hrid=" + hrid + ")");
|
|
|
+ }
|
|
|
+ querySQL.setWhere("NOT EXISTS (SELECT 1 from sa_esign_contract_taskmx WHERE sa_agentsid=t1.sa_agentsid and sa_esign_contract_taskid='" + sa_esign_contract_taskid + "' )");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setOrderBy("t1.createdate desc");
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "电子签合同任务明细-删除明细", apiversion = R.ID2026041315414702.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+
|
|
|
+ JSONArray sa_esign_contract_taskmxids = content.getJSONArray("sa_esign_contract_taskmxids");
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_esign_contract_taskmx");
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
+ deleteSQL.setWhere("sa_esign_contract_taskmxid", sa_esign_contract_taskmxids);
|
|
|
+ sqlList.add(deleteSQL.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 + "】成功").getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "电子签合同任务明细-修改期限", apiversion = R.ID2026041415245302.v1.class)
|
|
|
+ public String updateDate() throws YosException {
|
|
|
+ JSONArray sa_esign_contract_taskmxids = content.getJSONArray("sa_esign_contract_taskmxids");
|
|
|
+ String begindate = content.getStringValue("begindate");
|
|
|
+ String enddate = content.getStringValue("enddate");
|
|
|
+ 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("begindate", begindate);
|
|
|
+ updateSQL.setValue("enddate", enddate);
|
|
|
+ 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 + "】期限为:" + begindate + "~" + enddate).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", "license_address", "phonenumber", "legal_rep", "begindate", "enddate").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",
|
|
|
+ "enterprisename", "abbreviation", "province", "city", "county");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_tradefield", "t4", "t4.siteid = t2.siteid and t4.sys_enterpriseid = t2.sys_enterpriseid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t5", "t5.sa_saleareaid = t4.sa_saleareaid and t5.siteid = t4 .siteid", "areaname");
|
|
|
+
|
|
|
+ querySQL.setWhere("t1.sa_esign_contract_taskid=" + sa_esign_contract_taskid);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "电子签合同任务明细-编辑任务明细", apiversion = R.ID2026041315410702.v1.class)
|
|
|
+ public String edit() throws YosException {
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "经销商的合同列表", apiversion = R.ID2026041315425102.v1.class)
|
|
|
+ public String agentsList() throws YosException {
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|