Commit 6b7261e7 authored by hkl's avatar hkl

feat:1.bug修复

parent 6aba953e
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
<properties> <properties>
<package.environment>dev</package.environment> <package.environment>dev</package.environment>
</properties> </properties>
</profile> </profile>
<!-- 黄康林本地配置--> <!-- 黄康林本地配置-->
...@@ -73,6 +74,10 @@ ...@@ -73,6 +74,10 @@
<properties> <properties>
<package.environment>hkl</package.environment> <package.environment>hkl</package.environment>
</properties> </properties>
<!-- 是否默认 true表示默认-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile> </profile>
<!-- 测试环境 --> <!-- 测试环境 -->
...@@ -81,10 +86,6 @@ ...@@ -81,10 +86,6 @@
<properties> <properties>
<package.environment>test</package.environment> <package.environment>test</package.environment>
</properties> </properties>
<!-- 是否默认 true表示默认-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile> </profile>
<!-- 压测环境--> <!-- 压测环境-->
......
...@@ -93,7 +93,6 @@ public class RailManagementController extends JeecgController<RailManagement, IR ...@@ -93,7 +93,6 @@ public class RailManagementController extends JeecgController<RailManagement, IR
@ApiImplicitParam(name = "lineAliasId", value = "线别id") @ApiImplicitParam(name = "lineAliasId", value = "线别id")
}) })
public Result<String> intelligentGeneration(String lightRailId,String lineAliasId) { public Result<String> intelligentGeneration(String lightRailId,String lineAliasId) {
// this.service.intelligentGeneration(lightRailId);
this.service.intelligentGeneration(lightRailId,lineAliasId); this.service.intelligentGeneration(lightRailId,lineAliasId);
return Result.OK("生成成功"); return Result.OK("生成成功");
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
<if test="dto.lineAliasId != null and dto.lineAliasId != ''"> <if test="dto.lineAliasId != null and dto.lineAliasId != ''">
AND t1.line_alias_id = #{dto.lineAliasId} AND t1.line_alias_id = #{dto.lineAliasId}
</if> </if>
ORDER BY t1.light_rail_id ,t1.line_alias_id,t1.starting_mileage
</select> </select>
<select id="getLineSpecialRail" resultType="java.util.Map"> <select id="getLineSpecialRail" resultType="java.util.Map">
SELECT id, SELECT id,
......
...@@ -2,6 +2,7 @@ package org.jeecg.modules.deviceAsset.service.impl; ...@@ -2,6 +2,7 @@ package org.jeecg.modules.deviceAsset.service.impl;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.pinyin.PinyinUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
...@@ -26,6 +27,7 @@ import javax.annotation.Resource; ...@@ -26,6 +27,7 @@ import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
...@@ -135,19 +137,18 @@ public class RailManagementServiceImpl extends ServiceImpl<RailManagementMapper, ...@@ -135,19 +137,18 @@ public class RailManagementServiceImpl extends ServiceImpl<RailManagementMapper,
} }
@Override // @Override
public void intelligentGeneration(String lightRailId, String lineAliasId) { public void intelligentGeneration1(String lightRailId, String lineAliasId) {
System.out.printf("lineAliasId=" + lineAliasId); // 1.查询当前车站的上下行里程
// 2.查询当前车站的上下行里程
LightRail lightRail = lightRailMapper.selectById(lightRailId); LightRail lightRail = lightRailMapper.selectById(lightRailId);
// 3.1 查询上行所有里程数 // 2.1 查询上行所有里程数
List<RailManagement> allRailList = new ArrayList<>(); List<RailManagement> allRailList = new ArrayList<>();
generationCore(lightRail, allRailList, lineAliasId); generationCore(lightRail, allRailList, lineAliasId);
for (int i = 0; i < allRailList.size(); i++) { for (int i = 0; i < allRailList.size(); i++) {
RailManagement railManagement = allRailList.get(i); RailManagement railManagement = allRailList.get(i);
String railCode = "钢轨[上行]" + UnitCodeUtil.supplementZero(4, i + 1); String railCode = "钢轨[上行]" + UnitCodeUtil.supplementZero(4, i + 1) + "[自动]";
railManagement.setRailCode(railCode); railManagement.setRailCode(railCode);
String unitCode = "SXXGG" + UnitCodeUtil.supplementZero(4, i + 1); String unitCode = "SXXGG" + UnitCodeUtil.supplementZero(4, i + 1);
railManagement.setUnitCode(unitCode); railManagement.setUnitCode(unitCode);
...@@ -166,6 +167,189 @@ public class RailManagementServiceImpl extends ServiceImpl<RailManagementMapper, ...@@ -166,6 +167,189 @@ public class RailManagementServiceImpl extends ServiceImpl<RailManagementMapper,
} }
@Override
public void intelligentGeneration(String lightRailId, String lineAliasId) {
// 1.查询当前车站的上下行里程
LightRail lightRail = lightRailMapper.selectById(lightRailId);
// 2.1 查询上行所有里程数
List<RailManagement> allRailList = new ArrayList<>();
List<Map<String, Object>> lineSpecialRailList = this.getLineSpecialRail(lightRail.getId(), lineAliasId);
BigDecimal lineStartMileage = BigDecimal.ZERO;
LineAlias lineAlias = lineAliasMapper.selectById(lineAliasId);
BigDecimal endMileage = lightRail.getUpLineMileage();
if (lineAlias.getLineAliasName().contains("下行")) {
endMileage = lightRail.getDownLineMileage();
}
int size = lineSpecialRailList.size();
// 1.如果查询不到曲线,竖曲线,道岔,则全是钢轨
if (size == 0 && endMileage.compareTo(lineStartMileage) > 0) {
List<RailManagement> innerRailList = this.generate(lineStartMileage, endMileage, lineAliasId);
allRailList.addAll(innerRailList);
} else {
// true 可以进入生成规则2(说明没有空白部分) 否则用生成规则1
boolean isGenerateRule2 = true;
// 生成规则1:
for (int i = 0; i < size; i++) {
Map<String, Object> currentMap = lineSpecialRailList.get(i);
BigDecimal currentStartMileage = Convert.toBigDecimal(currentMap.get("startMileage"));
BigDecimal currentEndMileage = Convert.toBigDecimal(currentMap.get("endMileage"));
// 3.2.1 第一次进入循环
if (i == 0) {
// ① 线路起点 < 第一个单元开始里程[线路起点,第一个单元开始里程]
if (currentStartMileage.compareTo(lineStartMileage) > 0) {
isGenerateRule2 = false;
List<RailManagement> innerRailList = this.generate(lineStartMileage, currentStartMileage, lineAliasId);
allRailList.addAll(innerRailList);
}
// 只有一个的情况下做一个判断第一个单元可能只有半截
if (size == 1) {
// ② 第一个开始里程 < 线路起点里程 < 第一个单元结束里程[第一个单元结束里程,结束里程] ,
if (lineStartMileage.compareTo(currentStartMileage) > 0 && lineStartMileage.compareTo(currentEndMileage) < 0) {
isGenerateRule2 = false;
List<RailManagement> innerRailList = this.generate(currentEndMileage, endMileage, lineAliasId);
allRailList.addAll(innerRailList);
}
}
continue;
}
// 3.2.2 后一个的开始里程 - 前一个的结束里程 > 0 相当于有空白[注:1个单元情况下不做]
Map<String, Object> frontMap = lineSpecialRailList.get(i - 1);
BigDecimal frontEndMileage = Convert.toBigDecimal(frontMap.get("endMileage"));
if (currentStartMileage.subtract(frontEndMileage).compareTo(BigDecimal.ZERO) > 0) {
isGenerateRule2 = false;
List<RailManagement> innerRailList = this.generate(frontEndMileage, currentStartMileage, lineAliasId);
allRailList.addAll(innerRailList);
}
// 3.2.3 最后一次循环:线路终点里程 > 最后一个单元结束里程,要补充[最后一个单元结束里程,线路终点里程]
if (i == size - 1) {
if (endMileage.subtract(currentEndMileage).compareTo(BigDecimal.ZERO) > 0) {
isGenerateRule2 = false;
List<RailManagement> innerRailList = this.generate(currentEndMileage, endMileage, lineAliasId);
allRailList.addAll(innerRailList);
}
}
}
// 生成规则2:
if (isGenerateRule2) {
// 1.将钢轨删除,保留道岔,曲线,竖曲线
lineSpecialRailList = lineSpecialRailList.stream()
.filter(currentMap -> Convert.toInt(currentMap.get("type")) != 1)
.collect(Collectors.toList());
// 移除钢轨
this.lambdaUpdate()
.eq(RailManagement::getLightRailId, lightRailId)
.eq(RailManagement::getLineAliasId, lineAliasId)
.remove();
size = lineSpecialRailList.size();
for (int i = 0; i < size; i++) {
Map<String, Object> currentMap = lineSpecialRailList.get(i);
BigDecimal currentStartMileage = Convert.toBigDecimal(currentMap.get("startMileage"));
BigDecimal currentEndMileage = Convert.toBigDecimal(currentMap.get("endMileage"));
// 3.2.1 第一次进入循环
if (i == 0) {
// ① 线路起点 < 第一个单元开始里程[线路起点,第一个单元开始里程]
if (currentStartMileage.compareTo(lineStartMileage) > 0) {
List<RailManagement> innerRailList = this.generate(lineStartMileage, currentStartMileage, lineAliasId);
allRailList.addAll(innerRailList);
}
// 只有一个的情况下做一个判断第一个单元可能只有半截
if (size == 1) {
// ② 第一个开始里程 < 线路起点里程 < 第一个单元结束里程[第一个单元结束里程,结束里程] ,
if (lineStartMileage.compareTo(currentStartMileage) > 0 && lineStartMileage.compareTo(currentEndMileage) < 0) {
List<RailManagement> innerRailList = this.generate(currentEndMileage, endMileage, lineAliasId);
allRailList.addAll(innerRailList);
}
}
continue;
}
// 3.2.2 后一个的开始里程 - 前一个的结束里程 > 0 相当于有空白[注:1个单元情况下不做]
Map<String, Object> frontMap = lineSpecialRailList.get(i - 1);
BigDecimal frontEndMileage = Convert.toBigDecimal(frontMap.get("endMileage"));
if (currentStartMileage.subtract(frontEndMileage).compareTo(BigDecimal.ZERO) > 0) {
List<RailManagement> innerRailList = this.generate(frontEndMileage, currentStartMileage, lineAliasId);
allRailList.addAll(innerRailList);
}
// 3.2.3 最后一次循环:线路终点里程 > 最后一个单元结束里程,要补充[最后一个单元结束里程,线路终点里程]
if (i == size - 1) {
if (endMileage.subtract(currentEndMileage).compareTo(BigDecimal.ZERO) > 0) {
List<RailManagement> innerRailList = this.generate(currentEndMileage, endMileage, lineAliasId);
allRailList.addAll(innerRailList);
}
}
}
}
}
// 查询最大的编号
String lineAliasPinyin = PinyinUtil.getFirstLetter(lineAlias.getLineAliasName(), "").toUpperCase();
String unitCodePrefix = lineAliasPinyin + "GG";
RailManagement record = this.lambdaQuery()
.likeRight(RailManagement::getUnitCode, unitCodePrefix)
.orderByDesc(RailManagement::getUnitCode)
.last("limit 1")
.one();
// 流水号初始化为1
Integer serialNum = 1;
if (null != record && record.getUnitCode() != null) {
// 流水号+1
serialNum = Integer.parseInt(record.getUnitCode().substring(record.getUnitCode().length() - 4)) + 1;
}
for (int i = 0; i < allRailList.size(); i++) {
RailManagement railManagement = allRailList.get(i);
String railCode = "钢轨[" + lineAlias.getLineAliasName() + "]" + UnitCodeUtil.supplementZero(4, serialNum + i) + "[自动]";
railManagement.setRailCode(railCode);
String unitCode = unitCodePrefix + UnitCodeUtil.supplementZero(4, serialNum + i);
railManagement.setUnitCode(unitCode);
railManagement.setLightRailId(lightRailId);
railManagement.setRailOrderNum(serialNum + i);
railManagement.setCreateBy("系统生成");
railManagement.setUpdateBy("系统生成");
}
// 3.2 计算区间
this.calcSection(lightRailId, lineAliasId, allRailList);
// 异步执行保存
asyncTask.getAsyncExecutor().execute(() -> {
this.saveBatch(allRailList);
});
}
/** /**
* 计算区间 * 计算区间
* *
...@@ -245,6 +429,7 @@ public class RailManagementServiceImpl extends ServiceImpl<RailManagementMapper, ...@@ -245,6 +429,7 @@ public class RailManagementServiceImpl extends ServiceImpl<RailManagementMapper,
allRailList.addAll(innerRailList); allRailList.addAll(innerRailList);
} else { } else {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
Map<String, Object> currentMap = lineSpecialRailList.get(i); Map<String, Object> currentMap = lineSpecialRailList.get(i);
BigDecimal currentStartMileage = Convert.toBigDecimal(currentMap.get("startMileage")); BigDecimal currentStartMileage = Convert.toBigDecimal(currentMap.get("startMileage"));
...@@ -291,6 +476,8 @@ public class RailManagementServiceImpl extends ServiceImpl<RailManagementMapper, ...@@ -291,6 +476,8 @@ public class RailManagementServiceImpl extends ServiceImpl<RailManagementMapper,
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment