Blame view

src/main/java/com/huaheng/api/mes/controller/MesReceiptController.java 28 KB
hh authored
1
2
package com.huaheng.api.mes.controller;
hh authored
3
4
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
hh authored
5
6
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
7
8
9
import com.huaheng.api.mes.dto.*;
import com.huaheng.api.mes.dto.otherReceipt.OtherReceiptDetail;
import com.huaheng.api.mes.dto.otherReceipt.OtherReceiptHeader;
肖超群 authored
10
import com.huaheng.api.mes.service.IMesService;
hh authored
11
12
import com.huaheng.api.mes.utils.CallaMOM;
import com.huaheng.api.mes.utils.SqlServer;
hh authored
13
import com.huaheng.api.mes.vo.InventoryVO;
hh authored
14
import com.huaheng.api.mes.vo.InventoryTransactionVO;
hh authored
15
import com.huaheng.common.constant.QuantityConstant;
16
import com.huaheng.common.exception.service.ServiceException;
hh authored
17
import com.huaheng.common.utils.StringUtils;
hh authored
18
import com.huaheng.common.utils.reflect.ReflectUtils;
hh authored
19
20
21
22
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.RetCode;
hh authored
23
import com.huaheng.pc.config.material.domain.Material;
hh authored
24
import com.huaheng.pc.config.material.service.MaterialService;
hh authored
25
26
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
hh authored
27
28
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
hh authored
29
import com.huaheng.pc.momLog.service.IMomLogService;
hh authored
30
31
32
33
34
35
36
37
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
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
38
39
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
hh authored
40
41
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
hh authored
42
import io.swagger.annotations.ApiOperation;
hh authored
43
44
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
hh authored
45
import org.springframework.beans.BeanUtils;
hh authored
46
47
48
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
hh authored
49
import java.io.UnsupportedEncodingException;
hh authored
50
51
52
53
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
hh authored
54
import java.util.*;
hh authored
55
hh authored
56
hh authored
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
@RestController
@RequestMapping("/API/WMS/v2")
public class MesReceiptController extends BaseController {

    @Resource
    private ReceiptHeaderService receiptHeaderService;

    @Resource
    private ReceiptDetailService receiptDetailService;

    @Resource
    private ShipmentHeaderService shipmentHeaderService;

    @Resource
    private ShipmentDetailService shipmentDetailService;

    @Resource
    private InventoryDetailService inventoryDetailService;
hh authored
76
77
78
    @Resource
    private TaskDetailService taskDetailService;
hh authored
79
80
81
82
83
84
    @Resource
    private InventoryTransactionService inventoryTransactionService;

    @Resource
    private MaterialService materialService;
hh authored
85
86
    @Resource
    private IMomLogService momLogService;
肖超群 authored
87
88
    @Resource
    private IMesService mesService;
tongzhonghao authored
89
90
    @Resource
    private IUserService userService;
hh authored
91
hh authored
92
    private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class);
hh authored
93
hh authored
94
95
96
97
    @PostMapping("/receipt")
    @ApiLogger(apiName = "添加入库单及其明细", from="ROBOT")
    @ApiOperation("添加入库单及其明细")
    public AjaxResult receipt(@RequestBody ReceiptDTO receiptDTO) {
肖超群 authored
98
99
100
101
102
        AjaxResult ajaxResult = handleQuest("receipt", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.receipt(receiptDTO);
                return ajaxResult;
103
            }
肖超群 authored
104
105
        });
        return ajaxResult;
hh authored
106
107
    }
hh authored
108
hh authored
109
110
111
112
113
114
115
116
117
    /**
     * 添加出库单及其明细
     * @param receiptDTO
     * @return
     */
    @PostMapping("/shipment")
    @ApiLogger(apiName = "添加出库单及其明细", from="ROBOT")
    @ApiOperation("添加出库单及其明细")
    public AjaxResult shipment(@RequestBody ReceiptDTO receiptDTO) {
肖超群 authored
118
119
120
121
122
        AjaxResult ajaxResult = handleQuest("shipment", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.shipment(receiptDTO);
                return ajaxResult;
tongzhonghao authored
123
            }
hh authored
124
        });
肖超群 authored
125
        return ajaxResult;
hh authored
126
127
    }
hh authored
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    private JSONObject getJsonObject(Header header, List<Detail> details) {
        JSONObject data = new JSONObject();
        JSONObject Rd_In_M = new JSONObject();
        Rd_In_M.put("MGPK", header.getId());
        Rd_In_M.put("cCode", header.getReferCode());
        JSONArray Rd_In_S = new JSONArray();
        details.forEach(detail -> {
            JSONObject json = new JSONObject();
            json.put("MGPK", header.getId());
            json.put("SGPK", detail.getId());
            json.put("cInvCode", detail.getMaterialCode());
            Rd_In_S.add(json);
        });
        data.put("Requester", "WMS");
        data.put("Rd_In_M", Rd_In_M);
        data.put("Rd_In_S", Rd_In_S);
        return data;
    }
hh authored
147
hh authored
148
149
150
151
152
153
154
155
    /**
     * 入库单参数_判空处理
     * @param ajaxResult
     * @param shipmentHeader
     * @param shipemtnDetails
     */
    private boolean enterIsNull(AjaxResult ajaxResult, Header shipmentHeader, List<Detail> shipemtnDetails){
tongzhonghao authored
156
157
158
        if (isNullData(ajaxResult, shipmentHeader, shipemtnDetails)){
            return true;
        }
hh authored
159
160
161
162
163
164
165

        if (StringUtils.isEmpty(shipmentHeader.getRefeCodeType())) {
            ajaxResult.setCode(RetCode.FAIL).setMsg("单据类型不能为空!!!");
            return true;
        } else if (StringUtils.isEmpty(shipmentHeader.getReferCode())) {
            ajaxResult.setCode(RetCode.FAIL).setMsg("单据单号不能为空!!!");
            return true;
hh authored
166
167
        }else if (shipmentHeader.getTotalQty() == null || shipmentHeader.getTotalQty().intValue() <= 0) {
            ajaxResult.setCode(RetCode.FAIL).setMsg("数量不能为空!!!");
hh authored
168
169
170
171
172
        }

        shipemtnDetails.forEach(shipemtnDetail->{
            if (StringUtils.isEmpty(shipemtnDetail.getMaterialCode())) {
                ajaxResult.setCode(RetCode.FAIL).setMsg("物料编码不能为空!!!");
hh authored
173
174
            } else if (shipemtnDetail.getTotalQty() == null || shipemtnDetail.getQty().intValue() <= 0) {
                ajaxResult.setCode(RetCode.FAIL).setMsg("数量不能为空!!!");
hh authored
175
176
177
178
179
180
181
182
183
184
185
186
            }
        });
        return StringUtils.isNotEmpty(ajaxResult.getMsg());
    }

    /**
     * 出库单参数_判空处理
     * @param ajaxResult
     * @param shipmentHeader
     * @param shipemtnDetails
     */
    private boolean outIsNull (AjaxResult ajaxResult, Header shipmentHeader, List<Detail> shipemtnDetails){
tongzhonghao authored
187
188
189
        if (isNullData(ajaxResult, shipmentHeader, shipemtnDetails)){
            return true;
        }
hh authored
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

        if (StringUtils.isEmpty(shipmentHeader.getReferCode())) {
            ajaxResult.setCode(RetCode.FAIL).setMsg("单据单号不能为空!!!");
            return true;
        }

        shipemtnDetails.forEach(shipemtnDetail->{
            if (StringUtils.isEmpty(shipemtnDetail.getMaterialCode())) {
                ajaxResult.setCode(RetCode.FAIL).setMsg("物料编码不能为空!!!");
            }
        });
        return StringUtils.isNotEmpty(ajaxResult.getMsg());
    }

    /**
     * 判空处理
     */
    private boolean isNullData(AjaxResult ajaxResult, Header shipmentHeader, List<Detail> shipemtnDetails) {
        if (shipmentHeader == null) {
            ajaxResult.setCode(RetCode.FAIL).setMsg("出库单头表不能为空!!!");
            return true;
        } else if (shipemtnDetails == null || shipemtnDetails.size() < 1) {
            ajaxResult.setCode(RetCode.FAIL).setMsg("出库单明细表集不能为空!!!");
            return true;
        }
        return false;
    }

    /**
hh authored
219
     * 入库单单据取消
hh authored
220
     */
hh authored
221
222
    @PostMapping("/cancelEnterWarehouse")
    @ApiOperation("入库单单据取消")
肖超群 authored
223
    @ApiLogger(apiName = "入库单单据取消", from="ROBOT")
hh authored
224
    public AjaxResult cancelEnterWarehouse(@RequestBody ReceiptDTO receiptDTO) {
肖超群 authored
225
226
227
228
229
        AjaxResult ajaxResult = handleQuest("cancelEnterWarehouse", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.cancelEnterWarehouse(receiptDTO);
                return ajaxResult;
hh authored
230
            }
肖超群 authored
231
232
        });
        return ajaxResult;
hh authored
233
234
235
236
237
238
239
240
    }


    /**
     * 出库单单据取消
     */
    @PostMapping("/cancelOutWarehouse")
    @ApiOperation("出库单单据取消")
肖超群 authored
241
    @ApiLogger(apiName = "出库单单据取消", from="ROBOT")
hh authored
242
    public AjaxResult cancelOutWarehouse(@RequestBody ReceiptDTO receiptDTO) {
肖超群 authored
243
244
245
246
247
        AjaxResult ajaxResult = handleQuest("cancelOutWarehouse", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.cancelOutWarehouse(receiptDTO);
                return ajaxResult;
hh authored
248
            }
肖超群 authored
249
250
        });
        return ajaxResult;
hh authored
251
252
253
254
255
256
257
258
259
260
    }

    private AjaxResult isNull(Header header, List<Detail> details) {
        AjaxResult ajaxResult = new AjaxResult();
        boolean isNull = outIsNull(ajaxResult, header, details);
        details.forEach(detail -> {
            if (detail.getTotalQty() == null || detail.getTotalQty().intValue() <= 0) {
                ajaxResult.setCode(RetCode.FAIL).setMsg("总数量不能为空!!!");
            }
        });
tongzhonghao authored
261
262
263
        if (isNull || StringUtils.isNotEmpty(ajaxResult.getMsg())){
            return ajaxResult;
        }
hh authored
264
        return ajaxResult;
hh authored
265
266
267
268
269
270
271
272
273
274
275
276
    }

    /**
     * 查询库存
     */
    @PostMapping("/searchInventory")
    @ApiLogger(apiName = "查询库存", from="ROBOT")
    @ApiOperation("查询库存")
    public AjaxResult searchInventory(@RequestBody Detail detailed) {

        String materialName =  detailed.getMaterialName();
        String materialCode = detailed.getMaterialCode();
hh authored
277
        String containerCode = detailed.getContainerCode();
278
hh authored
279
280
281
282
283
        LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        // 物料编码
        if (StringUtils.isNotEmpty(materialName)){
            lambdaQueryWrapper.eq(InventoryDetail::getMaterialName, materialName);
        }
hh authored
284
        // 物料名称
hh authored
285
286
287
        if (StringUtils.isNotEmpty(materialCode)){
            lambdaQueryWrapper.eq(InventoryDetail::getMaterialCode, materialCode);
        }
hh authored
288
289
290
291
        // 托盘号
        if (StringUtils.isNotEmpty(containerCode)){
            lambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode);
        }
hh authored
292
hh authored
293
294
295
        if (StringUtils.isEmpty(materialName) && StringUtils.isEmpty(containerCode) && StringUtils.isEmpty(containerCode)){
            lambdaQueryWrapper.gt(InventoryDetail::getQty, 0);
        }
hh authored
296
        List<InventoryDetail> detailList = inventoryDetailService.list(lambdaQueryWrapper);
hh authored
297
hh authored
298
299
300
301
302
        List<InventoryVO> inventoryVOList = new ArrayList<>();
        detailList.forEach(detail->{
            InventoryVO inventoryVO = new InventoryVO();
            BeanUtils.copyProperties(detail,inventoryVO);
            inventoryVO.setWarehouse("035");
hh authored
303
            inventoryVOList.add(inventoryVO);
hh authored
304
305
        });
hh authored
306
        return AjaxResult.success(inventoryVOList);
hh authored
307
308
309
310

    }

    /**
hh authored
311
     * 获取出入库单明细记录
hh authored
312
313
314
     * @return AjaxResult
     */
    @PostMapping("/getShipmentDetail")
hh authored
315
316
    @ApiLogger(apiName = "获取出入库单明细记录", from="ROBOT")
    @ApiOperation("获取出入库单明细记录")
hh authored
317
318
319
320
321
    public AjaxResult getShipmentDetail(@RequestBody GetOrderHistoryDTO getOrderHistoryDTO) {

        if(StringUtils.isEmpty(getOrderHistoryDTO.getEndTime()) || StringUtils.isEmpty(getOrderHistoryDTO.getStartTime())){
            return AjaxResult.error("开始时间和结束时间不能为空!!!");
        }
hh authored
322
        LambdaQueryWrapper<InventoryTransaction> lambdaQueryWrapper = Wrappers.lambdaQuery();
hh authored
323
        lambdaQueryWrapper
hh authored
324
325
326
327
328
329
330
331
332
333
                .ge(InventoryTransaction::getCreated, getOrderHistoryDTO.getStartTime())
                .le(InventoryTransaction::getCreated, getOrderHistoryDTO.getEndTime());
        List<InventoryTransaction> list = inventoryTransactionService.list(lambdaQueryWrapper);
        List<InventoryTransactionVO> inventoryTransactionVOList = new ArrayList<>();
        list.forEach(inventoryTransaction -> {
            InventoryTransactionVO inventoryTransactionVO = new InventoryTransactionVO();
            BeanUtils.copyProperties(inventoryTransaction, inventoryTransactionVO);
            inventoryTransactionVOList.add(inventoryTransactionVO);
        });
        return AjaxResult.success(inventoryTransactionVOList);
hh authored
334
335
336
337
338
339
340
341
342
343
344
    }

    /**
     * 获取sqlServer数据库中物料信息, 同步到本地数据库中
     */
    @PostMapping("/getMaterial")
    @ApiOperation("获取外部物料信息")
    public List<Material> getMaterial(){
        List<Material> materialList = new ArrayList<>();
        try {
            // String sql = "SELECT * FROM [dbo].[sys_user] WHERE createTime > (select DATEADD(HOUR,-3,getdate())) AND createTime <= (select GETDATE())";
hh authored
345
346
            // String sql = "SELECT * FROM [dbo].[base_material]  WHERE MaterialName = 'SMLS Pipe'";
            // 获取新增一天以内和修改两个小时以内的物料数据
hh authored
347
            String sql = "select a.cInvCode, a.cInvName, b.cidefine6, b.cidefine7, c.cComUnitName from [dbo].[Inventory] a left join [dbo].[Inventory_extradefine] b on a.cInvCode = b.cInvCode LEFT JOIN [dbo].[ComputationUnit] c ON a.cComUnitCode = c.cComunitCode WHERE (datediff(day,a.dSDate,getdate())=0 OR a.dModifyDate >=  DATEADD(HOUR, -4, GETDATE()))  and  a.cDefWareHouse in ('035','003')";
hh authored
348
            ResultSet resultSet = SqlServer.find(sql);
hh authored
349
350
351
352
            if (resultSet == null){
                return materialList;
            }
            while(resultSet.next()){
hh authored
353
354
355
                // 字段要与海王表一致
                String code = resultSet.getString("cInvCode");
                String name = resultSet.getString("cInvName");
hh authored
356
                String unit = resultSet.getString("cComUnitName");
hh authored
357
358
359
                String spec = resultSet.getString("cidefine6");
                String high = resultSet.getString("cidefine7");
                int isHigh = "高托".equals(high) ? 1 : 0;
hh authored
360
361

                Material material = new Material();
hh authored
362
                material.setCode(code);
hh authored
363
364
                material.setName(name);
                material.setUnit(unit);
hh authored
365
366
                material.setSpec(spec);
                material.setIsHigh(isHigh);
hh authored
367
368
369
370
371
372
373
374
                material.setWarehouseCode("CS0001");
                material.setCompanyCode("BHF");
                materialList.add(material);
            }
            // materialService.saveBatch(materialList);
        } catch (SQLException throwable) {
            throwable.printStackTrace();
        }
hh authored
375
        logger.debug("******************************同步海王物料档案" + materialList.size() + "条数据!!!");
hh authored
376
        return materialList;
hh authored
377
    }
hh authored
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

    /** 当前时间向推几小时 */
    public String dateRoll(int ihour) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 获取当前时间
        LocalDateTime date = LocalDateTime.now();
        // 获取当前时间的前几小时时间
        LocalDateTime localDateTime = date.minusHours(ihour);

        return dateTimeFormatter.format(localDateTime);
    }

    /**
     * 查询站台任务明细列表
     */
    @ApiLogger(apiName = "查询站台任务明细列表", from="ROBOT")
    @PostMapping("/kanbanInfo")
hh authored
395
    @CrossOrigin
hh authored
396
397
    public AjaxResult kanbanInfo(@RequestBody TaskDetail taskDetail){
        String fromLocation = taskDetail.getFromLocation();
tongzhonghao authored
398
        if (StringUtils.isEmpty(fromLocation)) {
hh authored
399
            return AjaxResult.error("站台不能为空!!!");
tongzhonghao authored
400
        }
hh authored
401
402
403
404
405
406
407
        LambdaQueryWrapper<TaskDetail> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(TaskDetail::getFromLocation, fromLocation)
                .lt(TaskDetail::getStatus,"100");
        List<TaskDetail> taskDetailList = taskDetailService.list(wrapper);
        return AjaxResult.success(taskDetailList);
    }
hh authored
408
    /**
409
     * post调用E_Rd_InMOM)入库成功接口
hh authored
410
     */
411
    //@ApiLogger(apiName = "post调用E_Rd_In(MOM)入库接口", from="ROBOT")
hh authored
412
    @PostMapping("/postE_Rd_In")
413
    public Boolean postE_Rd_In(@RequestBody ReceiptDetail receiptDetail){
tongzhonghao authored
414
        User user = userService.selectUserByEmail(receiptDetail.getLastUpdatedBy());
415
        ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptDetail.getReceiptId()); //59
hh authored
416
        JSONObject Rd_In_M = new JSONObject();
hh authored
417
418
        Rd_In_M.put("mno", receiptHeader.getCode());
        Rd_In_M.put("MGPK", receiptHeader.getMOMID());
hh authored
419
420
421
        Rd_In_M.put("cBusType", receiptHeader.getReceiptType());
        Rd_In_M.put("TAID", receiptHeader.getTAID());
        Rd_In_M.put("FAID", receiptHeader.getFAID());
tongzhonghao authored
422
        Rd_In_M.put("UserNo",  user.getLoginName());
hh authored
423
        Rd_In_M.put("warehouse",  receiptHeader.getWarehouse());
hh authored
424
hh authored
425
        JSONArray jsonArray = new JSONArray();
肖超群 authored
426
427
428
429
430
        JSONObject Rd_In_S = new JSONObject();
        Rd_In_S.put("MGPK", receiptHeader.getMOMID());
        Rd_In_S.put("SGPK", receiptDetail.getMOMID());
        Rd_In_S.put("SNNO", receiptDetail.getSNNO());
        Rd_In_S.put("cInvCode", receiptDetail.getMaterialCode());
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
        Rd_In_S.put("Iquantity", receiptDetail.getTaskQty());
        Rd_In_S.put("iFQuantity", receiptDetail.getQty());
        Rd_In_S.put("cwhcode", receiptDetail.getWarehouseCode());
        Rd_In_S.put("MOCode", receiptDetail.getNoticeNo());
        Rd_In_S.put("ISUrgent", receiptDetail.getIsUrgent());
        Rd_In_S.put("receiptBarcode", receiptDetail.getReceiptBarcode());
        Rd_In_S.put("warehouse", receiptHeader.getWarehouse());
        Rd_In_S.put("warehouseName", receiptHeader.getWarehouseName());
        Rd_In_S.put("creatorCode", receiptDetail.getLastUpdatedBy());
        Rd_In_S.put("creatorName", receiptDetail.getLastUpdatedByName());
        Rd_In_S.put("productionWorker", receiptHeader.getProductionWorker());
        Rd_In_S.put("productionWorkerName", receiptHeader.getProductionWorkerName());
        jsonArray.add(Rd_In_S);
        JSONObject data = new JSONObject();
        data.put("Rd_In_M", Rd_In_M);
        data.put("Rd_In_S", jsonArray);

        String action = "E_Rd_In";
        JSONObject json = new JSONObject();
        json.put("data", data);
易文鹏 authored
451
        return postMOM(action, json, "入库回传");
452
453
454
455
456
457
    }


    /**
     * post调用E_Rd_InMOM)其他入库成功接口
     */
458
    //@ApiLogger(apiName = "post调用E_Rd_In(MOM)其他入库接口", from="ROBOT")
459
    @PostMapping("/postOther_E_Rd_In")
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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
    public Boolean postOther_E_Rd_In(@RequestBody List<ReceiptDetail> receiptDetails,ReceiptHeader receiptHeader){
        OtherReceiptDomain domain = new OtherReceiptDomain();

        OtherReceiptHeader receiptHeader1 = new OtherReceiptHeader();
        receiptHeader1.setCode(receiptHeader.getCode());
        receiptHeader1.setMomId(receiptHeader.getMOMID());
        receiptHeader1.setReceiptType(receiptHeader.getReceiptType());
        receiptHeader1.setTaId(receiptHeader.getTAID());
        receiptHeader1.setFaId(receiptHeader.getFAID());
        receiptHeader1.setLastUpdatedBy(receiptHeader.getLastUpdatedBy());
        receiptHeader1.setWarehouse(receiptHeader.getWarehouse());
        receiptHeader1.setDepCode(QuantityConstant.DEFAULT_DEPT);
        receiptHeader1.setStock(QuantityConstant.DEFAULT_STOCK);

        List<OtherReceiptDetail> list = new ArrayList<>();
        for (ReceiptDetail receiptDetail : receiptDetails) {
            OtherReceiptDetail detail = new OtherReceiptDetail();
            detail.setMomIdByHeader(receiptHeader.getMOMID());
            detail.setMomId(receiptDetail.getMOMID());
            detail.setSnNo(receiptDetail.getSNNO());
            detail.setMaterialCode(receiptDetail.getMaterialCode());
            detail.setTaskQty(receiptDetail.getTaskQty());
            detail.setQty(receiptDetail.getQty());
            detail.setWarehouseCode(receiptDetail.getWarehouseCode());
            detail.setNotice(receiptDetail.getNoticeNo());
            detail.setISUrgent(receiptDetail.getIsUrgent());
            detail.setReceiptBarcode(receiptDetail.getReceiptBarcode());
            detail.setWarehouse(receiptHeader.getWarehouse());
            detail.setWarehouseName(receiptHeader.getWarehouseName());
            detail.setLastUpdatedBy(receiptDetail.getLastUpdatedBy());
            detail.setLastUpdatedByName(receiptDetail.getLastUpdatedByName());
            detail.setProductionWorker(receiptHeader.getProductionWorker());
            detail.setProductionWorkerName(receiptHeader.getProductionWorkerName());
            list.add(detail);
        }
        domain.setReceiptHeader(receiptHeader1);
        domain.setReceiptDetails(list);
        //返回实体
        ReturnDomain data = new ReturnDomain();
        data.setData(domain);
        String str = JSONObject.toJSONString(data);

        JSONObject jsonObject = JSONObject.parseObject(str);
        return postMOM("E_Rd_In", jsonObject,"其他入库回传");
hh authored
504
505
506
    }

    /**
507
     * post调用E_Rd_InMOM)出库成功接口
hh authored
508
     */
509
    //@ApiLogger(apiName = "post调用E_Rd_Out(MOM)出库接口", from="ROBOT")
hh authored
510
    @PostMapping("/postE_Rd_Out")
511
    public Boolean  postE_Rd_Out(@RequestBody ShipmentHeader shipmentHeader){
hh authored
512
        // ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentHeaderID.getId());
513
        //StringBuffer keyField = new StringBuffer();
hh authored
514
515
516
517
        JSONArray dataArray = new JSONArray();
        // 如果订单为合并类型
        if ("merge".equals(shipmentHeader.getShipmentType())){
            // 查询所有子表
518
519
            List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>()
                    .eq(ShipmentDetail::getShipmentId, shipmentHeader.getId()));
hh authored
520
521
522
            // 查询所有合并前的头表
            String ids = shipmentHeader.getRecordID();
            String [] headerIdArr = ids.split(",");
523
524
            List<ShipmentHeader> shipmentHeaderList = shipmentHeaderService.list(new LambdaQueryWrapper<ShipmentHeader>()
                    .in(ShipmentHeader::getId, headerIdArr));
hh authored
525
526
527
528
            // 根据合并前的头表id分组
            Map<Integer,List<ShipmentDetail>> map = new HashMap<>();
            for (ShipmentDetail detail : shipmentDetailList){
                    Integer key = detail.getRecordID();
529
530
531
532
533
534
535
536
                    if (key!=null){
                        if(map.containsKey(key)) {
                            map.get(key).add(detail);
                        }else {
                            List<ShipmentDetail> list = new ArrayList<>();
                            list.add(detail);
                            map.put(key, list);
                        }
hh authored
537
538
                    }
            }
hh authored
539
hh authored
540
541
542
543
544
545
546
547
548
549
            for (Integer key : map.keySet()) {
                JSONObject data = new JSONObject();
                // 合并前的头表
                ShipmentHeader header = new ShipmentHeader();
                // 合并前头表对应的子表
                List<ShipmentDetail> detailList = new ArrayList<>();
                for(ShipmentHeader SH : shipmentHeaderList){
                    if (key.equals(SH.getId())){
                        header = SH;
                        detailList = map.get(key);
hh authored
550
                        break;
hh authored
551
552
553
554
555
556
557
558
559
560
561
562
563
                    }
                }
                // 查询出库单据表头
                JSONObject Rd_Out_M = getRd_Out_M(header);
                JSONArray jsonArray = getRd_Out_S(header, detailList);
                data.put("Rd_Out_M", Rd_Out_M);
                data.put("Rd_Out_S", jsonArray);
                dataArray.add(data);
            }
        }else {
            // 查询出库单据表头
            JSONObject Rd_Out_M = getRd_Out_M(shipmentHeader);
            // 查询出库单据明细
564
565
            List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>()
                    .eq(ShipmentDetail::getShipmentId, shipmentHeader.getId()));
hh authored
566
            JSONArray jsonArray = getRd_Out_S(shipmentHeader,shipmentDetailList);
hh authored
567
568
569
570
571
572
573
574
575
            JSONObject data = new JSONObject();
            data.put("Rd_Out_M", Rd_Out_M);
            data.put("Rd_Out_S", jsonArray);
            dataArray.add(data);
        }

        String action = "E_Rd_Out";
        JSONObject json = new JSONObject();
        json.put("data", dataArray);
易文鹏 authored
576
        boolean success = postMOM(action, json,"出库回传");
577
578
579
580
581
582
583
584
585
        if(success) {
            shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_RETURN);
            shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_RETURN);
            success = shipmentHeaderService.updateById(shipmentHeader);
            if(!success) {
                throw new ServiceException("更新出库单失败");
            }
        }
        return success;
hh authored
586
587
588
    }
hh authored
589
    public JSONArray getRd_Out_S(ShipmentHeader shipmentHeader, List<ShipmentDetail> shipmentDetailList) {
hh authored
590
        JSONArray jsonArray = new JSONArray();
hh authored
591
        shipmentDetailList.forEach(shipmentDetail->{
hh authored
592
            JSONObject Rd_Out_S = new JSONObject();
hh authored
593
594
            Rd_Out_S.put("MGPK", shipmentHeader.getMOMID());
            Rd_Out_S.put("SGPK",  shipmentDetail.getMOMID());
hh authored
595
            Rd_Out_S.put("SNNO",  shipmentDetail.getSNNO());
hh authored
596
            Rd_Out_S.put("cInvCode",  shipmentDetail.getMaterialCode());
hh authored
597
598
599
600
            // 实际入库数量
            Rd_Out_S.put("Iquantity",  shipmentDetail.getTaskQty());
            // MOM传入的入库数量
            Rd_Out_S.put("iFQuantity",  shipmentDetail.getQty());
hh authored
601
            Rd_Out_S.put("cwhcode",  shipmentDetail.getWarehouseCode());
hh authored
602
            Rd_Out_S.put("MOCode",  shipmentDetail.getNoticeNo());
hh authored
603
            Rd_Out_S.put("ISUrgent",  shipmentDetail.getIsUrgent());
hh authored
604
            Rd_Out_S.put("updatedBy",  shipmentDetail.getLastUpdatedBy());
tongzhonghao authored
605
606
607
608
609
            Rd_Out_S.put("warehouse",  shipmentHeader.getWarehouse());
            Rd_Out_S.put("warehouseName",  shipmentHeader.getWarehouseName());
            Rd_Out_S.put("creatorCode",  shipmentDetail.getLastUpdatedBy());
            Rd_Out_S.put("creatorName",  shipmentDetail.getLastUpdatedByName());
            Rd_Out_S.put("requestedStartDate",  shipmentHeader.getRequestedStartDate());
hh authored
610
611
            jsonArray.add(Rd_Out_S);
        });
hh authored
612
613
        return jsonArray;
    }
hh authored
614
hh authored
615
    public JSONObject getRd_Out_M(@RequestBody ShipmentHeader shipmentHeader) {
tongzhonghao authored
616
        User user = userService.selectUserByEmail(shipmentHeader.getLastUpdatedBy());
hh authored
617
618
619
620
621
622
        JSONObject Rd_Out_M = new JSONObject();
        Rd_Out_M.put("mno", shipmentHeader.getCode());
        Rd_Out_M.put("MGPK", shipmentHeader.getMOMID());
        Rd_Out_M.put("cBusType", shipmentHeader.getShipmentType());
        Rd_Out_M.put("TAID", shipmentHeader.getTAID());
        Rd_Out_M.put("FAID", shipmentHeader.getFAID());
tongzhonghao authored
623
        Rd_Out_M.put("UserNo",  user.getLoginName());
hh authored
624
        Rd_Out_M.put("warehouse",  shipmentHeader.getWarehouse());
陈翱 authored
625
626
        Rd_Out_M.put("cDepCode",  "01030101");//部门编码
        Rd_Out_M.put("cWhCode",  shipmentHeader.getWarehouse());//仓库编码
hh authored
627
        return Rd_Out_M;
hh authored
628
629
    }
hh authored
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
    /**  utf-8 转 GB2312 */
    public String getGB(String action){
        byte [] Rd_Out; //中间用ISO-8859-1过渡
        String data = null;
        try {
            Rd_Out = action.getBytes("8859_1");
            data = new String(Rd_Out, "GB2312"); //转换成GB2312字符
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return data;
    }


        /**
         * @param action MOM行为
         * @param JObject 行为参数
         * @return
         */
649
650
    public Boolean postMOM(String action, JSONObject JObject,String apiName){
        return CallaMOM.getMsg(action, JObject,apiName);
hh authored
651
    }
hh authored
652
hh authored
653
hh authored
654
}