增加用功能参数创建仿真的接口;

This commit is contained in:
thesai 2024-02-28 18:30:47 +08:00
parent 8446891ba5
commit 761c7e02eb
5 changed files with 678 additions and 689 deletions

View File

@ -0,0 +1,66 @@
package club.joylink.rtss.controller.racetr;
import org.springframework.web.bind.annotation.*;
/**
* 赛题训练接口
*/
@RestController
@RequestMapping("/api/race")
public class RaceApplicationController {
/**
* 开始训练
*
* @param paperId 赛题ID
* @return 训练的信息
*/
@PostMapping("/{paperId}")
public Object start(@PathVariable long paperId) {
//暂时就用用户id作为竞赛上下文的id也就是说一个用户同时只能开一个竞赛
return null;
}
/**
* 加载场景
*
* @param simulationId 场景依托的仿真
* @param sceneId 场景的ID
*/
@PutMapping("/{simulationId}/{sceneId}/load")
public void loadScene(@PathVariable String simulationId, @PathVariable String sceneId) {
}
/**
* 完成任务
*
* @param taskId 任务ID
* @param record 任务记录需要前端进行判定的操作的记录
*/
@PutMapping("/{taskId}/finish")
public void finishTask(@PathVariable long taskId, @RequestBody Object record) {
}
/**
* 完成训练
*
* @return 评分结果
*/
public Object finish() {
return null;
}
/**
* 获取用户正在进行的竞赛信息
* <p>
* 目前想到的使用场景就是页面刷新后
*
* @return 竞赛信息
*/
@GetMapping("")
public Object getRaceInfo() {
return null;
}
}

View File

@ -1,8 +1,6 @@
package club.joylink.rtss.services.training2;
import club.joylink.rtss.constants.MapStatus;
import club.joylink.rtss.constants.Project;
import club.joylink.rtss.controller.advice.AuthenticateInterceptor;
import club.joylink.rtss.dao.MapInfoDAO;
import club.joylink.rtss.dao.PublishedTraining2DAO;
import club.joylink.rtss.dao.RtsMapFunctionDAO;
@ -11,36 +9,29 @@ import club.joylink.rtss.entity.MapInfo;
import club.joylink.rtss.entity.MapInfoExample;
import club.joylink.rtss.entity.RtsMapFunction;
import club.joylink.rtss.entity.RtsMapFunctionExample;
import club.joylink.rtss.entity.training2.*;
import club.joylink.rtss.entity.training2.PublishedTraining2Example;
import club.joylink.rtss.entity.training2.PublishedTraining2WithBLOBs;
import club.joylink.rtss.entity.training2.RtsTraining2RuleExample;
import club.joylink.rtss.entity.training2.RtsTraining2RuleWithBLOBs;
import club.joylink.rtss.services.mapFunction.RtsMapFunctionService;
import club.joylink.rtss.services.project.ProjectService;
import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.SimulationService;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.data.map.Route;
import club.joylink.rtss.simulation.cbtc.data.map.Stand;
import club.joylink.rtss.simulation.cbtc.data.map.Switch;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.training2.ScoringRuleVO;
import club.joylink.rtss.vo.project.ProjectVO;
import club.joylink.rtss.vo.training2.rule.BgSceneStatusRule;
import club.joylink.rtss.vo.training2.rule.MapLocationRule;
import club.joylink.rtss.vo.training2.rule.StepRule;
import club.joylink.rtss.vo.training2.rule.Training2Rule;
import com.fasterxml.jackson.core.JsonParseException;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.BiConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
@ -85,7 +76,7 @@ public class Training2RuleService {
* @return 生成结果
*/
public List<String> generateTrainingByRule(String groupId) {
Simulation simulation = simulationManager.getById(groupId , Simulation.class);
Simulation simulation = simulationManager.getById(groupId, Simulation.class);
Long mapId = simulation.getBuildParams().getMap().getId();
if (runningMapIdSet.contains(mapId)) {
return Arrays.asList("该地图正在生成实训!");
@ -131,7 +122,6 @@ public class Training2RuleService {
}
/**
*
* @param mapId
* @param functionId
* @return
@ -144,7 +134,7 @@ public class Training2RuleService {
/**
* 根据地图ID生成实训
*/
public List<String> generateTrainingByMapId(List<Long> mapIdList, LoginUserInfoVO loginUserInfoVO){
public List<String> generateTrainingByMapId(List<Long> mapIdList, LoginUserInfoVO loginUserInfoVO) {
// 地图列表
MapInfoExample example = new MapInfoExample();
MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode());
@ -223,7 +213,7 @@ public class Training2RuleService {
List<Map<String, Long>> publishTrainingIdList = publishedTraining2DAO.selectTrainingByRuleId(
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())));
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);
@ -237,7 +227,7 @@ public class Training2RuleService {
List<String> errorMsgList = new ArrayList<>();
mapRuleIdMap.forEach((k, v) -> {
// 地图信息
MapInfo mapInfo = mapInfoDAO.selectByPrimaryKey(k);
MapInfo mapInfo = mapInfoDAO.selectByPrimaryKey(k);
// 规则列表
RtsTraining2RuleExample rtsTraining2RuleExample = new RtsTraining2RuleExample();
rtsTraining2RuleExample.createCriteria().andIdIn(v).andLineCodeEqualTo(mapInfo.getLineCode());
@ -246,8 +236,8 @@ public class Training2RuleService {
// 获取客户端参数
List<RtsMapFunction> entities = getRtsMapFunctions(k);
if (!CollectionUtils.isEmpty(entities)) {
List<Map<String,String>> ruleNameMapList = ruleList.stream().map(r -> {
Map<String,String> map = new HashMap<>();
List<Map<String, String>> ruleNameMapList = ruleList.stream().map(r -> {
Map<String, String> map = new HashMap<>();
map.put("ruleName", r.getName());
map.put("client", r.getClient());
return map;
@ -255,7 +245,7 @@ public class Training2RuleService {
// 需要删除的列表
List<Long> delTrainingIdList = publishedTraining2DAO.selectTrainingIdByRuleNameAndMapId(ruleNameMapList, k);
try {
Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO, false);
Simulation simulation = simulationService.createSimulation(entities.get(0).getId(), loginUserInfoVO, false);
errorMsgList.addAll(generateTraining(simulation, ruleList, delTrainingIdList, delPublishTrainingByIds));
} catch (Exception e) {
log.error("创建仿真失败", e);
@ -288,7 +278,7 @@ public class Training2RuleService {
bloBs.setId(rule.getId());
bloBs.setScoreRule(JsonUtils.writeValueAsString(detailVOList));
return bloBs;
}).collect(Collectors.toList());
}).collect(Collectors.toList());
rtsTraining2RuleMapper.updateScoreRule(ruleScoreList);
}
@ -302,7 +292,7 @@ public class Training2RuleService {
List<RtsMapFunction> entities = getRtsMapFunctions(mapInfo.getId());
if (!CollectionUtils.isEmpty(entities) && !CollectionUtils.isEmpty(lineCodeRuleMap.get(mapInfo.getLineCode()))) {
try {
Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO, false);
Simulation simulation = simulationService.createSimulation(entities.get(0).getId(), loginUserInfoVO, false);
if (CollectionUtils.isEmpty(deleteTrainingIdMap)) {
errorMsgList.addAll(generateTraining(simulation, lineCodeRuleMap.get(mapInfo.getLineCode()), null, delPublishTrainingByMapId));
} else {
@ -318,8 +308,9 @@ public class Training2RuleService {
/**
* 生成实训方法
* @param simulation 对应地图仿真
* @param ruleList 生成规则
*
* @param simulation 对应地图仿真
* @param ruleList 生成规则
* @param delTrainingIds 要删除已发布的实训ID
* @param delConsumer 删除实训方法
* @return
@ -358,11 +349,11 @@ public class Training2RuleService {
publishedTraining2DAO.insertList(training2WithBLOBs);
} catch (RuntimeException e) {
log.error("实训反序列化失败", e);
errorMsgList.add(String.format("地图%d实训[%s]反序列化实训ID【%d】", mapId, rule.getName(), rule.getId(),Locale.ENGLISH));
errorMsgList.add(String.format("地图%d实训[%s]反序列化实训ID【%d】", mapId, rule.getName(), rule.getId(), Locale.ENGLISH));
} catch (Exception e) {
log.error("实训生成失败", e);
errorMsgList.add(String.format("地图%d实训[%s]生成失败,设备信息【%s】原因%s", mapId,
rule.getName(), rule.getDeviceRule(),e.getMessage(),Locale.ENGLISH));
rule.getName(), rule.getDeviceRule(), e.getMessage(), Locale.ENGLISH));
}
}
}

View File

@ -6,7 +6,6 @@ import club.joylink.rtss.simulation.vo.SimulationInfoVO;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.mapFunction.MapFunctionVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import club.joylink.rtss.vo.client.simulationv1.SimulationInfoQueryVO;
import lombok.NonNull;
@ -18,9 +17,7 @@ public interface SimulationService {
/**
* 创建仿真
*/
String createSimulation(long mapId, MapFunctionVO mapFunctionVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map<String, Boolean> createUserType);
String createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo);
String createSimulation(long mapId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO);
/**
* 给仿真添加功能
@ -44,7 +41,8 @@ public interface SimulationService {
/**
* 根据地图和功能ID获取仿真GroupId
* @param mapId 地图ID
*
* @param mapId 地图ID
* @param mapFunctionId 功能ID
* @return 仿真GroupId
*/
@ -53,7 +51,8 @@ public interface SimulationService {
/**
* 根据地图和功能ID获取仿真GroupId返回仿真对象
* @param mapId 地图ID
*
* @param mapId 地图ID
* @param mapFunctionId 功能ID
* @return 仿真GroupId
*/
@ -64,17 +63,15 @@ public interface SimulationService {
*/
void monitor(String simulationId, AccountVO user);
Simulation createSimulationPojo(long mapId, MapFunctionVO mapFunctionVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map<String, Boolean> createUserType);
/**
* 后台创建仿真
*
* @param mapFunctionId mapFunctionId 功能ID
* @param loginInfo 登录信息
* @param checkAuth 是否检查权限
* @param loginInfo 登录信息
* @param checkAuth 是否检查权限
* @return 仿真对象
*/
Simulation createSimulationPojo(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth);
Simulation createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth);
void loadDraftRunPlan(String simulationId, long draftRunPlanId);

View File

@ -80,19 +80,20 @@ public class SimulationServiceImpl implements SimulationService {
@Override
public String createSimulation(long mapId, MapFunctionVO mapFunctionVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map<String, Boolean> createUserType) {
return createSimulationPojo(mapId,mapFunctionVO, loginUserInfoVO, createUserType).getId();
public String createSimulation(long mapId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(workParamVO.containsRealDeviceItem(), "此途径创建的仿真不能连接真实设备");
return createSimulation(mapId, null, workParamVO, loginUserInfoVO, null).getId();
}
//只获取所有与该功能相关的权限信息
private List<PermissionSubjectVO> filterUserPermission(List<PermissionSubjectVO> subjectVOList, MapFunctionVO functionVO, LoginUserInfoVO loginUserInfoVO){
private List<PermissionSubjectVO> filterUserPermission(List<PermissionSubjectVO> subjectVOList, MapFunctionVO functionVO, LoginUserInfoVO loginUserInfoVO) {
List<PermissionSubjectVO> newVoList = Lists.newArrayList();
for (PermissionSubjectVO subjectVO : subjectVOList) {
if(subjectVO.getStartTime().isAfter(LocalDateTime.now())){
log.info("权限主体id:[{}] 用户id:[{}] 开始时间:[{}]未到时间",subjectVO.getId(),subjectVO.getSubjectId(),subjectVO.getStartTime());
if (subjectVO.getStartTime().isAfter(LocalDateTime.now())) {
log.info("权限主体id:[{}] 用户id:[{}] 开始时间:[{}]未到时间", subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getStartTime());
continue;
}
if(!CollectionUtils.isEmpty(subjectVO.getSystemAbilityList())){
if (!CollectionUtils.isEmpty(subjectVO.getSystemAbilityList())) {
/* if(Objects.equals(PermissionTypeEnum.PROJECT.getValue(),subjectVO.getPermissionType())){
if(Objects.equals(subjectVO.getPermissionProjectCode(),loginUserInfoVO.getProject().toLowerCase())){
newVoList.add(subjectVO);
@ -103,15 +104,15 @@ public class SimulationServiceImpl implements SimulationService {
newVoList.add(subjectVO);
}
}else{*/
for (PermissionSystemAbilityVO permissionSystemAbilityVO : subjectVO.getSystemAbilityList()) {
if(Objects.equals(permissionSystemAbilityVO.getAbilityId(), functionVO.getId())) {
newVoList.add(subjectVO);
break;
}
for (PermissionSystemAbilityVO permissionSystemAbilityVO : subjectVO.getSystemAbilityList()) {
if (Objects.equals(permissionSystemAbilityVO.getAbilityId(), functionVO.getId())) {
newVoList.add(subjectVO);
break;
}
}
// }
}else {
log.error("权限主体对应的功能是空 主体id:[{}],subjectId:[{}],subjectType:[{}]",subjectVO.getId(),subjectVO.getSubjectId(),subjectVO.getSubjectType());
} else {
log.error("权限主体对应的功能是空 主体id:[{}],subjectId:[{}],subjectType:[{}]", subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getSubjectType());
}
}
return newVoList;
@ -119,122 +120,71 @@ public class SimulationServiceImpl implements SimulationService {
/**
* 检测用户对应的权限是否满足
*
* @param functionVO
* @param loginInfo
*/
private Map<String,Boolean> checkUserPermission(MapFunctionVO functionVO, LoginUserInfoVO loginInfo){
if(loginInfo.getAccountVO().isAdmin()){
private Map<String, Boolean> checkUserPermission(MapFunctionVO functionVO, LoginUserInfoVO loginInfo) {
if (loginInfo.getAccountVO().isAdmin()) {
return Collections.emptyMap();
}
LoginUserInfoVO newLoginUser = loginInfo;
if(loginInfo.getAccountVO().isThirdChildAccount()){
if (loginInfo.getAccountVO().isThirdChildAccount()) {
AccountVO user = this.iSysUserService.queryUserByAccountForMaster(loginInfo.getAccountVO().getParentAccount());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(user),"未找到主账号相关权限");
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(user), "未找到主账号相关权限");
newLoginUser = new LoginUserInfoVO();
user.setCompanyId(loginInfo.getAccountVO().getCompanyId());
newLoginUser.setAccountVO(user);
newLoginUser.setProjectInfo(loginInfo.getProjectInfo());
}
List<PermissionSubjectVO> subjectVOList = this.subjectService.findPermissionWithMapIdAndUserInfo(functionVO.getMapId(),newLoginUser);
List<PermissionSubjectVO> subjectVOList = this.subjectService.findPermissionWithMapIdAndUserInfo(functionVO.getMapId(), newLoginUser);
List<PermissionSubjectVO> newVOLIst = this.filterUserPermission(subjectVOList,functionVO,newLoginUser);
if(CollectionUtils.isEmpty(newVOLIst)){
log.error("未找到对应的权限数据mapId[{}],functionId[{}],userId[{}]",functionVO.getMapId(),functionVO.getId(),newLoginUser.getAccountVO().getId());
BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(true,"未找到该权限");
List<PermissionSubjectVO> newVOLIst = this.filterUserPermission(subjectVOList, functionVO, newLoginUser);
if (CollectionUtils.isEmpty(newVOLIst)) {
log.error("未找到对应的权限数据mapId[{}],functionId[{}],userId[{}]", functionVO.getMapId(), functionVO.getId(), newLoginUser.getAccountVO().getId());
BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(true, "未找到该权限");
}
Map<String,Boolean> resultMap2 = Maps.newHashMap();
Map<String,List<PermissionSubjectVO>> subjectMapList = newVOLIst.stream().collect(Collectors.groupingBy(PermissionSubjectVO::getSubjectType));
Map<String, Boolean> resultMap2 = Maps.newHashMap();
Map<String, List<PermissionSubjectVO>> subjectMapList = newVOLIst.stream().collect(Collectors.groupingBy(PermissionSubjectVO::getSubjectType));
for (PermissionSubjectTypeEnum st : PermissionSubjectTypeEnum.SORT_ENUM) {
List<PermissionSubjectVO> tmpSubjectVOList = subjectMapList.get(st.name());
if(CollectionUtils.isEmpty(tmpSubjectVOList)){
if (CollectionUtils.isEmpty(tmpSubjectVOList)) {
continue;
}
List<PermissionSubjectVO> canUseSubjectList = this.findCanUsedPermission(tmpSubjectVOList,functionVO,loginInfo);
BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(CollectionUtils.isEmpty(canUseSubjectList),"该权限过期");
List<PermissionSubjectVO> canUseSubjectList = this.findCanUsedPermission(tmpSubjectVOList, functionVO, loginInfo);
BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(CollectionUtils.isEmpty(canUseSubjectList), "该权限过期");
for (PermissionSubjectVO subjectVO : canUseSubjectList) {
String key = String.format("%s-%s",st.name(),subjectVO.getId());
String key = String.format("%s-%s", st.name(), subjectVO.getId());
List<Simulation> findSimList = this.simulationManager.finder(key);
resultMap2.put(key,false);
if(findSimList.size() +1 <= subjectVO.getAmount()){
resultMap2.put(key,true);
resultMap2.put(key, false);
if (findSimList.size() + 1 <= subjectVO.getAmount()) {
resultMap2.put(key, true);
break;
}
}
if(resultMap2.values().stream().anyMatch(d->Objects.equals(true,d))){
if (resultMap2.values().stream().anyMatch(d -> Objects.equals(true, d))) {
break;
}
}
BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(resultMap2.values().stream().allMatch(d->Objects.equals(false,d)),"仿真生成数量过载");
BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(resultMap2.values().stream().allMatch(d -> Objects.equals(false, d)), "仿真生成数量过载");
return resultMap2;
}
private List<PermissionSubjectVO> findCanUsedPermission(List<PermissionSubjectVO> newVOLIst, MapFunctionVO functionVO, LoginUserInfoVO loginInfo){
List<PermissionSubjectVO> canUseSubjectList = newVOLIst.stream().filter(d->Objects.equals(true,d.getForever())).collect(Collectors.toList());
if(CollectionUtils.isEmpty(canUseSubjectList)){
List<Long> timeOverIdList = newVOLIst.stream().filter(d->Objects.nonNull(d.getEndTime()) && d.getEndTime().isAfter(LocalDateTime.now()))
.map(d->d.getId())
private List<PermissionSubjectVO> findCanUsedPermission(List<PermissionSubjectVO> newVOLIst, MapFunctionVO functionVO, LoginUserInfoVO loginInfo) {
List<PermissionSubjectVO> canUseSubjectList = newVOLIst.stream().filter(d -> Objects.equals(true, d.getForever())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(canUseSubjectList)) {
List<Long> timeOverIdList = newVOLIst.stream().filter(d -> Objects.nonNull(d.getEndTime()) && d.getEndTime().isAfter(LocalDateTime.now()))
.map(d -> d.getId())
.collect(Collectors.toList());
if(CollectionUtils.isEmpty(timeOverIdList)){
log.error("mapId[{}],functionId[{}] userId[{}] 权限过期",functionVO.getMapId(),functionVO.getId(),loginInfo.getAccountVO().getId());
if (CollectionUtils.isEmpty(timeOverIdList)) {
log.error("mapId[{}],functionId[{}] userId[{}] 权限过期", functionVO.getMapId(), functionVO.getId(), loginInfo.getAccountVO().getId());
return Collections.emptyList();
}
canUseSubjectList = newVOLIst.stream().filter(d->timeOverIdList.contains(d.getId())).collect(Collectors.toList());
canUseSubjectList = newVOLIst.stream().filter(d -> timeOverIdList.contains(d.getId())).collect(Collectors.toList());
}
return canUseSubjectList;
}
private boolean checkUserPermissionDetail(List<PermissionSubjectVO> newVOLIst, MapFunctionVO functionVO, LoginUserInfoVO loginInfo){
boolean isForever = newVOLIst.stream().anyMatch(d->Objects.equals(true,d.getForever()));
if(Objects.equals(false,isForever)){
boolean timeOver = newVOLIst.stream().allMatch(d->Objects.nonNull(d.getEndTime()) && d.getEndTime().isBefore(LocalDateTime.now()));
if(timeOver){
log.error("mapId[{}],functionId[{}] userId[{}] 权限过期",functionVO.getMapId(),functionVO.getId(),loginInfo.getAccountVO().getId());
// BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(timeOver,"该权限过期");
return false;
}
return true;
}
return true;
}
private String checkUserExistSimulation(MapFunctionVO mapFunctionVO, AccountVO user){
List<String> userExistGroup = this.groupSimulationService.getUserRunningSimulationGroups(user);
if(!CollectionUtils.isEmpty(userExistGroup)){
Optional<Simulation> optional = userExistGroup.stream()
.map(d->this.groupSimulationService.getSimulationByGroup(d))
.filter(d->Objects.equals(d.getMapFunctionId(), mapFunctionVO.getId())).findAny();
if(optional.isPresent()){
BusinessExceptionAssertEnum.OPERATION_REPEAT.assertNotTrue(mapFunctionVO.getParamVO().getDomConfig().isHasExam(),"考试只能单独用户操作");
Simulation simulation = optional.get();
return simulation.getId();
}
BusinessExceptionAssertEnum.OPERATION_REPEAT.assertNotTrue(userExistGroup.size() >= 1,"用户重复创建仿真");
}
return null;
}
@Override
public String createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo) {
MapFunctionVO mapFunctionVO = rtsMapFunctionService.get(mapFunctionId);
/* String group = this.checkUserExistSimulation(mapFunctionVO,loginInfo.getAccountVO());
if(StringUtils.isNotEmpty(group)){
return group;
}*/
Long mapId = mapFunctionVO.getMapId();
Map<String,Boolean> createUserType = this.checkUserPermission(mapFunctionVO,loginInfo);
SimulationWorkParamVO workParamVO = mapFunctionVO.getParamVO();
if (workParamVO.containsRealDeviceItem()) {
//有实体设备加载项的地图功能实训室同时只能存在一个
Stream<Simulation> stream = simulationManager.getSimulationStream(Simulation.class);
Optional<Simulation> oldSimulationOptional = stream
.filter(sim -> Objects.equals(sim.getMapFunctionId(), mapFunctionId))
.findFirst();
oldSimulationOptional.ifPresent(simulation -> simulationManager.destroy(simulation.getId()));
}
return createSimulation(mapId, mapFunctionVO, loginInfo,createUserType);
}
@Override
public void addItems(@NonNull String simulationId, Map<SimulationWorkParamVO.Item, String> itemMap) {
@ -285,7 +235,7 @@ public class SimulationServiceImpl implements SimulationService {
/**
* 根据地图功能ID获取仿真ID
*
* @param mapId 地图ID
* @param mapId 地图ID
* @param mapFunctionId 功能ID
* @return 仿真ID
*/
@ -316,9 +266,8 @@ public class SimulationServiceImpl implements SimulationService {
simulationWorkServiceManager.addSimulationUser(simulation, simulationUser);
}
@Override
public Simulation createSimulationPojo(long mapId, MapFunctionVO mapFunctionVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map<String, Boolean> createUserType) {
SimulationWorkParamVO workParamVO = mapFunctionVO.getParamVO();
private Simulation createSimulation(long mapId, MapFunctionVO mapFunctionVO, @NonNull SimulationWorkParamVO workParamVO,
@NonNull LoginUserInfoVO loginUserInfoVO, Map<String, Boolean> createUserType) {
//获取仿真工作服务
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(workParamVO.getType());
@ -359,12 +308,12 @@ public class SimulationServiceImpl implements SimulationService {
}
@Override
public Simulation createSimulationPojo(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth) {
public Simulation createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth) {
MapFunctionVO mapFunctionVO = rtsMapFunctionService.get(mapFunctionId);
Long mapId = mapFunctionVO.getMapId();
Map<String,Boolean> createUserType = Maps.newHashMap();
Map<String, Boolean> createUserType = Maps.newHashMap();
if (checkAuth) {
createUserType = this.checkUserPermission(mapFunctionVO,loginInfo);
createUserType = this.checkUserPermission(mapFunctionVO, loginInfo);
}
SimulationWorkParamVO workParamVO = mapFunctionVO.getParamVO();
@ -377,7 +326,7 @@ public class SimulationServiceImpl implements SimulationService {
oldSimulationOptional.ifPresent(simulation -> simulationManager.destroy(simulation.getId()));
}
return createSimulationPojo(mapId, mapFunctionVO, loginInfo, createUserType);
return createSimulation(mapId, mapFunctionVO, mapFunctionVO.getParamVO(), loginInfo, createUserType);
}
@Override