|
|
@@ -1,255 +0,0 @@
|
|
|
-package com.uas.eis.task;
|
|
|
-
|
|
|
-import com.uas.eis.beans.result.BaseResult;
|
|
|
-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;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
-import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-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;
|
|
|
-
|
|
|
-@Component
|
|
|
-@EnableAsync
|
|
|
-@EnableScheduling
|
|
|
-public class CustomerTask {
|
|
|
-
|
|
|
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private BaseDao baseDao;
|
|
|
- @Autowired
|
|
|
- private CustomerManager customerManager;
|
|
|
- @Autowired
|
|
|
- private CommonManager commonManager;
|
|
|
-
|
|
|
- @Scheduled(cron = "0 0/15 * * * ?")
|
|
|
- public void syncCustomers() {
|
|
|
- try {
|
|
|
- List<String> field_values = new ArrayList<>();
|
|
|
- SqlRowList rs = baseDao.queryForRowSet("select ml_syncTime from (select * from FXXKDockingErrorlog where nvl(ML_TYPE,' ')='客户资料下载' and ML_SYNCTIME is not null order by ml_date desc) where rownum=1");
|
|
|
- if(rs.next()){
|
|
|
- String ml_syncTime = rs.getGeneralString("ml_syncTime");
|
|
|
- field_values.add(ml_syncTime);
|
|
|
- CrmQueryResult crmQueryResult = customerManager.queryCustomer(field_values);
|
|
|
- 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");
|
|
|
- //m:成功条数 n:失败条数
|
|
|
- int m=0,n=0;
|
|
|
- if(dataList.size()>0){
|
|
|
- //最后(即最近)一次同步时间
|
|
|
- Long create_time_Last = Long.parseLong(new BigDecimal(dataList.get(dataList.size()-1).get("create_time").toString()).toPlainString());
|
|
|
- for (int i = 0; i < dataList.size(); i++) {
|
|
|
- Object _id = dataList.get(i).get("_id");
|
|
|
- Object name = dataList.get(i).get("name");
|
|
|
- //判断负责人是否存在于人员资料名称中 CRM负责人名称字段:owner__r
|
|
|
- Map<String,Object> owner__r = (Map<String,Object>) dataList.get(i).get("owner__r");
|
|
|
- //负责人姓名
|
|
|
- String owner = owner__r==null ? "" : owner__r.get("name").toString();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat(Constant.YMD_HMS);
|
|
|
- if(baseDao.checkIf("PreCustomer", "cu_name='" + name + "'")){
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'客户名称已存在','客户资料下载','"+name+"')");
|
|
|
- logger.info("异常信息:客户名称已存在");
|
|
|
- n++;
|
|
|
- continue;
|
|
|
- }
|
|
|
- try {
|
|
|
- Object em_code = baseDao.getFieldDataByCondition("employee", "max(em_code) em_code", "em_name='" + dataList.get(i).get("field_w9e4q__c") + "'");
|
|
|
- Object cu_sellercode = baseDao.getFieldDataByCondition("employee", "max(em_code) em_code", "em_name='" + owner + "'");
|
|
|
- Long create_time = Long.parseLong(new BigDecimal(dataList.get(i).get("create_time").toString()).toPlainString());
|
|
|
- Long last_modified_time = Long.parseLong(new BigDecimal(dataList.get(i).get("last_modified_time").toString()).toPlainString());
|
|
|
- String cuKind = getDisplayField(dataList, i, "account_type", "客户类型");
|
|
|
- String wbsk_user = getDisplayField(dataList, i, "UDSSel1__c", "收款方式");//外部收款方式
|
|
|
- Object[] pa_data = baseDao.getFieldsDataByCondition("Payments", new String[]{"pa_id","pa_code"}, "nvl(pa_class,' ')='收款方式' and pa_name='" + wbsk_user + "'");//获取收款方式编号
|
|
|
- String paID = (pa_data == null || pa_data[0] == null) ? "" : pa_data[0].toString();
|
|
|
- String paCode = (pa_data == null || pa_data[1] == null) ? "" : pa_data[1].toString();
|
|
|
- String cu_level = getDisplayField(dataList, i, "account_level", "客户级别");
|
|
|
- String cu_turnSAP = getDisplayField(dataList, i, "field_RYzRf__c", "是否转正式客户在SAP内建档");
|
|
|
- String cu_currency = getDisplayField(dataList, i, "field_e2HeP__c", "货币");
|
|
|
- String cu_recordType = getDisplayField(dataList, i, "record_type", "业务类型");
|
|
|
- String cu_industry = getDisplayField(dataList, i, "field_00Ijp__c", "所属行业");
|
|
|
- String cu_taxrate = getDisplayField(dataList, i, "field_nhi2w__c", "税率");
|
|
|
- String cu_code = baseDao.sGetMaxNumber("PreCustomer", 2);
|
|
|
- //field_giBJk__c:收货人 UDSText5__c:送货地址 UDSText1__c:法定代表人 UDSText2__c:注册资金
|
|
|
- String sql="insert into PreCustomer(cu_id,cu_code,cu_name,cu_shortname,cu_add2,cu_sellercode,cu_sellername,cu_servicecode,cu_servicename,cu_kind," +
|
|
|
- "cu_contact,cu_add1,cu_lawman,cu_regamount,cu_rate,cu_wbsk_user," +
|
|
|
- //"cu_paymentid,cu_paymentscode,cu_payments," +
|
|
|
- "cu_level,cu_industry,cu_mainbusiness,cu_turnSAP,cu_currency,cu_taxrate," +
|
|
|
- "cu_dealstatus,cu_Shipmentamount,cu_receivable,cu_businessRegister,cu_recordType," +
|
|
|
- "cu_mobile,cu_email,cu_recordman,cu_recorddate,cu_lastdate,cu_auditstatus,cu_auditstatuscode,cu_remark,CU_FXXKID)" +
|
|
|
- "values(PRECUSTOMER_SEQ.nextval,'"+cu_code+"','"+name+"','"+dataList.get(i).get("UDSText3__c")+"','"+ dataList.get(i).get("address")+"'," +
|
|
|
- "'"+(cu_sellercode==null?"":cu_sellercode)+"','"+owner+"','"+em_code+"','"+dataList.get(i).get("field_w9e4q__c")+"','"+cuKind+"'," +
|
|
|
- "'"+getNotNull(dataList,i,"field_giBJk__c")+"','"+getNotNull(dataList,i,"UDSText5__c")+"'," +
|
|
|
- "'"+getNotNull(dataList,i,"UDSText1__c")+"','"+getNotNull(dataList,i,"UDSText2__c")+"','" +
|
|
|
- getNotNull(dataList,i,"field_1l3xo__c")+"','"+wbsk_user+"','"
|
|
|
- //+paID+"','"+paCode+"','"+wbsk_user+"','"
|
|
|
- +cu_level+"','"+cu_industry+"'," +
|
|
|
- "'"+getNotNull(dataList,i,"UDSText4__c")+"','"+cu_turnSAP+"','"+cu_currency+"',"+cu_taxrate+",'"+getNotNull(dataList,i,"deal_status")+"'," +
|
|
|
- "'"+getNotNull(dataList,i,"field_Ezg0w__c")+"','"+getNotNull(dataList,i,"field_59oLF__c")+"','"+getNotNull(dataList,i,"biz_reg_name")+"','"+cu_recordType+"',"+
|
|
|
- "'"+dataList.get(i).get("tel")+"','"+dataList.get(i).get("email")+"'," +
|
|
|
- "'CRM',"+DateUtil.parseDateToOracleString(Constant.YMD_HMS,sdf.parse(sdf.format(create_time)))+"," +
|
|
|
- DateUtil.parseDateToOracleString(Constant.YMD_HMS,sdf.parse(sdf.format(last_modified_time)))+",'已审核','AUDITED','"+getNotNull(dataList,i,"remark")+"','"+_id+"')";
|
|
|
- baseDao.execute(sql);
|
|
|
- m++;
|
|
|
- }catch (Exception e){
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','客户资料下载','"+name+"')");
|
|
|
- logger.info("异常信息:"+e);
|
|
|
- n++;
|
|
|
- }
|
|
|
- }
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_syncTime) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'下载记录"+dataList.size()+"条,成功"+m+"条,失败"+n+"条','客户资料下载','"+create_time_Last+"')");
|
|
|
- }
|
|
|
- }else{
|
|
|
- baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','客户资料下载','')");
|
|
|
- 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()+"','客户资料下载','')");
|
|
|
- logger.info("异常信息:"+e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Scheduled(cron = "0 0 23 * * ?")
|
|
|
- public void syncUpdateCustomers() {
|
|
|
- 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();
|
|
|
- String valueField = getValueField("客户资料", "客户级别", rs.getGeneralString("cu_level"));
|
|
|
- customer.setDataObjectApiName("AccountObj");
|
|
|
- customer.set_id(rs.getGeneralString("cu_fxxkid"));
|
|
|
- customer.setName(rs.getGeneralString("cu_name"));
|
|
|
- customer.setAccount_level(valueField);
|
|
|
- customer.setField_w9e4q__c(rs.getGeneralString("cu_servicename"));
|
|
|
- BaseResult baseResult = customerManager.updateCustomer(customer);
|
|
|
- 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());
|
|
|
- }
|
|
|
- }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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 同步人员资料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");
|
|
|
- if(dataList.size()>0){
|
|
|
- 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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String getDisplayField(List<Map<String, Object>> dataList, int i, String Field, String APINAME){
|
|
|
- String ValueField ="";
|
|
|
- Object account_type = dataList.get(i).get(Field);
|
|
|
- if(account_type !=null && !"".equals(account_type.toString())){
|
|
|
- Object DISPLAYFIELD = baseDao.getFieldDataByCondition("comboData", "DISPLAYFIELD", "VALUEFIELD='" + account_type + "' and APINAME='"+APINAME+"' and MODULEAPINAME='客户资料'");
|
|
|
- ValueField= DISPLAYFIELD==null? "" :DISPLAYFIELD.toString();
|
|
|
- }
|
|
|
- return ValueField;
|
|
|
- }
|
|
|
-
|
|
|
- private String getValueField(String MODULEAPINAME, String APINAME, String DISPLAYFIELD){
|
|
|
- String result ="";
|
|
|
- if(DISPLAYFIELD !=null && !"".equals(DISPLAYFIELD)){
|
|
|
- Object VALUEFIELD = baseDao.getFieldDataByCondition("comboData", "VALUEFIELD", "MODULEAPINAME='" + MODULEAPINAME + "' and APINAME='"+APINAME+"' and DISPLAYFIELD='"+DISPLAYFIELD+"'");
|
|
|
- result = VALUEFIELD==null? "" :VALUEFIELD.toString();
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- private String getNotNull(List<Map<String, Object>> dataList, int i, String Field){
|
|
|
- return (dataList.get(i).get(Field)==null?"":dataList.get(i).get(Field)).toString();
|
|
|
- }
|
|
|
-}
|