ZarshAddService.java 5.34 KB
package com.huaheng.pc.sap.service;

import javax.annotation.Resource;

import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.task.agvTask.domain.AgvTask;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.sap.domain.Zarsh;
import com.huaheng.pc.sap.mapper.ZarshMapper;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;

/**
 * Created by Enzo Cotter on 2022/5/11.
 * @author zhouhong
 */
@Service
public class ZarshAddService extends ServiceImpl<ZarshMapper, Zarsh> {

    @Resource
    private StationService stationService;
    @Resource
    private LocationService locationService;
    @Resource
    private TaskDetailService taskDetailService;
    @Resource
    private WorkTaskService workTaskService;
    @Resource
    private ContainerService containerService;
    @Resource
    private TaskHeaderService taskHeaderService;


    // 创建站点到站点任务
    public void createMoveTask(String containerCode, String zoneCode, String formPort, String toPort, String uniqueId) {
        if (StringUtils.isEmpty(formPort)) {
            throw new ServiceException("未找到起点站台");
        }
        if (StringUtils.isEmpty(toPort)) {
            throw new ServiceException("未找到终点站台");
        }
        if (zoneCode.equals("E") || zoneCode.equals("D") || zoneCode.equals("F")) {
        } else {
            throw new ServiceException("不支持此任务类型");
        }
        Container container=containerService.getContainerByCode(containerCode, QuantityConstant.WAREHOUSECODE);
        if(container==null){
            throw new ServiceException("托盘号不存在");
        }
        TaskHeader task = taskHeaderService.checkTaskByContainerCode(containerCode);
        if (task != null) {
            if (task.getInternalTaskType().intValue() == 100) {
                throw new ServiceException("该容器已存在未完成的入库任务,请不要重复下发" + containerCode);
            } else if (task.getInternalTaskType().intValue() == 200) {
                throw new ServiceException(
                        "该容器已存在未完成的出库任务,出库任务未完成,请到WCS中未完成任务查看是否有改任务,任务状态是否是响应接出站台请求,如果是直接手动强制完成该任务即可恢复正常,同时告知电气或WCS;" + containerCode);
            } else {
                throw new ServiceException("该容器已存在未完成的任务" + containerCode);
            }

        }
        AgvTask agvTask = taskHeaderService.checkAgvTaskByContainerCode(containerCode);
        if (agvTask != null) {
            throw new ServiceException("有货入库,该容器已存在未完成的agv任务,请不要重复下发" + containerCode);
        }
        LambdaQueryWrapper<Station> lambdaQuery_m_from = Wrappers.lambdaQuery();
        lambdaQuery_m_from.eq(Station::getByName, formPort);
        Station mfromStation = stationService.getOne(lambdaQuery_m_from);
        if (mfromStation == null) {
            throw new ServiceException(formPort + "站台异常,未找到站台");
        }
        LambdaQueryWrapper<Station> lambdaQuery_m_to = Wrappers.lambdaQuery();
        lambdaQuery_m_to.eq(Station::getByName, toPort);
        Station mtoStation = stationService.getOne(lambdaQuery_m_to);
        if (mfromStation == null) {
            throw new ServiceException(formPort + "站台异常,未找到站台");
        }
        Integer priority=mfromStation.getPriority();


        String fromArea = mfromStation.getAreaByWcs();
        String toArea = mtoStation.getAreaByWcs();
        // 验证区域
//        checkAreaByWcs(fromArea, toArea);
        AjaxResult stationToStaion =
            workTaskService.createStationToStation(containerCode, mfromStation.getCode(), mtoStation.getCode(), mfromStation.getZoneCode(), mtoStation.getCode(), uniqueId,priority);
    }

    public void createdReceiptCrossZone() {

    }

    // 验证区域
    public void checkAreaByWcs(String fromArea, String toArea) {
        if (StringUtils.isNotEmpty(fromArea) && StringUtils.isNotEmpty(toArea)) {
            if (fromArea.equals("A") && toArea.equals("C")) {
                throw new ServiceException(fromArea + ":" + toArea + ",起点站台或库位和终点站台或库位不能跨堆垛机区域");
            } else if (fromArea.equals("C") && toArea.equals("A")) {
                throw new ServiceException(fromArea + ":" + toArea + ",起点站台或库位和终点站台或库位不能跨堆垛机区域");
            }
        }
    }
}