|
|
@@ -0,0 +1,93 @@
|
|
|
+package com.uas.eis.task;
|
|
|
+
|
|
|
+import com.uas.eis.beans.result.CrmAddResult;
|
|
|
+import com.uas.eis.dao.BaseDao;
|
|
|
+import com.uas.eis.dao.SqlRowList;
|
|
|
+import com.uas.eis.manager.CommonManager;
|
|
|
+import com.uas.eis.utils.Configuration;
|
|
|
+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 javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+@EnableAsync
|
|
|
+@EnableScheduling
|
|
|
+public class SaleMonthDataTask {
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+ @Autowired
|
|
|
+ private CommonManager commonManager;
|
|
|
+ @Resource(name = "configuration")
|
|
|
+ private Configuration configuration;
|
|
|
+
|
|
|
+ //每月1日凌晨10分执行
|
|
|
+ @Scheduled(cron = "0 10 0 1 * ?")
|
|
|
+ public void syncProducts() {
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet("select * from (select * from saleMonthData left join customer on SM_CUSTCODE=CU_CODE where nvl(cu_fxxkid,' ')<>' ' and nvl(SM_SENDSTATUS,' ')='待上传' order by sm_id) where rownum<=200");
|
|
|
+ String openUserId = configuration.getOpenUserId();
|
|
|
+ while (rs.next()){
|
|
|
+ Map<String,Object> data = new HashMap<>();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ List<String> owner = new ArrayList<>();
|
|
|
+ owner.add(openUserId);
|
|
|
+ map.put("owner",owner);
|
|
|
+ map.put("field_6secE__c",rs.getGeneralDouble("sm_salesum"));//接单金额
|
|
|
+ map.put("field_Frnzy__c",rs.getGeneralString("cu_fxxkid"));//客户名称 关联ID
|
|
|
+ String sm_yearmonth = rs.getGeneralString("sm_yearmonth");
|
|
|
+ String year = sm_yearmonth.substring(0, 4);
|
|
|
+ String month = sm_yearmonth.substring(4);
|
|
|
+ String valueField_year = getValueField("销售月数据统计", "年份", year);
|
|
|
+ String valueField_month = getValueField("销售月数据统计", "月份", month);
|
|
|
+ map.put("field_22s1K__c",valueField_year);//年份
|
|
|
+
|
|
|
+ map.put("field_C71qd__c",rs.getGeneralDouble("sm_saleoutsum"));//出货金额
|
|
|
+ map.put("field_1s1t2__c",valueField_month);//月份
|
|
|
+ map.put("field_m2ypV__c",rs.getGeneralDouble("sm_paysum"));//应收货款
|
|
|
+ map.put("dataObjectApiName","object_8r53c__c");
|
|
|
+ map.put("created_by",openUserId);
|
|
|
+ map.put("life_status","normal");
|
|
|
+ map.put("record_type","default__c");
|
|
|
+ data.put("object_data",map);
|
|
|
+ try {
|
|
|
+ CrmAddResult crmAddResult = commonManager.createCommonOfCustom(data);
|
|
|
+ int errorCode = crmAddResult.getErrorCode();
|
|
|
+ String dataId = crmAddResult.getDataId();
|
|
|
+ if(errorCode == 0){
|
|
|
+ baseDao.execute("update saleMonthData set SM_SENDSTATUS='已上传',SM_FXXKDATAID='"+dataId+"' where sm_id="+rs.getInt("sm_id"));
|
|
|
+ baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'销售月数据统计上传成功','销售月数据统计上传','"+rs.getGeneralString("sm_yearmonth")+rs.getString("sm_custcode")+"')");
|
|
|
+ }else{
|
|
|
+ baseDao.execute("update saleMonthData set SM_SENDSTATUS='未上传成功' where sm_id="+rs.getInt("sm_id"));
|
|
|
+ baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmAddResult.getErrorMessage()+"','销售月数据统计上传','"+rs.getGeneralString("sm_yearmonth")+rs.getString("sm_custcode")+"')");
|
|
|
+ logger.info("异常信息:"+crmAddResult.getErrorMessage());
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ baseDao.execute("update saleMonthData set SM_SENDSTATUS='未上传成功' where sm_id="+rs.getInt("sm_id"));
|
|
|
+ baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+e.getMessage()+"','销售月数据统计上传','"+rs.getGeneralString("sm_yearmonth")+rs.getString("sm_custcode")+"')");
|
|
|
+ logger.info("异常信息:"+e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+}
|