ReceiptHeaderService.java 26.9 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 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
package com.huaheng.pc.receipt.receiptHeader.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.check.checkDetail.domain.CheckDetail;
import com.huaheng.pc.check.checkDetail.service.CheckDetailService;
import com.huaheng.pc.check.checkHeader.domain.CheckHeader;
import com.huaheng.pc.check.checkHeader.service.CheckHeaderService;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.receiptType.domain.ReceiptType;
import com.huaheng.pc.config.receiptType.service.ReceiptTypeService;
import com.huaheng.pc.config.sendMail.service.SendMailService;
import com.huaheng.pc.config.statusFlow.domain.StatusFlowDetail;
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.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.mapper.ReceiptHeaderMapper;
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 org.aspectj.weaver.loadtime.Aj;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ReceiptHeaderService extends ServiceImpl<ReceiptHeaderMapper, ReceiptHeader> {

    @Resource
    private ReceiptTypeService receiptTypeService;
    @Resource
    private ReceiptDetailService receiptDetailService;
    @Resource
    private CheckHeaderService checkHeaderService;
    @Resource
    private CheckDetailService checkDetailService;
    @Resource
    private ShipmentHeaderService shipmentHeaderService;
    @Resource
    private ReceiptHeaderMapper receiptHeaderMapper;
    @Resource
    private InventoryHeaderService inventoryHeaderService;
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private ShipmentDetailService shipmentDetailService;
    @Resource
    private InventoryTransactionService inventoryTransactionService;

    /**
     * 保存入库单
     *
     * @param receiptHeader
     * @return
     */
    public AjaxResult saveReceiptHeader(ReceiptHeader receiptHeader) {
        //根据仓库和货主以及传入单据类型编码判断单据类型是否存在
        LambdaQueryWrapper<ReceiptType> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ReceiptType::getCode, receiptHeader.getReceiptType())
                .eq(ReceiptType::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(ReceiptType::getCompanyCode, receiptHeader.getCompanyCode());
        ReceiptType receiptType = receiptTypeService.getOne(lambdaQueryWrapper);
        if (receiptType == null) {
            throw new ServiceException(ShiroUtils.getWarehouseCode(), receiptHeader.getCompanyCode(), "没有对应的入库单类型");
        }

        //根据单据类型生成单号
        String code = createCode(receiptHeader.getReceiptType());
        if (StringUtils.isEmpty(code)) {
            throw new ServiceException("根据单据类型" + receiptHeader.getReceiptType() + "生成单号失败");
        }
        receiptHeader.setCode(code);
        receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_BUILD);
        receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_BUILD);
        receiptHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
        return AjaxResult.toAjax(this.save(receiptHeader));
    }

    /**
     * 根据单据类型生成单号  规则:入库单类型 + 年月日 + 5位(排序号 + 1)
     *
     * @param receiptType
     * @return
     */
    //todo:huhai 单据生成规则,后续版本计划追加一个序列号生成规则表:统一设定前缀,填充位,流水码等
    public String createCode(String receiptType) {
        String code = null;
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        LambdaQueryWrapper<ReceiptHeader> lambda = Wrappers.lambdaQuery();
        lambda.select(ReceiptHeader::getCode).eq(ReceiptHeader::getReceiptType, receiptType)
                .orderByDesc(ReceiptHeader::getId).last("Limit 1");
        //如果指定类型的最后的code存在,并且日期一致。那么 code = 入库单类型 + 年月日 + (排序号 + 1)
        String maxCode = null;
        ReceiptHeader receiptHeader = this.getOne(lambda);
        if (receiptHeader != null) {
            maxCode = this.getOne(lambda).getCode();
        }
        //todo:隐藏了BUG,请修正。 修改好  去掉todo
        if (maxCode != null && maxCode.substring(maxCode.length() - 13, maxCode.length() - 5).equals(df.format(now))) {
            Integer Count = Integer.valueOf(maxCode.substring(maxCode.length() - 5, maxCode.length()));
            code = receiptType + df.format(now) + String.format("%05d", Count + 1);
        } else {
            code = receiptType + df.format(now) + "00001";
        }
        return code;
    }

    /**
     * 入库预约
     *
     * @param receiptHeader
     * @return
     */
    public AjaxResult reservation(ReceiptHeader receiptHeader) {
        LambdaQueryWrapper<ReceiptDetail> receiptDetailLambda = Wrappers.lambdaQuery();
        receiptDetailLambda.eq(ReceiptDetail::getReceiptId, receiptHeader.getId());
        List<ReceiptDetail> receiptDetails = receiptDetailService.list(receiptDetailLambda);
        //更新入库明细流程
        for (ReceiptDetail receiptDetail : receiptDetails) {
            receiptDetail.setProcessStamp(QuantityConstant.RECEIPT_HEADER_RESERVATION.toString());
            if (!receiptDetailService.updateById(receiptDetail)) {
                throw new ServiceException("更新入库明细处理标记失败");
            }
            receiptDetail = receiptDetailService.queryflow(receiptDetail);
            if (!receiptDetailService.updateById(receiptDetail)) {
                throw new ServiceException("更新入库明细流程失败");
            }
        }
        receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        //更新入库单预约时间
        if (!this.updateById(receiptHeader)) {
            throw new ServiceException("更新入库单预约时间失败");
        }
        receiptDetailService.updateReceiptHeaderLastStatus(receiptHeader.getId());
        return AjaxResult.success("预约成功");
    }

    /**
     * 入库到货
     *
     * @param id
     * @return
     */
    public AjaxResult arrival(Integer id) {
        LambdaQueryWrapper<ReceiptDetail> receiptDetailLambda = Wrappers.lambdaQuery();
        receiptDetailLambda.eq(ReceiptDetail::getReceiptId, id)
                .eq(ReceiptDetail::getProcessStamp, QuantityConstant.RECEIPT_HEADER_ARRIVAL.toString());
        List<ReceiptDetail> receiptDetails = receiptDetailService.list(receiptDetailLambda);
        //更新入库明细流程
        for (ReceiptDetail receiptDetail : receiptDetails) {
            receiptDetailService.queryflow(receiptDetail);
        }
        //更新入库单头表
        receiptDetailService.updateReceiptHeaderLastStatus(id);
        return AjaxResult.success("已通知到货");
    }

    /**
     * 入库质检
     */
    public AjaxResult check(Integer id) {

        ReceiptHeader receiptHeader = this.getById(id);
        LambdaQueryWrapper<ReceiptDetail> receiptDetailLambda = Wrappers.lambdaQuery();
        receiptDetailLambda.eq(ReceiptDetail::getReceiptId, id);
        List<ReceiptDetail> receiptDetails = receiptDetailService.list(receiptDetailLambda);

        //判断是否已经生成了质检单
        LambdaQueryWrapper<CheckHeader> checkHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        checkHeaderLambdaQueryWrapper.eq(CheckHeader::getCode, receiptHeader.getCode());
        CheckHeader checkHeaderQuery = checkHeaderService.getOne(checkHeaderLambdaQueryWrapper);
        if (checkHeaderQuery != null) {
            throw new ServiceException("质检单已生成");
        }
        //创建质检头表
        CheckHeader checkHeader = new CheckHeader();
        checkHeader.setCode(receiptHeader.getCode());
        checkHeader.setType(QuantityConstant.CHECK_TYPE_RECEIPT.toString());
        checkHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
        checkHeader.setReferCode(receiptHeader.getReferCode());
        checkHeader.setEnable(1);
        checkHeader.setStatus(QuantityConstant.CHECK_STATUS_BUILD.toString());
        checkHeader.setCreatedBy(ShiroUtils.getLoginName());
        checkHeader.setLastUpdatedBy(ShiroUtils.getLoginName());

        if (!checkHeaderService.save(checkHeader)) {
            throw new ServiceException("添加质检头表错误");
        }

        //查询保存后的质检头表
        LambdaQueryWrapper<CheckHeader> checkHeaderLambda = Wrappers.lambdaQuery(checkHeader);
        checkHeader = checkHeaderService.getOne(checkHeaderLambda);

        for (ReceiptDetail receiptDetail : receiptDetails) {
            CheckDetail checkDetail = new CheckDetail();
            checkDetail.setCheckHeaderId(checkHeader.getId());
            checkDetail.setWarehouseCode(ShiroUtils.getWarehouseCode());
            checkDetail.setCheckCode(checkHeader.getCode());
            checkDetail.setReceiptDetailId(receiptDetail.getId());
            checkDetail.setReceiptCode(receiptDetail.getReceiptCode());
            checkDetail.setReferCode(checkHeader.getReferCode());
            checkDetail.setMaterialCode(receiptDetail.getMaterialCode());
            checkDetail.setMaterialName(receiptDetail.getMaterialName());
            checkDetail.setMaterialSpec(receiptDetail.getMaterialSpec());
            checkDetail.setMaterialUnit(receiptDetail.getMaterialUnit());
            checkDetail.setCompanyCode(receiptDetail.getCompanyCode());
            checkDetail.setInventorySts(receiptDetail.getInventorySts());
            checkDetail.setStatus(QuantityConstant.CHECK_STATUS_BUILD.toString());
            checkDetail.setQty(receiptDetail.getTotalQty());
            checkDetail.setCheckBy(ShiroUtils.getLoginName());
            checkDetail.setCreatedBy(ShiroUtils.getLoginName());
            checkDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
            if (!checkDetailService.save(checkDetail)) {
                throw new ServiceException("保存质检明细失败");
            }
        }
        return AjaxResult.success("创建质检单成功");
    }

    /**
     * 提交审核入库单
     */
    @Transactional
    public AjaxResult submitReview(String ids) {
        String warehouseCode = ShiroUtils.getWarehouseCode();
        if (StringUtils.isEmpty(ids)) {
            return AjaxResult.error("仓库:" + warehouseCode + ",提交入库单审核,id不能为空");
        }
        Integer[] idArray = Convert.toIntArray(ids);
        for (int i = 0; i < idArray.length; i++) {
            ReceiptHeader receiptHeader = this.getById(idArray[i]);
            if (receiptHeader.getFirstStatus() > QuantityConstant.RECEIPT_HEADER_VERIFYING
                    || receiptHeader.getLastStatus() > QuantityConstant.RECEIPT_HEADER_VERIFYING) {
                return AjaxResult.error("仓库:" + warehouseCode + ",单据号:" + receiptHeader.getCode() + "入库单不需要审核");
            }
            LambdaQueryWrapper<ReceiptDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
            lambdaQueryWrapper.eq(ReceiptDetail::getReceiptId, idArray[i]);
            List<ReceiptDetail> receiptDetailList = receiptDetailService.list(lambdaQueryWrapper);
            if (receiptDetailList.isEmpty()) {
                return AjaxResult.error("仓库:" + warehouseCode + ",单据号:" + receiptHeader.getCode() + "入库单没有明细");
            }
            receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_VERIFYING);
            receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_VERIFYING);
            if (!this.updateById(receiptHeader)) {
                throw new ServiceException("仓库:" + warehouseCode + ",单据号:" + receiptHeader.getCode() + " 失败");
            }
        }
        return AjaxResult.success("仓库:" + warehouseCode + ",提交审核成功");
    }

    /**
     * 到货通知
     *
     * @param id
     * @return
     */
    public AjaxResult arrivalNotice(String id) {
        LambdaQueryWrapper<ReceiptDetail> lambda = Wrappers.lambdaQuery();
        lambda.eq(ReceiptDetail::getReceiptId, id);
        List<ReceiptDetail> receiptDetails = receiptDetailService.list(lambda);
        for (ReceiptDetail receiptDetail : receiptDetails) {
            receiptDetail.setProcessStamp(QuantityConstant.RECEIPT_HEADER_ARRIVAL.toString());
            receiptDetailService.updateById(receiptDetail);
            if (!receiptDetailService.updateById(receiptDetailService.queryflow(receiptDetail))) {
                throw new ServiceException("更新入库明细处理标记出错");
            }
            receiptDetailService.updateReceiptHeaderLastStatus(receiptDetail.getReceiptId());
        }
        return AjaxResult.success("已通知到货");
    }

    /**
     * 加入订单池
     *
     * @param ids 头表id字符串
     * @return
     */
    @Transactional
    public AjaxResult addPool(String ids) {
        List<Integer> idList = Arrays.asList(Convert.toIntArray(ids));
        List<StatusFlowDetail> statusFlowDetailList = receiptDetailService.queryflow();
        List<StatusFlowDetail> verifyList = statusFlowDetailList.stream().filter(item -> {
            return "审核".equals(item.getRecordType());
        }).collect(Collectors.toList());
        Integer nessaryFlag = 0;
        for (Integer id : idList) {
            LambdaQueryWrapper<ReceiptDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
            lambdaQueryWrapper.eq(ReceiptDetail::getReceiptId, id);
            List<ReceiptDetail> list = receiptDetailService.list(lambdaQueryWrapper);
            if (list.size() != 0) {
                if (nessaryFlag.equals(verifyList.get(0).getNessary())) {
                    for (ReceiptDetail receiptDetail : list) {
                        if (Integer.parseInt(receiptDetail.getProcessStamp()) < QuantityConstant.RECEIPT_HEADER_POOL) {
                            //加入订单池
                            receiptDetail.setProcessStamp(QuantityConstant.RECEIPT_HEADER_POOL.toString());
                            ReceiptDetail receiptDetail1 = receiptDetailService.queryflow(receiptDetail);
                            if (!receiptDetailService.updateById(receiptDetail1)) {
                                throw new ServiceException("更新入库明细状态失败");
                            }
                        } else {
                            throw new ServiceException("已有入库明细进入订单池");
                        }
                    }
                } else {
                    for (ReceiptDetail receiptDetail : list) {
                        if (Integer.parseInt(receiptDetail.getProcessStamp()) < QuantityConstant.RECEIPT_HEADER_POOL) {
                            //判断入库明细是否需要审核
                            ReceiptDetail beforeReceiptDetail = receiptDetailService.queryflow(receiptDetail);
                            if (Integer.parseInt(beforeReceiptDetail.getProcessStamp()) == QuantityConstant.RECEIPT_HEADER_VERIFYING
//                                    || Integer.parseInt(beforeReceiptDetail.getProcessStamp()) == QuantityConstant.RECEIPT_HEADER_APPROVE
                            ) {
                                throw new ServiceException("请先通过审核");
                            }
                            //加入订单池
                            receiptDetail.setProcessStamp(QuantityConstant.RECEIPT_HEADER_POOL.toString());
                            ReceiptDetail receiptDetail1 = receiptDetailService.queryflow(receiptDetail);
                            if (!receiptDetailService.updateById(receiptDetail1)) {
                                throw new ServiceException("更新入库明细状态失败");
                            }
                        } else {
                            throw new ServiceException("已有入库明细进入订单池");
                        }
                    }
                }

            }
            //更新头表状态
            receiptDetailService.updateReceiptHeaderLastStatus(id);
        }
        return AjaxResult.success("加入成功");
    }


    public List<ReceiptHeader> selectListByCreated() {
        return receiptHeaderMapper.selectListByCreated();
    }


    @Transactional(rollbackFor = Exception.class)
    public Integer createTodayHeader(String companyCode) {
        String receiptType = "PPI";
        String code = null;
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        String maxCode = receiptHeaderMapper.createCode(receiptType);
        //如果指定类型的最后的code存在,并且日期一致。那么 code = 入库单类型 + 年月日 + (排序号 + 1)
        if (maxCode != null && maxCode.substring(maxCode.length() - 13, maxCode.length() - 5).equals(df.format(now))) {
            Integer Count = Integer.valueOf(maxCode.substring(maxCode.length() - 5, maxCode.length()));
            code = receiptType + df.format(now) + String.format("%05d", Count + 1);
        } else {
            code = receiptType + df.format(now) + "00001";
        }
        ReceiptHeader receiptHeader = new ReceiptHeader();
        receiptHeader.setId(null);
        receiptHeader.setCode(code);
        receiptHeader.setReceiptType(receiptType);
        receiptHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
        receiptHeader.setCreated(null);
        receiptHeader.setCreatedBy(ShiroUtils.getLoginName());
        receiptHeader.setLastUpdated(null);
        receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
        receiptHeader.setFirstStatus(200);
        receiptHeader.setLastStatus(200);
        receiptHeader.setCompanyCode(companyCode);
        this.save(receiptHeader);
        return receiptHeader.getId();
    }

    @Transactional(rollbackFor = Exception.class)
    public List<ReceiptHeader> getLatestReceipt(String warehouseCode, String companyCode) {
        return receiptHeaderMapper.getLatestReceipt(warehouseCode, companyCode);
    }

    /**
     * 修改回传后状态
     *
     * @param id
     * @return
     */
    private AjaxResult editReceiveStatus(Integer id) {
        ReceiptHeader receiptHeader = new ReceiptHeader();
        receiptHeader.setId(id);
        receiptHeader.setFirstStatus(900);
        receiptHeader.setLastStatus(900);
        if (!updateById(receiptHeader)) {
            throw new ServiceException("更新头表状态失败");
        } else {
            LambdaQueryWrapper<ReceiptDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
            lambdaQueryWrapper.eq(ReceiptDetail::getReceiptId, id);
            List<ReceiptDetail> receiptDetails = receiptDetailService.list(lambdaQueryWrapper);
            for (ReceiptDetail receiptDetail : receiptDetails) {
                receiptDetail.setProcessStamp("900");
            }
            if (!receiptDetailService.updateBatchById(receiptDetails)) {
                throw new ServiceException("更新明细失败");
            }
        }
        return AjaxResult.success("");
    }

    public AjaxResult crossLocation(String ids) {
        String containerCode = "YKR01";
        String locationCode = "YRL01";
        for (Integer id : Convert.toIntArray(ids)) {
            ReceiptHeader receiptHeader = this.getById(id);
            /* 创建出库单*/
            ShipmentHeader shipmentHeader = new ShipmentHeader();
            shipmentHeader.setWarehouseCode(receiptHeader.getWarehouseCode());
            shipmentHeader.setCompanyCode(receiptHeader.getCompanyCode());
            shipmentHeader.setCode(receiptHeader.getCode());
            shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
            shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_CONTAINER_BUILD);
            shipmentHeader.setShipmentType("YK");
            shipmentHeader.setTotalQty(receiptHeader.getTotalQty());
            shipmentHeader.setTotalLines(receiptHeader.getTotalLines());
            if (!shipmentHeaderService.save(shipmentHeader)) {
                throw new ServiceException("创建出库单失败");
            }

            List<ReceiptDetail> receiptDetailList = receiptDetailService.findByReceiptId(id);
            /* 遍历入库单明细生成出库单与库存交易记录*/
            for (ReceiptDetail receiptDetail : receiptDetailList) {

                /* 创建出库明细*/
                ShipmentDetail shipmentDetail = new ShipmentDetail();
                shipmentDetail.setShipmentId(shipmentHeader.getId());
                shipmentDetail.setWarehouseCode(shipmentHeader.getWarehouseCode());
                shipmentDetail.setCompanyCode(shipmentHeader.getCompanyCode());
                shipmentDetail.setShipmentCode(shipmentHeader.getCode());
                shipmentDetail.setMaterialCode(receiptDetail.getMaterialCode());
                shipmentDetail.setMaterialName(receiptDetail.getMaterialName());
                shipmentDetail.setMaterialSpec(receiptDetail.getMaterialSpec());
                shipmentDetail.setMaterialUnit(receiptDetail.getMaterialUnit());
                shipmentDetail.setShipQty(receiptDetail.getTotalQty());
                shipmentDetail.setRequestQty(BigDecimal.ZERO);
                shipmentDetail.setBatch(receiptDetail.getBatch());
                shipmentDetail.setLot(receiptDetail.getLot());
                shipmentDetail.setProjectNo(receiptDetail.getProjectNo());
                shipmentDetail.setManufactureDate(receiptDetail.getManufactureDate());
                shipmentDetail.setExpirationDate(receiptDetail.getExpirationDate());
                shipmentDetail.setAgingDate(receiptDetail.getAgingDate());
                shipmentDetail.setInventorySts(receiptDetail.getInventorySts());
                shipmentDetail.setStatus(QuantityConstant.TASK_STATUS_BUILD);
                if (!shipmentDetailService.save(shipmentDetail)) {
                    throw new ServiceException("创建出库单明细失败");
                }

                InventoryTransaction inventoryTransaction = new InventoryTransaction();
                inventoryTransaction.setWarehouseCode(receiptHeader.getWarehouseCode());
                inventoryTransaction.setCompanyCode(receiptHeader.getCompanyCode());
                inventoryTransaction.setLocationCode(locationCode);
                inventoryTransaction.setContainerCode(containerCode);
                inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_RECEIPT);
                inventoryTransaction.setMaterialCode(receiptDetail.getMaterialCode());
                inventoryTransaction.setMaterialName(receiptDetail.getMaterialName());
                inventoryTransaction.setMaterialSpec(receiptDetail.getMaterialSpec());
                inventoryTransaction.setMaterialUnit(receiptDetail.getMaterialUnit());
                inventoryTransaction.setTaskQty(receiptDetail.getTotalQty());
                inventoryTransaction.setInventorySts(receiptDetail.getInventorySts());
                inventoryTransaction.setReferCode(receiptDetail.getReferCode());
                inventoryTransaction.setReferDetailId(receiptDetail.getReferLineNum());
                inventoryTransaction.setBatch(receiptDetail.getBatch());
                inventoryTransaction.setLot(receiptDetail.getLot());
                inventoryTransaction.setProjectNo(receiptDetail.getProjectNo());
                inventoryTransaction.setQcCheck(receiptDetail.getQcCheck());
                inventoryTransaction.setManufactureDate(receiptDetail.getManufactureDate());
                inventoryTransaction.setExpirationDate(receiptDetail.getExpirationDate());
                inventoryTransaction.setAgingDate(receiptDetail.getAgingDate());
                inventoryTransaction.setAttribute1(receiptDetail.getAttribute1());
                inventoryTransaction.setAttribute2(receiptDetail.getAttribute2());
                inventoryTransaction.setAttribute3(receiptDetail.getAttribute3());
                inventoryTransaction.setBillCode(receiptHeader.getCode());
                inventoryTransaction.setBillDetailId(receiptDetail.getId());
                inventoryTransaction.setSupplierCode(receiptDetail.getSupplierCode());
                if (!inventoryTransactionService.save(inventoryTransaction)) {
                    throw new ServiceException("保存库存交易记录失败");
                }
                inventoryTransaction.setTransactionType(QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT);
                inventoryTransaction.setBillCode(shipmentHeader.getCode());
                inventoryTransaction.setBillDetailId(shipmentDetail.getId());
                if (!inventoryTransactionService.save(inventoryTransaction)) {
                    throw new ServiceException("保存库存交易记录失败");
                }
            }

            receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_POSTING);
            receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_POSTING);
            if (!this.updateById(receiptHeader)) {
                throw new ServiceException("更新入库单状态失败");
            }
            shipmentHeader.setFirstStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
            shipmentHeader.setLastStatus(QuantityConstant.SHIPMENT_HEADER_COMPLETED);
            if (!shipmentHeaderService.updateById(shipmentHeader)) {
                throw new ServiceException("更新入库单状态失败");
            }

        }

        return AjaxResult.success();
    }
}