TaskConfirm.java 5.15 KB
package com.huaheng.api.acs.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.api.acs.domain.AgvTask;
import com.huaheng.api.acs.service.AcsService;
import com.huaheng.api.wcs.domain.ManyEmptyDomain;
import com.huaheng.common.constant.QuantityConstant;
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.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
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.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/api/ACS/v1")
@Api(tags = {"ACS任务回传接口"}, value = "ACS任务回传接口")
public class TaskConfirm extends BaseController {
    @Resource
    private AcsService acsService;
    @Resource
    private ContainerService containerService;
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private ShipmentTaskService shipmentTaskService;
    @Resource
    private TaskHeaderService taskHeaderService;


    /**
     * AGV 任务回传
     */
//    @RequiresPermissions("api:acs:TaskConfirm")
    @Log(title = "AGV 任务回传", action = BusinessType.UPDATE)
    @PostMapping("/TaskConfirm")
    @ApiOperation("AGV 任务回传接口")
    @ResponseBody
    @ApiLogger(apiName = "AGV任务回传", from="ACS")
    public AjaxResult TaskConfirm(@RequestBody AgvTask model)
    {
        return acsService.TaskConfirm(model);
    }

    @Log(title = "AGV 呼叫空托盘出库", action = BusinessType.UPDATE)
    @PostMapping("/callEmptyContainerShipment")
    @ApiOperation("AGV 呼叫空托盘出库")
    @ResponseBody
    @ApiLogger(apiName = "呼叫空托盘出库", from="ACS")
    public AjaxResult callEmptyContainerShipment(@RequestBody ManyEmptyDomain domain)
    {
        return AjaxResult.success();
    }

    /**
     * agv出库
     */
    @PostMapping("/agvShipment")
    @ApiOperation("agv出库")
    @ResponseBody
    @ApiLogger(apiName = "agv出库", from="ROBOT")
    public AjaxResult agvShipment (@RequestBody Map<String,Object> map) {
        String area = String.valueOf( (Integer) map.get("area"));
        List<String> containerCodeList =  (List<String>) map.get("containerCodeList");
//        String taskIndex = (String) map.get("taskIndex");
        if(containerCodeList == null) {
            return AjaxResult.error("没有containerCodeList");
        }
        if(area == null) {
            return AjaxResult.error("没有area");
        }

//        if(taskIndex == null) {
//            return AjaxResult.error("没有taskIndex");
//        }
        AjaxResult ajaxResult = null;
        int areaInt = Integer.parseInt(area);
        if(areaInt != 4) {
            return AjaxResult.error("AGV只有4号区");
        }
        String stationCode = "P1001";
        for(String containerCode : containerCodeList) {
            String warehouseCode = QuantityConstant.DEFAULT_WAREHOUSE;
            Container container = containerService.getContainerByCode(containerCode, warehouseCode);
            String locationCode = container.getLocationCode();
            String materialCode = null;
            LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
            inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode)
                    .eq(InventoryDetail::getTaskQty, 0);
            List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
            if (inventoryDetailList != null && inventoryDetailList.size() > 0) {
                InventoryDetail inventoryDetail = inventoryDetailList.get(0);
                materialCode = inventoryDetail.getMaterialCode();
            } else {
                return AjaxResult.error("没有找到库存");
            }

            ajaxResult = shipmentTaskService.createWholeShipmentTask(containerCode, locationCode, materialCode,
                    warehouseCode, stationCode);
            if (!ajaxResult.hasErr()) {
                Integer taskId = (Integer) ajaxResult.getData();
                TaskHeader taskHeader = taskHeaderService.getById(taskId);
                if (taskHeader != null) {
//                    taskHeader.setTaskIndex(taskIndex);
                }
                taskHeaderService.updateById(taskHeader);
                ajaxResult.setData("P1001");
            }
        }
        return ajaxResult;
    }

}