AgvTaskController.java 5.63 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.common.constant.QuantityConstant;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
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 io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

@Controller
@RequestMapping("/agv")
public class AgvTaskController extends BaseController {

    @Resource
    private AcsService acsService;
    @Resource
    private ContainerService containerService;
    @Resource
    private ContainerTypeService containerTypeService;
    @ApiOperation(value = "AGV创建任务", httpMethod = "POST")
    @PostMapping("/createAGVTask")
    @ResponseBody
    public AjaxResult createAGVTask (@RequestBody AgvTask agvTask) {
        return acsService.createAGVTask(agvTask);
    }

    @Log(title = "任务-任务管理", operating = "下发AGV任务", action = BusinessType.UPDATE)
    @PostMapping( "/execute")
    @ResponseBody
    public AjaxResult execute(String taskId)
    {
        if (StringUtils.isEmpty(taskId)){
            return AjaxResult.error("taskId不能为空");
        }
        AjaxResult<AgvTask> ajaxResult = acsService.sendTaskToAGV(Convert.toIntArray(taskId));
        return ajaxResult;
    }

    @Log(title = "任务-任务管理", operating = "取消AGV任务", action = BusinessType.DELETE)
    @PostMapping( "/cancelAGVTask")
    @ResponseBody
    public AjaxResult cancelAGVTask(String taskId)
    {
        if (StringUtils.isEmpty(taskId)) {
            return AjaxResult.error("taskId不能为空");
        }
        Integer[] idList = Convert.toIntArray(taskId);
        for (int id : idList) {
            AgvTask agvTask = acsService.getById(id);
            if(agvTask.getStatus().intValue()  <= QuantityConstant.TASK_STATUS_BUILD) {
                continue;
            }
            String containerCode = agvTask.getContainerCode();
            if (StringUtils.isEmpty(containerCode)) {
                return AjaxResult.error("空托盘");
            }
            Container container = containerService.getContainerByCode(
                    containerCode, agvTask.getWarehouseCode());
            LambdaQueryWrapper<ContainerType> containerTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
            containerTypeLambdaQueryWrapper.eq(ContainerType::getCode, container.getContainerType());
            ContainerType containerType = containerTypeService.getContainerTypeByCode(
                    container.getContainerType(), container.getWarehouseCode());
            AjaxResult ajaxResult = acsService.cancelTask(id,
                    agvTask.getWarehouseCode(), containerType.getArea());
            if (ajaxResult.hasErr()) {
                return ajaxResult;
            }
        }
        return acsService.cancelAGVTask(Convert.toIntArray(taskId));
    }

    @Log(title = "任务-任务管理", operating = "下发AGV任务", action = BusinessType.DELETE)
    @PostMapping( "/updateAGVTask")
    @ResponseBody
    public AjaxResult updateAGVTask(String taskId,Integer priority)
    {
        if (StringUtils.isEmpty(taskId)) {
        return AjaxResult.error("taskId不能为空");
        }
        Integer id = Integer.valueOf(taskId);
        AgvTask agvTask = acsService.getById(id);
        if(agvTask.getStatus().intValue()  > QuantityConstant.TASK_STATUS_BUILD) {
            String containerCode = agvTask.getContainerCode();
            if (StringUtils.isEmpty(containerCode)) {
                return AjaxResult.error("空托盘");
            }
            Container container = containerService.getContainerByCode(
                    containerCode, agvTask.getWarehouseCode());
            LambdaQueryWrapper<ContainerType> containerTypeLambdaQueryWrapper = Wrappers.lambdaQuery();
            containerTypeLambdaQueryWrapper.eq(ContainerType::getCode, container.getContainerType());
            ContainerType containerType = containerTypeService.getContainerTypeByCode(
                    container.getContainerType(), container.getWarehouseCode());
            AjaxResult ajaxResult = acsService.updateTask(id, agvTask.getWarehouseCode(), priority);
            if (ajaxResult.hasErr()) {
                return ajaxResult;
            }
        }
        return acsService.updateAGVTask(taskId,priority);

    }

    @Log(title = "任务-任务管理", operating = "更新AGV点位信息", action = BusinessType.UPDATE)
    @PostMapping( "/notifyAGVPort")
    @ResponseBody
    public AjaxResult notifyAGVPort(@RequestBody Map map)
    {
       AjaxResult ajaxResult=acsService.notifyAGVPort(map);
       return ajaxResult;
    }

    @Log(title = "任务-任务管理", operating = "AGV任务状态通知", action = BusinessType.UPDATE)
    @PostMapping( "/notifyAGVTask")
    @ResponseBody
    public AjaxResult notifyAGVTask(@RequestBody Map map)
    {
        AjaxResult ajaxResult=acsService.notifyAGVTask(map);
        return ajaxResult;
    }


}