TvControllerV1.java 7.48 KB
package com.huaheng.api.tv.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.acs.domain.AgvTaskCS;
import com.huaheng.api.acs.service.AgvTaskCSService;
import com.huaheng.api.tv.domain.TvForJLKTaskResponse;
import com.huaheng.api.tv.domain.TvRequstDomain;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.*;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.task.TaskDomain;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
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 com.huaheng.pc.task.taskHeader.service.TaskHeaderTvService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * @ClassName TVController
 * @Description TODO
 * @Author Administrator
 * @Date 2020/2/2217:16
 */
@RestController
@RequestMapping("/api/TV")
@Api(tags = {"TV"}, description = "TV接口")
public class TvControllerV1 extends BaseController {


    @Resource
    private MaterialService materialService;

    @Resource
    private TaskHeaderTvService taskHeaderTvService;

    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private ContainerService containerService;
    @Resource
    private AgvTaskCSService agvTaskCSService;



    @PostMapping("/gettvView")
    public AjaxResult<List<TaskDomain>> getTvView(String port){

        List<TaskDomain> taskDomainList = new ArrayList<>();

        //port多个站台用,分隔,查出所有头表
        List<TaskHeader> taskList = new ArrayList<>();
        for(String p : port.split(",")) {
            List<TaskHeader> tmpTaskList = taskHeaderTvService.getTaskByTvPort(p);
            taskList.addAll(tmpTaskList);
        }

        for(TaskHeader task : taskList){
            TaskDomain taskDomain = new TaskDomain();


            List<TaskDetail> taskDetails = taskDetailService.findByTaskId(task.getId());

            taskDomain.setTaskHeader(task);
            checkSpec(taskDetails);
            taskDomain.setTaskDetails(taskDetails);
            taskDomainList.add(taskDomain);
        }

        taskDomainList.sort(new Comparator<TaskDomain>() {
            @Override
            public int compare(TaskDomain o1, TaskDomain o2) {
                TaskHeader task1 = o1.getTaskHeader();
                TaskHeader task2 = o2.getTaskHeader();
                int ret = task2.getStatus() - task1.getStatus();
                if(ret == 0){
                    ret =  (int) (task2.getLastUpdated().getTime() - task1.getLastUpdated().getTime());
                }
                return ret;
            }
        });
        return AjaxResult.success(taskDomainList);
    }

    /**
     * 查检任务明细中是否有规格型号,没有的话主动查一下
     * @param taskDetails
     */
    public void checkSpec(List<TaskDetail> taskDetails){
        try {
            for (TaskDetail detail : taskDetails) {
                if (StringUtils.isEmpty(detail.getMaterialSpec())) {
                    Material material = materialService.getMaterialByCode(detail.getMaterialCode());
                    detail.setMaterialSpec(material.getSpec());
                }
            }
        }catch (Exception e){

        }
    }

    @PostMapping("/getStatusByContainer")
    public AjaxResult getStatusByContainer(String containerCode,String warehouseCode){
        Container container=containerService.getContainerByCode(containerCode,warehouseCode);
        if(container==null){
            return AjaxResult.error("未找到对应的容器");
        }
        return AjaxResult.success().setData(container.getStatus());
    }

    /**
     * 用仓库,库区查询该库区当前立库任务
     * @return
     */
    @PostMapping("/taskNow")
    public AjaxResult taskNow(@RequestBody TvRequstDomain domain){
        if(StringUtils.isEmpty(domain.getZoneCode())||StringUtils.isEmpty(domain.getWarehouseCode())){
            return AjaxResult.error("传参:库区zoneCode或仓库warehouseCode为空");
        }
        String zoneCode=domain.getZoneCode();
        String warehouseCode=domain.getWarehouseCode();
        LambdaQueryWrapper<TaskHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(TaskHeader::getZoneCode, zoneCode);
        lambdaQueryWrapper.eq(TaskHeader::getWarehouseCode,warehouseCode);
        lambdaQueryWrapper.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
        lambdaQueryWrapper.ne(TaskHeader::getTaskType,QuantityConstant.TASK_TYPE_OVER_STATION);
        lambdaQueryWrapper.orderByDesc(TaskHeader::getStatus);
        List<TaskHeader> list= taskHeaderTvService.list(lambdaQueryWrapper);
        List<TvForJLKTaskResponse> resultlist=new ArrayList<>();
        for(TaskHeader task:list){
            TvForJLKTaskResponse  taskResponse=new TvForJLKTaskResponse();
            taskResponse.setId(task.getId());
            taskResponse.setPort(task.getPort());
            taskResponse.setToLocation(task.getToLocation());
            taskResponse.setFromLocation(task.getFromLocation());
            taskResponse.setContainerCode(task.getContainerCode());
            taskResponse.setTaskType(TaskTypeEnum.getTaskTypeCode(task.getTaskType()));
            taskResponse.setStatusStr(TaskStatusEnum.getTaskStatusCode(task.getStatus()));
            resultlist.add(taskResponse);
        }
        return AjaxResult.success().setData(resultlist);
    }
    /**
     * 用仓库,库区查询该库区当前立库任务
     * @return
     */
    @PostMapping("/agvTaskNow")
    public AjaxResult agvTaskNow(@RequestBody TvRequstDomain domain){
        if(StringUtils.isEmpty(domain.getZoneCode())||StringUtils.isEmpty(domain.getWarehouseCode())){
            return AjaxResult.error("传参:库区zoneCode或仓库warehouseCode为空");
        }
        String zoneCode=domain.getZoneCode();
        String warehouseCode=domain.getWarehouseCode();
        LambdaQueryWrapper<AgvTaskCS> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(AgvTaskCS::getZoneCode, zoneCode);
        lambdaQueryWrapper.eq(AgvTaskCS::getWarehouseCode,warehouseCode);
        lambdaQueryWrapper.lt(AgvTaskCS::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
        lambdaQueryWrapper.orderByDesc(AgvTaskCS::getStatus);
        List<AgvTaskCS> list= agvTaskCSService.list(lambdaQueryWrapper);
        List<TvForJLKTaskResponse> resultlist=new ArrayList<>();
        for(AgvTaskCS task:list){
            TvForJLKTaskResponse  taskResponse=new TvForJLKTaskResponse();
            taskResponse.setId(task.getId());
            taskResponse.setFromPort(task.getFromPort());
            taskResponse.setToPort(task.getToPort());
            taskResponse.setContainerCode(task.getContainerCode());
            taskResponse.setStatusStr(TaskStatusAgvEnum.getTaskStatusCode(task.getStatus()));
            resultlist.add(taskResponse);
        }
        return AjaxResult.success().setData(resultlist);
    }
}