自动化立体仓库 - WMS系统
#
luxiaotao1123
2022-12-08 592f175ea0ad02c4e22cb62e77ea9e1e9cfbe516
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
package com.zy.common.service.erp.task;
 
import com.alibaba.fastjson.JSON;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.Tag;
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.dto.VoucherDto;
import com.zy.common.service.erp.entity.Goods;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
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;
 
    @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.getBarCode());
                if (mat == null) {
                    mat = new Mat();
                    mat.setTagId(top.getId());
                    mat.setMatnr(good.getBarCode());
                    mat.setMaktx(good.getMaterialNO());
                    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(JSON.toJSONString(good) + "商品同步失败");
                    }
                }
            }
        }
    }
 
    @Scheduled(cron = "0/5 * * * * ? ")
    @Synchronized
    @Transactional
    public synchronized void syncOrder() {
        List<VoucherDto> list = erpService.selectOrder(0);
        System.out.println(JSON.toJSONString(list));
    }
 
}