Blame view

src/main/java/com/huaheng/api/mes/controller/MesReceiptController.java 32.3 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;
10
import com.huaheng.api.mes.result.ReturnInfo;
肖超群 authored
11
import com.huaheng.api.mes.service.IMesService;
hh authored
12
13
import com.huaheng.api.mes.utils.CallaMOM;
import com.huaheng.api.mes.utils.SqlServer;
hh authored
14
import com.huaheng.api.mes.vo.InventoryVO;
hh authored
15
import com.huaheng.api.mes.vo.InventoryTransactionVO;
hh authored
16
import com.huaheng.common.constant.QuantityConstant;
17
import com.huaheng.common.exception.service.ServiceException;
hh authored
18
import com.huaheng.common.utils.StringUtils;
hh authored
19
import com.huaheng.common.utils.reflect.ReflectUtils;
hh authored
20
21
22
23
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;
24
import com.huaheng.pc.config.address.service.AddressService;
hh authored
25
import com.huaheng.pc.config.material.domain.Material;
hh authored
26
import com.huaheng.pc.config.material.service.MaterialService;
hh authored
27
28
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
hh authored
29
30
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
hh authored
31
import com.huaheng.pc.momLog.service.IMomLogService;
hh authored
32
33
34
35
36
37
38
39
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;
40
41
import com.huaheng.pc.shipment.shipmentHeaderHistory.domain.ShipmentHeaderHistory;
import com.huaheng.pc.shipment.shipmentHeaderHistory.service.ShipmentHeaderHistoryService;
tongzhonghao authored
42
43
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
hh authored
44
45
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
hh authored
46
import io.swagger.annotations.ApiOperation;
hh authored
47
48
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
hh authored
49
import org.springframework.beans.BeanUtils;
hh authored
50
51
52
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
hh authored
53
import java.io.UnsupportedEncodingException;
hh authored
54
55
56
57
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
hh authored
58
import java.util.*;
hh authored
59
hh authored
60
hh authored
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@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
80
81
82
    @Resource
    private TaskDetailService taskDetailService;
hh authored
83
84
85
86
    @Resource
    private InventoryTransactionService inventoryTransactionService;

    @Resource
87
88
    private ShipmentHeaderHistoryService shipmentHeaderHistoryService;
    @Resource
hh authored
89
90
    private MaterialService materialService;
hh authored
91
92
    @Resource
    private IMomLogService momLogService;
肖超群 authored
93
94
    @Resource
    private IMesService mesService;
tongzhonghao authored
95
96
    @Resource
    private IUserService userService;
hh authored
97
98
99
100
    @Resource
    private AddressService addressService;
hh authored
101
    private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class);
hh authored
102
hh authored
103
    @PostMapping("/receipt")
易文鹏 authored
104
    @ApiLogger(apiName = "添加入库单及其明细", from = "ROBOT")
hh authored
105
106
    @ApiOperation("添加入库单及其明细")
    public AjaxResult receipt(@RequestBody ReceiptDTO receiptDTO) {
肖超群 authored
107
108
109
110
111
        AjaxResult ajaxResult = handleQuest("receipt", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.receipt(receiptDTO);
                return ajaxResult;
112
            }
肖超群 authored
113
114
        });
        return ajaxResult;
hh authored
115
116
    }
hh authored
117
hh authored
118
119
    /**
     * 添加出库单及其明细
易文鹏 authored
120
     *
hh authored
121
122
123
124
     * @param receiptDTO
     * @return
     */
    @PostMapping("/shipment")
易文鹏 authored
125
    @ApiLogger(apiName = "添加出库单及其明细", from = "ROBOT")
hh authored
126
127
    @ApiOperation("添加出库单及其明细")
    public AjaxResult shipment(@RequestBody ReceiptDTO receiptDTO) {
肖超群 authored
128
129
130
131
132
        AjaxResult ajaxResult = handleQuest("shipment", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.shipment(receiptDTO);
                return ajaxResult;
tongzhonghao authored
133
            }
hh authored
134
        });
肖超群 authored
135
        return ajaxResult;
hh authored
136
137
    }
hh authored
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
    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
157
hh authored
158
159
    /**
     * 入库单参数_判空处理
易文鹏 authored
160
     *
hh authored
161
162
163
164
     * @param ajaxResult
     * @param shipmentHeader
     * @param shipemtnDetails
     */
易文鹏 authored
165
    private boolean enterIsNull(AjaxResult ajaxResult, Header shipmentHeader, List<Detail> shipemtnDetails) {
hh authored
166
易文鹏 authored
167
        if (isNullData(ajaxResult, shipmentHeader, shipemtnDetails)) {
tongzhonghao authored
168
169
            return true;
        }
hh authored
170
171
172
173
174
175
176

        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;
易文鹏 authored
177
        } else if (shipmentHeader.getTotalQty() == null || shipmentHeader.getTotalQty().intValue() <= 0) {
hh authored
178
            ajaxResult.setCode(RetCode.FAIL).setMsg("数量不能为空!!!");
hh authored
179
180
        }
易文鹏 authored
181
        shipemtnDetails.forEach(shipemtnDetail -> {
hh authored
182
183
            if (StringUtils.isEmpty(shipemtnDetail.getMaterialCode())) {
                ajaxResult.setCode(RetCode.FAIL).setMsg("物料编码不能为空!!!");
hh authored
184
185
            } else if (shipemtnDetail.getTotalQty() == null || shipemtnDetail.getQty().intValue() <= 0) {
                ajaxResult.setCode(RetCode.FAIL).setMsg("数量不能为空!!!");
hh authored
186
187
188
189
190
191
192
            }
        });
        return StringUtils.isNotEmpty(ajaxResult.getMsg());
    }

    /**
     * 出库单参数_判空处理
易文鹏 authored
193
     *
hh authored
194
195
196
197
     * @param ajaxResult
     * @param shipmentHeader
     * @param shipemtnDetails
     */
易文鹏 authored
198
199
    private boolean outIsNull(AjaxResult ajaxResult, Header shipmentHeader, List<Detail> shipemtnDetails) {
        if (isNullData(ajaxResult, shipmentHeader, shipemtnDetails)) {
tongzhonghao authored
200
201
            return true;
        }
hh authored
202
203
204
205
206
207

        if (StringUtils.isEmpty(shipmentHeader.getReferCode())) {
            ajaxResult.setCode(RetCode.FAIL).setMsg("单据单号不能为空!!!");
            return true;
        }
易文鹏 authored
208
        shipemtnDetails.forEach(shipemtnDetail -> {
hh authored
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
            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
231
     * 入库单单据取消
hh authored
232
     */
hh authored
233
234
    @PostMapping("/cancelEnterWarehouse")
    @ApiOperation("入库单单据取消")
易文鹏 authored
235
    @ApiLogger(apiName = "入库单单据取消", from = "ROBOT")
hh authored
236
    public AjaxResult cancelEnterWarehouse(@RequestBody ReceiptDTO receiptDTO) {
肖超群 authored
237
238
239
240
241
        AjaxResult ajaxResult = handleQuest("cancelEnterWarehouse", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.cancelEnterWarehouse(receiptDTO);
                return ajaxResult;
hh authored
242
            }
肖超群 authored
243
244
        });
        return ajaxResult;
hh authored
245
246
247
248
249
250
251
252
    }


    /**
     * 出库单单据取消
     */
    @PostMapping("/cancelOutWarehouse")
    @ApiOperation("出库单单据取消")
易文鹏 authored
253
    @ApiLogger(apiName = "出库单单据取消", from = "ROBOT")
hh authored
254
    public AjaxResult cancelOutWarehouse(@RequestBody ReceiptDTO receiptDTO) {
肖超群 authored
255
256
257
258
259
        AjaxResult ajaxResult = handleQuest("cancelOutWarehouse", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.cancelOutWarehouse(receiptDTO);
                return ajaxResult;
hh authored
260
            }
肖超群 authored
261
262
        });
        return ajaxResult;
hh authored
263
264
265
266
267
268
269
270
271
272
    }

    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("总数量不能为空!!!");
            }
        });
易文鹏 authored
273
        if (isNull || StringUtils.isNotEmpty(ajaxResult.getMsg())) {
tongzhonghao authored
274
275
            return ajaxResult;
        }
hh authored
276
        return ajaxResult;
hh authored
277
278
279
280
281
282
    }

    /**
     * 查询库存
     */
    @PostMapping("/searchInventory")
易文鹏 authored
283
    @ApiLogger(apiName = "查询库存", from = "ROBOT")
hh authored
284
285
286
    @ApiOperation("查询库存")
    public AjaxResult searchInventory(@RequestBody Detail detailed) {
易文鹏 authored
287
        String materialName = detailed.getMaterialName();
hh authored
288
        String materialCode = detailed.getMaterialCode();
hh authored
289
        String containerCode = detailed.getContainerCode();
290
hh authored
291
292
        LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        // 物料编码
易文鹏 authored
293
        if (StringUtils.isNotEmpty(materialName)) {
hh authored
294
295
            lambdaQueryWrapper.eq(InventoryDetail::getMaterialName, materialName);
        }
hh authored
296
        // 物料名称
易文鹏 authored
297
        if (StringUtils.isNotEmpty(materialCode)) {
hh authored
298
299
            lambdaQueryWrapper.eq(InventoryDetail::getMaterialCode, materialCode);
        }
hh authored
300
        // 托盘号
易文鹏 authored
301
        if (StringUtils.isNotEmpty(containerCode)) {
hh authored
302
303
            lambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode);
        }
hh authored
304
易文鹏 authored
305
        if (StringUtils.isEmpty(materialName) && StringUtils.isEmpty(containerCode) && StringUtils.isEmpty(containerCode)) {
hh authored
306
307
            lambdaQueryWrapper.gt(InventoryDetail::getQty, 0);
        }
hh authored
308
        List<InventoryDetail> detailList = inventoryDetailService.list(lambdaQueryWrapper);
hh authored
309
hh authored
310
        List<InventoryVO> inventoryVOList = new ArrayList<>();
易文鹏 authored
311
        detailList.forEach(detail -> {
hh authored
312
            InventoryVO inventoryVO = new InventoryVO();
易文鹏 authored
313
            BeanUtils.copyProperties(detail, inventoryVO);
hh authored
314
            inventoryVO.setWarehouse("035");
hh authored
315
            inventoryVOList.add(inventoryVO);
hh authored
316
317
        });
hh authored
318
        return AjaxResult.success(inventoryVOList);
hh authored
319
320
321
322

    }

    /**
hh authored
323
     * 获取出入库单明细记录
易文鹏 authored
324
     *
hh authored
325
326
327
     * @return AjaxResult
     */
    @PostMapping("/getShipmentDetail")
易文鹏 authored
328
    @ApiLogger(apiName = "获取出入库单明细记录", from = "ROBOT")
hh authored
329
    @ApiOperation("获取出入库单明细记录")
hh authored
330
331
    public AjaxResult getShipmentDetail(@RequestBody GetOrderHistoryDTO getOrderHistoryDTO) {
易文鹏 authored
332
        if (StringUtils.isEmpty(getOrderHistoryDTO.getEndTime()) || StringUtils.isEmpty(getOrderHistoryDTO.getStartTime())) {
hh authored
333
334
            return AjaxResult.error("开始时间和结束时间不能为空!!!");
        }
hh authored
335
        LambdaQueryWrapper<InventoryTransaction> lambdaQueryWrapper = Wrappers.lambdaQuery();
hh authored
336
        lambdaQueryWrapper
hh authored
337
338
339
340
341
342
343
344
345
346
                .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
347
348
349
350
351
352
353
    }

    /**
     * 获取sqlServer数据库中物料信息, 同步到本地数据库中
     */
    @PostMapping("/getMaterial")
    @ApiOperation("获取外部物料信息")
易文鹏 authored
354
    public List<Material> getMaterial() {
hh authored
355
356
357
        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
358
359
            // String sql = "SELECT * FROM [dbo].[base_material]  WHERE MaterialName = 'SMLS Pipe'";
            // 获取新增一天以内和修改两个小时以内的物料数据
360
            //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')";
361
362
363

            //DATEDIFF() 函数返回两个日期之间的天数。
易文鹏 authored
364
            String sql = "SELECT\n" +
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
                    "\ta.cinvcode,\n" +
                    "\ta.cinvname,\n" +
                    "\ta.cDefWareHouse,\n" +
                    "\ta.cComUnitCode,\n" +
                    "\tb.cComUnitName,\n" +
                    "\tc.cidefine6,\n" +
                    "\tc.cidefine7,\n" +
                    "\ta.dModifyDate,\n" +
                    "\ta.dSDate,\n" +
                    "\ta.cinvstd,\n" +
                    "\ta.Iinvweight,\n" +
                    "\ta.cinvccode,\n" +
                    "\td.cInvCName\n" +
                    "FROM\n" +
                    "\t[dbo].[Inventory] a\n" +
                    "\tLEFT JOIN [dbo].[ComputationUnit] b  ON a.cComUnitCode= b.cComUnitCode\n" +
                    "\tLEFT JOIN [dbo].[Inventory_extradefine] c ON a.cinvcode= c.cinvcode\n" +
                    "\tLEFT JOIN [dbo].[InventoryClass] d on a.cinvccode= d.cinvccode \n" +
                    "WHERE ( datediff( DAY, a.dSDate, getdate( ) ) = 0 OR a.dModifyDate >= DATEADD( HOUR, - 4, GETDATE( ) ) ) \n" +
易文鹏 authored
384
                    "\tAND a.cDefWareHouse IN ( '035', '003' ,'001')";
385
hh authored
386
            ResultSet resultSet = SqlServer.find(sql);
易文鹏 authored
387
            if (resultSet == null) {
hh authored
388
389
                return materialList;
            }
易文鹏 authored
390
            while (resultSet.next()) {
hh authored
391
                // 字段要与海王表一致
392
393
394
395
396
397
398
399
400
401
402
403
404
405
                String code = resultSet.getString("cInvCode");//物料编码
                String name = resultSet.getString("cInvName");//物料名称
                String unitName = resultSet.getString("cComUnitName");//单位名称
                String physicalDimension = resultSet.getString("cidefine6");//外形尺寸
                String high = resultSet.getString("cidefine7");//托盘类型

                String defWareHouse = resultSet.getString("cDefWareHouse");//u8仓库
                String unitCode = resultSet.getString("cComUnitCode");//单位编码
                //String modifyDate = resultSet.getString("dModifyDate");//修改时间
                //String startDate = resultSet.getString("dSDate");//启用时间
                String spec = resultSet.getString("cinvstd");//规格
                String weight = resultSet.getString("Iinvweight");//重量cinvccode
                String cinvccode = resultSet.getString("cinvccode");//存货类别编码
                String cInvCName = resultSet.getString("cInvCName");//存货类别名称
hh authored
406
                int isHigh = "高托".equals(high) ? 1 : 0;
hh authored
407
408

                Material material = new Material();
hh authored
409
                material.setCode(code);
hh authored
410
                material.setName(name);
411
                material.setUnit(unitName);
hh authored
412
413
                material.setSpec(spec);
                material.setIsHigh(isHigh);
hh authored
414
415
                material.setWarehouseCode("CS0001");
                material.setCompanyCode("BHF");
416
417
418
419
420
421
422
423
424

                material.setPhysicalDimension(physicalDimension);
                material.setDefWareHouse(defWareHouse);
                material.setUnitCode(unitCode);
                //material.setModifyDate();
                //material.setStartDate();
                material.setWeight(weight);
                material.setCinvccode(cinvccode);
                material.setCInvCName(cInvCName);
hh authored
425
426
427
428
429
430
                materialList.add(material);
            }
            // materialService.saveBatch(materialList);
        } catch (SQLException throwable) {
            throwable.printStackTrace();
        }
hh authored
431
        logger.debug("******************************同步海王物料档案" + materialList.size() + "条数据!!!");
hh authored
432
        return materialList;
hh authored
433
    }
hh authored
434
易文鹏 authored
435
436
437
    /**
     * 当前时间向推几小时
     */
hh authored
438
439
440
441
442
443
444
445
446
447
448
449
450
    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);
    }

    /**
     * 查询站台任务明细列表
     */
易文鹏 authored
451
    @ApiLogger(apiName = "查询站台任务明细列表", from = "ROBOT")
hh authored
452
    @PostMapping("/kanbanInfo")
hh authored
453
    @CrossOrigin
易文鹏 authored
454
    public AjaxResult kanbanInfo(@RequestBody TaskDetail taskDetail) {
hh authored
455
        String fromLocation = taskDetail.getFromLocation();
tongzhonghao authored
456
        if (StringUtils.isEmpty(fromLocation)) {
hh authored
457
            return AjaxResult.error("站台不能为空!!!");
tongzhonghao authored
458
        }
hh authored
459
460
        LambdaQueryWrapper<TaskDetail> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(TaskDetail::getFromLocation, fromLocation)
易文鹏 authored
461
                .lt(TaskDetail::getStatus, "100");
hh authored
462
463
464
465
        List<TaskDetail> taskDetailList = taskDetailService.list(wrapper);
        return AjaxResult.success(taskDetailList);
    }
hh authored
466
    /**
467
     * post调用E_Rd_InMOM)入库成功接口
hh authored
468
     */
469
    //@ApiLogger(apiName = "post调用E_Rd_In(MOM)入库接口", from="ROBOT")
hh authored
470
    @PostMapping("/postE_Rd_In")
易文鹏 authored
471
    public ReturnInfo postE_Rd_In(@RequestBody ReceiptDetail receiptDetail) {
tongzhonghao authored
472
        User user = userService.selectUserByEmail(receiptDetail.getLastUpdatedBy());
473
        ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptDetail.getReceiptId()); //59
hh authored
474
        JSONObject Rd_In_M = new JSONObject();
hh authored
475
476
        Rd_In_M.put("mno", receiptHeader.getCode());
        Rd_In_M.put("MGPK", receiptHeader.getMOMID());
hh authored
477
478
479
        Rd_In_M.put("cBusType", receiptHeader.getReceiptType());
        Rd_In_M.put("TAID", receiptHeader.getTAID());
        Rd_In_M.put("FAID", receiptHeader.getFAID());
易文鹏 authored
480
481
        Rd_In_M.put("UserNo", user.getLoginName());
        Rd_In_M.put("warehouse", receiptHeader.getWarehouse());
hh authored
482
hh authored
483
        JSONArray jsonArray = new JSONArray();
肖超群 authored
484
485
486
487
488
        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());
489
490
        Rd_In_S.put("Iquantity", receiptDetail.getTaskQty());
        Rd_In_S.put("iFQuantity", receiptDetail.getQty());
491
        Rd_In_S.put("cwhcode", "035");
492
493
494
495
496
        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());
497
498
        Rd_In_S.put("creatorCode", user.getLoginName());
        Rd_In_S.put("creatorName", receiptDetail.getLastUpdatedBy());
499
500
        Rd_In_S.put("productionWorker", receiptHeader.getProductionWorker());
        Rd_In_S.put("productionWorkerName", receiptHeader.getProductionWorkerName());
501
502
503
        Rd_In_S.put("ifrom", receiptDetail.getIfrom());
        Rd_In_S.put("LMPKID", receiptDetail.getLMPKID());
        Rd_In_S.put("LSPKID", receiptDetail.getLSPKID());
504
505
506
507
508
509
510
511
        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
512
        return postMOM(action, json, "入库回传");
513
514
515
516
517
518
    }


    /**
     * post调用E_Rd_InMOM)其他入库成功接口
     */
519
    //@ApiLogger(apiName = "post调用E_Rd_In(MOM)其他入库接口", from="ROBOT")
520
    @PostMapping("/postOther_E_Rd_In")
易文鹏 authored
521
    public ReturnInfo postOther_E_Rd_In(@RequestBody List<ReceiptDetail> receiptDetails, ReceiptHeader receiptHeader) {
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
        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);
易文鹏 authored
564
        return postMOM("E_Rd_In", jsonObject, "其他入库回传");
hh authored
565
566
567
    }

    /**
568
     * post调用E_Rd_InMOM)出库成功接口
hh authored
569
     */
570
    //@ApiLogger(apiName = "post调用E_Rd_Out(MOM)出库接口", from="ROBOT")
hh authored
571
    @PostMapping("/postE_Rd_Out")
易文鹏 authored
572
    public Boolean postE_Rd_Out(@RequestBody ShipmentHeader shipmentHeader) {
hh authored
573
        // ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentHeaderID.getId());
574
        //StringBuffer keyField = new StringBuffer();
hh authored
575
576
        JSONArray dataArray = new JSONArray();
        // 如果订单为合并类型
易文鹏 authored
577
        if ("merge".equals(shipmentHeader.getShipmentType())) {
hh authored
578
            // 查询所有子表
易文鹏 authored
579
            List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>().eq(ShipmentDetail::getShipmentId, shipmentHeader.getId()));
hh authored
580
            // 查询所有合并前的头表
581
582
583
584
585
586
587
            StringBuilder ids = new StringBuilder();
            for (ShipmentDetail shipmentDetail : shipmentDetailList) {
                ids.append(",").append(shipmentDetail.getRecordCode());
            }
            String codes = ids.substring(1, ids.length());
            String[] headerIdArr = codes.split(",");
易文鹏 authored
588
            List<ShipmentHeader> shipmentHeaderList = new ArrayList<>();
589
590
591
592
593
594
595
            List<ShipmentHeaderHistory> list2 = shipmentHeaderHistoryService.list(new LambdaQueryWrapper<ShipmentHeaderHistory>().in(ShipmentHeaderHistory::getCode, headerIdArr));
            for (ShipmentHeaderHistory shipmentHeaderHistory : list2) {
                ShipmentHeader shipmentHeader1 = new ShipmentHeader();
                BeanUtils.copyProperties(shipmentHeaderHistory, shipmentHeader1);
                shipmentHeaderList.add(shipmentHeader1);
            }
hh authored
596
            // 根据合并前的头表id分组
597
            Map<String, List<ShipmentDetail>> map = new HashMap<>();
易文鹏 authored
598
            for (ShipmentDetail detail : shipmentDetailList) {
599
                String key = detail.getRecordCode();
易文鹏 authored
600
601
602
603
604
605
606
                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
607
                    }
易文鹏 authored
608
                }
hh authored
609
            }
hh authored
610
611
            for (String key : map.keySet()) {
hh authored
612
613
614
615
616
                JSONObject data = new JSONObject();
                // 合并前的头表
                ShipmentHeader header = new ShipmentHeader();
                // 合并前头表对应的子表
                List<ShipmentDetail> detailList = new ArrayList<>();
易文鹏 authored
617
                for (ShipmentHeader SH : shipmentHeaderList) {
618
                    if (key.equals(SH.getCode())) {
hh authored
619
620
                        header = SH;
                        detailList = map.get(key);
hh authored
621
                        break;
hh authored
622
623
624
625
626
627
628
629
630
                    }
                }
                // 查询出库单据表头
                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);
            }
易文鹏 authored
631
        } else {
hh authored
632
633
634
            // 查询出库单据表头
            JSONObject Rd_Out_M = getRd_Out_M(shipmentHeader);
            // 查询出库单据明细
635
636
            List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(new LambdaQueryWrapper<ShipmentDetail>()
                    .eq(ShipmentDetail::getShipmentId, shipmentHeader.getId()));
易文鹏 authored
637
            JSONArray jsonArray = getRd_Out_S(shipmentHeader, shipmentDetailList);
hh authored
638
639
640
641
642
643
644
645
646
            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
647
648
        ReturnInfo returnInfo = postMOM(action, json, "出库回传");
        if (returnInfo == null) {
tongzhonghao authored
649
650
651
            shipmentHeader.setErrorMsg("出库回传:接口地址错误或返回为空");
            shipmentHeader.setPushSuccessStatus(2);
            shipmentHeaderService.updateById(shipmentHeader);
652
            return false;
tongzhonghao authored
653
        }
易文鹏 authored
654
        shipmentHeader.setPushErrorCount(shipmentHeader.getPushErrorCount() + 1);
655
        if (returnInfo.hasError()) {
656
            shipmentHeader.setPushSuccessStatus(1);
657
658
            shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_RETURN);
            shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_RETURN);
易文鹏 authored
659
        } else {
660
            shipmentHeader.setPushSuccessStatus(2);
661
            shipmentHeader.setErrorMsg(returnInfo.getMsg());
662
        }
663
664
        shipmentHeaderService.updateById(shipmentHeader);
        return true;
hh authored
665
666
667
    }
hh authored
668
    public JSONArray getRd_Out_S(ShipmentHeader shipmentHeader, List<ShipmentDetail> shipmentDetailList) {
hh authored
669
        JSONArray jsonArray = new JSONArray();
易文鹏 authored
670
        shipmentDetailList.forEach(shipmentDetail -> {
671
            User user = userService.selectUserByEmail(shipmentDetail.getLastUpdatedBy());
hh authored
672
            JSONObject Rd_Out_S = new JSONObject();
hh authored
673
            Rd_Out_S.put("MGPK", shipmentHeader.getMOMID());
易文鹏 authored
674
675
676
            Rd_Out_S.put("SGPK", shipmentDetail.getMOMID());
            Rd_Out_S.put("SNNO", shipmentDetail.getSNNO());
            Rd_Out_S.put("cInvCode", shipmentDetail.getMaterialCode());
hh authored
677
            // 实际入库数量
易文鹏 authored
678
            Rd_Out_S.put("Iquantity", shipmentDetail.getTaskQty());
hh authored
679
            // MOM传入的入库数量
易文鹏 authored
680
            Rd_Out_S.put("iFQuantity", shipmentDetail.getQty());
681
            Rd_Out_S.put("cwhcode", "035");
易文鹏 authored
682
683
            Rd_Out_S.put("MOCode", shipmentDetail.getNoticeNo());
            Rd_Out_S.put("ISUrgent", shipmentDetail.getIsUrgent());
684
            Rd_Out_S.put("updatedByNo", user.getLoginName());
易文鹏 authored
685
686
687
            Rd_Out_S.put("updatedBy", shipmentDetail.getLastUpdatedBy());
            Rd_Out_S.put("warehouse", shipmentHeader.getWarehouse());
            Rd_Out_S.put("warehouseName", shipmentHeader.getWarehouseName());
688
689
690
691
692
693
            Rd_Out_S.put("creatorCode", shipmentHeader.getCreatorCode());
            Rd_Out_S.put("creatorName", shipmentHeader.getCreatorName());
//            Rd_Out_S.put("requestedStartDate", shipmentHeader.getRequestedStartDate());
            Rd_Out_S.put("ifrom", shipmentDetail.getIfrom());
            Rd_Out_S.put("LMPKID", shipmentDetail.getLMPKID());
            Rd_Out_S.put("LSPKID", shipmentDetail.getLSPKID());
hh authored
694
695
            jsonArray.add(Rd_Out_S);
        });
hh authored
696
697
        return jsonArray;
    }
hh authored
698
hh authored
699
    public JSONObject getRd_Out_M(@RequestBody ShipmentHeader shipmentHeader) {
tongzhonghao authored
700
        User user = userService.selectUserByEmail(shipmentHeader.getLastUpdatedBy());
hh authored
701
702
703
704
705
706
        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());
707
708
        Rd_Out_M.put("UserNo", user.getLoginName());
        Rd_Out_M.put("warehouse", "035");
易文鹏 authored
709
710
        Rd_Out_M.put("cDepCode", "01030101");//部门编码
        Rd_Out_M.put("cWhCode", shipmentHeader.getWarehouse());//仓库编码
hh authored
711
        return Rd_Out_M;
hh authored
712
713
    }
易文鹏 authored
714
715
716
717
718
    /**
     * utf-8  GB2312
     */
    public String getGB(String action) {
        byte[] Rd_Out; //中间用ISO-8859-1过渡
hh authored
719
720
721
722
723
724
725
726
727
728
729
        String data = null;
        try {
            Rd_Out = action.getBytes("8859_1");
            data = new String(Rd_Out, "GB2312"); //转换成GB2312字符
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return data;
    }
730
    /**
易文鹏 authored
731
     * @param action  MOM行为
732
733
734
     * @param JObject 行为参数
     * @return
     */
易文鹏 authored
735
    public ReturnInfo postMOM(String action, JSONObject JObject, String apiName) {
736
        String url = addressService.selectAddress(QuantityConstant.MOM);
易文鹏 authored
737
        return CallaMOM.getMsg(action, JObject, apiName, url);
hh authored
738
    }
hh authored
739
hh authored
740
hh authored
741
}