RobotController.java 26.1 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
package com.huaheng.api.robot.controller;

import com.alibaba.druid.support.spring.stat.annotation.Stat;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.general.domain.InventoryQueryDomain;
import com.huaheng.api.robot.domain.RobotInfo;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.emptyOutHandle.EmptyOutHandleService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
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.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.domain.ContainerType;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.service.InventoryMaterialSummaryService;
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.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.ReceiptTaskService;
import com.huaheng.pc.task.taskHeader.service.ShipmentTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/API/WMS/v2")

@Api(tags = {"机器人对接接口"}, value = "机器人对接接口RobotController")
public class RobotController  extends BaseController {

    @Resource
    private EmptyOutHandleService emptyOutHandleService;
    @Resource
    private ZoneService zoneService;
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private ContainerService containerService;
    @Resource
    private ContainerTypeService containerTypeService;
    @Resource
    private TaskHeaderService taskHeaderService;
    @Resource
    private StationService stationService;
    @Resource
    private ReceiptTaskService receiptTaskService;
    @Resource
    private ShipmentTaskService shipmentTaskService;
    @Resource
    private InventoryHeaderService inventoryHeaderService;
    @Resource
    private InventoryMaterialSummaryService inventoryMaterialSummaryService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private MaterialService materialService;


    @Log(title = "生产入库", action = BusinessType.INSERT)
    @PostMapping("/callReceipt")
    @ApiOperation("生产入库")
    @ApiLogger(apiName = "生产入库", from="robot")
    @ResponseBody
    public AjaxResult callReceipt(@RequestBody Map<String,String> map) {
        String warehouseCode = "CS0001";
        String line = map.get("line");
        String materialCode = map.get("materialCode");
        String qty = map.get("qty");
        String area = map.get("area");
        if(line == null) {
            return AjaxResult.error("没有line");
        }
        if(materialCode == null) {
            return AjaxResult.error("没有materialCode");
        }
        if(qty == null) {
            return AjaxResult.error("没有qty");
        }
        if(area == null) {
            return AjaxResult.error("没有area");
        }
        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
        zoneLambdaQueryWrapper.eq(Zone::getArea, area);
        Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
        String zoneCode = zone.getCode();

        LambdaQueryWrapper<Station> stationLambdaQueryWrapper = Wrappers.lambdaQuery();
        stationLambdaQueryWrapper.eq(Station::getArea, area)
                .eq(Station::getLine, line);
        List<Station> stationList = stationService.list(stationLambdaQueryWrapper);
        List<String> portCodeList = stationList.stream().map(t->t.getCode()).collect(Collectors.toList());
        String port = null;
        Material material = materialService.findAllByCode(materialCode, warehouseCode);
        int maxContainer = material.getMaxContainer();
        if(portCodeList.size() > 1) {
            for (String portCode : portCodeList) {
                LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper2 = Wrappers.lambdaQuery();
                taskHeaderLambdaQueryWrapper2.eq(TaskHeader::getPort, portCode)
                        .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
                TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper2);

                LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
                List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
                if(taskDetailList != null && taskDetailList.size() > 0) {
                    int size = taskDetailList.size();

                }
                if (taskHeader == null) {
                    port = portCode;
                    break;
                }

            }
        } else {
            port = portCodeList.get(0);
        }

        LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery();
        containerLambdaQueryWrapper.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY)
                .ne(Container::getLocationCode, "")
                .eq(Container::getArea, area);
        List<Location> list = containerService.getEmptyContainerInLocation(
                zoneCode, "","", warehouseCode);
        List<String> emptyContainerCodeList = list.stream().map(t->t.getContainerCode()).collect(Collectors.toList());
        if(emptyContainerCodeList != null && emptyContainerCodeList.size() > 0) {
            Container container = containerService.getContainerByCode(emptyContainerCodeList.get(0), warehouseCode);
            int maxEmpty = container.getMaxEmpty();
            if(emptyContainerCodeList.size() > maxEmpty) {
                String containerCode = container.getCode();
                String locationCode = container.getLocationCode();
                return receiptTaskService.createSuppleReceiptTask(containerCode, locationCode, warehouseCode, port);
            }
        }
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getMaterialCode, materialCode)
                .lt(InventoryDetail::getQty, maxContainer)
                .eq(InventoryDetail::getZoneCode, zoneCode);
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        if(inventoryDetailList != null &&  inventoryDetailList.size() > 0) {
            List<String> containerList = inventoryDetailList.stream().
                    map(t -> t.getContainerCode()).collect(Collectors.toList());
            String containerCode = containerList.get(0);
            Container container = containerService.getContainerByCode(containerCode, warehouseCode);
            String locationCode = container.getLocationCode();
            return receiptTaskService.createSuppleReceiptTask(containerCode, locationCode, warehouseCode, port);
        } else {
            if(emptyContainerCodeList != null && emptyContainerCodeList.size() > 0) {
                Container container = containerService.getContainerByCode(
                        emptyContainerCodeList.get(0), warehouseCode);
                String containerCode = container.getCode();
                String locationCode = container.getLocationCode();
                return receiptTaskService.createSuppleReceiptTask(containerCode, locationCode,
                        warehouseCode, port);

            }
        }
        return AjaxResult.error("没有托盘可以满足入库");
    }

    @Log(title = "生产叫料", action = BusinessType.INSERT)
    @PostMapping("/callShipment")
    @ApiOperation("生产叫料")
    @ResponseBody
    public AjaxResult callShipment(@RequestBody Map<String,String> map) {
        String warehouseCode = "CS0001";
        String line = map.get("line");
        String materialCode = map.get("materialCode");
        String qty = map.get("qty");
        String area = map.get("area");
        if(line == null) {
            return AjaxResult.error("没有line");
        }
        if(materialCode == null) {
            return AjaxResult.error("没有materialCode");
        }
        if(qty == null) {
            return AjaxResult.error("没有qty");
        }
        if(area == null) {
            return AjaxResult.error("没有area");
        }
        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
        zoneLambdaQueryWrapper.eq(Zone::getArea, area);
        Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
        String zoneCode = zone.getCode();
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getMaterialCode, materialCode)
                                        .eq(InventoryDetail::getTaskQty, 0)
                                        .eq(InventoryDetail::getZoneCode, zoneCode);
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        if(inventoryDetailList == null || inventoryDetailList.size() == 0) {
            return AjaxResult.error("没有对应库存");
        }
        LambdaQueryWrapper<Station> stationLambdaQueryWrapper = Wrappers.lambdaQuery();
        stationLambdaQueryWrapper.eq(Station::getArea, area)
                                .eq(Station::getLine, line);
        List<Station> stationList = stationService.list(stationLambdaQueryWrapper);
        List<String> portCodeList = stationList.stream().map(t->t.getCode()).collect(Collectors.toList());
        RobotInfo robotInfo = new RobotInfo();
        List<String> containerList = inventoryDetailList.stream().
                map(t -> t.getContainerCode()).collect(Collectors.toList());
        containerList = containerList.stream().distinct().collect(Collectors.toList());
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.in(TaskHeader::getPort, portCodeList)
                                .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
                                .in(TaskHeader::getContainerCode, containerList);
        List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
        if(taskHeaderList != null && taskHeaderList.size() > 0) {
            TaskHeader taskHeader = taskHeaderList.get(0);
            return AjaxResult.success(robotInfo);
        } else {

        }

        String port = null;
        if(portCodeList.size() > 1) {
            for (String portCode : portCodeList) {
                LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper2 = Wrappers.lambdaQuery();
                taskHeaderLambdaQueryWrapper2.eq(TaskHeader::getPort, portCode)
                        .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
                TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper2);
                if (taskHeader == null) {
                    port = portCode;
                    break;
                }
            }
        } else {
            port = portCodeList.get(0);
        }
        if(port == null) {
            return AjaxResult.error("没有对应库存");
        }
        String containerCode = containerList.get(0);
        Container container = containerService.getContainerByCode(containerCode, warehouseCode);
        String locationCode = container.getLocationCode();
        AjaxResult ajaxResult = shipmentTaskService.createPickingTask(
                containerCode, locationCode, warehouseCode, port);
        return ajaxResult;
    }

    /**
     * 查询托盘库存
     */
    @Log(title = "查询托盘库存", action = BusinessType.INSERT)
    @PostMapping("/searchContainerInventory")
    @ApiOperation("查询托盘库存")
    @ApiLogger(apiName = "查询托盘库存", from="robot")
    @ResponseBody
    public AjaxResult searchContainerInventory(@RequestBody InventoryQueryDomain inventoryQueryDomain)
    {
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getWarehouseCode()),
                InventoryDetail::getWarehouseCode, inventoryQueryDomain.getWarehouseCode())
                .eq(StringUtils.isNotEmpty(inventoryQueryDomain.getContainerCode()),
                        InventoryDetail::getContainerCode, inventoryQueryDomain.getContainerCode())
                .eq(StringUtils.isNotEmpty(inventoryQueryDomain.getLocationCode()),
                        InventoryDetail::getLocationCode, inventoryQueryDomain.getLocationCode())
                .eq(StringUtils.isNotEmpty(inventoryQueryDomain.getCompanyCode()),
                        InventoryDetail::getCompanyCode, inventoryQueryDomain.getCompanyCode())
                .eq(StringUtils.isNotEmpty(inventoryQueryDomain.getMaterialCode()),
                        InventoryDetail::getMaterialCode, inventoryQueryDomain.getMaterialCode());
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        return AjaxResult.success(inventoryDetailList);
    }

    @Log(title = "wcs托盘回库", action = BusinessType.INSERT)
    @PostMapping("/back")
    @ApiOperation("wcs托盘回库")
    @ResponseBody
    public AjaxResult back(@RequestBody WcsTask wcsTask)
    {
        String containerCode = wcsTask.getContainerCode();
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getContainerCode, containerCode);
        taskHeaderLambdaQueryWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
        TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
        if(taskHeader == null) {
            return AjaxResult.error("不允许回库");
        }
        int back = taskHeader.getBack();
        if(back == 1) {
            return AjaxResult.success("允许回库");
        }
        return AjaxResult.error("不允许回库");
    }

    /**
     * 查询库存
     */
    @Log(title = "查询库存", action = BusinessType.INSERT)
    @PostMapping("/searchInventory")
    @ApiOperation("查询库存")
    @ResponseBody
    @ApiLogger(apiName = "查询库存", from="ERP")
    public AjaxResult searchInventory(@RequestBody InventoryMaterialSummary inventoryMaterialSummary)
    {
        LambdaQueryWrapper<InventoryMaterialSummary> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper
                .eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getWarehouseCode()),
                        InventoryMaterialSummary::getWarehouseCode, inventoryMaterialSummary.getWarehouseCode())
                //物料编码
                .eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getMaterialCode()),
                        InventoryMaterialSummary::getMaterialCode, inventoryMaterialSummary.getMaterialCode())
                //物料名称
                .eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getMaterialName()),
                        InventoryMaterialSummary::getMaterialName, inventoryMaterialSummary.getMaterialName())
                .eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getZoneCode()),
                        InventoryMaterialSummary::getZoneCode, inventoryMaterialSummary.getZoneCode())
                //货主
                .eq(!StringUtils.isEmpty(inventoryMaterialSummary.getCompanyCode()),
                        InventoryMaterialSummary::getCompanyCode, inventoryMaterialSummary.getCompanyCode());
        List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(lambdaQueryWrapper);
        if (list == null) {
            list = Collections.emptyList();
        }
        //筛选库存汇总数据的专用方法
        List<InventoryMaterialSummary> details = inventoryMaterialSummaryService.duplicateRemoval(list);
        return AjaxResult.success(details);
    }

    /**
     * 出库抓取信息
     */
    @Log(title = "出库抓取信息", action = BusinessType.INSERT)
    @PostMapping("/addShipmentDetail")
    @ApiOperation("出库抓取信息")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult addShipmentDetail(@RequestBody Map<String,String> map)
    {
        String warehouseCode = "CS0001";
        String containerCode = map.get("containerCode");
        String port = map.get("port");
        String materialCode = map.get("materialCode");
        String qty = map.get("qty");
        String sn = map.get("sn");
        String position = map.get("position");
        String area = map.get("area");
        if(containerCode == null) {
            return AjaxResult.error("没有containerCode");
        }
        if(port == null) {
            return AjaxResult.error("没有port");
        }
        if(materialCode == null) {
            return AjaxResult.error("没有materialCode");
        }
        if(qty == null) {
            return AjaxResult.error("没有qty");
        }
        if(sn == null) {
            return AjaxResult.error("没有sn");
        }
        if(position == null) {
            return AjaxResult.error("没有position");
        }
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT)
                                    .eq(TaskHeader::getContainerCode, containerCode)
                                    .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
                                    .eq(TaskHeader::getPort, port);
        TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
        if(taskHeader == null) {
            return AjaxResult.error("没有找到任务");
        }
        BigDecimal taskQty = new BigDecimal(qty);
        Material material = materialService.findAllByCode(materialCode, warehouseCode);
        TaskDetail taskDetail = new TaskDetail();
        taskDetail.setTaskId(taskHeader.getId());
        taskDetail.setQty(taskQty);
        taskDetail.setSerialNum(sn);
        taskDetail.setPosition(position);
        taskDetail.setMaterialCode(materialCode);
        taskDetail.setMaterialName(material.getName());
        taskDetail.setTaskType(taskHeader.getTaskType());
        taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
        taskDetail.setCompanyCode(taskHeader.getCompanyCode());
        taskDetail.setFromLocation(taskHeader.getFromLocation());
        taskDetail.setToLocation(taskHeader.getToLocation());
        taskDetail.setInternalTaskType(taskHeader.getInternalTaskType());
        taskDetail.setContainerCode(taskHeader.getContainerCode());
        boolean result = taskDetailService.save(taskDetail);
        if(!result) {
            throw new ServiceException("减少物料失败");
        }
        LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getContainerCode, containerCode)
                .eq(InventoryHeader::getWarehouseCode, warehouseCode);
        InventoryHeader inventoryHeader = inventoryHeaderService.getOne(inventoryHeaderLambdaQueryWrapper);
        if(inventoryHeader == null) {
            throw new ServiceException("没有找到库存头");
        }
        int headerId = inventoryHeader.getId();
        LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getInventoryHeaderId, headerId)
                                        .eq(InventoryDetail::getWarehouseCode, warehouseCode)
                                        .eq(InventoryDetail::getMaterialCode, materialCode)
                                        .eq(InventoryDetail::getQty, qty)
                                        .eq(InventoryDetail::getPosition, position);
        InventoryDetail inventoryDetail = inventoryDetailService.getOne(inventoryDetailLambdaQueryWrapper);
        if(inventoryDetail == null) {
            throw new ServiceException("没有找到库存详情");
        }
        result = inventoryDetailService.removeById(inventoryDetail);
        if(!result) {
            throw new ServiceException("库存详情删除失败");
        }
        inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
        inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getInventoryHeaderId, headerId)
                .eq(InventoryDetail::getWarehouseCode, warehouseCode)
                .eq(InventoryDetail::getMaterialCode, materialCode);
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        if(inventoryDetailList != null && inventoryDetailList.size() > 0) {
            int size = inventoryDetailList.size();
            inventoryHeader.setTotalQty(new BigDecimal(size));
            inventoryHeader.setTotalLines(size);
            inventoryHeader.setContainerStatus(QuantityConstant.STATUS_CONTAINER_SOME);
            LambdaQueryWrapper<InventoryHeader> wrapper = Wrappers.lambdaQuery();
            wrapper.eq(InventoryHeader::getId, inventoryHeader.getId());
            inventoryHeaderService.update(inventoryHeader, wrapper);
        } else {
            inventoryHeaderService.removeById(inventoryHeader);
        }
        return AjaxResult.success("减少物料成功");
    }

    /**
     * 入库抓取信息
     */
    @Log(title = "入库抓取信息", action = BusinessType.INSERT)
    @PostMapping("/addReceiptDetail")
    @ApiOperation("入库抓取信息")
    @ResponseBody
    public AjaxResult addReceiptDetail(@RequestBody Map<String,String> map)
    {
        String warehouseCode = "CS0001";
        String containerCode = map.get("containerCode");
        String port = map.get("port");
        String materialCode = map.get("materialCode");
        String qty = map.get("qty");
        String sn = map.get("sn");
        String isPrint = map.get("isPrint");
        String position = map.get("position");
        String area = map.get("area");
        if(containerCode == null) {
            return AjaxResult.error("没有containerCode");
        }
        if(port == null) {
            return AjaxResult.error("没有port");
        }
        if(materialCode == null) {
            return AjaxResult.error("没有materialCode");
        }
        if(qty == null) {
            return AjaxResult.error("没有qty");
        }
        if(position == null) {
            return AjaxResult.error("没有position");
        }
        LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
        taskHeaderLambdaQueryWrapper.eq(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT)
                                    .eq(TaskHeader::getContainerCode, containerCode)
                                    .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED)
                                    .eq(TaskHeader::getPort, port);
        TaskHeader taskHeader = taskHeaderService.getOne(taskHeaderLambdaQueryWrapper);
        if(taskHeader == null) {
            return AjaxResult.error("没有找到任务");
        }
        BigDecimal taskQty = new BigDecimal(qty);
        Material material = materialService.findAllByCode(materialCode, warehouseCode);
        TaskDetail taskDetail = new TaskDetail();
        taskDetail.setTaskId(taskHeader.getId());
        taskDetail.setQty(taskQty);
        taskDetail.setSerialNum(sn);
        taskDetail.setPosition(position);
        if(isPrint != null) {
            taskDetail.setIsPrint(Integer.parseInt(isPrint));
        }
        taskDetail.setMaterialCode(materialCode);
        taskDetail.setMaterialName(material.getName());
        taskDetail.setTaskType(taskHeader.getTaskType());
        taskDetail.setWarehouseCode(taskHeader.getWarehouseCode());
        taskDetail.setCompanyCode(taskHeader.getCompanyCode());
        taskDetail.setFromLocation(taskHeader.getFromLocation());
        taskDetail.setToLocation(taskHeader.getToLocation());
        taskDetail.setInternalTaskType(taskHeader.getInternalTaskType());
        taskDetail.setContainerCode(taskHeader.getContainerCode());
        try {
            boolean result = taskDetailService.save(taskDetail);
            if (!result) {
                throw new ServiceException("增加物料失败");
            }
        } catch (Exception e) {
            throw new ServiceException("增加物料失败");
        }
        return AjaxResult.success("增加物料成功");
    }
}