【根据修改的实训规则生成实训接口】
This commit is contained in:
parent
4d9343142a
commit
24a0a5f0d2
@ -63,4 +63,13 @@ public class TrainingRuleController {
|
|||||||
return training2RuleService.generateTrainingByLineCode(lineCodeList, loginUserInfoVO);
|
return training2RuleService.generateTrainingByLineCode(lineCodeList, loginUserInfoVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据规则ID生成实训
|
||||||
|
*/
|
||||||
|
@PostMapping("generate/ruleId")
|
||||||
|
public List<String> generateTrainingByRuleId(@RequestBody List<Long> ruleIdList
|
||||||
|
, @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO) {
|
||||||
|
return training2RuleService.generateTrainingByRuleId(ruleIdList, loginUserInfoVO);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Select;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
@Repository
|
@Repository
|
||||||
@ -63,4 +64,7 @@ public interface PublishedTraining2DAO {
|
|||||||
void batchInsert(@Param("list") PublishedTraining2 list);
|
void batchInsert(@Param("list") PublishedTraining2 list);
|
||||||
|
|
||||||
int insertList(@Param("list") List<PublishedTraining2WithBLOBs> list);
|
int insertList(@Param("list") List<PublishedTraining2WithBLOBs> list);
|
||||||
|
|
||||||
|
|
||||||
|
List<Map<String, Long>> selectByRuleId(@Param("ruleIdList") List<Long> ruleIdList, @Param("mapIdList") List<Long> mapIdList);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public class Training2RuleService {
|
|||||||
Map<String, List<RtsTraining2RuleWithBLOBs>> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode));
|
Map<String, List<RtsTraining2RuleWithBLOBs>> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode));
|
||||||
|
|
||||||
List<String> errorMsgList = new ArrayList<>();
|
List<String> errorMsgList = new ArrayList<>();
|
||||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList);
|
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList, null);
|
||||||
return errorMsgList;
|
return errorMsgList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ public class Training2RuleService {
|
|||||||
List<MapInfo> mapList = mapInfoDAO.selectByExample(example);
|
List<MapInfo> mapList = mapInfoDAO.selectByExample(example);
|
||||||
|
|
||||||
List<String> errorMsgList = new ArrayList<>();
|
List<String> errorMsgList = new ArrayList<>();
|
||||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList);
|
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList, null);
|
||||||
return errorMsgList;
|
return errorMsgList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,15 +185,43 @@ public class Training2RuleService {
|
|||||||
List<MapInfo> mapList = mapInfoDAO.selectByExample(example);
|
List<MapInfo> mapList = mapInfoDAO.selectByExample(example);
|
||||||
|
|
||||||
List<String> errorMsgList = new ArrayList<>();
|
List<String> errorMsgList = new ArrayList<>();
|
||||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList);
|
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList, null);
|
||||||
return errorMsgList;
|
return errorMsgList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据规则ID生成实训
|
||||||
|
*/
|
||||||
|
public List<String> generateTrainingByRuleId(List<Long> ruleIdList, LoginUserInfoVO loginUserInfoVO) {
|
||||||
|
// 规则列表
|
||||||
|
RtsTraining2RuleExample rtsTraining2RuleExample = new RtsTraining2RuleExample();
|
||||||
|
rtsTraining2RuleExample.createCriteria().andIdIn(ruleIdList);
|
||||||
|
List<RtsTraining2RuleWithBLOBs> ruleList = rtsTraining2RuleMapper.selectByExampleWithBLOBs(rtsTraining2RuleExample);
|
||||||
|
Map<String, List<RtsTraining2RuleWithBLOBs>> lineCodeRuleMap = ruleList.stream().collect(Collectors.groupingBy(RtsTraining2RuleWithBLOBs::getLineCode));
|
||||||
|
|
||||||
|
// 地图列表
|
||||||
|
MapInfoExample example = new MapInfoExample();
|
||||||
|
MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode());
|
||||||
|
criteria.andLineCodeIn(lineCodeRuleMap.keySet().stream().collect(Collectors.toList()));
|
||||||
|
List<MapInfo> mapList = mapInfoDAO.selectByExample(example);
|
||||||
|
|
||||||
|
// 需要删除的发布的实训
|
||||||
|
List<Map<String, Long>> publishTrainingIdList = publishedTraining2DAO.selectByRuleId(
|
||||||
|
ruleIdList, mapList.stream().map(MapInfo::getId).collect(Collectors.toList()));
|
||||||
|
Map<Long, List<Long>> publishTrainingIdMap = publishTrainingIdList.stream().collect(
|
||||||
|
Collectors.groupingBy(m -> m.get("mapId"), Collectors.mapping(m -> m.get("id") , Collectors.toList())));
|
||||||
|
|
||||||
|
List<String> errorMsgList = new ArrayList<>();
|
||||||
|
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList, publishTrainingIdMap);
|
||||||
|
return errorMsgList;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 循环地图列表生成实训信息
|
* 循环地图列表生成实训信息
|
||||||
*/
|
*/
|
||||||
private void loopMapListGenerateTraining(LoginUserInfoVO loginUserInfoVO, List<MapInfo> mapList
|
private void loopMapListGenerateTraining(LoginUserInfoVO loginUserInfoVO, List<MapInfo> mapList
|
||||||
, Map<String, List<RtsTraining2RuleWithBLOBs>> lineCodeRuleMap, List<String> errorMsgList) {
|
, Map<String, List<RtsTraining2RuleWithBLOBs>> lineCodeRuleMap, List<String> errorMsgList, Map<Long, List<Long>> deleteTrainingIdMap) {
|
||||||
mapList.forEach(mapInfo -> {
|
mapList.forEach(mapInfo -> {
|
||||||
RtsMapFunctionExample rtsExample = new RtsMapFunctionExample();
|
RtsMapFunctionExample rtsExample = new RtsMapFunctionExample();
|
||||||
RtsMapFunctionExample.Criteria rtsCriteria = rtsExample.createCriteria();
|
RtsMapFunctionExample.Criteria rtsCriteria = rtsExample.createCriteria();
|
||||||
@ -203,7 +231,11 @@ public class Training2RuleService {
|
|||||||
if (!CollectionUtils.isEmpty(entities) && !CollectionUtils.isEmpty(lineCodeRuleMap.get(mapInfo.getLineCode()))) {
|
if (!CollectionUtils.isEmpty(entities) && !CollectionUtils.isEmpty(lineCodeRuleMap.get(mapInfo.getLineCode()))) {
|
||||||
try {
|
try {
|
||||||
Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO);
|
Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO);
|
||||||
errorMsgList.addAll(generateTraining(simulation, lineCodeRuleMap.get(mapInfo.getLineCode())));
|
if (CollectionUtils.isEmpty(deleteTrainingIdMap)) {
|
||||||
|
errorMsgList.addAll(generateTraining(simulation, lineCodeRuleMap.get(mapInfo.getLineCode()), null));
|
||||||
|
} else {
|
||||||
|
errorMsgList.addAll(generateTraining(simulation, lineCodeRuleMap.get(mapInfo.getLineCode()), deleteTrainingIdMap.get(mapInfo.getId())));
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
errorMsgList.add(String.format("地图%d创建仿真报错,原因:%s", mapInfo.getId(), e.getMessage(), Locale.ENGLISH));
|
errorMsgList.add(String.format("地图%d创建仿真报错,原因:%s", mapInfo.getId(), e.getMessage(), Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
@ -211,7 +243,7 @@ public class Training2RuleService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> generateTraining(Simulation simulation, List<RtsTraining2RuleWithBLOBs> ruleList) {
|
private List<String> generateTraining(Simulation simulation, List<RtsTraining2RuleWithBLOBs> ruleList, List<Long> delTrainingIds) {
|
||||||
List<String> errorMsgList = new ArrayList<>(ruleList.size());
|
List<String> errorMsgList = new ArrayList<>(ruleList.size());
|
||||||
Long mapId = simulation.getBuildParams().getMap().getId();
|
Long mapId = simulation.getBuildParams().getMap().getId();
|
||||||
if (runningMapIdSet.contains(mapId)) {
|
if (runningMapIdSet.contains(mapId)) {
|
||||||
@ -224,7 +256,11 @@ public class Training2RuleService {
|
|||||||
runningMapIdSet.add(mapId);
|
runningMapIdSet.add(mapId);
|
||||||
// 清除数据库原有数据
|
// 清除数据库原有数据
|
||||||
PublishedTraining2Example publishedTraining2Example = new PublishedTraining2Example();
|
PublishedTraining2Example publishedTraining2Example = new PublishedTraining2Example();
|
||||||
publishedTraining2Example.createCriteria().andMapIdEqualTo(mapId).andCreatorIdEqualTo(0L);
|
if (CollectionUtils.isEmpty(delTrainingIds)) { // 传递删除ID,则删除所有生成的实训
|
||||||
|
publishedTraining2Example.createCriteria().andMapIdEqualTo(mapId).andCreatorIdEqualTo(0L);
|
||||||
|
} else { // 删除指定ID的实训
|
||||||
|
publishedTraining2Example.createCriteria().andIdIn(delTrainingIds);
|
||||||
|
}
|
||||||
publishedTraining2DAO.deleteByExample(publishedTraining2Example);
|
publishedTraining2DAO.deleteByExample(publishedTraining2Example);
|
||||||
// 生成新数据
|
// 生成新数据
|
||||||
for (RtsTraining2RuleWithBLOBs rule : ruleList) {
|
for (RtsTraining2RuleWithBLOBs rule : ruleList) {
|
||||||
|
@ -578,4 +578,21 @@
|
|||||||
client = #{record.client,jdbcType=VARCHAR}
|
client = #{record.client,jdbcType=VARCHAR}
|
||||||
where id = #{id,jdbcType=BIGINT}
|
where id = #{id,jdbcType=BIGINT}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<select id="selectByRuleId" resultType="map">
|
||||||
|
SELECT t.id as id, t.map_id as mapId
|
||||||
|
FROM (
|
||||||
|
SELECT line_code,REGEXP_REPLACE(`name`,'【.*】','【】') as replaceName
|
||||||
|
FROM rts_training2_rule
|
||||||
|
WHERE id IN (<foreach collection="ruleIdList" item="ruleId" separator=",">#{ruleId}</foreach>)
|
||||||
|
) r
|
||||||
|
INNER JOIN map_info m ON m.line_code = r.line_code
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT id,map_id,name,REGEXP_REPLACE(name,'【.*】','【】') as replaceName
|
||||||
|
FROM rts_published_training2
|
||||||
|
WHERE map_id IN (<foreach collection="mapIdList" item="mapId" separator=",">#{mapId}</foreach>)
|
||||||
|
) t
|
||||||
|
ON t.map_id = m.id AND t.replaceName = r.replaceName
|
||||||
|
WHERE t.id is not NULL
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
Loading…
Reference in New Issue
Block a user