Blame view

src/main/java/com/huaheng/api/sap/controller/WMSApiController.java 6.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
package com.huaheng.api.sap.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONException;
import com.huaheng.api.sap.domain.ReceiptQuick;
import com.huaheng.api.sap.domain.ZarDomain;
import com.huaheng.api.sap.service.WmsCreateTaskApiService;
13
import com.huaheng.api.sap.service.WmsCreateTaskForShipmentApiService;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import com.huaheng.api.sap.service.ZarApiService;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.sap.domain.Zarsh;
import com.huaheng.pc.sap.service.BackSapStatusService;
import com.huaheng.pc.sap.service.LockSapUniqueIdService;
import com.huaheng.pc.sap.service.SapTaskLogService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/api/zarapi")
@Api(tags = {"入库单接口"}, value = "入库单接口receipt")
public class WMSApiController extends BaseController {

    @Resource
    private ZarApiService zarApiService;
    @Resource
    private BackSapStatusService backSapStatusService;
    @Resource
    private SapTaskLogService sapTaskLogService;
    @Resource
    private LockSapUniqueIdService lockSapUniqueIdService;
    @Resource
    private WmsCreateTaskApiService wmsCreateTaskApiService;
47
48
    @Resource
    private WmsCreateTaskForShipmentApiService wmsCreateTaskForShipmentApiService;
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

    /**
     * WMS模拟SAP下发任务单据
     */
    @Log(title = "WMS-PDA下发任务单据", action = BusinessType.INSERT)
    @PostMapping("/quickReceipt")
    @ApiOperation("WMS-PDA下发任务单据")
    @ResponseBody
    @ApiLogger(apiName = "WMS-PDA下发任务单据", from = "PDA")
    public AjaxResult quickReceipt(@RequestBody @ApiParam(value = "收货单") List<ReceiptQuick> receiptQuicks) {
        if (receiptQuicks == null || receiptQuicks.size() <= 0) {
            throw new JSONException("没有收货信息");
        }
        if (ShiroUtils.getUser() == null) {
            return AjaxResult.error("登录超时,请重新登录");
        } else {
            if (StringUtils.isEmpty(ShiroUtils.getZoneCode())) {
                return AjaxResult.error("登录超时,请重新登录");
            }
        }
        AjaxResult ajaxResult1 = wmsCreateTaskApiService.createZarshBywms(receiptQuicks);
        if (ajaxResult1.hasErr()) {
            return ajaxResult1;
        }
        ZarDomain zarDomain = (ZarDomain)ajaxResult1.getData();
        Zarsh zarsh = zarDomain.getZarsh();
        if (zarsh == null) {
            throw new ServiceException("zarsh参数为空");
        }
78
        AjaxResult ajaxResult = handleMultiProcess("saveSapTask", new BaseController.MultiProcessListener() {
79
80
81
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = null;
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
                try {
                    ajaxResult = zarApiService.saveSapData(zarDomain);
                    sapTaskLogService.addSapTaskLog(zarDomain, ajaxResult.getMsg(), 0);
                    if (ajaxResult.hasErr()) {
                        lockSapUniqueIdService.lockStaionByUniqueId(zarsh);
                    } else {
                        lockSapUniqueIdService.unlockStaionByUniqueId(zarsh);
                    }
                } catch (Exception e) {
                    // 调用sap的api,传递任务状态
                    ajaxResult = AjaxResult.error(e.getMessage());
                    backSapStatusService.addBackSapStatus(zarsh.getUniqueId(), zarsh.getLgnum(), null, "1", "C", null, e.getMessage());
                    sapTaskLogService.addSapTaskLog(zarDomain, e.getMessage(), 1);
                    lockSapUniqueIdService.lockStaionByUniqueId(zarsh);
                }
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    /**
     * WMS模拟SAP下发出库任务单据
     */
    @Log(title = "WMS-PDA下发任务单据", action = BusinessType.INSERT)
    @PostMapping("/quickShipment")
    @ApiOperation("WMS-PDA下发任务单据")
    @ResponseBody
    @ApiLogger(apiName = "WMS下发出库任务单据", from = "PC")
    public AjaxResult quickShipment(String id, String port) {
        if (StringUtils.isEmpty(id)) {
            throw new JSONException("没有库存id");
        }
        if (StringUtils.isEmpty(port)) {
            throw new JSONException("没有选择站台");
        }

        AjaxResult ajaxResult1 = wmsCreateTaskForShipmentApiService.shipmentContainer(id, port);
        if (ajaxResult1.hasErr()) {
            return ajaxResult1;
        }
        ZarDomain zarDomain = (ZarDomain)ajaxResult1.getData();
        Zarsh zarsh = zarDomain.getZarsh();
        if (zarsh == null) {
            throw new ServiceException("zarsh参数为空");
        }
128
        AjaxResult ajaxResult = handleMultiProcess("saveSapTaskShipment", new BaseController.MultiProcessListener() {
129
130
131
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = null;
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
                try {
                    ajaxResult = zarApiService.saveSapData(zarDomain);
                    sapTaskLogService.addSapTaskLog(zarDomain, ajaxResult.getMsg(), 0);
                    if (ajaxResult.hasErr()) {
                        lockSapUniqueIdService.lockStaionByUniqueId(zarsh);
                    } else {
                        lockSapUniqueIdService.unlockStaionByUniqueId(zarsh);
                    }
                } catch (Exception e) {
                    // 调用sap的api,传递任务状态
                    ajaxResult = AjaxResult.error(e.getMessage());
                    backSapStatusService.addBackSapStatus(zarsh.getUniqueId(), zarsh.getLgnum(), null, "1", "C", null, e.getMessage());
                    sapTaskLogService.addSapTaskLog(zarDomain, e.getMessage(), 1);
                    lockSapUniqueIdService.lockStaionByUniqueId(zarsh);
                }
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

}