Blame view

src/main/java/com/huaheng/mobile/shipment/MobileShipmentController.java 26.1 KB
游杰 authored
1
2
3
package com.huaheng.mobile.shipment;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
周鸿 authored
4
import com.huaheng.common.utils.Wrappers;
游杰 authored
5
6
import com.huaheng.api.general.domain.ReceiptDomain;
import com.huaheng.api.general.domain.ShipmentDomain;
7
import com.huaheng.common.constant.QuantityConstant;
mahuandong authored
8
import com.huaheng.common.exception.BusinessException;
9
import com.huaheng.common.exception.service.ServiceException;
游杰 authored
10
11
12
13
14
15
16
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
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.mobile.invenory.TaskIds;
游杰 authored
17
import com.huaheng.mobile.receipt.ReceiptBill;
游杰 authored
18
19
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
20
21
22
23
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
游杰 authored
24
25
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
游杰 authored
26
27
28
import com.huaheng.pc.config.receiptType.domain.ReceiptType;
import com.huaheng.pc.config.shipmentType.domain.ShipmentType;
import com.huaheng.pc.config.shipmentType.service.ShipmentTypeService;
29
30
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
31
32
33
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
游杰 authored
34
35
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
36
37
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentCombinationModel;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
游杰 authored
38
39
40
41
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
游杰 authored
42
import com.huaheng.pc.shipment.shipmentHeader.mapper.ShipmentHeaderMapper;
游杰 authored
43
44
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
45
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
46
import com.huaheng.pc.task.taskHeader.service.ShipmentTaskService;
游杰 authored
47
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
游杰 authored
48
import io.swagger.annotations.ApiOperation;
游杰 authored
49
50
51
52
53
54
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
55
import java.math.BigDecimal;
游杰 authored
56
57
import java.text.SimpleDateFormat;
import java.util.*;
58
import java.util.stream.Collectors;
游杰 authored
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

/**
 * @author mahua
 * @ClassName MobileShipmentController
 * @projectName wms_xinyi
 * @description: TODO
 * @date 2020/2/1115:29
 */
@RestController
@RequestMapping("/mobile/shipment")
public class MobileShipmentController extends BaseController {
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
    @Resource
    private ShipmentDetailService shipmentDetailService;
    @Resource
    private ShipmentContainerHeaderService shipmentContainerHeaderService;
    @Resource
77
    private ShipmentTaskService shipmentTaskService;
78
    @Resource
游杰 authored
79
    private ShipmentTypeService shipmentTypeService;
80
81
    @Resource
    private InventoryDetailService inventoryDetailService;
游杰 authored
82
83
84
85
    @Resource
    private ShipmentHeaderMapper shipmentHeaderMapper;
    @Resource
    private MaterialService  materialService;
86
87
    @Resource
    private StationService stationService;
游杰 authored
88
89
90
91
92
93
    @Resource
    private ContainerService containerService;

    @Resource
    private LocationService locationService;
94
95
96

    @Resource
    private TaskHeaderService taskHeaderService;
游杰 authored
97
    /**
mahuandong authored
98
     * 自动组盘
99
     * @param
mahuandong authored
100
101
102
103
     * @return
     */
    @PostMapping("/autoCombination")
    @ResponseBody
104
105
106
107
108
    public AjaxResult autoCombination(@RequestBody List<ShipmentDetail> shipmentDetailList) {
        if(shipmentDetailList == null || shipmentDetailList.size() <= 0) {
            return AjaxResult.error("组盘信息为空");
        }
        AjaxResult ajaxResult = shipmentContainerHeaderService.autoCombination(shipmentDetailList);
mahuandong authored
109
110
        return ajaxResult;
    }
huhai authored
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
     * 手动组盘
     * @param
     * @return
     */
    @PostMapping("/combination")
    @ResponseBody
    public AjaxResult combination(@RequestBody List<ShipmentMaterial> shipmentMaterials){
        if(shipmentMaterials == null || shipmentMaterials.size() <= 0) {
            return AjaxResult.error("组盘信息为空");
        }
        List<Integer> taskIds = new ArrayList<>();
        for(ShipmentMaterial shipmentMaterial : shipmentMaterials) {
            if(shipmentMaterial.getQty() == 0) {
                continue;
            }
            ShipmentCombinationModel shipmentCombination = new ShipmentCombinationModel();
            String containerCode = shipmentMaterial.getContainerCode();
            String locationCode = shipmentMaterial.getLocaitonCode();
            shipmentCombination.setShipQty(new BigDecimal(shipmentMaterial.getQty()));
            shipmentCombination.setTaskType(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
            shipmentCombination.setCompanyCode(shipmentMaterial.getCompanyCode());
            shipmentCombination.setShipmentDetailId(shipmentMaterial.getShipmentDetailId());
            LambdaQueryWrapper<InventoryDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
            lambdaQueryWrapper.eq(InventoryDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
                             .eq(StringUtils.isNotEmpty(containerCode), InventoryDetail::getContainerCode, containerCode)
                             .eq(StringUtils.isNotEmpty(locationCode), InventoryDetail::getLocationCode, locationCode)
                             .eq(InventoryDetail::getMaterialCode, shipmentMaterial.getMaterialCode());
            InventoryDetail inventoryDetail = inventoryDetailService.getOne(lambdaQueryWrapper);
            int qty =  inventoryDetail.getQty().subtract(inventoryDetail.getTaskQty()).intValue();
            if(shipmentMaterial.getQty() > qty) {
                return AjaxResult.error("出库数量必须小于库存数量");
            }
            shipmentCombination.setInventoryDetailId(inventoryDetail.getId());
            ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.combination(shipmentCombination);
            taskIds.add(shipmentContainerHeader.getId());
        }
        if(taskIds.size() > 0) {
            return AjaxResult.success(taskIds);
        } else {
            return AjaxResult.error("组盘失败");
        }
    }

    /**
游杰 authored
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
     * 查询出库单主列表
     */
    @Log(title = "出库-出库单", operating="查看出库主单", action = BusinessType.GRANT)
    @PostMapping("/list")
    public AjaxResult list(@RequestBody @ApiParam(value = "出库单号-referCode、货主编码-companyCode、出库单类型-shipmentType") Map<String, String> param) {
        if (StringUtils.isEmpty(param.get("companyCode"))) {
            return AjaxResult.error("上游系统单号为空");
        } else if (StringUtils.isEmpty(param.get("shipmentType"))) {
            return AjaxResult.error("类型为空");
        } else if (StringUtils.isEmpty(param.get("referCode"))) {
            return AjaxResult.error("上游系统单号为空");
        }
        LambdaQueryWrapper<ShipmentHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(ShipmentHeader::getDeleted,false)
                .in(ShipmentHeader::getCompanyCode, param.get("companyCode"))
                .eq(ShipmentHeader::getShipmentType,param.get("shipmentType"))
                .eq(ShipmentHeader::getReferCode, param.get("referCode"))
                .orderByDesc(ShipmentHeader::getId);
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(lambdaQueryWrapper);

        if (shipmentHeader == null) {
            return AjaxResult.error("没有找到出库单");
        }
        LambdaQueryWrapper<ShipmentDetail> detailLambdaQueryWrapper = Wrappers.lambdaQuery();
        detailLambdaQueryWrapper.eq(ShipmentDetail::getShipmentId, shipmentHeader.getId());
        Shipment shipment = new Shipment();
        shipment.setShipmentHeader(shipmentHeader);
        List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(detailLambdaQueryWrapper);
        shipment.setShipmentDetailList(shipmentDetailList);
        return AjaxResult.success(shipment);
    }
190
游杰 authored
191
192
193
194
195
196
197
    /**
     * 根据出库单号生成出库任务
     */
    @PostMapping("/createShipmentTask")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult createShipmentTask(@RequestBody List<TaskIds> taskDetails){
198
199
200
201
202
        List<Integer> ids = new ArrayList<>();
        for (TaskIds task : taskDetails) {
            ids.add(task.getTaskId());
        }
        List<Integer> listWithoutDuplicates = ids.stream().distinct().collect(Collectors.toList());
游杰 authored
203
204
        ShipmentTaskCreateModel shipmentTask = new ShipmentTaskCreateModel();
        List<Integer> taskIds = new ArrayList<>();
205
206
        for (Integer id : listWithoutDuplicates) {
            shipmentTask.setShipmentContainerHeaderIds(id);
207
            AjaxResult ajaxResult = shipmentTaskService.createTaskFromShipmentContainers(shipmentTask);
208
            if(ajaxResult.hasErr()) {
游杰 authored
209
210
211
212
213
214
215
                return ajaxResult;
            }
            Integer taskId = (Integer)ajaxResult.getData();
            taskIds.add(taskId);
        }
        return AjaxResult.success(taskIds);
    }
游杰 authored
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
    /**
     * 根据出库单号生成出库任务
     */
    @PostMapping("/outPort")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult outPort(@RequestBody Map<String, String> param) {
        int type = Integer.parseInt(param.get("type"));
        String area = param.get("area");
        LambdaQueryWrapper<Station> queryWrapper = Wrappers.lambdaQuery();
        if(type == QuantityConstant.STATION_PICK_AND_OUT) {
            queryWrapper.in(Station::getType,
                    QuantityConstant.STATION_OUT, QuantityConstant.STATION_PICK);
        } else {
            queryWrapper.eq(Station::getType, type);
        }
        queryWrapper.eq(Station::getArea, area);
        List<Station> stationList = stationService.list(queryWrapper);
        return AjaxResult.success(stationList);
    }
游杰 authored
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
    @PostMapping("/findShipment")
    @ApiOperation("移动端查询出库单")
    @Log(title = "移动端查询出库单", action = BusinessType.OTHER)
    public AjaxResult findShipment(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        String shipmentCode = param.get("shipmentCode");
        String companyCode = param.get("companyCode");
        if (StringUtils.isNull(shipmentCode)){
            return AjaxResult.error("上游系统关联单号为空");
        } else if (StringUtils.isNull(companyCode)){
            return AjaxResult.error("公司编码为空");
        }

        /* 查询入库单,如果数据库中不存在,则调用ERP接口拉取单据,成功后再次查询返回结果*/
        LambdaQueryWrapper<ShipmentHeader> shipmentLambdaQueryWrapper = Wrappers.lambdaQuery();
        shipmentLambdaQueryWrapper.eq(ShipmentHeader::getCode, shipmentCode)
                .eq(ShipmentHeader::getCompanyCode, companyCode);
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(shipmentLambdaQueryWrapper);
        if(shipmentHeader == null) {
            return AjaxResult.error("没有找到出库单");
        }
        ShipmentDomain shipment = new ShipmentDomain();
        shipment.setShipmentHeader(shipmentHeader);

        LambdaQueryWrapper<ShipmentDetail> shipmentDetailQueryWrapper = Wrappers.lambdaQuery();
        shipmentDetailQueryWrapper.eq(ShipmentDetail::getShipmentId, shipmentHeader.getId());
        List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(shipmentDetailQueryWrapper);
        shipment.setShipmentDetails(shipmentDetailList);
        return AjaxResult.success(shipment);
    }

    @PostMapping("/searchShipment")
    @ApiOperation("移动端查询出库单")
    @Log(title = "移动端查询出库单", action = BusinessType.OTHER)
    public AjaxResult searchShipment(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        String companyCode = param.get("companyCode");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String now = df.format(new Date());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, -7);
        Date first = c.getTime();
        String start = df.format(first);//前一天
        LambdaQueryWrapper<ShipmentHeader> shipmentHeaderQueryWrapper = Wrappers.lambdaQuery();
        shipmentHeaderQueryWrapper.eq(ShipmentHeader::getCompanyCode, companyCode)
                .eq(ShipmentHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .le(ShipmentHeader::getCreated, now)
                .gt(ShipmentHeader::getCreated, start)
                .orderByDesc(ShipmentHeader::getCreated);
        List<ShipmentHeader> receiptHeaderList = shipmentHeaderService.list(shipmentHeaderQueryWrapper);
        return AjaxResult.success(receiptHeaderList);
    }
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
    @PostMapping("/searchShipmentInCondition")
    @ApiOperation("移动端查询出库单")
    @Log(title = "移动端查询出库单", action = BusinessType.OTHER)
    public AjaxResult searchShipmentInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
        String companyCode = param.get("companyCode");
        String code = param.get("code");
        String shipmentType = param.get("shipmentType");
        String lastStatus = param.get("lastStatus");
        String startTime = param.get("startTime");
        String endTime = param.get("endTime");
        LambdaQueryWrapper<ShipmentHeader> shipmentQueryWrapper = Wrappers.lambdaQuery();
        shipmentQueryWrapper.eq(ShipmentHeader::getCompanyCode, companyCode)
                .eq(ShipmentHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .like(StringUtils.isNotEmpty(code), ShipmentHeader::getCode, code)
                .eq(StringUtils.isNotEmpty(shipmentType), ShipmentHeader::getShipmentType, shipmentType)
                .eq(StringUtils.isNotEmpty(lastStatus), ShipmentHeader::getLastStatus, lastStatus)
                .gt(StringUtils.isNotEmpty(startTime), ShipmentHeader::getCreated, startTime)
                .le(StringUtils.isNotEmpty(endTime), ShipmentHeader::getCreated, endTime)
                .orderByDesc(ShipmentHeader::getCreated);
游杰 authored
309
310
311
312
313
314
315
316
317
318
319
        if(lastStatus.equals("200")) {
            shipmentQueryWrapper = Wrappers.lambdaQuery();
            shipmentQueryWrapper.lt(ShipmentHeader::getLastStatus, 900);
            shipmentQueryWrapper.eq(ShipmentHeader::getCompanyCode, companyCode)
                    .eq(ShipmentHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                    .like(StringUtils.isNotEmpty(code), ShipmentHeader::getCode, code)
                    .eq(StringUtils.isNotEmpty(shipmentType), ShipmentHeader::getShipmentType, shipmentType)
                    .gt(StringUtils.isNotEmpty(startTime), ShipmentHeader::getCreated, startTime)
                    .le(StringUtils.isNotEmpty(endTime), ShipmentHeader::getCreated, endTime)
                    .orderByDesc(ShipmentHeader::getCreated);
        }
320
321
322
323
        List<ShipmentHeader>  shipmentHeaderList = shipmentHeaderService.list(shipmentQueryWrapper);
        return AjaxResult.success(shipmentHeaderList);
    }
游杰 authored
324
325
326
327
    @PostMapping("/getShipmentType")
    @ApiOperation("移动端查询入库类型")
    @Log(title = "移动端查询字典信息", action = BusinessType.OTHER)
    public AjaxResult getShipmentType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
游杰 authored
328
        String companyCode = param.get("companyCode");
游杰 authored
329
        LambdaQueryWrapper<ShipmentType> shipmentTypeLambda = Wrappers.lambdaQuery();
游杰 authored
330
331
        shipmentTypeLambda.eq(ShipmentType::getCompanyCode, companyCode);
        shipmentTypeLambda.eq(ShipmentType::getWarehouseCode, ShiroUtils.getWarehouseCode());
游杰 authored
332
333
334
        List<ShipmentType> shipmentTypes = shipmentTypeService.list(shipmentTypeLambda);
        return AjaxResult.success(shipmentTypes);
    }
游杰 authored
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
    @PostMapping("/getStationByCombinId")
    @ApiOperation("移动端根据组盘头id查询可用站台")
    @Log(title = "移动端根据组盘头id查询可用站台", action = BusinessType.OTHER)
    public AjaxResult getStationByCombinId(Integer id){
        ShipmentContainerHeader header = shipmentContainerHeaderService.getById(id);

        int taskType = header.getTaskType().intValue();
        int stationType = -1;
        if(taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT ||
                taskType == QuantityConstant.TASK_TYPE_EMPTYSHIPMENT)  {
            stationType = QuantityConstant.STATION_OUT;
        } else if(taskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT ||
                taskType == QuantityConstant.TASK_TYPE_SORTINGSHIPMENT ||
                taskType == QuantityConstant.TASK_TYPE_VIEW ||
                taskType == QuantityConstant.TASK_TYPE_CYCLECOUNT) {
            stationType = QuantityConstant.STATION_PICK;
        } else {
            throw new ServiceException("任务类型不需要选站台");
        }

        List<Station> stationList = getStationListByContainerAndType(header.getContainerCode(), stationType);
        return AjaxResult.success(stationList);
    }
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
    @PostMapping("/getStationByTaskId")
    @ApiOperation("移动端根据任务ID查询可用站台")
    @Log(title = "移动端根据任务ID查询可用站台", action = BusinessType.OTHER)
    public AjaxResult getStationByTaskId(Integer id){
        TaskHeader header = taskHeaderService.getById(id);

        int taskType = header.getTaskType().intValue();
        int stationType = -1;
        if(taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT ||
                taskType == QuantityConstant.TASK_TYPE_EMPTYSHIPMENT)  {
            stationType = QuantityConstant.STATION_OUT;
        } else if(taskType == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT ||
                taskType == QuantityConstant.TASK_TYPE_SORTINGSHIPMENT ||
                taskType == QuantityConstant.TASK_TYPE_VIEW ||
                taskType == QuantityConstant.TASK_TYPE_CYCLECOUNT) {
            stationType = QuantityConstant.STATION_PICK;
        } else {
            throw new ServiceException("任务类型不需要选站台");
        }

        List<Station> stationList = getStationListByContainerAndType(header.getContainerCode(), stationType);
        return AjaxResult.success(stationList);
    }
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
    /**
     * StationController.getStationFromType移植过来
     * @param containerCode
     * @param type
     * @return
     */
    private List<Station> getStationListByContainerAndType(String containerCode, int type){
        Container container = containerService.getContainerByCode(containerCode);

        String locationCode = container.getLocationCode();
        if(StringUtils.isEmpty(locationCode)) {
            return null;
        }
        LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
        locationLambdaQueryWrapper.eq(Location::getCode, locationCode)
                .eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode());
        Location location1 = locationService.getOne(locationLambdaQueryWrapper);
        if(location1 == null) {
            return null;
        }

        LambdaQueryWrapper<Station> queryWrapper = Wrappers.lambdaQuery();
        if(type == QuantityConstant.STATION_PICK_AND_OUT) {
            queryWrapper.in(Station::getType,
                    QuantityConstant.STATION_OUT, QuantityConstant.STATION_PICK);
        } else {
            queryWrapper.eq(Station::getType, type);
        }
        queryWrapper.eq(Station::getArea, location1.getArea());
        List<Station> stationList = stationService.list(queryWrapper);

        return stationList;
    }
游杰 authored
417
418
419
420
421

    @PostMapping("/createShipmentCode")
    @ApiOperation("移动端创建出库单号")
    @Log(title = "移动端创建出库单号", action = BusinessType.OTHER)
    public AjaxResult createShipmentCode(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
游杰 authored
422
423
        String companyCode = param.get("companyCode");
        String shipmentType =  param.get("shipmentType");
游杰 authored
424
425
426
        String code = null;
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
xumiao authored
427
        String maxCode = shipmentHeaderMapper.createCode(shipmentType,ShiroUtils.getWarehouseCode());
游杰 authored
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
        //如果指定类型的最后的code存在,并且日期一致。那么 code = 入库单类型 + 年月日 + (排序号 + 1)
        if (maxCode != null && maxCode.substring(maxCode.length() - 11, maxCode.length() - 3).equals(df.format(now))) {
            Integer Count = Integer.valueOf(maxCode.substring(maxCode.length() - 3, maxCode.length()));
            code = shipmentType + df.format(now) + String.format("%03d", Count + 1);
        } else {
            code = shipmentType + df.format(now) + "001";
        }
        return AjaxResult.success().setData(code);
    }

    @PostMapping("/createShipment")
    @ApiOperation("移动端创建出库单")
    @Log(title = "移动端创建出库单", action = BusinessType.OTHER)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult createShipment(@RequestBody @ApiParam(value = "物料号")List<ShipmentBill> shipmentBills){
        String companyCode = shipmentBills.get(0).getCompanyCode();
        String shipmentCode = shipmentBills.get(0).getShipmentCode();
游杰 authored
445
        String shipmentType = shipmentBills.get(0).getShipmentType();
游杰 authored
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
        ShipmentHeader shipmentHeader = new ShipmentHeader();
        shipmentHeader.setId(null);
        shipmentHeader.setCode(shipmentCode);
        shipmentHeader.setShipmentType(shipmentType);
        shipmentHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
        shipmentHeader.setCreatedBy(ShiroUtils.getLoginName());
        shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        shipmentHeader.setFirstStatus(200);
        shipmentHeader.setLastStatus(200);
        shipmentHeader.setCompanyCode(companyCode);
        shipmentHeaderService.save(shipmentHeader);
        List<Integer> shipmentdetailIds = insertTodayShipmentDetail(shipmentHeader.getId(), shipmentBills, false, companyCode);
        shipmentDetailService.updateShipmentHeader(shipmentHeader);
        if(shipmentdetailIds != null && shipmentdetailIds.size() > 0) {
            return AjaxResult.success("创建出库单成功");
        }
        return AjaxResult.error("创建出库单失败");
    }

    public List<Integer> insertTodayShipmentDetail(int headerId, List<ShipmentBill> shipmentBills, boolean isCompletedQty, String companyCode) {
        List<Integer> mShipmentDetailIds = new ArrayList<>();
        ShipmentHeader shipmentHeader = shipmentHeaderService.getById(headerId);

        for (ShipmentBill shipmentBill : shipmentBills) {
            ShipmentDetail shipmentDetail = new ShipmentDetail();
            shipmentDetail.setId(null);
            shipmentDetail.setWarehouseCode(ShiroUtils.getWarehouseCode());
            shipmentDetail.setCompanyCode(companyCode);
            shipmentDetail.setShipmentId(headerId);
            shipmentDetail.setShipmentCode(shipmentHeader.getCode());
            shipmentDetail.setMaterialCode(shipmentBill.getMaterialCode());
            LambdaQueryWrapper<Material> lambdaQueryWrapper = Wrappers.lambdaQuery();
            lambdaQueryWrapper.eq(Material::getCode, shipmentBill.getMaterialCode())
                    .eq(Material::getWarehouseCode, ShiroUtils.getWarehouseCode());
            Material material = materialService.getOne(lambdaQueryWrapper);
            shipmentDetail.setMaterialName(material.getName());
            shipmentDetail.setMaterialUnit(material.getUnit());
            shipmentDetail.setInventorySts("good");
肖超群 authored
484
            shipmentDetail.setQty(shipmentBill.getQty());
游杰 authored
485
486
487
488
489
490
            shipmentDetailService.save(shipmentDetail);
            mShipmentDetailIds.add(shipmentDetail.getId());
        }
        return mShipmentDetailIds;
    }
491
    @Log(title = "移动端设置出库站台", operating = "设置站台", action = BusinessType.GRANT)
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
    @PostMapping("/setStation")
    @ResponseBody
    public AjaxResult setStation (String id, String station){
            LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
            shipmentContainerHeaderLambdaQueryWrapper.eq(ShipmentContainerHeader::getId, id);
            ShipmentContainerHeader shipmentContainerHeader1 = shipmentContainerHeaderService.getOne(shipmentContainerHeaderLambdaQueryWrapper);
            shipmentContainerHeader1.setPort(station);
            shipmentContainerHeaderService.update(shipmentContainerHeader1, shipmentContainerHeaderLambdaQueryWrapper);
            return AjaxResult.success();
    }

    @Log(title = "移动端根据id_list取组盘头", operating = "移动端根据id_list取组盘头", action = BusinessType.GRANT)
    @PostMapping("/getShipmentInfoByIdList")
    @ResponseBody
    public AjaxResult<List<ShipmentContainerHeader>> getShipmentInfoByIdList(String[] id_list){
        LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        shipmentContainerHeaderLambdaQueryWrapper.in(ShipmentContainerHeader::getId, id_list);
        List<ShipmentContainerHeader> list = shipmentContainerHeaderService.list(shipmentContainerHeaderLambdaQueryWrapper);
        return AjaxResult.success(list);
    }
}