自动化立体仓库 - WMS系统
zc
2024-07-27 cef8161169e99e299eefb7c67eeb4cb6e41d99f2
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
package com.zy.third.erp.task;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.Tag;
import com.zy.asrs.mapper.MatMapper;
import com.zy.asrs.mapper.TagMapper;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.TagService;
import com.zy.common.utils.NodeUtils;
import com.zy.third.erp.entity.ItemTB;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
 
 
@Slf4j
@Component
public class ERPItemService {
 
    @Autowired
    private MatService matService;
 
    @Autowired
    private TagService tagService;
 
    @Autowired
    private TagMapper tagMapper;
 
    @Autowired
    private MatMapper matMapper;
 
    /**
     * 将物料中间表数据同步到立库物料基础数据,如果没有则插入,如果有则更新
     *
     * @param itemTB,物料实体类
     */
    protected void addToMainDatabase(ItemTB itemTB) {
        Date now = new Date();
        Mat mat = matService.selectByMatnr(itemTB.getItemId());
        if (mat == null) {
            mat = new Mat();
            Tag priTag = null;
            if (!Cools.isEmpty(itemTB.getItemKind())) {
                priTag = tagService.selectByName(itemTB.getItemKind(), 2);
                if (priTag == null) {
                    Tag top = tagService.getTop();
                    NodeUtils nodeUtils = new NodeUtils();
                    nodeUtils.executePath(top.getId());
                    priTag = new Tag(
                            null,    // 编号
                            itemTB.getItemKind(),    // 名称
                            top.getId(),    // 父级
                            top.getName(),    // 父级名称
                            nodeUtils.path.toString(),    // 关联路径
                            nodeUtils.pathName.toString(),    // 关联路径名
                            0,    // 类型
                            null,    // 负责人
                            null,    // 图片
                            null,    // 简要描述
                            null,    // 数量
                            2,    // 等级
                            null,    // 排序
                            1,    // 状态
                            now,    // 添加时间
                            null,    // 添加人员
                            now,    // 修改时间
                            null,    // 修改人员
                            null    // 备注
                    );
                    if (tagMapper.insert(priTag) == 0) {
                        throw new CoolException("服务器内部错误,请联系管理员");
                    }
                }
            }
            priTag = tagService.selectByName(itemTB.getItemKind(), 2);
            mat = sync(mat, itemTB);
 
            mat.setTagId(priTag.getId());
            mat.setStatus(1);
            mat.setCreateTime(now);
            mat.setUpdateTime(now);
            if (!matService.insert(mat)) {
                throw new CoolException("服务器内部错误,请联系管理员");
            } else {
                log.info("同步新物料[商品编号:{}]", mat.getMatnr());
            }
        } else {
            mat = sync(mat, itemTB);
            if (!matService.update(mat, new EntityWrapper<Mat>().eq("matnr", itemTB.getItemId()))) {
                throw new CoolException("更新已存在商品信息失败,请联系管理员");
            }
        }
    }
 
    private Mat sync(Mat mat, ItemTB itemTB) {
        mat.setModel(itemTB.getItemCode());
        mat.setMatnr(itemTB.getItemId());
        mat.setMaktx(itemTB.getItemName());
        mat.setSpecs(itemTB.getItemSpc());
        mat.setUnit(itemTB.getItemUnit());
        mat.setMemo(itemTB.getRemark());
        mat.setCreateTime(itemTB.getMakeDate());
        mat.setTemp1(itemTB.getTemp1());
        mat.setTemp2(itemTB.getTemp2());
        mat.setTemp3(itemTB.getTemp3());
        return mat;
    }
 
    /**
     * 删除ASRS物料通知档数据
     *
     * @param itemTB,物料实体类
     */
    protected void deleteFromMainDatabase(ItemTB itemTB) {
        EntityWrapper<Mat> matCodeEntityWrapper = new EntityWrapper<>();
        matCodeEntityWrapper.eq("matnr", itemTB.getItemCode());
        matMapper.delete(matCodeEntityWrapper);
    }
 
 
}