#
luxiaotao1123
2024-10-23 7a68bbe9a032df8c54b2263be097002e01383bce
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/service/impl/RouteServiceImpl.java
@@ -1,9 +1,9 @@
package com.zy.acs.manager.manager.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.acs.manager.common.exception.BusinessException;
import com.zy.acs.common.utils.GsonUtils;
import com.zy.acs.framework.exception.CoolException;
import com.zy.acs.manager.manager.entity.Code;
import com.zy.acs.manager.manager.entity.Route;
import com.zy.acs.manager.manager.mapper.RouteMapper;
@@ -12,9 +12,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
@Service("routeService")
public class RouteServiceImpl extends ServiceImpl<RouteMapper, Route> implements RouteService {
@@ -23,17 +21,31 @@
    private CodeService codeService;
    @Override
    public Route createRouteByCode(Code code0, Code code1) {
        Route route = this.findByCodeOfBoth(code0.getId(), code1.getId());
    public Route createRouteByCode(Code startCode, Code endCode) {
        return createRouteByCode(startCode, endCode, 0, null);
    }
    @Override
    public Route createRouteByCode(Code startCode, Code endCode, Integer direction, Long userId) {
        if (startCode.getData().equals(endCode.getData())) {
            return null;
        }
        Route route = this.findByCodeOfBoth(startCode.getId(), endCode.getId());
        direction = Optional.ofNullable(direction).orElse(0);
        if (null == route) {
            Date now = new Date();
            route = new Route();
            route.setUuid(code0.getData()+"-"+code1.getData());
            route.setStartCode(code0.getId());
            route.setEndCode(code1.getId());
            route.setDirection(0);
            route.setCodeArr(JSON.toJSONString(Arrays.asList(code0.getId(), code1.getId())));
            route.setUuid(startCode.getData() + "-" + endCode.getData());
            route.setStartCode(startCode.getId());
            route.setEndCode(endCode.getId());
            route.setDirection(direction);
            route.setCodeArr(GsonUtils.toJson(Arrays.asList(startCode.getId(), endCode.getId())));
            route.setCreateBy(userId);
            route.setCreateTime(now);
            route.setUpdateBy(userId);
            route.setUpdateTime(now);
            if (!this.save(route)) {
                throw new BusinessException(route.getCodeArr()+" save fail![Route]");
                throw new CoolException(route.getCodeArr()+" save fail![Route]");
            }
        }
        return route;
@@ -54,10 +66,10 @@
    }
    @Override
    public Route findByCodeOfBoth(Long code0, Long code1) {
        Route route = getOne(new LambdaQueryWrapper<Route>().eq(Route::getStartCode, code0).eq(Route::getEndCode, code1).eq(Route::getStatus, 1));
    public Route findByCodeOfBoth(Long startCode, Long endCode) {
        Route route = getOne(new LambdaQueryWrapper<Route>().eq(Route::getStartCode, startCode).eq(Route::getEndCode, endCode).eq(Route::getStatus, 1));
        if (null == route) {
            route = getOne(new LambdaQueryWrapper<Route>().eq(Route::getEndCode, code0).eq(Route::getStartCode, code1).eq(Route::getStatus, 1));
            route = getOne(new LambdaQueryWrapper<Route>().eq(Route::getEndCode, startCode).eq(Route::getStartCode, endCode).eq(Route::getStatus, 1));
        }
        return route;
    }