VerifyController.java 11.9 KB
package com.huaheng.pc.tool.verify.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import com.huaheng.pc.tool.verify.domain.ContrastLocation;
import com.huaheng.pc.tool.verify.domain.ContrastTask;
import com.huaheng.pc.tool.verify.domain.LocationVerify;
import com.huaheng.pc.tool.verify.domain.TaskVerify;
import com.huaheng.pc.tool.verify.service.WcslocationService;
import com.huaheng.pc.tool.verify.service.WcstaskService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
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.List;

@Controller
@RequestMapping("/tool/verify")
public class VerifyController {

    @Resource
    private WcslocationService wcslocationService;
    @Resource
    private WcstaskService wcstaskService;
    @Resource
    private LocationService locationService;
    @Resource
    private TaskHeaderService taskService;

    private String prefix = "tool/verify";

    @GetMapping()
    public String verify(){
        return prefix + "/verify";
    }

    @GetMapping("/locationStatusList")
    @ResponseBody
    public AjaxResult locationStatusList() {
        LambdaQueryWrapper<ContrastLocation> wcsWrapper = Wrappers.lambdaQuery();

        wcsWrapper.eq(ContrastLocation::getStatus, "lock");

        List<Location> locations = locationService.remoteList("status");
        if (locations == null) {
            throw new ServiceException("调用库位服务失败");
        }
        List<ContrastLocation> contrastLocations = wcslocationService.list(wcsWrapper);
        if (contrastLocations == null) {
            throw new ServiceException("读取对照库失败");
        }

        ArrayList<LocationVerify> verifyLocations = new ArrayList<>();
        ArrayList<Location> removeWmsLocation = new ArrayList<>();
        ArrayList<ContrastLocation> removeWcsLocation = new ArrayList<>();

        for (Location location : locations) {
            for (ContrastLocation contrastLocation : contrastLocations) {
                if (location.getCode().equals(contrastLocation.getCode())) {
                    removeWmsLocation.add(location);
                    removeWcsLocation.add(contrastLocation);
                }
            }
        }
        if (removeWcsLocation.size() == contrastLocations.size() && removeWmsLocation.size() == locations.size()) {
            return AjaxResult.success("校验通过,数据匹配");
        } else {
            locations.removeAll(removeWmsLocation);
            contrastLocations.removeAll(removeWcsLocation);
            if (locations.size() != 0) {
                for (Location location : locations) {
                    LocationVerify locationVerify = new LocationVerify();
                    locationVerify.setLocalContain(location.getContainerCode());
                    locationVerify.setLocalLocation(location.getCode());
                    locationVerify.setLocalLocationStatus(location.getStatus());
                    locationVerify.setContrastLocationStatus("empty");
                    verifyLocations.add(locationVerify);
                }
            }
            if (contrastLocations.size() != 0) {
                for (ContrastLocation contrastLocation : contrastLocations) {
                    LocationVerify locationVerify = new LocationVerify();
                    locationVerify.setLocalContain(contrastLocation.getContainerCode());
                    locationVerify.setLocalLocation(contrastLocation.getCode());
                    locationVerify.setLocalLocationStatus("empty");
                    locationVerify.setContrastLocationStatus("lock");
                    verifyLocations.add(locationVerify);
                }
            }
//            if (verifyLocations.size()>1000){
//                return AjaxResult.success("校验不通过,不符的数据大于1000条,暂时不支持大数据量差的结果显示");
//            }
            return AjaxResult.success("校验不通过,有" + verifyLocations.size() + "条数据不符", verifyLocations);
        }
    }

    @GetMapping("/locationWithContainerList")
    @ResponseBody
    public AjaxResult locationWithContainerList() {
        LambdaQueryWrapper<ContrastLocation> wcsWrapper = Wrappers.lambdaQuery();
        wcsWrapper.isNotNull(ContrastLocation::getContainerCode)
                .ne(ContrastLocation::getContainerCode, "");
        List<Location> locations = locationService.remoteList("container");
        List<ContrastLocation> contrastLocations = wcslocationService.list(wcsWrapper);

        if (locations == null) {
            throw new ServiceException("调用库位服务失败");
        }
        if (contrastLocations == null) {
            throw new ServiceException("读取对照库失败");
        }

        ArrayList<LocationVerify> verifyLocations = new ArrayList<>();
        ArrayList<Location> removeWmsLocation = new ArrayList<>();
        ArrayList<ContrastLocation> removeWcsLocation = new ArrayList<>();

        for (Location location : locations) {
            for (ContrastLocation contrastLocation : contrastLocations) {
                if (location.getCode().equals(contrastLocation.getCode())) {
                    if (!location.getContainerCode().equals(contrastLocation.getContainerCode())) {
                        LocationVerify locationVerify = new LocationVerify();
                        locationVerify.setLocalLocation(location.getCode());
                        locationVerify.setContrastLocation(contrastLocation.getCode());
                        locationVerify.setLocalContain(location.getContainerCode());
                        locationVerify.setContrastLocation(location.getContainerCode());
                        verifyLocations.add(locationVerify);
                    }
                    removeWmsLocation.add(location);
                    removeWcsLocation.add(contrastLocation);
                }
            }
        }
        if (removeWcsLocation.size() == contrastLocations.size() && removeWmsLocation.size() == locations.size() &&
                verifyLocations.size() == 0) {
            return AjaxResult.success("校验通过,数据匹配");
        } else {
            locations.removeAll(removeWmsLocation);
            contrastLocations.removeAll(removeWcsLocation);
            if (locations.size() != 0) {
                for (Location location : locations) {
                    LocationVerify locationVerify = new LocationVerify();
                    locationVerify.setLocalContain(location.getContainerCode());
                    locationVerify.setLocalLocation(location.getCode());
                    locationVerify.setContrastLocation(location.getCode());
                    locationVerify.setContrastContain("");
                    verifyLocations.add(locationVerify);
                }
            }
            if (contrastLocations.size() != 0) {
                for (ContrastLocation contrastLocation : contrastLocations) {
                    LocationVerify locationVerify = new LocationVerify();
                    locationVerify.setLocalContain("");
                    locationVerify.setLocalLocation(contrastLocation.getCode());
                    locationVerify.setContrastContain(contrastLocation.getContainerCode());
                    locationVerify.setContrastLocation(contrastLocation.getCode());
                    verifyLocations.add(locationVerify);
                }
            }
//            if (verifyLocations.size()>1000){
//                return AjaxResult.success("校验不通过,不符的数据大于1000条,暂时不支持大数据量差的结果显示");
//            }
            return AjaxResult.success("校验不通过,有" + verifyLocations.size() + "条数据不符", verifyLocations);
        }
    }

    @GetMapping("/taskStatuslist")
    @ResponseBody
    public AjaxResult taskStatuslist() {
        LambdaQueryWrapper<ContrastTask> wcsTaskWrapper = Wrappers.lambdaQuery();
        wcsTaskWrapper.lt(ContrastTask::getTaskStatus, 100);
        List<TaskHeader> taskHeaders = taskService.remoteList();
        List<ContrastTask> contrastTasks = wcstaskService.list(wcsTaskWrapper);

        if (taskHeaders == null) {
            return AjaxResult.success("本地任务获取失败");
        }

        if (contrastTasks == null) {
            return AjaxResult.success("对照任务获取失败");
        }

        ArrayList<TaskVerify> verifyTasks = new ArrayList<>();
        ArrayList<TaskHeader> removeWmsTask = new ArrayList<>();
        ArrayList<ContrastTask> removeWcsTask = new ArrayList<>();

        for (TaskHeader taskHeader : taskHeaders) {
            for (ContrastTask contrastTask : contrastTasks) {
                if (contrastTask.getRemoteTaskNo() == null) {
                    throw new ServiceException("对照任务id为" + contrastTask.getId() + "的任务上游任务号为空,无法处理");
                }
                if (taskHeader.getId().equals(Integer.valueOf(contrastTask.getRemoteTaskNo()))) {
                    taskHeader.setContrastTaskId(contrastTask.getId());
                    removeWmsTask.add(taskHeader);
                    removeWcsTask.add(contrastTask);
                }
            }
        }
        if (taskHeaders.size() == 0) {
            for (ContrastTask contrastTask : contrastTasks) {
                if (contrastTask.getRemoteTaskNo() == null) {
                    throw new ServiceException("对照任务id为" + contrastTask.getId() + "的任务上游任务号为空,无法处理");
                }
            }
        }
        if (removeWcsTask.size() == contrastTasks.size() && removeWmsTask.size() == taskHeaders.size()) {
            return AjaxResult.success("校验通过,数据匹配");
        } else {
            taskHeaders.removeAll(removeWmsTask);
            contrastTasks.removeAll(removeWcsTask);
            if (taskHeaders.size() != 0) {
                for (TaskHeader taskHeader : taskHeaders) {
                    TaskVerify taskVerify = new TaskVerify();
                    taskVerify.setLocalId(taskHeader.getId());
                    taskVerify.setContrastId(taskHeader.getContrastTaskId());
                    taskVerify.setLocalContainerCode(taskHeader.getContainerCode());
                    taskVerify.setLocalTaskStatus(taskHeader.getStatus());
                    taskVerify.setContrastTaskStatus(100);
                    verifyTasks.add(taskVerify);
                }
            }
            if (contrastTasks.size() != 0) {
                for (ContrastTask contrastTask : contrastTasks) {
                    TaskVerify taskVerify = new TaskVerify();
                    taskVerify.setLocalId(Integer.valueOf(contrastTask.getRemoteTaskNo()));
                    taskVerify.setContrastId(contrastTask.getId());
                    taskVerify.setLocalContainerCode(contrastTask.getContainerCode());
                    taskVerify.setLocalTaskStatus(100);
                    taskVerify.setContrastTaskStatus((int) contrastTask.getTaskStatus());
                    verifyTasks.add(taskVerify);
                }
            }
//            if (verifyTasks.size()>1000){
//                return AjaxResult.success("校验不通过,不符的数据大于1000条,暂时不支持大数据量差的结果显示");
//            }
            return AjaxResult.success("校验不通过,有" + verifyTasks.size() + "条数据不符", verifyTasks);
        }
    }
}