#
18516761980
2022-07-16 36c3b2e0b7e631115fe76fad221b3d97c578a07f
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
package com.zy.common.web;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.core.common.Cools;
import com.zy.asrs.entity.WaitPakin;
import com.zy.asrs.service.OutStockService;
import com.zy.asrs.service.WaitPakinService;
import com.zy.common.entity.InterData;
import com.zy.common.service.erp.entity.OutStockBillEntry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import java.math.BigDecimal;
import java.util.List;
 
/**
 * Created by vincent on 2020/10/30
 */
@Slf4j
@RestController
 
public class WcsController {
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private OutStockService outStockService;
 
    @PostMapping("/inout/cancel/auth/v1")
    @ResponseBody
    public JSON getLocNo(@RequestBody String param) throws Exception {
        log.info("ERP取消任务:"+ param);
        JSONObject jsonObject = JSONObject.parseObject(param);//将参数转化为JSON格式
        String inter = jsonObject.getString("data");
        List<InterData> list = JSONArray.parseArray(inter, InterData.class);//获取参数集合
        JSONObject jsonObject1 = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        for (InterData interData : list) {
 
            //原材料入庫
            if ((interData.getIoType() == 1 && interData.getMatType() == 1)) {
                //查询对应入库通知档信息
                Wrapper wrapper = new EntityWrapper<WaitPakin>().eq("supplier", interData.getFBillNo()).eq("matnr", interData.getFnumber());
                WaitPakin waitPakin = waitPakinService.selectOne(wrapper);
                if(Cools.isEmpty(waitPakin)){
                    JSONObject object = new JSONObject();
                    object.put("FInterID", interData.getFInterID());
                    object.put("Fnumber", interData.getFnumber());
                    object.put("code", 500);
                    object.put("msg", "单据不存在或单据已被删除");
                    jsonArray.add(object);
                    continue;
                }
 
                if (Cools.isEmpty(waitPakin)) {
                    JSONObject object = new JSONObject();
                    object.put("FInterID", interData.getFInterID());
                    object.put("Fnumber", interData.getFnumber());
                    object.put("code", 500);
                    object.put("msg", "单据不存在或单据已被删除");
                    jsonArray.add(object);
                    continue;
                }
 
                //判断是否有入库动作   "N"没有  “Y”有
//                interData.getFQty().compareTo(waitPakin.getAnfme())
                if (waitPakin.getIoStatus().equals("N") && waitPakin.getAnfme() < interData.getFQty().doubleValue() ) {
                    //判断传入的数量是否为0来执行删除或者修改
                    if (interData.getFQty().compareTo(BigDecimal.ZERO) == 0) {
                        waitPakinService.delete(wrapper);
                        JSONObject object = new JSONObject();
                        object.put("Fnumber", interData.getFnumber());
                        object.put("FInterID", interData.getFInterID());
                        object.put("code", 200);
                        object.put("msg", "删除成功");
                        jsonArray.add(object);
                    } else {
                        waitPakin.setAnfme(interData.getFQty().doubleValue());
                        waitPakinService.update(waitPakin, wrapper);
                        JSONObject object = new JSONObject();
                        object.put("Fnumber", interData.getFnumber());
                        object.put("FInterID", interData.getFInterID());
                        object.put("code", 200);
                        object.put("msg", "修改成功");
                        jsonArray.add(object);
                    }
 
                } else {
                    JSONObject object = new JSONObject();
                    object.put("FInterID", interData.getFInterID());
                    object.put("Fnumber", interData.getFnumber());
                    object.put("code", 500);
                    object.put("msg", "已在入库中,无法取消");
                    jsonArray.add(object);
                }
            }
 
            //成品入庫
            if (interData.getIoType() == 2 && interData.getMatType() == 2) {
                //查询对应入库通知档信息
                Wrapper wrapper = new EntityWrapper<WaitPakin>().eq("supplier", interData.getFBillNo()).eq("matnr", interData.getFnumber());
                WaitPakin waitPakin = waitPakinService.selectOne(wrapper);
                if(Cools.isEmpty(waitPakin)){
                    JSONObject object = new JSONObject();
                    object.put("FInterID", interData.getFInterID());
                    object.put("Fnumber", interData.getFnumber());
                    object.put("code", 500);
                    object.put("msg", "单据不存在或单据已被删除");
                    jsonArray.add(object);
                    continue;
                }
 
                if (Cools.isEmpty(waitPakin)) {
                    JSONObject object = new JSONObject();
                    object.put("FInterID", interData.getFInterID());
                    object.put("Fnumber", interData.getFnumber());
                    object.put("code", 500);
                    object.put("msg", "单据不存在或单据已被删除");
                    jsonArray.add(object);
                    continue;
                }
 
                WaitPakin one = waitPakinService.selectOne(new EntityWrapper<WaitPakin>()
                        .eq("supplier", interData.getFBillNo())
                        .eq("matnr", interData.getFnumber())
                        .isNotNull("zpallet"));
                //判断是否有入库动作   "N"没有  “Y”有
                if (waitPakin.getIoStatus().equals("N") && Cools.isEmpty(one)) {
                    //判断传入的数量是否为0来执行删除或者修改
                    if (interData.getFQty().compareTo(BigDecimal.ZERO) == 0) {
                        waitPakinService.delete(wrapper);
                        JSONObject object = new JSONObject();
                        object.put("Fnumber", interData.getFnumber());
                        object.put("FInterID", interData.getFInterID());
                        object.put("code", 200);
                        object.put("msg", "删除成功");
                        jsonArray.add(object);
                    } else {
                        waitPakin.setAnfme(interData.getFQty().doubleValue());
                        waitPakinService.update(waitPakin, wrapper);
                        JSONObject object = new JSONObject();
                        object.put("Fnumber", interData.getFnumber());
                        object.put("FInterID", interData.getFInterID());
                        object.put("code", 200);
                        object.put("msg", "修改成功");
                        jsonArray.add(object);
                    }
 
                } else {
                    JSONObject object = new JSONObject();
                    object.put("FInterID", interData.getFInterID());
                    object.put("Fnumber", interData.getFnumber());
                    object.put("code", 500);
                    object.put("msg", "已在入库中,无法取消");
                    jsonArray.add(object);
                }
            }
 
            //成品出庫
            if (interData.getIoType() == 3) {
                Wrapper wrapper1 = new EntityWrapper<OutStockBillEntry>().eq("FInterID", interData.getFInterID()).and().eq("Fnumber", interData.getFnumber());
                OutStockBillEntry outStockBillEntry = outStockService.selectOne(wrapper1);
                if (Cools.isEmpty(outStockBillEntry)) {
                    JSONObject object = new JSONObject();
                    object.put("FInterID", interData.getFInterID());
                    object.put("Fnumber", interData.getFnumber());
                    object.put("code", 500);
                    object.put("msg", "单据不存在或单据已被删除");
                    jsonArray.add(object);
                    continue;
                }
                //判断出库数量回传字段和出库数量字段是否为0
                if (outStockBillEntry.getFAuxCommitQty().compareTo(BigDecimal.ZERO) == 0 && outStockBillEntry.getFAmount().compareTo(BigDecimal.ZERO) == 0) {
                    //判断传入的数量是否为0来执行删除或者修改
                    if (interData.getFQty().compareTo(BigDecimal.ZERO) == 0) {
                        outStockService.delete(wrapper1);
                        JSONObject object = new JSONObject();
                        object.put("Fnumber", interData.getFnumber());
                        object.put("FInterID", interData.getFInterID());
                        object.put("code", 200);
                        object.put("msg", "删除成功");
                        jsonArray.add(object);
                    } else {
                        outStockBillEntry.setFAuxQty(interData.getFQty());
                        outStockBillEntry.setFQty(interData.getFQty());
                        outStockService.update(outStockBillEntry, wrapper1);
                        JSONObject object = new JSONObject();
                        object.put("Fnumber", interData.getFnumber());
                        object.put("FInterID", interData.getFInterID());
                        object.put("code", 200);
                        object.put("msg", "修改成功");
                        jsonArray.add(object);
                    }
                } else {
                    if (outStockBillEntry.getFAuxCommitQty().compareTo(BigDecimal.ZERO) > 0) {
                        JSONObject object = new JSONObject();
                        object.put("Fnumber", interData.getFnumber());
                        object.put("FInterID", interData.getFInterID());
                        object.put("code", 500);
                        object.put("msg", "已在出库中,无法取消");
                        jsonArray.add(object);
                    }
                }
            }
            if (Cools.isEmpty(jsonArray)) {
                JSONObject object = new JSONObject();
                object.put("Fnumber", interData.getFnumber());
                object.put("FInterID", interData.getFInterID());
                object.put("code", 500);
                object.put("msg", "单据有错误,请核对");
                jsonArray.add(object);
            }
        }
 
        jsonObject1.put("data", jsonArray);
        log.info("ERP取消任务--WMS返回结果===>>"+ jsonObject1.toJSONString());
        return jsonObject1;
 
    }
//        if (Cools.isEmpty(param.getIoType())) {
//            return R.error("入出库类型不能为空");
//        }
//        if (Cools.isEmpty(param.getSourceStaNo())) {
//            return R.error("源站编号不能为空");
//        }
//        List<WaitPakin> waitPakins = new ArrayList<WaitPakin>();
//        if (param.getIoType() == 1) {
//            if (Cools.isEmpty(param.getBarcode())) {
//                return R.error("条码不能为空");
//            }
////            waitPakins = waitPakinService.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", param.getBarcode()));
////            if (Cools.isEmpty(waitPakins)) {
////                return R.error("条码数据错误");
////            }
//            int countLoc = locDetlService.selectCount(new EntityWrapper<LocDetl>().eq("zpallet",param.getBarcode()));
//            int countWrk = wrkDetlService.selectCount(new EntityWrapper<WrkDetl>().eq("zpallet",param.getBarcode()));
//            if (countLoc > 0 || countWrk > 0) {
//                return R.error("工作档/库存条码数据已存在");
//            }
//        }
//        if (Cools.isEmpty(param.getLocType1())){
//            return R.error("高低检测信号不能为空");
//        }
//
//        LocTypeDto locTypeDto = new LocTypeDto();
//        locTypeDto.setLocType1(param.getLocType1());
//
//        StartupDto dto = null;
//        switch (param.getIoType()) {
//            case 1:
//                WaitPakin waitPakin = new WaitPakin();
//                waitPakin.setMatnr(param.getBarcode());
//                waitPakin.setAnfme(1D);
//                waitPakins.add(waitPakin);
//                dto = startupFullPutStore(param.getSourceStaNo(), param.getBarcode(), locTypeDto, waitPakins);
//                break;
//            case 10:
//                dto = emptyPlateIn(param.getSourceStaNo(), locTypeDto);
//                break;
//            default:
//                break;
//        }
 
 
}