pang.jiabao
2025-03-07 dcdb2b8cf1b0c5d05900acec72c80caf3bb5616c
1
2
3
4
5
6
7
8
9
10
11
12
13
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
47
48
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
78
79
80
81
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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
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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package com.zy.asrs.wms.asrs.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.common.domain.CodeRes;
import com.zy.asrs.common.domain.enums.LoginSystemType;
import com.zy.asrs.framework.annotations.ManagerAuth;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.framework.exception.CoolException;
import com.zy.asrs.wms.asrs.entity.CacheSite;
import com.zy.asrs.wms.asrs.entity.Order;
import com.zy.asrs.wms.asrs.entity.WaitPakin;
import com.zy.asrs.wms.asrs.entity.dto.OrderInfoDto;
import com.zy.asrs.wms.asrs.entity.dto.PickSheetDetlDto;
import com.zy.asrs.wms.asrs.entity.dto.ShippingOrderDetlDto;
import com.zy.asrs.wms.asrs.entity.param.BatchMergeOrdersParam;
import com.zy.asrs.wms.asrs.entity.param.PakinOnShelvesParams;
import com.zy.asrs.wms.asrs.service.MobileService;
import com.zy.asrs.wms.asrs.service.OrderService;
import com.zy.asrs.wms.asrs.service.WaitPakinService;
import com.zy.asrs.wms.system.controller.BaseController;
import com.zy.asrs.wms.system.entity.Host;
import com.zy.asrs.wms.system.entity.User;
import com.zy.asrs.wms.system.entity.UserLogin;
import com.zy.asrs.wms.system.service.UserLoginService;
import com.zy.asrs.wms.system.service.UserService;
import io.jsonwebtoken.lang.Collections;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@RequestMapping("/pda")
@RestController
public class MobileController extends BaseController {
 
    @Value("${super.pwd}")
    private String superPwd;
    @Autowired
    private UserService userService;
    @Autowired
    private UserLoginService userLoginService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private MobileService mobileService;
    @Autowired
    private WaitPakinService waitPakinService;
 
    /**
     * 获取用户机构
     * @return
     */
    @GetMapping("/current/host")
    public R getUserHost() {
        List<Host> hosts = mobileService.getHosts();
        return R.ok(hosts);
    }
 
    /**
     * 入库单据--扫码获取订单明细列表
     * @param barcode
     * @return
     */
    @PostMapping("/mat/auth")
    public R getProductForBarcode(@RequestBody Map<String, String> barcode) {
        if (Objects.isNull(barcode)) {
            return  R.error("参数不能为空!!");
        }
        if (StringUtil.isNullOrEmpty(barcode.get("barcode"))) {
            return  R.error("条码不能为空!!");
        }
        Order order =  orderService.selectByBarcode(barcode.get("barcode"));
 
        if (Objects.isNull(order)) {
            return R.error("订单不存在!");
        }
 
        List<OrderInfoDto> orders = orderService.getDetlForOrderId(order.getId());
 
        return R.ok(orders);
    }
 
    /**
     * 平库上架
     * PDA扫码入库
     * 1. 绑定库位号与拖盘码
     * 2. 库位置为在库状态
     * @return
     */
    @PostMapping("/matnr/in/barcode")
    public R pakinToStock(@RequestBody PakinOnShelvesParams shelvesParams) {
        if (StringUtil.isNullOrEmpty(shelvesParams.getBarcode())) {
            return R.error("拖盘码不能为空!!");
        }
        if (StringUtil.isNullOrEmpty(shelvesParams.getLoc())) {
            return R.error("库位不能为空!!");
        }
        //TODO 绑定库位,添加库位明细
        if (mobileService.pakinToStock(shelvesParams)) {
            return R.ok("入库成功!!");
        } else {
            return R.error("入库失败!!");
        }
 
    }
 
    /**
     * 获取拖盘码绑定商品
     * @return
     */
    @GetMapping("/barcode/matnr/{code}")
    public R getAllGoods(@PathVariable String code) {
        if (StringUtil.isNullOrEmpty(code)) {
            return R.error("托盘码不能为空!!");
        }
 
        String str = code.trim();
        // 确保字符串长度至少为8
        if (str.length() >= 8) {
           code = str.substring(str.length() - 8);
        } else {
            return R.error("字符串长度小于8,无法获取后8位");
        }
 
        List<WaitPakin> waitPakins = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, code));
 
        return R.ok(waitPakins);
    }
 
 
    @GetMapping("/login.action")
    @ManagerAuth(value = ManagerAuth.Auth.NONE, memo = "登录")
    public R loginAction(String username, String password, Boolean wms) {
        if (username.equals("super") && password.equals(Cools.md5(superPwd))) {
            Map<String, Object> res = new HashMap<>();
            res.put("username", username);
            res.put("token", Cools.enToken(System.currentTimeMillis() + username, superPwd));
            return R.ok(res);
        }
        LambdaQueryWrapper<User> userWrapper = new LambdaQueryWrapper<>();
        userWrapper.eq(User::getUsername, username);
        User user = userService.getOne(userWrapper);
        if (Cools.isEmpty(user)) {
            return R.parse(CodeRes.USER_10001);
        }
        if (user.getStatus() != 1) {
            return R.parse(CodeRes.USER_10002);
        }
        if (!user.getPassword().equals(password)) {
            return R.parse(CodeRes.USER_10003);
        }
        String system = null;//登陆系统
        if (wms) {
            system = String.valueOf(LoginSystemType.WMS);
        }else {
            system = String.valueOf(LoginSystemType.WCS);
        }
        String token = Cools.enToken(System.currentTimeMillis() + username, user.getPassword());
        userLoginService.remove(new LambdaQueryWrapper<UserLogin>().eq(UserLogin::getUserId, user.getId()).eq(UserLogin::getSystemCode, system));
        UserLogin userLogin = new UserLogin();
        userLogin.setUserId(user.getId());
        userLogin.setToken(token);
        userLogin.setCreateTime(new Date());
        userLogin.setSystemCode(system);
//        if (user.getRoleId() == 2) {
//            userLogin.setHostId(hostService.getTop1().getId());
//        }
        userLoginService.save(userLogin);
        Map<String, Object> res = new HashMap<>();
        res.put("username", user.getUsername());
        res.put("token", token);
        return R.ok(res);
    }
 
 
    @PostMapping("/comb/auth")
    public  R combMats(@RequestBody BatchMergeOrdersParam ordersParam) {
        if (StringUtil.isNullOrEmpty(ordersParam.getOrderNo())) {
            return R.error("订单号不能为空!!");
        }
        if (StringUtil.isNullOrEmpty(ordersParam.getMergeNo())) {
            return R.error("托盘码不能为空!!");
        }
        if (Collections.isEmpty(ordersParam.getOrderDetls())) {
            return R.error("订单明细不能为空!!");
        }
 
        String str = ordersParam.getMergeNo().trim();
        // 确保字符串长度至少为8
        if (str.length() >= 8) {
            ordersParam.setMergeNo(str.substring(str.length() - 8));
        } else {
            return R.error("字符串长度小于8,无法获取后8位");
        }
 
       boolean result = mobileService.batchMergeOrders(ordersParam);
        if (result) {
            return R.ok("组托成功!!");
        } else {
            return R.ok("组托失败!!");
        }
    }
 
    /**
     * 获取拣货明细
     * @return
     */
    @GetMapping("/pick/detl/{code}")
    public R pickDetlByPickNo(@PathVariable String code) {
        if (StringUtil.isNullOrEmpty(code)) {
            return R.error("拣货单据编码不能为空!!");
        }
        PickSheetDetlDto pickSheetDetls =  mobileService.outFlatSheet(code);
 
        return R.ok(pickSheetDetls);
    }
 
    /**
     * 拣货单确认出库
     * @param code
     * @return
     */
    @GetMapping("/pick/confirm/{code}")
    public R confirmOutFlatSheet(@PathVariable String code) {
        if (StringUtil.isNullOrEmpty(code)) {
            return R.error("拣货单据编码不能为空!!");
        }
        if (!mobileService.confirmFlatSheet(code)) {
            return R.error("出库失败!!");
        }
        return R.ok("出库成功!!");
    }
 
 
    /**
     * 获取播种位
     * @return
     */
    @GetMapping("/pick/seed/locs")
    public R seedLocs() {
        List<CacheSite> sites = mobileService.getSeedLocs();
        return R.ok(sites);
    }
 
    /**
     * 订单绑定站点
     * @param param
     * @return
     */
    @PostMapping("/pick/seed/bind")
    public R bindLoc(@RequestBody Map<String, Object> param) {
        if (Objects.isNull(param)) {
            throw new CoolException("请求参数不能为空!!");
        }
        if (Objects.isNull(param.get("barcode"))) {
            throw new CoolException("播种墙容器编码不能为空");
        }
        if (Objects.isNull(param.get("orderNo"))) {
            throw new CoolException("订单编号不能为空!!");
        }
        if (Objects.isNull(param.get("siteNo"))) {
            throw new CoolException("播种站点不能为空!!");
        }
        if (Objects.isNull(param.get("type"))) {
            throw new CoolException("参数类型不能为空!!");
        }
       boolean result =  mobileService.bindOrderBySite(param);
        if (result) {
            return R.ok("绑定成功!!");
        } else {
            return R.error("绑定失败!!");
        }
    }
 
 
    /**
     * 获取发货订单明细
     * @return
     */
    @PostMapping("/shipping/order/detl")
    public R  getOrderDetl(@RequestBody Map<String, Object> params) {
        if (Objects.isNull(params)) {
            throw new CoolException("参数不能为空!!");
        }
        return mobileService.selectShippingDetl(params);
    }
 
    /**
     * 确认发货单明细
     * @return
     */
    @PostMapping("/shipping/confirm")
    public R confirmShipping(@RequestBody List<ShippingOrderDetlDto> params) {
        if (params.isEmpty()) {
            throw new CoolException("发货单明细不能为空!!");
        }
        return mobileService.confirmShippingDetl(params);
    }
 
 
 
}