package com.zy.acs.manager.manager.service.impl; 
 | 
  
 | 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 
 | 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 
 | 
import com.zy.acs.framework.common.BaseRes; 
 | 
import com.zy.acs.manager.common.domain.TaskDto; 
 | 
import com.zy.acs.manager.manager.controller.param.OpenBusSubmitParam; 
 | 
import com.zy.acs.manager.manager.entity.Bus; 
 | 
import com.zy.acs.manager.manager.enums.BusStsType; 
 | 
import com.zy.acs.manager.manager.mapper.BusMapper; 
 | 
import com.zy.acs.manager.manager.service.BusService; 
 | 
import com.zy.acs.framework.common.Cools; 
 | 
import com.zy.acs.manager.manager.service.TaskService; 
 | 
import lombok.extern.slf4j.Slf4j; 
 | 
import org.springframework.beans.factory.annotation.Autowired; 
 | 
import org.springframework.stereotype.Service; 
 | 
  
 | 
import java.util.ArrayList; 
 | 
import java.util.HashSet; 
 | 
import java.util.List; 
 | 
import java.util.Set; 
 | 
  
 | 
@Slf4j 
 | 
@Service("busService") 
 | 
public class BusServiceImpl extends ServiceImpl<BusMapper, Bus> implements BusService { 
 | 
  
 | 
    @Autowired 
 | 
    private TaskService taskService; 
 | 
  
 | 
    @Override 
 | 
    public Bus selectByUuid(String uuid) { 
 | 
        return this.getOne(new LambdaQueryWrapper<Bus>().eq(Bus::getUuid, uuid)); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public String checkoutValid(OpenBusSubmitParam param) { 
 | 
        if (null == param) { 
 | 
            return BaseRes.PARAM; 
 | 
        } 
 | 
        if (Cools.isEmpty(param.getBatch())) { 
 | 
            return "Batch cannot be empty!"; 
 | 
        } 
 | 
        Set<String> oriStaNoSet = new HashSet<>(); 
 | 
        Set<String> oriLocNoSet = new HashSet<>(); 
 | 
        Set<String> destStaNoSet = new HashSet<>(); 
 | 
        Set<String> destLocNoSet = new HashSet<>(); 
 | 
        for (TaskDto dto : param.getTaskList()) { 
 | 
            if (!Cools.isEmpty(dto.getOriSta()) && !Cools.isEmpty(dto.getOriLoc())) { 
 | 
                return "OriSta and OriLoc cannot exist at the same time!"; 
 | 
            } 
 | 
            if (Cools.isEmpty(dto.getOriSta()) && Cools.isEmpty(dto.getOriLoc())) { 
 | 
                return "OriSta and OriLoc must have one!"; 
 | 
            } 
 | 
            if (!Cools.isEmpty(dto.getOriSta())) { 
 | 
                if (Cools.isEmpty(dto.getDestSta()) && Cools.isEmpty(dto.getDestLoc())) { 
 | 
                    return "Destination cannot be empty!"; 
 | 
                } 
 | 
            } 
 | 
            if (!Cools.isEmpty(dto.getOriLoc())) { 
 | 
                if (Cools.isEmpty(dto.getDestSta()) && Cools.isEmpty(dto.getDestLoc())) { 
 | 
                    return "Destination cannot be empty!"; 
 | 
                } 
 | 
                if (oriLocNoSet.contains(dto.getOriLoc())) { 
 | 
                    return "OriLoc cannot be repeated"; 
 | 
                } else { 
 | 
                    oriLocNoSet.add(dto.getOriLoc()); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            if (!Cools.isEmpty(dto.getDestSta()) && !Cools.isEmpty(dto.getDestLoc())) { 
 | 
                return "DestSta and DestLoc cannot exist at the same time!"; 
 | 
            } 
 | 
            if (Cools.isEmpty(dto.getDestSta()) && Cools.isEmpty(dto.getDestLoc())) { 
 | 
                return "DestSta and DestLoc must have one!"; 
 | 
            } 
 | 
            if (!Cools.isEmpty(dto.getDestSta())) { 
 | 
                if (Cools.isEmpty(dto.getOriSta()) && Cools.isEmpty(dto.getOriLoc())) { 
 | 
                    return "Origin cannot be empty!"; 
 | 
                } 
 | 
            } 
 | 
            if (!Cools.isEmpty(dto.getDestLoc())) { 
 | 
                if (Cools.isEmpty(dto.getOriSta()) && Cools.isEmpty(dto.getOriLoc())) { 
 | 
                    return "Origin cannot be empty!"; 
 | 
                } 
 | 
                if (destLocNoSet.contains(dto.getDestLoc())) { 
 | 
                    return "DestLoc cannot be repeated"; 
 | 
                } else { 
 | 
                    destLocNoSet.add(dto.getDestLoc()); 
 | 
                } 
 | 
            } 
 | 
            if (Cools.isEmpty(dto.getSeqNum())) { 
 | 
                dto.setSeqNum(taskService.generateSeqNum()); 
 | 
            } 
 | 
  
 | 
        } 
 | 
        return null; 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public List<Bus> selectBySts(BusStsType busStsType) { 
 | 
        return this.selectBySts(busStsType, null); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public List<Bus> selectInSts(BusStsType... busStsTypes) { 
 | 
        List<Long> params = new ArrayList<>(); 
 | 
        for (BusStsType busStsType : busStsTypes) { 
 | 
            params.add(busStsType.val()); 
 | 
        } 
 | 
        return this.list(new LambdaQueryWrapper<Bus>().in(Bus::getBusSts, params)); 
 | 
    } 
 | 
  
 | 
    @Override 
 | 
    public List<Bus> selectBySts(BusStsType busStsType, String memo) { 
 | 
        LambdaQueryWrapper<Bus> wrapper = new LambdaQueryWrapper<>(); 
 | 
        wrapper.eq(Bus::getBusSts, busStsType.val()); 
 | 
        if (!Cools.isEmpty(memo)) { 
 | 
            wrapper.eq(Bus::getMemo, memo); 
 | 
        } 
 | 
        return this.list(wrapper); 
 | 
    } 
 | 
  
 | 
} 
 |