浏览代码

1.新增定时任务,每日零点自动排查已出库的库存出库状态未更新的库存,自动更新出库状态

dw 5 天前
父节点
当前提交
1d772e737d

+ 6
- 0
src/main/java/com/th/demo/mapping/ware/DistributionMapper.java 查看文件

@@ -24,4 +24,10 @@ public interface DistributionMapper {
24 24
 
25 25
 //    取消出库修改cancle_flag字段
26 26
     int updateCancleFlag(@Param("distributionId") String distributionId,@Param("outId") String outId);
27
+
28
+//    根据主表id修改出库状态
29
+    int updateOutStatus(@Param("storeId") String storeId);
30
+
31
+//    查询未出库状态,出库单存在的数据
32
+    List<String> selectWaitOutIds();
27 33
 }

+ 22
- 0
src/main/java/com/th/demo/service/impl/ware/OutServiceImpl.java 查看文件

@@ -19,6 +19,7 @@ import com.th.demo.service.ware.OutService;
19 19
 import com.th.demo.tools.JSONTools;
20 20
 import com.th.demo.tools.Tools;
21 21
 import org.springframework.beans.factory.annotation.Autowired;
22
+import org.springframework.scheduling.annotation.Scheduled;
22 23
 import org.springframework.stereotype.Service;
23 24
 import org.springframework.transaction.annotation.Transactional;
24 25
 
@@ -55,6 +56,8 @@ public class OutServiceImpl implements OutService {
55 56
 
56 57
     String result = Type.FAIL;
57 58
     int num = 0;
59
+//    定时任务执行统计
60
+    int count = 0;
58 61
 
59 62
     @Override
60 63
     public String out(String json, String userId, String belongId) {
@@ -171,6 +174,7 @@ public class OutServiceImpl implements OutService {
171 174
         distribution.setOutFlag("1");
172 175
         if(distribution.getTransportName().equals("")||distribution.getTransportName() == null){
173 176
             result = JSONTools.toString(ResponseCodeMsg.CODE_EX, "承运单位不可为空!");
177
+            return result;
174 178
         }
175 179
         num += distributionMapper.updateByPrimaryKey(distribution);
176 180
         List<String> listStoreId = new ArrayList<String>();
@@ -344,4 +348,22 @@ public class OutServiceImpl implements OutService {
344 348
     }
345 349
 
346 350
 
351
+    /**
352
+     * 库存状态检测方法(定时)
353
+     */
354
+    @Scheduled(cron = "0 * * * * *")
355
+    public void checkStock() {
356
+        count += 1;
357
+//      查询未出库状态,出库单存在的数据
358
+        List<String> list = distributionMapper.selectWaitOutIds();
359
+        if(!list.isEmpty()){
360
+            for (String storeId : list) {
361
+//                根据id修改主表出库状态
362
+                distributionMapper.updateOutStatus(storeId);
363
+            }
364
+        }
365
+        System.out.println("执行定时任务_______"+count);
366
+
367
+    }
368
+
347 369
 }

+ 10
- 0
src/main/java/com/th/demo/tools/ScheduledTools.java 查看文件

@@ -0,0 +1,10 @@
1
+package com.th.demo.tools;
2
+
3
+import org.springframework.context.annotation.Configuration;
4
+import org.springframework.scheduling.annotation.EnableScheduling;
5
+
6
+@Configuration
7
+@EnableScheduling
8
+public class ScheduledTools {
9
+
10
+}

+ 20
- 0
src/main/resource/mapper/ware/DistributionMapper.xml 查看文件

@@ -230,6 +230,26 @@
230 230
             WHERE
231 231
                 out_id = #{outId})
232 232
     </update>
233
+    <update id="updateOutStatus" parameterType="java.lang.String">
234
+        update t_ware_store
235
+        set out_flag = '1'
236
+        where id = #{storeId}
237
+    </update>
238
+    <select id="selectWaitOutIds" parameterType="java.lang.String">
239
+        SELECT
240
+            b.id
241
+        FROM
242
+            t_ware_distribution_detail a
243
+                LEFT JOIN t_ware_store b ON a.store_id = b.id
244
+                LEFT JOIN t_ware_distribution c ON c.id = a.distribution_id
245
+        WHERE
246
+--             未出库
247
+            b.out_flag = '0'
248
+          AND b.cancel_flag = '0'
249
+          AND a.cancel_flag = '0'
250
+--           出库单已存在
251
+          AND c.out_flag = '1'
252
+    </select>
233 253
   <update id="updateByPrimaryKey" parameterType="com.th.demo.model.ware.Distribution" >
234 254
     update t_ware_distribution
235 255
     set truck_no = #{truckNo,jdbcType=VARCHAR},

正在加载...
取消
保存