自动化立体仓库 - WMS系统
zyx
2023-10-15 86b8273226c7aa87e7c346659ed9e76278dcc471
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package com.zy.common.service.erp.task;
 
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.AllLocDetl;
import com.zy.asrs.entity.InventoryVariance;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.Tag;
import com.zy.asrs.service.AllLocDetlService;
import com.zy.asrs.service.InventoryVarianceService;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.TagService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.common.service.erp.ErpService;
import com.zy.common.service.erp.entity.Goods;
import com.zy.common.service.erp.entity.WlzhVStRd;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * erp任务控制器
 * Created by vincent on 2020/11/27
 */
@Slf4j
@Component
public class ErpScheduler extends AbstractHandler<Exception> {
 
    @Autowired
    private ErpService erpService;
    @Autowired
    private TagService tagService;
    @Autowired
    private MatService matService;
    @Autowired
    private AllLocDetlService allLocDetlService;
    @Autowired
    private InventoryVarianceService inventoryVarianceService;
 
    //@Scheduled(cron = "0/5 * * * * ? ")
    @Synchronized
    @Transactional
    public synchronized void syncMat() {
        Tag top = tagService.getTop();
        List<Goods> goods = erpService.selectGoods(0);
        Date now = new Date();
        if (!Cools.isEmpty(goods)) {
            for (Goods good : goods) {
                Mat mat = matService.selectByMatnr(good.getMaterialNO());
                if (mat == null) {
                    mat = new Mat();
                    mat.setTagId(top.getId());
                    mat.setMatnr(good.getMaterialNO());
//                    mat.setMaktx(good.getBarCode());
                    mat.setSpecs(good.getProdSpec());
                    mat.setModel(good.getBatch());
                    mat.setWeight(good.getNWT());
                    mat.setUnits(good.getNumOfBobbins()==null?null:good.getNumOfBobbins().doubleValue());
                    mat.setManuDate(good.getProdDate());
 
                    mat.setCreateTime(now);
                    mat.setSku(good.getLocation());
                    if (!Cools.isEmpty(good.getLastUpdatedDate())) {
                        mat.setUpdateTime(DateUtils.convert(good.getLastUpdatedDate().substring(0, 19)));
                    }
 
                    if (!matService.insert(mat)) {
                        throw new CoolException(good.getBarCode() + "商品同步失败");
                    }
                }
                int state = 1;
                if (!erpService.updateStateForGoods(good.getBarCode(), state)) {
                    throw new CoolException(good.getBarCode() + "商品修改State为"+state+"失败");
                }
            }
        }
    }
 
    //@Scheduled(cron = "0/5 * * * * ? ")
    @Synchronized
    @Transactional
    public void syncLocDetl(){
 
        List<InventoryVariance> inventoryVariances = new ArrayList<>();
 
        int pageSize = 500;
        int pageNumber = 0;
        while (true){
            List<WlzhVStRd> wlzhVStRds = erpService.selectPage(pageSize, pageNumber);
            if(wlzhVStRds.size() < pageSize){
                break;
            }
 
            //ERP库存与立库库存比对
            compileStock(wlzhVStRds,inventoryVariances);
            pageNumber ++;
 
        }
 
        inventoryVarianceService.insertBatch(inventoryVariances);
 
    }
 
    private void compileStock(List<WlzhVStRd> wlzhVStRds, List<InventoryVariance> inventoryVariances){
        wlzhVStRds.forEach(wlzhVStRd -> {
            String matnr = wlzhVStRd.getCInvCode();
            String csocode = wlzhVStRd.getCsocode();
            String isoseq = wlzhVStRd.getIsoseq();
            Double iQuantity = wlzhVStRd.getIQuantity();
 
            Double anfme = 0.0;
 
            List<AllLocDetl> allLocDetlList = allLocDetlService.getByMatnrAndCsocodeAndIsoseq(matnr, csocode, isoseq);
            for(AllLocDetl allLocDetl : allLocDetlList){
                anfme += allLocDetl.getAnfme();
            }
 
            int compare = Double.compare(iQuantity, anfme);
            if(compare != 0){
                InventoryVariance inventoryVarianceParam = new InventoryVariance(matnr,csocode,isoseq,iQuantity,anfme);
                inventoryVariances.add(inventoryVarianceParam);
            }
 
        });
    }
 
 
}