自动化立体仓库 - WMS系统
#
18516761980
2021-12-06 d4633ae0282a7a3f8af135fc2a1d6a6c7b656dbb
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
101
102
103
104
package com.zy.ints.task;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.zy.ints.entity.IoComplete;
import com.zy.ints.entity.StockSync;
import com.zy.ints.service.IoCompleteService;
import com.zy.ints.service.StockSyncService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * erp任务控制器
 * Created by vincent on 2020/11/27
 */
@Slf4j
@Component
public class ERPApiScheduler {
    @Autowired
    private IoCompleteService ioCompleteService;
    @Autowired
    private StockSyncService stockSyncService;
 
    /**
     * ERP接口是否启用
     */
    @Value("${erp.enabled}")
    private Boolean erpEnabled;
    @Autowired
    private JdbcTemplate jdbcTemplate;
 
    /**
     * 提取回报档资料,上报ERP处理
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void ioCompleteExecute(){
        if(!erpEnabled) return;
        Date now = new Date();
        boolean res = false;
        String errMsg = "";//上报返回异常信息
        Wrapper<IoComplete> wrapper = new EntityWrapper<IoComplete>().ne("upd_status",1).last("order by upd_status,modi_time asc");
        List<IoComplete> ioCompletes = ioCompleteService.selectList(wrapper);
//        IoComplete ioComplete = ioCompleteService.selectOne(wrapper);
        if(null != ioCompletes && ioCompletes.size() > 0){
            IoComplete ioComplete = ioCompletes.get(0);
            ////////////上报ERP接口
            ///////////调ERP接口后,需要插入接口日志表ints_erpreq_log
 
            if(res){
                ioComplete.setUpdStatus(1);
                ioComplete.setModiTime(now);
                ioCompleteService.updateById(ioComplete);
            } else {
                ioComplete.setUpdStatus(2);
                ioComplete.setErrorMemo(errMsg);
                ioComplete.setModiTime(now);
                ioCompleteService.updateById(ioComplete);
            }
        }
 
    }
 
    /**
     * 提取库存同步表资料,上报ERP库存同步
     */
    @Scheduled(cron = "0/3 * * * * ? ")
    public void stockSyncExecute() {
        if (!erpEnabled) return;
        Date now = new Date();
        boolean res = false;
        String errMsg = "";//上报返回异常信息
 
        String sql = "select top 10 mat_no as matNo,mat_name as matName,qty from ints_stock_sync where upd_status<>1 order by upd_status,modi_time asc";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
        if(null != maps){
            for (Map map: maps) {
                StockSync stockSync = Cools.conver(map, StockSync.class);
                ////////////上报ERP接口
                ///////////调ERP接口后,需要插入接口日志表ints_erpreq_log
 
                if (res) {
                    stockSync.setUpdStatus(1);
                    stockSync.setModiTime(now);
                    stockSyncService.update(stockSync,new EntityWrapper<StockSync>().eq("mat_no",stockSync.getMatNo()));
                } else {
                    stockSync.setUpdStatus(2);
                    stockSync.setErrorMemo(errMsg);
                    stockSync.setModiTime(now);
                    stockSyncService.update(stockSync,new EntityWrapper<StockSync>().eq("mat_no",stockSync.getMatNo()));
                }
            }
        }
 
    }
}