自动化立体仓库 - WMS系统
dubin
2025-12-19 b00eeab31bd13ba34a03301aa441b0751d6a93e4
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package com.zy.ints.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.core.exception.CoolException;
import com.zy.asrs.entity.LocDetl;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.MatCode;
import com.zy.asrs.service.LocDetlService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.MatCodeService;
import com.zy.common.web.BaseController;
import com.zy.ints.entity.IoComplete;
import com.zy.ints.entity.WaitMatchk;
import com.zy.ints.service.IoCompleteService;
import com.zy.ints.service.WaitMatchkLogService;
import com.zy.ints.service.WaitMatchkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@RestController
public class WaitMatchkController extends BaseController {
 
    @Autowired
    private WaitMatchkService waitMatchkService;
    @Autowired
    private WaitMatchkLogService waitMatchkLogService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private MatCodeService matCodeService;
    @Autowired
    private IoCompleteService ioCompleteService;
 
    //盘点通知档
 
    @RequestMapping(value = "/waitMatchk/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(waitMatchkService.selectById(String.valueOf(id)));
    }
 
    @RequestMapping(value = "/waitMatchk/list/auth")
    @ManagerAuth
    public R list(@RequestParam(defaultValue = "1")Integer curr,
                  @RequestParam(defaultValue = "10")Integer limit,
                  @RequestParam(required = false)String orderByField,
                  @RequestParam(required = false)String orderByType,
                  @RequestParam(required = false)String condition,
                  @RequestParam Map<String, Object> param){
        EntityWrapper<WaitMatchk> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        allLike(WaitMatchk.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(waitMatchkService.selectPage(new Page<>(curr, limit), wrapper));
    }
 
    private void convert(Map<String, Object> map, EntityWrapper wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)){
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else {
                wrapper.like(entry.getKey(), val);
            }
        }
    }
 
    @RequestMapping(value = "/waitMatchk/add/auth")
    @ManagerAuth
    public R add(WaitMatchk waitMatchk) {
        waitMatchkService.insert(waitMatchk);
        return R.ok();
    }
 
    @RequestMapping(value = "/waitMatchk/update/auth")
    @ManagerAuth
    public R update(WaitMatchk waitMatchk){
        if (Cools.isEmpty(waitMatchk) || null==waitMatchk.getMatNo()){
            return R.error();
        }
        waitMatchkService.updateById(waitMatchk);
        return R.ok();
    }
 
    /**
     * 删除盘点通知档,删除前转历史档
     * @param param
     * @return
     */
    @RequestMapping(value = "/waitMatchk/delete/auth")
    @ManagerAuth
    @Transactional
    public R delete(@RequestParam String param){
        List<WaitMatchk> list = JSONArray.parseArray(param, WaitMatchk.class);
        if (Cools.isEmpty(list)){
            return R.error();
        }
        for (WaitMatchk entity : list){
            boolean res =  waitMatchkLogService.save(entity.getBillNo(),entity.getLocNo(),entity.getMatNo());
            if(!res){
                throw new CoolException("转历史档出错[locNo:"+entity.getLocNo()+"],[matNo:"+entity.getMatNo()+"]");
            }else {
                waitMatchkService.delete(new EntityWrapper<>(entity));
            }
        }
        return R.ok();
    }
 
    /**
     * 审核盘点单据
     * @param param
     * @return
     */
    @RequestMapping(value = "/waitMatchk/verify/auth")
    @ManagerAuth
    @Transactional
    public R verify(@RequestParam String param){
        List<WaitMatchk> list = JSONArray.parseArray(param, WaitMatchk.class);
        if (Cools.isEmpty(list)){
            return R.error();
        }
        Date now = new Date();
        for (WaitMatchk entity : list){
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no",entity.getLocNo()));
            if(null != locMast && locMast.getLocSts().equals("F")){
                Wrapper<LocDetl> wrapperDetl = new EntityWrapper<LocDetl>().eq("loc_no",entity.getLocNo()).eq("mat_no",entity.getMatNo());
                LocDetl locDetl = locDetlService.selectOne(wrapperDetl);
                if(null != locDetl) {//更新数量,删除明细
                    if(entity.getCheckQty().equals(0)){
                        if(!locDetlService.delete(wrapperDetl)){
                            throw new CoolException("删除数量为0明细出错[locNo:"+locDetl.getLocNo()+"],[matNo:"+locDetl.getMatNo()+"]");
                        }
 
                        //盘点结果插入回报档
                        IoComplete ioComplete = new IoComplete();
                        ioComplete.setBillNo(entity.getBillNo());
                        ioComplete.setSeqNo(entity.getSeqNo());
                        ioComplete.setTaskType(4);  //盘亏
                        ioComplete.setLocNo(entity.getLocNo());
                        ioComplete.setMatNo(entity.getMatNo());
                        ioComplete.setMatName(locDetl.getMatName());
                        ioComplete.setZpallet(locDetl.getZpallet());
                        ioComplete.setQty(locDetl.getQty());
                        ioComplete.setUpdStatus(0);
                        ioComplete.setModiUser(getUserId());
                        ioComplete.setModiTime(now);
                        ioComplete.setAppeUser(getUserId());
                        ioComplete.setAppeTime(now);
                        if(!ioCompleteService.insert(ioComplete)){
                            throw new CoolException("插入回报档出错[locNo:"+locDetl.getLocNo()+"],[matNo:"+locDetl.getMatNo()+"]");
                        }
 
                    }else{
                        if(!entity.getCheckQty().equals(locDetl.getQty())){ //库存数量与盘点数量相同不用更新
                            locDetl.setQty(entity.getCheckQty());
                            if(!locDetlService.update(locDetl,wrapperDetl)){
                                throw new CoolException("更新库存明细出错[locNo:"+locDetl.getLocNo()+"],[matNo:"+locDetl.getMatNo()+"]");
                            }
 
                            //盘点结果插入回报档
                            Double qty = 0D;
                            int type = 0;
                            if(entity.getCheckQty()>locDetl.getQty()){//盘盈
                                qty = entity.getCheckQty() - locDetl.getQty();
                                type = 3;
                            } else { //盘亏
                                qty = locDetl.getQty() - entity.getCheckQty();
                                type = 4;
                            }
                            IoComplete ioComplete = new IoComplete();
                            ioComplete.setBillNo(entity.getBillNo());
                            ioComplete.setSeqNo(entity.getSeqNo());
                            ioComplete.setTaskType(type);
                            ioComplete.setLocNo(entity.getLocNo());
                            ioComplete.setMatNo(entity.getMatNo());
                            ioComplete.setMatName(locDetl.getMatName());
                            ioComplete.setZpallet(locDetl.getZpallet());
                            ioComplete.setQty(qty);
                            ioComplete.setUpdStatus(0);
                            ioComplete.setModiUser(getUserId());
                            ioComplete.setModiTime(now);
                            ioComplete.setAppeUser(getUserId());
                            ioComplete.setAppeTime(now);
                            if(!ioCompleteService.insert(ioComplete)){
                                throw new CoolException("插入回报档出错[locNo:"+locDetl.getLocNo()+"],[matNo:"+locDetl.getMatNo()+"]");
                            }
                        }
 
                    }
                } else {//插入明细
                    LocDetl one = new LocDetl();
                    one.setLocNo(entity.getLocNo());
                    one.setMatNo(entity.getMatNo());
                    one.setQty(entity.getCheckQty());
                    one.setModiUser(getUserId());
                    one.setModiTime(now);
                    one.setAppeUser(getUserId());
                    one.setAppeTime(now);
 
                    WaitMatchk waitMatchk = waitMatchkService.selectOne(new EntityWrapper<WaitMatchk>().eq("loc_no",entity.getLocNo()));
                    if(null != waitMatchk){
                        one.setZpallet(waitMatchk.getZpallet());
                    }
                    MatCode matCode = matCodeService.selectOne(new EntityWrapper<MatCode>().eq("mat_no",entity.getMatNo()));
                    if(null != matCode) {
                        one.setMatName(matCode.getMatName());
                        one.setUnit(matCode.getUnit());
                        one.setSpecs(matCode.getSpecs());
                        one.setSize(matCode.getSize());
                        one.setColor(matCode.getColor());
                    } else {
                        throw new CoolException("新增明细物料编码不存在出错[matNo:"+entity.getMatNo()+"]");
                    }
 
                    if(!locDetlService.insert(one)){
                        throw new CoolException("插入库存明细出错[locNo:"+entity.getLocNo()+"],[matNo:"+entity.getMatNo()+"]");
                    }
 
                    //盘点结果插入回报档
                    IoComplete ioComplete = new IoComplete();
                    ioComplete.setBillNo(entity.getBillNo());
                    ioComplete.setSeqNo(entity.getSeqNo());
                    ioComplete.setTaskType(3);  //盘盈
                    ioComplete.setLocNo(entity.getLocNo());
                    ioComplete.setMatNo(entity.getMatNo());
                    ioComplete.setMatName(one.getMatName());
                    ioComplete.setZpallet(one.getZpallet());
                    ioComplete.setQty(entity.getCheckQty());
                    ioComplete.setUpdStatus(0);
                    ioComplete.setModiUser(getUserId());
                    ioComplete.setModiTime(now);
                    ioComplete.setAppeUser(getUserId());
                    ioComplete.setAppeTime(now);
                    if(!ioCompleteService.insert(ioComplete)){
                        throw new CoolException("插入回报档出错[locNo:"+entity.getLocNo()+"],[matNo:"+entity.getMatNo()+"]");
                    }
                }
 
                entity.setVerifyStatus(1);
                entity.setVerifyUser(getUserId());
                entity.setModiTime(now);
                Wrapper<WaitMatchk> wrapper = new EntityWrapper<WaitMatchk>().eq("loc_no",entity.getLocNo()).eq("mat_no",entity.getMatNo());
                waitMatchkService.update(entity,wrapper);
            } else {
                throw new CoolException("库位非在库状态:" + locMast.getLocNo());
            }
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/waitMatchk/export/auth")
    @ManagerAuth
    public R export(@RequestBody JSONObject param){
        EntityWrapper<WaitMatchk> wrapper = new EntityWrapper<>();
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        Map<String, Object> map = excludeTrash(param.getJSONObject("waitMatchk"));
        convert(map, wrapper);
        List<WaitMatchk> list = waitMatchkService.selectList(wrapper);
        return R.ok(exportSupport(list, fields));
    }
 
    @RequestMapping(value = "/waitMatchkQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        EntityWrapper<WaitMatchk> wrapper = new EntityWrapper<>();
        wrapper.like("mat_no", condition);
        Page<WaitMatchk> page = waitMatchkService.selectPage(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (WaitMatchk waitMatchk : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", waitMatchk.getMatNo());
            map.put("value", waitMatchk.getMatNo());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping(value = "/waitMatchk/check/column/auth")
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<WaitMatchk> wrapper = new EntityWrapper<WaitMatchk>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != waitMatchkService.selectOne(wrapper)){
            return R.parse(BaseRes.REPEAT).add(getComment(WaitMatchk.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
    }
 
}