ShipmentContainerHeaderServiceImpl.java 25 KB
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 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 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 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 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 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 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 470 471 472 473 474 475 476 477 478 479 480
package com.huaheng.pc.shipment.shipmentContainerHeader.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.domain.RetCode;
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;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
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;
import com.huaheng.pc.shipment.shippingCombination.domain.ShippingSearch;
import com.huaheng.pc.shipment.shippingCombination.service.ShippingCombinationService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.mapper.ShipmentContainerHeaderMapper;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentContainerHeaderMapper, ShipmentContainerHeader> implements ShipmentContainerHeaderService{

    @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;
    @Autowired
    private ShippingCombinationService shippingCombinationService;
    @Autowired
    private TaskHeaderService taskHeaderService;
    @Autowired
    private TaskDetailService taskDetailService;


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



    /**
     * 出库组盘单条保存
     * @param shipmentCombinationModel
     * @return
     */
    @Transactional
    @Override
    public ShipmentContainerHeader combination(ShipmentCombinationModel shipmentCombinationModel) {

        //校验
        if(shipmentCombinationModel.getShipQty().compareTo(new BigDecimal("0")) <= 0){
            throw new ServiceException("出库数量必须大于0");
        }
        ShipmentDetail shipmentDetail = shipmentDetailService.getById(shipmentCombinationModel.getShipmentDetailId());
        if(shipmentDetail==null){
            throw new ServiceException("出库明细未找到");
        }
        InventoryDetail inventoryDetail = inventoryDetailService.getById((shipmentCombinationModel.getInventoryDetailId()));
        if(inventoryDetail==null){
            throw new ServiceException("库存未找到");
        }
        //校验数量是否超出
        if((shipmentDetail.getShipQty().subtract(shipmentDetail.getRequestQty())).compareTo(shipmentCombinationModel.getShipQty())<0){
            throw new ServiceException("录入数量超出明细待出数量");
        }
        //校验库存可用数量
        if(inventoryDetail.getQty().subtract(inventoryDetail.getTaskQty()).subtract(inventoryDetail.getLockedQty()).compareTo(shipmentCombinationModel.getShipQty())<0){
            throw new ServiceException("录入数量超出可出数量");
        }
        if(!shipmentDetail.getMaterialCode().equals(inventoryDetail.getMaterialCode())){
            throw new ServiceException("配盘物料不一致");
        }
        //库位
        LambdaQueryWrapper<Location> lambdaQueryWrapper= Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(Location::getWarehouseCode,inventoryDetail.getWarehouseCode())
                .eq(Location::getCode,inventoryDetail.getLocationCode());
        Location location = locationService.getOne(lambdaQueryWrapper);
        if (location == null)
            throw new ServiceException("库位 "+ inventoryDetail.getLocationCode() +" 不存在");
//        if (location.getStatus().equals("lock"))    {
//            //如果库位状态是锁定的话,就查找出库组盘表,如果存在未下发
//            LambdaQueryWrapper<ShipmentContainerHeader> lam=Wrappers.lambdaQuery();
//            lam.eq(ShipmentContainerHeader::getWarehouseCode,ShiroUtils.getWarehouseCode())
//                    .eq(ShipmentContainerHeader::getContainerCode,location.getContainerCode())
//                    .eq(ShipmentContainerHeader::getTaskCreated,0);
//            ShipmentContainerHeader shipmentContainerHeader = this.getOne(lam);
//            if (shipmentContainerHeader == null)    {
//                throw new ServiceException("库位已经锁定不能使用");
//            }
//        }

        //更新库存分配数
        inventoryDetail.setTaskQty(inventoryDetail.getTaskQty().add(shipmentCombinationModel.getShipQty()));
        inventoryDetailService.saveOrUpdate(inventoryDetail);
        //获取库位,然后锁定
        if(location.getStatus().equals("empty")) {
            location.setStatus("lock");
            locationService.saveOrUpdate(location);
        }
        //更新单据明细的已出库数量
        shipmentDetail.setRequestQty(shipmentDetail.getRequestQty().add(shipmentCombinationModel.getShipQty()));
        int i = shipmentDetail.getShipQty().compareTo(shipmentDetail.getRequestQty());
        if(i > 0){
            shipmentDetail.setStatus(200);
        }else if(i == 0){
            shipmentDetail.setStatus(300);
        }else if(i < 0){
            throw new ServiceException("出库数量不能大于单据数量!");
        }
        shipmentDetailService.saveOrUpdate(shipmentDetail);

        //自动判定出库任务状态,根据库存数量减去预定库存相等就是整盘出--预计任务状态
        BigDecimal inventoryQty = inventoryDetail.getQty().subtract(inventoryDetail.getTaskQty());
        if(inventoryQty.compareTo(new BigDecimal(0)) <= 0) {
            shipmentCombinationModel.setTaskType(300);
        } else {
            shipmentCombinationModel.setTaskType(400);
        }

        //增加出库组盘头
        ShipmentContainerHeader shipmentContainerHeader = ShipmentContainerHeaderAdd(location, shipmentDetail, shipmentCombinationModel);
        //增加出库组盘明细
        ShipmentContainerDetail shipmentContainerDetail = ShipmentContainerDetailAdd(shipmentDetail, shipmentContainerHeader, shipmentCombinationModel);
        //更新单据状态
        shipmentHeaderService.updateShipmentStatus(shipmentDetail.getShipmentId());

        return  shipmentContainerHeader;
    }

    /**
     * 在组盘表中查找任务状态小于20的容器,如果状态为0就合并出库明细,状态大于0就提示不能组盘。如果找不到就新增一条组盘表头
     * @param location
     * @param shipmentCombination
     * @return
     */
    private ShipmentContainerHeader ShipmentContainerHeaderAdd(Location location,
                                                               ShipmentDetail shipmentDetail,
                                                               ShipmentCombinationModel shipmentCombination) {
        LambdaQueryWrapper<ShipmentContainerHeader> lambdaQueryWrapper=Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentContainerHeader::getContainerCode,location.getContainerCode())
                .eq(ShipmentContainerHeader::getWarehouseCode,ShiroUtils.getWarehouseCode())
                .le(ShipmentContainerHeader::getStatus,20);
        ShipmentContainerHeader shipmentContainerHeader = this.getOne(lambdaQueryWrapper);
        if(shipmentContainerHeader != null)  {
            return shipmentContainerHeader;
        }
        else {
//            LambdaQueryWrapper<ShipmentContainerHeader> lam=Wrappers.lambdaQuery();
//            lam.eq(ShipmentContainerHeader::getContainerCode,location.getContainerCode())
//                    .eq(ShipmentContainerHeader::getWarehouseCode,ShiroUtils.getWarehouseCode())
//                    .eq(ShipmentContainerHeader::getTaskCreated,0)
//                    .eq(ShipmentContainerHeader::getStatus,0);
//            shipmentContainerHeader = this.getOne(lam);
//            if (shipmentContainerHeader == null) {
                shipmentContainerHeader = new ShipmentContainerHeader();
                shipmentContainerHeader.setContainerCode(location.getContainerCode());
                shipmentContainerHeader.setLocationCode(location.getCode());
                shipmentContainerHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
                //赋值u8仓库
                shipmentContainerHeader.setCompanyCode(shipmentDetail.getCompanyCode());
                shipmentContainerHeader.setStatus(0);
                shipmentContainerHeader.setTaskCreated(0);
                shipmentContainerHeader.setCreatedBy(ShiroUtils.getLoginName());
                shipmentContainerHeader.setCreated(null);
//            Material material=new Material();
//            material.setCode(shipmentDetail.getMaterialCode());
//            shipmentContainerHeader.setZoneCode(materialService.selectFirstEntity(material).getZoneCode());
                this.save(shipmentContainerHeader);
            return shipmentContainerHeader;
            }
//        }
    }

    /**
     * 查询 容器编码、库存Id、出库明细Id 一致的组盘明细,如果存在则增加组盘数量,如果不存在就新增一条组盘明细
     * @param shipmentDetail
     * @param shipmentContainerHeader
     * @param shipmentCombinationModel
     * @return
     */
    private ShipmentContainerDetail ShipmentContainerDetailAdd(ShipmentDetail shipmentDetail,
                                                               ShipmentContainerHeader shipmentContainerHeader,
                                                               ShipmentCombinationModel shipmentCombinationModel) {
        LambdaQueryWrapper<ShipmentContainerDetail> lambdaQueryWrapper=Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentContainerDetail::getShippingContainerId,shipmentContainerHeader.getId())
                .eq(ShipmentContainerDetail::getShipmentDetailId,shipmentCombinationModel.getShipmentDetailId())
                .eq(ShipmentContainerDetail::getWarehouseCode,ShiroUtils.getWarehouseCode());
        ShipmentContainerDetail shipmentContainerDetail = shipmentContainerDetailService.getOne(lambdaQueryWrapper);
        if(shipmentContainerDetail != null)    {
            shipmentContainerDetail.setQty(shipmentContainerDetail.getQty().add(shipmentCombinationModel.getShipQty()));
            shipmentContainerDetailService.saveOrUpdate(shipmentContainerDetail);
        }
        else    {
            //构建明细

            LambdaQueryWrapper<Material> lam=Wrappers.lambdaQuery();
            lam.eq(Material::getCode,shipmentDetail.getMaterialCode())
                    .eq(Material::getWarehouseCode,ShiroUtils.getWarehouseCode());
            Material material = materialService.getOne(lam);
            if (material == null)
                throw new ServiceException("出库单(" + shipmentDetail.getShipmentCode() + ")的物料("+ shipmentDetail.getMaterialCode() +")不存在!");
            shipmentContainerDetail = new ShipmentContainerDetail();
            shipmentContainerDetail.setWarehouseCode(shipmentContainerHeader.getWarehouseCode());
            shipmentContainerDetail.setCompanyCode(shipmentContainerHeader.getCompanyCode());
            shipmentContainerDetail.setContainerCode(shipmentContainerHeader.getContainerCode());
            shipmentContainerDetail.setLocationCode(shipmentContainerHeader.getLocationCode());
            shipmentContainerDetail.setInventoryId(shipmentCombinationModel.getInventoryDetailId());
            shipmentContainerDetail.setInventorySts(shipmentDetail.getInventorySts());
            shipmentContainerDetail.setShippingContainerId(shipmentContainerHeader.getId());
            shipmentContainerDetail.setShipmentCode(shipmentDetail.getShipmentCode());
            shipmentContainerDetail.setShipmentId(shipmentDetail.getShipmentId());
            shipmentContainerDetail.setShipmentDetailId(shipmentCombinationModel.getShipmentDetailId());
            shipmentContainerDetail.setMaterialCode(material.getCode());
            shipmentContainerDetail.setMaterialName(material.getName());
            shipmentContainerDetail.setMaterialSpec(material.getSpec());
            shipmentContainerDetail.setQty(shipmentCombinationModel.getShipQty());
            shipmentContainerDetail.setCreated(null);
            shipmentContainerDetail.setCreatedBy(ShiroUtils.getLoginName());
            shipmentContainerDetailService.save(shipmentContainerDetail);
        }

        //
        if(shipmentContainerHeader.getStatus()>=10 && shipmentContainerHeader.getStatus()<30){
            LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper=Wrappers.lambdaQuery();
            taskHeaderLambdaQueryWrapper.eq(TaskHeader::getWarehouseCode,shipmentContainerHeader.getWarehouseCode())
                    .eq(TaskHeader::getInternalTaskType,200)
                    .eq(TaskHeader::getAllocationHeadId,shipmentContainerHeader.getId());
            TaskHeader taskHeader=taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
            if(taskHeader==null){
                throw new ServiceException("有相同的组盘头,但找不到相应的任务头");
            }
            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(shipmentContainerDetail.getId());
            taskDetail.setBillCode(shipmentContainerDetail.getShipmentCode());
            taskDetail.setBillDetailId(shipmentContainerDetail.getShipmentDetailId());
            taskDetail.setMaterialCode(shipmentContainerDetail.getMaterialCode());
            taskDetail.setMaterialName(shipmentContainerDetail.getMaterialName());
            taskDetail.setMaterialSpec(shipmentContainerDetail.getMaterialSpec());
            taskDetail.setMaterialUnit(shipmentContainerDetail.getMaterialUnit());
            taskDetail.setFromInventoryId(shipmentContainerDetail.getInventoryId());
            taskDetail.setQty(shipmentContainerDetail.getQty());
            taskDetail.setContainerCode(taskHeader.getContainerCode());
            taskDetail.setFromLocation(taskHeader.getFromLocation());
            taskDetail.setToLocation(taskHeader.getToLocation());
            if(shipmentContainerHeader.getStatus()==10) {
                taskDetail.setStatus(0);
            }else {
                taskDetail.setStatus(10);
            }
            taskDetail.setTaskType(taskHeader.getTaskType());
            taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
            taskDetail.setLastUpdated(null);
            taskDetailService.save(taskDetail);
        }
        return shipmentContainerDetail;
    }


    /**
     * 取消组盘的一组明细
     * @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());
            if(shipmentContainerHeader.getStatus()>9){
                return AjaxResult.error("容器"+shipmentContainerHeader.getContainerCode()+"非新建状态,不允许取消明细");
            }
            //恢复占用库存
            InventoryDetail inventoryDetail = inventoryDetailService.getById(shipmentContainerDetail.getInventoryId());
            inventoryDetail.setTaskQty(inventoryDetail.getTaskQty().subtract(shipmentContainerDetail.getQty()));
            inventoryDetailService.saveOrUpdate(inventoryDetail);
            //恢复单据发货数量
            ShipmentDetail shipmentDetail = shipmentDetailService.getById(shipmentContainerDetail.getShipmentDetailId());
            shipmentDetail.setRequestQty(shipmentDetail.getRequestQty().subtract(shipmentContainerDetail.getQty()));
            if(shipmentDetail.getRequestQty().compareTo(BigDecimal.ZERO) != 0 ){
                shipmentDetail.setStatus(200);//明细状态恢复,如果删除后还有以出数量就是波次
            }else{
                shipmentDetail.setStatus(0 );//明细状态
            }
            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());
                locationService.updateStatus(shipmentContainerHeader.getLocationCode(),"empty");
            }
            //更新单据状态
            shipmentHeaderService.updateShipmentStatus(shipmentDetail.getShipmentId());
        }
        return AjaxResult.success("");
    }

    /**
     * 取消组盘
     * @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("");
    }

    /**
     *  出库自动组盘
     * @param shipmentCode
     * @return
     */
    @Override
    @Transactional
    public AjaxResult autoCombination(String shipmentCode) {
        int num=0;
        AjaxResult ajaxResult=new AjaxResult();

        LambdaQueryWrapper<ShipmentDetail> lambdaQueryWrapper=Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ShipmentDetail::getShipmentCode,shipmentCode)
                .eq(ShipmentDetail::getWarehouseCode,ShiroUtils.getWarehouseCode());
        List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(lambdaQueryWrapper);
        if(shipmentDetailList.size()<1 || shipmentDetailList==null){
            return AjaxResult.error("找不到子单链");
        }
        for (ShipmentDetail item : shipmentDetailList) {
            //获取需要出库数量
            BigDecimal shipmentQty = item.getShipQty().subtract(item.getRequestQty());
            //判断是否还有需要出库的物料,如果没有就跳过该物料
            if (shipmentQty.compareTo(BigDecimal.ZERO) <= 0) {
                continue;
            }
            // 根据 仓库编码、货主编码、存货编码,物料状态,项目号来查找可以出库的物料
//            ShippingSearch search = new ShippingSearch();
//            search.setWarehouseCode(ShiroUtils.getWarehouseCode());
//            search.setCompanyCode(item.getCompanyCode());
//            search.setMaterialCode(item.getMaterialCode());
//            search.setInventorySts(item.getInventorySts()); //物料状态

            List<InventoryDetail> inventoryList = shippingCombinationService.getInventorys(item);
            if (inventoryList.size() < 1) {
                num = num + 1;
            } else {
                for (InventoryDetail inventory : inventoryList) {
                    //判断是否组盘完毕,完毕就退出内循环
                    if (shipmentQty.compareTo(BigDecimal.ZERO) <= 0) {
                        break;
                    }

                    BigDecimal inventoryQty = inventory.getQty().subtract(inventory.getTaskQty());
                    ShipmentCombinationModel shipmentCombination = new ShipmentCombinationModel();
                    shipmentCombination.setInventoryDetailId(inventory.getId());
                    shipmentCombination.setShipmentDetailId(item.getId());
                    shipmentCombination.setType((short) 300);
                    List<Integer> list=new ArrayList<>();
                    //如果库存数 >= 待出库数,组盘数就是待出库数并且结束组盘,否则组盘数就是库存数
                    if (inventoryQty.compareTo(shipmentQty) > -1) {
                        shipmentCombination.setShipQty(shipmentQty);
                        ShipmentContainerHeader shipmentContainerHeader=this.combination(shipmentCombination);
                    } else {
                        shipmentCombination.setShipQty(inventoryQty);
                        ShipmentContainerHeader shipmentContainerHeader=this.combination(shipmentCombination);
                        list.add(shipmentContainerHeader.getId());
                    }
                    shipmentQty = shipmentQty.subtract(shipmentCombination.getShipQty());
                }
            }
        }
        if(num==shipmentDetailList.size()){
            throw new ServiceException("单据物料在此库区没有库存,无法出库");
        }
        return AjaxResult.success("成功");
    }

    /**
     * 检查是否可以进行取消配盘
     * @param shipmentContainerIds
     * @return
     */
    @Override
    public AjaxResult checkForCancelCombination(List<Integer> shipmentContainerIds) {
        for(int id : shipmentContainerIds){
            ShipmentContainerHeader shipmentContainerHeader = this.getById(id);
            if(shipmentContainerHeader.getStatus()>9){
                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);
            AjaxResult ajaxResult = taskHeaderService.createTaskFromShipmentContainers(shipmentTask);
            if(ajaxResult.hasErr()){
                return ajaxResult;
            }
        }
        return AjaxResult.success("全部生成完毕");
    }

}