Blame view

src/main/java/com/huaheng/api/mes/controller/MesReceiptController.java 18.4 KB
易文鹏 authored
1
2
3
4
5
package com.huaheng.api.mes.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
6
import com.huaheng.api.general.domain.CallEmptyContainer;
易文鹏 authored
7
8
9
import com.huaheng.api.mes.dto.Detail;
import com.huaheng.api.mes.dto.GetOrderHistoryDTO;
import com.huaheng.api.mes.dto.ReceiptDTO;
易文鹏 authored
10
11
12
13
14
import com.huaheng.api.mes.result.ReturnInfo;
import com.huaheng.api.mes.service.IMesService;
import com.huaheng.api.mes.utils.CallaMOM;
import com.huaheng.api.mes.utils.SqlServer;
import com.huaheng.api.mes.vo.InventoryTransactionVO;
易文鹏 authored
15
import com.huaheng.api.mes.vo.InventoryVO;
16
import com.huaheng.api.wcs.service.taskAssignService.TaskAssignService;
易文鹏 authored
17
18
19
20
21
22
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.StringUtils;
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.pc.config.address.service.AddressService;
23
24
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
25
import com.huaheng.pc.config.labelCode.domain.LabelCode;
26
import com.huaheng.pc.config.location.service.LocationService;
易文鹏 authored
27
28
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
易文鹏 authored
29
import com.huaheng.pc.config.station.service.StationService;
易文鹏 authored
30
31
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
易文鹏 authored
32
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
易文鹏 authored
33
34
35
36
37
38
39
40
41
42
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.momLog.service.IMomLogService;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
43
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
易文鹏 authored
44
import io.swagger.annotations.ApiOperation;
45
import lombok.extern.slf4j.Slf4j;
易文鹏 authored
46
47
48
49
50
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
51
import java.math.BigDecimal;
易文鹏 authored
52
53
import java.sql.ResultSet;
import java.sql.SQLException;
易文鹏 authored
54
55
56
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
易文鹏 authored
57
58
59


@RestController
60
@Slf4j
易文鹏 authored
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@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;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private InventoryTransactionService inventoryTransactionService;
    @Resource
    private MaterialService materialService;
    @Resource
    private IMomLogService momLogService;
    @Resource
    private IMesService mesService;
    @Resource
    private IUserService userService;
    @Resource
    private AddressService addressService;
87
88
89
90
91
92
93
94
95
96
    @Resource
    private TaskAssignService taskAssignService;
    @Resource
    private ContainerService containerService;
    @Resource
    private LocationService locationService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private ContainerTypeService containerTypeService;
易文鹏 authored
97
98
    @Resource
    private StationService stationService;
易文鹏 authored
99
易文鹏 authored
100
101
102
    @Resource
    private InventoryHeaderService inventoryHeaderService;
易文鹏 authored
103
104
105
106
107
    /**
     * 入库单单据取消
     */
    @PostMapping("/cancelEnterWarehouse")
    @ApiOperation("入库单单据取消")
108
    @ApiLogger(apiName = "入库单单据取消", from = "ROBOT")
易文鹏 authored
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    public AjaxResult cancelEnterWarehouse(@RequestBody ReceiptDTO receiptDTO) {
        AjaxResult ajaxResult = handleQuest("cancelEnterWarehouse", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.cancelEnterWarehouse(receiptDTO);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }


    /**
     * 出库单单据取消
     */
    @PostMapping("/cancelOutWarehouse")
    @ApiOperation("出库单单据取消")
126
    @ApiLogger(apiName = "出库单单据取消", from = "ROBOT")
易文鹏 authored
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
    public AjaxResult cancelOutWarehouse(@RequestBody ReceiptDTO receiptDTO) {
        AjaxResult ajaxResult = handleQuest("cancelOutWarehouse", new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = mesService.cancelOutWarehouse(receiptDTO);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }


    /**
     * 查询库存
     */
    @PostMapping("/searchInventory")
143
    @ApiLogger(apiName = "查询库存", from = "ROBOT")
易文鹏 authored
144
145
146
    @ApiOperation("查询库存")
    public AjaxResult searchInventory(@RequestBody Detail detailed) {
147
        String materialName = detailed.getMaterialName();
易文鹏 authored
148
149
150
151
152
        String materialCode = detailed.getMaterialCode();
        String containerCode = detailed.getContainerCode();

        LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        // 物料编码
153
        if (StringUtils.isNotEmpty(materialName)) {
易文鹏 authored
154
155
156
            lambdaQueryWrapper.eq(InventoryDetail::getMaterialName, materialName);
        }
        // 物料名称
157
        if (StringUtils.isNotEmpty(materialCode)) {
易文鹏 authored
158
159
160
            lambdaQueryWrapper.eq(InventoryDetail::getMaterialCode, materialCode);
        }
        // 托盘号
161
        if (StringUtils.isNotEmpty(containerCode)) {
易文鹏 authored
162
163
164
            lambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode);
        }
165
        if (StringUtils.isEmpty(materialName) && StringUtils.isEmpty(containerCode) && StringUtils.isEmpty(containerCode)) {
易文鹏 authored
166
167
168
169
170
            lambdaQueryWrapper.gt(InventoryDetail::getQty, 0);
        }
        List<InventoryDetail> detailList = inventoryDetailService.list(lambdaQueryWrapper);

        List<InventoryVO> inventoryVOList = new ArrayList<>();
171
        detailList.forEach(detail -> {
易文鹏 authored
172
            InventoryVO inventoryVO = new InventoryVO();
173
            BeanUtils.copyProperties(detail, inventoryVO);
易文鹏 authored
174
175
176
177
178
179
180
181
182
183
            inventoryVO.setWarehouse("035");
            inventoryVOList.add(inventoryVO);
        });

        return AjaxResult.success(inventoryVOList);

    }

    /**
     * 获取出入库单明细记录
184
     *
易文鹏 authored
185
186
187
     * @return AjaxResult
     */
    @PostMapping("/getShipmentDetail")
188
    @ApiLogger(apiName = "获取出入库单明细记录", from = "ROBOT")
易文鹏 authored
189
190
191
    @ApiOperation("获取出入库单明细记录")
    public AjaxResult getShipmentDetail(@RequestBody GetOrderHistoryDTO getOrderHistoryDTO) {
192
        if (StringUtils.isEmpty(getOrderHistoryDTO.getEndTime()) || StringUtils.isEmpty(getOrderHistoryDTO.getStartTime())) {
易文鹏 authored
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
            return AjaxResult.error("开始时间和结束时间不能为空!!!");
        }
        LambdaQueryWrapper<InventoryTransaction> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper
                .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);
    }
209
210
211
    public List<LabelCode> getLabelCodeList() {
        List<LabelCode> labelCodeList = new ArrayList<>();
        try {
易文鹏 authored
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
            String sql = "SELECT * FROM [dbo].[V_WCS_Code] WHERE datediff( DAY, createtime, getdate( ) ) = 0";
            ResultSet resultSet = SqlServer.find(sql);
            if (resultSet == null) {
                return labelCodeList;
            }
            while (resultSet.next()) {
                // 字段要与表一致
                String code = resultSet.getString("materialCode");//物料编码
                String name = resultSet.getString("materialName");//物料名称
                String unit = resultSet.getString("materialUnit");//单位名称
                String spec = resultSet.getString("materialSpec");//物料规格
                String fcode = resultSet.getString("Fcode");//标签条码
                String batch = resultSet.getString("BatchNo");//批次
                BigDecimal qty = resultSet.getBigDecimal("Qty");//qty
                LabelCode labelCode = new LabelCode();
                labelCode.setCode(code);
                labelCode.setName(name);
                labelCode.setUnit(unit);
                labelCode.setSpec(spec);
                labelCode.setQty(qty);
                labelCode.setLabelCode(fcode);
                labelCode.setBatch(batch);
                labelCode.setWarehouseCode("CS0001");
                labelCode.setCompanyCode("BHF");
                labelCodeList.add(labelCode);
            }
        } catch (SQLException throwable) {
            throwable.printStackTrace();
        }
        log.debug("******************************同步标签条码数据:" + labelCodeList.size() + "条数据!!!");
        return labelCodeList;
    }

    public List<LabelCode> getAllLabelCodeList() {
        List<LabelCode> labelCodeList = new ArrayList<>();
        try {
            String sql = "SELECT * FROM [dbo].[V_WCS_Code]";
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
            ResultSet resultSet = SqlServer.find(sql);
            if (resultSet == null) {
                return labelCodeList;
            }
            while (resultSet.next()) {
                // 字段要与表一致
                String code = resultSet.getString("materialCode");//物料编码
                String name = resultSet.getString("materialName");//物料名称
                String unit = resultSet.getString("materialUnit");//单位名称
                String spec = resultSet.getString("materialSpec");//物料规格
                String fcode = resultSet.getString("Fcode");//标签条码
                String batch = resultSet.getString("BatchNo");//批次
                BigDecimal qty = resultSet.getBigDecimal("Qty");//qty
                LabelCode labelCode = new LabelCode();
                labelCode.setCode(code);
                labelCode.setName(name);
                labelCode.setUnit(unit);
                labelCode.setSpec(spec);
                labelCode.setQty(qty);
                labelCode.setLabelCode(fcode);
                labelCode.setBatch(batch);
                labelCode.setWarehouseCode("CS0001");
                labelCode.setCompanyCode("BHF");
                labelCodeList.add(labelCode);
            }
        } catch (SQLException throwable) {
            throwable.printStackTrace();
        }
        log.debug("******************************同步标签条码数据:" + labelCodeList.size() + "条数据!!!");
        return labelCodeList;
    }
280
281
易文鹏 authored
282
283
284
285
    /**
     * 获取sqlServer数据库中物料信息, 同步到本地数据库中
     */
    @PostMapping("/getMaterial")
易文鹏 authored
286
    @ApiOperation("更新物料信息")
287
    public List<Material> getMaterial() {
易文鹏 authored
288
289
        List<Material> materialList = new ArrayList<>();
        try {
易文鹏 authored
290
291
            // */10 * * * *
            String sql = "SELECT * FROM [dbo].[V_WCS_MATERIAL] WHERE ( datediff( DAY, createtime, getdate( ) ) = 0 OR updatetime >= DATEADD( MINUTE, - 10, GETDATE( ) ) )";
易文鹏 authored
292
293
294
295
296
297
298
299
300
            ResultSet resultSet = SqlServer.find(sql);
            if (resultSet == null) {
                return materialList;
            }
            while (resultSet.next()) {
                String code = resultSet.getString("materialCode");//物料编码
                String name = resultSet.getString("materialName");//物料名称
                String unit = resultSet.getString("materialUnit");//单位名称
                String spec = resultSet.getString("materialSpec");//物料规格
301
                Integer ERPID = resultSet.getInt("materialId");//id
易文鹏 authored
302
303
304
305
306
307
308
309
                Date createtime = resultSet.getTimestamp("createtime");//创建时间
                Date updatetime = resultSet.getTimestamp("updatetime");//更新时间

                Material material = new Material();
                material.setCode(code);
                material.setName(name);
                material.setUnit(unit);
                material.setSpec(spec);
310
                material.setERPID(ERPID);
易文鹏 authored
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
                material.setCreated(createtime);
                material.setLastUpdated(updatetime);
                material.setWarehouseCode("CS0001");
                material.setCompanyCode("BHF");
                materialList.add(material);
            }
        } catch (SQLException throwable) {
            throwable.printStackTrace();
        }
        log.debug("******************************同步物料:" + materialList.size() + "条数据!!!");
        return materialList;
    }


    @ApiOperation("获取全部物料信息")
    public List<Material> getAllMaterial() {
        List<Material> materialList = new ArrayList<>();
        try {
            String sql = "SELECT * FROM [dbo].[V_WCS_MATERIAL]";
易文鹏 authored
330
            ResultSet resultSet = SqlServer.find(sql);
331
            if (resultSet == null) {
易文鹏 authored
332
333
                return materialList;
            }
334
335
336
337
338
            while (resultSet.next()) {
                String code = resultSet.getString("materialCode");//物料编码
                String name = resultSet.getString("materialName");//物料名称
                String unit = resultSet.getString("materialUnit");//单位名称
                String spec = resultSet.getString("materialSpec");//物料规格
339
                Integer ERPID = resultSet.getInt("materialId");//id
340
341
                Date createtime = resultSet.getTimestamp("createtime");//创建时间
                Date updatetime = resultSet.getTimestamp("updatetime");//更新时间
易文鹏 authored
342
343
344
345

                Material material = new Material();
                material.setCode(code);
                material.setName(name);
346
                material.setUnit(unit);
易文鹏 authored
347
                material.setSpec(spec);
348
                material.setERPID(ERPID);
349
350
                material.setCreated(createtime);
                material.setLastUpdated(updatetime);
易文鹏 authored
351
352
353
354
355
356
357
                material.setWarehouseCode("CS0001");
                material.setCompanyCode("BHF");
                materialList.add(material);
            }
        } catch (SQLException throwable) {
            throwable.printStackTrace();
        }
358
        log.debug("******************************同步物料:" + materialList.size() + "条数据!!!");
易文鹏 authored
359
360
361
        return materialList;
    }
362
易文鹏 authored
363
364
365
    /**
     * 查询站台任务明细列表
     */
366
    @ApiLogger(apiName = "查询站台任务明细列表", from = "ROBOT")
易文鹏 authored
367
368
    @PostMapping("/kanbanInfo")
    @CrossOrigin
369
    public AjaxResult kanbanInfo(@RequestBody TaskDetail taskDetail) {
易文鹏 authored
370
371
372
373
374
375
        String fromLocation = taskDetail.getFromLocation();
        if (StringUtils.isEmpty(fromLocation)) {
            return AjaxResult.error("站台不能为空!!!");
        }
        LambdaQueryWrapper<TaskDetail> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(TaskDetail::getFromLocation, fromLocation)
376
                .lt(TaskDetail::getStatus, "100");
易文鹏 authored
377
378
379
380
381
        List<TaskDetail> taskDetailList = taskDetailService.list(wrapper);
        return AjaxResult.success(taskDetailList);
    }

    /**
382
383
384
385
     * utf-8  GB2312
     */
    public String getGB(String action) {
        byte[] Rd_Out; //中间用ISO-8859-1过渡
易文鹏 authored
386
387
388
389
390
391
392
393
394
395
396
        String data = null;
        try {
            Rd_Out = action.getBytes("8859_1");
            data = new String(Rd_Out, "GB2312"); //转换成GB2312字符
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return data;
    }
397
398
399
400
401
402
    /**
     * @param action  MOM行为
     * @param JObject 行为参数
     * @return
     */
    public ReturnInfo postMOM(String action, JSONObject JObject, String apiName) {
易文鹏 authored
403
        String url = addressService.selectAddress(QuantityConstant.MOM);
404
        return CallaMOM.getMsg(action, JObject, apiName, url);
易文鹏 authored
405
406
407
    }
408
409
410
411
412
413
414
415
416
417
    /**
     * MES呼叫空托盘
     */
    @PostMapping("/callEmptyContainer")
    @ResponseBody
    @ApiLogger(apiName = "MES呼叫空托盘", from = "MES")
    public AjaxResult callEmptyContainer(@RequestBody CallEmptyContainer callEmptyContainer) {
        if (StringUtils.isEmpty(callEmptyContainer.getContainerType())) {
            return AjaxResult.error("托盘类型为空");
        }
418
        return handleQuest("callEmptyContainer", () -> mesService.callEmptyContainer(callEmptyContainer));
易文鹏 authored
419
    }
易文鹏 authored
420
易文鹏 authored
421
422
423
424
425
426
427
428
429
430
    /**
     * MES空托盘入库
     */
    @PostMapping("/inEmptyContainer")
    @ResponseBody
    @ApiLogger(apiName = "MES空托盘入库", from = "MES")
    public AjaxResult inEmptyContainer(@RequestBody CallEmptyContainer callEmptyContainer) {
        if (StringUtils.isEmpty(callEmptyContainer.getContainerCode())) {
            return AjaxResult.error("托盘号不能为空");
        }
431
        return handleQuest("inEmptyContainer", () -> mesService.inEmptyContainer(callEmptyContainer));
易文鹏 authored
432
    }
433
434
易文鹏 authored
435
436
437
438
439
440
441
442
443
    /**
     * WCS呼叫空托盘
     */
    @PostMapping("/outEmptyContainer")
    @ResponseBody
    @ApiLogger(apiName = "WCS呼叫空托盘", from = "WCS")
    public AjaxResult outEmptyContainer(@RequestBody CallEmptyContainer callEmptyContainer) {
        if (StringUtils.isEmpty(callEmptyContainer.getContainerType())) {
            return AjaxResult.error("托盘类型为空");
444
        }
445
        return handleQuest("outEmptyContainer", () -> mesService.outEmptyContainer(callEmptyContainer));
446
447
    }
易文鹏 authored
448
}