【根据修改的实训规则生成实训接口】
This commit is contained in:
parent
4d9343142a
commit
24a0a5f0d2
@ -63,4 +63,13 @@ public class TrainingRuleController {
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
@Repository
|
||||
@ -63,4 +64,7 @@ public interface PublishedTraining2DAO {
|
||||
void batchInsert(@Param("list") PublishedTraining2 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));
|
||||
|
||||
List<String> errorMsgList = new ArrayList<>();
|
||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList);
|
||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList, null);
|
||||
return errorMsgList;
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ public class Training2RuleService {
|
||||
List<MapInfo> mapList = mapInfoDAO.selectByExample(example);
|
||||
|
||||
List<String> errorMsgList = new ArrayList<>();
|
||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList);
|
||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList, null);
|
||||
return errorMsgList;
|
||||
}
|
||||
|
||||
@ -185,15 +185,43 @@ public class Training2RuleService {
|
||||
List<MapInfo> mapList = mapInfoDAO.selectByExample(example);
|
||||
|
||||
List<String> errorMsgList = new ArrayList<>();
|
||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList);
|
||||
loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList, null);
|
||||
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
|
||||
, Map<String, List<RtsTraining2RuleWithBLOBs>> lineCodeRuleMap, List<String> errorMsgList) {
|
||||
, Map<String, List<RtsTraining2RuleWithBLOBs>> lineCodeRuleMap, List<String> errorMsgList, Map<Long, List<Long>> deleteTrainingIdMap) {
|
||||
mapList.forEach(mapInfo -> {
|
||||
RtsMapFunctionExample rtsExample = new RtsMapFunctionExample();
|
||||
RtsMapFunctionExample.Criteria rtsCriteria = rtsExample.createCriteria();
|
||||
@ -203,7 +231,11 @@ public class Training2RuleService {
|
||||
if (!CollectionUtils.isEmpty(entities) && !CollectionUtils.isEmpty(lineCodeRuleMap.get(mapInfo.getLineCode()))) {
|
||||
try {
|
||||
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) {
|
||||
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());
|
||||
Long mapId = simulation.getBuildParams().getMap().getId();
|
||||
if (runningMapIdSet.contains(mapId)) {
|
||||
@ -224,7 +256,11 @@ public class Training2RuleService {
|
||||
runningMapIdSet.add(mapId);
|
||||
// 清除数据库原有数据
|
||||
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);
|
||||
// 生成新数据
|
||||
for (RtsTraining2RuleWithBLOBs rule : ruleList) {
|
||||
|
@ -578,4 +578,21 @@
|
||||
client = #{record.client,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=BIGINT}
|
||||
</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>
|
||||
|
Loading…
Reference in New Issue
Block a user