|
|
@@ -0,0 +1,181 @@
|
|
|
+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.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.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+@EnableAsync
|
|
|
+@EnableScheduling
|
|
|
+public class YITCustomerTask {
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+ @Autowired
|
|
|
+ private CustomerManager customerManager;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0/5 * * * ?")
|
|
|
+ public void syncCustomers() {
|
|
|
+ String Master ="YIT.";
|
|
|
+ try {
|
|
|
+ List<String> field_values = new ArrayList<>();
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet("select ml_syncTime from (select * from "+Master+"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,k=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");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(Constant.YMD_HMS);
|
|
|
+ //判断是否为易探客户 根据负责人是否存在于易探人员资料名称中 CRM负责人字段:relevant_team__r
|
|
|
+ String relevant_team__r = getNotNull(dataList, i, "relevant_team__r");
|
|
|
+
|
|
|
+ if(!baseDao.checkIf(Master+"employee","nvl(em_statuscode,' ')='AUDITED' and nvl(em_name,' ')= '"+relevant_team__r+"'")){
|
|
|
+ k++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(baseDao.checkIf(Master+"PreCustomer", "cu_name='" + name + "'")){
|
|
|
+ baseDao.execute("insert into "+Master+"FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values("+Master+"FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'客户名称已存在','客户资料下载','"+name+"')");
|
|
|
+ logger.info("异常信息:客户名称已存在");
|
|
|
+ n++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Object em_code = baseDao.getFieldDataByCondition(Master+"employee", "max(em_code) em_code", "em_name='" + dataList.get(i).get("field_w9e4q__c") + "'");
|
|
|
+ Object cu_sellercode = baseDao.getFieldDataByCondition(Master+"employee", "max(em_code) em_code", "em_name='" + dataList.get(i).get("relevant_team__r") + "'");
|
|
|
+ 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(Master+"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(Master+"PreCustomer", 2);
|
|
|
+ //field_giBJk__c:收货人 UDSText5__c:送货地址 UDSText1__c:法定代表人 UDSText2__c:注册资金
|
|
|
+ String sql="insert into "+Master+"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)+"','"+getNotNull(dataList,i,"relevant_team__r")+"','"+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 "+Master+"FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values("+Master+"FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','客户资料下载','"+name+"')");
|
|
|
+ logger.info("异常信息:"+e);
|
|
|
+ n++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ baseDao.execute("insert into "+Master+"FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_syncTime) values("+Master+"FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'下载记录"+dataList.size()+"条,成功"+m+"条,失败"+n+"条,非易探客户"+k+"条','客户资料下载','"+create_time_Last+"')");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ baseDao.execute("insert into "+Master+"FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values("+Master+"FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmQueryResult.getErrorMessage()+"','客户资料下载','')");
|
|
|
+ logger.info("异常信息:"+crmQueryResult.getErrorMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ baseDao.execute("insert into "+Master+"FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values("+Master+"FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+e.getMessage()+"','客户资料下载','')");
|
|
|
+ logger.info("异常信息:"+e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @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");
|
|
|
+ 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 "+Master+"customerUpdInfo set cui_updatestatus='已更新',cui_updatedate=sysdate where cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
|
|
|
+ }else{
|
|
|
+ baseDao.execute("update "+Master+"customerUpdInfo set cui_error='"+baseResult.getErrorMessage()+"' where cui_code='"+rs.getGeneralString("cui_code")+"' and trunc(cui_date)=trunc(sysdate)");
|
|
|
+ logger.info("异常信息:"+baseResult.getErrorMessage());
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ baseDao.execute("update "+Master+"customerUpdInfo set cui_error='"+e.getMessage()+"' where 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 Master ="YIT.";
|
|
|
+ String ValueField ="";
|
|
|
+ Object account_type = dataList.get(i).get(Field);
|
|
|
+ if(account_type !=null && !"".equals(account_type.toString())){
|
|
|
+ Object DISPLAYFIELD = baseDao.getFieldDataByCondition(Master+"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 Master ="YIT.";
|
|
|
+ String result ="";
|
|
|
+ if(DISPLAYFIELD !=null && !"".equals(DISPLAYFIELD)){
|
|
|
+ Object VALUEFIELD = baseDao.getFieldDataByCondition(Master+"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();
|
|
|
+ }
|
|
|
+}
|