RobotController.java 16 KB
package com.huaheng.api.robot.controller;

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.service.RobotService;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.emptyOutHandle.EmptyOutHandleService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
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.service.InventoryHeaderService;
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.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/API/WMS/v2")
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;
    @Resource
    private RobotService robotService;


    @PostMapping("/callReceipt")
    @ApiOperation("生产入库")
    @ApiLogger(apiName = "生产入库", from = "ROBOT")
    @ResponseBody
    public AjaxResult callReceipt(@RequestBody Map<String, String> map) {
        String materialCodePLC = map.get("materialCodePLC");
        String orderNo = map.get("orderNo");
        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");
        }
        if (materialCodePLC == null) {
            return AjaxResult.error("没有materialCodePLC");
        }
        if (orderNo == null) {
            return AjaxResult.error("没有orderNo");
        }
        int materialCodePLCint = Integer.parseInt(materialCodePLC);
        AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = robotService.innerCallReceipt(line,
                        materialCode, qty, area, materialCodePLCint, orderNo);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }


    @PostMapping("/callShipment")
    @ApiOperation("生产叫料")
    @ApiLogger(apiName = "生产叫料", from = "ROBOT")
    @ResponseBody
    public AjaxResult callShipment(@RequestBody Map<String, String> map) {
        String materialCodePLC = map.get("materialCodePLC");
        String orderNo = map.get("orderNo");
        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");
        }
        if (materialCodePLC == null) {
            return AjaxResult.error("没有materialCodePLC");
        }
        if (orderNo == null) {
            return AjaxResult.error("没有orderNo");
        }
        int materialCodePLCint = Integer.parseInt(materialCodePLC);
        AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = robotService.innerCallShipment(line, materialCode, qty,
                        area, materialCodePLCint, orderNo);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    /**
     * 查询托盘库存
     */
    @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.getZoneCode()),
                        InventoryDetail::getZoneCode, inventoryQueryDomain.getZoneCode())
                .eq(StringUtils.isNotEmpty(inventoryQueryDomain.getMaterialCode()),
                        InventoryDetail::getMaterialCode, inventoryQueryDomain.getMaterialCode());
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        return AjaxResult.success(inventoryDetailList);
    }

    /**
     * 查询托盘库存
     */
    @PostMapping("/searchContainer")
    @ApiOperation("查询托盘库存")
    @ApiLogger(apiName = "查询托盘库存", from = "ROBOT")
    @ResponseBody
    public AjaxResult searchContainer(@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.getZoneCode()),
                        InventoryDetail::getZoneCode, inventoryQueryDomain.getZoneCode())
                .eq(StringUtils.isNotEmpty(inventoryQueryDomain.getMaterialCode()),
                        InventoryDetail::getMaterialCode, inventoryQueryDomain.getMaterialCode());
        List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
        List<InventoryDetail> removeInventoryDetailList = new ArrayList<>();
        if (inventoryDetailList != null && inventoryDetailList.size() > 0) {
            for (InventoryDetail inventoryDetail : inventoryDetailList) {
                String zoneCode = inventoryDetail.getZoneCode();
                if (zoneCode.equals("H") || zoneCode.equals("I")) {
                    int taskQty = inventoryDetail.getTaskQty().intValue();
                    if (taskQty != 0) {
                        removeInventoryDetailList.add(inventoryDetail);
                    }
                }
            }
            inventoryDetailList.removeAll(removeInventoryDetailList);
        }
        return AjaxResult.success(inventoryDetailList);
    }

    @PostMapping("/back")
    @ApiOperation("wcs托盘回库")
    @ResponseBody
    public AjaxResult back(@RequestBody WcsTask wcsTask) {
        AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
            @Override
            public AjaxResult doProcess() {
                AjaxResult ajaxResult = robotService.innerBack(wcsTask);
                return ajaxResult;
            }
        });
        return ajaxResult;
    }

    /**
     * 查询库存
     */
    @PostMapping("/searchInventory")
    @ApiOperation("查询库存")
    @ResponseBody
    @ApiLogger(apiName = "查询库存", from = "ROBOT")
    public AjaxResult searchInventory(@RequestBody InventoryMaterialSummary inventoryMaterialSummary) {
        String area = inventoryMaterialSummary.getArea();
        if (StringUtils.isNotEmpty(area)) {
            LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
            zoneLambdaQueryWrapper.eq(Zone::getArea, area);
            Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
            inventoryMaterialSummary.setZoneCode(zone.getCode());
        }
        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(InventoryMaterialSummary::getTaskQty, 0)
                //货主
                .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);
    }


    /**
     * 查询是否满足自动出库
     */
    @PostMapping("/searchShipmentTask")
    @ApiOperation("查询出库任务")
    @ResponseBody
    @ApiLogger(apiName = "查询出库任务", from = "ROBOT")
    public AjaxResult searchShipmentTask(@RequestBody Map<String, String> map) {
        String area = map.get("area");
        String line = map.get("line");

        if (line == null) {
            return AjaxResult.error("没有line");
        }
        if (area == null) {
            return AjaxResult.error("没有area");
        }

        LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
        zoneLambdaQueryWrapper.eq(Zone::getArea,area);
        Zone zoneServiceOne = zoneService.getOne(zoneLambdaQueryWrapper);


        LambdaQueryWrapper<Station> stationLambdaQueryWrapper = Wrappers.lambdaQuery();
        stationLambdaQueryWrapper.eq(Station::getArea, area)
                .eq(Station::getLine, line);
        List<Station> stationList = stationService.list(stationLambdaQueryWrapper);
        if (stationList == null || stationList.size() == 0) {
            return AjaxResult.error("区域和线体不正确");
        }
        List<String> portCodeList = stationList.stream().map(t -> t.getCode()).collect(Collectors.toList());
        if (portCodeList == null || portCodeList.size() == 0) {
            return AjaxResult.error("线体编码或者区域不正确,没有找到对应出口");
        }
        if (portCodeList.size() > 1) {
            for (String portCode : portCodeList) {
                LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
                taskHeaderLambdaQueryWrapper.eq(TaskHeader::getPort, portCode)
                        .eq(TaskHeader::getZoneCode,zoneServiceOne.getCode())
                        .isNull(TaskHeader::getOrderNo)
                        .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT,
                                QuantityConstant.TASK_TYPE_WHOLESHIPMENT)
                        .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
                List<TaskHeader> taskHeaders = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
                if (taskHeaders != null && !taskHeaders.isEmpty()) {
                    return AjaxResult.error("还存在手动任务,无法下发自动任务!");
                }
            }
        } else {
            LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
            taskHeaderLambdaQueryWrapper.eq(TaskHeader::getPort, portCodeList.get(0))
                    .eq(TaskHeader::getZoneCode,zoneServiceOne.getCode())
                    .isNull(TaskHeader::getOrderNo)
                    .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT,
                            QuantityConstant.TASK_TYPE_WHOLESHIPMENT)
                    .lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
            List<TaskHeader> taskHeaders = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
            if (taskHeaders != null && !taskHeaders.isEmpty()) {
                return AjaxResult.error("还存在手动任务,无法下发自动任务!");
            }
        }
        return AjaxResult.success();
    }
}