Просмотр исходного кода

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

dw 1 неделю назад
Родитель
Сommit
1d772e737d

+ 6
- 0
src/main/java/com/th/demo/mapping/ware/DistributionMapper.java Просмотреть файл

24
 
24
 
25
 //    取消出库修改cancle_flag字段
25
 //    取消出库修改cancle_flag字段
26
     int updateCancleFlag(@Param("distributionId") String distributionId,@Param("outId") String outId);
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
 import com.th.demo.tools.JSONTools;
19
 import com.th.demo.tools.JSONTools;
20
 import com.th.demo.tools.Tools;
20
 import com.th.demo.tools.Tools;
21
 import org.springframework.beans.factory.annotation.Autowired;
21
 import org.springframework.beans.factory.annotation.Autowired;
22
+import org.springframework.scheduling.annotation.Scheduled;
22
 import org.springframework.stereotype.Service;
23
 import org.springframework.stereotype.Service;
23
 import org.springframework.transaction.annotation.Transactional;
24
 import org.springframework.transaction.annotation.Transactional;
24
 
25
 
55
 
56
 
56
     String result = Type.FAIL;
57
     String result = Type.FAIL;
57
     int num = 0;
58
     int num = 0;
59
+//    定时任务执行统计
60
+    int count = 0;
58
 
61
 
59
     @Override
62
     @Override
60
     public String out(String json, String userId, String belongId) {
63
     public String out(String json, String userId, String belongId) {
171
         distribution.setOutFlag("1");
174
         distribution.setOutFlag("1");
172
         if(distribution.getTransportName().equals("")||distribution.getTransportName() == null){
175
         if(distribution.getTransportName().equals("")||distribution.getTransportName() == null){
173
             result = JSONTools.toString(ResponseCodeMsg.CODE_EX, "承运单位不可为空!");
176
             result = JSONTools.toString(ResponseCodeMsg.CODE_EX, "承运单位不可为空!");
177
+            return result;
174
         }
178
         }
175
         num += distributionMapper.updateByPrimaryKey(distribution);
179
         num += distributionMapper.updateByPrimaryKey(distribution);
176
         List<String> listStoreId = new ArrayList<String>();
180
         List<String> listStoreId = new ArrayList<String>();
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 Просмотреть файл

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
             WHERE
230
             WHERE
231
                 out_id = #{outId})
231
                 out_id = #{outId})
232
     </update>
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
   <update id="updateByPrimaryKey" parameterType="com.th.demo.model.ware.Distribution" >
253
   <update id="updateByPrimaryKey" parameterType="com.th.demo.model.ware.Distribution" >
234
     update t_ware_distribution
254
     update t_ware_distribution
235
     set truck_no = #{truckNo,jdbcType=VARCHAR},
255
     set truck_no = #{truckNo,jdbcType=VARCHAR},

Загрузка…
Отмена
Сохранить