|
|
@@ -0,0 +1,72 @@
|
|
|
+package com.uas.eis.task;
|
|
|
+
|
|
|
+import com.uas.eis.beans.result.CrmAddResult;
|
|
|
+import com.uas.eis.beans.result.Goods;
|
|
|
+import com.uas.eis.dao.BaseDao;
|
|
|
+import com.uas.eis.dao.SqlRowList;
|
|
|
+import com.uas.eis.manager.ProductManager;
|
|
|
+import com.uas.eis.utils.StringUtil;
|
|
|
+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.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+@EnableAsync
|
|
|
+@EnableScheduling
|
|
|
+public class ProductTask {
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BaseDao baseDao;
|
|
|
+ @Autowired
|
|
|
+ private ProductManager productManager;
|
|
|
+
|
|
|
+ @Scheduled(cron = "*/10 * * * * ?")
|
|
|
+ public void syncProducts() {
|
|
|
+ SqlRowList rs = baseDao.queryForRowSet("select pr_id,pr_code,pr_detail,pr_unit,pr_standardprice from product where nvl(pr_sendstatus,' ')='待上传' and 1=2 order by pr_id");
|
|
|
+ while (rs.next()){
|
|
|
+ List<Map<String,Object>> sku = new ArrayList<>();
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ List spec_and_value = new ArrayList();
|
|
|
+ map.put("spec_and_value",spec_and_value);
|
|
|
+ map.put("product_status","1");
|
|
|
+ map.put("unit",rs.getString("pr_unit"));
|
|
|
+ sku.add(map);
|
|
|
+ Goods goods = new Goods();
|
|
|
+ goods.setDataObjectApiName("SPUObj");
|
|
|
+ goods.setUnit(rs.getString("pr_unit"));
|
|
|
+ goods.setIs_spec(false);
|
|
|
+ goods.setStandard_price(rs.getDouble("pr_standardprice") == -1.0 ? 0.0 : rs.getDouble("pr_standardprice"));
|
|
|
+ goods.setProduct_line("1");
|
|
|
+ goods.setName(rs.getString("pr_detail"));
|
|
|
+ goods.setCategory("6");
|
|
|
+ goods.setSku(sku);
|
|
|
+ try {
|
|
|
+ CrmAddResult crmAddResult = productManager.addGoods(goods);
|
|
|
+ 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("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("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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|