自动化立体仓库 - WMS系统
zwl
2025-10-28 d3c7820992ccfb3296ec031a7c019a4300347b83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.zy.third.task;
 
import com.zy.third.entity.ExdInstockSource;
import com.zy.third.entity.ExdOutstockSource;
import com.zy.third.mapper.ExdInstockSourceMapper;
import com.zy.third.mapper.ExdOutstockSourceMapper;
import com.zy.third.task.handler.OrderHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
@Component
@Slf4j
public class OrderScheduler {
 
 
    @Autowired
    private OrderHandler orderHandler;
 
    @Autowired
    private ExdInstockSourceMapper exdInstockSourceMapper;
 
 
    @Autowired
    private ExdOutstockSourceMapper exdOutstockSourceMapper;
 
 
    /**
     * 读取入库单据
     */
    @Scheduled(cron = "0/10 * * * * ? ")
    public void readInOrder() {
        //log.info("读取入库单据");
        List<String> orderNos = exdInstockSourceMapper.listOrderNo();
        for (String orderNo : orderNos) {
            List<ExdInstockSource> exdInstockSources = exdInstockSourceMapper.listAll(orderNo);
            try {
                boolean success = orderHandler.readInOrder(exdInstockSources).isSuccess();
                for (ExdInstockSource exdInstockSource : exdInstockSources) {
                    if (success) {
                        exdInstockSource.setReadtime(new Date());
                        exdInstockSource.setStatus(1);
                        exdInstockSourceMapper.updateById(exdInstockSource);
                    } else {
                        exdInstockSource.setReadtime(new Date());
                        exdInstockSource.setStatus(2);
                        exdInstockSourceMapper.updateById(exdInstockSource);
                    }
                }
            } catch (Exception e) {
                log.error("读取入库单据信息失败:{},{}", exdInstockSources, e.getMessage());
                e.printStackTrace();
                for (ExdInstockSource exdInstockSource : exdInstockSources) {
                    exdInstockSource.setReadormsg(e.getMessage());
                    exdInstockSource.setStatus(2);
                    exdInstockSourceMapper.updateById(exdInstockSource);
                }
            }
        }
    }
 
    /**
     * 读取出库单据
     */
    @Scheduled(cron = "0/10 * * * * ? ")
    public void readOutOrder() {
        //log.info("读取出库单据");
        List<String> orderNos = exdOutstockSourceMapper.listOrderNo();
        for (String orderNo : orderNos) {
            List<ExdOutstockSource> exdOutstockSources = exdOutstockSourceMapper.listAll(orderNo);
            try {
                boolean success = orderHandler.readOutOrder(exdOutstockSources).isSuccess();
                for (ExdOutstockSource exdOutstockSource : exdOutstockSources) {
                    if (success) {
                        exdOutstockSource.setReadtime(new Date());
                        exdOutstockSource.setStatus(1);
                        exdOutstockSourceMapper.updateById(exdOutstockSource);
                    } else {
                        exdOutstockSource.setReadtime(new Date());
                        exdOutstockSource.setStatus(2);
                        exdOutstockSourceMapper.updateById(exdOutstockSource);
                    }
                }
            } catch (Exception e) {
                log.error("读取出库单据信息失败:{},{}", exdOutstockSources, e.getMessage());
                e.printStackTrace();
                for (ExdOutstockSource exdOutstockSource : exdOutstockSources) {
                    exdOutstockSource.setStatus(2);
                    exdOutstockSource.setReadormsg(e.getMessage());
                    exdOutstockSourceMapper.updateById(exdOutstockSource);
                }
            }
        }
    }
 
}