Browse Source

客户资料下载 同步业务员变更

samhoo 3 years ago
parent
commit
b2644b18d9

+ 34 - 0
src/main/java/com/uas/eis/beans/req/CrmChangeOwnerReq.java

@@ -0,0 +1,34 @@
+package com.uas.eis.beans.req;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Crm更新对象数据参数
+ * Created by zhongcy on 2017/1/4.
+ */
+public class CrmChangeOwnerReq<T> extends BaseOfOpenUserIdReq {
+    private static final long serialVersionUID = -3661876864620608225L;
+
+    private T data;
+
+    public CrmChangeOwnerReq() {
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("corpAccessToken", corpAccessToken)
+                .add("corpId", corpId)
+                .add("currentOpenUserId", currentOpenUserId)
+                .add("data", data)
+                .toString();
+    }
+}

+ 4 - 0
src/main/java/com/uas/eis/manager/CommonManager.java

@@ -1,11 +1,15 @@
 package com.uas.eis.manager;
 
+import com.uas.eis.beans.result.BaseResult;
 import com.uas.eis.beans.result.CrmQueryResult;
 import com.uas.eis.exception.AccessTokenException;
 
 import java.util.List;
+import java.util.Map;
 
 public interface CommonManager {
 
     public CrmQueryResult queryCommon(String field_name, List<String> field_values, String operator, String orderFieldName, Boolean orderAsc, int limit, String dataObjectApiName, Boolean isCustom) throws AccessTokenException;
+
+    public BaseResult changeOwnerCommon(List<Map<String,Object>> list, String dataObjectApiName) throws AccessTokenException;
 }

+ 28 - 0
src/main/java/com/uas/eis/manager/impl/CommonManagerImpl.java

@@ -1,7 +1,9 @@
 package com.uas.eis.manager.impl;
 
 import com.uas.eis.beans.CorpAccessToken;
+import com.uas.eis.beans.req.CrmChangeOwnerReq;
 import com.uas.eis.beans.req.CrmQueryReq;
+import com.uas.eis.beans.result.BaseResult;
 import com.uas.eis.beans.result.CrmQueryResult;
 import com.uas.eis.exception.AccessTokenException;
 import com.uas.eis.manager.AccessTokenManager;
@@ -12,7 +14,9 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Service("commonManager")
 public class CommonManagerImpl implements CommonManager {
@@ -73,4 +77,28 @@ public class CommonManagerImpl implements CommonManager {
         }
         return crmQueryResult;
     }
+
+    @Override
+    public BaseResult changeOwnerCommon(List<Map<String,Object>> list,String dataObjectApiName) throws AccessTokenException{
+        BaseResult baseResult = new BaseResult();
+        CorpAccessToken token = accessTokenManager.getCorpAccessToken();
+        String openUserId = configuration.getOpenUserId();
+
+        Map<String,Object> dataMap = new HashMap<>();
+        dataMap.put("Data",list);
+        dataMap.put("dataObjectApiName",dataObjectApiName);
+
+        CrmChangeOwnerReq changeOwnerReq = new CrmChangeOwnerReq();
+        changeOwnerReq.setCorpAccessToken(token.getCorpAccessToken());
+        changeOwnerReq.setCorpId(token.getCorpId());
+        changeOwnerReq.setCurrentOpenUserId(openUserId);
+        changeOwnerReq.setData(dataMap);
+
+        try {
+            baseResult = OpenAPIUtils.changeCrmOwner(changeOwnerReq);
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return baseResult;
+    }
 }

+ 80 - 4
src/main/java/com/uas/eis/task/CustomerTask.java

@@ -5,6 +5,7 @@ import com.uas.eis.beans.result.CrmQueryResult;
 import com.uas.eis.beans.result.Customer;
 import com.uas.eis.dao.BaseDao;
 import com.uas.eis.dao.SqlRowList;
+import com.uas.eis.manager.CommonManager;
 import com.uas.eis.manager.CustomerManager;
 import com.uas.eis.utils.Constant;
 import com.uas.eis.utils.DateUtil;
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Component;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -33,6 +35,8 @@ public class CustomerTask {
     private BaseDao baseDao;
     @Autowired
     private CustomerManager customerManager;
+    @Autowired
+    private CommonManager commonManager;
 
     @Scheduled(cron = "0 0/15 * * * ?")
     public void syncCustomers() {
@@ -122,7 +126,7 @@ public class CustomerTask {
 
     @Scheduled(cron = "0 0 23 * * ?")
     public void syncUpdateCustomers() {
-        SqlRowList rs = baseDao.queryForRowSet("select * from (select distinct cui_code from customerUpdInfo where trunc(cui_date)=trunc(sysdate)) left join precustomer on cui_code=cu_code where nvl(cu_name,' ')<>' ' order by cu_id");
+        SqlRowList rs = baseDao.queryForRowSet("select * from (select distinct cui_code from customerUpdInfo where CUI_UPDATEDATE is null and nvl(cui_type,' ')='普通变更' and trunc(cui_date)=trunc(sysdate)) left join customer on cui_code=cu_code where nvl(cu_name,' ')<>' ' order by cu_id");
         while (rs.next()){
             try {
                 Customer customer = new Customer();
@@ -135,13 +139,85 @@ public class CustomerTask {
                 BaseResult baseResult = customerManager.updateCustomer(customer);
                 int errorCode = baseResult.getErrorCode();
                 if(errorCode == 0){
-                    baseDao.execute("update customerUpdInfo set cui_updatestatus='已更新',cui_updatedate=sysdate where cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
+                    baseDao.execute("update customerUpdInfo set cui_updatestatus='已更新',cui_updatedate=sysdate where nvl(cui_type,' ')='普通变更' and cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
                 }else{
-                    baseDao.execute("update customerUpdInfo set cui_error='"+baseResult.getErrorMessage()+"' where cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
+                    baseDao.execute("update customerUpdInfo set cui_error='"+baseResult.getErrorMessage()+"' where nvl(cui_type,' ')='普通变更' and cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
                     logger.info("异常信息:"+baseResult.getErrorMessage());
                 }
             }catch (Exception e){
-                baseDao.execute("update customerUpdInfo set cui_error='"+e.getMessage()+"' where cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
+                baseDao.execute("update customerUpdInfo set cui_error='"+e.getMessage()+"' where nvl(cui_type,' ')='普通变更' and cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
+                logger.info("异常信息:"+e.getMessage());
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * 同步人员资料crm唯一id
+     */
+    @Scheduled(cron = "0 0/5 * * * ?")
+    public void syncEmployeeFXXKID() {
+        SqlRowList rs = baseDao.queryForRowSet("select em_id,em_name,em_code from employee where nvl(EM_FXXKID,' ')=' ' and nvl(EM_ISSYNCFXXKID,0)=-1 order by em_id");
+        while (rs.next()){
+            try {
+                List<String> field_values = new ArrayList<>();
+                field_values.add(rs.getGeneralString("em_name"));
+                CrmQueryResult crmQueryResult = commonManager.queryCommon("name", field_values, "EQ", "name", true, 50, "PersonnelObj", true);
+                int errorCode = crmQueryResult.getErrorCode();
+                if(errorCode == 0) {
+                    Map<String, Object> data = crmQueryResult.getData();
+                    List<Map<String, Object>> dataList = (List<Map<String, Object>>) data.get("dataList");
+                    Object user_id = dataList.get(0).get("user_id");
+                    if(user_id!=null){
+                        baseDao.execute("update employee set em_fxxkid='"+user_id+"' where em_id="+rs.getGeneralInt("em_id"));
+                        baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'人员资料纷享销客主键下载成功','人员资料纷享销客主键下载','"+rs.getGeneralString("em_code")+"')");
+                    }else{
+                        baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','人员资料纷享销客主键下载','"+rs.getGeneralString("em_code")+"')");
+                        logger.info("异常信息:crm不存在该人员资料");
+                    }
+                }else{
+                    baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','人员资料纷享销客主键下载','"+rs.getGeneralString("em_code")+"')");
+                    logger.info("异常信息:"+crmQueryResult.getErrorMessage());
+                }
+            }catch (Exception e){
+                baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+e.getMessage()+"','人员资料纷享销客主键下载','"+rs.getGeneralString("em_code")+"')");
+                logger.info("异常信息:"+e.getMessage());
+                e.printStackTrace();
+            }
+        }
+    }
+
+    /**
+     * 变更负责人
+     */
+    @Scheduled(cron = "0 0 23 * * ?")
+    public void syncChangeSellerCustomers() {
+        SqlRowList rs = baseDao.queryForRowSet("select * from (select distinct cui_code from customerUpdInfo where CUI_UPDATEDATE is null and nvl(cui_type,' ')='变更负责人' and trunc(cui_date)=trunc(sysdate)) left join customer on cui_code=cu_code left join employee on cu_sellercode=em_code where nvl(cu_name,' ')<>' ' order by cu_id");
+        String dataObjectApiName="AccountObj";
+        while (rs.next()){
+            try {
+                if(rs.getGeneralString("em_fxxkid")!=null && !"".equals(rs.getGeneralString("em_fxxkid")) && rs.getGeneralString("cu_fxxkid")!=null && !"".equals(rs.getGeneralString("cu_fxxkid"))){
+                    List<Map<String,Object>> list = new ArrayList<>();
+                    Map<String,Object> map = new HashMap<>();
+                    List<String> emfxxidList = new ArrayList<>();
+                    emfxxidList.add(rs.getGeneralString("em_fxxkid"));
+                    map.put("ownerId",emfxxidList);
+                    map.put("objectDataId",rs.getGeneralString("cu_fxxkid"));
+                    list.add(map);
+                    BaseResult baseResult = commonManager.changeOwnerCommon(list, dataObjectApiName);
+                    int errorCode = baseResult.getErrorCode();
+                    if(errorCode == 0){
+                        baseDao.execute("update customerUpdInfo set cui_updatestatus='已更新',cui_updatedate=sysdate where nvl(cui_type,' ')='变更负责人' and cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
+                    }else{
+                        baseDao.execute("update customerUpdInfo set cui_error='"+baseResult.getErrorMessage()+"' where nvl(cui_type,' ')='变更负责人' and cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
+                        logger.info("异常信息:"+baseResult.getErrorMessage());
+                    }
+                }else{
+                    baseDao.execute("update customerUpdInfo set cui_error='客户对应业务员对应人员表中纷享销客ID为空或客户资料纷享销客ID为空' where nvl(cui_type,' ')='变更负责人' and cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
+                    logger.info("异常信息:客户对应业务员对应人员表中纷享销客ID为空或客户资料纷享销客ID为空");
+                }
+            }catch (Exception e){
+                baseDao.execute("update customerUpdInfo set cui_error='"+e.getMessage()+"' where nvl(cui_type,' ')='变更负责人' and cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
                 logger.info("异常信息:"+e.getMessage());
                 e.printStackTrace();
             }

+ 1 - 1
src/main/java/com/uas/eis/task/YITCustomerTask.java

@@ -129,7 +129,7 @@ public class YITCustomerTask {
     @Scheduled(cron = "0 0 23 * * ?")
     public void syncUpdateCustomers() {
         String Master ="YIT.";
-        SqlRowList rs = baseDao.queryForRowSet("select * from (select distinct cui_code from "+Master+"customerUpdInfo where trunc(cui_date)=trunc(sysdate)) left join "+Master+"precustomer on cui_code=cu_code where nvl(cu_name,' ')<>' ' order by cu_id");
+        SqlRowList rs = baseDao.queryForRowSet("select * from (select distinct cui_code from "+Master+"customerUpdInfo where CUI_UPDATEDATE is null and trunc(cui_date)=trunc(sysdate)) left join "+Master+"customer on cui_code=cu_code where nvl(cu_name,' ')<>' ' order by cu_id");
         while (rs.next()){
             try {
                 Customer customer = new Customer();

+ 8 - 7
src/main/java/com/uas/eis/utils/OpenAPIUtils.java

@@ -130,13 +130,14 @@ public class OpenAPIUtils {
         return doPost(url, arg, CrmDescResult.class);
     }
     
-    *//**
+    */
+    /**
      * CRM 字段描述  修改负责人
-     *//*
-    public static BaseResult changeCrmOwner(CrmChangeOwnerArg arg) {
-        String url = prefix + "/cgi/crm/data/changeOwner";
+     */
+    public static BaseResult changeCrmOwner(CrmChangeOwnerReq arg) {
+        String url = prefix + "/cgi/crm/v2/data/changeOwner";
         return doPost(url, arg, BaseResult.class);
-    }*/
+    }
     
     /**
      * CRM添加 元数据接口
@@ -266,9 +267,9 @@ public class OpenAPIUtils {
 
         try {
             String reqJosn = new Gson().toJson(req);
-            //System.out.println("reqJosn"+reqJosn);
+            System.out.println("reqJosn"+reqJosn);
             HttpResponseMessageVO resp = HttpTookit.sendPostByJson(url, reqJosn);
-            //System.out.println("content"+resp.getContent());
+            System.out.println("content"+resp.getContent());
             if ("200".equals(resp.getHttpCode())) {
                 result.setData(resp.getContent());
             } else {