Blame view

src/main/java/com/huaheng/pc/shipment/shipmentHeader/service/ShipmentHeaderServiceImpl.java 24.5 KB
tangying authored
1
2
package com.huaheng.pc.shipment.shipmentHeader.service;
tongzhonghao authored
3
import com.alibaba.fastjson.JSON;
mahuandong authored
4
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
tongzhonghao authored
5
import com.huaheng.common.utils.DateUtils;
周鸿 authored
6
import com.huaheng.common.utils.Wrappers;
mahuandong authored
7
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
mahuandong authored
8
9
10
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
11
import com.huaheng.common.utils.StringUtils;
tongzhonghao authored
12
import com.huaheng.common.utils.http.HttpUtils;
mahuandong authored
13
import com.huaheng.common.utils.security.ShiroUtils;
tongzhonghao authored
14
import com.huaheng.framework.aspectj.ApiLogAspect;
mahuandong authored
15
import com.huaheng.framework.web.domain.AjaxResult;
tongzhonghao authored
16
import com.huaheng.pc.config.address.service.AddressService;
mahuandong authored
17
import com.huaheng.pc.config.company.service.CompanyService;
18
19
import com.huaheng.pc.config.customer.domain.Customer;
import com.huaheng.pc.config.customer.service.CustomerServiceImpl;
mahuandong authored
20
import com.huaheng.pc.config.material.service.MaterialService;
21
import com.huaheng.pc.config.shipmentType.service.ShipmentTypeService;
tongzhonghao authored
22
23
import com.huaheng.pc.monitor.apilog.domain.ApiLog;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
游杰 authored
24
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
周鸿 authored
25
import com.huaheng.pc.shipment.lockingWorkOrder.domain.LockingWorkOrder;
mahuandong authored
26
27
28
29
30
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentDetailHistory.domain.ShipmentDetailHistory;
import com.huaheng.pc.shipment.shipmentDetailHistory.service.ShipmentDetailHistoryService;
mahuandong authored
31
32
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.mapper.ShipmentHeaderMapper;
mahuandong authored
33
34
35
import com.huaheng.pc.shipment.shipmentHeaderHistory.domain.ShipmentHeaderHistory;
import com.huaheng.pc.shipment.shipmentHeaderHistory.service.ShipmentHeaderHistoryService;
import com.huaheng.pc.system.dict.service.IDictDataService;
36
37
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
tongzhonghao authored
38
import com.huaheng.pc.u8.domain.*;
39
40
import com.huaheng.pc.u8.service.ICSShipmentDetailService;
import com.huaheng.pc.u8.service.ICSShipmentHeaderService;
mahuandong authored
41
42
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
tongzhonghao authored
43
import org.springframework.http.HttpHeaders;
tangying authored
44
import org.springframework.stereotype.Service;
mahuandong authored
45
46
import org.springframework.transaction.annotation.Transactional;
tangying authored
47
import javax.annotation.Resource;
mahuandong authored
48
import java.lang.reflect.InvocationTargetException;
tongzhonghao authored
49
import java.math.BigDecimal;
mahuandong authored
50
51
52
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
mahuandong authored
53
import java.util.List;
mahuandong authored
54
import java.util.Map;
55
import java.util.stream.Collectors;
mahuandong authored
56
tangying authored
57
@Service
mahuandong authored
58
public class ShipmentHeaderServiceImpl extends ServiceImpl<ShipmentHeaderMapper, ShipmentHeader> implements ShipmentHeaderService{
tangying authored
59
mahuandong authored
60
61
62
63
64
65
66
67
68
69
70
71
    @Autowired
    private IDictDataService dictDataService;
    @Resource
    private ShipmentHeaderMapper shipmentHeaderMapper;
    @Autowired
    private ShipmentDetailService shipmentDetailService;
    @Autowired
    private ShipmentContainerHeaderService shipmentContainerHeaderService;
    @Autowired
    private ShipmentHeaderHistoryService shipmentHeaderHistoryService;
    @Autowired
    private ShipmentDetailHistoryService shipmentDetailHistoryService;
mahuandong authored
72
73
74
    @Resource
    private CompanyService companyService;
    @Resource
75
76
    private CustomerServiceImpl customerService;
    @Resource
mahuandong authored
77
    private MaterialService materialService;
78
79
    @Resource
    private ShipmentTypeService shipmentTypeService;
80
81
82
83
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
tongzhonghao authored
84
85
    @Resource
    private AddressService addressService;
86
87
88
89
    @Resource
    private ICSShipmentHeaderService icsShipmentHeaderService;
    @Resource
    private ICSShipmentDetailService icsShipmentDetailService;
mahuandong authored
90
91
92
93

    //新增出库主单
    @Override
    public AjaxResult<Boolean> saveHeader(ShipmentHeader shipmentHeader) {
94
95

        if(shipmentTypeService.checkCode(shipmentHeader.getShipmentType()) == false)
mahuandong authored
96
97
98
99
100
101
102
103
104
105
106
107
108
        {
            return  AjaxResult.error("没有对应的出库单类型");
        }
        String code = createCode(shipmentHeader.getShipmentType());
        shipmentHeader.setId(null);
        shipmentHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_BUILD);
        shipmentHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_BUILD);
        shipmentHeader.setLastUpdated(null);
        shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        shipmentHeader.setCreated(null);
        shipmentHeader.setCreatedBy(ShiroUtils.getLoginName());
        shipmentHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
        shipmentHeader.setCode(code);
109
        shipmentHeader.setUWarehouseCode(shipmentHeader.getUWarehouseCode());
110
111
112
113
114
115
116
117
        if(StringUtils.isNotEmpty(shipmentHeader.getCustomerCode())){
            LambdaQueryWrapper<Customer> customerLambd = Wrappers.lambdaQuery();
            customerLambd.eq(Customer::getCode,shipmentHeader.getCustomerCode());
            Customer customer =customerService.getOne(customerLambd);
            if(customer == null){
                return AjaxResult.error("客户编码错误,wms系统没有此客户");
            }
        }
mahuandong authored
118
119
120
121
122
123
        boolean result = this.save(shipmentHeader);
        return  AjaxResult.toAjax(result);
    }


    //根据单据类型建单据号
mahuandong authored
124
    @Override
mahuandong authored
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
    public String createCode(String shipmentType)
    {
        String code = null;
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        String maxCode = shipmentHeaderMapper.createCode(shipmentType);
        if (maxCode != null && maxCode.length() > 13 && maxCode.substring(maxCode.length() - 13, maxCode.length() - 5).equals(df.format(now)))
        {
            Integer Count = Integer.valueOf(maxCode.substring(maxCode.length() - 5, maxCode.length()));
            code = shipmentType + df.format(now) + String.format("%05d", Count + 1);
        }
        else
        {
            code = shipmentType + df.format(now) + "00001";
        }
        return code;
    }

    /**
     * 根据Id更新这个单据的首尾状态
     * @param shipmentId
     * @return
     */
    @Override
    public AjaxResult updateShipmentStatus(int shipmentId)  {
        //获取这个单
        ShipmentHeader shipmentHeader = this.getById(shipmentId);
        if(shipmentHeader==null){
            return AjaxResult.error("单据未找到,Id:"+shipmentId);
        }
        //查询是否有生成出库货箱,如果有,则返回出库货箱的最高与最低状态
        Map<String,Integer> map = shipmentContainerHeaderService.getShipmentContainerMaxAndMinStatusByShipmentID(shipmentId);
        if(map==null){
            //说明没有货箱,则直接首位均为新建
            shipmentHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_POOL);
            shipmentHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_POOL);

            this.saveOrUpdate(shipmentHeader);
        }else {
            int firstStatus = map.get("maxStatus");
            int lastStatus = map.get("minStatus");
            if(firstStatus<=QuantityConstant.SHIPMENT_CONTAINER_FINISHED){
                shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_GROUPDISK);
            }
            if(firstStatus==QuantityConstant.SHIPMENT_CONTAINER_REVIEWSUCCESS){
                shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
            }
            if(lastStatus <=QuantityConstant.SHIPMENT_CONTAINER_FINISHED){
                shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_GROUPDISK);
            }
            if(lastStatus==QuantityConstant.SHIPMENT_CONTAINER_REVIEWSUCCESS){
                shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
            }
            //是否存在未配盘的数量,如果是,则尾状态为新建
            Integer UnCompleted = shipmentDetailService.countUnCompleted(shipmentId);
            if(UnCompleted != null && UnCompleted.intValue() > 0){
                shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_POOL);
            }
            this.saveOrUpdate(shipmentHeader);
        }

        return AjaxResult.success("");

    }

    //出库单字段变为历史出库单
    @Override
    @Transactional
    public AjaxResult addHistory(ShipmentHeader shipmentHeader) throws InvocationTargetException, IllegalAccessException {
pengcheng authored
194
195
        //单据主单重复
        LambdaQueryWrapper<ShipmentHeaderHistory> headerHistoryLamb = Wrappers.lambdaQuery();
lector authored
196
        headerHistoryLamb.eq(ShipmentHeaderHistory::getCode,shipmentHeader.getCode())
pengcheng authored
197
                        .eq(ShipmentHeaderHistory::getWarehouseCode,shipmentHeader.getWarehouseCode());
mahuandong authored
198
pengcheng authored
199
200
201
202
        ShipmentHeaderHistory headerHistory =shipmentHeaderHistoryService.getOne(headerHistoryLamb);
        if(headerHistory == null) {
            //历史出库主单
            ShipmentHeaderHistory shipmentHeaderHistory = new ShipmentHeaderHistory();
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//            BeanUtils.copyProperties(shipmentHeaderHistory, shipmentHeader);
            shipmentHeaderHistory.setId(shipmentHeader.getId());
            shipmentHeaderHistory.setWarehouseCode(shipmentHeader.getWarehouseCode());
            shipmentHeaderHistory.setCarrierCode(shipmentHeader.getCarrierCode());
            shipmentHeaderHistory.setCode(shipmentHeader.getCode());
            shipmentHeaderHistory.setReferCode(shipmentHeader.getReferCode());
            shipmentHeaderHistory.setReferPlatform(shipmentHeader.getFirstStatus());
            shipmentHeaderHistory.setFirstStatus(shipmentHeader.getId());
            shipmentHeaderHistory.setLastStatus(shipmentHeader.getId());
            shipmentHeaderHistory.setShipmentType(shipmentHeader.getShipmentType());
            shipmentHeaderHistory.setTotalQty(shipmentHeader.getTotalQty());
            shipmentHeaderHistory.setTotalLines(shipmentHeader.getTotalLines());
            shipmentHeaderHistory.setLastWaveId(shipmentHeader.getLastWaveId());
            shipmentHeaderHistory.setCreated(shipmentHeader.getCreated());
            shipmentHeaderHistory.setCreatedBy(shipmentHeader.getCreatedBy());
            shipmentHeaderHistory.setLastUpdated(shipmentHeader.getLastUpdated());
            shipmentHeaderHistory.setLastUpdatedBy(shipmentHeader.getLastUpdatedBy());
            shipmentHeaderHistory.setVersion(shipmentHeader.getVersion());
            shipmentHeaderHistory.setDeleted(shipmentHeader.getDeleted());
            shipmentHeaderHistory.setCompanyCode(shipmentHeader.getCompanyCode());
pengcheng authored
223
224
225
            if (shipmentHeaderHistoryService.save(shipmentHeaderHistory) == false) {
                throw new ServiceException("存入历史出库主单失败");
            }
mahuandong authored
226
        }
pengcheng authored
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
            LambdaQueryWrapper<ShipmentDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
            lambdaQueryWrapper.eq(ShipmentDetail::getWarehouseCode, shipmentHeader.getWarehouseCode())
                    .eq(ShipmentDetail::getShipmentCode, shipmentHeader.getCode());
            List<ShipmentDetail> shipmentDetails = shipmentDetailService.list(lambdaQueryWrapper);

            //历史出库子单
            List<ShipmentDetailHistory> shipmentDetailHistories = new ArrayList<>();
            for (ShipmentDetail item : shipmentDetails) {
                ShipmentDetailHistory shipmentDetailHistory = new ShipmentDetailHistory();
                BeanUtils.copyProperties(shipmentDetailHistory, item);
                shipmentDetailHistories.add(shipmentDetailHistory);
            }
            Boolean flag = shipmentDetailHistoryService.saveBatch(shipmentDetailHistories);
            if (flag == false) {
                throw new ServiceException("存入历史出库子单失败");
            }
mahuandong authored
243
244
245
246
247
248
249
250
251
252
253
254
255
        return null;
    }

    /**审核出库单,加入订单池
     * 1、找到主单,确定主单的状态是否小于100
     * 2.小于100时,把主单和相应的子单加入到list中,大于等于100时,直接跳过
     * 3.将修改后的主单列表和子单列表进行修改,加入订单池
     *
     * @param ids
     * @return
     */

    @Override
256
    @Transactional
mahuandong authored
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
    public AjaxResult review(String ids) {

        List<ShipmentHeader> shipmentHeaders = new ArrayList<>();
        List<ShipmentDetail> shipmentDetails = new ArrayList<>();

        //1、找到主单,确定主单的状态是否小于100
        for (Integer id : Convert.toIntArray(ids)){
            ShipmentHeader shipmentHeader = this.getById(id);
            if(shipmentHeader == null){
                return AjaxResult.error("id为"+id+"的主单在系统不存在");
            }

            //2.小于100时,把主单和相应的子单加入到list中,大于等于100时,直接跳过
            if(shipmentHeader.getFirstStatus() < QuantityConstant.SHIPMENT_HEADER_POOL && shipmentHeader.getLastStatus() <QuantityConstant.SHIPMENT_HEADER_POOL){
                shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_POOL);
                shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_POOL);
                shipmentHeaders.add(shipmentHeader);

                LambdaQueryWrapper<ShipmentDetail> lam = Wrappers.lambdaQuery();
                lam.eq(ShipmentDetail::getShipmentId,id)
                        .eq(ShipmentDetail::getWarehouseCode,ShiroUtils.getWarehouseCode());
                List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(lam);
279
                if(!shipmentDetailList.isEmpty()){
mahuandong authored
280
281
282
283
284
285
286
287
288
289
                    for(ShipmentDetail shipmentDetail : shipmentDetailList){
                        shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_POOL);
                    }
                    shipmentDetails.addAll(shipmentDetailList);
                }else {
                    return AjaxResult.error("id为"+id+"的出库明细在系统不存在");
                }
            }
        }
pengcheng authored
290
291
292
293
294
295
        if(shipmentHeaders.isEmpty()){
            return AjaxResult.error("选中的单据不需要订单审核");
        }
        if(shipmentDetails.isEmpty()){
            return AjaxResult.error("选中的单据不需要订单审核或没有子单");
        }
mahuandong authored
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
        // 3.将修改后的主单列表和子单列表进行修改,加入订单池
        Boolean flag = this.updateBatchById(shipmentHeaders);
        if (flag == false){
            throw new ServiceException("修改主单状态失败");
        }
        flag = shipmentDetailService.updateBatchById(shipmentDetails);
        if (flag == false){
            throw new ServiceException("修改明细状态失败");
        }
        return AjaxResult.success("订单审核成功,成功加入订单池");
    }

    @Override
    public List<ShipmentHeader> selectListByCreated() {
        return shipmentHeaderMapper.selectListByCreated();
    }
mahuandong authored
312
游杰 authored
313
314
315
316
317
318
    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<ShipmentHeader> getLatestShipment() {
        return shipmentHeaderMapper.getLatestShipment();
    }
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
    @Override
    public AjaxResult removeShipmentByHeaderId(Integer headerId) {
        if(headerId!=null && headerId != 0){
            return AjaxResult.error();
        }
        ShipmentHeader shipmentHeader = this.getById(headerId);
        if (shipmentHeader == null) {
            return AjaxResult.success("");
        }
        LambdaQueryWrapper<TaskDetail> queryWrapper = com.baomidou.mybatisplus.core.toolkit.Wrappers.lambdaQuery();
        queryWrapper.eq(TaskDetail::getBillCode,shipmentHeader.getCode())
                .gt(TaskDetail::getStatus,QuantityConstant.TASK_STATUS_RELEASE);
        List<TaskDetail> taskDetails = taskDetailService.list(queryWrapper);
        if (!taskDetails.isEmpty()) {
            throw new ServiceException("此单据存在任务,无法删除");
        }
        ShipmentHeaderHistory shh = shipmentHeaderHistoryService.getOne(new LambdaQueryWrapper<ShipmentHeaderHistory>()
                .eq(ShipmentHeaderHistory::getCode, shipmentHeader.getCode()));

        List<ShipmentDetailHistory> shipmentDetailHistories = new ArrayList<>();

        List<ShipmentDetail> list = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>()
                .eq(ShipmentDetail::getShipmentId, headerId));
        ShipmentHeaderHistory shipmentHeaderHistory = new ShipmentHeaderHistory();

        try {
            //复制到出库历史实体
            if (list != null && list.size() > 0) {
                BeanUtils.copyProperties(shipmentHeaderHistory, shipmentHeader);
                for (ShipmentDetail item : list) {
                    ShipmentDetailHistory shipmentDetailHistory = new ShipmentDetailHistory();
                    BeanUtils.copyProperties(shipmentDetailHistory, item);
                    shipmentDetailHistories.add(shipmentDetailHistory);
                }
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        boolean b = shipmentHeaderService.removeById(shipmentHeader.getId());
        if (!b) {
            throw new ServiceException("删除头表失败");
        }
        if (list != null && list.size() > 0 && shh == null) {
            boolean save = shipmentHeaderHistoryService.save(shipmentHeaderHistory);
            if (!save) {
                throw new ServiceException("新增历史出库单失败");
            }
        }
        // 当存在明细时删除
        if (list != null && list.size() > 0) {
            //删除出库明细
            if (shh == null) {
                for (int i = 0; i < shipmentDetailHistories.size(); i++) {
                    shipmentDetailHistories.get(i).setShipmentId(shipmentHeaderHistory.getId());
                }
            } else {
                for (int i = 0; i < shipmentDetailHistories.size(); i++) {
                    shipmentDetailHistories.get(i).setShipmentId(shh.getId());
                }
            }
            List<Integer> collect = list.stream().map(ShipmentDetail::getId).collect(Collectors.toList());
            if (!shipmentDetailService.removeByIds(collect)) {
                throw new ServiceException("删除明细表失败");
            }
            if (!shipmentDetailHistoryService.saveBatch(shipmentDetailHistories)) {
                throw new ServiceException("新增明细失败");
            }
        }
        return AjaxResult.success("删除成功");
    }
周鸿 authored
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424

    @Override
    public ShipmentHeader createShipmentHeader(LockingWorkOrder lockingWorkOrder) {
        ShipmentHeader shipmentHeader = new ShipmentHeader();
        // 公司编码
        shipmentHeader.setCompanyCode(ShiroUtils.getCompanyCode());
        // 公司id
//        shipmentHeader.setCompanyId(QuantityConstant.COMPANYID);
        // 出库单类型
        shipmentHeader.setShipmentType("PO");
        // 发货站台
        shipmentHeader.setStation("102");
        // 是否启用
        shipmentHeader.setEnable(1);
        String code = createCode(shipmentHeader.getShipmentType());
        shipmentHeader.setId(null);
        shipmentHeader.setLastUpdated(null);
        // 更新用户
        shipmentHeader.setLastUpdatedBy("mms");
        // 创建时间
        shipmentHeader.setCreated(new Date());
        // 创建人
        shipmentHeader.setCreatedBy("mms");
//        shipmentHeader.setWarehouseId(ShiroUtils.getWarehouseId());
        shipmentHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
        shipmentHeader.setCode(code);
        shipmentHeader.setUploadStatus(0);
        if (this.save(shipmentHeader)){
            return shipmentHeader;
        }
        return null;
    }
tongzhonghao authored
425
426
    @Override
    public AjaxResult postBack(String id, Map<Integer, BigDecimal> detailsQtyMap){
427
        AjaxResult ajaxResult = AjaxResult.success();
tongzhonghao authored
428
429
430
431
        ShipmentHeader shipmentHeader = this.getById(id);
        if(shipmentHeader==null){
            return AjaxResult.error("回传:入库单"+id+" 不存在。");
        }
432
        String warehouseCode = shipmentHeader.getWarehouseCode();
tongzhonghao authored
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
        //获取当前时间
        String nowDateStr = DateUtils.getNowDateString(DateUtils.YYYY_MM_DD_HH_MM_SS);
        String type = shipmentHeader.getShipmentType();
        ICSShipmentModel model = null;
        switch (type){
            case "MO" :
                model = postBackByMO(shipmentHeader,type,detailsQtyMap);
                break;
            case "OO" :
                model = postBackByOO(shipmentHeader,type,detailsQtyMap);
                break;
            case "PRO" :
                model = postBackByPRO(shipmentHeader,type,detailsQtyMap);
                break;
            case "SO" :
                model = postBackBySO(shipmentHeader,type,detailsQtyMap);
                break;
        }
        String JsonParam = JSON.toJSONString(model);
452
        String url = addressService.selectAddress(QuantityConstant.U8_SHIPMENT_BACK, warehouseCode);
tongzhonghao authored
453
454
455
456
457
458

        String msg = "";
        ApiLog log = null;
        HttpHeaders headers = new HttpHeaders();
        try {
            log = ApiLogAspect.initApiLog("post", url,
459
460
                    JsonParam, headers, warehouseCode);
            String result = HttpUtils.bodypost(url, JsonParam,warehouseCode);
tongzhonghao authored
461
462
463
            if(StringUtils.isEmpty(result)){
                throw new ServiceException("接口地址错误或服务器连接不到或返回为空");
            }
464
            ajaxResult = JSON.parseObject(result, AjaxResult.class);
tongzhonghao authored
465
466
467
468
469
470
        }catch (Exception e) {
            e.printStackTrace();
            ApiLogAspect.setApiLogException(log, e);
        } finally {
            ApiLogAspect.finishApiLog(log, headers, msg);
        }
471
        return ajaxResult;
tongzhonghao authored
472
473
474
475
476
477
478
    }

    private ICSShipmentModel postBackByMO(ShipmentHeader shipmentHeader, String type, Map<Integer,BigDecimal> detailsQtyMap){
        ICSShipmentModel model = new ICSShipmentModel();
        if(!type.equals(QuantityConstant.U8_SHIPMENT_TYPE_MO)){
            return model;
        }
479
480
481
482
483
        List<ShipmentDetail> shipmentDetails = shipmentDetailService.getListByShipmentHeaderId(shipmentHeader.getId(), shipmentHeader.getWarehouseCode());
        ICSShipmentHeader icsShipmentHeader = icsShipmentHeaderService.getHeaderByMO(shipmentHeader);
        List<ICSShipmentDetail> details = icsShipmentDetailService.getDetailsByMO(shipmentDetails, icsShipmentHeader, detailsQtyMap);
        model.setIcsShipmentHeader(icsShipmentHeader);
        model.setIcsShipmentDetails(details);
tongzhonghao authored
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
        return model;
    }

    private ICSShipmentModel postBackByOO(ShipmentHeader shipmentHeader,String type,Map<Integer,BigDecimal> detailsQtyMap){
        ICSShipmentModel model = new ICSShipmentModel();
        if(!type.equals(QuantityConstant.U8_SHIPMENT_TYPE_OO)){
            return model;
        }
        ICSShipmentHeader icsShipmentHeader = new ICSShipmentHeader();
        return model;
    }
    private ICSShipmentModel postBackByPRO(ShipmentHeader shipmentHeader,String type,Map<Integer,BigDecimal> detailsQtyMap){
        ICSShipmentModel model = new ICSShipmentModel();
        if(!type.equals(QuantityConstant.U8_SHIPMENT_TYPE_PRO)){
            return model;
        }
500
501
502
503
504
        List<ShipmentDetail> shipmentDetails = shipmentDetailService.getListByShipmentHeaderId(shipmentHeader.getId(), shipmentHeader.getWarehouseCode());
        ICSShipmentHeader icsShipmentHeader = icsShipmentHeaderService.getHeaderByPRO(shipmentHeader);
        List<ICSShipmentDetail> details = icsShipmentDetailService.getDetailsByPRO(shipmentDetails, icsShipmentHeader, detailsQtyMap);
        model.setIcsShipmentHeader(icsShipmentHeader);
        model.setIcsShipmentDetails(details);
tongzhonghao authored
505
506
507
508
509
510
511
        return model;
    }
    private ICSShipmentModel postBackBySO(ShipmentHeader shipmentHeader,String type,Map<Integer,BigDecimal> detailsQtyMap){
        ICSShipmentModel model = new ICSShipmentModel();
        if(!type.equals(QuantityConstant.U8_SHIPMENT_TYPE_SO)){
            return model;
        }
512
513
514
515
516
        List<ShipmentDetail> shipmentDetails = shipmentDetailService.getListByShipmentHeaderId(shipmentHeader.getId(), shipmentHeader.getWarehouseCode());
        ICSShipmentHeader icsShipmentHeader = icsShipmentHeaderService.getHeaderBySO(shipmentHeader);
        List<ICSShipmentDetail> details = icsShipmentDetailService.getDetailsBySO(shipmentDetails, icsShipmentHeader, detailsQtyMap);
        model.setIcsShipmentHeader(icsShipmentHeader);
        model.setIcsShipmentDetails(details);
tongzhonghao authored
517
518
519
520
        return model;
    }
tangying authored
521
}