Ver Fonte

新增crm同步e订单客户档案自动任务

shenjingwei há 1 mês atrás
pai
commit
2849d0485d

+ 114 - 0
src/custom/common/crm/bean/customer.java

@@ -0,0 +1,114 @@
+package common.crm.bean;
+
+import common.YosException;
+import common.crm.bean.core.CrmBase;
+import common.data.*;
+import org.apache.logging.log4j.Logger;
+
+import java.util.ArrayList;
+
+public class customer extends CrmBase {
+    public customer(Logger logger) {
+        super(logger);
+    }
+
+    @Override
+    public void autoAction() throws YosException {
+        Rows rows = crmDBConnect.runSqlQuery("select t1.id as syncid,t2.* from (select max(id) id,ownerid from e_order_sync where ownertable='st_customer' group by ownerid) t1 left join st_customer t2 on t1.ownerid=t2.cid");
+        logger.info("监测到crm有{}个客户档案待同步" + rows.size());
+        ArrayList<String> agentnums = rows.toArrayList("fagent_num_created");
+        agentnums.addAll(rows.toArrayList("fagent_num"));
+
+        QuerySQL agentQuery = SQLFactory.createQuerySQL(dbConnect, "sa_agents", "sa_agentsid", "sys_enterpriseid", "agentnum");
+        agentQuery.setWhere("siteid", "MD");
+        agentQuery.setWhere("agentnum", agentnums);
+        RowsMap agentRowsMap = agentQuery.query().toRowsMap("agentnum");
+
+
+        RowsMap regionsMap = dbConnect.runSqlQuery("select code,name from t_regions where countryid=1").toRowsMap("code");
+
+        for (Row row : rows) {
+            long syncid = row.getLong("syncid");
+            long cid = row.getLong("cid");
+            String createby = row.getString("createby");
+            String createtime = row.getString("createtime");
+            String changeby = row.getString("changeby");
+            String changetime = row.getString("changetime");
+            String customer_status = row.getString("customer_status");
+            String fchannel = row.getString("fchannel");
+            String fname = row.getString("fname");
+            String fphone = row.getString("fphone");
+            String fcommunity = row.getString("fcommunity");
+            String fcustom_num = row.getString("fcustom_num");
+            String fagent_num_created = row.getString("fagent_num_created");
+            String fagent_num = row.getString("fagent_num");
+            String fprovince = row.getString("fprovince");
+            String fcity = row.getString("fcity");
+            String fcounty = row.getString("fcounty");
+
+            if (agentRowsMap.containsKey(fagent_num_created)) {
+                if (dbConnect.runSqlQuery("select * from sa_customers where sa_customersid=" + cid).isEmpty()) {
+                    InsertSQL insertSQL = SQLFactory.createInsertSQL(dbConnect, "sa_customers");
+                    insertSQL.setValue("siteid", "MD");
+                    insertSQL.setValue("sa_customersid", cid);
+                    insertSQL.setValue("createby", createby);
+                    insertSQL.setValue("createdate", createtime);
+                    insertSQL.setValue("changeby", changeby);
+                    insertSQL.setValue("changedate", changetime);
+                    insertSQL.setValue("sys_enterpriseid", agentRowsMap.get(fagent_num_created).get(0).getLong("sys_enterpriseid"));
+                    insertSQL.setValue("sa_agentsid", agentRowsMap.get(fagent_num_created).get(0).getLong("sa_agentsid"));
+                    if (agentRowsMap.containsKey(fagent_num)) {
+                        insertSQL.setValue("sa_agentsid_to", agentRowsMap.get(fagent_num).get(0).getLong("sa_agentsid"));
+                    }
+                    insertSQL.setValue("status", customer_status);
+                    insertSQL.setValue("source", fchannel);
+                    insertSQL.setValue("tradingstatus", customer_status.equals("正式客户") ? "已成交" : "未成交");
+                    insertSQL.setValue("datastatus", 0);
+                    insertSQL.setValue("ispublic", 0);
+                    insertSQL.setValue("name", fname);
+                    insertSQL.setValue("phonenumber", fphone);
+                    if (regionsMap.containsKey(fprovince)) {
+                        insertSQL.setValue("province", regionsMap.get(fprovince).get(0).getString("name"));
+                    }
+                    if (regionsMap.containsKey(fcity)) {
+                        insertSQL.setValue("city", regionsMap.get(fcity).get(0).getString("name"));
+                    }
+                    if (regionsMap.containsKey(fcounty)) {
+                        insertSQL.setValue("county", regionsMap.get(fcounty).get(0).getString("name"));
+                    }
+                    insertSQL.setValue("address", fcommunity);
+                    insertSQL.setValue("custnum", fcustom_num);
+                    insertSQL.insert();
+                } else {
+                    UpdateSQL updateSQL = SQLFactory.createUpdateSQL(dbConnect, "sa_customers");
+                    updateSQL.setValue("changeby", changeby);
+                    updateSQL.setValue("changedate", changetime);
+                    if (agentRowsMap.containsKey(fagent_num)) {
+                        updateSQL.setValue("sa_agentsid_to", agentRowsMap.get(fagent_num).get(0).getLong("sa_agentsid"));
+                    }
+                    updateSQL.setValue("status", customer_status);
+                    updateSQL.setValue("source", fchannel);
+                    updateSQL.setValue("tradingstatus", customer_status.equals("正式客户") ? "已成交" : "未成交");
+                    updateSQL.setValue("name", fname);
+                    updateSQL.setValue("phonenumber", fphone);
+                    if (regionsMap.containsKey(fprovince)) {
+                        updateSQL.setValue("province", regionsMap.get(fprovince).get(0).getString("name"));
+                    }
+                    if (regionsMap.containsKey(fcity)) {
+                        updateSQL.setValue("city", regionsMap.get(fcity).get(0).getString("name"));
+                    }
+                    if (regionsMap.containsKey(fcounty)) {
+                        updateSQL.setValue("county", regionsMap.get(fcounty).get(0).getString("name"));
+                    }
+                    updateSQL.setValue("address", fcommunity);
+                    updateSQL.setValue("custnum", fcustom_num);
+
+                    updateSQL.setWhere("siteid", "MD");
+                    updateSQL.setWhere("sa_customersid", cid);
+                    updateSQL.update();
+                }
+            }
+            crmDBConnect.runSqlUpdate("delete from e_order_sync where ownertable='st_customer' and dataid=" + cid + " and id<=" + syncid);
+        }
+    }
+}

+ 16 - 0
src/custom/common/crm/bean/custorder.java

@@ -0,0 +1,16 @@
+package common.crm.bean;
+
+import common.YosException;
+import common.crm.bean.core.CrmBase;
+import org.apache.logging.log4j.Logger;
+
+public class custorder extends CrmBase {
+    public custorder(Logger logger) {
+        super(logger);
+    }
+
+    @Override
+    public void autoAction() throws YosException {
+        crmDBConnect.runSqlUpdate("delete from e_order_sync where ownertable='st_custorder'");
+    }
+}

+ 5 - 1
src/custom/restcontroller/sale/report/DTPHB.java

@@ -19,9 +19,13 @@ public class DTPHB extends Controller {
 
     @API(title = "动态平衡表查询", apiversion = R.ID2025120115482401.v1.class)
     public String getData() throws YosException {
+        String ffitemclsnum = content.getStringValue("ffitemclsnum");
+        String ffdate = content.getStringValue("ffdate");
+        String ffitemno = content.getStringValue("ffitemno");
+
         JSONObject dataObject = new JSONObject();
         DBConnect dbConnect = new DBConnect();
-        Rows rows = dbConnect.runSqlQuery("CALL DTPHBNEW('1','2025-12-01','','') ");
+        Rows rows = dbConnect.runSqlQuery("CALL DTPHBNEW('" + ffitemclsnum + "','" + ffdate + "','" + ffitemno + "','') ");
         dataObject.put("mx", rows.toJsonArray());
         ArrayList<String> fieldList = rows.getFieldList();
         ArrayList<String> pzdhlist = rows.toArrayList("配置代号");

+ 10 - 0
src/custom/service/CRMDataSync.java

@@ -61,6 +61,16 @@ public class CRMDataSync extends ServiceController {
         } catch (Exception e) {
             logger.error(e);
         }
+        try {
+            new customer(logger).autoAction();//获取客户档案
+        } catch (Exception e) {
+            logger.error(e);
+        }
+        try {
+            new custorder(logger).autoAction();//获取客户订单
+        } catch (Exception e) {
+            logger.error(e);
+        }
     }
 
     @Override