package com.uas.eis.task; import com.uas.eis.beans.result.BaseResult; import com.uas.eis.beans.result.CrmAddResult; import com.uas.eis.beans.result.Product; import com.uas.eis.dao.BaseDao; import com.uas.eis.dao.SqlRowList; import com.uas.eis.manager.ProductManager; 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.util.ArrayList; import java.util.List; @Component @EnableAsync @EnableScheduling public class ProductTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private BaseDao baseDao; @Autowired private ProductManager productManager; @Scheduled(cron = "0 0/15 * * * ?") public void syncProducts() { SqlRowList rs = baseDao.queryForRowSet("select * from (select * from product where nvl(pr_statuscode,' ')='AUDITED' and nvl(pr_sfjszy_user,' ')<>'是' and upper(nvl(pr_brand,' ')) <> 'EASYDETEK' and nvl(pr_sendstatus,' ')='待上传' order by pr_id) where rownum<=200"); while (rs.next()){ Product product = setProduct(rs); product.set_id(""); try { CrmAddResult crmAddResult = productManager.addProducts(product); int errorCode = crmAddResult.getErrorCode(); String dataId = crmAddResult.getDataId(); if(errorCode == 0){ baseDao.execute("update product set pr_sendstatus='已上传',PR_FXXKDATAID='"+dataId+"' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'物料资料上传成功','物料资料上传','"+rs.getString("pr_code")+"')"); }else{ baseDao.execute("update product set pr_sendstatus='未上传成功' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+crmAddResult.getErrorMessage()+"','物料资料上传','"+rs.getString("pr_code")+"')"); logger.info("异常信息:"+crmAddResult.getErrorMessage()); } }catch (Exception e){ baseDao.execute("update product set pr_sendstatus='未上传成功' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+e.getMessage()+"','物料资料上传','"+rs.getString("pr_code")+"')"); logger.info("异常信息:"+e.getMessage()); e.printStackTrace(); } } } @Scheduled(cron = "0 0/10 * * * ?") public void syncBannedProducts() { SqlRowList rs = baseDao.queryForRowSet("select * from (select * from product where nvl(pr_statuscode,' ')='DISABLE' and nvl(pr_sendstatus,' ')='待上传' order by pr_id) where rownum<=200"); while (rs.next()){ Product product = setProduct(rs); try { BaseResult baseResult = productManager.invalidProduct(product.get_id()); int errorCode = baseResult.getErrorCode(); if(errorCode == 0){ baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'物料资料作废成功','物料资料作废','"+rs.getString("pr_code")+"')"); }else{ baseDao.execute("update product set pr_sendstatus='未上传成功' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+baseResult.getErrorMessage()+"','物料资料作废','"+rs.getString("pr_code")+"')"); logger.info("异常信息:"+baseResult.getErrorMessage()); } List idList = new ArrayList<>(); idList.add(product.get_id()); BaseResult baseResult_del = productManager.deleteProducts(idList); int errorCode_del = baseResult_del.getErrorCode(); if(errorCode_del == 0){ baseDao.execute("update product set pr_sendstatus='已上传' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'物料资料删除成功','物料资料删除','"+rs.getString("pr_code")+"')"); }else{ baseDao.execute("update product set pr_sendstatus='未上传成功' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+baseResult_del.getErrorMessage()+"','物料资料删除','"+rs.getString("pr_code")+"')"); logger.info("异常信息:"+baseResult_del.getErrorMessage()); } }catch (Exception e){ baseDao.execute("update product set pr_sendstatus='未上传成功' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+e.getMessage()+"','物料资料作废或删除','"+rs.getString("pr_code")+"')"); logger.info("异常信息:"+e.getMessage()); e.printStackTrace(); } } } @Scheduled(cron = "0 0 19 * * ?") public void syncUpdateProducts() { SqlRowList rs = baseDao.queryForRowSet("select * from (select distinct pis_prodcode from productInfoSync where trunc(pis_date)=trunc(sysdate) and pis_updatedate is null and PIS_ERROR is null) left join product on pis_prodcode=pr_code where nvl(pr_statuscode,' ')='AUDITED' and nvl(pr_sfjszy_user,' ')<>'是' and upper(nvl(pr_brand,' ')) <> 'EASYDETEK' order by pr_id"); while (rs.next()){ Product product = setProduct(rs); try { BaseResult baseResult = productManager.updateGoods(product); int errorCode = baseResult.getErrorCode(); if(errorCode == 0){ baseDao.execute("update productInfoSync set pis_updatestatus='已更新',pis_updatedate=sysdate where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); }else{ baseDao.execute("update productInfoSync set pis_error='"+baseResult.getErrorMessage()+"' where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); logger.info("异常信息:"+baseResult.getErrorMessage()); } }catch (Exception e){ baseDao.execute("update productInfoSync set pis_error='"+e.getMessage()+"' where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); logger.info("异常信息:"+e.getMessage()); e.printStackTrace(); } } } @Scheduled(cron = "0 0 1-6 * * ?") public void syncUpdateProductsAgain() { SqlRowList rs = baseDao.queryForRowSet("select * from (select distinct pis_prodcode from productInfoSync where 1=2 and trunc(pis_date)=trunc(sysdate)-1 and pis_updatedate is null and PIS_ERROR is null) left join product on pis_prodcode=pr_code where nvl(pr_statuscode,' ')='AUDITED' and nvl(pr_sfjszy_user,' ')<>'是' and upper(nvl(pr_brand,' ')) <> 'EASYDETEK' order by pr_id"); while (rs.next()){ Product product = setProduct(rs); try { BaseResult baseResult = productManager.updateGoods(product); int errorCode = baseResult.getErrorCode(); if(errorCode == 0){ baseDao.execute("update productInfoSync set pis_updatestatus='已更新',pis_updatedate=sysdate where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); }else{ baseDao.execute("update productInfoSync set pis_error='"+baseResult.getErrorMessage()+"' where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); logger.info("异常信息:"+baseResult.getErrorMessage()); } }catch (Exception e){ baseDao.execute("update productInfoSync set pis_error='"+e.getMessage()+"' where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); logger.info("异常信息:"+e.getMessage()); e.printStackTrace(); } } } //是否寄售专用 由否改为是时定时报废CRM对应的物料 @Scheduled(cron = "0 30 23 * * ?") public void syncUpdateProductsOnSFJSZY() { SqlRowList rs = baseDao.queryForRowSet("select * from (select distinct pis_prodcode from productInfoSync where trunc(pis_date)=trunc(sysdate) and pis_updatedate is null) left join product on pis_prodcode=pr_code where nvl(pr_statuscode,' ')='AUDITED' and nvl(pr_sendstatus,' ')='已上传' and nvl(pr_sfjszy_user,' ')='是' order by pr_id"); while (rs.next()){ Product product = setProduct(rs); try { BaseResult baseResult = productManager.invalidProduct(product.get_id()); int errorCode = baseResult.getErrorCode(); if(errorCode == 0){ baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'物料资料作废成功','物料资料作废','"+rs.getString("pr_code")+"')"); List idList = new ArrayList<>(); idList.add(product.get_id()); BaseResult baseResult_del = productManager.deleteProducts(idList); int errorCode_del = baseResult_del.getErrorCode(); if(errorCode_del == 0){ baseDao.execute("update product set pr_sendstatus='待上传' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'物料资料删除成功','物料资料删除','"+rs.getString("pr_code")+"')"); baseDao.execute("update productInfoSync set pis_updatestatus='已更新',pis_updatedate=sysdate where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); }else{ baseDao.execute("update product set pr_sendstatus='未报废成功' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+baseResult_del.getErrorMessage()+"','物料资料删除','"+rs.getString("pr_code")+"')"); baseDao.execute("update productInfoSync set pis_error='"+baseResult_del.getErrorMessage()+"' where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); logger.info("异常信息:"+baseResult_del.getErrorMessage()); } }else{ baseDao.execute("update product set pr_sendstatus='未报废成功' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+baseResult.getErrorMessage()+"','物料资料作废','"+rs.getString("pr_code")+"')"); baseDao.execute("update productInfoSync set pis_error='"+baseResult.getErrorMessage()+"' where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); logger.info("异常信息:"+baseResult.getErrorMessage()); } }catch (Exception e){ baseDao.execute("update product set pr_sendstatus='未报废成功' where pr_id="+rs.getInt("pr_id")); baseDao.execute("insert into FXXKDockingErrorlog(ml_id,ml_date,ml_result,ml_type,ml_code) values(FXXKDOCKINGERRORLOG_SEQ.nextval,sysdate,'"+e.getMessage()+"','物料资料作废或删除','"+rs.getString("pr_code")+"')"); baseDao.execute("update productInfoSync set pis_error='"+e.getMessage()+"' where pis_prodcode='"+rs.getGeneralString("pis_prodcode")+"' and trunc(pis_date)=trunc(sysdate) and pis_updatedate is null"); logger.info("异常信息:"+e.getMessage()); e.printStackTrace(); } } } private Product setProduct(SqlRowList rs){ Product product = new Product(); product.setDataObjectApiName("ProductObj"); product.set_id(rs.getGeneralString("pr_fxxkdataid")); product.setField_ea4Nh__c("祥瑞微".equals(rs.getGeneralString("pr_brand")) || "Easydetek".equals(rs.getGeneralString("pr_brand")) || "EasyDetek".equals(rs.getGeneralString("pr_brand")) ? null : rs.getGeneralDouble("pr_lasttaxpurcprice_user")); product.setField_i0v47__c(rs.getGeneralString("pr_YPstock")); product.setField_iW998__c(rs.getGeneralString("pr_PLstock")); product.setField_dioys__c(rs.getGeneralString("pr_wlfl_user")); product.setProduct_code(rs.getGeneralString("pr_code")); product.setUDSText1__c(rs.getGeneralString("pr_brand")); product.setField_cwppk__c(rs.getGeneralString("pr_fz_user")); product.setField_r02le__c(rs.getGeneralString("pr_zxbzs")); product.setUnit(rs.getGeneralString("pr_unit")); product.setName(rs.getGeneralString("pr_brand")+"~"+rs.getGeneralString("pr_spec")); product.setPrice(rs.getGeneralDouble("pr_standardprice")); product.setCategory("6"); product.setField_uwFmi__c(rs.getGeneralString("pr_aflypstock_user"));//艾富利样品仓库存 product.setField_ehcac__c(rs.getGeneralString("pr_aflplstock_user"));//艾富利批量仓库存 product.setField_f0qjS__c("祥瑞微".equals(rs.getGeneralString("pr_brand")) || "Easydetek".equals(rs.getGeneralString("pr_brand")) ? null : rs.getGeneralDouble("pr_afllasttaxpurcprice_user"));//艾富利成本(含税) product.setField_rY1jT__c(rs.getGeneralString("pr_yjhhkplstock_user"));//越加红(香港)仓批量库存 product.setField_CN00a__c(rs.getGeneralString("pr_tjxz_user"));//推荐星值 product.setField_1WO33__c(rs.getGeneralString("pr_abc")); product.setField_2llh1__c(rs.getGeneralString("pr_kind2"));//物料中类 product.setField_a13W6__c(rs.getGeneralDouble("pr_zdj_user"));//指导价 return product; } }