瀏覽代碼

ERP商品同步增加更新包装数量

hu 2 年之前
父節點
當前提交
3c95e66c47
共有 1 個文件被更改,包括 18 次插入12 次删除
  1. 18 12
      src/custom/service/AutoDockItemService.java

+ 18 - 12
src/custom/service/AutoDockItemService.java

@@ -1,13 +1,16 @@
 package service;
 
+import beans.parameter.Parameter;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import common.BaseClass;
 import common.ServiceController;
 import common.YosException;
 import common.data.Row;
 import common.data.Rows;
 import common.data.RowsMap;
 import common.data.SQLFactory;
+import common.data.db.DBConnect;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
 import restcontroller.webmanage.sale.item.Item;
@@ -23,6 +26,16 @@ public class AutoDockItemService extends ServiceController {
     public void serviceRun() throws YosException {
         ArrayList<String> sqlList = new ArrayList<>();
         String siteid ="CCYOSG";
+        Rows rows = new DBConnect().runSqlQuery("select * from sys_parameter where paramname='AutoDockItemServiceTime'");
+        Date date =new Date();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String AutoDockItemServiceTime =simpleDateFormat.format(date);
+        if(!rows.isEmpty()){
+            AutoDockItemServiceTime =rows.get(0).getString("paramvalue");
+            dbConnect.runSqlUpdate("delete from sys_parameter where paramname='AutoDockItemServiceTime'");
+        }else{
+            Parameter.create(new BaseClass(),"AutoDockItemServiceTime",simpleDateFormat.format(date),"");
+        }
         Rows itemRows = dbConnect.runSqlQuery("SELECT itemid,itemno from  plm_item WHERE siteid = '" + siteid + "' AND status = '新建' ");
         Rows itemRowsAll = dbConnect.runSqlQuery("SELECT itemid,itemno,status from  plm_item WHERE siteid = '" + siteid + "'");
         //单位
@@ -32,16 +45,8 @@ public class AutoDockItemService extends ServiceController {
         RowsMap itemRowsMap = itemRows.toRowsMap("itemno");
         RowsMap itemRowsMapAll = itemRowsAll.toRowsMap("itemno");
         ERPDocking erpDocking =new ERPDocking();
-        Rows servicesRows = dbConnect.runSqlQuery("select lastruntime,lastruntime1 from sys_services where classname='AutoDockItemService'");
-        Date date =new Date();
-        if(!servicesRows.isEmpty()){
-            if(StringUtils.isNotBlank(servicesRows.get(0).getString("lastruntime1"))){
-                date=servicesRows.get(0).getDate("lastruntime1");
-            }
-        }
-        dbConnect.runSqlUpdate("update sys_services set lastruntime1=now() where classname='AutoDockItemService'");
-        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        JSONArray jsonArray = erpDocking.getErpItemRows(simpleDateFormat.format(date), 100000, 1);
+
+        JSONArray jsonArray = erpDocking.getErpItemRows(AutoDockItemServiceTime, 100000, 1);
         if(!jsonArray.isEmpty()){
             for (Object object:jsonArray) {
                 JSONObject jsonObject =(JSONObject)object;
@@ -115,7 +120,7 @@ public class AutoDockItemService extends ServiceController {
                     sqlFactory.addParameter("delistingstatus","");
 
                     sqlFactory.addParameter("ismodule", 0);
-                    sqlFactory.addParameter("packageqty", 0);
+                    sqlFactory.addParameter("packageqty", (StringUtils.isBlank(jsonObject.getStringValue("fpackageqty"))?"0":jsonObject.getStringValue("fpackageqty")));
                     sqlFactory.addParameter("iswoodproducts", 0);
 
                     sqlFactory.addParameter("sa_customschemeid", 0);
@@ -153,13 +158,14 @@ public class AutoDockItemService extends ServiceController {
 
                 }else{
                    if(itemRowsMapAll.get(jsonObject.getString("fitemno")).get(0).getString("status").equals("新建")){
-                       sqlList.add("update plm_item set itemname='"+jsonObject.getString("fitemname")+"',volume='"+ jsonObject.getStringValue("fvolume")+"' where itemid="+itemRowsMapAll.get(jsonObject.getString("fitemno")).get(0).getLong("itemid"));
+                       sqlList.add("update plm_item set itemname='"+jsonObject.getString("fitemname")+"',volume='"+ jsonObject.getStringValue("fvolume")+"',packageqty='"+ (StringUtils.isBlank(jsonObject.getStringValue("fpackageqty"))?"0":jsonObject.getStringValue("fpackageqty"))+" where itemid="+itemRowsMapAll.get(jsonObject.getString("fitemno")).get(0).getLong("itemid"));
                    }
                 }
 
             }
         }
         dbConnect.runSqlUpdate(sqlList);
+        Parameter.create(new BaseClass(),"AutoDockItemServiceTime",simpleDateFormat.format(new Date()),"");
     }
 
 }