MobileBatchReceiptController.java 46.6 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 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 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 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
package com.huaheng.mobile.receipt;

import com.alibaba.fastjson.JSONException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.api.general.domain.ReceiptDomain;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.domain.AjaxResult;
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.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.config.materialType.domain.MaterialType;
import com.huaheng.pc.config.materialType.service.MaterialTypeService;
import com.huaheng.pc.config.receiptType.domain.ReceiptType;
import com.huaheng.pc.config.receiptType.service.ReceiptTypeService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerView;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
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.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.system.dict.domain.DictData;
import com.huaheng.pc.system.dict.service.IDictDataService;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Enzo Cotter
 * @date 2019/12/15
 */
@CrossOrigin
@RestController
@RequestMapping("/mobile/receipt/batch")
@Api(tags = {"移动端收货"}, value = "移动端收货MobileBatchReceiptController")
public class MobileBatchReceiptController {

    @Resource
    private ShipmentContainerHeaderService shipmentContainerHeaderService;
    @Resource
    private ReceiptContainerHeaderService receiptContainerHeaderService;
    @Resource
    private ReceiptHeaderService receiptHeaderService;
    @Resource
    private ReceiptDetailService receiptDetailService;
    @Resource
    private ReceiptContainerDetailService receiptContainerDetailService;
    @Resource
    private ContainerService containerService;
    @Resource
    private MaterialService materialService;
    @Resource
    private MaterialTypeService materialTypeService;
    @Resource
    private LocationService locationService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private CompanyService companyService;
    @Resource
    private IDictDataService dictDataService;
    @Resource
    private ReceiptTypeService receiptTypeService;
    @Resource
    private ReceiptHeaderMapper receiptHeaderMapper;

    @Resource
    private InventoryHeaderService inventoryHeaderService;


    @PostMapping("/scanContainer")
    @ApiOperation("移动端入库扫描容器")
    @Log(title = "移动端入库扫描容器", action = BusinessType.OTHER)
    public AjaxResult scanContainer(@RequestBody @ApiParam(value = "容器号") Map<String, String> param) throws Exception {
        if (param.get("code") == null || param.get("code").trim().length() < 1) {
            throw new JSONException("容器号(code)不能为空");
        }

        ReceiptContainerView receiptContainerView = new ReceiptContainerView();
        receiptContainerView.setReceiptContainerCode(param.get("code"));
        receiptContainerView.setTaskType((short) 100);
        AjaxResult result = receiptContainerHeaderService.checkContainer(receiptContainerView);
        LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
        containerLambdaQueryWrapper.eq(Container::getCode, param.get("code"));
        Container container = containerService.getOne(containerLambdaQueryWrapper);
        if (container == null) {
            return AjaxResult.error("托盘编码错误");
        }
        if (!QuantityConstant.STATUS_CONTAINER_EMPTY.equals(container.getStatus())) {
            return AjaxResult.error("托盘状态不为空");
        }
        if (!"".equals(container.getLocationCode())) {
            return AjaxResult.error("");
        }
        return result;
    }

    @PostMapping("/save")
    @ApiOperation("移动端收货保存")
    @Log(title = "移动端收货保存", action = BusinessType.OTHER)
    public AjaxResult save(@RequestBody @ApiParam(value = "收货单") List<ReceiptContainerView> record) throws Exception {
        AjaxResult result = receiptContainerHeaderService.batchSave(record);
        return result;
    }

    @PostMapping("/getMaterial")
    @ApiOperation("移动端获取物料信息")
    @Log(title = "移动端获取物料信息", action = BusinessType.OTHER)
    public AjaxResult getMaterial(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        if (param.get("code") == null || param.get("code").trim().length() < 1) {
            throw new JSONException("容器号(code)不能为空");
        }
        Material material = materialService.getMaterialByCode(param.get("code"));
        if (material == null) {
            return AjaxResult.error("没有该物料");
        }
        MaterialInfo materialInfo = new MaterialInfo();
        materialInfo.setMaterialCode(material.getCode());
        materialInfo.setMaterialName(material.getName());
        materialInfo.setType(material.getSpec());

        return AjaxResult.success(materialInfo);
    }

    @PostMapping("/getLatestMaterial")
    @ApiOperation("移动端获取物料信息")
    @Log(title = "移动端获取物料信息", action = BusinessType.OTHER)
    public AjaxResult getLatestMaterial(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        List<Material> materials = materialService.findLatest();
        if (materials == null) {
            return AjaxResult.error("没有找到物料");
        }

        return AjaxResult.success(materials);
    }

    @PostMapping("/getLatestReceipt")
    @ApiOperation("移动端获取入库单")
    @Log(title = "移动端获取入库单", action = BusinessType.OTHER)
    public AjaxResult getLatestReceipt(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        List<ReceiptHeader> receiptHeaders = receiptHeaderService.getLatestReceipt(ShiroUtils.getWarehouseCode(), param.get("companyCode"));
        if (receiptHeaders == null) {
            return AjaxResult.error("没有找到入库单");
        }
        return AjaxResult.success(receiptHeaders);
    }


    @PostMapping("/checkLocation")
    @ApiOperation("移动端验证库位")
    @Log(title = "移动端验证库位", action = BusinessType.OTHER)
    public AjaxResult checkLocation(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        if (param.get("code") == null || param.get("code").trim().length() < 1) {
            throw new JSONException("容器号(code)不能为空");
        }

        boolean result = locationService.checkLocation(param.get("code"));
        if (!result) {
            return AjaxResult.error("没有该库位");
        }
        return AjaxResult.success(result);
    }

    @PostMapping("/getFreeLocation")
    @ApiOperation("移动端获得空闲库位")
    @Log(title = "移动端获得空闲库位", action = BusinessType.OTHER)
    public AjaxResult getFreeLocation(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        if (param.get("materialCode") == null || param.get("materialCode").trim().length() < 1) {
            throw new JSONException("materialCode不能为空");
        }

        if (param.get("batch") == null || param.get("batch").trim().length() < 1) {
            throw new JSONException("batch不能为空");
        }
        String materialCode = param.get("materialCode");
        String batch = param.get("batch");
        boolean result = locationService.getFreeLocation(materialCode, batch);
        if (!result) {
            return AjaxResult.error("没有空闲的分区库位");
        }
        return AjaxResult.success(result);
    }

    @PostMapping("/getContainerCode")
    @ApiOperation("移动端验证库位")
    @Log(title = "移动端验证库位", action = BusinessType.OTHER)
    public AjaxResult getContainerCode(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        if (param.get("code") == null || param.get("code").trim().length() < 1) {
            throw new JSONException("容器号(code)不能为空");
        }
        LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Location::getCode, param.get("code"))
                .eq(Location::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(Location::getDeleted, false);
        Location location = locationService.getOne(queryWrapper);
        if (location == null) {
            return AjaxResult.error("没有该库位");
        }
        return AjaxResult.success("成功", location.getContainerCode());
    }

    @PostMapping("/quickReceipt")
    @ApiOperation("移动端收货保存")
    @Log(title = "移动端收货保存", action = BusinessType.OTHER)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult quickReceipt(@RequestBody @ApiParam(value = "收货单") List<ReceiptBill> receiptBills) throws Exception {
        if (receiptBills == null || receiptBills.size() <= 0) {
            throw new JSONException("没有收货信息");
        }
        String containerCode = receiptBills.get(0).receiptContainerCode;
        String locationCode = receiptBills.get(0).locationCode;
        String companyCode = receiptBills.get(0).getCompanyCode();
        String receiptDetailId = receiptBills.get(0).getReceiptDetailId();

        LambdaQueryWrapper<Container> containerQueryWrapper = Wrappers.lambdaQuery();
        containerQueryWrapper.eq(Container::getCode, containerCode);
        Container container = containerService.getOne(containerQueryWrapper);
        if (container == null) {
            throw new JSONException("不存在这个托盘");
        }

        //pda入库增加托盘任务校验
        List<TaskHeader> unfinishTask = taskHeaderService.getUnCompleteTaskList().stream().filter((t) -> {
            return t.getContainerCode().equals(container.getCode());
        }).collect(Collectors.toList());

        if (unfinishTask.size() > 0) {
            TaskHeader t = unfinishTask.get(0);
            String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(t.getCreated());
            throw new ServiceException(container.getCode() + "托盘已经有未完成的任务,请不要重复下发\n该托盘任务创建于:" + time);
        }


        if (locationCode != null && locationCode.equals(container.getLocationCode())) {
            /* 查询未完成的入库任务*/
            LambdaQueryWrapper<TaskHeader> taskQueryWrapper = Wrappers.lambdaQuery();
            taskQueryWrapper.eq(TaskHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                    .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLERECEIPT,
                            QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT)
                    .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
                    .eq(TaskHeader::getContainerCode, containerCode);
            TaskHeader taskHeader = taskHeaderService.getOne(taskQueryWrapper);
            if (taskHeader == null) {
                throw new JSONException("没有找到托盘对应的任务");
            }
            LambdaQueryWrapper<ReceiptDetail> receiptDetailQueryWrapper = Wrappers.lambdaQuery();
            receiptDetailQueryWrapper.eq(ReceiptDetail::getId, receiptDetailId);
            ReceiptDetail receiptDetail = receiptDetailService.getOne(receiptDetailQueryWrapper);
            if (receiptDetail == null) {
                throw new JSONException("没有找到入库单详情");
            }

            LambdaQueryWrapper<ReceiptHeader> receiptHeaderQueryWrapper = Wrappers.lambdaQuery();
            receiptHeaderQueryWrapper.eq(ReceiptHeader::getId, receiptDetail.getReceiptId());
            ReceiptHeader receiptHeader = receiptHeaderService.getOne(receiptHeaderQueryWrapper);
            if (receiptHeader == null) {
                throw new JSONException("没有找到入库单");
            }

            LambdaQueryWrapper<ReceiptContainerHeader> lambda = Wrappers.lambdaQuery();
            lambda.eq(ReceiptContainerHeader::getContainerCode, containerCode)
                    .lt(ReceiptContainerHeader::getStatus, QuantityConstant.RECEIPT_CONTAINER_FINISHED);
            List<ReceiptContainerHeader> list = receiptContainerHeaderService.list(lambda);
            if (list.size() >= 1) {
                throw new ServiceException("容器已经生成任务,不能放物料了!");
            }
            ReceiptContainerHeader receiptContainerHeader = new ReceiptContainerHeader();
            //如果不存在记录则新建记录
            receiptContainerHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
            receiptContainerHeader.setCompanyCode(companyCode);
            receiptContainerHeader.setContainerCode(containerCode);
            Container container2 = containerService.getContainerByCode(containerCode);
            receiptContainerHeader.setContainerType(container2.getContainerType());
            receiptContainerHeader.setTaskType(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT);
            receiptContainerHeader.setFromLocation(container2.getLocationCode());
            receiptContainerHeader.setToLocation(locationCode);
            receiptContainerHeader.setCreatedBy(ShiroUtils.getName());
            receiptContainerHeader.setLastUpdatedBy(ShiroUtils.getName());
            receiptContainerHeader.setStatus(10);

            if (!receiptContainerHeaderService.save(receiptContainerHeader)) {
                throw new ServiceException("入库组盘头表保存失败");
            }

            receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RECEIVING);
            receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_RECEIVING);
            receiptHeaderService.update(receiptHeader, receiptHeaderQueryWrapper);

            taskHeader.setAllocationHeadId(receiptContainerHeader.getId());
            taskHeaderService.updateById(taskHeader);
            for (ReceiptBill receiptBill : receiptBills) {

                LambdaQueryWrapper<ReceiptDetail> receiptDetail2QueryWrapper = Wrappers.lambdaQuery();
                receiptDetail2QueryWrapper.eq(ReceiptDetail::getId, receiptBill.getReceiptDetailId());
                ReceiptDetail receiptDetail2 = receiptDetailService.getOne(receiptDetail2QueryWrapper);
                if (receiptDetail2 == null) {
                    throw new JSONException("没有找到入库单详情");
                }

                BigDecimal openQty = receiptDetail2.getTaskQty();
                BigDecimal totalQty = receiptDetail2.getQty();
                BigDecimal qty = openQty.add(receiptBill.getQty());
                if (totalQty.subtract(qty).compareTo(BigDecimal.ZERO) < 0) {
                    throw new Exception("配盘数量大于表单数量");
                }

                receiptDetail2.setTaskQty(qty);
                receiptDetailService.update(receiptDetail2, receiptDetail2QueryWrapper);

                ReceiptContainerDetail receiptContainerDetail = new ReceiptContainerDetail();
                receiptContainerDetail.setReceiptContainerId(receiptContainerHeader.getId());
                receiptContainerDetail.setWarehouseCode(ShiroUtils.getWarehouseCode());
                receiptContainerDetail.setReceiptId(receiptHeader.getId());
                receiptContainerDetail.setReceiptDetailId(receiptDetail2.getId());
                receiptContainerDetail.setReceiptCode(receiptHeader.getCode());
                receiptContainerDetail.setReceiptType(receiptHeader.getReceiptType());
                receiptContainerDetail.setLocationCode(locationCode);
                receiptContainerDetail.setContainerCode(containerCode);
                receiptContainerDetail.setContainerType(container.getContainerType());
                receiptContainerDetail.setCompanyCode(companyCode);

                LambdaQueryWrapper<Material> materialQueryWrapper = Wrappers.lambdaQuery();
                materialQueryWrapper.eq(Material::getCode, receiptBill.getMaterialCode())
                        .eq(Material::getDeleted, 0);
                Material material = materialService.getOne(materialQueryWrapper);

                receiptContainerDetail.setMaterialCode(material.getCode());
                receiptContainerDetail.setMaterialName(material.getName());
                receiptContainerDetail.setMaterialSpec(material.getSpec());
                receiptContainerDetail.setMaterialUnit(material.getUnit());
                receiptContainerDetail.setQty(receiptBill.getQty());
                receiptContainerDetail.setStatus(10);
                receiptContainerDetail.setCreatedBy(ShiroUtils.getName());
                receiptContainerDetail.setLastUpdatedBy(ShiroUtils.getName());
                receiptContainerDetailService.save(receiptContainerDetail);

                TaskDetail taskDetail = new TaskDetail();
                taskDetail.setTaskId(taskHeader.getId());
                taskDetail.setContainerCode(containerCode);
                taskDetail.setTaskType(taskHeader.getTaskType());
                taskDetail.setInternalTaskType(taskHeader.getInternalTaskType());
                taskDetail.setWarehouseCode(ShiroUtils.getWarehouseCode());
                taskDetail.setCompanyCode(companyCode);
                taskDetail.setBillCode(receiptHeader.getCode());
                taskDetail.setBillDetailId(Integer.parseInt(receiptBill.getReceiptDetailId()));
                taskDetail.setMaterialCode(receiptBill.getMaterialCode());
                taskDetail.setMaterialName(receiptBill.getMaterialName());
                taskDetail.setQty(receiptBill.getQty());
                taskDetail.setFromLocation(taskHeader.getFromLocation());
                taskDetail.setToLocation(taskHeader.getToLocation());
                taskDetail.setAllocationId(receiptContainerDetail.getId());
                taskDetail.setStatus(taskHeader.getStatus());
                taskDetail.setBatch(receiptBill.getBatch());
                taskDetail.setCompanyCode(taskHeader.getCompanyCode());
                taskDetailService.save(taskDetail);
            }

        } else {
            ReceiptContainerView record = new ReceiptContainerView();
            record.setReceiptContainerCode(containerCode);
            record.setLocationCode(locationCode);
            record.setTaskType((short) 100);
            record.setCompanyCode(receiptBills.get(0).getCompanyCode());
            receiptContainerHeaderService.checkContainer(record);
            if (locationCode != null) {
                receiptContainerHeaderService.mobileCheckLocationCode(record);
            }
            int receiptHeaderId = receiptHeaderService.createTodayHeader(companyCode);
            ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptHeaderId);
            List<Integer> receiptDetailIds = receiptDetailService.insertTodayReceiptDetail(receiptHeaderId, receiptBills, true, companyCode);
            if (receiptDetailIds != null && receiptDetailIds.size() > 0) {
                int containerHeaderId = receiptContainerHeaderService.insertTodayReceiptContainerHeader(receiptBills.get(0), receiptHeader.getCode());
                if (containerHeaderId > 0) {
                    List<Integer> receiptContainerDetailIds = receiptContainerDetailService.insertTodayReceiptcContainerDetail(containerHeaderId, receiptHeaderId, receiptDetailIds, receiptBills);
                    if (receiptContainerDetailIds != null && receiptContainerDetailIds.size() > 0) {

                    } else {
                        return AjaxResult.error("入库组盘失败");
                    }
                } else {
                    return AjaxResult.error("插入入库容器表单头失败");
                }
            } else {
                return AjaxResult.error("插入入库明细表单失败");
            }
        }

        return AjaxResult.success("收货成功");
    }

    @PostMapping("/listReceipt")
    @ApiOperation("移动端根据表单整盘入库")
    @Log(title = "移动端根据表单整盘入库", action = BusinessType.OTHER)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult listReceipt(@RequestBody @ApiParam(value = "收货单") List<ReceiptBill> receiptBills) throws Exception {
        if (receiptBills == null || receiptBills.size() <= 0) {
            throw new JSONException("没有收货信息");
        }
        String containerCode = receiptBills.get(0).receiptContainerCode;
        String companyCode = receiptBills.get(0).getCompanyCode();
        String receiptDetailId = receiptBills.get(0).getReceiptDetailId();
        String locationCode = receiptBills.get(0).locationCode;

        LambdaQueryWrapper<Container> containerQueryWrapper = Wrappers.lambdaQuery();
        containerQueryWrapper.eq(Container::getCode, containerCode);
        Container container = containerService.getOne(containerQueryWrapper);
        if (container == null) {
            if (locationCode != null) {
                LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
                locationLambdaQueryWrapper.eq(Location::getCode, locationCode);
                Location location = locationService.getOne(locationLambdaQueryWrapper);
                if (location != null && location.getLocationType().equals("PK")) {
                    containerCode = location.getContainerCode();
                    if (StringUtils.isEmpty(containerCode)) {
                        LambdaQueryWrapper<Container> containerQueryWrapper2 = Wrappers.lambdaQuery();
                        containerQueryWrapper2.eq(Container::getEnable, true)
                                .eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY)
                                .eq(Container::getContainerType, "DM");
                        List<Container> containerList = containerService.list(containerQueryWrapper2);
                        containerCode = containerList.get(0).getCode();
                    }
                } else {
                    return AjaxResult.error("不存在这个托盘");
                }
            } else {
                return AjaxResult.error("不存在这个托盘");
            }
        }

        if (locationCode != null) {
            LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
            locationLambdaQueryWrapper.eq(Location::getCode, locationCode);
            Location location = locationService.getOne(locationLambdaQueryWrapper);
            if (location == null) {
                throw new JSONException("不存在这个托盘");
            }

            if (!QuantityConstant.STATUS_LOCATION_EMPTY.equals(location.getStatus())) {
                throw new JSONException("库位状态不是空闲");
            }
        }

        LambdaQueryWrapper<ReceiptDetail> receiptDetailQueryWrapper = Wrappers.lambdaQuery();
        receiptDetailQueryWrapper.eq(ReceiptDetail::getId, receiptDetailId);
        ReceiptDetail receiptDetail = receiptDetailService.getOne(receiptDetailQueryWrapper);
        if (receiptDetail == null) {
            throw new JSONException("没有找到入库单详情");
        }

        LambdaQueryWrapper<ReceiptHeader> receiptHeaderQueryWrapper = Wrappers.lambdaQuery();
        receiptHeaderQueryWrapper.eq(ReceiptHeader::getId, receiptDetail.getReceiptId());
        ReceiptHeader receiptHeader = receiptHeaderService.getOne(receiptHeaderQueryWrapper);
        if (receiptHeader == null) {
            throw new JSONException("没有找到入库单");
        }

        List<ReceiptContainerView> receiptContainerViewList = new ArrayList<>();
        for (ReceiptBill receiptBill : receiptBills) {
            if (receiptBill.getQty().compareTo(BigDecimal.ZERO) == 0) {
                continue;
            }
            ReceiptContainerView receiptContainerView = new ReceiptContainerView();
            receiptContainerView.setLocationCode(receiptBill.getLocationCode());
            receiptContainerView.setCompanyCode(receiptBill.getCompanyCode());
            receiptContainerView.setReceiptContainerCode(containerCode);
            receiptContainerView.setReceiptDetailId(Integer.parseInt(receiptBill.getReceiptDetailId()));
            receiptContainerView.setQty(receiptBill.getQty());
            receiptContainerView.setTaskType((short) 100);
            receiptContainerViewList.add(receiptContainerView);
        }
        receiptContainerHeaderService.batchSave(receiptContainerViewList);
        AjaxResult retResult = taskHeaderService.createQuickTask(containerCode);
        return retResult;
    }

    @PostMapping("/findReceipt")
    @ApiOperation("移动端查询入库单")
    @Log(title = "移动端查询入库单", action = BusinessType.OTHER)
    public AjaxResult findReceipt(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        String receiptCode = param.get("receiptCode");
        String companyCode = param.get("companyCode");
        if (StringUtils.isNull(receiptCode)) {
            return AjaxResult.error("上游系统关联单号为空");
        } else if (StringUtils.isNull(companyCode)) {
            return AjaxResult.error("公司编码为空");
        }

        /* 查询入库单,如果数据库中不存在,则调用ERP接口拉取单据,成功后再次查询返回结果*/
        LambdaQueryWrapper<ReceiptHeader> receiptLambdaQueryWrapper = Wrappers.lambdaQuery();
        receiptLambdaQueryWrapper.eq(ReceiptHeader::getCode, receiptCode)
                .eq(ReceiptHeader::getCompanyCode, companyCode);
        ReceiptHeader receiptHeader = receiptHeaderService.getOne(receiptLambdaQueryWrapper);
        if (receiptHeader == null) {
            return AjaxResult.error("没有找到入库单");
        }
        ReceiptDomain receipt = new ReceiptDomain();
        receipt.setReceiptHeader(receiptHeader);

        LambdaQueryWrapper<ReceiptDetail> receiptDetailQueryWrapper = Wrappers.lambdaQuery();
        receiptDetailQueryWrapper.eq(ReceiptDetail::getReceiptId, receiptHeader.getId());
        List<ReceiptDetail> receiptDetailList = receiptDetailService.list(receiptDetailQueryWrapper);
        receipt.setReceiptDetails(receiptDetailList);
        return AjaxResult.success(receipt);
    }


    @PostMapping("/callBox")
    @ApiOperation("移动端呼叫料盒")
    @ApiLogger(apiName = "PDA呼叫料盒", from = "WCS")
    @Log(title = "移动端呼叫料盒", action = BusinessType.OTHER)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult callBox(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        String containerCode = param.get("containerCode");
        String destinationLocation = param.get("destinationLocation");
        int type = Integer.parseInt(param.get("type"));
        String companyCode = param.get("companyCode");

        if (StringUtils.isEmpty(destinationLocation) && StringUtils.isEmpty(containerCode)) {
            return AjaxResult.error("库位和容器不能都为空");
        }

        InventoryHeader inventoryHeader = null;
        //如果没传库位,根据容器查询库存拿到库位
        if (StringUtils.isEmpty(destinationLocation)) {
            inventoryHeader = inventoryHeaderService.getOne(new LambdaQueryWrapper<InventoryHeader>().eq(InventoryHeader::getContainerCode, containerCode));
            if (inventoryHeader == null) {
                return AjaxResult.error("没有这个库存,容器:", containerCode);
            }
            destinationLocation = inventoryHeader.getLocationCode();
        }

        //如果没传容器,根据库位查询库存拿到容器
        if (StringUtils.isEmpty(containerCode)) {
            inventoryHeader = inventoryHeaderService.getOne(new LambdaQueryWrapper<InventoryHeader>().eq(InventoryHeader::getLocationCode, destinationLocation));
            if (inventoryHeader == null) {
                return AjaxResult.error("没有这个库存,库位:", destinationLocation);
            }
            containerCode = inventoryHeader.getContainerCode();
        }

        if (StringUtils.isNotEmpty(containerCode) && StringUtils.isNotEmpty(destinationLocation)) {
            inventoryHeader = inventoryHeaderService.getOne(new LambdaQueryWrapper<InventoryHeader>().eq(InventoryHeader::getContainerCode, containerCode));
            if (inventoryHeader == null) {
                return AjaxResult.error("没有这个库存,库位:", destinationLocation);
            }
        }


        Location location = locationService.getOne(new LambdaQueryWrapper<Location>().eq(Location::getCode, destinationLocation));
        Container container = containerService.getOne(new LambdaQueryWrapper<Container>().eq(Container::getCode, containerCode).eq(Container::getWarehouseCode, "CS0001").last("limit 1"));
        if (container == null) {
            return AjaxResult.error("容器不存在");
        }
        if (location == null) {
            return AjaxResult.error("库位不存在");
        }
        if (StringUtils.isEmpty(container.getLocationCode())) {
            return AjaxResult.error("容器没有对应库位");
        }
        if (StringUtils.isEmpty(location.getContainerCode())) {
            return AjaxResult.error("库位没有对应容器");
        }
        if (!container.getLocationCode().equals(destinationLocation)) {
            return AjaxResult.error("库位不在容器[" + location.getContainerCode() + "]上");
        }
        if (!location.getContainerCode().equals(containerCode)) {
            return AjaxResult.error("容器不在库位[" + container.getLocationCode() + "]上");
        }
        if (!QuantityConstant.STATUS_LOCATION_EMPTY.equals(location.getStatus())) {
            return AjaxResult.error("目标库位非空闲");
        }
        if (QuantityConstant.STATUS_LOCATION_LOCK.equals(container.getStatus())) {
            return AjaxResult.error("容器是锁定状态");
        }
        if (QuantityConstant.STATUS_CONTAINER_EMPTY.equals(container.getStatus())) {
            return AjaxResult.error("容器是空托盘,不能做补充入库");
        }

        //判断托盘是否已经存在任务
        int taskCount = taskHeaderService.count(new LambdaQueryWrapper<TaskHeader>()
                .ne(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
                .eq(TaskHeader::getContainerCode, containerCode));
        if (taskCount > 0) {
            return AjaxResult.error("容器已存在任务");
        }

        //判断托盘是否已经存在入库组盘
        int receiptContainerHeaderCount = receiptContainerHeaderService.count(new LambdaQueryWrapper<ReceiptContainerHeader>()
                .ne(ReceiptContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_FINISHED)
                .eq(ReceiptContainerHeader::getContainerCode, containerCode));
        if (receiptContainerHeaderCount > 0) {
            return AjaxResult.error("该托盘已经用于入库组盘");
        }

        //判断托盘是否已经存在出库组盘
        int count = shipmentContainerHeaderService.count(new LambdaQueryWrapper<ShipmentContainerHeader>()
                .ne(ShipmentContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_FINISHED)
                .eq(ShipmentContainerHeader::getContainerCode, containerCode));
        if (count > 0) {
            return AjaxResult.error("该托盘已经用于出库组盘");
        }
        //自建库位不能呼叫料盒
        if (location.getSelfCreated()) {
            return AjaxResult.error("自建库位不能呼叫料盒");
        }
        //创建主任务
        TaskHeader taskHeader = new TaskHeader();
        taskHeader.setWarehouseCode(location.getWarehouseCode());
        taskHeader.setCompanyCode(companyCode);//货主
        if (type == QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT) {
            taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_RECEIPT);
            taskHeader.setTaskType(QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT);
        } else if (type == QuantityConstant.TASK_TYPE_WHOLERECEIPT) {
            taskHeader.setInternalTaskType(QuantityConstant.TASK_INTENERTYPE_RECEIPT);
            taskHeader.setTaskType(QuantityConstant.TASK_TYPE_WHOLERECEIPT);
        } else {
            return AjaxResult.error("type不对:" + type);
        }
        if (inventoryHeader == null) {
            return AjaxResult.error("库存不存在");
        }
        taskHeader.setWarehouse(inventoryHeader.getWarehouse());
        taskHeader.setWarehouseName(inventoryHeader.getWarehouseName());
        taskHeader.setContainerCode(container.getCode());
        taskHeader.setStatus(QuantityConstant.TASK_STATUS_BUILD);
        taskHeader.setFromLocation(location.getCode());
//        taskHeader.setToLocation(location.getCode());
        taskHeader.setCreated(new Date());
        taskHeader.setCreatedBy(ShiroUtils.getName());
        taskHeader.setLastUpdatedBy(ShiroUtils.getName());
        taskHeader.setLastUpdated(new Date());
        if (taskHeaderService.save(taskHeader)) {
            //锁定库位状态
            locationService.updateStatus(location.getCode(), QuantityConstant.STATUS_LOCATION_LOCK);
            //containerService.updateStatus(container.getCode(), QuantityConstant.STATUS_LOCATION_LOCK, "CS0001");
        } else {
            throw new ServiceException("补充入库主表生成失败!");
        }

        return AjaxResult.success(taskHeader.getId());
    }


    @PostMapping("/searchReceipt")
    @ApiOperation("移动端查询入库单")
    @Log(title = "移动端查询入库单", action = BusinessType.OTHER)
    public AjaxResult searchReceipt(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        String companyCode = param.get("companyCode");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String now = df.format(new Date());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, -7);
        Date first = c.getTime();
        String start = df.format(first);//前一天
        LambdaQueryWrapper<ReceiptHeader> receiptHeaderQueryWrapper = Wrappers.lambdaQuery();
        receiptHeaderQueryWrapper.eq(ReceiptHeader::getCompanyCode, companyCode)
                .eq(ReceiptHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .ne(ReceiptHeader::getReceiptType, "PPI")
                .le(ReceiptHeader::getCreated, now)
                .gt(ReceiptHeader::getCreated, start)
                .orderByDesc(ReceiptHeader::getCreated);
        List<ReceiptHeader> receiptHeaderList = receiptHeaderService.list(receiptHeaderQueryWrapper);
        return AjaxResult.success(receiptHeaderList);
    }

    @PostMapping("/searchReceiptInCondition")
    @ApiOperation("移动端查询入库单")
    @Log(title = "移动端查询入库单", action = BusinessType.OTHER)
    public AjaxResult searchReceiptInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        String companyCode = param.get("companyCode");
        String code = param.get("code");
        String receiptType = param.get("receiptType");
        String lastStatus = param.get("lastStatus");
        String startTime = param.get("startTime");
        String endTime = param.get("endTime");
        LambdaQueryWrapper<ReceiptHeader> receiptQueryWrapper = Wrappers.lambdaQuery();
        receiptQueryWrapper.eq(ReceiptHeader::getCompanyCode, companyCode)
                .eq(ReceiptHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .like(StringUtils.isNotEmpty(code), ReceiptHeader::getCode, code)
                .eq(StringUtils.isNotEmpty(receiptType), ReceiptHeader::getReceiptType, receiptType)
                .eq(StringUtils.isNotEmpty(lastStatus), ReceiptHeader::getLastStatus, lastStatus)
                .gt(StringUtils.isNotEmpty(startTime), ReceiptHeader::getCreated, startTime)
                .le(StringUtils.isNotEmpty(endTime), ReceiptHeader::getCreated, endTime)
                .orderByDesc(ReceiptHeader::getCreated);
        if (lastStatus.equals("200")) {
            receiptQueryWrapper = Wrappers.lambdaQuery();
            receiptQueryWrapper.lt(ReceiptHeader::getLastStatus, 900);
            receiptQueryWrapper.eq(ReceiptHeader::getCompanyCode, companyCode)
                    .eq(ReceiptHeader::getWarehouseCode, ShiroUtils.getWarehouseCode())
                    .like(StringUtils.isNotEmpty(code), ReceiptHeader::getCode, code)
                    .eq(StringUtils.isNotEmpty(receiptType), ReceiptHeader::getReceiptType, receiptType)
                    .gt(StringUtils.isNotEmpty(startTime), ReceiptHeader::getCreated, startTime)
                    .le(StringUtils.isNotEmpty(endTime), ReceiptHeader::getCreated, endTime)
                    .orderByDesc(ReceiptHeader::getCreated);
        }
        List<ReceiptHeader> receiptDetailList = receiptHeaderService.list(receiptQueryWrapper);
        return AjaxResult.success(receiptDetailList);
    }

    @PostMapping("/getDictListData")
    @ApiOperation("移动端查询字典信息")
    @Log(title = "移动端查询字典信息", action = BusinessType.OTHER)
    public AjaxResult getDictListData(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        String dictType = param.get("dictType");
        List<DictData> dictDataList = dictDataService.selectDictDataByType(dictType);
        return AjaxResult.success(dictDataList);
    }

    @PostMapping("/getReceiptType")
    @ApiOperation("移动端查询入库类型")
    @Log(title = "移动端查询字典信息", action = BusinessType.OTHER)
    public AjaxResult getReceiptType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        String companyCode = param.get("companyCode");
        LambdaQueryWrapper<ReceiptType> receiptTypeLambda = Wrappers.lambdaQuery();
        receiptTypeLambda.eq(ReceiptType::getCompanyCode, companyCode);
        receiptTypeLambda.eq(ReceiptType::getWarehouseCode, ShiroUtils.getWarehouseCode());
        List<ReceiptType> receiptType = receiptTypeService.list(receiptTypeLambda);
        return AjaxResult.success(receiptType);
    }

    @PostMapping("/createReceiptCode")
    @ApiOperation("移动端创建入库单号")
    @Log(title = "移动端创建入库单号", action = BusinessType.OTHER)
    public AjaxResult createReceiptCode(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        String companyCode = param.get("companyCode");
        String receiptType = param.get("receiptType");
        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";
        }
        return AjaxResult.success().setData(code);
    }

    @PostMapping("/createReceipt")
    @ApiOperation("移动端创建入库单")
    @Log(title = "移动端创建入库单", action = BusinessType.OTHER)
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult createReceipt(@RequestBody @ApiParam(value = "物料号") List<ReceiptBill> receiptBills) {
        String companyCode = receiptBills.get(0).getCompanyCode();
        String receiptCode = receiptBills.get(0).getReceiptCode();
        String receiptType = receiptBills.get(0).getReceiptType();
        ReceiptHeader receiptHeader = new ReceiptHeader();
        receiptHeader.setId(null);
        receiptHeader.setCode(receiptCode);
        receiptHeader.setReceiptType(receiptType);
        receiptHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
        receiptHeader.setCreated(null);
        receiptHeader.setCreatedBy(ShiroUtils.getName());
        receiptHeader.setLastUpdated(null);
        receiptHeader.setLastUpdatedBy(ShiroUtils.getName());
        receiptHeader.setFirstStatus(200);
        receiptHeader.setLastStatus(200);
        receiptHeader.setCompanyCode(companyCode);
        receiptHeaderService.save(receiptHeader);
        List<Integer> receiptDetailIds = receiptDetailService.insertTodayReceiptDetail(receiptHeader.getId(), receiptBills, false, companyCode);
        receiptDetailService.updateReceiptHeader(receiptHeader);
        if (receiptDetailIds != null && receiptDetailIds.size() > 0) {
            return AjaxResult.success("创建入库单成功");
        }
        return AjaxResult.error("创建入库单失败");
    }

    @PostMapping("/findMaterial")
    @ApiOperation("移动端查询物料信息")
    @Log(title = "移动端查询物料信息", action = BusinessType.OTHER)
    public AjaxResult findMaterial(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialLambdaQueryWrapper.eq(Material::getDeleted, false)
                .orderByDesc(Material::getCreated);
        List<Material> materialList = materialService.list(materialLambdaQueryWrapper);
        return AjaxResult.success(materialList);
    }

    @PostMapping("/addMaterial")
    @ApiOperation("移动端增加物料信息")
    @Log(title = "移动端增加物料信息", action = BusinessType.OTHER)
    public AjaxResult addMaterial(@RequestBody @ApiParam(value = "物料号") Material material) throws Exception {
        AjaxResult result = materialService.addSave(material);
        return result;
    }

    @PostMapping("/searchMaterialInCondition")
    @ApiOperation("移动端查询物料信息")
    @Log(title = "移动端查询物料信息", action = BusinessType.OTHER)
    public AjaxResult searchMaterialInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        String companyCode = param.get("companyCode");
        String code = param.get("code");
        String name = param.get("name");
        String spec = param.get("spec");
        String startTime = param.get("startTime");
        String endTime = param.get("endTime");
        LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialLambdaQueryWrapper.eq(Material::getCompanyCode, companyCode)
                .eq(Material::getWarehouseCode, ShiroUtils.getWarehouseCode())
                .eq(Material::getDeleted, false)
                .like(StringUtils.isNotEmpty(code), Material::getCode, code)
                .like(StringUtils.isNotEmpty(name), Material::getName, name)
                .like(StringUtils.isNotEmpty(spec), Material::getSpec, spec)
                .gt(StringUtils.isNotEmpty(startTime), Material::getCreated, startTime)
                .le(StringUtils.isNotEmpty(endTime), Material::getCreated, endTime)
                .orderByDesc(Material::getCreated);
        List<Material> materialList = materialService.list(materialLambdaQueryWrapper);
        return AjaxResult.success(materialList);
    }

    @PostMapping("/createMaterialCode")
    @ApiOperation("移动端创建物料编码")
    @Log(title = "移动端创建物料编码", action = BusinessType.OTHER)
    public AjaxResult createMaterialCode(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) {
        String code = null;
        Date now = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        String day = df.format(now);
        LambdaQueryWrapper<Material> materialLambdaQueryWrapper = Wrappers.lambdaQuery();
        materialLambdaQueryWrapper.like(Material::getCode, day);
        ;
        List<Material> materials = materialService.list(materialLambdaQueryWrapper);
        int length = materials.size();
        //如果指定类型的最后的code存在,并且日期一致。那么 code = 入库单类型 + 年月日 + (排序号 + 1)
        if (length > 0) {
            code = day + String.format("%03d", length + 1);
        } else {
            code = day + "001";
        }
        return AjaxResult.success().setData(code);
    }

    @PostMapping("/getMaterialType")
    @ApiOperation("移动端获取物料类型")
    @Log(title = "移动端获取物料类型", action = BusinessType.OTHER)
    public AjaxResult getMaterialType(@RequestBody @ApiParam(value = "物料号") Map<String, String> param) throws Exception {
        LambdaQueryWrapper<MaterialType> materialTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
        List<MaterialType> materialTypes = materialTypeService.list(materialTypeLambdaQueryWrapper);
        return AjaxResult.success(materialTypes);
    }

}