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

import com.huaheng.common.utils.StringUtils;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

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;



    @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());
    }
}