fix: Route

This commit is contained in:
yanps
2023-12-07 14:27:09 +08:00
parent 64ae2fcf77
commit 69a7c4e256
7 changed files with 169 additions and 55 deletions

View File

@@ -40,19 +40,46 @@ public interface RouteLineService extends CommonService<RouteLine> {
*/
List<RouteLineDto> queryAll(RouteLineQueryParam query);
/**
* 根据id查询
* @param id
* @return
*/
RouteLine getById(String id);
/**
* 根据id查询
* @param id
* @return
*/
RouteLineDto findById(String id);
/**
* 插入一条新数据。
* @param resources
* @return
*/
int insert(RouteLineDto resources);
/**
* 根据id修改
* @param resources
* @return
*/
int updateById(RouteLineDto resources);
/**
* 根据id删除
* @param id
* @return
*/
int removeById(String id);
/**
* 批量删除
* @param ids
* @return
*/
int removeByIds(Set<String> ids);
/**
@@ -115,8 +142,8 @@ public interface RouteLineService extends CommonService<RouteLine> {
/**
* 根据编码,查询下一级的路由,即此设备目标的路由
*
* @param code
* @param plan_uuid
* @return
*/
JSONArray queryNextLine(String code, String plan_uuid);
@@ -150,23 +177,23 @@ public interface RouteLineService extends CommonService<RouteLine> {
/**
* 创建
*
* @param data /
* @param data
* @throws SQLException
*/
void create(Map data) throws SQLException;
/**
* 编辑
*
* @param dto /
* @param dto
* @throws SQLException
*/
void update(RouteLineDto dto) throws SQLException;
/**
* 多选删除
*
* @param ids /
* @param ids
* @throws SQLException
*/
void deleteAll(String[] ids) throws SQLException;
@@ -181,14 +208,16 @@ public interface RouteLineService extends CommonService<RouteLine> {
/**
* 启用或停用
*
* @param routeLineId
* @param ia_active 1 启用0 禁用
* @throws SQLException
*/
void enabled(String routeLineId, String ia_active) throws SQLException;
/**
* 更新通路情况
* 任意两台设备之间的通路情况
* @param route_plan_id
*/
void replaceAccess(String route_plan_id);
@@ -201,12 +230,36 @@ public interface RouteLineService extends CommonService<RouteLine> {
*/
boolean getReplaceAccess(String startDeviceCode, String endDeviceCode);
/**
* 重新加载通路
* @throws SQLException
*/
void reload() throws SQLException;
/**
* 检查是否存在通路
* @param startDevice
* @param nextDevice
* @param routecode
* @return
* @throws Exception
*/
boolean checkRouteLine(String startDevice, String nextDevice, String routecode) throws Exception;
/**
* 查询所有通路
* @return
*/
public Map<String, List> getRouteLines();
/**
* 根据起点设备编号查询所有目的地设备
*
* @param device_code
* @param next_device_code
* @param plan_code
* @return
*/
public List<RouteLineDto> getShortPathLines(String device_code, String next_device_code, String plan_code);
/**
@@ -227,8 +280,23 @@ public interface RouteLineService extends CommonService<RouteLine> {
*/
public List<RouteLineDto> getPathLinesByCode(String device_code, String plan_code);
/**
* 根据设备编号查询所有目的地设备
*
* @param device_code
* @param plan_code
* @return
*/
public List<RouteLineDto> getSuperiorShortPathLinesByCode(String device_code, String plan_code);
/**
* 根据设备编号终点设备路由查询所有目的地设备
*
* @param device_code
* @param next_device_code
* @param plan_code
* @return
*/
public JSONArray getActivePathLine(String device_code, String next_device_code, String plan_code);
/**

View File

@@ -38,19 +38,49 @@ public interface RouteLocService extends CommonService<RouteLoc> {
*/
List<RouteLocDto> queryAll(RouteLocQueryParam query);
/**
* 根据ID查询
*
* @param id ID
* @return RouteLoc
*/
RouteLoc getById(String id);
/**
* 根据ID查询
*
* @param id ID
* @return RouteLocDto
*/
RouteLocDto findById(String id);
/**
* 插入一条新数据
* 新数据
*
* @param resources /
* @return RouteLocDto
*/
int insert(RouteLocDto resources);
/**
* 编辑数据
*
* @param resources /
*/
int updateById(RouteLocDto resources);
/**
* 删除数据
*
* @param id ID
*/
int removeById(String id);
/**
* 批量删除数据
*
* @param ids ID集合
*/
int removeByIds(Set<String> ids);
/**

View File

@@ -39,19 +39,49 @@ public interface RoutePlanService extends CommonService<RoutePlan> {
*/
List<RoutePlanDto> queryAll(RoutePlanQueryParam query);
/**
* 根据ID查询
*
* @param id ID
* @return RoutePlan
*/
RoutePlan getById(String id);
/**
* 根据ID查询
*
* @param id ID
* @return RoutePlanDto
*/
RoutePlanDto findById(String id);
/**
* 插入一条新数据
* 新数据
*
* @param resources /
* @return RoutePlanDto
*/
int insert(RoutePlanDto resources);
/**
* 修改数据
*
* @param resources /
*/
int updateById(RoutePlanDto resources);
/**
* 删除数据
*
* @param id ID
*/
int removeById(String id);
/**
* 批量删除数据
*
* @param ids ID集合
*/
int removeByIds(Set<String> ids);
/**

View File

@@ -70,9 +70,10 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
Map<String, RoutePlanDto> routePlans = new HashMap();
Map<Integer, String> routeIndex = new HashMap();
Map<String, List> routeLines = new HashMap();
Map<String, Integer> deviceCoordinate = null;//用来确定设备在 路由二维数组中的坐标
Map<String, String>[][] routeChart = null;//路由二维数组
//用来确定设备在 路由二维数组中的坐标
Map<String, Integer> deviceCoordinate = null;
//路由二维数组
Map<String, String>[][] routeChart = null;
List<Map> routePlansList = new ArrayList<>();
// private final RedisUtils redisUtils;
private final RouteLineMapper routeLineMapper;
@@ -161,13 +162,6 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
return ConvertUtil.convertList(list, RouteLineDto.class);
}
// @Override
// public RouteLineDto findById(String line_uuid) {
// WQLObject wo = WQLObject.getWQLObject("acs_route_line");
// JSONObject json = wo.query("line_uuid ='" + line_uuid + "'").uniqueResult(0);
// final RouteLineDto obj = json.toJavaObject(RouteLineDto.class);
// return obj;
// }
@Override
public RouteLineDto findByCode(String code) {
@@ -180,17 +174,6 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
return ConvertUtil.convert(routeLine, RouteLineDto.class);
}
// @Override
// public JSONArray queryAll(String code, String plan_uuid) {
// JSONArray arr = WQLObject.getWQLObject("acs_route_line").query(" is_active= '1' and device_code = '" + code + "' and route_plan_id='" + plan_uuid + "'").getResultJSONArray(0);
// return arr;
// }
// @Override
// public JSONArray querySuperiorLine(String code, String plan_uuid) {
// JSONArray arr = WQLObject.getWQLObject("acs_route_line").query(" is_active= '1' and next_device_code = '" + code + "'and route_plan_id='" + plan_uuid + "'").getResultJSONArray(0);
// return arr;
// }
@Override
public JSONArray queryNextLine(String code, String plan_uuid) {
@@ -438,7 +421,8 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
JSONObject jo = (JSONObject) route.get(i);
String start = jo.getString("device_code");
String end = jo.getString("next_device_code");
if (ObjectUtil.isEmpty(map.get(start)) || ObjectUtil.isEmpty(map.get(end))) {//如果路由中的设备号在设备列表中找不到就跳过
//如果路由中的设备号在设备列表中找不到就跳过
if (ObjectUtil.isEmpty(map.get(start)) || ObjectUtil.isEmpty(map.get(end))) {
continue;
}
Integer s = Integer.valueOf(map.get(start));
@@ -478,9 +462,13 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
routePlansList = maps;
}
//floyd算法将所有设备之间的最短路线计算出来如果是null 则代表不通
/**
* floyd算法将所有设备之间的最短路线计算出来如果是null 则代表不通
* @param graph
*/
private static void floyd(Map[][] graph) {
for (int i = 0; i < graph.length; i++) {// floyd
// floyd
for (int i = 0; i < graph.length; i++) {
for (int j = 0; j < graph.length; j++) {
for (int k = 0; k < graph.length; k++) {
if (graph[j][i] != null && graph[i][k] != null && j != k) {
@@ -490,11 +478,14 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
String s2 = (String) graph[i][k].get("path");
String s3 = s2.substring(s2.indexOf("-"));
String end = s2.substring(s2.lastIndexOf(">") + 1);
if (graph[j][k] == null) {//最开始两点间不是直接通路,需要经过别的点
//最开始两点间不是直接通路,需要经过别的点
if (graph[j][k] == null) {
String device_code = s1.substring(0, s1.indexOf("-"));
HashMap<String, String> map = new HashMap<>();
map.put("device_code", device_code);//开始
map.put("next_device_code", end);//终点
//开始
map.put("device_code", device_code);
//终点
map.put("next_device_code", end);
map.put("weights", v1 + v2 + "");
map.put("type", (String) graph[j][i].get("type"));
map.put("route_plan_id", (String) graph[j][i].get("route_plan_id"));
@@ -679,11 +670,11 @@ public class RouteLineServiceImpl extends CommonServiceImpl<RouteLineMapper, Rou
}
public int getSize() {
public Integer getSize() {
return this.deviceAppService.findDeviceDriver(RouteableDeviceDriver.class).size();
}
public int getIndex(String device_code) {
public Integer getIndex(String device_code) {
Iterator var2 = this.routeIndex.keySet().iterator();
Integer i;

View File

@@ -41,7 +41,6 @@ import java.util.*;
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class RouteLocServiceImpl extends CommonServiceImpl<RouteLocMapper, RouteLoc> implements RouteLocService {
// private final RedisUtils redisUtils;
private final RouteLocMapper routeLocMapper;
@Override
@@ -155,13 +154,7 @@ public class RouteLocServiceImpl extends CommonServiceImpl<RouteLocMapper, Route
// return obj;
// }
// @Override
// public RouteLocDto findByCode(String code) {
// WQLObject wo = WQLObject.getWQLObject("acs_route_loc");
// JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
// final RouteLocDto obj = json.toJavaObject(RouteLocDto.class);
// return obj;
// }
@Override
@Transactional(rollbackFor = Exception.class)

View File

@@ -43,7 +43,6 @@ import java.util.*;
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class RoutePlanServiceImpl extends CommonServiceImpl<RoutePlanMapper, RoutePlan> implements RoutePlanService {
// private final RedisUtils redisUtils;
private final RoutePlanMapper routePlanMapper;
@Override
@@ -156,13 +155,7 @@ public class RoutePlanServiceImpl extends CommonServiceImpl<RoutePlanMapper, Rou
// return obj;
// }
// @Override
// public RoutePlanDto findByCode(String code) {
// WQLObject wo = WQLObject.getWQLObject("acs_route_plan");
// JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
// final RoutePlanDto obj = json.toJavaObject(RoutePlanDto.class);
// return obj;
// }
@Override
@Transactional(rollbackFor = Exception.class)

View File

@@ -33,10 +33,19 @@ public interface RouteLineMapper extends CommonMapper<RouteLine> {
/**
* 分页查询
* @param page
* @param queryWrapper
* @param <P>
* @return
*/
@Select(wrapperSql)
<P extends IPage<RouteLine>> P queryPage(P page, @Param("ew") Wrapper<RouteLine> queryWrapper);
/**
* 查询所有
* @param queryWrapper
* @return
*/
@Select(wrapperRlSql)
List<RouteLine> selectRouteLineList(@Param("ew") Wrapper<RouteLine> queryWrapper);
}