Browse Source

发货提醒上传时增加上传中过滤状态

hejq 7 years ago
parent
commit
7fc7851ccb

+ 23 - 0
src/main/java/com/uas/erp/schedular/b2b/task/AbstractTask.java

@@ -316,4 +316,27 @@ public class AbstractTask {
         }
         }
     }
     }
 
 
+    /**
+     * 单据上传时增加上传中过滤状态
+     *
+     * @param tableName 表名称
+     * @param statusColumn 上传状态字段
+     * @param idColumn id字段
+     * @param idStr id
+     */
+    protected void setSendStatusBeforeUpload(String tableName, String statusColumn, String idColumn, String idStr) {
+        jdbcTemplate.execute(String.format("update %s set %s='上传中' where %s in (%s)", tableName, statusColumn, idColumn, idStr));
+    }
+
+    /**
+     * 上传错误更新上传状态为待上传
+     *
+     * @param tableName 表名称
+     * @param statusColumn 上传状态字段
+     * @param idColumn id字段
+     * @param idStr id
+     */
+    protected void setSendStatusOnError(String tableName, String statusColumn, String idColumn, String idStr) {
+        jdbcTemplate.execute(String.format("update %s set %s='待上传' where %s in (%s)", tableName, statusColumn, idColumn, idStr));
+    }
 }
 }

+ 15 - 9
src/main/java/com/uas/erp/schedular/b2b/task/PurchaseNotifyTask.java

@@ -30,17 +30,23 @@ public class PurchaseNotifyTask extends AbstractTask {
                 PurchaseNotify.class);
                 PurchaseNotify.class);
         if (!CollectionUtils.isEmpty(notifies)) {
         if (!CollectionUtils.isEmpty(notifies)) {
             ContextHolder.setDataSize(notifies.size());
             ContextHolder.setDataSize(notifies.size());
-            notifies = postForList("/erp/purchase/notice", PurchaseNotify.class, dataWrap(notifies));
-            List<String> sqlList = new ArrayList<>();
-            if (!CollectionUtils.isEmpty(notifies)) {
-                for (PurchaseNotify notify : notifies) {
-                    if (null != notify.getPn_b2bid()) {
-                        sqlList.add("update purchaseNotify set pn_sendStatus = '已上传', pn_b2bid = " + notify.getPn_b2bid() + " where pn_id = " + notify.getPn_id());
+            // 增加上传中过滤状态
+            setSendStatusBeforeUpload("purchaseNotify", "pn_sendStatus", "pn_id", CollectionUtil.getKeyString(notifies));
+            try {
+                notifies = postForList("/erp/purchase/notice", PurchaseNotify.class, dataWrap(notifies));
+                List<String> sqlList = new ArrayList<>();
+                if (!CollectionUtils.isEmpty(notifies)) {
+                    for (PurchaseNotify notify : notifies) {
+                        if (null != notify.getPn_b2bid()) {
+                            sqlList.add("update purchaseNotify set pn_sendStatus = '已上传', pn_b2bid = " + notify.getPn_b2bid() + " where pn_id = " + notify.getPn_id());
+                        }
                     }
                     }
                 }
                 }
-            }
-            if (!CollectionUtils.isEmpty(sqlList)) {
-                jdbcTemplate.batchExecute(sqlList);
+                if (!CollectionUtils.isEmpty(sqlList)) {
+                    jdbcTemplate.batchExecute(sqlList);
+                }
+            } catch (RuntimeException e) {
+                setSendStatusOnError("purchaseNotify", "pn_sendStatus", "pn_id", CollectionUtil.getKeyString(notifies));
             }
             }
         }
         }
     }
     }