| | |
| | | |
| | | 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) { |
| | | 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 |
| | |
| | | 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"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |