自动化立体仓库 - WMS系统
LSH
2023-01-04 a740e5dfd94871f23b9ef859d0b552ade6790fff
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
105
106
107
108
109
110
111
112
113
114
package com.zy.ints.task.scheduler;
 
import com.baomidou.mybatisplus.plugins.Page;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.LocDetlService;
import com.zy.common.web.BaseController;
import com.zy.ints.entity.ErpLk;
import com.zy.ints.entity.ErpLkBak;
import com.zy.ints.erp.ErpSqlServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
/**
 * erp任务控制器
 * Created by vincent on 2020/11/27
 */
@Slf4j
@Component
public class ErpLkScheduler extends BaseController {
    /**
     * ERP接口是否启用
     */
    @Value("${erp.enabled}")
    private Boolean erpEnabled;
    @Value("${erp.useName.ip}")
    private String ip;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private ErpSqlServer erpSqlServer;
    @Autowired
    private LocDetlService locDetlService;
 
    /**
     * ERP与lk库存数据比对
     */
    @Scheduled(cron = "${erp.refreshtime}")
    public void proofread() {
        if (!erpEnabled) return;
        String sqlSelectErpLk = "select prd_no as prdNo,prd_mark as prdMark,qty,wh,status,temp1,temp2,temp3 from bas_erp_lk where 1=1";
        String sqlUpDateErpLkOne = "update bas_erp_lk set status=1 where prd_no=";
        String sqlUpDateErpLkTwo = "update bas_erp_lk set status=2 where prd_no=";
 
        try {
            List<ErpLk> erpLks = erpSqlServer.select(sqlSelectErpLk, ErpLk.class);
            if (erpLks.size() > 0) {
                for (ErpLk erpLk : erpLks) {
                    Integer status = erpLk.getStatus();
                    if (status == 0) {
                        HashMap<String, Object> param = new HashMap<>();
                        param.put("curr", 1);
                        param.put("limit", 20);
                        param.put("matnr", erpLk.getPrdNo());
                        param.put("batch", erpLk.getPrdMark());
                        Page<LocDetl> stockStatis = locDetlService.getStockStatis(toPage(1, 10, param, LocDetl.class));
                        if (stockStatis.getRecords().size() == 1) {
                            for (LocDetl locDetl : stockStatis.getRecords()) {
                                if (locDetl.getAnfme() - erpLk.getQty() == 0) {
                                    erpSqlServer.update(sqlUpDateErpLkOne + "'" + erpLk.getPrdNo() + "' and prd_mark='" + erpLk.getPrdMark() + "'");
                                    callApiLogSave(erpLk, "bas_erp_lk", "库存对比数量相同!!!总量为:" + erpLk.getQty(), true);
                                } else {
                                    erpSqlServer.update(sqlUpDateErpLkTwo + "'" + erpLk.getPrdNo() + "' and prd_mark='" + erpLk.getPrdMark() + "'");
                                    callApiLogSave(erpLk, "bas_erp_lk", "库存对比数量不同!!!立库总量为:" + locDetl.getAnfme() + "、ERP总量为:" + erpLk.getQty(), false);
                                }
                            }
                        } else {
                            callApiLogSave(erpLk, "bas_erp_lk", "立库库存异常!!!相同品号、货品特征的货物重复!!!", false);
                        }
                    } else if (status == 1) {
                        HashMap<String, Object> condition = new HashMap<>();
                        condition.put("prd_no", "'" + erpLk.getPrdNo() + "'");
                        condition.put("prd_mark", "'" + erpLk.getPrdMark() + "'");
                        condition.put("qty", "'" + erpLk.getQty() + "'");
                        condition.put("wh", "'" + erpLk.getWh() + "'");
                        condition.put("status", "'" + erpLk.getStatus() + "'");
                        condition.put("temp1", "'" + erpLk.getTemp1() + "'");
                        condition.put("temp2", "'" + erpLk.getTemp2() + "'");
                        condition.put("temp3", "'" + erpLk.getTemp3() + "'");
                        erpSqlServer.insert(ErpLkBak.class, condition);
 
//                        callApiLogSave(erpLk, "bas_erp_lk", "库存对比记录备份成功!!!总量为:" + erpLk.getQty(), true);
 
                        HashMap<String, String> condition2 = new HashMap<>();
                        condition2.put("prd_no", "'" + erpLk.getPrdNo() + "'");
                        condition2.put("prd_mark", "'" + erpLk.getPrdMark() + "'");
                        erpSqlServer.delete(ErpLk.class, condition2);
 
//                        callApiLogSave(erpLk, "bas_erp_lk", "库存对比记录备份后删除成功!!!总量为:" + erpLk.getQty(), true);
 
                    } else {
                        callApiLogSave(erpLk, "bas_erp_lk", "库存对比存在异常数据未处理!!!", false);
                    }
                }
            }
        } catch (Exception e) {
            Date date = new Date();
            log.error(date + ": 表名:bas_erp_lk :" + e);
        }
    }
 
    public void callApiLogSave(ErpLk erpLk, String tableName, String response, Boolean bool) {
        apiLogService.save("ERP与lk库存数据比对", tableName, "null", ip,
                "品号:" + erpLk.getPrdNo() + "、货品特征:" + erpLk.getPrdMark() + "、数量:" + erpLk.getQty() + "、状态:" + erpLk.getStatus(),
                response, bool);
    }
}