Blame view

src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java 43.5 KB
1
2
package com.huaheng.pc.shipment.shipmentContainerHeader.service;
pengcheng authored
3
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
周鸿 authored
4
import com.huaheng.common.utils.Wrappers;
pengcheng authored
5
import com.huaheng.common.constant.QuantityConstant;
pengcheng authored
6
import com.huaheng.common.exception.service.ServiceException;
7
import com.huaheng.common.utils.StringUtils;
pengcheng authored
8
9
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
10
import com.huaheng.framework.web.domain.RetCode;
11
12
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
13
14
15
16
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
17
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
pengcheng authored
18
19
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
20
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
21
22
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
周鸿 authored
23
24
import com.huaheng.pc.shipment.lockingWorkOrder.domain.LockingWorkOrder;
import com.huaheng.pc.shipment.lockingWorkOrder.service.LockingWorkOrderService;
pengcheng authored
25
26
27
28
29
30
31
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentCombinationModel;
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;
pengcheng authored
32
33
import com.huaheng.pc.shipment.shippingCombination.domain.ShippingSearch;
import com.huaheng.pc.shipment.shippingCombination.service.ShippingCombinationService;
pengcheng authored
34
35
import com.huaheng.pc.shipment.wave.domain.Wave;
import com.huaheng.pc.shipment.wave.service.WaveService;
36
37
import com.huaheng.pc.system.role.domain.Role;
import com.huaheng.pc.system.role.service.IRoleService;
38
39
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
40
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
41
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
42
import com.huaheng.pc.task.taskHeader.service.ShipmentTaskService;
43
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
44
import io.swagger.models.auth.In;
pengcheng authored
45
import org.springframework.beans.factory.annotation.Autowired;
46
47
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
pengcheng authored
48
import java.math.BigDecimal;
pengcheng authored
49
import java.util.ArrayList;
50
import java.util.Collections;
51
import java.util.List;
pengcheng authored
52
import java.util.Map;
53
import java.util.stream.Collectors;
pengcheng authored
54
55
56
57
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.mapper.ShipmentContainerHeaderMapper;
pengcheng authored
58
59
import org.springframework.transaction.annotation.Transactional;
60
61
62
@Service
public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentContainerHeaderMapper, ShipmentContainerHeader> implements ShipmentContainerHeaderService{
pengcheng authored
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    @Autowired
    private ShipmentDetailService shipmentDetailService;
    @Autowired
    private InventoryDetailService inventoryDetailService;
    @Autowired
    private LocationService locationService;
    @Autowired
    private ShipmentHeaderService shipmentHeaderService;
    @Resource
    private ShipmentContainerHeaderMapper shipmentContainerHeaderMapper;
    @Autowired
    private ShipmentContainerDetailService shipmentContainerDetailService;
    @Autowired
    private MaterialService materialService;
pengcheng authored
77
78
    @Autowired
    private ShippingCombinationService shippingCombinationService;
79
80
    @Autowired
    private TaskHeaderService taskHeaderService;
81
82
    @Autowired
    private TaskDetailService taskDetailService;
pengcheng authored
83
84
    @Autowired
    private WaveService waveService;
85
86
    @Autowired
    private ShipmentPreferenceService shipmentPreferenceService;
87
88
    @Autowired
    private ContainerService containerService;
89
90
    @Resource
    private ShipmentTaskService shipmentTaskService;
91
92
    @Autowired
    private ReceiptContainerHeaderService receiptContainerHeaderService;
周鸿 authored
93
94
    @Autowired
    private LockingWorkOrderService lockingWorkOrderService;
95
96
    @Autowired
    private IRoleService roleService;
pengcheng authored
97
98
99
100
101
102
103
104
105
106


    @Override
    public Map<String, Integer> getShipmentContainerMaxAndMinStatusByShipmentID(int shipmentId) {
        return shipmentContainerHeaderMapper.getShipmentContainerMaxAndMinStatusByShipmentID(shipmentId);
    }



    /**
107
108
109
110
111
112
113
114
     * 1.检查基本属性
     * 2.更改库存明细
     * 3.更新单据明细的已出库数量
     * 4.自动判定出库任务状态,根据库存数量减去预定库存相等就是整盘出--预计任务状态
     * 5.增加出库组盘头
     * 6.增加出库组盘明细
     * 7.更新单据状态
     *
pengcheng authored
115
116
117
118
119
120
     * 出库组盘单条保存
     * @param shipmentCombinationModel
     * @return
     */
    @Transactional
    @Override
pengcheng authored
121
    public ShipmentContainerHeader combination(ShipmentCombinationModel shipmentCombinationModel) {
pengcheng authored
122
123
        //1.检查基本属性
pengcheng authored
124
125
        //校验
        if(shipmentCombinationModel.getShipQty().compareTo(new BigDecimal("0")) <= 0){
pengcheng authored
126
            throw new ServiceException("出库数量必须大于0");
pengcheng authored
127
128
        }
        ShipmentDetail shipmentDetail = shipmentDetailService.getById(shipmentCombinationModel.getShipmentDetailId());
129
        if(shipmentDetail == null){
pengcheng authored
130
            throw new ServiceException("出库明细未找到");
pengcheng authored
131
132
        }
        InventoryDetail inventoryDetail = inventoryDetailService.getById((shipmentCombinationModel.getInventoryDetailId()));
133
        if(inventoryDetail == null){
pengcheng authored
134
            throw new ServiceException("库存未找到");
pengcheng authored
135
        }
136
137
138
139
140
        String containerCode = inventoryDetail.getContainerCode();
        int unCompleteCombineNumber = receiptContainerHeaderService.getUnCompleteCombineNumber(containerCode);
        if(unCompleteCombineNumber > 0) {
            throw new ServiceException("托盘:" + containerCode + " 已经用于入库组盘");
        }
141
142
143
        Container container = containerService.getContainerByCode(containerCode);
        if(container != null) {
            if(container.getStatus().equals(QuantityConstant.STATUS_CONTAINER_LOCK)) {
xumiao authored
144
                //throw new ServiceException("托盘已经锁定,不能再组盘");
145
146
            }
        }
pengcheng authored
147
        //校验数量是否超出
肖超群 authored
148
        if((shipmentDetail.getQty().subtract(shipmentDetail.getTaskQty())).compareTo(shipmentCombinationModel.getShipQty())<0){
pengcheng authored
149
            throw new ServiceException("录入数量超出明细待出数量");
pengcheng authored
150
151
        }
        //校验库存可用数量
152
        if(inventoryDetail.getQty().subtract(inventoryDetail.getTaskQty()).compareTo(shipmentCombinationModel.getShipQty())<0){
pengcheng authored
153
            throw new ServiceException("录入数量超出可出数量");
pengcheng authored
154
155
        }
        if(!shipmentDetail.getMaterialCode().equals(inventoryDetail.getMaterialCode())){
pengcheng authored
156
            throw new ServiceException("配盘物料不一致");
pengcheng authored
157
158
159
160
161
162
        }
        //库位
        LambdaQueryWrapper<Location> lambdaQueryWrapper= Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(Location::getWarehouseCode,inventoryDetail.getWarehouseCode())
                .eq(Location::getCode,inventoryDetail.getLocationCode());
        Location location = locationService.getOne(lambdaQueryWrapper);
163
164
165
        if (location == null) {
            throw new ServiceException("库位 " + inventoryDetail.getLocationCode() + " 不存在");
        }
pengcheng authored
166
167
        //2.更新库存分配数
pengcheng authored
168
169
        inventoryDetail.setTaskQty(inventoryDetail.getTaskQty().add(shipmentCombinationModel.getShipQty()));
        inventoryDetailService.saveOrUpdate(inventoryDetail);
170
        //3.更新单据明细的已出库数量
肖超群 authored
171
172
        shipmentDetail.setTaskQty(shipmentDetail.getTaskQty().add(shipmentCombinationModel.getShipQty()));
        int i = shipmentDetail.getQty().compareTo(shipmentDetail.getTaskQty());
pengcheng authored
173
        if(i > 0){
pengcheng authored
174
            shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_WAVE);
175
        }else if(i == 0) {
pengcheng authored
176
            shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_GROUPDISK);
177
        }else if(i < 0) {
pengcheng authored
178
179
            throw new ServiceException("出库数量不能大于单据数量!");
        }
180
pengcheng authored
181
182
183
184

        //自动判定出库任务状态,根据库存数量减去预定库存相等就是整盘出--预计任务状态
        BigDecimal inventoryQty = inventoryDetail.getQty().subtract(inventoryDetail.getTaskQty());
        if(inventoryQty.compareTo(new BigDecimal(0)) <= 0) {
pengcheng authored
185
            shipmentCombinationModel.setTaskType(QuantityConstant.TASK_TYPE_WHOLESHIPMENT);
pengcheng authored
186
        } else {
pengcheng authored
187
            shipmentCombinationModel.setTaskType(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
pengcheng authored
188
        }
tongzhonghao authored
189
190
191
192
193
        Container container1 = containerService.getContainerByCode(inventoryDetail.getContainerCode());
        String containerType = container1.getContainerType();
        if("S".equals(containerType)){
            shipmentCombinationModel.setTaskType(QuantityConstant.TASK_TYPE_SORTINGSHIPMENT);
        }
194
195
196
        //5.增加出库组盘头
        ShipmentContainerHeader shipmentContainerHeader = ShipmentContainerHeaderAdd(location, shipmentDetail);
        //6.增加出库组盘明细
pengcheng authored
197
        ShipmentContainerDetail shipmentContainerDetail = ShipmentContainerDetailAdd(shipmentDetail, shipmentContainerHeader, shipmentCombinationModel);
198
199

        shipmentDetailService.saveOrUpdate(shipmentDetail);
200
        //7.更新单据状态
pengcheng authored
201
202
        shipmentHeaderService.updateShipmentStatus(shipmentDetail.getShipmentId());
pengcheng authored
203
        return  shipmentContainerHeader;
pengcheng authored
204
205
206
    }

    /**
207
208
209
210
     * 组盘头
     * 1.查看是否有状态小于等于20的组盘头,有就需新建组盘头,没有就新建
     * 2.没有符合条件的组盘头,新建组盘头
     *
pengcheng authored
211
     * @param location
212
     * @param shipmentDetail
pengcheng authored
213
214
215
     * @return
     */
    private ShipmentContainerHeader ShipmentContainerHeaderAdd(Location location,
216
217
                                                               ShipmentDetail shipmentDetail) {
        //1.查看是否有状态小于等于20的组盘头,有就需新建组盘头,没有就新建
pengcheng authored
218
        LambdaQueryWrapper<ShipmentContainerHeader> lambdaQueryWrapper=Wrappers.lambdaQuery();
pengcheng authored
219
220
        lambdaQueryWrapper.eq(ShipmentContainerHeader::getLocationCode,location.getCode())
                .eq(ShipmentContainerHeader::getContainerCode,location.getContainerCode())
pengcheng authored
221
                .eq(ShipmentContainerHeader::getWarehouseCode,ShiroUtils.getWarehouseCode())
222
                .lt(ShipmentContainerHeader::getStatus,QuantityConstant.SHIPMENT_CONTAINER_FINISHED);
pengcheng authored
223
224
        ShipmentContainerHeader shipmentContainerHeader = this.getOne(lambdaQueryWrapper);
        if(shipmentContainerHeader != null)  {
225
            if (shipmentDetail.getWarehouseCode().equals("KS0001")&&!ShiroUtils.getUserName().equals(shipmentContainerHeader.getCreatedBy())){
226
                throw new ServiceException(shipmentDetail.getMaterialName()+"物料匹配托盘"+location.getContainerCode()+"已被"+shipmentContainerHeader.getCreatedBy()+"组盘,暂时不能组盘");
227
            }
228
            return shipmentContainerHeader;
pengcheng authored
229
230
        }
        else {
231
232
233
234
235
236
            // 2.没有符合条件的组盘头,新建组盘头
            //找到容器类型
            LambdaQueryWrapper<Container> containerLam=Wrappers.lambdaQuery();
            containerLam.eq(Container::getCode,location.getContainerCode())
                    .eq(Container::getWarehouseCode,ShiroUtils.getWarehouseCode());
            Container container = containerService.getOne(containerLam);
237
            if(container == null) {
238
239
                throw new ServiceException("系统没有此容器编码");
            }
240
241
242
243
244
245
246
247
248
249
            LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
            inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getContainerCode, container.getCode());
            List<InventoryDetail> inventoryDetailList =  inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
            int taskType = QuantityConstant.TASK_TYPE_WHOLESHIPMENT;
            if(inventoryDetailList != null && inventoryDetailList.size() > 0) {
                for(InventoryDetail inventoryDetail : inventoryDetailList) {
                    if(inventoryDetail.getQty().subtract(inventoryDetail.getTaskQty()).
                            compareTo(BigDecimal.ZERO) > 0) {
                        taskType = QuantityConstant.TASK_TYPE_SORTINGSHIPMENT;
                    }
250
                }
pengcheng authored
251
            }
tongzhonghao authored
252
253
254
255

            if("S".equals(container.getContainerType())){
                taskType = QuantityConstant.TASK_TYPE_SORTINGSHIPMENT;
            }
周鸿 authored
256
            ShipmentHeader shipmentHeader=shipmentHeaderService.getById(shipmentDetail.getShipmentId());
257
258
259
            shipmentContainerHeader = new ShipmentContainerHeader();
            shipmentContainerHeader.setContainerCode(location.getContainerCode());
            shipmentContainerHeader.setLocationCode(location.getCode());
260
            shipmentContainerHeader.setZoneCode(location.getZoneCode());
261
            shipmentContainerHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
周鸿 authored
262
            shipmentContainerHeader.setUWarehouseCode(shipmentHeader.getUWarehouseCode());
263
264
265
266
267
268
269
270
271
272
273
274
275
            shipmentContainerHeader.setCompanyCode(shipmentDetail.getCompanyCode());
            shipmentContainerHeader.setPort(shipmentDetail.getPort());
            shipmentContainerHeader.setContainerType(container.getContainerType());
            shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
            shipmentContainerHeader.setTaskType(taskType);
            shipmentContainerHeader.setTaskCreated(0);
            shipmentContainerHeader.setCreatedBy(ShiroUtils.getLoginName());
            Boolean flag = this.save(shipmentContainerHeader);
            if (flag == false) {
                throw new ServiceException("新建组盘头失败,sql错误");
            }
            return shipmentContainerHeader;
        }
pengcheng authored
276
277
278
    }

    /**
279
280
281
282
283
284
     * 组盘明细
     * 1.查看是否有同一出库明细的物料需要出库
     * 2.有时修改阻盘明细的出库数量就行
     * 3.没有就新建明细
     * 4。查看组盘头状态,如果状态在1020,则生成任务明细或修改任务明细的数量
     *
pengcheng authored
285
286
287
288
289
290
291
292
     * @param shipmentDetail
     * @param shipmentContainerHeader
     * @param shipmentCombinationModel
     * @return
     */
    private ShipmentContainerDetail ShipmentContainerDetailAdd(ShipmentDetail shipmentDetail,
                                                               ShipmentContainerHeader shipmentContainerHeader,
                                                               ShipmentCombinationModel shipmentCombinationModel) {
293
294
295

        Boolean flag =true;
        //1.查看是否有同一出库明细的物料需要出库
pengcheng authored
296
        LambdaQueryWrapper<ShipmentContainerDetail> lambdaQueryWrapper=Wrappers.lambdaQuery();
297
298
299
300
301
302
        lambdaQueryWrapper.eq(ShipmentContainerDetail::getShippingContainerId, shipmentContainerHeader.getId())
                .eq(ShipmentContainerDetail::getLocationCode, shipmentContainerHeader.getLocationCode())
                .eq(ShipmentContainerDetail::getContainerCode, shipmentContainerHeader.getContainerCode())
                .eq(ShipmentContainerDetail::getShipmentDetailId, shipmentCombinationModel.getShipmentDetailId())
                .eq(ShipmentContainerDetail::getInventoryId, shipmentCombinationModel.getInventoryDetailId())
                .eq(ShipmentContainerDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
pengcheng authored
303
        ShipmentContainerDetail shipmentContainerDetail = shipmentContainerDetailService.getOne(lambdaQueryWrapper);
304
305
        ShipmentContainerDetail shipmentContainerDetaill = new ShipmentContainerDetail();
周鸿 authored
306
        Container container=containerService.getContainerByCode(shipmentContainerHeader.getContainerCode());
周鸿 authored
307
308
        //2.有时修改阻盘明细的出库数量就行
pengcheng authored
309
310
        if(shipmentContainerDetail != null)    {
            shipmentContainerDetail.setQty(shipmentContainerDetail.getQty().add(shipmentCombinationModel.getShipQty()));
周鸿 authored
311
            shipmentContainerDetaill.setZoneCode(container.getZoneCode());
312
313
314
315
            flag=shipmentContainerDetailService.saveOrUpdate(shipmentContainerDetail);
            if(flag == false){
                throw new ServiceException("修改组盘明细失败,sql错误");
            }
pengcheng authored
316
        }
317
        else  {
pengcheng authored
318
319
            //3.没有就新建明细
pengcheng authored
320
321
322
323
            LambdaQueryWrapper<Material> lam=Wrappers.lambdaQuery();
            lam.eq(Material::getCode,shipmentDetail.getMaterialCode())
                    .eq(Material::getWarehouseCode,ShiroUtils.getWarehouseCode());
            Material material = materialService.getOne(lam);
324
325
326
            if (material == null) {
                throw new ServiceException("出库单(" + shipmentDetail.getShipmentCode() + ")的物料(" + shipmentDetail.getMaterialCode() + ")不存在!");
            }
周鸿 authored
327
328
329
            shipmentContainerDetaill.setWarehouseCode(shipmentContainerHeader.getWarehouseCode());
周鸿 authored
330
            shipmentContainerDetaill.setUWarehouseCode(shipmentContainerHeader.getUWarehouseCode());
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
            shipmentContainerDetaill.setCompanyCode(shipmentContainerHeader.getCompanyCode());
            shipmentContainerDetaill.setContainerCode(shipmentContainerHeader.getContainerCode());
            shipmentContainerDetaill.setLocationCode(shipmentContainerHeader.getLocationCode());
            shipmentContainerDetaill.setInventoryId(shipmentCombinationModel.getInventoryDetailId());
            shipmentContainerDetaill.setInventorySts(shipmentDetail.getInventorySts());
            shipmentContainerDetaill.setShippingContainerId(shipmentContainerHeader.getId());
            shipmentContainerDetaill.setShipmentCode(shipmentDetail.getShipmentCode());
            shipmentContainerDetaill.setShipmentId(shipmentDetail.getShipmentId());
            shipmentContainerDetaill.setShipmentDetailId(shipmentDetail.getId());
            shipmentContainerDetaill.setMaterialCode(shipmentDetail.getMaterialCode());
            shipmentContainerDetaill.setMaterialName(shipmentDetail.getMaterialName());
            shipmentContainerDetaill.setMaterialSpec(shipmentDetail.getMaterialSpec());
            shipmentContainerDetaill.setMaterialUnit(shipmentDetail.getMaterialUnit());
            shipmentContainerDetaill.setQty(shipmentCombinationModel.getShipQty());
            shipmentContainerDetaill.setWaveId(shipmentDetail.getWaveId());
            shipmentContainerDetaill.setTaskCreated(0);
pengcheng authored
347
            shipmentContainerDetaill.setStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
348
349
350
351
            shipmentContainerDetaill.setBatch(shipmentDetail.getBatch());
            shipmentContainerDetaill.setLot(shipmentDetail.getLot());
            shipmentContainerDetaill.setProjectNo(shipmentDetail.getProjectNo());
            shipmentContainerDetaill.setCreatedBy(ShiroUtils.getLoginName());
周鸿 authored
352
            shipmentContainerDetaill.setZoneCode(container.getZoneCode());
pengcheng authored
353
            flag = shipmentContainerDetailService.save(shipmentContainerDetaill);
354
355
356
            if(flag == false){
                throw new ServiceException("新建组盘明细失败,sql错误");
            }
pengcheng authored
357
        }
358
359
        //4.查看组盘头状态,如果状态在10到30,则生成任务明细或修改任务明细的数量
360
        //查看任务头
361
362
363
        int containerHeaderStatus = shipmentContainerHeader.getStatus().intValue();
        if(QuantityConstant.SHIPMENT_CONTAINER_TASK <= containerHeaderStatus &&
                containerHeaderStatus < QuantityConstant.SHIPMENT_CONTAINER_FINISHED){
364
365
            LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper=Wrappers.lambdaQuery();
            taskHeaderLambdaQueryWrapper.eq(TaskHeader::getWarehouseCode,shipmentContainerHeader.getWarehouseCode())
游杰 authored
366
                    .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT, QuantityConstant.TASK_TYPE_WHOLESHIPMENT)
367
                    .eq(TaskHeader::getAllocationHeadId,shipmentContainerHeader.getId());
368
369
            TaskHeader taskHeader=taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
            if(taskHeader==null){
pengcheng authored
370
                throw new ServiceException("有相同的组盘头,但找不到相应的任务头");
371
            }
372
373
374
375
376
377
378
379

            if(shipmentContainerDetaill == null) {
                //shipmentContainerDetaill为空时,说明组盘明细不是新建,so修改任务明细
                //查找任务明细
                LambdaQueryWrapper<TaskDetail> taskDetailLam = Wrappers.lambdaQuery();
                taskDetailLam.eq(TaskDetail::getWarehouseCode,shipmentContainerDetail.getWarehouseCode())
                        .eq(TaskDetail::getAllocationId,shipmentContainerDetail.getId())
                        .eq(TaskDetail::getTaskId,taskHeader.getId())
游杰 authored
380
                        .in(TaskDetail::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT, QuantityConstant.TASK_TYPE_WHOLESHIPMENT);
381
382
383
384
385
386
387
388
389
                TaskDetail taskDetail = taskDetailService.getOne(taskDetailLam);
                if(taskDetail == null){
                    throw new ServiceException("找不到对应的任务明细");
                }
                taskDetail.setQty(taskDetail.getQty().add(shipmentCombinationModel.getShipQty()));
                flag=taskDetailService.saveOrUpdate(taskDetail);
                if(flag == false){
                    throw new ServiceException("修改任务明细失败,sql错误");
                }
390
391
392
393
                shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
                if (!shipmentContainerDetailService.updateById(shipmentContainerDetail)) {
                    throw new ServiceException("修改组盘明细状态失败");
                }
394
            }else {
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
                //shipmentContainerDetaill不为空时,说明组盘明细是新建,so新建任务明细
                TaskDetail taskDetail = new TaskDetail();
                taskDetail.setTaskId(taskHeader.getId());
                taskDetail.setInternalTaskType(taskHeader.getInternalTaskType());
                taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
                taskDetail.setCompanyCode(taskHeader.getCompanyCode());
                taskDetail.setTaskType(taskHeader.getTaskType());
                taskDetail.setAllocationId(shipmentContainerDetaill.getId());
                taskDetail.setBillCode(shipmentContainerDetaill.getShipmentCode());
                taskDetail.setBillDetailId(shipmentContainerDetaill.getShipmentDetailId());
                taskDetail.setMaterialCode(shipmentContainerDetaill.getMaterialCode());
                taskDetail.setMaterialName(shipmentContainerDetaill.getMaterialName());
                taskDetail.setMaterialSpec(shipmentContainerDetaill.getMaterialSpec());
                taskDetail.setMaterialUnit(shipmentContainerDetaill.getMaterialUnit());
                taskDetail.setFromInventoryId(shipmentContainerDetaill.getInventoryId());
410
411
                taskDetail.setToInventoryId(shipmentContainerDetaill.getInventoryId());
                taskDetail.setInventorySts(shipmentContainerDetaill.getInventorySts());
412
413
414
415
416
417
418
                taskDetail.setQty(shipmentContainerDetaill.getQty());
                taskDetail.setContainerCode(taskHeader.getContainerCode());
                taskDetail.setFromLocation(taskHeader.getFromLocation());
                taskDetail.setToLocation(taskHeader.getToLocation());
                taskDetail.setLot(shipmentContainerDetaill.getLot());
                taskDetail.setWaveId(shipmentContainerDetaill.getWaveId());
                taskDetail.setBatch(shipmentContainerDetaill.getBatch());
周峰 authored
419
                taskDetail.setProjectNo(shipmentContainerDetaill.getProjectNo());
420
                taskDetail.setReferenceCode(shipmentDetail.getReferCode());
421
                taskDetail.setGoodsShelfNo(taskHeader.getGoodsShelfNo());
xqs authored
422
                if (shipmentContainerHeader.getStatus().equals(QuantityConstant.SHIPMENT_CONTAINER_TASK)) {
423
424
//                    taskDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD);
                    taskDetail.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
425
                } else {
pengcheng authored
426
                    taskDetail.setStatus(QuantityConstant.TASK_STATUS_RELEASE);
427
428
429
430
431
432
433
                }
                taskDetail.setCreatedBy(ShiroUtils.getLoginName());
                taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
                flag = taskDetailService.save(taskDetail);
                if(flag == false){
                    throw new ServiceException("新建任务明细失败,sql错误");
                }
434
435
                shipmentContainerDetaill.setStatus(QuantityConstant.SHIPMENT_CONTAINER_TASK);
                if (!shipmentContainerDetailService.updateById(shipmentContainerDetaill)) {
436
437
                    throw new ServiceException("修改组盘明细状态失败");
                }
438
439
            }
        }
pengcheng authored
440
441
442
        return shipmentContainerDetail;
    }
pengcheng authored
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469

    /**
     * 取消组盘的一组明细
     * @param detailIds
     * @return
     */
    @Override
    public AjaxResult cancelCombinationDetail(List<Integer> detailIds)  {
        List<ShipmentContainerDetail> shipmentContainerDetails = new ArrayList<>();
        for(int detailId:detailIds){
            ShipmentContainerDetail shipmentContainerDetail = shipmentContainerDetailService.getById(detailId);
            shipmentContainerDetails.add(shipmentContainerDetail);
        }
        return cancelCombinationDetailInner(shipmentContainerDetails);
    }

    /**
     * 取消组盘的一组明细
     * @param shipmentContainerDetails
     * @return
     */
    @Override
    @Transactional
    public AjaxResult cancelCombinationDetailInner(List<ShipmentContainerDetail> shipmentContainerDetails)  {
        for(ShipmentContainerDetail shipmentContainerDetail:shipmentContainerDetails){
            //获取头
            ShipmentContainerHeader shipmentContainerHeader = this.getById(shipmentContainerDetail.getShippingContainerId());
pengcheng authored
470
            if(shipmentContainerHeader.getStatus()>= QuantityConstant.SHIPMENT_CONTAINER_TASK){
pengcheng authored
471
472
473
474
                return AjaxResult.error("容器"+shipmentContainerHeader.getContainerCode()+"非新建状态,不允许取消明细");
            }
            //恢复占用库存
            InventoryDetail inventoryDetail = inventoryDetailService.getById(shipmentContainerDetail.getInventoryId());
周鸿 authored
475
476
477
478
            if(inventoryDetail!=null){
                inventoryDetail.setTaskQty(inventoryDetail.getTaskQty().subtract(shipmentContainerDetail.getQty()));
                inventoryDetailService.saveOrUpdate(inventoryDetail);
            }
pengcheng authored
479
480
            //恢复单据发货数量
            ShipmentDetail shipmentDetail = shipmentDetailService.getById(shipmentContainerDetail.getShipmentDetailId());
肖超群 authored
481
482
            shipmentDetail.setTaskQty(shipmentDetail.getTaskQty().subtract(shipmentContainerDetail.getQty()));
            if(shipmentDetail.getTaskQty().compareTo(BigDecimal.ZERO) != 0 ){
pengcheng authored
483
                shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_WAVE);//明细状态恢复,如果删除后还有以出数量就是波次
pengcheng authored
484
            }else{
pengcheng authored
485
                shipmentDetail.setStatus(QuantityConstant.SHIPMENT_HEADER_POOL );//明细状态
pengcheng authored
486
487
488
489
490
491
492
493
494
495
496
            }
            shipmentDetailService.saveOrUpdate(shipmentDetail);
            //删除这个配盘明细
            shipmentContainerDetailService.removeById(shipmentContainerDetail.getId());

            //查询头表下还有没有明细,如果没有,则删了这个头表
            ShipmentContainerDetail condition = new ShipmentContainerDetail();
            condition.setShippingContainerId(shipmentContainerDetail.getShippingContainerId());
            List<Map<String, Object>> list= shipmentContainerDetailService.selectListMapByEqual("id", condition);
            if(list==null||list.size() == 0){
                this.removeById(shipmentContainerHeader.getId());
游杰 authored
497
498
                locationService.updateStatus(shipmentContainerHeader.getLocationCode(),
                        QuantityConstant.STATUS_LOCATION_EMPTY);
pengcheng authored
499
500
501
502
503
504
505
            }
            //更新单据状态
            shipmentHeaderService.updateShipmentStatus(shipmentDetail.getShipmentId());
        }
        return AjaxResult.success("");
    }
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
    /**
     * 取消组盘
     * @param shipmentContainerIds
     * @return
     */
    @Override
    public AjaxResult cancelCombination(List<Integer> shipmentContainerIds)  {

        AjaxResult result = checkForCancelCombination(shipmentContainerIds);
        if(result.getCode()!= RetCode.SUCCESS.getValue()){
            return result;
        }
        for(int id : shipmentContainerIds){
            LambdaQueryWrapper<ShipmentContainerDetail> lambdaQueryWrapper=Wrappers.lambdaQuery();
            lambdaQueryWrapper.eq(ShipmentContainerDetail::getShippingContainerId,id);
            List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.list(lambdaQueryWrapper);
            result = cancelCombinationDetailInner(shipmentContainerDetails);
            if(result.hasErr()){
                return result;
            }
        }

        return AjaxResult.success("");
    }
pengcheng authored
530
531
532
533
534
535
536
537
538

    /**
     *  出库自动组盘
     * @param shipmentCode
     * @return
     */
    @Override
    @Transactional
    public AjaxResult autoCombination(String shipmentCode) {
539
540
541
542
543
544
545
        LambdaQueryWrapper<ShipmentHeader> shipmentHeaderLam = Wrappers.lambdaQuery();
        shipmentHeaderLam.eq(ShipmentHeader::getWarehouseCode,ShiroUtils.getWarehouseCode())
                .eq(ShipmentHeader::getCode,shipmentCode);
        ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(shipmentHeaderLam);
        if(shipmentHeader == null){
            throw new ServiceException("系统没有此单据");
        }
546
        shipmentPreferenceService.checkShipmentProcess(shipmentHeader.getId().toString(),100,shipmentCode);
547
pengcheng authored
548
549
550
        LambdaQueryWrapper<ShipmentDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentDetail::getShipmentCode, shipmentCode)
                .eq(ShipmentDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
pengcheng authored
551
        List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(lambdaQueryWrapper);
552
        if (shipmentDetailList.isEmpty()) {
pengcheng authored
553
554
            return AjaxResult.error("找不到子单链");
        }
555
        for(ShipmentDetail shipmentDetail: shipmentDetailList){
556
           /* if(shipmentDetail.getWaveId() != 0){
557
                return AjaxResult.error(shipmentCode+"单号已加入波次"+shipmentDetail.getWaveId()+",无法自动组盘");
558
            }*/
559
        }
pengcheng authored
560
561
562
563
564
        return this.autoCombination(shipmentDetailList);
    }


    //出库自动组盘
xqs authored
565
    @Override
pengcheng authored
566
567
    public AjaxResult autoCombination(List<ShipmentDetail> shipmentDetailList){
        int num = 0;
568
        List<Integer> list = new ArrayList<>();
569
        lable1:for (ShipmentDetail item : shipmentDetailList) {
pengcheng authored
570
            //获取需要出库数量
肖超群 authored
571
            BigDecimal shipmentQty = item.getQty().subtract(item.getTaskQty());
572
573
574
575
            String userDef1 = item.getUserDef1();
            if (StringUtils.isNotEmpty(userDef1)) {
                shipmentQty = new BigDecimal(userDef1);
            }
pengcheng authored
576
577
            //判断是否还有需要出库的物料,如果没有就跳过该物料
            if (shipmentQty.compareTo(BigDecimal.ZERO) <= 0) {
578
                continue lable1;
pengcheng authored
579
            }
xumiao authored
580
581
582
583
584
585
586
            List<InventoryDetail> inventoryList = null;
            if(item.getWarehouseCode().equals("CS0001")){
                inventoryList= shippingCombinationService.getInventorys(item);
            }
            if(item.getWarehouseCode().equals("KS0001")){
                inventoryList = shippingCombinationService.getInventoryAutoKS(item);
            }
xumiao authored
587
            if(inventoryList==null){
588
//                throw new ServiceException("没有可用库存");
589
                continue lable1;
xumiao authored
590
            }
591
            inventoryList = combCondit(inventoryList);
tongzhonghao authored
592
            if(inventoryList.isEmpty()){
593
                continue lable1;
594
//                throw new ServiceException("没有可用库存");
595
            }
lector authored
596
            //去除已锁的库存
597
            ArrayList<InventoryDetail> removeInventoryList = new ArrayList<>();
598
599
600
//            List<TaskHeader> taskHeaderList = taskHeaderService.getUnCompleteTaskList();
//            List<ReceiptContainerHeader> receiptContainerHeaderList =
//                    receiptContainerHeaderService.getUnCompleteCombineList();
lector authored
601
602
            boolean lock = false;
            for (InventoryDetail inventoryDetail : inventoryList) {
周鸿 authored
603
604
605
606
607
608
609
610
611
612
613
614
                // 校验锁定数量之前,先查询锁定工作令数据是否存在
//                LockingWorkOrder lockingWorkOrder = lockingWorkOrderService.selectLockingWorkOrder(item.getMoCode(), item.getMaterialCode(), item.getId().toString());
//                if (lockingWorkOrder == null){
//                    //校验库存是否有被锁定的数量
//                    LockingWorkOrder lockingWorkOrder1=new LockingWorkOrder();
//                    lockingWorkOrder1.setInventoryId(inventoryDetail.getId().toString());
//                    List<LockingWorkOrder> lockingWorkOrderList = lockingWorkOrderService.getListByDoamin(lockingWorkOrder1);
//                    BigDecimal qty = inventoryDetail.getQty().subtract(inventoryDetail.getTaskQty());
//                    if (lockingWorkOrderService.inventoryCheck(lockingWorkOrderList, qty, shipmentQty)){
//                        continue;
//                    }
//                }
xumiao authored
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
//                LambdaQueryWrapper<Container> containerLambdaQueryWrapper  = Wrappers.lambdaQuery();
//                containerLambdaQueryWrapper.eq(Container::getCode, inventoryDetail.getContainerCode());
//                Container container = containerService.getOne(containerLambdaQueryWrapper);
//                if (QuantityConstant.STATUS_CONTAINER_LOCK.equals(container.getStatus())) {
//                    removeInventoryList.add(inventoryDetail);
//                    lock = true;
//                }
//                if(taskHeaderList != null) {
//                    for(TaskHeader taskHeader : taskHeaderList) {
//                        if(taskHeader.getContainerCode().equals(container.getCode())) {
//                            removeInventoryList.add(inventoryDetail);
//                        }
//                    }
//                }
//                if(receiptContainerHeaderList != null) {
//                    for(ReceiptContainerHeader receiptContainerHeader : receiptContainerHeaderList) {
//                        if(receiptContainerHeader.getContainerCode().equals(container.getCode())) {
//                            removeInventoryList.add(inventoryDetail);
//                        }
//                    }
//                }
周鸿 authored
636
637
638
639
                // 判断锁定工作令数据是否需要修改
//                if (lockingWorkOrder != null){
//                    lockingWorkOrderService.checkLockingWorkOrder(lockingWorkOrder, shipmentQty);
//                }
lector authored
640
            }
641
            inventoryList.removeAll(removeInventoryList);
lector authored
642
            if (inventoryList.size()<1 && lock){
643
//                return AjaxResult.error("'"+item.getMaterialName()+"' 所在托盘全部处于锁定状态,请完成或取消任务后再进行组盘");
644
                continue lable1;
lector authored
645
646
            }
pengcheng authored
647
            if(inventoryList.size() < 1 && item.getWaveId() != 0){
pengcheng authored
648
                Wave wave = waveService.getById(item.getWaveId());
pengcheng authored
649
650
651
                wave.setStatus(QuantityConstant.WAVE_STATUS_ERROR);
                wave.setCurrentWaveStep(QuantityConstant.WAVE_STEP_ERROR);
                wave.setLastWaveStep(QuantityConstant.WAVE_STEP_BUILD);
pengcheng authored
652
                waveService.updateById(wave);
653
                throw new ServiceException("主单为"+item.getShipmentCode()+"子单id为"+item.getId() + "的单据没有库存,波次失败");
pengcheng authored
654
            }
pengcheng authored
655
656
657
            if (inventoryList.size() < 1) {
                num = num + 1;
            } else {
658
                //遍历扣减库存,知道扣完为止
659
                lable2:for (InventoryDetail inventory : inventoryList) {
pengcheng authored
660
661
                    //判断是否组盘完毕,完毕就退出内循环
                    if (shipmentQty.compareTo(BigDecimal.ZERO) <= 0) {
662
                        break lable2;
pengcheng authored
663
664
                    }
665
pengcheng authored
666
667
668
669
                    BigDecimal inventoryQty = inventory.getQty().subtract(inventory.getTaskQty());
                    ShipmentCombinationModel shipmentCombination = new ShipmentCombinationModel();
                    shipmentCombination.setInventoryDetailId(inventory.getId());
                    shipmentCombination.setShipmentDetailId(item.getId());
游杰 authored
670
                    shipmentCombination.setType((short) QuantityConstant.TASK_TYPE_WHOLESHIPMENT);
pengcheng authored
671
672
673
674
                    if (inventoryQty.compareTo(BigDecimal.ZERO) <= 0) {
                        continue lable2;
                    }
pengcheng authored
675
676
677
678
                    //如果库存数 >= 待出库数,组盘数就是待出库数并且结束组盘,否则组盘数就是库存数
                    if (inventoryQty.compareTo(shipmentQty) > -1) {
                        shipmentCombination.setShipQty(shipmentQty);
                    } else {
xumiao authored
679
                        shipmentCombination.setShipQty(inventoryQty);
pengcheng authored
680
                    }
681
                    try{
682
683
684
                        ShipmentContainerHeader shipmentContainerHeader=this.combination(shipmentCombination);
                        list.add(shipmentContainerHeader.getId());
                        shipmentQty = shipmentQty.subtract(shipmentCombination.getShipQty());
685
686
687
                    }catch (Exception e){
                        break lable2;
                    }
688
pengcheng authored
689
690
691
                }
            }
        }
692
693

        if(num == shipmentDetailList.size()){
易文鹏 authored
694
695
            //throw new ServiceException("单据物料的库存分配规则在此库区没有库存,无法出库");
            throw new ServiceException("此库区没有库存了,无法出库");
pengcheng authored
696
        }
pengcheng authored
697
        return AjaxResult.success("成功",list);
pengcheng authored
698
699
    }
700
701
702
703
704
705
706
707
708
    /**
     * 检查是否可以进行取消配盘
     * @param shipmentContainerIds
     * @return
     */
    @Override
    public AjaxResult checkForCancelCombination(List<Integer> shipmentContainerIds) {
        for(int id : shipmentContainerIds){
            ShipmentContainerHeader shipmentContainerHeader = this.getById(id);
709
710
711
            if(shipmentContainerHeader==null){
                return AjaxResult.error("找不到组盘信息");
            }
pengcheng authored
712
            if(shipmentContainerHeader.getStatus()>=QuantityConstant.SHIPMENT_CONTAINER_TASK){
713
714
715
716
717
718
719
720
721
722
723
724
725
                return AjaxResult.error("存在已生成任务的记录,请先取消任务再取消组盘");
            }
        }
        return AjaxResult.success("");
    }

    /* 生成任务 */
    @Override
    @Transactional
    public AjaxResult createTask(List<Integer> idList) {
        ShipmentTaskCreateModel shipmentTask = new ShipmentTaskCreateModel();
        for (Integer id : idList)   {
            shipmentTask.setShipmentContainerHeaderIds(id);
726
            AjaxResult ajaxResult = shipmentTaskService.createTaskFromShipmentContainers(shipmentTask);
pengcheng authored
727
728
729
            if(ajaxResult.hasErr()){
                return ajaxResult;
            }
730
731
732
733
        }
        return AjaxResult.success("全部生成完毕");
    }
lector authored
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
    /**
     * 取消出库任务
     */
    @Override
    @Transactional(rollbackFor = ServiceException.class)
    public boolean cancelShipment(Integer combineHeaderId) {
        // 回滚组盘主表状态
        ShipmentContainerHeader shipmentContainerHeader = new ShipmentContainerHeader();
        shipmentContainerHeader.setId(combineHeaderId);
        shipmentContainerHeader.setStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
        if (!updateById(shipmentContainerHeader)){
            throw new ServiceException("更新出库组盘头表失败");
        }
        // 回滚组盘明细状态
        LambdaQueryWrapper<ShipmentContainerDetail> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(ShipmentContainerDetail::getShippingContainerId,combineHeaderId);
        List<ShipmentContainerDetail> shipmentContainerDetailList = shipmentContainerDetailService.list(queryWrapper);
        for (ShipmentContainerDetail shipmentContainerDetail : shipmentContainerDetailList) {
            shipmentContainerDetail.setStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
        }
        if (!shipmentContainerDetailService.updateBatchById(shipmentContainerDetailList)){
            throw new ServiceException("更新出库组盘明细失败");
        }
        return true;
    }
760
761
762
763
    @Override
    public AjaxResult getShipmentInfoByCode(String code) {
        LambdaQueryWrapper<ShipmentContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentContainerDetail::getShipmentCode, code)
xumiao authored
764
                .le(ShiroUtils.getWarehouseCode().equals("KS0001"),ShipmentContainerDetail::getStatus,QuantityConstant.SHIPMENT_CONTAINER_TASK)
765
766
                .eq(ShipmentContainerDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .orderByAsc(ShipmentContainerDetail::getStatus);
767
768
769
770
771

        List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.list(lambdaQueryWrapper);
        return AjaxResult.success(shipmentContainerDetails);
    }
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
    @Override
    public int getUnCompleteCombineNumber(String containerCode) {
        LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        shipmentContainerHeaderLambdaQueryWrapper.eq(ShipmentContainerHeader::getContainerCode, containerCode)
                .lt(ShipmentContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_FINISHED);
        int number = 0;
        List<ShipmentContainerHeader> shipmentContainerHeaderList = list(shipmentContainerHeaderLambdaQueryWrapper);
        if(shipmentContainerHeaderList != null && shipmentContainerHeaderList.size() > 0) {
            number = shipmentContainerHeaderList.size();
        }
        return number;
    }

    @Override
    public List<ShipmentContainerHeader> getUnCompleteCombineList() {
        LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        shipmentContainerHeaderLambdaQueryWrapper.lt(ShipmentContainerHeader::getStatus,
                QuantityConstant.SHIPMENT_CONTAINER_FINISHED);
        List<ShipmentContainerHeader> shipmentContainerHeaderList =
                list(shipmentContainerHeaderLambdaQueryWrapper);
        return  shipmentContainerHeaderList;
    }
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
    private List<InventoryDetail> combCondit(List<InventoryDetail> inventoryDetails){
        List<Role> roles = roleService.selectRolesByUserId(ShiroUtils.getUserId(), ShiroUtils.getWarehouseCode());
        List<Integer> roleIds = roles.stream().map(Role::getId).collect(Collectors.toList());
        int role = QuantityConstant.ROLE_XC;
        int roleNum = 0;
        if(roleIds.contains(role)){
            roleNum = 1;
        }else{
            roleNum = 2;
        }
        String XC = QuantityConstant.ZONECODE_XC;
        List<InventoryDetail> returnList = Collections.EMPTY_LIST;
        for (InventoryDetail inventoryDetail : inventoryDetails) {
            if(roleNum == 1 && !XC.equals(inventoryDetail.getZoneCode())){
               return returnList;
            }else if(roleNum == 2 && XC.equals(inventoryDetail.getZoneCode())){
                return returnList;
            }
        }
        return inventoryDetails;
    }
817
}