VerifyController.java 9.61 KB
package com.huaheng.tool.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.core.web.domain.AjaxResult;
import com.huaheng.config.api.RemoteLocationService;
import com.huaheng.config.api.domain.Location;
import com.huaheng.task.api.RemoteTaskService;
import com.huaheng.task.api.domain.TaskHeader;
import com.huaheng.tool.domain.LocationVerify;
import com.huaheng.tool.domain.TaskVerify;
import com.huaheng.tool.domain.Wcslocation;
import com.huaheng.tool.domain.Wcstask;
import com.huaheng.tool.service.WcslocationService;
import com.huaheng.tool.service.WcstaskService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/verify")
public class VerifyController {

    @Resource
    private WcslocationService wcslocationService;
    @Resource
    private WcstaskService wcstaskService;
    @Resource
    private RemoteLocationService locationService;
    @Resource
    private RemoteTaskService taskService;


    @GetMapping("/locationStatusList")
    public AjaxResult locationStatusList() {
        LambdaQueryWrapper<Wcslocation> wcsWrapper = Wrappers.lambdaQuery();
        LambdaQueryWrapper<Location> wmsWrapper = Wrappers.lambdaQuery();
        wcsWrapper.eq(Wcslocation::getStatus, "lock");
        wmsWrapper.eq(Location::getStatus, 10);
        List<Location> locations = locationService.remoteList(wmsWrapper);
        List<Wcslocation> wcslocations = wcslocationService.list(wcsWrapper);

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

        for (Location location : locations) {
            for (Wcslocation wcslocation : wcslocations) {
                if (location.getCode().equals(wcslocation.getCode())) {
                    removeWmsLocation.add(location);
                    removeWcsLocation.add(wcslocation);
                }
            }
        }
        if (removeWcsLocation.size() == wcslocations.size() && removeWmsLocation.size() == locations.size()) {
            return AjaxResult.success("校验通过,数据匹配");
        } else {
            locations.removeAll(removeWmsLocation);
            wcslocations.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 (wcslocations.size() != 0) {
                    for (Wcslocation wcslocation : wcslocations) {
                        LocationVerify locationVerify = new LocationVerify();
                        locationVerify.setLocalContain(wcslocation.getContainerCode());
                        locationVerify.setLocalLocation(wcslocation.getCode());
                        locationVerify.setLocalLocationStatus("empty");
                        locationVerify.setContrastLocationStatus("lock");
                        verifyLocations.add(locationVerify);
                    }
                }
            }
            return AjaxResult.success("校验不通过,有"+verifyLocations.size()+"条数据不符",verifyLocations);
        }
    }

    @GetMapping("locationWithContainerList")
    public AjaxResult locationWithContainerList() {
        LambdaQueryWrapper<Wcslocation> wcsWrapper = Wrappers.lambdaQuery();
        LambdaQueryWrapper<Location> wmsWrapper = Wrappers.lambdaQuery();
        wcsWrapper.isNotNull(Wcslocation::getContainerCode);
        wmsWrapper.isNotNull(Location::getContainerCode);
        List<Location> locations = locationService.remoteList(wmsWrapper);
        List<Wcslocation> wcslocations = wcslocationService.list(wcsWrapper);

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

        for (Location location : locations) {
            for (Wcslocation wcslocation : wcslocations) {
                if (location.getCode().equals(wcslocation.getCode())) {
                    if (!location.getContainerCode().equals(wcslocation.getContainerCode())) {
                        LocationVerify locationVerify = new LocationVerify();
                        locationVerify.setLocalLocation(location.getCode());
                        locationVerify.setContrastLocation(wcslocation.getCode());
                        locationVerify.setLocalContain(location.getContainerCode());
                        locationVerify.setContrastLocation(location.getContainerCode());
                        verifyLocations.add(locationVerify);
                    }
                    removeWmsLocation.add(location);
                    removeWcsLocation.add(wcslocation);
                }
            }
        }
        if (removeWcsLocation.size() == wcslocations.size() && removeWmsLocation.size() == locations.size() &&
                verifyLocations.size() == 0) {
            return AjaxResult.success("校验通过,数据匹配");
        } else {
            locations.removeAll(removeWmsLocation);
            wcslocations.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 (wcslocations.size() != 0) {
                    for (Wcslocation wcslocation : wcslocations) {
                        LocationVerify locationVerify = new LocationVerify();
                        locationVerify.setLocalContain("");
                        locationVerify.setLocalLocation(wcslocation.getCode());
                        locationVerify.setContrastContain(wcslocation.getContainerCode());
                        locationVerify.setContrastLocation(wcslocation.getCode());
                        verifyLocations.add(locationVerify);
                    }
                }
            }
            return AjaxResult.success("校验不通过,有"+verifyLocations.size()+"条数据不符",verifyLocations);
        }
    }

    @GetMapping("/taskStatuslist")
    public AjaxResult taskStatuslist(){
        LambdaQueryWrapper<TaskHeader> localTaskWrapper = Wrappers.lambdaQuery();
        LambdaQueryWrapper<Wcstask> wcsTaskWrapper = Wrappers.lambdaQuery();
        localTaskWrapper.gt(TaskHeader::getStatus,10)
                .lt(TaskHeader::getStatus,100);
        wcsTaskWrapper.lt(Wcstask::getTaskStatus,100);
        List<TaskHeader> taskHeaders = taskService.remoteList(localTaskWrapper);
        List<Wcstask> wcstasks = wcstaskService.list(wcsTaskWrapper);

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

        for (TaskHeader taskHeader : taskHeaders) {
            for (Wcstask wcstask : wcstasks) {
                if (taskHeader.getId().equals(Integer.valueOf(wcstask.getRemoteTaskNo()))) {
                    removeWmsTask.add(taskHeader);
                    removeWcsTask.add(wcstask);
                }
            }
        }
        if (removeWcsTask.size() == wcstasks.size() && removeWmsTask.size() == taskHeaders.size()) {
            return AjaxResult.success("校验通过,数据匹配");
        } else {
            taskHeaders.removeAll(removeWmsTask);
            wcstasks.removeAll(removeWcsTask);
            if (taskHeaders.size() != 0) {
                for (TaskHeader taskHeader : taskHeaders) {
                    TaskVerify taskVerify = new TaskVerify();
                    taskVerify.setLocalId(taskHeader.getId());
                    taskVerify.setLocalContainerCode(taskHeader.getContainerCode());
                    taskVerify.setLocalTaskStatus(taskHeader.getStatus());
                    taskVerify.setContrastTaskStatus(100);
                    verifyTasks.add(taskVerify);
                }
                if (wcstasks.size() != 0) {
                    for (Wcstask wcstask : wcstasks) {
                        TaskVerify taskVerify = new TaskVerify();
                        taskVerify.setLocalId(Integer.valueOf(wcstask.getRemoteTaskNo()));
                        taskVerify.setLocalContainerCode(wcstask.getContainerCode());
                        taskVerify.setLocalTaskStatus(100);
                        taskVerify.setContrastTaskStatus((int)wcstask.getTaskStatus());
                        verifyTasks.add(taskVerify);
                    }
                }
            }
            return AjaxResult.success("校验不通过,有"+verifyTasks.size()+"条数据不符",verifyTasks);
        }
    }
}