Blame view

src/main/java/com/huaheng/pc/u8/service/ICSShipmentApiService.java 44.6 KB
1
2
package com.huaheng.pc.u8.service;
tongzhonghao authored
3
import com.alibaba.fastjson.JSON;
4
5
6
7
8
9
10
11
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.general.domain.ShipmentDomain;
import com.huaheng.api.general.service.ShipmentApiService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
tongzhonghao authored
12
import com.huaheng.common.utils.http.HttpUtils;
13
import com.huaheng.framework.web.domain.AjaxResult;
14
import com.huaheng.pc.config.company.domain.CompanyU8;
15
import com.huaheng.pc.config.company.service.CompanyService;
16
import com.huaheng.pc.config.company.service.CompanyU8Service;
17
18
19
20
21
import com.huaheng.pc.config.documentWarning.service.IDocumentWarningService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.warehouse.domain.WarehouseU8;
import com.huaheng.pc.config.warehouse.service.WarehouseU8Service;
tongzhonghao authored
22
23
import com.huaheng.pc.referenceCode.domain.U8Reference;
import com.huaheng.pc.referenceCode.service.U8ReferenceService;
24
25
26
27
28
29
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
tongzhonghao authored
30
31
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
32
33
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
tongzhonghao authored
34
import com.huaheng.pc.u8.domain.*;
35
36
37
38
39
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.ParseException;
40
41
import java.util.*;
import java.util.stream.Collectors;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

@Service
public class ICSShipmentApiService {

    @Resource
    private IDocumentWarningService documentWarningService;
    @Resource
    private WarehouseU8Service warehouseU8Service;
    @Resource
    private ShipmentApiService shipmentApiService;
    @Resource
    private MaterialService materialService;
    @Resource
    private ICSShipmentDetailService icsShipmentDetailService;
    @Resource
    private ICSShipmentHeaderService icsShipmentHeaderService;
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
    @Resource
    private ShipmentDetailService shipmentDetailService;
    @Resource
    private ShipmentContainerDetailService shipmentContainerDetailService;
    @Resource
    private TaskDetailService taskDetailService;
66
67
    @Resource
    private CompanyU8Service companyU8Service;
tongzhonghao authored
68
69
70
71
    @Resource
    private ICSReceiptAPIService icsReceiptAPIService;
    @Resource
    private IUserService userService;
tongzhonghao authored
72
73
    @Resource
    private U8ReferenceService u8ReferenceService;
74
75
    @Resource
    private CompanyService companyService;
76
77
78
79
80
81
82
83




        //u8-wms出库下发
    @Transactional
    public AjaxResult procureShipment(ICSShipmentModel icsShipmentModel){
    //获取主单和子单列
tongzhonghao authored
84
        icsShipmentModel = assign(icsShipmentModel);
85
86
        ICSShipmentHeader icsShipmentHeader=icsShipmentModel.getIcsShipmentHeader();
        List<ICSShipmentDetail> icsShipmentDetails=icsShipmentModel.getIcsShipmentDetails();
87
88
89
90
        String currentWarehouseCode = icsShipmentHeader.getWarehouseCode();
        if(StringUtils.isEmpty(currentWarehouseCode)){
            return AjaxResult.error("仓库编码不能为空");
        }
tongzhonghao authored
91
92
93
        if(StringUtils.isEmpty(icsShipmentHeader.getIsNew())){
            return AjaxResult.error("IsNew不能为空");
        }
tongzhonghao authored
94
        boolean isFlag = "0".equals(icsShipmentHeader.getIsNew()) ? true : false;
95
        String type = icsShipmentHeader.getType();
tongzhonghao authored
96
        String typeName = getShipmentTypeName(type);
97
98
99
100
101
102
103
        switch (type){
            case "QO" :
            case "MO" :
            case "OO" :
            case "PKO" :
            case "TO" :
                break;
tongzhonghao authored
104
105
            default:
                return AjaxResult.error("出库类型不匹配");
106
        }
tongzhonghao authored
107
        //U8仓库编码
108
        String u8WarehouseCode = icsShipmentHeader.getStock();
tongzhonghao authored
109
        //U8公司编码
110
111
112
113
114
        String u8CompanyCode = icsShipmentHeader.getCompanyCode();
        //判断U8货主
        CompanyU8 companyU8 = companyU8Service.getCompanyByU8CodeWarehouseCode(u8CompanyCode, currentWarehouseCode);
        if(companyU8==null){
            return AjaxResult.error("系统没有此货主:【"+u8CompanyCode+"】");
115
        }
116
117
        if(StringUtils.isEmpty(u8WarehouseCode)){
            return AjaxResult.error("仓库编码为空:【"+u8WarehouseCode+"】");
118
        }
119
        companyService.checkwarehouseCompany(companyU8.getCompanyCode());
120
121
122
        //通过u8的货主和仓库匹配wms的仓库
        WarehouseU8 warehouseU8 = warehouseU8Service.getOne(new LambdaQueryWrapper<WarehouseU8>()
                .eq(WarehouseU8::getUCompanyCode, icsShipmentHeader.getCompanyCode())
周鸿 authored
123
                .eq(WarehouseU8::getUWarehouseCode, u8WarehouseCode));
124
125
126
        if (warehouseU8 == null) {
            return AjaxResult.error("系统没有此仓库");
        }
127
128
129
130
        //u8关联表 检查上游单号是否重复
        U8Reference one = u8ReferenceService.getOne(new LambdaQueryWrapper<U8Reference>()
                .eq(U8Reference::getReferCode, icsShipmentHeader.getReferCode())
                .eq(U8Reference::getReferType, icsShipmentHeader.getType())
tongzhonghao authored
131
132
                .eq(U8Reference::getWarehouseCode, currentWarehouseCode)
                .last("LIMIT 1"));
133
134
        //入库单表 检查上游单号是否重复
        ShipmentHeader shipmentHeader1 = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
tongzhonghao authored
135
136
                .eq(ShipmentHeader::getReferCode, icsShipmentHeader.getReferCode())
                .eq(ShipmentHeader::getWarehouseCode,currentWarehouseCode));
137
138
139
140
141
        if(!isFlag){
            if(one != null && shipmentHeader1 != null){
                return AjaxResult.error(":请不要重复下发 "+icsShipmentHeader.getReferCode());
            }
        }
tongzhonghao authored
142
143
144
        if(icsShipmentHeader.getIsFlag()){
            checkShipmentBill(isFlag,icsShipmentHeader.getReferCode(),icsShipmentHeader.getType());
        }
tongzhonghao authored
145
146
147
148
149
150
151
152
153
154
155
156

        boolean save = icsShipmentHeaderService.save(icsShipmentHeader);
        if(!save){
            throw new ServiceException("下发失败");
        }
        for (ICSShipmentDetail icsShipmentDetail : icsShipmentDetails) {
            icsShipmentDetail.setHeaderId(icsShipmentHeader.getSId());
        }
        save = icsShipmentDetailService.saveBatch(icsShipmentDetails);
        if(!save){
            throw new ServiceException("下发失败");
        }
tongzhonghao authored
157
158
159
        if(!icsShipmentHeader.getIsFlag()){
            return AjaxResult.success();
        }
160
161
162
        //根据icsShipmentHeader生成shipmentHeader
        ShipmentHeader shipmentHeader=new ShipmentHeader();
163
164
        String maker = icsShipmentHeader.getCMaker();
        shipmentHeader.setShipmentType(type);
165
166
        shipmentHeader.setReferCode(icsShipmentHeader.getReferCode());
        shipmentHeader.setReferId(icsShipmentHeader.getReferId());
167
168
169
        shipmentHeader.setId(null);
        shipmentHeader.setLastUpdatedBy(maker);
        shipmentHeader.setCreatedBy(maker);
170
        shipmentHeader.setCreated(icsShipmentHeader.getCreated());
171
172
173
        shipmentHeader.setCustomerCode(icsShipmentHeader.getCCusCode());
        shipmentHeader.setShipmentNote(icsShipmentHeader.getCMemo());
        shipmentHeader.setWarehouseCode(warehouseU8.getWarehouseCode());
174
        shipmentHeader.setUWarehouseCode(icsShipmentHeader.getStock());
175
        shipmentHeader.setCompanyCode(warehouseU8.getCompanyCode());
tongzhonghao authored
176
        shipmentHeader.setCDepName(icsShipmentHeader.getCDepName());
177
178
179
180
181
182
183
184
        shipmentHeader.setRecMobile(icsShipmentHeader.getRecMobile());
        shipmentHeader.setRecCompany(icsShipmentHeader.getRecCompany());
        shipmentHeader.setRecName(icsShipmentHeader.getRecName());
        shipmentHeader.setRecAddr(icsShipmentHeader.getRecAddr());
        shipmentHeader.setSendAddr(icsShipmentHeader.getSendAddr());
        shipmentHeader.setSendCompany(icsShipmentHeader.getSendCompany());
        shipmentHeader.setSendMobile(icsShipmentHeader.getSendMobile());
        shipmentHeader.setSendName(icsShipmentHeader.getSendName());
185
186
187
        switch (type){
            case "OO" :
                shipmentHeader.setReferCode(icsShipmentHeader.getMoCode());
188
                shipmentHeader.setReferId(icsShipmentHeader.getReferId());
189
190
191
                break;
            case "TO" :
                shipmentHeader.setReferCode(icsShipmentHeader.getCTVCode());
192
                shipmentHeader.setReferId(icsShipmentHeader.getReferId());
193
194
195
                break;
            default:
                shipmentHeader.setReferCode(icsShipmentHeader.getCCode());
196
                shipmentHeader.setReferId(icsShipmentHeader.getReferId());
197
198
199
200
201
202
203
204
205
206
207
                break;
        }
        if (StringUtils.isEmpty(shipmentHeader.getReferCode())) {
            throw new ServiceException("没有单号");
        }
        //根据icsShipmentDetail生成shipmentAetail
        List<ShipmentDetail> shipmentDetails = new ArrayList<ShipmentDetail>();
        for (ICSShipmentDetail icsShipmentDetail : icsShipmentDetails) {
            //查找物料
            Material material = materialService.getOne(new LambdaQueryWrapper<Material>()
                    .eq(Material::getCode, icsShipmentDetail.getCInvCode())
周鸿 authored
208
                    .eq(Material::getWarehouseCode, warehouseU8.getWarehouseCode()));
209
210
211
212
213
            if (material == null) {
                throw new ServiceException("该物料不存在:" + icsShipmentDetail.getCInvCode());
            }
            ShipmentDetail shipmentDetail = new ShipmentDetail();
            shipmentDetail.setId(null);
214
            shipmentDetail.setReferId(icsShipmentDetail.getAutoID());
215
216
217
218
219
            shipmentDetail.setReferCode(shipmentHeader.getReferCode());
            shipmentDetail.setMoCode(icsShipmentDetail.getMoCode());
            shipmentDetail.setLot(icsShipmentDetail.getCDefine23());
            shipmentDetail.setWarehouseCode(warehouseU8.getWarehouseCode());
            shipmentDetail.setMaterialCode(icsShipmentDetail.getCInvCode());
220
221
            shipmentDetail.setMaterialName(icsShipmentDetail.getCInvName());
            shipmentDetail.setMaterialSpec(icsShipmentDetail.getCInvStd());
222
//                    shipmentDetail.setZoneCode(material.getZoneCode());
223
224
            shipmentDetail.setCreated(DateUtils.getNowDate());
            shipmentDetail.setBatch("");
tongzhonghao authored
225
            shipmentDetail.setUWarehouseCode(shipmentHeader.getUWarehouseCode());
226
227
            shipmentDetail.setMaterialUnit(icsShipmentDetail.getCComUnitName());
            shipmentDetail.setCreatedBy(maker);
228
            shipmentDetail.setLastUpdated(DateUtils.getNowDate());
229
            shipmentDetail.setLastUpdatedBy(maker);
230
            shipmentDetail.setMoCode(icsShipmentDetail.getMoCode());
231
            if (!icsShipmentDetail.getCompanyCode().equals(icsShipmentHeader.getCompanyCode())) {
tongzhonghao authored
232
//                documentWarningService.ErpSendWarning(shipmentHeader.getReferCode(), "子单货主与主单不对应");
233
234
235
                throw new ServiceException("子单货主与主单不对应");
            }
            shipmentDetail.setCompanyCode(warehouseU8.getCompanyCode());
tongzhonghao authored
236
            shipmentDetail.setAutoId(icsShipmentDetail.getAutoID());
237
238
239
            shipmentDetail.setProjectNo(icsShipmentDetail.getCItemName());
            shipmentDetail.setQty((icsShipmentDetail.getIQuantity()).abs());
            shipmentDetail.setQtyCompleted(icsShipmentDetail.getIQuantity());
tongzhonghao authored
240
            shipmentDetail.setInventorySts(QuantityConstant.GOOD);
241
242
243
244
245
246
247
248
249
250
251
252
253
254
            if (icsShipmentDetail.getIrowno() != null && StringUtils.isNotEmpty(icsShipmentDetail.getIrowno().toString())) {
                shipmentDetail.setReferLineNum(icsShipmentDetail.getIrowno().toString());
            }
            if (icsShipmentDetail.getSortSeq() != null && StringUtils.isNotEmpty(icsShipmentDetail.getSortSeq().toString())) {
                shipmentDetail.setReferLineNum(icsShipmentDetail.getSortSeq().toString());
            }
            shipmentDetails.add(shipmentDetail);
        }

        //调用公共API
        ShipmentDomain shipmentDomain = new ShipmentDomain();
        shipmentDomain.setShipmentHeader(shipmentHeader);
        shipmentDomain.setShipmentDetails(shipmentDetails);
        AjaxResult ajaxResult = shipmentApiService.shipment(shipmentDomain);
255
256
257
258
259
260
261
262
263
264
265
        if(!ajaxResult.hasErr() && !isFlag){
            U8Reference reference = new U8Reference();
            reference.setReferType(icsShipmentHeader.getType());
            reference.setReferCode(icsShipmentHeader.getReferCode());
            reference.setStock(icsShipmentHeader.getStock());
            reference.setCompanyCode(warehouseU8.getCompanyCode());
            reference.setWarehouseCode(currentWarehouseCode);
            reference.setTypeName(typeName);
            reference.setCreated(DateUtils.getNowDate());
            u8ReferenceService.save(reference);
        }
266
267
268
        if(ajaxResult.hasErr()){
            return ajaxResult;
        }
tongzhonghao authored
269
        if(!isFlag){
270
             return AjaxResult.success("出库单下发成功");
tongzhonghao authored
271
        }else if (isFlag) {
272
273
274
275
276
277
            return AjaxResult.success("出库单更新成功");
        }
        return AjaxResult.success("出库单下发成功");
    }
278
279
280
281
282
283
284
285
286
        //出库单为销售出库或采购退货单时

    /**
     * 出库单为 销售出库单 | 采购退货单
     * @param icsShipmentModel
     * @return
     */
    @Transactional
    public AjaxResult saleShipmentOrPurchReturn(ICSShipmentModel icsShipmentModel){
287
        icsShipmentModel = assign(icsShipmentModel);
288
289
        ICSShipmentHeader icsShipmentHeader=icsShipmentModel.getIcsShipmentHeader();
        List<ICSShipmentDetail> icsShipmentDetails=icsShipmentModel.getIcsShipmentDetails();
tongzhonghao authored
290
291
292
        if(StringUtils.isEmpty(icsShipmentHeader.getIsNew())){
            return AjaxResult.error("isNew为空");
        }
293
294
        boolean isFlag = "0".equals(icsShipmentHeader.getIsNew()) ? true : false;
        String type = icsShipmentHeader.getType();
295
        String currentWarehouseCode = icsShipmentHeader.getWarehouseCode();
tongzhonghao authored
296
297
298
        if(StringUtils.isEmpty(currentWarehouseCode)){
            return AjaxResult.error("仓库编码不能为空");
        }
299
300
301
302
303
304
305
        String typeName = getShipmentTypeName(type);
        switch (type){
            case "SO" :
            case "PRO" :
                break;
            default:
                return AjaxResult.error("出库类型不匹配");
306
        }
tongzhonghao authored
307
308
        String code=icsShipmentHeader.getReferCode();
309
        if(StringUtils.isEmpty(code)){
310
            return AjaxResult.error("没有单号");
311
312
313
        }

        CompanyU8 companyWu = companyU8Service.getOne(new LambdaQueryWrapper<CompanyU8>()
tongzhonghao authored
314
315
                .eq(CompanyU8::getUCompanyCode, icsShipmentHeader.getCompanyCode())
                .last("LIMIT 1"));
316
317
318
        if(companyWu == null){
            return AjaxResult.error("单据货主不存在"+icsShipmentHeader.getCompanyCode());
        }
319
        WarehouseU8 warehouseU81 = warehouseU8Service.getOne(new LambdaQueryWrapper<WarehouseU8>()
tongzhonghao authored
320
                .eq(WarehouseU8::getUCompanyCode, icsShipmentHeader.getCompanyCode())
321
322
323
324
                .eq(WarehouseU8::getUWarehouseCode, icsShipmentHeader.getStock())
                .eq(WarehouseU8::getWarehouseCode, currentWarehouseCode));
        if(warehouseU81==null){
            return AjaxResult.error("仓库编码不错误:"+icsShipmentHeader.getStock());
325
        }
326
327
328
329
330
331
332
333
334
335
        //u8关联表 检查上游单号是否重复
        U8Reference one = u8ReferenceService.getOne(new LambdaQueryWrapper<U8Reference>()
                .eq(U8Reference::getReferCode, icsShipmentHeader.getReferCode())
                .eq(U8Reference::getReferType, icsShipmentHeader.getType())
                .eq(U8Reference::getWarehouseCode, currentWarehouseCode));
        //入库单表 检查上游单号是否重复
        ShipmentHeader shipmentHeader1 = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
                .eq(ShipmentHeader::getReferCode, icsShipmentHeader.getReferCode()));
        if(one != null && !isFlag && shipmentHeader1 != null){
            return AjaxResult.error(typeName + ":请不要重复下发 "+icsShipmentHeader.getReferCode());
336
        }
337
        //判断出库单是否可以更新
tongzhonghao authored
338
339
340
341
342
343
344
345
346
347
348
349
350
351
        checkShipmentBill(isFlag,code,icsShipmentHeader.getType());

        boolean save = icsShipmentHeaderService.save(icsShipmentHeader);
        if(!save){
            throw new ServiceException("下发失败");
        }
        for (ICSShipmentDetail icsShipmentDetail : icsShipmentDetails) {
            icsShipmentDetail.setHeaderId(icsShipmentHeader.getSId());
        }
        save = icsShipmentDetailService.saveBatch(icsShipmentDetails);
        if(!save){
            throw new ServiceException("下发失败");
        }
352
353
354
355
356
357
358
        String maker = icsShipmentHeader.getCMaker();
        ShipmentHeader shipmentHeader = new ShipmentHeader();
        shipmentHeader.setShipmentType(icsShipmentHeader.getType());
        shipmentHeader.setId(null);
        if(StringUtils.isNotEmpty(icsShipmentHeader.getFromCompanyCode())){
            shipmentHeader.setUserDef3("跨账套");
359
        }
360
361
        shipmentHeader.setReferId(icsShipmentHeader.getReferId());
        shipmentHeader.setReferCode(icsShipmentHeader.getReferCode());
362
363
364
365
366
367
        shipmentHeader.setLastUpdatedBy(maker);
        shipmentHeader.setCreatedBy(maker);
        shipmentHeader.setCreated(icsShipmentHeader.getCreated());
        shipmentHeader.setCustomerCode(icsShipmentHeader.getCCusCode());
        shipmentHeader.setLastUpdated(icsShipmentHeader.getCreated());
        shipmentHeader.setReferCode(code);
tongzhonghao authored
368
        shipmentHeader.setShipmentNote(icsShipmentHeader.getCMemo());
369
370
371
        shipmentHeader.setWarehouseCode(currentWarehouseCode);
        shipmentHeader.setUWarehouseCode(icsShipmentHeader.getStock());
        shipmentHeader.setCompanyCode(companyWu.getCompanyCode());
372
373
        shipmentHeader.setSupplierCode(icsShipmentHeader.getCVenCode());
        shipmentHeader.setDeptCode(icsShipmentHeader.getCDepCode());
374
375
376
377
378
379
380
381
382
        shipmentHeader.setCDepName(icsShipmentHeader.getCDepName());
        shipmentHeader.setRecMobile(icsShipmentHeader.getRecMobile());
        shipmentHeader.setRecCompany(icsShipmentHeader.getRecCompany());
        shipmentHeader.setRecName(icsShipmentHeader.getRecName());
        shipmentHeader.setRecAddr(icsShipmentHeader.getRecAddr());
        shipmentHeader.setSendAddr(icsShipmentHeader.getSendAddr());
        shipmentHeader.setSendCompany(icsShipmentHeader.getSendCompany());
        shipmentHeader.setSendMobile(icsShipmentHeader.getSendMobile());
        shipmentHeader.setSendName(icsShipmentHeader.getSendName());
383
        //销售单向wms主单存入发货信息和收货信息
tongzhonghao authored
384
        if (!StringUtils.isEmpty(icsShipmentHeader.getCSCName()) && "快递".equals(icsShipmentHeader.getCSCName()) && StringUtils.isNotEmpty(icsShipmentHeader.getRecName())) {
385
386
            shipmentHeader.setKdEable(1);
        }
387
388
389
390
391
392
393
        List<ShipmentDetail> shipmentDetails = new ArrayList<>();
        for (ICSShipmentDetail item : icsShipmentDetails) {
            //查找物料
            Material material = materialService.getOne(new LambdaQueryWrapper<Material>()
                    .eq(Material::getCode, item.getCInvCode())
                    .eq(Material::getWarehouseCode, currentWarehouseCode));
            if(material==null){
tongzhonghao authored
394
//                documentWarningService.ErpSendWarning(code, "该物料不存在:"+item.getCInvCode());
395
                throw new ServiceException("该物料不存在:"+item.getCInvCode());
396
            }
397
398
399
            ShipmentDetail shipmentDetail = new ShipmentDetail();
            shipmentDetail.setId(null);
            shipmentDetail.setReferCode(code);
tongzhonghao authored
400
            shipmentDetail.setAutoId(item.getAutoID());
401
            shipmentDetail.setReferLineNum(item.getIrowno()+"");
402
            shipmentDetail.setWarehouseCode(currentWarehouseCode);
403
            shipmentDetail.setUWarehouseCode(icsShipmentHeader.getUWarehouseCode());
404
405
406
407
408
409
410
411
            shipmentDetail.setMaterialCode(item.getCInvCode());
            shipmentDetail.setZoneCode(material.getZoneCode());
            shipmentDetail.setCreated(DateUtils.getNowDate());
            shipmentDetail.setUWarehouseCode(item.getCWHCode());
            shipmentDetail.setCreatedBy(maker);
            shipmentDetail.setMaterialSpec(item.getCComUnitName());
            shipmentDetail.setLastUpdated(DateUtils.getNowDate());
            shipmentDetail.setLastUpdatedBy(maker);
412
413
414
            shipmentDetail.setPoId(item.getPOID());
            shipmentDetail.setPodId(item.getPODID());
            shipmentDetail.setPoCode(item.getPOCode());
415
            if (!item.getCompanyCode().equals(icsShipmentHeader.getCompanyCode())) {
tongzhonghao authored
416
//                documentWarningService.ErpSendWarning(code, "子单货主与主单不对应");
417
                throw new ServiceException("子单货主与主单不对应");
418
            }
tongzhonghao authored
419
//            shipmentDetail.setMoCode(item.getCDefine22());
420
421
422
423
424
425
426
427
428
            shipmentDetail.setLot(item.getCDefine23());
            shipmentDetail.setCompanyCode(companyWu.getCompanyCode());
            shipmentDetail.setProjectNo(item.getCItemName());
            shipmentDetail.setQty((item.getIQuantity()).abs());
            shipmentDetail.setQtyCompleted(item.getIQuantity());
            shipmentDetail.setInventorySts(QuantityConstant.GOOD);
            shipmentDetail.setSoCode(item.getCSOCode());
            shipmentDetail.setSoId(item.getCSOID());
            shipmentDetail.setSoAutoId(item.getCSOAutoID());
429
            shipmentDetail.setBatch("");
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
            shipmentDetails.add(shipmentDetail);
        }
        //调用公共API
        ShipmentDomain shipmentDomain = new ShipmentDomain();
        shipmentDomain.setShipmentHeader(shipmentHeader);
        shipmentDomain.setShipmentDetails(shipmentDetails);
        AjaxResult ajaxResult = shipmentApiService.shipment(shipmentDomain);
        if(!ajaxResult.hasErr() && !isFlag){
            U8Reference reference = new U8Reference();
            reference.setReferType(icsShipmentHeader.getType());
            reference.setReferCode(icsShipmentHeader.getReferCode());
            reference.setStock(icsShipmentHeader.getStock());
            reference.setCompanyCode(companyWu.getCompanyCode());
            reference.setWarehouseCode(currentWarehouseCode);
            reference.setTypeName(typeName);
            reference.setCreated(DateUtils.getNowDate());
            u8ReferenceService.save(reference);
        }
        if(ajaxResult.hasErr()){
            return ajaxResult;
        }
        String isNew = icsShipmentHeader.getIsNew();
        if("1".equals(isNew)){
            return AjaxResult.success("出库单下发成功");
        }else if ("0".equals(isNew)) {
            return AjaxResult.success("出库单更新成功");
        }else {
            return ajaxResult;
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
        }
    }



    //wms-u8出库回传

    /**
     * 出库单回传
     * @param url
     * @param status
     * @return
     */
    @Transactional
    public AjaxResult shipmentReturn(String url, Integer status) {
        //找出所有首状态为1000的出库单
        List<ShipmentHeader> shipmentHeaders = shipmentHeaderService.list(new LambdaQueryWrapper<ShipmentHeader>()
                .lt(ShipmentHeader::getFirstStatus, 1000));
        //获取code集合
        List<String> codeList = shipmentHeaders.stream().map(ShipmentHeader::getCode).collect(Collectors.toList());

        //先找出处于完成状态的taskDetail
        List<TaskDetail> taskDetails = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
                .eq(TaskDetail::getStatus, status)
                .eq(TaskDetail::getInternalTaskType, QuantityConstant.SHIPMENT_CONTAINER_FINISHED)
                .in(TaskDetail::getBillCode,codeList));

        if(taskDetails==null || taskDetails.size()<1){
tongzhonghao authored
486
            return AjaxResult.error("没有完成状态的子任务");
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
        }

        Set<String> billCodes = new HashSet<>();
        final List<String> collect = taskDetails.stream().map(t -> t.getBillCode()).distinct().collect(Collectors.toList());


        for(TaskDetail taskDetail:taskDetails) {
            ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
                    .eq(ShipmentHeader::getCode, taskDetail.getBillCode()));
            if(shipmentHeader==null){
                continue;
            }
            if(shipmentHeader!=null && shipmentHeader.getFirstStatus()== 1000){
                continue;
            }
            shipmentHeader.setFirstStatus(1000);
            //更新状态为1000
            shipmentHeaderService.updateById(shipmentHeader);
            //修改任务明细状态
            taskDetail.setStatus(200);
            taskDetailService.updateById(taskDetail);
        }
        return AjaxResult.success();
    }
512
tongzhonghao authored
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
    @Transactional
    public AjaxResult ConfirmShipment(TaskDetail taskDetail,String url,Integer status){
        String currentWarehouseCode = taskDetail.getWarehouseCode();
        AjaxResult ajaxResult=new AjaxResult();
        //根据子任务查找主单
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
                .eq(ShipmentHeader::getCode, taskDetail.getBillCode()));
        if(shipmentHeader==null){
            taskDetail.setStatus(QuantityConstant.TASK_STATUS_REMOVE);
            taskDetailService.updateById(taskDetail);
            return AjaxResult.success("出库单已删除");
        }
        //查找相同单号的状态为100的子任务
        List<TaskDetail> taskDetails = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
                .eq(TaskDetail::getStatus, status)
                .eq(TaskDetail::getBillCode, shipmentHeader.getCode()));
        if(taskDetails ==null || taskDetails.size()<1){
            return AjaxResult.success("已完成");
        }
        //查找相同单号状态为10的子任务
        List<TaskDetail> taskDetailList = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
                .eq(TaskDetail::getStatus, QuantityConstant.TASK_STATUS_RELEASE)
                .eq(TaskDetail::getBillCode, shipmentHeader.getCode()));

        if(taskDetailList!=null && taskDetailList.size()>0){
tongzhonghao authored
538
            return AjaxResult.error("该单据还有任务未完成,请先完成该单据的任务");
tongzhonghao authored
539
540
541
542
543
544
545
546
547
548
549
550
551
        }

        String type=shipmentHeader.getShipmentType();
        String code=shipmentHeader.getReferCode();

        if (!type.equals("PRO") && !type.equals("MO") && !type.equals("QO") && !type.equals("SO") ) {
            for(TaskDetail item :taskDetails) {
                item.setStatus(110);
                taskDetailService.updateById(item);
            }
            if (shipmentHeader.getFirstStatus() == 300 && shipmentHeader.getLastStatus() == 300) {
                shipmentHeaderService.removeShipmentByHeaderId(shipmentHeader.getId());
            }
tongzhonghao authored
552
            return AjaxResult.error("该子任务所属单据无需上传");
tongzhonghao authored
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
        }


        //根据子任务查找子单
        Set<String> uwarehouseCodes = new HashSet<>();
        List<ShipmentDetail> shipmentDetails=new ArrayList<>();
        Integer number =0;
        for(TaskDetail item:taskDetails) {
            ShipmentDetail shipmentDetail = shipmentDetailService.getById(item.getBillDetailId());

            if (shipmentDetails != null && shipmentDetails.size() > 0) {
                for (ShipmentDetail detail1 : shipmentDetails) {
                    if (shipmentDetail.getId() == detail1.getId()) {
                        detail1.setTaskQty(detail1.getTaskQty().add(item.getQty()));
                        number=1;
                        break;
                    }
                }
            }
            if(number == 0) {
                shipmentDetail.setTaskQty(item.getQty());
                shipmentDetails.add(shipmentDetail);
                uwarehouseCodes.add(shipmentDetail.getUWarehouseCode());
            }
            number=0;

        }

        Iterator<String> iterator=uwarehouseCodes.iterator();
        String uWarehouseCode=iterator.next();

        CompanyU8 companyWu = companyU8Service.getOne(new LambdaQueryWrapper<CompanyU8>()
                .eq(CompanyU8::getCompanyCode, shipmentHeader.getCompanyCode()));


        boolean isSameDate = icsReceiptAPIService.isSameMonth(taskDetail.getLastUpdated());

        if(isSameDate == false){
            for(TaskDetail item: taskDetails) {
                item.setStatus(180);
                taskDetailService.updateById(item);
            }
tongzhonghao authored
595
596
//            documentWarningService.ErpReturnWarning(shipmentHeader.getCode(), shipmentHeader.getReferCode(),
//                "回传超时" + shipmentHeader.getUserDef2());
tongzhonghao authored
597
            return AjaxResult.error("取消回传");
tongzhonghao authored
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
        }

        List<ICSShipmentDetail> icsShipmentDetails=new ArrayList<ICSShipmentDetail>();
        String dt = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS_S,taskDetail.getLastUpdated());
        String userName =taskDetail.getLastUpdatedBy();
        User user =new User();
        user = userService.selectUserByLoginName(userName);
        if(user != null){
            userName = user.getUserName();
        }
        ICSShipmentHeader icsShipmentHeader= null;
        //出库类型为采购的主单和子单
        switch (type){
            case "PRO":
                 icsShipmentHeader = icsShipmentHeaderService.getOne(new LambdaQueryWrapper<ICSShipmentHeader>()
                        .eq(ICSShipmentHeader::getCCode, code)
                        .eq(ICSShipmentHeader::getCompanyCode, companyWu.getUCompanyCode()));
                icsShipmentHeader.setDPODate(dt);
                icsShipmentHeader.setCWHCode(uWarehouseCode);
                icsShipmentHeader.setCMaker(userName);
                icsShipmentHeader.setID(shipmentHeader.getId());
                icsShipmentHeader.setVoucherType("CreateICSRdRecord_01_Return");

                //子单
                for(ShipmentDetail item:shipmentDetails) {
                    if (uWarehouseCode.equals(item.getUWarehouseCode())) {
                        ICSShipmentDetail icsShipmentDetail = icsShipmentDetailService.getOne(new LambdaQueryWrapper<ICSShipmentDetail>()
                                .eq(ICSShipmentDetail::getCCode, code)
                                .eq(ICSShipmentDetail::getCompanyCode, companyWu.getUCompanyCode())
                                .eq(ICSShipmentDetail::getCInvCode, item.getMaterialCode()));
                        icsShipmentDetail.setID(item.getId());
                        icsShipmentDetail.setIArrsId(icsShipmentDetail.getAutoID());
                        icsShipmentDetail.setIPOsID(icsShipmentDetail.getPODID());
                        icsShipmentDetail.setIQuantity(item.getQtyCompleted().negate());
                        icsShipmentDetails.add(icsShipmentDetail);
                    }
                }
                break;
            case "MO":
                icsShipmentHeader.setVoucherType("UpdateICSRdRecord_11_Confirm");
            case "QO":
                //出库类型为材料或其他的主单和子单
                 icsShipmentHeader = icsShipmentHeaderService.getOne(new LambdaQueryWrapper<ICSShipmentHeader>()
                        .eq(ICSShipmentHeader::getCCode, code)
                        .eq(ICSShipmentHeader::getCWHCode, shipmentHeader.getUWarehouseCode())
                        .eq(ICSShipmentHeader::getCompanyCode, companyWu.getUCompanyCode()));
                icsShipmentHeader.setDDate(dt);
                icsShipmentHeader.setCMaker(userName);
                icsShipmentHeader.setVoucherType("UpdateICSRdRecord_09_Confirm");
                for(ShipmentDetail item:shipmentDetails){

                    ICSShipmentDetail icsShipmentDetailA = icsShipmentDetailService.getOne(new LambdaQueryWrapper<ICSShipmentDetail>()
                            .eq(ICSShipmentDetail::getCCode, code)
                            .eq(ICSShipmentDetail::getCompanyCode, companyWu.getUCompanyCode())
tongzhonghao authored
652
                            .eq(ICSShipmentDetail::getAutoID, item.getAutoId()));
tongzhonghao authored
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
                    icsShipmentDetailA.setIQuantity(item.getTaskQty());
                    icsShipmentDetails.add(icsShipmentDetailA);
                }
                break;
            case "SO":
                icsShipmentHeader = icsShipmentHeaderService.getOne(new LambdaQueryWrapper<ICSShipmentHeader>()
                        .eq(ICSShipmentHeader::getCDLCode,code)
                        .eq(ICSShipmentHeader::getCompanyCode,companyWu.getUCompanyCode()));

                icsShipmentHeader.setDDate(dt);
                icsShipmentHeader.setCMaker(userName);
                icsShipmentHeader.setCWHCode(shipmentHeader.getUWarehouseCode());

                WarehouseU8 warehouseU8 = warehouseU8Service.getOne(new LambdaQueryWrapper<WarehouseU8>()
                        .eq(WarehouseU8::getUWarehouseCode, shipmentHeader.getUWarehouseCode())
                        .eq(WarehouseU8::getUCompanyCode, companyWu.getUCompanyCode()));
                icsShipmentHeader.setCWHName(warehouseU8.getUWarehouseName());
                icsShipmentHeader.setCCode(shipmentHeader.getSourceCode());
                icsShipmentHeader.setVoucherType("CreateICSRdRecord_32");
                icsShipmentHeader.setID(icsShipmentHeader.getDLID());
                for(ShipmentDetail item:shipmentDetails){

                    ICSShipmentDetail icsShipmentDetailB = icsShipmentDetailService.getOne(new LambdaQueryWrapper<ICSShipmentDetail>()
                            .eq(ICSShipmentDetail::getCCode, code)
                            .eq(ICSShipmentDetail::getCompanyCode, companyWu.getUCompanyCode())
                            .eq(ICSShipmentDetail::getCInvCode, item.getMaterialCode())
tongzhonghao authored
679
                            .eq(ICSShipmentDetail::getAutoID, item.getAutoId()));
tongzhonghao authored
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709

                    icsShipmentDetailB.setCCode(code);
                    icsShipmentDetailB.setID(icsShipmentDetailB.getDLID());
                    icsShipmentDetailB.setAutoID(icsShipmentDetailB.getAutoID());
                    icsShipmentDetailB.setIQuantity(item.getTaskQty());
                    icsShipmentDetails.add(icsShipmentDetailB);
                }
                break;
        }


        if(type.equals("MO")){
            icsShipmentHeader.setVoucherType("UpdateICSRdRecord_11_Confirm");
        }
        if(type.equals("QO")){
            icsShipmentHeader.setVoucherType("UpdateICSRdRecord_09_Confirm");
        }

        ICSShipmentModel model = new ICSShipmentModel();
        model.setIcsShipmentHeader(icsShipmentHeader);
        model.setIcsShipmentDetails(icsShipmentDetails);
        String JsonParam = JSON.toJSONString(model);
        String result = HttpUtils.bodypost(url, JsonParam,currentWarehouseCode);
        if(StringUtils.isEmpty(result)){
            throw new ServiceException("接口地址错误或服务器连接不到或返回为空");
        }
        ajaxResult = JSON.parseObject(result, AjaxResult.class);
        if (ajaxResult.getCode() ==200 || ajaxResult.getCode() == 400) {
tongzhonghao authored
710
            if(shipmentHeader.getShipmentType().equals(QuantityConstant.U8_SHIPMENT_TYPE_SO) || shipmentHeader.getShipmentType().equals(QuantityConstant.U8_SHIPMENT_TYPE_PRO)){
tongzhonghao authored
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
                shipmentHeader.setUserDef2(ajaxResult.getMsg());
                shipmentHeaderService.updateById(shipmentHeader);
            }

            for(TaskDetail item: taskDetails) {
                item.setStatus(120);
                taskDetailService.updateById(item);
            }

            /**
             *  生成快递单
             *  1U8返回值为200
             *  2wms出库单快递信息存在
             *  3、存在就生成快递单
             *
             */
//            if(ajaxResult.getCode() == 200 && shipmentHeader.getKdEable() == 1){
//                AjaxResult ajaxResult1 = kuaidiHeaderService.saveKD(shipmentDetails,shipmentHeader,ajaxResult.getMsg());
//            }

            if(ajaxResult.getCode() == 400) {
tongzhonghao authored
732
//                documentWarningService.ErpReturnWarning(shipmentHeader.getCode(), shipmentHeader.getSourceCode(), ajaxResult.getMsg());
tongzhonghao authored
733
734
            }
tongzhonghao authored
735
            if (shipmentHeader.getFirstStatus() == QuantityConstant.SHIPMENT_HEADER_GROUPDISK && shipmentHeader.getLastStatus() != QuantityConstant.SHIPMENT_HEADER_GROUPDISK) {
tongzhonghao authored
736
737
738
739
740
741
742
743
744
                shipmentHeader.setUploadStatus(15);
                shipmentHeaderService.updateById(shipmentHeader);
            }
            TaskDetail condition = new TaskDetail();
            condition.setBillCode(shipmentHeader.getCode());

            //select  * from task_detail where billCode = #{billCode} and billId = #{billId} and (status &lt;= 100 or status = 150 or status= 160)
            LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
            queryWrapper.eq(TaskDetail::getBillCode,shipmentHeader.getCode())
tongzhonghao authored
745
                    .lt(TaskDetail::getStatus,QuantityConstant.TASK_STATUS_COMPLETED)
tongzhonghao authored
746
                    .or()
tongzhonghao authored
747
                    .eq(TaskDetail::getStatus,QuantityConstant.TASK_STATUS_COMPLETED)
tongzhonghao authored
748
749
750
751
752
                    .or()
                    .eq(TaskDetail::getStatus,150)
                    .or()
                    .eq(TaskDetail::getStatus,160);
            List<TaskDetail> taskDetails1 = taskDetailService.list(queryWrapper);
tongzhonghao authored
753
754
755
            if (shipmentHeader.getFirstStatus() == QuantityConstant.SHIPMENT_HEADER_GROUPDISK && shipmentHeader.getLastStatus() == QuantityConstant.SHIPMENT_HEADER_GROUPDISK && taskDetails1.isEmpty()) {
                shipmentHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
                shipmentHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_RETURN);
tongzhonghao authored
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
                shipmentHeader.setUploadStatus(20);
                shipmentHeaderService.updateById(shipmentHeader);
            }
        }

        if(ajaxResult.getCode() == 300){
            shipmentHeader.setUserDef2(ajaxResult.getMsg());
            shipmentHeaderService.updateById(shipmentHeader);
            for(TaskDetail item: taskDetails) {
                item.setStatus(160);
                taskDetailService.updateById(item);
            }
        }
        return ajaxResult;

    }
774
775
776
777
778

    /**
          * 判断出库单是否可以更新
          * @param code U8单号
          */
tongzhonghao authored
779
    private void checkShipmentBill(boolean isFlag,String code,String type){
780
        //U8单据类型
tongzhonghao authored
781
        LambdaQueryWrapper<ShipmentHeader> queryWrapper = Wrappers.lambdaQuery();
tongzhonghao authored
782
783
        queryWrapper.eq(ShipmentHeader::getReferCode,code)
                .eq(ShipmentHeader::getShipmentType,type);
tongzhonghao authored
784
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(queryWrapper);
785
786

        //WMS出库单 和 U8出库单 都不能为空 才能更新
tongzhonghao authored
787
788
        if (isFlag) {
            if(shipmentHeader!=null){
789
790
791
792
                if(StringUtils.isNotNull(shipmentHeader) ){
                    //找出 出库单未完成的任务
                    List<TaskDetail> taskDetailList = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
                            .eq(TaskDetail::getBillCode, shipmentHeader.getCode())
tongzhonghao authored
793
                            .le(TaskDetail::getStatus,100));
794
                    if(taskDetailList!=null&&taskDetailList.size()>0){
tongzhonghao authored
795
                        throw  new ServiceException("更新失敗,此出库单存在任务");
796
797
798
799
                    }
                    //找出库配盘明细 未配盘的单据
                    List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.list(new LambdaQueryWrapper<ShipmentContainerDetail>()
                            .eq(ShipmentContainerDetail::getShipmentCode, shipmentHeader.getCode())
tongzhonghao authored
800
                            .le(ShipmentContainerDetail::getStatus, QuantityConstant.SHIPMENT_CONTAINER_FINISHED));
801
802

                    if(shipmentContainerDetails!=null&&shipmentContainerDetails.size()>0){
tongzhonghao authored
803
                        throw  new ServiceException("更新失敗,此出库单已组盘");
804
805
806
807
808
809
810
811
                    }
                    //删除wms出库单头表
                    shipmentHeaderService.removeById(shipmentHeader.getId());
                    //删除wms出库单明细表
                    shipmentDetailService.remove(new LambdaQueryWrapper<ShipmentDetail>()
                            .eq(ShipmentDetail::getShipmentCode,shipmentHeader.getCode()));
                }
            }
tongzhonghao authored
812
813
814
815
816
817
818
819
            ICSShipmentHeader icsShipmentHeader = icsShipmentHeaderService.getOne(new LambdaQueryWrapper<ICSShipmentHeader>()
                    .eq(ICSShipmentHeader::getReferCode, code)
                    .eq(ICSShipmentHeader::getType, type));
            if(icsShipmentHeader!=null){
                icsShipmentHeaderService.removeById(icsShipmentHeader.getSId());
                icsShipmentDetailService.remove(new LambdaQueryWrapper<ICSShipmentDetail>()
                        .eq(ICSShipmentDetail::getHeaderId,icsShipmentHeader.getSId()));
            }
tongzhonghao authored
820
821
822
823
824
825
826
827
828
829
        }
    }

    private ICSShipmentModel assign(ICSShipmentModel icsShipmentModel){
        ICSShipmentHeader header = icsShipmentModel.getIcsShipmentHeader();
        List<ICSShipmentDetail> details = icsShipmentModel.getIcsShipmentDetails();
        String type = header.getType();
        Date created = null;
        if(header.getDDate() !=null){
            try {
830
                created = DateUtils.parseDate(header.getDDate(),DateUtils.YYYY_MM_DD_HH_MM_SS);
tongzhonghao authored
831
832
            } catch (ParseException e) {
                e.printStackTrace();
833
834
            }
        }
tongzhonghao authored
835
836
837
838
839
        switch (type){
            case "MO" :
                header.setReferId(header.getID());
                header.setReferCode(header.getCCode());
                header.setCreated(created);
840
                header.setStock(header.getCWHCode());
tongzhonghao authored
841
842
843
844
845
                for (ICSShipmentDetail detail : details) {
                    detail.setReferId(detail.getAutoID());
                    detail.setReferCode(detail.getPOCode());
                }
                break;
846
            case "SO" :
tongzhonghao authored
847
848
                header.setReferId(header.getDLID());
                header.setReferCode(header.getCDLCode());
849
850
851
852
853
854
                try {
                    header.setCreated(DateUtils.parseDate(header.getDPODate(),DateUtils.YYYY_MM_DD_HH_MM_SS_S));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                String stock = "";
tongzhonghao authored
855
                stock = header.getCWHCode();
tongzhonghao authored
856
                for (ICSShipmentDetail detail : details) {
857
858
                    detail.setReferId(detail.getAutoID());
                    detail.setReferCode(detail.getPOCode());
tongzhonghao authored
859
860
861
                    if(StringUtils.isEmpty(stock)){
                        stock = detail.getCWHCode();
                    }
tongzhonghao authored
862
                }
863
                header.setStock(stock);
tongzhonghao authored
864
                break;
865
            case "OO" :
tongzhonghao authored
866
                header.setIsFlag(false);
867
868
869
870
871
872
873
874
875
                header.setStock("20");
                header.setCreated(created);
                header.setReferId(header.getMoId());
                header.setReferCode(header.getMoCode());
                for (ICSShipmentDetail detail : details) {
                    detail.setCWHCode("20");
                    detail.setReferId(detail.getMoDId());
                    detail.setAutoID(detail.getMoDId());
                }
tongzhonghao authored
876
                break;
877
878
879
880
881
882
            case "PRO" :
                try {
                    header.setCreated(DateUtils.parseDate(header.getDPODate(),DateUtils.YYYY_MM_DD_HH_MM_SS_S));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
883
884
885
886
887
888
889
890
891
                header.setReferId(header.getID());
                header.setReferCode(header.getCCode());
                String stock1 = "";
                for (ICSShipmentDetail detail : details) {
                    stock1 = detail.getCWHCode();
                    detail.setPOCode(detail.getPOCode());
                    detail.setPODID(detail.getPODID());
                    detail.setPOID(detail.getPOID());
                }
tongzhonghao authored
892
                header.setStock(stock1);
893
                header.setCWHCode(stock1);
tongzhonghao authored
894
895
896
897
898
899
900
901
902
903
904
905
906
                break;
        }
        icsShipmentModel.setIcsShipmentHeader(header);
        icsShipmentModel.setIcsShipmentDetails(details);
        return icsShipmentModel;
    }

    private String getShipmentTypeName(String code){
        String typeName = "";
        switch (code){
            case "MO" :
                typeName = "生产领料";
                break;
907
908
909
            case "SO" :
                typeName = "普通销售";
                break;
tongzhonghao authored
910
            case "OO" :
911
                typeName = "生产订单";
tongzhonghao authored
912
913
914
                break;
        }
        return typeName;
915
916
917
    }

}