自动化立体仓库 - WMS系统
zc
2024-07-25 09b04dd475fffad1d38cecf946cd09b6698b0938
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
package com.zy.third.erp.task;
 
import com.zy.common.service.erp.ErpSqlServer;
import com.zy.third.erp.entity.ItemTB;
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 org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * 物料档案
 */
@Slf4j
@Component
public class ERPItemScheduler {
    @Value("${erp.enabled}")
    private Boolean erpEnabled;
 
    @Autowired
    private ERPItemService erpItemService;
 
    @Autowired
    private ErpSqlServer erpSqlServer;
 
 
 
    @Transactional(rollbackFor = Throwable.class)
    @Scheduled(cron = "${erp.refreshtime}")
    public void ItemScheduler() {
        //log.info("ItemScheduler开始了");
        if (!erpEnabled) return;
        String sqlItemTB = "select * from erp_ItemTB where LKName='中扬二期'";
        List<ItemTB> itemTBS = erpSqlServer.select(sqlItemTB, ItemTB.class);
        if (itemTBS != null && itemTBS.size() > 0) {
            for (ItemTB itemTB : itemTBS) {
                System.out.println(itemTB);
                //00代表新增
                if (itemTB.getFlag().equals("00")) {
                    erpItemService.addToMainDatabase(itemTB);
                }
                //22代表删除
                if (itemTB.getFlag().equals("22")) {
                    erpItemService.deleteFromMainDatabase(itemTB);
                }
                moveToBak(itemTB);
            }
        }
    }
 
    /**
     * 数据库里有触发器,当item表的数据被删除时,会自动向item_bak添加,不用卸载代码里
     *
     * @param itemTB
     */
    //将数据从主表移动到bak表里
    private void moveToBak(ItemTB itemTB) {
        erpSqlServer.update("delete from erp_ItemTB where LKName='中扬二期' and ItemId = '" + itemTB.getItemId() + "'");
    }
}