自动化立体仓库 - WMS系统
wang..123
2022-02-15 7182f72ba4781c620eebdf501ca46b3f69f5585d
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package com.zy.asrs.service.impl;
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.MatCode;
import com.zy.asrs.entity.PltBarcode;
import com.zy.asrs.entity.WrkDetl;
import com.zy.asrs.entity.param.CombParam;
import com.zy.asrs.service.*;
import com.zy.ints.entity.WaitMatin;
import com.zy.ints.service.WaitMatinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.text.SimpleDateFormat;
import java.time.chrono.IsoEra;
import java.util.Date;
import java.util.List;
import java.util.Random;
 
/**
 * 移动端服务核心类
 * Created by vincent on 2020/6/28
 */
@Service
public class MobileServiceImpl implements MobileService {
 
    @Autowired
    private MatCodeService matCodeService;
    @Autowired
    private WaitMatinService waitMatinService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private WrkDetlService wrkDetlService;
    @Autowired
    private PltBarcodeService pltBarcodeService;
 
    @Override
    @Transactional
    public void comb(CombParam param, Long userId) {
        if (Cools.isEmpty(param.getBarcode()) || param.getCombMats().isEmpty()) {
            throw new CoolException(BaseRes.PARAM);
        }
//        int countPak = waitPakinService.selectCount(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()));
//                eq("zpallet", param.getBarcode()).eq("io_status", "N"));
        int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode()));
        int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode()));
        int countPlt = pltBarcodeService.selectCount(new EntityWrapper<PltBarcode>().eq("barcode",param.getBarcode()));
        if (countPlt > 0 || countLoc > 0 || countWrk > 0) {
            throw new CoolException("条码数据已存在");
        }
 
        Date now = new Date();
        if (Cools.isEmpty(param.getBillNo())) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            Random rand = new Random();
            Integer r = rand.nextInt(900)+ 100;
            String billNo = sdf.format(new Date()) + r;
            Integer seqNo=0;
            for (CombParam.CombMat combMat : param.getCombMats()) {
                MatCode matCode = matCodeService.selectOne(new EntityWrapper<MatCode>().eq("mat_no", combMat.getMatNo()));
                if (Cools.isEmpty(matCode)) {
                    throw new CoolException("物料数据错误");
                }
                seqNo++;
                PltBarcode pltBarcode = new PltBarcode();
                pltBarcode.setBarcode(param.getBarcode());
                pltBarcode.setBillNo(billNo);
                pltBarcode.setSeqNo(seqNo);
                pltBarcode.setBillType(5);
                pltBarcode.setMatNo(matCode.getMatNo());
                pltBarcode.setMatName(matCode.getMatName());
                pltBarcode.setQty(combMat.getCount());
                pltBarcode.setUnit(matCode.getUnit());
                pltBarcode.setSpecs(matCode.getSpecs());
                pltBarcode.setSize(matCode.getSize());
                if(Cools.isEmpty(combMat.getSupplier())){
                    String supp = sdf.format(new Date()) + r;
                    pltBarcode.setSupplier(supp);
                }else{
                    pltBarcode.setSupplier(combMat.getSupplier());
                }
                pltBarcode.setMemo(combMat.getMemo());
                pltBarcode.setColor(matCode.getColor());
                pltBarcode.setLinkErp(0);
                pltBarcode.setModiUser(userId);
                pltBarcode.setModiTime(now);
                pltBarcode.setAppeUser(userId);
                pltBarcode.setAppeTime(now);
                if(matCode.getWeight()==null){
                    matCode.setWeight(0.0);
                }
                if(matCode.getStr6()==null){
                    matCode.setStr6(0.0);
                    pltBarcode.setAllQty(pltBarcode.getQty());
                }else {
                    pltBarcode.setAllQty(matCode.getStr6()*pltBarcode.getQty());
                }
                pltBarcode.setWeight(matCode.getWeight());
                pltBarcode.setAllWeight(matCode.getWeight()*pltBarcode.getQty()+30);
                pltBarcode.setVendor(combMat.getVendor());
                pltBarcode.setSource(combMat.getSource());
                pltBarcode.setQtyBox(matCode.getStr6());
                if (!pltBarcodeService.insert(pltBarcode)) {
                    throw new CoolException("保存数据失败");
                }
            }
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            Random rand = new Random();
            Integer r = rand.nextInt(900)+ 100;
            // 关联通知单组托
            for (CombParam.CombMat combMat : param.getCombMats()) {
                WaitMatin waitMatin = waitMatinService.selectOne(new EntityWrapper<WaitMatin>()
 
                        .eq("bill_no",param.getBillNo()).eq("seq_no",combMat.getSeqNo()));
 
                MatCode matCode = matCodeService.selectOne(new EntityWrapper<MatCode>().eq("mat_no", combMat.getMatNo()));
 
                if (waitMatin == null) {
                    throw new CoolException("通知单不存在" + combMat.getMatNo() + "数据!");
                }
 
                if (combMat.getCount() > (waitMatin.getQty()-waitMatin.getInQty())) {
                    throw new CoolException(combMat.getMatNo() + "组托物料数量不足!");
                }
 
                PltBarcode pltBarcode = new PltBarcode();
                pltBarcode.setBarcode(param.getBarcode());
                pltBarcode.setBillNo(waitMatin.getBillNo());
                pltBarcode.setSeqNo(waitMatin.getSeqNo());
                pltBarcode.setBillType(waitMatin.getBillType());
                pltBarcode.setMatNo(waitMatin.getMatNo());
                pltBarcode.setMatName(waitMatin.getMatName());
                pltBarcode.setQty(combMat.getCount());
                pltBarcode.setUnit(waitMatin.getUnit());
                pltBarcode.setSpecs(waitMatin.getSpecs());
                pltBarcode.setSize(waitMatin.getSize());
                pltBarcode.setColor(waitMatin.getColor());
                pltBarcode.setLinkErp(waitMatin.getLinkErp());
                pltBarcode.setModiUser(userId);
                pltBarcode.setModiTime(now);
                pltBarcode.setAppeUser(userId);
                pltBarcode.setAppeTime(now);
                if(Cools.isEmpty(combMat.getSupplier())){
                    String supp = sdf.format(new Date()) + r;
                    pltBarcode.setSupplier(supp);
                }else{
                    pltBarcode.setSupplier(combMat.getSupplier());
                }
                if(matCode.getWeight()==null){
                    matCode.setWeight(0.0);
                }
                if(matCode.getStr6()==null){
                    matCode.setStr6(0.0);
                    pltBarcode.setAllQty(pltBarcode.getQty());
                }else {
                    pltBarcode.setAllQty(matCode.getStr6()*pltBarcode.getQty());
                }
                pltBarcode.setWeight(matCode.getWeight());
                pltBarcode.setAllWeight(matCode.getWeight()*pltBarcode.getQty()+30);
                pltBarcode.setVendor(combMat.getVendor());
                pltBarcode.setSource(combMat.getSource());
                pltBarcode.setQtyBox(matCode.getStr6());
                if (!pltBarcodeService.insert(pltBarcode)) {
                    throw new CoolException("保存数据失败");
                }
 
                waitMatin.setInQty(combMat.getCount() + waitMatin.getInQty());
                if (!waitMatinService.update(waitMatin,new EntityWrapper<WaitMatin>()
                        .eq("bill_no",param.getBillNo()).eq("seq_no",combMat.getSeqNo()))){
                    throw new CoolException("更新数据失败");
                }
 
            }
        }
    }
 
}