#
vincentlu
2025-05-13 ebd2f4397a92c6a5096de1b86d59154363344720
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/BusServiceImpl.java
@@ -3,22 +3,29 @@
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.framework.common.Cools;
import com.zy.acs.framework.exception.CoolException;
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.entity.Task;
import com.zy.acs.manager.manager.enums.BusStsType;
import com.zy.acs.manager.manager.enums.TaskStsType;
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.List;
import java.util.*;
@Slf4j
@Service("busService")
public class BusServiceImpl extends ServiceImpl<BusMapper, Bus> implements BusService {
    @Autowired
    private TaskService taskService;
    @Override
    public Bus selectByUuid(String uuid) {
@@ -33,23 +40,56 @@
        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.getOriLoc())) {
                    return "OriSta and OriLoc cannot exist at the same time!";
                }
                if (Cools.isEmpty(dto.getDestSta()) && Cools.isEmpty(dto.getDestLoc())) {
                    return "Destination cannot be empty!";
                }
            }
            if (!Cools.isEmpty(dto.getDestSta())) {
                if (!Cools.isEmpty(dto.getDestLoc())) {
                    return "DestSta and DestLoc cannot exist at the same time!";
            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());
            }
        }
@@ -80,4 +120,32 @@
        return this.list(wrapper);
    }
    @Override
    public void checkoutComplete(Long busId) {
        if (null == busId) {
            return;
        }
        int taskTotalCount = taskService.count(new LambdaQueryWrapper<Task>().eq(Task::getBusId, busId));
        List<Task> actualDoneTasks = taskService.list(new LambdaQueryWrapper<Task>()
                .eq(Task::getBusId, busId)
                .in(Task::getTaskSts
                        , TaskStsType.COMPLETE.val()
                        , TaskStsType.CANCEL.val()
                )
        );
        if (taskTotalCount == actualDoneTasks.size()) {
            Bus bus = this.getById(busId);
            long cancelTasksCount = actualDoneTasks.stream().filter(task -> TaskStsType.CANCEL.val() == task.getTaskSts()).count();
            if (cancelTasksCount == taskTotalCount) {
                bus.setBusSts(BusStsType.CANCEL.val());
            } else {
                bus.setBusSts(BusStsType.FINISH.val());
            }
            bus.setUpdateTime(new Date());
            if (!this.updateById(bus)) {
                throw new CoolException("Bus[{" + busId + "}] failed to update");
            }
        }
    }
}