自动化立体仓库 - WMS系统
zc
2024-11-01 797fce4ad48f7b70dc08766068b64f35ee9d4775
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
package com.zy.third.erp.task;
 
import com.core.common.Cools;
import com.zy.common.service.erp.ErpSqlServer;
import com.zy.third.erp.entity.OutDetTB;
import com.zy.third.erp.entity.OutHedTB;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
 
/**
 * 入库单据
 */
@Slf4j
@Component
public class ERPOutHedTBScheduler {
 
    @Value("${erp.enabled}")
    private Boolean erpEnabled;
 
 
    @Autowired
    private ERPInOrOutService inMS;
 
 
    @Autowired
    private ErpSqlServer erpSqlServer;
 
 
    //@Transactional(rollbackFor = Throwable.class)
    @Scheduled(cron = "${erp.refreshtime}")
    @Async("orderThreadPool")
    public void OutHedTBScheduler() {
        //log.info("OutHedTBScheduler开始了");
        if (!erpEnabled) return;
        String sqlInHed = "select * from erp_OutHedTB where LKName='中扬二期'";
        List<OutHedTB> inHeds = erpSqlServer.select(sqlInHed, OutHedTB.class);
        if (!inHeds.isEmpty()) {
            for (OutHedTB inHed : inHeds) {
                if (!Cools.isEmpty(inHed.getTemp3()) && inHed.getTemp3().equals("fault")) {
                    //continue;
                }
                HashMap<String, String> condition = new HashMap<>();
                condition.put("BillNo", "'" + inHed.getBillNo() + "'");
                List<OutDetTB> inDetTBS = erpSqlServer.selectList(OutDetTB.class, condition);
                HashMap<String, Object> hedAndDet = new HashMap<>();
                hedAndDet.put("hed", inHed);
                hedAndDet.put("det", inDetTBS);
                try {
                    inMS.createOutOrder(inHed, inDetTBS);
                    log.info("出库单据成功,{}", inHed);
                    move(hedAndDet);
                } catch (Exception e) {
                    log.info(e.getMessage());
//                    e.printStackTrace();
                    String sql = "UPDATE erp_OutHedTB SET Temp3 = 'fault' WHERE BillNo = '" + inHed.getBillNo() + "'";
                    erpSqlServer.update(sql);
//
                }
            }
        }
    }
 
    @Transactional(rollbackFor = Throwable.class)
    public void move(HashMap<String, Object> hedAndDet) {
        OutHedTB hed = (OutHedTB) hedAndDet.get("hed");
        ArrayList<OutDetTB> dets = (ArrayList<OutDetTB>) hedAndDet.get("det");
        HashMap<String, String> condition = new HashMap<>();
        condition.put("BillNo", "'" + hed.getBillNo() + "'");
        erpSqlServer.delete(OutHedTB.class, condition);
        for (OutDetTB det : dets) {
            HashMap<String, String> condition2 = new HashMap<>();
            condition2.put("BillNo", "'" + det.getBillNo() + "'");
            condition2.put("iNo", String.valueOf(det.getINO()));
            erpSqlServer.delete(OutDetTB.class, condition2);
        }
 
    }
}