|
|
@@ -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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|