ShipmentAdviceService.java 25.2 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
package com.huaheng.pc.shipment.shipmentContainerAdvice.service;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.sn.domain.SnPartDetailHistory;
import com.huaheng.pc.config.sn.service.SnPartDetailHistoryService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.shipment.shipmentContainerAdvice.domain.ShipmentContainerAdvice;
import com.huaheng.pc.shipment.shipmentContainerAdvice.service.ShipmentContainerAdviceService;
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


@Service
public class ShipmentAdviceService{

    @Resource
    private ShipmentHeaderService shipmentHeaderService;

    @Autowired
    private ShipmentContainerHeaderService shipmentContainerHeaderService;
    @Autowired
    private ShipmentContainerAdviceService shipmentContainerAdviceService;
    @Autowired
    private LocationService locationService;
    @Autowired
    private TaskHeaderService taskHeaderService;
    @Autowired
    private StationService stationService;
    @Resource
    private ShipmentDetailService shipmentDetailService;
    @Resource
    private ShipmentContainerDetailService shipmentContainerDetailService;
    @Resource
    private InventoryHeaderService inventoryHeaderService;
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private InventoryTransactionService inventoryTransactionService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private SnPartDetailHistoryService snPartDetailHistoryService;
    @Resource
    private IUserService userService;



    /**
     * 自动预配盘出库
     * @param shipmentId
     * @param warehouseCode
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult autoShipmentAdvice(Integer shipmentId, String warehouseCode) {
        if (StringUtils.isEmpty(shipmentId)) {
            return AjaxResult.error("自动预配盘出库, 出库单编码为空");
        }
        ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentId);
        if (shipmentHeader == null) {
            throw new ServiceException("自动预配盘出库, 没有找到出库单");
        }
        warehouseCode=shipmentHeader.getWarehouseCode();
        if(StringUtils.isEmpty(shipmentHeader.getCompanyCode())){
            throw new ServiceException("自动预配盘出库, 没有找到出库单货主");
        }
        if(StringUtils.isEmpty(shipmentHeader.getUWarehouseCode())){
            throw new ServiceException("自动预配盘出库, 没有找到出库单上游仓库");
        }
        String shipmentCode=shipmentHeader.getCode();
        AjaxResult result = shipmentContainerHeaderService.autoCombination(shipmentCode,true,warehouseCode);
        if (result.hasErr()) {
            throw new ServiceException("自动预配盘出库," + result.getMsg());
        }
        List<ShipmentContainerAdvice> shipmentContainerAdviceList =
                shipmentContainerAdviceService.getShipmentContainerAdviceListByShipmentCode(shipmentCode, warehouseCode);
        if (CollectionUtils.isEmpty(shipmentContainerAdviceList)) {
            throw new ServiceException("自动预配盘出库, 没有找到出库配盘详情或找不到含SN库存");
        }
        List<Integer> shipmentContainerIdList =
                shipmentContainerAdviceList.stream().map(ShipmentContainerAdvice::getShipmentContainerId).distinct().collect(Collectors.toList());
        long shipmentOrder = System.currentTimeMillis();
        int sequenceNumber = shipmentContainerIdList.size();
        int sequence = 0;
        for (int shipmentContainerId : shipmentContainerIdList) {
            sequence++;
            ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.getById(shipmentContainerId);
            if (shipmentContainerHeader == null) {
                throw new ServiceException("自动预配盘出库, 没有找到出库表头:" + shipmentContainerId);
            }
            int taskType = shipmentContainerHeader.getTaskType();
            int type = QuantityConstant.STATION_PICK;
            if (taskType == QuantityConstant.TASK_TYPE_WHOLESHIPMENT) {
                type = QuantityConstant.STATION_OUT;
            }
            String fromLocationCode = shipmentContainerHeader.getLocationCode();
            if (StringUtils.isEmpty(fromLocationCode)) {
                throw new ServiceException("自动预配盘出库, 没有起始库位编码");
            }
            Location fromLocation = locationService.getLocationByCode(fromLocationCode, warehouseCode);
            if (fromLocation == null) {
                throw new ServiceException("自动预配盘出库, 没有起始库位" + fromLocationCode);
            }
            String roadWay = fromLocation.getRoadway();
            List<Station> portList =stationService.getListByType(type, roadWay, shipmentContainerHeader.getZoneCode(), warehouseCode);
            String portcode=null;
            if (portList == null||portList.size()==0) {
                //地面库没有站台
//                throw new ServiceException("自动预配盘出库, 没有合适的出库口");
            }else{
                Station port = portList.get(0);
                portcode=port.getCode();
            }

            ShipmentContainerHeader shipmentContainerHeader1 = new ShipmentContainerHeader();
            shipmentContainerHeader1.setId(shipmentContainerHeader.getId());
            shipmentContainerHeader1.setPort(portcode);
            shipmentContainerHeader1.setAdvice(QuantityConstant.STATUS_OPEN);
            boolean success = shipmentContainerHeaderService.updateById(shipmentContainerHeader1);
            if (!success) {
                throw new ServiceException("自动预配盘出库, 更新出库组盘头失败");
            }
            result = shipmentContainerAdviceService.createCallShipmentTask(shipmentContainerHeader, warehouseCode, shipmentOrder, sequence, sequenceNumber);
            if (result.hasErr()) {
                throw new ServiceException("自动预配盘出库, " + result.getMsg());
            }
            String containerCode = shipmentContainerHeader.getContainerCode();
            if (StringUtils.isEmpty(containerCode)) {
                throw new ServiceException("自动预配盘出库, 容器号为空");
            }
            TaskHeader taskHeader = taskHeaderService.getUnCompleteTaskByContainerCode(containerCode, warehouseCode);
            if (taskHeader == null) {
                throw new ServiceException("自动预配盘出库, 没有找到容器号对应任务" + containerCode);
            }
        }
        return AjaxResult.success("自动预配盘出库成功");
    }

    @Transactional(rollbackFor = Exception.class)
    public AjaxResult reduceInventoryDetailBySn(String snList, String warehouseCode) {
        List<String> snList1 = Arrays.asList(snList.split(","));
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.in(InventoryDetail::getSn, snList1).eq(InventoryDetail::getWarehouseCode, warehouseCode);
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(inventoryDetailList)) {
            return AjaxResult.error("预配盘扣减库存失败,没有找到库存详情");
        }
        List<String> containerCodeList =
                inventoryDetailList.stream().map(InventoryDetail::getContainerCode).distinct().collect(java.util.stream.Collectors.toList());
        if (containerCodeList.size() > 1) {
            return AjaxResult.error("预配盘扣减库存失败,库存详情不在同一个托盘上");
        }
        String containerCode = containerCodeList.get(0);
        TaskHeader taskHeader = taskHeaderService.getUnCompleteTaskByContainerCode(containerCode, warehouseCode);
        if (taskHeader == null) {
            return AjaxResult.error("预配盘扣减库存失败,托盘号:" + containerCode + "没有未完成的任务");
        }
        if (taskHeader.getTaskType() != QuantityConstant.TASK_TYPE_SORTINGSHIPMENT) {
            return AjaxResult.error("预配盘扣减库存失败,托盘号:" + containerCode + "不是出库任务");
        }
        for (InventoryDetail inventoryDetail : inventoryDetailList) {
            String materialCode = inventoryDetail.getMaterialCode();
            LambdaQueryWrapper<ShipmentContainerAdvice> shipmentContainerAdviceLambdaQueryWrapper = Wrappers.lambdaQuery();
            shipmentContainerAdviceLambdaQueryWrapper.eq(ShipmentContainerAdvice::getMaterialCode, materialCode)
                    .eq(ShipmentContainerAdvice::getContainerCode, containerCode)
                    .lt(ShipmentContainerAdvice::getStatus, QuantityConstant.SHIPMENT_CONTAINER_TASK);
            List<ShipmentContainerAdvice> shipmentContainerAdvices = shipmentContainerAdviceService.list(shipmentContainerAdviceLambdaQueryWrapper);
            if (shipmentContainerAdvices == null||shipmentContainerAdvices.size()==0) {
                throw new ServiceException("预配盘扣减库存失败,托盘号:" + containerCode + "没有找到物料编码:" + materialCode + "的预配盘");
            }

            List<ShipmentContainerAdvice> shipmentContainerAdvice2=shipmentContainerAdvices.stream().filter(l ->
                    l.getInventoryDetailId().equals(inventoryDetail.getId())
            ).collect(Collectors.toList());
            ShipmentContainerAdvice shipmentContainerAdvice=null;
            if(shipmentContainerAdvice2.size()>0){
                shipmentContainerAdvice=shipmentContainerAdvice2.get(0);
            }else{
                shipmentContainerAdvice=shipmentContainerAdvices.get(0);
            }
            BigDecimal inventoryDetailQty = inventoryDetail.getQty();
            BigDecimal shipmentContainerAdviceQty = shipmentContainerAdvice.getQty();
            BigDecimal shipmentContainerAdviceTaskQty = shipmentContainerAdvice.getTaskQty();
            BigDecimal qty = shipmentContainerAdviceQty.subtract(shipmentContainerAdviceTaskQty);
            if (inventoryDetailQty.compareTo(qty) > 0) {
                throw new ServiceException("预配盘扣减库存失败, sn:"+inventoryDetail.getSn()+",库存详情ID:" + inventoryDetail.getId() + "的数量大于预配盘ID:" + shipmentContainerAdvice.getId() + "的数量");
            }
            shipmentContainerAdviceTaskQty = shipmentContainerAdviceTaskQty.add(inventoryDetailQty);
            if (!shipmentContainerAdviceService.updateTaskQtyById(shipmentContainerAdviceTaskQty, shipmentContainerAdvice.getId())) {
                throw new ServiceException("预配盘扣减库存失败, 更新预配盘ID:" + shipmentContainerAdvice.getId() + "的任务数量失败");
            }
            ShipmentDetail shipmentDetail = shipmentDetailService.getById(shipmentContainerAdvice.getShipmentDetailId());
            if (shipmentDetail == null) {
                throw new ServiceException("预配盘扣减库存失败, 没有找到出库单,出库详情ID:" + shipmentContainerAdvice.getShipmentDetailId());
            }
            BigDecimal shipmentDetailShipmentQty = shipmentDetail.getTaskQty();
//            shipmentDetailShipmentQty = shipmentDetailShipmentQty.add(inventoryDetailQty);
//            if (shipmentDetailShipmentQty.compareTo(shipmentDetail.getQty()) > 0) {
//                throw new ServiceException("预配盘扣减库存失败, 出库单ID:" + shipmentDetail.getShipmentId() + "的出库数量大于出库单数量");
//            }
            if (!shipmentDetailService.updateTashQtyById(shipmentDetailShipmentQty, shipmentDetail.getId())) {
                throw new ServiceException("预配盘扣减库存失败, 更新出库单ID:" + shipmentDetail.getShipmentId() + "的出库数量失败");
            }
            if (shipmentDetailShipmentQty.compareTo(shipmentDetail.getQty()) == 0) {
                if (!shipmentDetailService.updateStatusById(QuantityConstant.SHIPMENT_HEADER_COMPLETED, shipmentDetail.getId())) {
                    throw new ServiceException("预配盘扣减库存失败, 更新出库单ID:" + shipmentDetail.getShipmentId() + "的状态失败");
                }
            }
            ShipmentContainerHeader shipmentContainerHeader = shipmentContainerHeaderService.getById(shipmentContainerAdvice.getShipmentContainerId());
            if (shipmentContainerHeader == null) {
                throw new ServiceException("预配盘扣减库存失败, 没有找到" + shipmentContainerAdvice.getShipmentContainerId() + "的出库组盘头");
            }
            ShipmentContainerDetail shipmentContainerDetail = new ShipmentContainerDetail();
            shipmentContainerDetail.setShipmentCode(shipmentContainerAdvice.getShipmentCode());
            shipmentContainerDetail.setShippingContainerId(shipmentContainerHeader.getId());
            shipmentContainerDetail.setMaterialCode(shipmentContainerAdvice.getMaterialCode());
            shipmentContainerDetail.setMaterialName(shipmentContainerAdvice.getMaterialName());
            shipmentContainerDetail.setMaterialSpec(shipmentContainerAdvice.getMaterialSpec());
            shipmentContainerDetail.setMaterialUnit(shipmentContainerAdvice.getMaterialUnit());
            shipmentContainerDetail.setQty(inventoryDetailQty);
            shipmentContainerDetail.setSn(inventoryDetail.getSn());
            shipmentContainerDetail.setInventoryId(inventoryDetail.getId());
            shipmentContainerDetail.setShipmentId(shipmentContainerAdvice.getShipmentId());
            shipmentContainerDetail.setBatch(shipmentContainerAdvice.getBatch());
            shipmentContainerDetail.setContainerCode(shipmentContainerAdvice.getContainerCode());
            shipmentContainerDetail.setLocationCode(inventoryDetail.getLocationCode());
            shipmentContainerDetail.setWarehouseCode(warehouseCode);
            shipmentContainerDetail.setShipmentDetailId(shipmentContainerAdvice.getShipmentDetailId());
            shipmentContainerDetail.setShipmentId(shipmentContainerAdvice.getShipmentId());
            shipmentContainerDetail.setCompanyCode(shipmentContainerAdvice.getCompanyCode());
            shipmentContainerDetail.setInventorySts(inventoryDetail.getInventorySts());
            if (!shipmentContainerDetailService.save(shipmentContainerDetail)) {
                throw new ServiceException("预配盘扣减库存失败, 保存出库组盘明细表失败");
            }
            //生成任务
            TaskDetail taskDetail = new TaskDetail();
            taskDetail.setTaskId(taskHeader.getId());
            taskDetail.setInternalTaskType(taskHeader.getInternalTaskType());
            taskDetail.setCompanyCode(taskHeader.getCompanyCode());
            taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
            taskDetail.setUWarehouseCode(shipmentContainerDetail.getUWarehouseCode());
            taskDetail.setErpWarehouseCode(shipmentContainerDetail.getErpWarehouseCode());
            taskDetail.setCompanyCode(taskHeader.getCompanyCode());
            taskDetail.setTaskType(taskHeader.getTaskType());
            taskDetail.setToInventoryId(shipmentContainerDetail.getInventoryId());
            taskDetail.setAllocationId(shipmentContainerDetail.getId());
            taskDetail.setBillCode(shipmentContainerDetail.getShipmentCode());
            taskDetail.setBillDetailId(shipmentContainerDetail.getShipmentDetailId());
            taskDetail.setReferenceCode(shipmentDetail.getReferCode());
            try {
                taskDetail.setReferenceLineId(Integer.valueOf(shipmentDetail.getReferLineNum()));
            } catch (NumberFormatException e) {
            }
            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.setGoodsShelfNo(taskHeader.getGoodsShelfNo());
            taskDetail.setFromLocation(taskHeader.getFromLocation());
            taskDetail.setReferenceCode(shipmentDetail.getReferCode());
            taskDetail.setMoCode(shipmentDetail.getMoCode());
            taskDetail.setLot(shipmentContainerDetail.getLot());
            taskDetail.setBatch(shipmentContainerDetail.getBatch());
            taskDetail.setProjectNo(shipmentContainerDetail.getProjectNo());
            taskDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD);
            taskDetail.setWaveId(shipmentContainerDetail.getWaveId());
            taskDetail.setInventorySts(shipmentContainerDetail.getInventorySts());
            taskDetail.setSn(shipmentContainerDetail.getSn());

            taskDetail.setCreatedBy(shipmentContainerDetail.getCreatedBy());
            if (!taskDetailService.save(taskDetail)) {
                throw new ServiceException("新建任务明细失败,sql报错");
            }

            InventoryTransaction inventoryTransaction = new InventoryTransaction();
            inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
            inventoryTransaction.setWarehouseCode(warehouseCode);
            inventoryTransaction.setCompanyCode(inventoryDetail.getCompanyCode());
            inventoryTransaction.setContainerCode(containerCode);
            inventoryTransaction.setZoneCode(inventoryDetail.getZoneCode());
            inventoryTransaction.setLocationCode(inventoryDetail.getLocationCode());
            inventoryTransaction.setMaterialCode(inventoryDetail.getMaterialCode());
            inventoryTransaction.setMaterialName(inventoryDetail.getMaterialName());
            inventoryTransaction.setMaterialSpec(inventoryDetail.getMaterialSpec());
            inventoryTransaction.setMaterialUnit(inventoryDetail.getMaterialUnit());
            inventoryTransaction.setInventorySts(inventoryDetail.getInventorySts());
            inventoryTransaction.setBillCode(shipmentContainerAdvice.getShipmentCode());
            inventoryTransaction.setBillDetailId(shipmentContainerAdvice.getShipmentDetailId());

            inventoryTransaction.setBatch(inventoryDetail.getBatch());
            inventoryTransaction.setLot(inventoryDetail.getLot());
            inventoryTransaction.setProjectNo(inventoryDetail.getProjectNo());
            inventoryTransaction.setTaskQty(inventoryDetailQty);
            inventoryTransaction.setSn(inventoryDetail.getSn());
            inventoryTransaction.setMoCode(inventoryDetail.getMoCode());
            inventoryTransaction.setReferCode(shipmentDetail.getReferCode());
            inventoryTransaction.setReferDetailId(shipmentDetail.getReferLineNum());
            inventoryTransaction.setBillCode(shipmentDetail.getShipmentCode());
            inventoryTransaction.setBillDetailId(shipmentDetail.getId());

            if (!inventoryTransactionService.save(inventoryTransaction)) {
                throw new ServiceException("预配盘扣减库存失败, 保存库存交易记录失败");
            }
            //sn记录
            this.createdSnHistory(inventoryDetail,shipmentDetail.getShipmentCode(),inventoryTransaction.getCreatedBy(),shipmentDetail.getReferCode(),shipmentDetail.getReferLineNum());
            if (!inventoryDetailService.removeById(inventoryDetail.getId())) {
                throw new ServiceException("预配盘扣减库存失败, 删除库存明细" + inventoryDetail.getId() + "失败");
            }

            Integer adviceInventory=shipmentContainerAdvice.getInventoryDetailId();
            if(adviceInventory!=null&&!adviceInventory.equals(inventoryDetail.getId())){
                InventoryDetail inventoryDetail1=inventoryDetailService.getById(adviceInventory);
                InventoryDetail inventoryDetail2=new InventoryDetail();
                inventoryDetail2.setId(inventoryDetail1.getId());
                BigDecimal qtyAdvice=inventoryDetail1.getTaskQty().subtract(inventoryDetail.getQty());
                inventoryDetail2.setTaskQty(qtyAdvice);
                inventoryDetailService.updateById(inventoryDetail2);
            }

        }
        InventoryHeader inventoryHeader = inventoryHeaderService.getInventoryHeaderByContainerCode(containerCode, warehouseCode);
        if (inventoryHeader == null) {
            throw new ServiceException("预配盘扣减库存失败, 没有找到" + containerCode + "库存表头");
        }
        List<InventoryDetail> inventoryDetailList1 = inventoryDetailService.getInventoryDetailListByInventoryHeaderId(inventoryHeader.getId());
        if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(inventoryDetailList1)) {
            if (!inventoryHeaderService.removeById(inventoryHeader.getId())) {
                throw new ServiceException("预配盘扣减库存失败,删除库存头失败" + inventoryHeader.getId());
            }
        } else {
            if (!taskHeaderService.combineInventoryDetail(containerCode, warehouseCode)) {
                throw new ServiceException("预配盘扣减库存失败,托盘:" + containerCode + "调整库存失败");
            }
        }
        return AjaxResult.success("预配盘扣减库存成功");
    }

    /**
     * 保存sn记录表
     */
    public void createdSnHistory(InventoryDetail inventoryDetail,String shipmentCode,String createdBy,String referCode,String referNum){
        SnPartDetailHistory snPartDetailHistory=new SnPartDetailHistory();
        snPartDetailHistory.setSnCode(inventoryDetail.getSn());
        snPartDetailHistory.setContainerCode(inventoryDetail.getContainerCode());
        snPartDetailHistory.setReferCode(referCode);
        snPartDetailHistory.setReferLineNum(referNum);
        snPartDetailHistory.setOperation(QuantityConstant.SN_TYPE_SHIPMENT);
        snPartDetailHistory.setBillCode(shipmentCode);
        snPartDetailHistory.setMaterialCode(inventoryDetail.getMaterialCode());
        snPartDetailHistory.setCreatedBy(createdBy);
        snPartDetailHistory.setCreated(new Date());
        snPartDetailHistory.setWarehouseCode(inventoryDetail.getWarehouseCode());
        snPartDetailHistory.setOperationUserName(createdBy);
        snPartDetailHistory.setOperationUser(createdBy);
        snPartDetailHistory.setOperationTime(DateUtils.getNowPreDays("yyyy-MM-dd HH:mm:ss",0));
        if(com.huaheng.common.utils.StringUtils.isNotEmpty(createdBy)){
            User user=userService.selectLoginname(createdBy);
            if(user!=null){
                snPartDetailHistory.setOperationUser(user.getLoginName());
            }
        }
        snPartDetailHistoryService.save(snPartDetailHistory);
    }
}