[新增]成工院虚仿平台对接的登录接口、统计数据并同步服务

This commit is contained in:
thesai 2024-05-07 16:47:32 +08:00
parent 5d15ba3240
commit bef6dda6b2
40 changed files with 2303 additions and 5028 deletions

View File

@ -0,0 +1,41 @@
package club.joylink.rtss.aop;
import club.joylink.rtss.services.cgy.CgyStatsService;
import club.joylink.rtss.simulation.cbtc.SimulationService;
import club.joylink.rtss.vo.client.cgy.CgyThirdPartyLoginInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@Aspect
@Slf4j
@Component
public class CgyViewAspect {
private CgyStatsService cgyStatsService;
private RestTemplate restTemplate;
private SimulationService simulationService;
@Autowired
public CgyViewAspect(CgyStatsService cgyStatsService, RestTemplate restTemplate,
SimulationService simulationService) {
this.cgyStatsService = cgyStatsService;
this.restTemplate = restTemplate;
this.simulationService = simulationService;
}
/**
* 成工院第三方登录接口被调用后加一个浏览量并同步给虚仿平台
*/
@AfterReturning(value = "execution(public * club.joylink.rtss.controller.LoginController.cgyThirdPartyLogin(..))")
public void addViewCount(JoinPoint joinPoint) {
Object arg = joinPoint.getArgs()[0];
CgyThirdPartyLoginInfoVO loginInfoVO = (CgyThirdPartyLoginInfoVO) arg;
cgyStatsService.updateView(loginInfoVO.getAppId());
}
}

View File

@ -0,0 +1,32 @@
package club.joylink.rtss.bo.cgy;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
/**
* 成工院虚仿平台对接统计数据
*/
@Getter
@Setter
@RequiredArgsConstructor
public class CgyStatsBO {
private final String appId;
private final String appSecret;
private final Long FunctionId;
//统计数据是否发生变化
private AtomicBoolean change;
//浏览量
private AtomicLong view;
//实训人次
private AtomicLong visitor;
//实训人数
private final Set<Long> userSet = new HashSet<>();
//实训时长
private AtomicLong duration;
}

View File

@ -6,5 +6,6 @@ public interface ProjectCode {
String SR_SANDBOX = "SR_SANDBOX";
String NGY_SAND_TABLE = "NGY_SAND_TABLE";
String CDGXY = "CDGXY";
String CGY = "CGY";
}

View File

@ -7,13 +7,19 @@ import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.LoginStatusVO;
import club.joylink.rtss.vo.client.LoginUserVO;
import club.joylink.rtss.vo.client.cgy.CgyThirdPartyLoginInfoVO;
import club.joylink.rtss.vo.client.validGroup.LoginInfoCheck;
import club.joylink.rtss.vo.client.validGroup.ThirdLoginInfoCheck;
import javax.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotBlank;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/login")
@ -22,8 +28,14 @@ public class LoginController {
@Autowired
private IAuthenticateService iAuthenticateService;
@PostMapping("/cgy/third")
public String cgyThirdPartyLogin(@RequestBody @Validated CgyThirdPartyLoginInfoVO loginInfo) {
return this.iAuthenticateService.cgyThirdPartyLogin(loginInfo);
}
@PostMapping(path = "/third")
public String thirdPartyLogin(@RequestBody @Validated(ThirdLoginInfoCheck.class) LoginUserVO loginInfo) {
public String thirdPartyLogin(
@RequestBody @Validated(ThirdLoginInfoCheck.class) LoginUserVO loginInfo) {
return this.iAuthenticateService.thirdPartyLogin(loginInfo);
}

View File

@ -47,12 +47,10 @@ import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@ -591,16 +589,7 @@ public class SimulationV1Controller {
*/
@GetMapping("/list")
public List<SimulationInfoVO> queryInfo(SimulationInfoQueryVO queryVO) {
List<Simulation> simulationList = this.simulationManager.getSimulationList();
Stream<Simulation> stream = simulationList.stream();
if (StringUtils.hasText(queryVO.getGroup())) {
stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup()));
}
if (StringUtils.hasText(queryVO.getUserName())) {
stream = stream.filter(simulation -> simulation.getSimulationUsers().stream()
.anyMatch(user -> user.getName().contains(queryVO.getUserName())));
}
return stream.map(Simulation::convertToVO).collect(Collectors.toList());
return simulationService.listAllSimulation(queryVO);
}
/**

View File

@ -0,0 +1,12 @@
package club.joylink.rtss.dao;
import club.joylink.rtss.entity.CgyView;
import club.joylink.rtss.entity.CgyViewExample;
import org.springframework.stereotype.Repository;
/**
* CgyViewDAO继承基类
*/
@Repository
public interface CgyViewDAO extends MyBatisBaseDao<CgyView, String, CgyViewExample> {
}

View File

@ -1,12 +0,0 @@
//package club.joylink.rtss.dao;
//
//import club.joylink.rtss.entity.Company;
//import club.joylink.rtss.entity.CompanyExample;
//import org.springframework.stereotype.Repository;
//
///**
// * CompanyDAO继承基类
// */
////@Repository
////public interface CompanyDAO extends MyBatisBaseDao<Company, Integer, CompanyExample> {
////}

View File

@ -0,0 +1,107 @@
package club.joylink.rtss.entity;
import java.io.Serializable;
/**
* cgy_view
* @author
*/
public class CgyView implements Serializable {
/**
* 接入虚仿平台后获取
*/
private String appId;
/**
* 接入虚仿平台后获取
*/
private String appSecret;
/**
* 地图功能id
*/
private Long functionId;
/**
* 浏览量
*/
private Long viewCount;
private static final long serialVersionUID = 1L;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getAppSecret() {
return appSecret;
}
public void setAppSecret(String appSecret) {
this.appSecret = appSecret;
}
public Long getFunctionId() {
return functionId;
}
public void setFunctionId(Long functionId) {
this.functionId = functionId;
}
public Long getViewCount() {
return viewCount;
}
public void setViewCount(Long viewCount) {
this.viewCount = viewCount;
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
CgyView other = (CgyView) that;
return (this.getAppId() == null ? other.getAppId() == null : this.getAppId().equals(other.getAppId()))
&& (this.getAppSecret() == null ? other.getAppSecret() == null : this.getAppSecret().equals(other.getAppSecret()))
&& (this.getFunctionId() == null ? other.getFunctionId() == null : this.getFunctionId().equals(other.getFunctionId()))
&& (this.getViewCount() == null ? other.getViewCount() == null : this.getViewCount().equals(other.getViewCount()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getAppId() == null) ? 0 : getAppId().hashCode());
result = prime * result + ((getAppSecret() == null) ? 0 : getAppSecret().hashCode());
result = prime * result + ((getFunctionId() == null) ? 0 : getFunctionId().hashCode());
result = prime * result + ((getViewCount() == null) ? 0 : getViewCount().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", appId=").append(appId);
sb.append(", appSecret=").append(appSecret);
sb.append(", functionId=").append(functionId);
sb.append(", viewCount=").append(viewCount);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}

View File

@ -0,0 +1,482 @@
package club.joylink.rtss.entity;
import java.util.ArrayList;
import java.util.List;
public class CgyViewExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
private Integer limit;
private Long offset;
public CgyViewExample() {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
public void setLimit(Integer limit) {
this.limit = limit;
}
public Integer getLimit() {
return limit;
}
public void setOffset(Long offset) {
this.offset = offset;
}
public Long getOffset() {
return offset;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andAppIdIsNull() {
addCriterion("app_id is null");
return (Criteria) this;
}
public Criteria andAppIdIsNotNull() {
addCriterion("app_id is not null");
return (Criteria) this;
}
public Criteria andAppIdEqualTo(String value) {
addCriterion("app_id =", value, "appId");
return (Criteria) this;
}
public Criteria andAppIdNotEqualTo(String value) {
addCriterion("app_id <>", value, "appId");
return (Criteria) this;
}
public Criteria andAppIdGreaterThan(String value) {
addCriterion("app_id >", value, "appId");
return (Criteria) this;
}
public Criteria andAppIdGreaterThanOrEqualTo(String value) {
addCriterion("app_id >=", value, "appId");
return (Criteria) this;
}
public Criteria andAppIdLessThan(String value) {
addCriterion("app_id <", value, "appId");
return (Criteria) this;
}
public Criteria andAppIdLessThanOrEqualTo(String value) {
addCriterion("app_id <=", value, "appId");
return (Criteria) this;
}
public Criteria andAppIdLike(String value) {
addCriterion("app_id like", value, "appId");
return (Criteria) this;
}
public Criteria andAppIdNotLike(String value) {
addCriterion("app_id not like", value, "appId");
return (Criteria) this;
}
public Criteria andAppIdIn(List<String> values) {
addCriterion("app_id in", values, "appId");
return (Criteria) this;
}
public Criteria andAppIdNotIn(List<String> values) {
addCriterion("app_id not in", values, "appId");
return (Criteria) this;
}
public Criteria andAppIdBetween(String value1, String value2) {
addCriterion("app_id between", value1, value2, "appId");
return (Criteria) this;
}
public Criteria andAppIdNotBetween(String value1, String value2) {
addCriterion("app_id not between", value1, value2, "appId");
return (Criteria) this;
}
public Criteria andAppSecretIsNull() {
addCriterion("app_secret is null");
return (Criteria) this;
}
public Criteria andAppSecretIsNotNull() {
addCriterion("app_secret is not null");
return (Criteria) this;
}
public Criteria andAppSecretEqualTo(String value) {
addCriterion("app_secret =", value, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretNotEqualTo(String value) {
addCriterion("app_secret <>", value, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretGreaterThan(String value) {
addCriterion("app_secret >", value, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretGreaterThanOrEqualTo(String value) {
addCriterion("app_secret >=", value, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretLessThan(String value) {
addCriterion("app_secret <", value, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretLessThanOrEqualTo(String value) {
addCriterion("app_secret <=", value, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretLike(String value) {
addCriterion("app_secret like", value, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretNotLike(String value) {
addCriterion("app_secret not like", value, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretIn(List<String> values) {
addCriterion("app_secret in", values, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretNotIn(List<String> values) {
addCriterion("app_secret not in", values, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretBetween(String value1, String value2) {
addCriterion("app_secret between", value1, value2, "appSecret");
return (Criteria) this;
}
public Criteria andAppSecretNotBetween(String value1, String value2) {
addCriterion("app_secret not between", value1, value2, "appSecret");
return (Criteria) this;
}
public Criteria andFunctionIdIsNull() {
addCriterion("function_id is null");
return (Criteria) this;
}
public Criteria andFunctionIdIsNotNull() {
addCriterion("function_id is not null");
return (Criteria) this;
}
public Criteria andFunctionIdEqualTo(Long value) {
addCriterion("function_id =", value, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdNotEqualTo(Long value) {
addCriterion("function_id <>", value, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdGreaterThan(Long value) {
addCriterion("function_id >", value, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdGreaterThanOrEqualTo(Long value) {
addCriterion("function_id >=", value, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdLessThan(Long value) {
addCriterion("function_id <", value, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdLessThanOrEqualTo(Long value) {
addCriterion("function_id <=", value, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdIn(List<Long> values) {
addCriterion("function_id in", values, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdNotIn(List<Long> values) {
addCriterion("function_id not in", values, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdBetween(Long value1, Long value2) {
addCriterion("function_id between", value1, value2, "functionId");
return (Criteria) this;
}
public Criteria andFunctionIdNotBetween(Long value1, Long value2) {
addCriterion("function_id not between", value1, value2, "functionId");
return (Criteria) this;
}
public Criteria andViewCountIsNull() {
addCriterion("view_count is null");
return (Criteria) this;
}
public Criteria andViewCountIsNotNull() {
addCriterion("view_count is not null");
return (Criteria) this;
}
public Criteria andViewCountEqualTo(Long value) {
addCriterion("view_count =", value, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountNotEqualTo(Long value) {
addCriterion("view_count <>", value, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountGreaterThan(Long value) {
addCriterion("view_count >", value, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountGreaterThanOrEqualTo(Long value) {
addCriterion("view_count >=", value, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountLessThan(Long value) {
addCriterion("view_count <", value, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountLessThanOrEqualTo(Long value) {
addCriterion("view_count <=", value, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountIn(List<Long> values) {
addCriterion("view_count in", values, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountNotIn(List<Long> values) {
addCriterion("view_count not in", values, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountBetween(Long value1, Long value2) {
addCriterion("view_count between", value1, value2, "viewCount");
return (Criteria) this;
}
public Criteria andViewCountNotBetween(Long value1, Long value2) {
addCriterion("view_count not between", value1, value2, "viewCount");
return (Criteria) this;
}
}
/**
*/
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@ -6,14 +6,19 @@ import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.UserQueryVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.client.user.*;
import club.joylink.rtss.vo.client.user.MobileInfoVO;
import club.joylink.rtss.vo.client.user.RetrievePwdVO;
import club.joylink.rtss.vo.client.user.UpdateEmailVO;
import club.joylink.rtss.vo.client.user.UpdateMobileVO;
import club.joylink.rtss.vo.client.user.UpdatePasswordVO;
import club.joylink.rtss.vo.client.user.WeChatBindStatusVO;
import club.joylink.rtss.vo.user.AccountCreateVO;
import club.joylink.rtss.vo.user.AccountRegisterVO;
import club.joylink.rtss.vo.wx.WmUserSession;
import java.util.Map;
import lombok.NonNull;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotEmpty;
import lombok.NonNull;
public interface ISysUserService {
@ -337,7 +342,7 @@ public interface ISysUserService {
*/
List<AccountVO> queryAdminsAndSuperAdmins();
AccountVO queryOrCreateThirdAccount(String parentAccount, String account);
AccountVO queryOrCreateThirdAccount(String parentAccount, String account, @NotEmpty String name);
AccountVO getThirdAccount(String account);

View File

@ -6,14 +6,25 @@ import club.joylink.rtss.constants.SystemEnv;
import club.joylink.rtss.dao.LearnCommentDAO;
import club.joylink.rtss.dao.LearnMessageDAO;
import club.joylink.rtss.dao.LearnPostDAO;
import club.joylink.rtss.entity.*;
import club.joylink.rtss.entity.LearnComment;
import club.joylink.rtss.entity.LearnCommentExample;
import club.joylink.rtss.entity.LearnMessage;
import club.joylink.rtss.entity.LearnMessageExample;
import club.joylink.rtss.entity.LearnPost;
import club.joylink.rtss.entity.LearnPostExample;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.client.PageQueryVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.learn.*;
import club.joylink.rtss.vo.client.learn.LearnCommentUpdateVO;
import club.joylink.rtss.vo.client.learn.LearnCommentVO;
import club.joylink.rtss.vo.client.learn.LearnCreateVO;
import club.joylink.rtss.vo.client.learn.LearnMessageUpdateVO;
import club.joylink.rtss.vo.client.learn.LearnPostCreateVO;
import club.joylink.rtss.vo.client.learn.LearnPostUpdateVO;
import club.joylink.rtss.vo.client.learn.LearnPostVO;
import club.joylink.rtss.vo.client.post.LearnMessageCreateVO;
import club.joylink.rtss.vo.client.post.LearnMessagePagedQueryVO;
import club.joylink.rtss.vo.client.post.LearnMessageVO;
@ -22,18 +33,23 @@ import club.joylink.rtss.wechat.MiniProgramService;
import club.joylink.rtss.wechat.vo.WxError;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -48,9 +64,6 @@ public class LearnService implements ILearnService {
@Autowired
private ISysUserService iSysUserService;
@Autowired
private RestTemplate restTemplate;
@Autowired
private WeChatConfig weChatConfig;
@ -71,7 +84,8 @@ public class LearnService implements ILearnService {
example.createCriteria().andProjectEqualTo(queryVO.getProject());
}
Page<LearnPost> page = (Page<LearnPost>) learnPostDAO.selectByExample(example);
List<LearnPostVO> vos = page.getResult().stream().map(LearnPostVO::new).collect(Collectors.toList());
List<LearnPostVO> vos = page.getResult().stream().map(LearnPostVO::new)
.collect(Collectors.toList());
return PageVO.convert(page, vos);
}
@ -161,11 +175,13 @@ public class LearnService implements ILearnService {
}
// 回复的用户的昵称
if (comment.getParentId() != null) {
commentVO.setReplyUserNickName(iSysUserService.findUserById(comment.getParentId()).getNickname());
commentVO.setReplyUserNickName(
iSysUserService.findUserById(comment.getParentId()).getNickname());
}
// 回复数
LearnCommentExample learnCommentExample = new LearnCommentExample();
learnCommentExample.createCriteria().andMessageIdEqualTo(comment.getMessageId()).andRootIdEqualTo(comment.getId());
learnCommentExample.createCriteria().andMessageIdEqualTo(comment.getMessageId())
.andRootIdEqualTo(comment.getId());
commentVO.setCommentCount(learnCommentDAO.countByExample(learnCommentExample));
return commentVO;
}
@ -185,7 +201,8 @@ public class LearnService implements ILearnService {
}
@Override
public void addComment(Long messageId, Long commentId, LearnCreateVO postCreateVO, AccountVO accountVO) {
public void addComment(Long messageId, Long commentId, LearnCreateVO postCreateVO,
AccountVO accountVO) {
checkMessageExist(messageId);
if (SystemEnv.isPrdEnv(otherConfig.getEnv())) {
this.checkContent(postCreateVO.getContent());
@ -241,7 +258,8 @@ public class LearnService implements ILearnService {
//删除留言
LearnMessageExample messageExample = new LearnMessageExample();
messageExample.createCriteria().andPostIdEqualTo(postId);
List<Long> messageIds = learnMessageDAO.selectByExample(messageExample).stream().map(LearnMessage::getId).collect(Collectors.toList());
List<Long> messageIds = learnMessageDAO.selectByExample(messageExample).stream()
.map(LearnMessage::getId).collect(Collectors.toList());
learnMessageDAO.deleteByExample(messageExample);
//删除评论
LearnCommentExample commentExample = new LearnCommentExample();
@ -268,7 +286,8 @@ public class LearnService implements ILearnService {
@Override
public long createMessage(LearnMessageCreateVO messageCreateVO, AccountVO user) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(StringUtils.hasText(messageCreateVO.getContent()),
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(
StringUtils.hasText(messageCreateVO.getContent()),
"内容不能空白");
if (SystemEnv.isPrdEnv(otherConfig.getEnv())) {
this.checkContent(messageCreateVO.getContent());
@ -281,7 +300,8 @@ public class LearnService implements ILearnService {
}
@Override
public PageVO<LearnMessageVO> pagedQueryMessageByPostId(Long postId, LearnMessagePagedQueryVO queryVO) {
public PageVO<LearnMessageVO> pagedQueryMessageByPostId(Long postId,
LearnMessagePagedQueryVO queryVO) {
PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize());
Page<LearnMessageVO> page = (Page<LearnMessageVO>) learnMessageDAO.select(postId, queryVO);
for (LearnMessageVO vo : page.getResult()) {
@ -318,7 +338,8 @@ public class LearnService implements ILearnService {
}
@Override
public PageVO<LearnMessageVO> pagedQueryMessageByProject(String project, LearnMessagePagedQueryVO queryVO) {
public PageVO<LearnMessageVO> pagedQueryMessageByProject(String project,
LearnMessagePagedQueryVO queryVO) {
LearnPostVO post = queryPost(project);
if (post == null) {
log.error(String.format("项目[%s]的留言板不存在", project));
@ -331,15 +352,17 @@ public class LearnService implements ILearnService {
public void updatePost(Long postId, LearnPostUpdateVO updateVO, AccountVO user) {
iSysUserService.confirmAdmin(user);
LearnPost entity = getPostEntity(postId);
if (Objects.equals(updateVO.getTitle(), entity.getTitle()))
if (Objects.equals(updateVO.getTitle(), entity.getTitle())) {
return;
}
entity.setTitle(updateVO.getTitle());
learnPostDAO.updateByPrimaryKey(entity);
}
@Override
public long cgyCreateMessage(LearnMessageCreateVO messageCreateVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(StringUtils.hasText(messageCreateVO.getContent()),
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(
StringUtils.hasText(messageCreateVO.getContent()),
"内容不能空白");
LearnMessage message = messageCreateVO.convert2DB(1L);
message.setCreatorId(null);
@ -407,10 +430,13 @@ public class LearnService implements ILearnService {
example.createCriteria().andPostIdEqualTo(27L);
List<LearnMessage> allMessage = learnMessageDAO.selectByExample(example);
//删重复数据
List<LearnMessage> list = allMessage.stream().collect(Collectors.toMap(LearnMessage::getContent, Function.identity(), (old, newValue) -> old))
.values().stream().sorted(Comparator.comparingLong(LearnMessage::getId)).collect(Collectors.toList());
List<LearnMessage> list = allMessage.stream().collect(
Collectors.toMap(LearnMessage::getContent, Function.identity(), (old, newValue) -> old))
.values().stream().sorted(Comparator.comparingLong(LearnMessage::getId))
.collect(Collectors.toList());
HashSet<LearnMessage> distinctSet = new HashSet<>(list);
List<Long> deleteIds = allMessage.stream().filter(message -> !distinctSet.contains(message)).map(LearnMessage::getId).collect(Collectors.toList());
List<Long> deleteIds = allMessage.stream().filter(message -> !distinctSet.contains(message))
.map(LearnMessage::getId).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(deleteIds)) {
example.clear();
example.createCriteria().andIdIn(deleteIds);
@ -424,7 +450,8 @@ public class LearnService implements ILearnService {
dayOffsetList.add(random.nextInt(day));
}
dayOffsetList.sort((i1, i2) -> i2 - i1);
Map<Integer, Long> dayCountMap = dayOffsetList.stream().collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting()));
Map<Integer, Long> dayCountMap = dayOffsetList.stream().collect(
Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting()));
int startIndex = 0;
LocalDateTime now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
for (Integer dayOffset : dayCountMap.keySet()) {
@ -436,7 +463,8 @@ public class LearnService implements ILearnService {
}
for (int i = startIndex; i < startIndex + dayCount; i++) {
LearnMessage message = list.get(i);
message.setCreateTime(now.minusDays(dayOffset).plusSeconds(secondsOffsetList.get(i - startIndex)));
message.setCreateTime(
now.minusDays(dayOffset).plusSeconds(secondsOffsetList.get(i - startIndex)));
learnMessageDAO.updateByPrimaryKey(message);
}
startIndex += dayCount;
@ -519,7 +547,8 @@ public class LearnService implements ILearnService {
private LearnMessage getMessageEntity(Long messageId) {
LearnMessage message = findMessageEntity(messageId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(message, String.format("id为[%s]的留言不存在", messageId));
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(message,
String.format("id为[%s]的留言不存在", messageId));
return message;
}
@ -539,7 +568,8 @@ public class LearnService implements ILearnService {
private void confirmPostIsNotExist(String project) {
LearnPostExample example = new LearnPostExample();
example.createCriteria().andProjectEqualTo(project);
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(learnPostDAO.countByExample(example) == 0,
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(
learnPostDAO.countByExample(example) == 0,
String.format("项目[%s]下留言板已存在", project));
}
}

View File

@ -6,7 +6,12 @@ import club.joylink.rtss.constants.StatusEnum;
import club.joylink.rtss.dao.OrgDAO;
import club.joylink.rtss.dao.SysAccountDAO;
import club.joylink.rtss.dao.UserSubscribeMapper;
import club.joylink.rtss.entity.*;
import club.joylink.rtss.entity.Org;
import club.joylink.rtss.entity.OrgUser;
import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.entity.SysAccountExample;
import club.joylink.rtss.entity.UserSubscribe;
import club.joylink.rtss.entity.UserSubscribeExample;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.cache.ICacheService;
import club.joylink.rtss.services.org.IOrgProjectService;
@ -14,10 +19,19 @@ import club.joylink.rtss.services.org.IOrgService;
import club.joylink.rtss.services.org.IOrgUserService;
import club.joylink.rtss.util.EncryptUtil;
import club.joylink.rtss.util.RandomGenerator;
import club.joylink.rtss.vo.*;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.SmsResponse;
import club.joylink.rtss.vo.UserQueryVO;
import club.joylink.rtss.vo.VdCode;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.org.OrgVO;
import club.joylink.rtss.vo.client.user.*;
import club.joylink.rtss.vo.client.user.MobileInfoVO;
import club.joylink.rtss.vo.client.user.RetrievePwdVO;
import club.joylink.rtss.vo.client.user.UpdateEmailVO;
import club.joylink.rtss.vo.client.user.UpdateMobileVO;
import club.joylink.rtss.vo.client.user.UpdatePasswordVO;
import club.joylink.rtss.vo.client.user.WeChatBindStatusVO;
import club.joylink.rtss.vo.map.MapVO;
import club.joylink.rtss.vo.user.AccountCreateVO;
import club.joylink.rtss.vo.user.AccountRegisterVO;
@ -25,6 +39,18 @@ import club.joylink.rtss.vo.wx.WmUserSession;
import club.joylink.rtss.vo.wx.WxUserGet;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -34,13 +60,6 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@Slf4j
public class SysUserService implements ISysUserService {
@ -360,7 +379,8 @@ public class SysUserService implements ISysUserService {
BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotHasText(account.getWmOpenId(),
String.format("用户[%s]已经绑定微信小程序", account.getNickname()));
// 如果之前已经存在绑定解除之前的绑定
WmUserSession userSession = this.iWxApiService.getWmUserSession(WxApiService.MiniApp.JoyLink, code);
WmUserSession userSession = this.iWxApiService.getWmUserSession(WxApiService.MiniApp.JoyLink,
code);
String openid = userSession.getOpenid();
SysAccountExample example = new SysAccountExample();
example.createCriteria()
@ -392,7 +412,8 @@ public class SysUserService implements ISysUserService {
@Transactional
public OrgVO userScanCodeBindCompanyManager(Long userId, Long companyId) {
SysAccount sysAccount = sysAccountDAO.selectByPrimaryKey(userId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(sysAccount, String.format("id为[%s]的用户不存在", userId));
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(sysAccount,
String.format("id为[%s]的用户不存在", userId));
AccountVO accountVO = new AccountVO(sysAccount);
OrgVO orgVO = iOrgUserService.userBindCompanyManager(accountVO, companyId);
this.loginSessionManager.updateLoginUser(accountVO);
@ -655,7 +676,8 @@ public class SysUserService implements ISysUserService {
@Override
public void updateMobile(Long id, UpdateMobileVO updateMobileVO) {
Objects.requireNonNull(id, "用户id不能为空");
validateMobileVerificationCode(updateMobileVO.getNationCode(), updateMobileVO.getMobile(), updateMobileVO.getValidCode());
validateMobileVerificationCode(updateMobileVO.getNationCode(), updateMobileVO.getMobile(),
updateMobileVO.getValidCode());
SysAccount account = this.sysAccountDAO.selectByPrimaryKey(id);
if (Objects.nonNull(account)) {
account.setNationcode(updateMobileVO.getNationCode());
@ -666,7 +688,8 @@ public class SysUserService implements ISysUserService {
}
}
private void validateMobileVerificationCode(String nationCode, String mobile, String verificationCode) {
private void validateMobileVerificationCode(String nationCode, String mobile,
String verificationCode) {
VdCode vdCode = (VdCode) this.iCacheService.get(nationCode + mobile);
// 验证验证码
BusinessExceptionAssertEnum.INCORRECT_VERIFICATION_CODE.assertNotNull(vdCode);
@ -705,16 +728,20 @@ public class SysUserService implements ISysUserService {
@Override
public String sendMobileValidCode(MobileInfoVO mobileInfoVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(mobileInfoVO.validate(), "发送验证码请求未通过");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(mobileInfoVO.validate(),
"发送验证码请求未通过");
String code = RandomGenerator.getByLen(4);
long ts = System.currentTimeMillis();
List<String> params = new ArrayList<>();
params.add(code);
params.add(VdCode.CODE_TIMEOUT + "");
SmsResponse resp = this.iSmsService.sendValidateCode(mobileInfoVO.getMobile(), mobileInfoVO.getNationCode(), params, ts);
SmsResponse resp = this.iSmsService.sendValidateCode(mobileInfoVO.getMobile(),
mobileInfoVO.getNationCode(), params, ts);
BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.assertTrue(resp.getResult() == 0,
String.format("短信发送服务调用异常:[result: %s, errmsg: %s]", resp.getResult(), resp.getErrmsg()));
iCacheService.putExpired(mobileInfoVO.buildUp(), new VdCode(code, ts), VdCode.CODE_TIMEOUT, TimeUnit.MINUTES);
String.format("短信发送服务调用异常:[result: %s, errmsg: %s]", resp.getResult(),
resp.getErrmsg()));
iCacheService.putExpired(mobileInfoVO.buildUp(), new VdCode(code, ts), VdCode.CODE_TIMEOUT,
TimeUnit.MINUTES);
log.debug(String.format("短息发送手机%s验证码[%s]", mobileInfoVO.buildUp(), code));
return EncryptUtil.md5(code);
}
@ -729,7 +756,8 @@ public class SysUserService implements ISysUserService {
private void updatePwdByMobileVdCode(UpdatePasswordVO updatePasswordVO, SysAccount account) {
if (Objects.nonNull(account)) {
VdCode vdCode = (VdCode) this.iCacheService.get(account.getNationcode() + account.getMobile());
VdCode vdCode = (VdCode) this.iCacheService.get(
account.getNationcode() + account.getMobile());
BusinessExceptionAssertEnum.INCORRECT_VERIFICATION_CODE.assertNotNull(vdCode);
// 验证验证码
vdCode.isValidCode(updatePasswordVO.getVfCode());
@ -787,7 +815,8 @@ public class SysUserService implements ISysUserService {
SysAccountExample example = new SysAccountExample();
example.createCriteria().andNameLike(String.format("%%%s%%", name));
List<SysAccount> users = sysAccountDAO.selectByExample(example);
List<AccountVO> voList = users.stream().map(account -> new AccountVO(account)).collect(Collectors.toList());
List<AccountVO> voList = users.stream().map(account -> new AccountVO(account))
.collect(Collectors.toList());
return voList;
}
@ -800,7 +829,8 @@ public class SysUserService implements ISysUserService {
@Override
public List<AccountVO> getUsersWithEmail() {
SysAccountExample example = new SysAccountExample();
example.createCriteria().andMobileIsNotNull().andNationcodeIsNotNull().andStatusEqualTo(BusinessConsts.STATUS_USE);
example.createCriteria().andMobileIsNotNull().andNationcodeIsNotNull()
.andStatusEqualTo(BusinessConsts.STATUS_USE);
List<SysAccount> sysUsers = sysAccountDAO.selectByExample(example);
List<AccountVO> users = sysUsers.stream().map(AccountVO::new).collect(Collectors.toList());
return users;
@ -882,7 +912,8 @@ public class SysUserService implements ISysUserService {
private SysAccount getEntity(Long id) {
SysAccount account = sysAccountDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(account, String.format("id为[%s]的用户不存在", id));
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(account,
String.format("id为[%s]的用户不存在", id));
return account;
}
@ -893,7 +924,8 @@ public class SysUserService implements ISysUserService {
@Override
public void register(AccountCreateVO accountCreateVO) {
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(this.isSameEmailExist(accountCreateVO.getEmail()));
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(
this.isSameEmailExist(accountCreateVO.getEmail()));
SysAccount account = accountCreateVO.toDB();
account.setRoles(BusinessConsts.ROLE_01);
account.setCreateTime(LocalDateTime.now());
@ -918,7 +950,7 @@ public class SysUserService implements ISysUserService {
}
@Override
public AccountVO queryOrCreateThirdAccount(String parentAccount, String account) {
public AccountVO queryOrCreateThirdAccount(String parentAccount, String account, String name) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(parentAccount);
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(account);
String key = parentAccount + account;
@ -939,9 +971,14 @@ public class SysUserService implements ISysUserService {
SysAccount sysAccount = new SysAccount();
sysAccount.setAccount(account);
sysAccount.setParentAccount(parentAccount);
if (StringUtils.hasText(name)) {
sysAccount.setName(name);
sysAccount.setNickname(name);
} else {
sysAccount.setNickname(String.format("第三方账户%s", account));
}
sysAccount.setType(AccountVO.Type_3);
String initPassword = EncryptUtil.md5("123456");
String initPassword = EncryptUtil.md5(BusinessConsts.DEFAULT_PASSWORD);
sysAccount.setPassword(initPassword);
sysAccount.setStatus(BusinessConsts.STATUS_USE);
sysAccount.setRoles(BusinessConsts.ROLE_01);
@ -1017,10 +1054,13 @@ public class SysUserService implements ISysUserService {
@Override
public void register2(AccountRegisterVO registerVO) {
if (StringUtils.hasText(registerVO.getMobile())) {
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(isSameMobileExist(registerVO.getMobile()));
validateMobileVerificationCode(registerVO.getNationCode(), registerVO.getMobile(), registerVO.getVerificationCode());
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(
isSameMobileExist(registerVO.getMobile()));
validateMobileVerificationCode(registerVO.getNationCode(), registerVO.getMobile(),
registerVO.getVerificationCode());
} else if (StringUtils.hasText(registerVO.getEmail())) {
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(isSameEmailExist(registerVO.getEmail()));
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(
isSameEmailExist(registerVO.getEmail()));
validateEmailVerificationCode(registerVO.getEmail(), registerVO.getVerificationCode());
}
SysAccount sysAccount = registerVO.toDB();
@ -1097,7 +1137,8 @@ public class SysUserService implements ISysUserService {
* @param account
*/
private void updateLoginUserInfoWithOrgInfo(SysAccount account) {
List<LoginUserInfoVO> loginUserInfoVOS = loginSessionManager.queryLoginInfoByUserId(account.getId());
List<LoginUserInfoVO> loginUserInfoVOS = loginSessionManager.queryLoginInfoByUserId(
account.getId());
if (!CollectionUtils.isEmpty(loginUserInfoVOS)) {
for (LoginUserInfoVO loginInfo : loginUserInfoVOS) {
AccountVO oldAccountVO = loginInfo.getAccountVO();

View File

@ -3,6 +3,7 @@ package club.joylink.rtss.services.auth;
import club.joylink.rtss.configuration.configProp.OtherConfig;
import club.joylink.rtss.configuration.configProp.WeChatConfig;
import club.joylink.rtss.constants.Client;
import club.joylink.rtss.constants.ProjectCode;
import club.joylink.rtss.dao.SysAccountLoginDAO;
import club.joylink.rtss.entity.SysAccountLogin;
import club.joylink.rtss.entity.project.Project;
@ -22,6 +23,7 @@ import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.LoginStatusVO;
import club.joylink.rtss.vo.client.LoginUserVO;
import club.joylink.rtss.vo.client.SocketMessageVO;
import club.joylink.rtss.vo.client.cgy.CgyThirdPartyLoginInfoVO;
import club.joylink.rtss.vo.client.factory.SocketMessageFactory;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.RelationLoginConfigVO;
@ -239,6 +241,24 @@ public class AuthenticateService implements IAuthenticateService {
}
}
@Override
public String cgyThirdPartyLogin(CgyThirdPartyLoginInfoVO loginInfo) {
BusinessExceptionAssertEnum.INVALID_OPERATION
.assertTrue(this.iSysUserService.isThirdParentAccountExist(loginInfo.getParentAccount()),
String.format("成工院父账号不存在: %s", loginInfo.getParentAccount()));
AccountVO accountVO = this.iSysUserService.queryOrCreateThirdAccount(
loginInfo.getParentAccount(),
loginInfo.getAccount(),
loginInfo.getName());
ProjectVO projectVO = projectService.queryLoginProjectByCode(ProjectCode.CGY);
// 构造登陆用户信息
LoginUserInfoVO loginUserInfo = new LoginUserInfoVO(accountVO, Client.Joylink, projectVO, null);
loginUserInfo.setThirdLogin(true);
// 执行登录
login(loginUserInfo, true);
return loginUserInfo.getToken();
}
/**
* @update 20221019 去除设置组织信息
*/
@ -384,8 +404,7 @@ public class AuthenticateService implements IAuthenticateService {
.assertTrue(this.iSysUserService.isThirdParentAccountExist(loginInfo.getParentAccount()),
String.format("第三方企业账号不存在: %s", loginInfo.getParentAccount()));
AccountVO accountVO = this.iSysUserService.queryOrCreateThirdAccount(
loginInfo.getParentAccount(),
loginInfo.getAccount());
loginInfo.getParentAccount(), loginInfo.getAccount(), null);
Client client = Client.getByIdAndSecret(loginInfo.getClientId(), loginInfo.getSecret());
ProjectVO projectVO = projectService.queryLoginProjectByCode(loginInfo.getProject());
// 构造登陆用户信息

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.LoginStatusVO;
import club.joylink.rtss.vo.client.LoginUserVO;
import club.joylink.rtss.vo.client.cgy.CgyThirdPartyLoginInfoVO;
public interface IAuthenticateService {
@ -64,7 +65,8 @@ public interface IAuthenticateService {
* <p>
* 测试文档后删除相关注释
*/
LoginStatusVO getWmLoginUrl(String clientId, String secret, String projectCode, String deviceCode);
LoginStatusVO getWmLoginUrl(String clientId, String secret, String projectCode,
String deviceCode);
/**
* 微信小程序确认登陆
@ -121,4 +123,9 @@ public interface IAuthenticateService {
* @param token
*/
void preLogout(String token);
/**
* 成工业虚仿平台跳转登录接口
*/
String cgyThirdPartyLogin(CgyThirdPartyLoginInfoVO loginInfo);
}

View File

@ -0,0 +1,175 @@
package club.joylink.rtss.services.cgy;
import club.joylink.rtss.bo.cgy.CgyStatsBO;
import club.joylink.rtss.dao.CgyViewDAO;
import club.joylink.rtss.entity.CgyView;
import club.joylink.rtss.entity.CgyViewExample;
import club.joylink.rtss.entity.UserSimulationRecord;
import club.joylink.rtss.event.UserSimulationRecordEvent;
import club.joylink.rtss.services.user.UserSimulationRecordService;
import club.joylink.rtss.simulation.cbtc.SimulationService;
import club.joylink.rtss.simulation.vo.SimulationInfoVO;
import club.joylink.rtss.util.EncryptUtil;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.simulationUsage.SimulationUsageRecordQueryVO;
import club.joylink.rtss.vo.client.simulationv1.SimulationInfoQueryVO;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import javax.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
/**
* 成工院虚仿平台对接统计服务
*/
@Slf4j
@Service
public class CgyStatsService {
private CgyViewDAO cgyViewDAO;
private UserSimulationRecordService userSimulationRecordService;
private SimulationService simulationService;
private RestTemplate restTemplate;
@Autowired
public CgyStatsService(CgyViewDAO cgyViewDAO,
UserSimulationRecordService userSimulationRecordService,
SimulationService simulationService, RestTemplate restTemplate) {
this.cgyViewDAO = cgyViewDAO;
this.userSimulationRecordService = userSimulationRecordService;
this.simulationService = simulationService;
this.restTemplate = restTemplate;
}
private final ConcurrentHashMap<String, CgyStatsBO> appStatsMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Long, CgyStatsBO> functionStatsMap = new ConcurrentHashMap<>();
@PostConstruct
public void makeCache() {
List<CgyView> cgyViews = cgyViewDAO.selectByExample(new CgyViewExample());
if (CollectionUtils.isEmpty(cgyViews)) {
return;
}
cgyViews.forEach(cgyView -> {
CgyStatsBO bo = new CgyStatsBO(cgyView.getAppId(), cgyView.getAppSecret(),
cgyView.getFunctionId());
bo.setView(new AtomicLong(cgyView.getViewCount()));
makeCache(bo);
appStatsMap.put(cgyView.getAppId(), bo);
functionStatsMap.put(cgyView.getFunctionId(), bo);
});
}
/**
* 向虚仿平台同步数据
*/
@Scheduled(fixedRate = 2000)
public void syncData() {
appStatsMap.forEach((appId, statsBO) -> {
if (!statsBO.getChange().getAndSet(false)) {
return;
}
//同步汇总数据
Map<String, Object> body = new HashMap<>();
body.put("appId", appId);
body.put("timestamp", System.currentTimeMillis());
body.put("view", statsBO.getView().get());
body.put("visitor", statsBO.getVisitor().get());
body.put("user", statsBO.getUserSet().size());
//扩展字段
body.put("duration", statsBO.getDuration().get());
SimulationInfoQueryVO queryVO = new SimulationInfoQueryVO();
queryVO.setFunctionId(statsBO.getFunctionId());
List<SimulationInfoVO> sims = simulationService.listAllSimulation(queryVO);
body.put("onlineUser", sims.size());
String sb = "appId="
+ body.get("appId") + "&"
+ "timestamp="
+ body.get("timestamp") + "&"
+ "user="
+ body.get("user") + "&"
+ "view="
+ body.get("view") + "&"
+ "visitor="
+ body.get("visitor") + "&"
+ "app_secret="
+ statsBO.getAppSecret();
body.put("sign", EncryptUtil.md5(sb).toLowerCase());
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> httpEntity = new HttpEntity<>(JsonUtils.writeValueAsString(body),
httpHeaders);
Map<String, String> resBody = restTemplate.postForObject(
"/api/applicationCenter/openapi/summary", httpEntity, Map.class);
if (resBody != null && Objects.equals(resBody.get("code"), "100001")) {
log.error(String.format("成工院虚仿平台同步数据失败:[%s][%s]", resBody.get("msg"),
resBody.get("data")));
}
});
}
@Async("thirdAccountDataSyncExecutor")
@EventListener
public void syncUserSimulationUsing(UserSimulationRecordEvent event) {
UserSimulationRecord record = event.getRecord();
CgyStatsBO cgyStatsBO = functionStatsMap.get(record.getFunctionId());
cgyStatsBO.getVisitor().incrementAndGet();
cgyStatsBO.getUserSet().add(record.getUserId());
cgyStatsBO.getDuration().addAndGet(record.getDuration());
cgyStatsBO.getChange().set(true);
}
/**
* 更新此App的浏览量数据
*/
public void updateView(String appId) {
CgyStatsBO cgyStatsBO = appStatsMap.get(appId);
if (cgyStatsBO == null) {
log.warn(String.format("成工院虚仿平台未知的appId%s", appId));
return;
}
long count = cgyStatsBO.getView().incrementAndGet();
CgyView record = new CgyView();
record.setAppId(appId);
record.setViewCount(count);
CgyViewExample example = new CgyViewExample();
example.createCriteria().andAppIdEqualTo(appId).andViewCountLessThan(count);
cgyViewDAO.updateByExampleSelective(record, example);
cgyStatsBO.getChange().set(true);
}
/**
* 实训人数实训人次实训时长缓存
*/
private void makeCache(CgyStatsBO bo) {
long visitor = 0;
long duration = 0;
//实训人数人次时长
List<UserSimulationRecord> records = userSimulationRecordService.listSimulationUsageRecords(
new SimulationUsageRecordQueryVO(null, bo.getFunctionId()));
if (!CollectionUtils.isEmpty(records)) {
visitor = records.size();
for (UserSimulationRecord record : records) {
bo.getUserSet().add(record.getUserId()); //实训人数
duration += record.getDuration();
}
}
bo.setVisitor(new AtomicLong(visitor)); //实训人次
bo.setDuration(new AtomicLong(duration)); //实训时长
}
}

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.entity.RtsMapFunction;
import club.joylink.rtss.entity.SysAccount;
import club.joylink.rtss.entity.UserSimulationRecord;
import club.joylink.rtss.entity.UserSimulationRecordExample;
import club.joylink.rtss.entity.UserSimulationRecordExample.Criteria;
import club.joylink.rtss.event.UserSimulationRecordEvent;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.IMapService;
@ -13,6 +14,7 @@ import club.joylink.rtss.services.mapFunction.RtsMapFunctionService;
import club.joylink.rtss.simulation.cbtc.message.UserSimulationRecordManager;
import club.joylink.rtss.util.TimeUnit;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.simulationUsage.SimulationUsageRecordQueryVO;
import club.joylink.rtss.vo.client.simulationUsage.UserSimulationQueryVO;
import club.joylink.rtss.vo.client.simulationUsage.UserSimulationRecordVO;
import club.joylink.rtss.vo.client.simulationUsage.UserSimulationStatsVO;
@ -66,7 +68,8 @@ public class UserSimulationRecordService {
}
public List<UserSimulationRecord> queryByMapAndUserIds(Long mapId, List<Long> userIds) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertCollectionNotEmpty(userIds, "用户列表不能为空");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertCollectionNotEmpty(userIds,
"用户列表不能为空");
UserSimulationRecordExample example = new UserSimulationRecordExample();
example.createCriteria().andMapIdEqualTo(mapId).andUserIdIn(userIds);
return userSimulationRecordDAO.selectByExample(example);
@ -165,6 +168,22 @@ public class UserSimulationRecordService {
return statistic(startTime, endTime, timeUnit, list);
}
/**
* 查询仿真使用记录
*/
public List<UserSimulationRecord> listSimulationUsageRecords(
SimulationUsageRecordQueryVO queryVO) {
UserSimulationRecordExample example = new UserSimulationRecordExample();
Criteria criteria = example.createCriteria();
if (queryVO.getUid() != null) {
criteria.andUserIdEqualTo(queryVO.getUid());
}
if (queryVO.getFunctionId() != null) {
criteria.andFunctionIdEqualTo(queryVO.getFunctionId());
}
return userSimulationRecordDAO.selectByExample(example);
}
/**
* 对使用记录按照时间单位开始结束时间分段统计
*/
@ -223,9 +242,12 @@ public class UserSimulationRecordService {
}
private void checkParam(UserSimulationQueryVO queryVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getTimeUnit(), "缺少时间单位");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getStartTime(), "缺少开始时间");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getEndTime(), "缺少结束时间");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getTimeUnit(),
"缺少时间单位");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getStartTime(),
"缺少开始时间");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(queryVO.getEndTime(),
"缺少结束时间");
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(
!queryVO.getStartTime().isAfter(queryVO.getEndTime()), "开始时间不能晚于结束时间");
}

View File

@ -1,78 +0,0 @@
/*
package club.joylink.rtss.services.voice.huawei;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.voice.IVoiceService;
import club.joylink.rtss.util.VoiceFileUtils;
import club.joylink.rtss.vo.client.VoiceRecognitionResult;
import com.huawei.sis.bean.AuthInfo;
import com.huawei.sis.bean.SisConfig;
import com.huawei.sis.bean.request.AsrCustomShortRequest;
import com.huawei.sis.bean.response.AsrCustomShortResponse;
import com.huawei.sis.client.AsrCustomizationClient;
import com.huawei.sis.exception.SisException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Base64;
@Slf4j
@Service("HuaWeiVoiceService")
public class HuaweiVoiceServiceImpl implements IVoiceService {
@Override
public String synthesis(String message, String per) {
throw BusinessExceptionAssertEnum.THIRD_SERVICE_CALL_EXCEPTION.exception("功能暂未实现");
}
@Override
public String synthesis(String message) {
return this.synthesis(message, "0");
}
*/
/**
* 华为语音识别配置
*//*
private final String ak = "YDUXTXRYGAHGPHAIXZCU";
private final String sk = "Kcbm3sTDCYEou8kGeAhKxfBkgWybIn6IjJyGBX3p";
private final String region = "cn-north-4";
private final String projectId = "0aada8176180f28c2f34c0196f5394e8";
@Override
public VoiceRecognitionResult voiceRecognition(MultipartFile file, String lang) {
String filePath = VoiceFileUtils.saveFile(file);
try {
return voiceRecognition(file.getBytes(), filePath);
} catch (IOException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("第三方服务调用异常");
}
}
@Override
public VoiceRecognitionResult voiceRecognition(byte[] bytes, String filePath) {
AuthInfo authInfo = new AuthInfo(ak, sk, region, projectId);
SisConfig sisConfig = new SisConfig();
AsrCustomizationClient client = new AsrCustomizationClient(authInfo, sisConfig);
String data = Base64.getEncoder().encodeToString(bytes);
try {
AsrCustomShortRequest request = new AsrCustomShortRequest(data, "pcm16k16bit", "chinese_16k_common");
AsrCustomShortResponse response = client.getAsrShortResponse(request);
return new VoiceRecognitionResult(filePath, response.getResult().getText());
} catch (SisException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("语音识别失败", e);
}
}
@Override
public VoiceRecognitionResult voiceRecognition(String fileBase64) {
String base64 = fileBase64.substring(fileBase64.indexOf("base64,") + "base64,".length());
byte[] bytes = Base64.getDecoder().decode(base64.trim());
String filePath = VoiceFileUtils.saveFile(bytes);
return voiceRecognition(bytes, filePath);
}
}
*/

View File

@ -1,154 +0,0 @@
//package club.joylink.rtss.simulation;
//
//import club.joylink.rtss.simulation.operation.SimulationOperationDispatcher;
//import club.joylink.rtss.simulation.vo.SimulationFaultVO;
//import club.joylink.rtss.simulation.vo.SimulationInfoVO;
//import club.joylink.rtss.simulation.vo.SimulationMemberVO;
//import club.joylink.rtss.simulation.vo.SimulationUserVO;
//import club.joylink.rtss.vo.LoginUserInfoVO;
//import club.joylink.rtss.vo.client.simulationv1.SimulationInfoQueryVO;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.util.StringUtils;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//import java.util.Map;
//import java.util.Objects;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
//import static club.joylink.rtss.controller.advice.AuthenticateInterceptor.LOGIN_INFO_KEY;
//
///**
// * 仿真通用接口
// */
//@Slf4j
//@RestController
//@RequestMapping("/common/simulation")
//public class SimulationCommonController {
// @Autowired
// private SimulationManager simulationManager;
// @Autowired
// private SimulationOperationDispatcher simulationOperationDispatcher;
//
// /**
// * 监管仿真
// * @param loginUserInfoVO
// * @param queryVO
// * @return
// */
// @GetMapping("/supervise")
// public List<SimulationInfoVO> superviseSimulation(@RequestAttribute(name=LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO, SimulationInfoQueryVO queryVO) {
// List<Simulation> simulationList = this.simulationManager.getSimulationList();
// Stream<Simulation> stream = simulationList.stream();
//
// stream = stream.filter(simulation -> simulation instanceof club.joylink.rtss.simulation.cbtc.Simulation
// && Objects.equals(loginUserInfoVO.getTopOrgId(),((club.joylink.rtss.simulation.cbtc.Simulation)simulation).getBuildParams().getLoginUserInfo().getTopOrgId()));
//
// if (StringUtils.hasText(queryVO.getGroup())) {
// stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup()));
// }
// if (StringUtils.hasText(queryVO.getUserName())) {
// stream = stream.filter(simulation -> simulation.getSimulationUsers().stream().anyMatch(user -> ((SimulationUser) user).getName().contains(queryVO.getUserName())));
// }
// if (StringUtils.hasText(queryVO.getPrdType())) {
// stream = stream.filter(simulation -> simulation instanceof club.joylink.rtss.simulation.cbtc.Simulation
// && queryVO.getPrdType().equals(((club.joylink.rtss.simulation.cbtc.Simulation) simulation).getBuildParams().getProdType().getCode()));
// }
// return stream.map(Simulation::convertToVO).collect(Collectors.toList());
// }
//
// @GetMapping("/list")
// public List<SimulationInfoVO> queryInfo(SimulationInfoQueryVO queryVO) {
// List<Simulation> simulationList = this.simulationManager.getSimulationList();
// Stream<Simulation> stream = simulationList.stream();
// if (StringUtils.hasText(queryVO.getGroup())) {
// stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup()));
// }
// if (StringUtils.hasText(queryVO.getUserName())) {
// stream = stream.filter(simulation -> simulation.getSimulationUsers().stream().anyMatch(user -> ((SimulationUser) user).getName().contains(queryVO.getUserName())));
// }
// if (StringUtils.hasText(queryVO.getPrdType())) {
// stream = stream.filter(simulation -> simulation instanceof club.joylink.rtss.simulation.cbtc.Simulation
// && queryVO.getPrdType().equals(((club.joylink.rtss.simulation.cbtc.Simulation) simulation).getBuildParams().getProdType().getCode()));
// }
// return stream.map(Simulation::convertToVO).collect(Collectors.toList());
// }
//
// @PutMapping("/{id}/pause")
// public void pause(@PathVariable String id) {
// this.simulationManager.pause(id);
// }
//
// @PutMapping("/{id}/start")
// public void start(@PathVariable String id) {
// this.simulationManager.start(id);
// }
//
// @PutMapping("/{id}/init")
// public void init(@PathVariable String id) {
// this.simulationManager.init(id);
// }
//
// @PutMapping("/{id}/updateSpeed/{speed}")
// public void updateSpeed(@PathVariable String id, @PathVariable int speed) {
// this.simulationManager.updateSpeed(id, speed);
// }
//
// @GetMapping("/{id}")
// public SimulationInfoVO getSimulationInfo(@PathVariable String id) {
// return this.simulationManager.getById(id).convertToVO();
// }
//
// @GetMapping("/{id}/users")
// public List<SimulationUserVO> getSimulationUsers(@PathVariable String id) {
// return this.simulationManager.getSimulationUsers(id).stream()
// .map(SimulationUser::convertToVO)
// .collect(Collectors.toList());
// }
//
// @GetMapping("/{id}/members")
// public List<SimulationMemberVO> getSimulationMembers(@PathVariable String id, @RequestParam(required = false) String role) {
// return this.simulationManager.getSimulationMembers(id).stream()
// .map(SimulationMember::convertToVO)
// .filter(member -> StringUtils.hasText(role) ? member.getRole().toString().equals(role) : true)
// .collect(Collectors.toList());
// }
//
// @GetMapping("/{id}/member/playedBy/{userId}")
// public SimulationMemberVO queryUserPlayedMember(@PathVariable String id, @PathVariable String userId) {
// return this.simulationManager.getById(id)
// .getSimulationMemberByUserId(userId).convertToVO();
// }
//
// @PostMapping("/{id}/member/{memberId}/operate/{type}")
// public Object operate(@PathVariable String id, @PathVariable String memberId,
// @PathVariable String type, @RequestBody Map<String, Object> params) {
// return this.simulationOperationDispatcher.doDispatch(id, memberId, type, params);
// }
//
// /**
// * 故障注入
// */
// @PostMapping("/{id}/fault")
// public void injectFault(@PathVariable String id, @RequestBody SimulationFaultVO faultVO) {
// this.simulationManager.injectFault(id, faultVO);
// }
//
// @DeleteMapping("/{id}/device/{deviceId}/fault/{fault}")
// public void removeFault(@PathVariable String id, @PathVariable String deviceId, @PathVariable String fault) {
// this.simulationManager.removeFault(id, deviceId, fault);
// }
//
// @PutMapping("/{id}/member/{memberId}/playby/{userId}")
// public void memberPlay(@PathVariable String id, @PathVariable String memberId, @PathVariable String userId) {
// this.simulationManager.memberPlayedByUser(id, memberId, userId);
// }
//
// @DeleteMapping("/{id}/destroy")
// public void destroy(@PathVariable String id) {
// this.simulationManager.destroy(id);
// log.info(String.format("仿真通用接口销毁仿真[%s]", id));
// }
//}

View File

@ -1,687 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.ATP.ground;
//
//import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
//import club.joylink.rtss.simulation.cbtc.ATS.AtsApiService;
//import club.joylink.rtss.simulation.cbtc.CI.service.RouteService;
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.constant.RunLevel;
//import club.joylink.rtss.simulation.cbtc.data.CalculateService;
//import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
//import club.joylink.rtss.simulation.cbtc.data.map.*;
//import club.joylink.rtss.simulation.cbtc.data.support.MovementAuthority;
//import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
//import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService;
//import club.joylink.rtss.simulation.cbtc.onboard.ATP.OnboardAtpApiService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * ZC逻辑循环
// */
//@Slf4j
//@Component
//public class ZCLogicLoop {
//
// @Autowired
// private OnboardAtpApiService onboardAtpApiService;
//
// @Autowired
// private ATPService ATPService;
//
// @Autowired
// private AtsApiService atsApiService;
//
// @Autowired
// private MaService maService;
//
// @Autowired
// private RouteService routeService;
//
// public void run(Simulation simulation) {
// List<VirtualRealityTrain> trainList = simulation.getRepository().getOnlineTrainList();
// trainList.forEach(train -> {
// SectionPosition headPosition = train.getHeadPosition();
// Station deviceStation = headPosition.getSection().getDeviceStation();
// RunLevel defaultRunLevel = simulation.getRepository().getConfig().getRunMode();
// if (RunLevel.ITC.equals(defaultRunLevel)) { //如果线路最高运行级别为ITC级别
// if (!Station.Fault.INTERLOCK_MACHINE_FAULT.equals(deviceStation.getFault())) {
// this.calculateMAOfITC(simulation, train);
// }
// } else if (RunLevel.CBTC.equals(defaultRunLevel)) {
// //更新ITC ma
// if (!simulation.getRepository().hasResponder()) {
// if (!Station.Fault.INTERLOCK_MACHINE_FAULT.equals(deviceStation.getFault())) {
// Float distance2NextSignal = train.calculateDistance2NextNormalOpenSignal();
// if (distance2NextSignal != null && distance2NextSignal <= 5) {
// train.setPositioned(true);
// this.calculateMAOfITC(simulation, train);
// }
// }
// } else {
// simulation.getRepository().getSectionRespondersMap().forEach((section, responders) ->
// responders.stream()
// .filter(Responder::isVB)
// .forEach(responder -> {
// if (responder.getSignal().isNormalOpen()) {
// responder.setMa(this.calculateMAOfITC(simulation, responder));
// }
// }));
// }
// //更新CBTC ma
// if (train.isCommunicable()) {
// this.calculateMAOfCBTC(simulation, train, trainList);
// }
// }
// });
// }
//
// private void calculateMAOfCBTC(Simulation simulation, VirtualRealityTrain train,
// List<VirtualRealityTrain> trainList) {
// // 查找移动授权终端列表
// List<MovementAuthority.End> endList = this.findMaEnd(simulation, train, trainList);
// // 根据查找到的授权终端比较并构建最终的移动授权数据
// MovementAuthority ma = this.compareAndBuildMa(train, endList);
// // 通知车载ATP
// this.onboardAtpApiService.updateMA4CBTC(train, ma);
// }
//
// /**
// * 计算移动授权终端
// *
// * @param simulation
// * @param train
// * @param trainList
// * @return
// */
// private List<MovementAuthority.End> findMaEnd(Simulation simulation, VirtualRealityTrain train, List<VirtualRealityTrain> trainList) {
// // 从车尾开始找车尾主要查看是否在站台轨上且站台轨屏蔽门开放
// boolean right = train.isRight();
// SectionPosition headPosition = train.getHeadPosition();
// SectionPosition tailPosition = train.calculateTailPosition();
// Section tailSection = tailPosition.getSection();
// MovementAuthority.End openPsdEnd = checkPsdOpenOrClose(tailSection);
// List<MovementAuthority.End> endList = new ArrayList<>();
// if (openPsdEnd != null)
// endList.add(openPsdEnd);
// MovementAuthority.End ecStandEnd = checkEC(simulation.getRepository().getConfig(), tailSection);
// if (ecStandEnd != null)
// endList.add(ecStandEnd);
// MovementAuthority.End closedSection = checkClosedSection(tailSection);
// if (closedSection != null)
// return List.of(closedSection);
// // 如果车尾正常从车头开始往前查找
// Section section = headPosition.getSection();
// MovementAuthority.End switchEnd = checkSwitch(tailSection, section, right);
// if (switchEnd != null)
// return List.of(switchEnd);
// // 检查列车当前所在进路是否锁闭
//// MovementAuthority.End end1 = this.checkRouteLock(simulation, section, tailSection, right, train);
//// if (Objects.nonNull(end1)) {
//// endList.add(end1);
//// return endList;
//// }
//// // 检查车头区段是否故障
//// if (headPosition.getSection().isFault()) {
//// endList.add(new MovementAuthority.End(headPosition.getSection(), MovementAuthority.EndType.FAULT_SECTION));
//// }
// //非通信车占用区段
// if (section.hasNctOccupy() && !section.isInvalid()) {
// endList.add(new MovementAuthority.End(section, MovementAuthority.EndType.NCT_OCCUPIED_SECTION));
// return endList;
// }
// //通信车占用区段
// List<Section> occupiedLogicSectionList = simulation.getRepository().queryTrainOccupyAtpSectionList(train.getGroupNumber());
// Set<Section> occupiedLogicSectionSet;
// if (!CollectionUtils.isEmpty(occupiedLogicSectionList)) {
// occupiedLogicSectionSet = new HashSet<>(occupiedLogicSectionList);
// } else {
// occupiedLogicSectionSet = new HashSet<>();
// }
// List<Section> logicList = section.getLogicList();
// if (!CollectionUtils.isEmpty(logicList)) {
// Section logicSection = headPosition.getLogicSection();
// int index = logicList.indexOf(logicSection);
// if (right) {
// for (int i = index + 1; i < logicList.size(); i++) {
// MovementAuthority.End end = checkSectionOccupied(logicList.get(i), right, occupiedLogicSectionSet);
// if (end != null)
// endList.add(end);
// }
// } else {
// for (int i = index - 1; i >= 0; i--) {
// MovementAuthority.End end = checkSectionOccupied(logicList.get(i), right, occupiedLogicSectionSet);
// if (end != null)
// endList.add(end);
// }
// }
// }
// int count = 0;
// while (count < 50) {
// ++count;
//// // 区段未进路锁闭或延时解锁中转换轨除外因为出库列车加载到转换轨没有进路
//// if (!section.isTransferTrack()) {
//// if (section.isDelayUnlock()) {
//// deviceEnd = new MovementAuthority.End(section, MovementAuthority.EndType.UNLOCK_SECTION);
//// break;
//// }
//// if (!section.isRouteLock()) {
//// deviceEnd = new MovementAuthority.End(section, MovementAuthority.EndType.UNLOCK_SECTION);
//// break;
//// }
//// }
// // 站台屏蔽门
// MovementAuthority.End psdEnd = checkPsdOpenOrClose(section);
// if (psdEnd != null)
// endList.add(psdEnd);
// // 紧急关闭的站台
// MovementAuthority.End standEnd = checkEC(simulation.getRepository().getConfig(), section);
// if (standEnd != null)
// endList.add(standEnd);
// // 信号机
// MovementAuthority.End signalEnd = checkSignal(section, right);
// if (Objects.nonNull(signalEnd)) {
// endList.add(signalEnd);
// MovementAuthority.End unlockedOverlapEnd = this.checkUnlockedOverlap(simulation, section, right);
// if (Objects.nonNull(unlockedOverlapEnd)) {
// endList.add(unlockedOverlapEnd);
// }
// }
// // 道岔
// MovementAuthority.End end = checkSwitch(section, right);
// if (end != null)
// endList.add(end);
// // 轨道尽头/问题道岔
// Section temp = section.getNextRunningSectionOf(right);
// if (Objects.isNull(temp)) { // 到尽头
// if (!section.isSwitchTrack()) { // 问题道岔
// endList.add(new MovementAuthority.End(section, MovementAuthority.EndType.END_TRACK));
// }
// break;
// }
// //通信车占用区段
// MovementAuthority.End trainEnd = checkSectionOccupied(temp, right, occupiedLogicSectionSet);
// if (trainEnd != null)
// endList.add(trainEnd);
// //非通信车占用区段
// if (temp.hasNctOccupy() && !temp.isInvalid()) {
// endList.add(new MovementAuthority.End(temp, MovementAuthority.EndType.NCT_OCCUPIED_SECTION));
// }
// //检查关闭的区段
// MovementAuthority.End cs = checkClosedSection(section);
// if (cs != null)
// endList.add(cs);
//
// if (endList.stream().anyMatch(end2 -> !MovementAuthority.EndType.CLOSED_SIGNAL.equals(end2.getType()))) {
// break;
// }
// section = temp;
// }
//// // 前方列车
//// VirtualRealityTrain frontTrain = this.queryFrontTrain(train, trainList);
//// if (Objects.nonNull(frontTrain)) {
//// Section baseSection;
//// if (Objects.equals(frontTrain.isRight(), train.isRight())) {
//// baseSection = frontTrain.calculateTailPosition().getSection();
//// } else {
//// baseSection = frontTrain.getHeadPosition().getSection();
//// }
//// endList.add(new MovementAuthority.End(frontTrain,
//// MovementAuthority.EndType.FRONT_TRAIN,
//// baseSection));
//// }
// return endList;
// }
//
// private MovementAuthority.End checkSectionOccupied(Section section, boolean right, Set<Section> occupiedLogicSectionSet) {
// List<Section> logicList = section.getLogicList();
// if (!CollectionUtils.isEmpty(logicList)) {
// if (right) {
// for (Section logic : logicList) {
// if (logic.isCtOccupied() && !occupiedLogicSectionSet.contains(logic)) {
// return new MovementAuthority.End(logic, MovementAuthority.EndType.FRONT_TRAIN, null);
// }
// }
// } else {
// for (int i = logicList.size() - 1; i >= 0; i--) {
// Section logic = logicList.get(i);
// if (logic.isCtOccupied() && !occupiedLogicSectionSet.contains(logic)) {
// return new MovementAuthority.End(logic, MovementAuthority.EndType.FRONT_TRAIN, null);
// }
// }
// }
// } else {
// if (section.isCtOccupied() && !occupiedLogicSectionSet.contains(section)) {
// return new MovementAuthority.End(section, MovementAuthority.EndType.FRONT_TRAIN, null);
// }
// }
// return null;
// }
//
// private MovementAuthority.End checkSwitch(Section tailSection, Section headSection, boolean right) {
// Section section = tailSection;
// for (int i = 0; i < 10; i++) {
// if (section == null || section.equals(headSection))
// break;
// MovementAuthority.End end = checkSwitch(section, right);
// if (end != null)
// return end;
// section = section.getNextRunningSectionOf(right);
// }
// return null;
// }
//
// private MovementAuthority.End checkSwitch(Section section, boolean right) {
// Switch relSwitch = section.getRelSwitch();
// Section nextSection = section.getNextRunningSectionOf(right);
// if (relSwitch != null) { //是道岔区段
// Route route = relSwitch.getRoute();
// Section previousSection = section.getNextRunningSectionOf(!right);
// if (previousSection == null)
// return null;
// if (route != null) { //道岔进路锁闭
// if (relSwitch.isLoss()) { //失表且下个区段
// return new MovementAuthority.End(relSwitch, MovementAuthority.EndType.FAULT_SWITCH, previousSection);
// } else {
// List<RouteFls> flsList = route.getFlsList();
// if (!CollectionUtils.isEmpty(flsList)) {
// List<RouteFls> fls = flsList.stream()
// .filter(routeFls -> routeFls.getBase().getASwitch().equals(relSwitch))
// .collect(Collectors.toList());
// if (!routeService.isFlsCheckPass(fls)) {
// return new MovementAuthority.End(relSwitch, MovementAuthority.EndType.FAULT_SWITCH, previousSection);
// }
// }
// }
// }
// }
// return null;
// }
//
// private MovementAuthority.End checkClosedSection(Section section) {
// if (section.isClosed()) {
// return new MovementAuthority.End(section, MovementAuthority.EndType.CLOSED_SECTION);
// }
// return null;
// }
//
// private MovementAuthority.End checkEC(MapConfig config, Section section) {
// if (section.isNormalStandTrack()) {
// Station station = section.getStation();
// if (config.isSharingECStation(station.getCode())) {
// for (Stand stand : station.getAllStandList()) {
// if (stand.isEmergencyClosed()) {
// return new MovementAuthority.End(stand, MovementAuthority.EndType.EC_STAND, section);
// }
// }
// } else {
// List<Stand> standList = section.getStandList();
// for (Stand stand : standList) {
// if (stand.isEmergencyClosed()) {
// return new MovementAuthority.End(stand, MovementAuthority.EndType.EC_STAND, section);
// }
// }
// }
// }
// return null;
// }
//
// private MovementAuthority.End checkUnlockedOverlap(Simulation simulation, Section section, boolean right) {
// SimulationDataRepository repository = simulation.getRepository();
// // 判断是否已经办理进路的区段
// Route route = null;
// if (section.isRouteLock()) {
// List<Route> settingRoutes = repository.getSettingRoutes();
// for (Route settingRoute : settingRoutes) {
// if (settingRoute.isLastRouteSection(section)) {
// route = settingRoute;
// break;
// }
// }
// }
// if (Objects.nonNull(route) && repository.isOverlapNeedSetting(route)) { // 进路需要办理延续保护
// RouteOverlap overlap = route.getOverlap();
// if (!overlap.isLock()) { // 延续保护未锁闭
// return new MovementAuthority.End(overlap,
// MovementAuthority.EndType.UNLOCKED_OVERLAP, overlap.getSection());
// }
// }
// return null;
// }
//
// public void calculateMAOfITC(Simulation simulation, VirtualRealityTrain train) {
// // 查找移动授权终端列表
// List<MovementAuthority.End> endList = this.findItcMaEnd(train.getHeadPosition(), train.isRight());
// if (CollectionUtils.isEmpty(endList)) { // 未找到授权终点
// return;
// }
// // 根据查找到的授权终端比较并构建最终的移动授权数据
// MovementAuthority ma = this.compareAndBuildMa(train, endList);
// // 通知车载ATP
// this.onboardAtpApiService.updateMA4ITC(train, ma);
// }
//
// public MovementAuthority calculateMAOfITC(Simulation simulation, Responder responder) {
// // 查找移动授权终端列表
// List<MovementAuthority.End> endList = this.findItcMaEnd(responder.getPosition(), responder.getSignal().isRight());
// if (CollectionUtils.isEmpty(endList)) { // 未找到授权终点
// return null;
// }
// // 根据查找到的授权终端比较并构建最终的移动授权数据
// MovementAuthority ma = this.compareAndBuildMa(responder.getSignal().isRight(), endList);
// // 通知车载ATP
// return ma;
// }
//
// private List<MovementAuthority.End> findItcMaEnd(SectionPosition position, boolean right) {
// List<MovementAuthority.End> endList = new ArrayList<>();
// MovementAuthority.End deviceEnd = null;
// Section section = position.getSection();
// int count = 0;
// while (Objects.nonNull(section) && count < 20) {
// if (count > 1 && !CollectionUtils.isEmpty(endList))
// break;
// ++count;
// // 信号机
// MovementAuthority.End signalEnd = checkGroundSignal(section, right);
// if (Objects.nonNull(signalEnd)) {
// endList.add(signalEnd);
//// deviceEnd = signalEnd;
// break;
// }
// // 轨道尽头/问题道岔
// Section temp = section.getNextRunningSectionOf(right);
// if (Objects.isNull(temp)) { // 到尽头
// if (!section.isSwitchTrack()) { // 问题道岔
// endList.add(new MovementAuthority.End(section,
// MovementAuthority.EndType.END_TRACK));
// }
// break;
// }
// }
// if (Objects.nonNull(deviceEnd)) {
// endList.add(deviceEnd);
// }
// return endList;
// }
//
// /**
// * 比较并构建移动授权数据
// *
// * @param train
// * @param endList
// * @return
// */
// private MovementAuthority compareAndBuildMa(VirtualRealityTrain train, List<MovementAuthority.End> endList) {
// return compareAndBuildMa(train.isRight(), endList);
// }
//
// /**
// * 比较并构建移动授权数据
// *
// * @param endList
// * @return
// */
// private MovementAuthority compareAndBuildMa(boolean right, List<MovementAuthority.End> endList) {
// MovementAuthority.End end = null;
// if (endList.size() == 1) { // 只有一个直接构建移动授权
// end = endList.get(0);
// } else {
// for (MovementAuthority.End temp : endList) {
// if (Objects.isNull(end)) {
// end = temp;
// } else {
// if (end.isAheadOf(temp, right)) {
// end = temp;
// }
// }
// }
// }
// BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(end);
// end.confirmEndPosition(right);
// return new MovementAuthority(end);
// }
//
// private VirtualRealityTrain queryFrontTrain(VirtualRealityTrain train, List<VirtualRealityTrain> trainList) {
// boolean right = train.isRight();
// SectionPosition headPosition = train.getHeadPosition();
// VirtualRealityTrain front = null;
// Float distance = null;
// for (VirtualRealityTrain other : trainList) {
// if (Objects.equals(other, train)) {
// continue;
// }
// SectionPosition otherTrainPosition;
// if (Objects.equals(right, other.isRight())) {
// // 同向列车取车尾
// otherTrainPosition = other.calculateTailPosition();
//
// } else {
// // 反向列车取车头
// otherTrainPosition = other.getHeadPosition();
// }
// Float tempDistance = CalculateService.calculateDistance(headPosition, otherTrainPosition, right);
// if (Objects.isNull(tempDistance) || tempDistance < 0) {
// // 未找到
// continue;
// } else {
// if (Objects.isNull(front) || tempDistance < distance) {
// front = other;
// distance = tempDistance;
// }
// }
// }
//// if (Objects.nonNull(front)) {
//// log.debug(String.format("列车[%s-%s|%s|%s]前方列车为[%s-%s|%s|%s]",
//// train.getGroupNumber(), train.getServiceNumber(),
//// train.getTripNumber(), train.getDestinationCode(),
//// front.getGroupNumber(), front.getServiceNumber(),
//// front.getTripNumber(), front.getDestinationCode()));
//// }
// return front;
// }
//
// private MovementAuthority.End checkRouteLock(Simulation simulation, Section section, Section tailSection, boolean right, VirtualRealityTrain train) {
// if (section.isTransferTrack())
// return null;
// SimulationDataRepository repository = simulation.getRepository();
// // 判断前方是否有信号机(如果存在信号机则不判断进路锁闭以兼容现在列车加载到转换轨没有进路情况)
//// Signal aheadSignal = section.getSignalOf(right);
//// if (Objects.nonNull(aheadSignal)) {
//// return null;
//// }
// // 先查询是否是已排列的锁闭进路
// List<Route> settingRoutes = repository.getSettingRoutes();
// boolean lock = false;
// if (!CollectionUtils.isEmpty(settingRoutes)) {
// for (Route route : settingRoutes) {
// if (route.isRouteSection(section)
//// && !route.isSetting()
// ) {
// Signal signal = section.getSignalOf(right);
// if (route.isRight() == right || (signal == null || signal.isNormalOpen())) {
// lock = true;
// break;
// }
// }
// }
// }
// if (!lock) { // 未找到锁闭进路判断是否自动信号
// Section base = section;
// int count = 0;
// while (Objects.nonNull(base) && count < 20) {
// ++count;
// // 向反方向查找找信号机判断是否自动信号
// Section pre = base.getNextRunningSectionOf(!right);
// if (Objects.nonNull(pre)) {
// Signal signal = pre.getSignalOf(right);
// if (Objects.nonNull(signal)) {
// if (signal.isAutoSignal()) {
// lock = true; // 如果是自动信号也相当于锁闭
// }
// break; // 找到信号机结束
// }
// }
// base = pre;
// }
// }
// if (!lock) {
// // 未锁闭进路中设置移动授权终点
// return new MovementAuthority.End(section, MovementAuthority.EndType.UNLOCK_SECTION);
// }
// return null;
//
//
//// SimulationDataRepository repository = simulation.getRepository();
//// // 判断前方是否有信号机(如果存在信号机则不判断进路锁闭以兼容现在列车加载到转换轨没有进路情况)
//// if (section.isTransferTrack()) {
//// return null;
//// }
////// Signal aheadSignal = section.getSignalOf(right);
////// if (Objects.nonNull(aheadSignal)) {
////// return null;
////// }
//// // 先查询是否是已排列的锁闭进路
//// List<Route> settingRoutes = repository.getSettingRoutes();
//// boolean lock = false;
//// if (!CollectionUtils.isEmpty(settingRoutes)) {
//// boolean headRoute = false;
//// boolean tailRoute = false;
//// for (Route route : settingRoutes) {
//// if (route.isRight() == right && (route.isRouteSection(section) || route.isRouteSection(tailSection))) {
//// if (route.isRouteSection(section))
//// headRoute = true;
//// if (route.isRouteSection(tailSection))
//// tailRoute = true;
//// lock = true;
//// List<Switch> switches = screenSwitchesInFront(route, tailSection);
//// if (!this.checkRouteSwitchPosition(route, switches) || !this.isFlsCheckPass(route.getFlsList(), switches)) {
//// return new MovementAuthority.End(section, MovementAuthority.EndType.ROUTE_INTERLOCK_NOT_MET);
//// }
//// if (headRoute && tailRoute)
//// break;
//// }
//// }
//// }
//// if (!lock) { // 未找到锁闭进路判断是否自动信号
//// Section base = section;
//// int count = 0;
//// while (Objects.nonNull(base) && count < 20) {
//// ++count;
//// // 向反方向查找找信号机判断是否自动信号
//// Section pre = base.getNextRunningSectionOf(!right);
//// if (Objects.nonNull(pre)) {
//// Signal signal = pre.getSignalOf(right);
//// if (Objects.nonNull(signal)) {
//// if (signal.isAutoSignal()) {
//// lock = true; // 如果是自动信号也相当于锁闭
//// }
//// break; // 找到信号机结束
//// }
//// }
//// base = pre;
//// }
//// }
//// if (!lock && section.getSignalOf(right) == null) {
//// // 未锁闭进路中设置移动授权终点
//// return new MovementAuthority.End(section, MovementAuthority.EndType.UNLOCK_SECTION);
//// }
//// return null;
// }
//
// private boolean checkRouteSwitchPosition(Route route, List<Switch> switches) {
// List<SwitchElement> collect = route.getSwitchList().stream()
// .filter(element -> switches.contains(element.getASwitch()))
// .collect(Collectors.toList());
// return routeService.checkRouteSwitchPosition(collect);
// }
//
// private boolean isFlsCheckPass(List<RouteFls> flsList, List<Switch> switches) {
// if (!CollectionUtils.isEmpty(flsList) && !CollectionUtils.isEmpty(switches)) {
// List<RouteFls> collect = flsList.stream().filter(fls -> switches.contains(fls.getBase().getASwitch())).collect(Collectors.toList());
// return routeService.isFlsCheckPass(collect);
// }
// return true;
// }
//
// /**
// * 筛选前方的道岔
// */
// private List<Switch> screenSwitchesInFront(Route route, Section section) {
// boolean right = route.isRight();
// List<Section> sectionList = route.getSectionList();
// List<Switch> sectionRelSwitches = new ArrayList<>();
// for (int i = 0; i < 10; i++) {
// if (sectionList.contains(section))
// break;
// else
// section = section.getNextRunningSectionOf(right);
// }
// while (sectionList.contains(section)) {
// if (section.getRelSwitch() != null)
// sectionRelSwitches.add(section.getRelSwitch());
// section = section.getNextRunningSectionOf(right);
// }
// return sectionRelSwitches;
// }
//
// /**
// * 检查地面真实信号机是否未开放/故障信号机
// *
// * @param section
// * @param right
// * @return
// */
// private MovementAuthority.End checkGroundSignal(Section section, boolean right) {
// Signal signal = section.getSignalOf(right);
// if (Objects.nonNull(signal) && !signal.isVirtual() && !signal.isNormalOpen()) {
// return new MovementAuthority.End(signal,
// MovementAuthority.EndType.CLOSED_SIGNAL);
// }
// return null;
// }
//
// /**
// * 检查是否未开放/故障信号机
// *
// * @param section
// * @param right
// * @return
// */
// private MovementAuthority.End checkSignal(Section section, boolean right) {
// Signal signal = section.getSignalOf(right);
// if (Objects.nonNull(signal) && !signal.isNormalOpen()) {
// return new MovementAuthority.End(signal,
// MovementAuthority.EndType.CLOSED_SIGNAL);
// }
// return null;
// }
//
// /**
// * 检查是否站台屏蔽门开门
// */
// private MovementAuthority.End checkPsdOpenOrClose(Section section) {
// if (section.isStandTrack()) {
// List<Stand> standList = section.getStandList();
// for (Stand stand : standList) {
// if (!stand.isPsdSafe()) {
// return new MovementAuthority.End(stand, MovementAuthority.EndType.OPENED_PSD, section);
// }
// if (stand.isClosed()) {
// return new MovementAuthority.End(stand, MovementAuthority.EndType.CLOSED_STAND, section);
// }
// }
// }
// return null;
// }
//
//// public void addJobs(Simulation simulation) {
////// simulation.addJob(SimulationModule.ZC.name(), () -> this.run(simulation), SimulationConstants.ZC_LOOP_RATE);
//// simulation.addJob("MaCal", () -> this.maService.calculateMaOfCtcTrains(simulation), 1000);
//// }
//}

View File

@ -1,59 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.CI.service;
//
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.data.map.AutoSignal;
//import club.joylink.rtss.simulation.cbtc.data.map.Section;
//import club.joylink.rtss.simulation.cbtc.data.map.Signal;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//
///**
// * 自动信号服务
// */
//@Slf4j
//@Component
//public class AutoSignalService {
//
// @Autowired
// private SignalService signalService;
//
// /**
// * 根据连锁关系更新信号显示
// * @param simulation
// * @param autoSignal
// */
// public void updateSignalDisplay(Simulation simulation, AutoSignal autoSignal) {
// Signal signal = autoSignal.getSignal();
// if (!signal.isLogicLight()) {
// List<Section> sectionList = autoSignal.getSectionList();
// boolean clear = true; // 所有区段是否出清
// for (Section section : sectionList) {
// if (section.isOccupied()) {
// clear = false;
// break;
// }
// }
// if (clear) { // 全部出清开信号机
// this.signalService.openGreenSignal(simulation, signal);
// } else { // 关信号机
// this.signalService.close(simulation, signal);
// }
// } else {
// if (!signal.isMainAspect()) {
// this.signalService.openGreenSignal(simulation, signal);
// }
// }
//// if (!clear) { // 信号机物理点红灯
//// if (signal.isLogicLight()) {
//// signal.changeLightType(false);
//// }
//// this.signalService.close(simulation, signal);
//// } else { // 信号机开灯
//// this.signalService.openGreenSignal(simulation, signal);
//// }
// }
//
//}

View File

@ -1,120 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.CI.service;
//
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
//import club.joylink.rtss.simulation.cbtc.data.map.Route;
//import club.joylink.rtss.simulation.cbtc.data.map.Section;
//import club.joylink.rtss.simulation.cbtc.data.map.Signal;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.util.List;
//import java.util.Objects;
//
///**
// * 区段服务
// */
//@Component
//@Slf4j
//public class SectionService {
//
// @Autowired
// private SignalService signalService;
// @Autowired
// private RouteService routeService;
//
// /**
// * 封锁(封锁后包含区段的进路不能排列)
// */
// public void blockade(Section section) {
//// if(section.isRouteLock() || section.isOverlapLock()) {
//// log.info(String.format("区段[%s(%s)]进路锁闭,不能封锁", section.getName(), section.getCode()));
//// return;
//// }
// if (!section.isBlockade()) {
// section.setBlockade(true);
// if (!section.isCross() && !CollectionUtils.isEmpty(section.getLogicList())) {
// section.getLogicList().forEach(logic -> logic.setBlockade(true));
// }
// }
// }
//
// /**
// * 解封
// */
// public void unblock(Section section) {
// if (section.isBlockade()) {
// section.setBlockade(false);
// if (!section.isCross() && !CollectionUtils.isEmpty(section.getLogicList())) {
// section.getLogicList().forEach(logic -> logic.setBlockade(false));
// }
// }
// }
//
// /**
// * 区故解
// */
// public void sectionFaultUnlock(Simulation simulation, Section section, Route route) {
// if (route != null) {
// if (route.isOpenMain()) {
// signalService.close(simulation, route.getStart());
// }
// if (routeService.isApproachLock(simulation.getRepository(), route) || section.isOverlapLock()) {
// // 区段延时解锁
// int delayTime = route.getDelayReleaseTime() * 1000;
// section.delayUnlock(delayTime);
// if (section.isShowLogic()) {
// section.getLogicList().forEach(ls -> ls.delayUnlock(delayTime));
// }
// return;
// } else {
// route.setLock(false);
// Signal start = route.getStart();
// if (start.getLockedRoute() == route) {
// start.setLockedRoute(null);
// }
// }
// }
// section.faultUnlock();
// if (section.isShowLogic()) {
// section.getLogicList().forEach(Section::faultUnlock);
// }
// }
//
// /**
// * 区段延时区故解
// *
// * @param simulation
// * @param section
// */
// public void delayUnlock(Simulation simulation, Section section) {
// int remainTime = section.getDelayTime();
// if (remainTime > 0) {
// remainTime -= SimulationConstants.CI_LOOP_RATE;
// if (remainTime <= 0) {
// List<Route> routeList = simulation.getRepository().queryAllLockedRoute();
// Route lockedRoute = null;
// for (Route route : routeList) {
// if (route.containSection(section)) {
// lockedRoute = route;
// break;
// }
// }
// if (Objects.nonNull(lockedRoute)) {
// lockedRoute.setLock(false);
// Signal start = lockedRoute.getStart();
// this.signalService.close(simulation, start);
// if (start.getLockedRoute() == lockedRoute) {
// start.setLockedRoute(null);
// }
// }
// section.faultUnlock();
// section.setDelayTime(0);
// } else {
// section.setDelayTime(remainTime);
// }
// }
// }
//}

View File

@ -1,180 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.CI.service;
//
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.data.map.Route;
//import club.joylink.rtss.simulation.cbtc.data.map.Signal;
//import club.joylink.rtss.simulation.cbtc.data.support.SignalApproachMessage;
//import club.joylink.rtss.simulation.cbtc.event.RouteModeChangeEvent;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.util.List;
//import java.util.Objects;
//
///**
// * 信号机服务
// */
//@Component
//@Slf4j
//public class SignalService {
//
// @Autowired
// private VrSignalControlService vrSignalControlService;
//
// @Autowired
// private ApplicationContext applicationContext;
//
// /**
// * 封锁(封锁后包含信号机的进路不能排列)
// * @param signal
// */
// public void blockade(Simulation simulation, Signal signal) {
// if(!signal.isBlockade()) {
// signal.setBlockade(true);
// this.close(simulation, signal);
// if (signal.getLockedRoute() != null) {
// signal.setReblockade(true);
// log.debug(signal.debugStr() + "因信号机封锁且有锁闭的进路而重复封锁");
// }
// }
// }
//
// /**
// * 解封
// * @param signal
// */
// public void unblock(Signal signal) {
// if (signal.isBlockade()) {
// signal.setBlockade(false);
// }
// }
//
// /**
// * 信号关闭
// * @param simulation
// * @param signal
// */
// public void close(Simulation simulation, Signal signal) {
// if (signal.isLogicLight()) {
// signal.apply(false, false, true);
// if (!signal.isVirtual()) {
// this.vrSignalControlService.close(simulation, signal.getVirtualSignal());
// }
// } else {
// if (!signal.isVirtual()) {
// this.vrSignalControlService.openRedSignal(simulation, signal.getVirtualSignal());
// }
// }
// }
//
// /**
// * 控制室外信号机点绿灯
// * @param simulation
// * @param signal
// */
// public void openGreenSignal(Simulation simulation, Signal signal) {
// if (signal.isLogicLight()) {
// signal.apply(true, false, false);
// if (!signal.isVirtual()) {
// this.vrSignalControlService.close(simulation, signal.getVirtualSignal());
// }
// } else {
// if (!signal.isVirtual()) {
// this.vrSignalControlService.openGreenSignal(simulation, signal.getVirtualSignal());
// }
// }
// }
//
// /**
// * 控制室外信号机点黄灯
// * @param simulation
// * @param signal
// */
// public void openYellowSignal(Simulation simulation, Signal signal) {
// if (signal.isLogicLight()) {
// signal.apply(false, true, false);
// if (!signal.isVirtual()) {
// this.vrSignalControlService.close(simulation, signal.getVirtualSignal());
// }
// } else {
// this.vrSignalControlService.openYellowSignal(simulation, signal.getVirtualSignal());
// }
// }
//
// /**
// * 控制室外信号机点黄红灯
// * @param simulation
// * @param signal
// */
// public void openGuideSignal(Simulation simulation, Signal signal) {
// signal.changeLightType(false);
// this.vrSignalControlService.openGuideSignal(simulation, signal.getVirtualSignal());
// signal.apply(false, true, true);
// int guideRemain = signal.getGuideRemain();
// if (guideRemain > 0) {
// signal.guideInfinite();
// } else {
// signal.guideStart();
// }
// signal.setInit(false);
// if (signal.isReblockade()) {
// signal.setReblockade(false);
// }
// }
//
// /**
// * 处理信号机接近消息
// * @param simulation
// * @param signal
// * @param approachMessage
// */
// public void handleApproachMessage(Simulation simulation, Signal signal, SignalApproachMessage approachMessage) {
// if (Objects.equals(signal.getApproachMsg(), approachMessage.getApproachMsg())) {
// return;
// }
// signal.setApproachMsg(approachMessage.getApproachMsg());
// if (signal.isNctApproach()) { // 接近区段非通信车占用
// this.changeRoutesCBTCMode(simulation, signal, false);
// if (signal.isLogicLight()) { // 非通信车占用改为物理点灯
// this.changeSignalLightType(simulation, signal, false);
// }
// } else if (signal.isCbtcApproach()) { // 接近区段通信车占用
// this.changeRoutesCBTCMode(simulation, signal, true);
// if (!signal.isLogicLight()) {
// this.changeSignalLightType(simulation, signal, true);
// }
// }
// }
//
// private void changeSignalLightType(Simulation simulation, Signal signal, boolean logic) {
// if (!Objects.equals(signal.isLogicLight(), logic)) {
// signal.changeLightType(logic);
// if (!signal.isLogicLight()) {
// if (!signal.isVirtual()) {
// if (signal.isGreenOpen()) {
// this.vrSignalControlService.openGreenSignal(simulation, signal.getVirtualSignal());
// } else if (signal.isYellowOpen()) {
// this.vrSignalControlService.openYellowSignal(simulation, signal.getVirtualSignal());
// } else {
// this.vrSignalControlService.openRedSignal(simulation, signal.getVirtualSignal());
// }
// }
// } else {
// if (!signal.isVirtual()) {
// this.vrSignalControlService.close(simulation, signal.getVirtualSignal());
// }
// }
// }
// }
//
// private void changeRoutesCBTCMode(Simulation simulation, Signal signal, boolean cbtc) {
// List<Route> routeList = signal.getRouteList();
// if (!CollectionUtils.isEmpty(routeList)) {
// routeList.forEach(route -> route.setCbtcMode(cbtc));
// applicationContext.publishEvent(new RouteModeChangeEvent(this, simulation, routeList));
// }
// }
//}

View File

@ -1,185 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.CI.service;
//
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.communication.vo.ControllableDevice;
//import club.joylink.rtss.simulation.cbtc.communication.vo.PsdSwitch;
//import club.joylink.rtss.simulation.cbtc.data.map.*;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
//import club.joylink.rtss.simulation.cbtc.event.SimulationDeviceControlEvent;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.stereotype.Component;
//
//import java.util.Objects;
//
///**
// * 屏蔽门服务
// */
//@Component
//@Slf4j
//public class StandService {
//
// @Autowired
// private ApplicationContext applicationContext;
//
// @Autowired
// private SignalService signalService;
//
// @Autowired
// private RouteService routeService;
//
// /**
// * 控制室外屏蔽门开关
// */
// public void controlVrPSD(Simulation simulation, VirtualRealityScreenDoor vrPsd, boolean open) {
// if ((open && (vrPsd.isSettingOpen() || vrPsd.isOpen2End())) ||
// (!open && (vrPsd.isSettingClose() || vrPsd.isLockAndClose()))) {
//// log.debug(String.format("屏蔽门[%s(%s)]已经在对应状态,不需要再控制", vrPsd.getName(), vrPsd.getCode()));
// return;
// }
// vrPsd.startSetting(open);
// ControllableDevice ctrlMsg = new PsdSwitch(vrPsd, open);
// SimulationDeviceControlEvent event = new SimulationDeviceControlEvent(this, simulation, ctrlMsg);
// this.applicationContext.publishEvent(event);
// }
//
// /**
// * 打开屏蔽门
// *
// * @param simulation
// * @param psd
// */
// public void openScreenDoor(Simulation simulation, PSD psd) {
// VirtualRealityScreenDoor vrPsd = psd.getVirtualScreenDoor();
// if (vrPsd.isPslControl()) {
// return;
// }
// this.controlVrPSD(simulation, vrPsd, true);
// }
//
// /**
// * 关闭屏蔽门
// *
// * @param simulation
// * @param psd
// */
// public void closeScreenDoor(Simulation simulation, PSD psd) {
// VirtualRealityScreenDoor vrPsd = psd.getVirtualScreenDoor();
// if (vrPsd.isPslControl()) {
// return;
// }
// this.controlVrPSD(simulation, vrPsd, false);
// }
//
// /**
// * 设置扣车
// *
// * @param simulation
// * @param stand
// * @param center
// */
// public void holdTrain(Simulation simulation, Stand stand, boolean center) {
// if (center) {
// stand.setCenterHoldTrain(true);
// } else {
// stand.setStationHoldTrain(true);
// }
// // 关闭出站信号机
// Signal signal = stand.getSection().getSignalOf(stand.isRight());
// if (Objects.nonNull(signal)) {
// MapConfig config = simulation.getRepository().getConfig();
// if (config.isStandHoldCloseLogicLight()/* || !signal.isLogicLight()*/) {
// this.signalService.close(simulation, signal);
// }
// }
// }
//
// /**系统扣车*/
// public void sysHoldTrain(Simulation simulation, Stand stand) {
// stand.setSysHoldTrain(true);
// // 关闭出站信号机
// Signal signal = stand.getSection().getSignalOf(stand.isRight());
// if (Objects.nonNull(signal)) {
// MapConfig config = simulation.getRepository().getConfig();
// if (config.isStandHoldCloseLogicLight() || !signal.isLogicLight()) {
// this.signalService.close(simulation, signal);
// }
// }
// }
//
// public void cancelSysHoldTrain(Simulation simulation, Stand stand) {
// stand.setSysHoldTrain(false);
// // 如果所有扣车都取消开放出站信号机
// if (!stand.isHoldTrain()) {
// this.reopenSignal(simulation, stand);
// }
// }
//
// public void ibpHoldTrain(Simulation simulation, Stand stand) {
// stand.setIbpHoldTrain(true);
// // 关闭出站信号机
// Signal signal = stand.getSection().getSignalOf(stand.isRight());
// if (Objects.nonNull(signal)) {
// MapConfig config = simulation.getRepository().getConfig();
// if (config.isStandHoldCloseLogicLight() || !signal.isLogicLight()) {
// this.signalService.close(simulation, signal);
// }
// }
// }
//
// public void cancelIbpHoldTrain(Simulation simulation, Stand stand) {
// stand.setIbpHoldTrain(false);
// // 如果所有扣车都取消开放出站信号机
// if (!stand.isHoldTrain()) {
// this.reopenSignal(simulation, stand);
// }
// }
//
// /**
// * 取消扣车
// *
// * @param simulation
// * @param stand
// * @param center
// */
// public void cancelHoldTrain(Simulation simulation, Stand stand, boolean center) {
// if (center) {
// stand.setCenterHoldTrain(false);
// } else {
// stand.setStationHoldTrain(false);
// }
// // 如果所有扣车都取消开放出站信号机
// if (!stand.isHoldTrain()) {
// this.reopenSignal(simulation, stand);
// }
// }
//
// public void cancelAllHoldTrain(Simulation simulation, Stand stand) {
// stand.setCenterHoldTrain(false);
// stand.setStationHoldTrain(false);
// this.reopenSignal(simulation, stand);
// }
//
// private void reopenSignal(Simulation simulation, Stand stand) {
// Signal signal = stand.getSection().getSignalOf(stand.isRight());
// if (Objects.nonNull(signal) && !signal.isMainAspect()) {
// Route lockedRoute = signal.getLockedRoute();
// if (Objects.nonNull(lockedRoute) && this.routeService.isInterlocked(lockedRoute)) { // 锁闭进路存在,开信号机
// this.routeService.routeOpen(simulation, lockedRoute);
// }
// }
// }
//
// /**
// * 设置或取消互锁解除
// * @param release 是否是设置
// */
// public void setOrCancelInterlockRelease(Simulation simulation, Stand stand, boolean release) {
// stand.getPsd().getVirtualScreenDoor().updateIL(release);
// stand.getPsd().setInterlockRelease(release);
// if (release) {
// this.reopenSignal(simulation, stand);
// }
// }
//}

View File

@ -1,263 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.CI.service;
//
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.communication.vo.ControllableDevice;
//import club.joylink.rtss.simulation.cbtc.communication.vo.SwitchTurn;
//import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
//import club.joylink.rtss.simulation.cbtc.data.map.*;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
//import club.joylink.rtss.simulation.cbtc.event.RouteModeChangeEvent;
//import club.joylink.rtss.simulation.cbtc.event.SimulationDeviceControlEvent;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.event.EventListener;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.util.List;
//import java.util.Objects;
//import java.util.Random;
//import java.util.stream.Collectors;
//
///**
// * 道岔服务
// */
//@Component
//@Slf4j
//public class SwitchService {
//
// @Autowired
// private ApplicationContext applicationContext;
//
// @Autowired
// private SignalService signalService;
//
// @Autowired
// private RouteService routeService;
//
// @Autowired
// private SectionService sectionService;
//
// /**
// * 控制室外道岔转动道岔转动指令下达
// * @param simulation
// * @param aSwitch
// * @param toNormal
// */
// public void controlSwitch(Simulation simulation, Switch aSwitch, boolean toNormal) {
// if (simulation.getRepository().getConfig().isSwitchTurnOperationCanRecoverSplitFault()) {
// if (new Random().nextInt(3) == 0) {
// Switch.SwitchFault.SPLIT.fix(aSwitch);
// Switch.SwitchFault.NORMAL_SPLIT.fix(aSwitch);
// Switch.SwitchFault.REVERSE_SPLIT.fix(aSwitch);
// }
// }
// VirtualRealitySwitch virtualSwitch = aSwitch.getVirtualSwitch();
// if ((virtualSwitch.isNormal() && toNormal) ||
// (virtualSwitch.isReverse() && !toNormal)) {
// log.debug(String.format("道岔[%s]已经在指定位置[%s],无需转动", aSwitch.debugStr(), virtualSwitch.isNormal()?"N":"R"));
// return;
// }
// if (virtualSwitch.isSettingTo(toNormal)) {
// return;
// }
// // 向虚拟室外设备发送转换指令
// virtualSwitch.startSetting(toNormal);
// ControllableDevice ctrlMsg = new SwitchTurn(virtualSwitch, toNormal);
// SimulationDeviceControlEvent event = new SimulationDeviceControlEvent(this, simulation, ctrlMsg);
// this.applicationContext.publishEvent(event);
// }
//
// /**
// * 道岔定操
// * @param simulation
// * @param aSwitch
// */
// public boolean turn2NormalPosition(Simulation simulation, Switch aSwitch) {
// if(aSwitch.isLocked() || aSwitch.isSectionOccupied()) {
// return false;
// }
// this.controlSwitch(simulation, aSwitch, true);
// return true;
// }
//
// /**
// * 道岔反操
// * @param simulation
// * @param aSwitch
// * @return
// */
// public boolean turn2ReversePosition(Simulation simulation, Switch aSwitch) {
// if(aSwitch.isLocked() || aSwitch.isSectionOccupied()) {
// return false;
// }
// this.controlSwitch(simulation, aSwitch, false);
// return true;
// }
//
// /**
// * 道岔单锁
// * @param aSwitch
// */
// public void singleLock(Switch aSwitch) {
// if (!aSwitch.isSingleLock()) {
// aSwitch.setSingleLock(true);
// }
// }
//
// /**
// * 道岔单解
// * @param aSwitch
// */
// public void singleUnlock(Switch aSwitch) {
// if (aSwitch.isSingleLock()) {
// aSwitch.setSingleLock(false);
// }
// }
//
// /**
// * 封锁(封锁后包含道岔的进路不能排列)
// * @param aSwitch
// */
// public void blockade(Switch aSwitch) {
// if(!aSwitch.isBlockade()) {
// aSwitch.setBlockade(true);
// aSwitch.getA().setBlockade(true);
// aSwitch.getB().setBlockade(true);
// aSwitch.getC().setBlockade(true);
// }
// aSwitch.setInit(false);
// }
//
// /**
// * 解封
// * @param aSwitch
// */
// public void unblock(Switch aSwitch) {
// if(aSwitch.isBlockade()) {
// aSwitch.setBlockade(false);
// aSwitch.getA().setBlockade(false);
// aSwitch.getB().setBlockade(false);
// aSwitch.getC().setBlockade(false);
// }
// }
//
// /**
// * 道岔区段故障解锁
// * @param simulation
// * @param aSwitch
// * @param route
// */
// public void switchFaultUnlock(Simulation simulation, Switch aSwitch, Route route) {
// if (route != null) {
// if (route.isOpenMain()) {
// signalService.close(simulation, route.getStart());
// }
// if (routeService.isApproachLock(simulation.getRepository(), route) || aSwitch.isOverlapLock()) {
// // 延时解锁
// aSwitch.setDelayTime(route.getDelayReleaseTime() * 1000);
// aSwitch.getAllSections().forEach(section -> {
// if (section.isLocked())
// sectionService.sectionFaultUnlock(simulation, section, route);
// });
// return;
// } else {
// route.setLock(false);
// Signal start = route.getStart();
// if (start.getLockedRoute() == route) {
// start.setLockedRoute(null);
// }
// }
// }
// this.faultUnlock(aSwitch, route);
// }
//
// public void faultUnlock(Switch aSwitch, Route route) {
// aSwitch.faultUnlock();
// aSwitch.sectionFaultUnlock();
// if (route != null) {
// route.unlockRouteFlsOfSwitch(aSwitch); //进路中该道岔对应的侧防解除锁闭
// RouteOverlap overlap = route.getOverlap();
// if (overlap != null) {
// for (SectionPath sectionPath : overlap.getPathList()) {
// overlap.unlockFlsOfSwitch(sectionPath.getFlsList(), aSwitch); //延续保护中该道岔的侧防解除锁闭
// }
// }
// }
// }
//
// public void delayUnlock(Simulation simulation, Switch aSwitch) {
// int remainTime = aSwitch.getDelayTime();
// if (remainTime > 0) {
// remainTime -= SimulationConstants.CI_LOOP_RATE;
// if (remainTime <= 0) {
// List<Route> routeList = simulation.getRepository().queryAllLockedRoute();
// Route lockedRoute = null;
// if (aSwitch.isRouteLock()) {
// lockedRoute = aSwitch.getRoute();
// } else {
// for (Route route : routeList) {
// if (route.overlapContainSwitch(aSwitch)) {
// lockedRoute = route;
// break;
// }
// }
// }
// if (Objects.nonNull(lockedRoute)) {
// lockedRoute.setLock(false);
// Signal start = lockedRoute.getStart();
// if (start.getLockedRoute() == lockedRoute) {
// start.setLockedRoute(null);
// }
// }
// this.faultUnlock(aSwitch, lockedRoute);
// aSwitch.setDelayTime(0);
// } else {
// aSwitch.setDelayTime(remainTime);
// }
// }
// }
//
// @EventListener
// public void handle(RouteModeChangeEvent event) {
// this.switchStatusUpdate(event.getSimulation(), event.getRoutes());
// }
//
// /**
// * 道岔的封锁失效状态更新
// */
// private void switchStatusUpdate(Simulation simulation, List<Route> routes) {
// if (!simulation.getRepository().getConfig().isBlockadeCommandOnlyValidInStandbyMode()) {
// return;
// }
// if (!CollectionUtils.isEmpty(routes)) {
// if (!routes.get(0).isCbtcMode()) { //进路的状态被设为非cbtc
// routes.forEach(route -> {
// route.getSwitchList().forEach(switchElement -> {
// Switch aSwitch = switchElement.getASwitch();
// if (aSwitch.isBlockade()) {
// aSwitch.setBlockadeInvalid(false);
// }
// });
// });
// } else {
// List<Switch> switches = routes.stream()
// .flatMap(route -> route.getSwitchList()
// .stream()
// .map(SwitchElement::getASwitch)
// .filter(aSwitch -> aSwitch.isBlockade() && !aSwitch.isBlockadeInvalid()))
// .collect(Collectors.toList()); //进路下所有处于封锁且封锁有效状态的道岔
// for (Route route : simulation.getRepository().getRouteList()) {
// if (!route.isCbtcMode()) {
// switches.removeIf(route::isRouteSwitch);
// if (switches.isEmpty()) {
// break;
// }
// }
// }
// switches.forEach(aSwitch -> aSwitch.setBlockadeInvalid(true));
// }
// }
// }
//}

View File

@ -1,100 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.CI.service;
//
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.communication.vo.ControllableDevice;
//import club.joylink.rtss.simulation.cbtc.communication.vo.SignalLight;
//import club.joylink.rtss.simulation.cbtc.data.map.Signal;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
//import club.joylink.rtss.simulation.cbtc.event.SimulationDeviceControlEvent;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.stereotype.Component;
//
//import java.util.Objects;
//
///**
// * 信号机服务
// */
//@Component
//@Slf4j
//public class VrSignalControlService {
//
// @Autowired
// private ApplicationContext applicationContext;
//
// /**
// * 控制室外信号机灭灯
// * @param simulation
// * @param vrSignal
// */
// public void close(Simulation simulation, VirtualRealitySignal vrSignal) {
// if (!vrSignal.isBlack()) {
// this.controlRealSignal(simulation, vrSignal, false, false, false);
// }
// }
//
// /**
// * 控制室外信号机点绿灯
// * @param simulation
// * @param vrSignal
// */
// public void openGreenSignal(Simulation simulation, VirtualRealitySignal vrSignal) {
// controlRealSignal(simulation, vrSignal, true, false, false);
// }
//
// /**
// * 控制室外信号机点黄灯
// * @param simulation
// * @param vrSignal
// */
// public void openYellowSignal(Simulation simulation, VirtualRealitySignal vrSignal) {
// controlRealSignal(simulation, vrSignal, false, true, false);
// }
//
// /**
// * 控制室外信号机点红灯
// * @param simulation
// * @param vrSignal
// */
// public void openRedSignal(Simulation simulation, VirtualRealitySignal vrSignal) {
// controlRealSignal(simulation, vrSignal, false, false, true);
// }
//
// /**
// * 控制室外信号机点黄红灯
// * @param simulation
// * @param vrSignal
// */
// public void openGuideSignal(Simulation simulation, VirtualRealitySignal vrSignal) {
// this.controlRealSignal(simulation, vrSignal, false, true, true);
// }
//
// /**
// * 控制室外信号灯显示
// * @param simulation
// * @param vrSignal
// * @param greenOpen
// * @param yellowOpen
// * @param redOpen
// */
// private void controlRealSignal(Simulation simulation, VirtualRealitySignal vrSignal,
// boolean greenOpen, boolean yellowOpen, boolean redOpen) {
// // 根据点灯类型和要开放信号下达信号机控制指令
// if(Objects.isNull(vrSignal)){
// return;
// }
// if (!vrSignal.isSame(greenOpen, yellowOpen, redOpen)) {
// Signal signal = simulation.getRepository().getByCode(vrSignal.getCode(), Signal.class);
// if (signal.isFault()) {
// vrSignal.apply(false, false, true);
// } else {
// vrSignal.apply(greenOpen, yellowOpen, redOpen);
// }
// ControllableDevice ctrlMsg = new SignalLight(vrSignal);
// SimulationDeviceControlEvent event = new SimulationDeviceControlEvent(this, simulation, ctrlMsg);
// this.applicationContext.publishEvent(event);
// }
// }
//
//}

View File

@ -1,39 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.ISCS;
//
//import club.joylink.rtss.services.voice.VoiceService;
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
//import club.joylink.rtss.vo.client.iscs.Ats2PisMsg;
//import club.joylink.rtss.vo.client.voice.BaseVoiceSynthesisVO;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
///**
// * PIS系统逻辑服务
// */
//@Component
//public class OnBoardPisService {
// /*@Autowired
// @Qualifier("baiDuVoiceService")
// private IVoiceService iVoiceService;*/
//
// @Autowired
//// @Qualifier("baiDuVoiceService2")
// private VoiceService iVoiceService;
// public void play(Simulation simulation, Ats2PisMsg msg) {
// String content;
// if (msg.isArrivalMsg()) {
// String direction = msg.getStand().isInside() ? "" : "";
// content = msg.getStation().getName() + "站到了,下车的乘客请从列车运行方向的" + direction + "侧车门下车";
// } else {
// content = "本次列车开往" + msg.getTerminalStation().getName() + "方向,下一站" + msg.getStation().getName();
// }
// BaseVoiceSynthesisVO vo = new BaseVoiceSynthesisVO(content);
// String path = iVoiceService.synthesis(vo).getFilePath();
//// String path = iVoiceService.synthesis(content);
// SimulationDataRepository repository = simulation.getRepository();
// VirtualRealityTrain train = repository.getOnlineTrainBy(msg.getGroupNumber());
// train.getVrAudio().updateUrl(path);
// }
//}

View File

@ -8,16 +8,17 @@ import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import club.joylink.rtss.vo.client.simulationv1.SimulationInfoQueryVO;
import lombok.NonNull;
import java.util.List;
import java.util.Map;
import lombok.NonNull;
public interface SimulationService {
/**
* 创建仿真
*/
String createSimulation(long mapId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO);
String createSimulation(long mapId, SimulationWorkParamVO workParamVO,
@NonNull LoginUserInfoVO loginUserInfoVO);
/**
* 给仿真添加功能
@ -27,7 +28,8 @@ public interface SimulationService {
/**
* 从仿真中移除功能
*/
void removeItems(String simulationId, List<SimulationWorkParamVO.Item> items, LoginUserInfoVO loginInfo);
void removeItems(String simulationId, List<SimulationWorkParamVO.Item> items,
LoginUserInfoVO loginInfo);
/**
* 按计划行车
@ -82,4 +84,6 @@ public interface SimulationService {
PageVO<SimulationInfoVO> pagedSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO);
void sendUnreceivedMessages(String simulationId, String memberId);
List<SimulationInfoVO> listAllSimulation(SimulationInfoQueryVO queryVO);
}

View File

@ -34,6 +34,15 @@ import club.joylink.rtss.vo.permission.subject.PermissionSubjectVO;
import club.joylink.rtss.websocket.StompMessageService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -42,14 +51,10 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Service
@Slf4j
public class SimulationServiceImpl implements SimulationService {
@Autowired
private SimulationManager simulationManager;
@Autowired
@ -80,17 +85,21 @@ public class SimulationServiceImpl implements SimulationService {
@Override
public String createSimulation(long mapId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(workParamVO.containsRealDeviceItem(), "此途径创建的仿真不能连接真实设备");
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());
log.info("权限主体id:[{}] 用户id:[{}] 开始时间:[{}]未到时间", subjectVO.getId(),
subjectVO.getSubjectId(), subjectVO.getStartTime());
continue;
}
if (!CollectionUtils.isEmpty(subjectVO.getSystemAbilityList())) {
@ -112,7 +121,8 @@ public class SimulationServiceImpl implements SimulationService {
}
// }
} else {
log.error("权限主体对应的功能是空 主体id:[{}],subjectId:[{}],subjectType:[{}]", subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getSubjectType());
log.error("权限主体对应的功能是空 主体id:[{}],subjectId:[{}],subjectType:[{}]",
subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getSubjectType());
}
}
return newVoList;
@ -124,36 +134,45 @@ public class SimulationServiceImpl implements SimulationService {
* @param functionVO
* @param loginInfo
*/
private Map<String, Boolean> checkUserPermission(MapFunctionVO functionVO, LoginUserInfoVO loginInfo) {
private Map<String, Boolean> checkUserPermission(MapFunctionVO functionVO,
LoginUserInfoVO loginInfo) {
if (loginInfo.getAccountVO().isAdmin()) {
return Collections.emptyMap();
}
LoginUserInfoVO newLoginUser = loginInfo;
if (loginInfo.getAccountVO().isThirdChildAccount()) {
AccountVO user = this.iSysUserService.queryUserByAccountForMaster(loginInfo.getAccountVO().getParentAccount());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(user), "未找到主账号相关权限");
AccountVO user = this.iSysUserService.queryUserByAccountForMaster(
loginInfo.getAccountVO().getParentAccount());
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);
List<PermissionSubjectVO> newVOLIst = this.filterUserPermission(subjectVOList, functionVO,
newLoginUser);
if (CollectionUtils.isEmpty(newVOLIst)) {
log.error("未找到对应的权限数据mapId[{}],functionId[{}],userId[{}]", functionVO.getMapId(), functionVO.getId(), newLoginUser.getAccountVO().getId());
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, 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)) {
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());
List<Simulation> findSimList = this.simulationManager.finder(key);
@ -167,49 +186,60 @@ public class SimulationServiceImpl implements SimulationService {
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());
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()))
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());
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;
}
@Override
public void addItems(@NonNull String simulationId, Map<SimulationWorkParamVO.Item, String> itemMap) {
public void addItems(@NonNull String simulationId,
Map<SimulationWorkParamVO.Item, String> itemMap) {
if (!CollectionUtils.isEmpty(itemMap)) {
Simulation simulation = simulationManager.getById(simulationId, Simulation.class);
Simulation.Type simulationType = simulation.getType();
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(simulationType);
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(
simulationType);
// if (StringUtils.hasText(simulation.getCreatorId())) {
// BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertEquals(loginInfo.getAccountVO().getIdStr(), simulation.getCreatorId(),
// "非仿真创建者不能使用该功能");
// }
initService.addItems(simulation, itemMap);
SocketMessageVO<SimulationWorkParamVO> workParamMessage = SocketMessageFactory
.buildSimulationWorkParamMessage(simulationId, simulation.getBuildParams().getWorkParamVO());
.buildSimulationWorkParamMessage(simulationId,
simulation.getBuildParams().getWorkParamVO());
Set<String> users = simulation.getSimulationUserIds();
stompMessageService.sendToUser(users, workParamMessage);
}
}
@Override
public void removeItems(@NonNull String simulationId, List<SimulationWorkParamVO.Item> items, LoginUserInfoVO loginInfo) {
public void removeItems(@NonNull String simulationId, List<SimulationWorkParamVO.Item> items,
LoginUserInfoVO loginInfo) {
if (!CollectionUtils.isEmpty(items)) {
Simulation simulation = simulationManager.getById(simulationId, Simulation.class);
Simulation.Type simulationType = simulation.getType();
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(simulationType);
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(
simulationType);
// if (StringUtils.hasText(simulation.getCreatorId())) {
// BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertEquals(loginInfo.getAccountVO().getIdStr(), simulation.getCreatorId(),
// "非仿真创建者不能使用该功能");
@ -221,14 +251,16 @@ public class SimulationServiceImpl implements SimulationService {
@Override
public void runAsPlan(String simulationId, RunAsPlanParam param) {
Simulation simulation = simulationManager.getById(simulationId, Simulation.class);
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(simulation.getType());
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(
simulation.getType());
initService.runAsPlan(simulation, param);
}
@Override
public void reset(String simulationId) {
Simulation simulation = simulationManager.getById(simulationId, Simulation.class);
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(simulation.getType());
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(
simulation.getType());
initService.reset(simulation);
}
@ -262,17 +294,21 @@ public class SimulationServiceImpl implements SimulationService {
@Override
public void monitor(String simulationId, AccountVO user) {
Simulation simulation = simulationManager.getById(simulationId, Simulation.class);
SimulationUser simulationUser = new SimulationUser(simulation, user, club.joylink.rtss.simulation.SimulationUser.Type.TEACHER);
SimulationUser simulationUser = new SimulationUser(simulation, user,
club.joylink.rtss.simulation.SimulationUser.Type.TEACHER);
simulationWorkServiceManager.addSimulationUser(simulation, simulationUser);
}
private Simulation createSimulation(long mapId, MapFunctionVO mapFunctionVO, @NonNull SimulationWorkParamVO workParamVO,
private Simulation createSimulation(long mapId, MapFunctionVO mapFunctionVO,
@NonNull SimulationWorkParamVO workParamVO,
@NonNull LoginUserInfoVO loginUserInfoVO, Map<String, Boolean> createUserType) {
//获取仿真工作服务
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(workParamVO.getType());
SimulationWorkService initService = simulationWorkServiceManager.getWorkService(
workParamVO.getType());
//创建仿真
String simulationId = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), mapId);
String simulationId = SimulationIdGenerator.generateGroup(
loginUserInfoVO.getAccountVO().getId(), mapId);
Simulation simulation = initService.create(mapId, workParamVO, loginUserInfoVO, simulationId);
//语音配置数据
@ -308,7 +344,8 @@ public class SimulationServiceImpl implements SimulationService {
}
@Override
public Simulation createSimulation(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();
@ -326,7 +363,8 @@ public class SimulationServiceImpl implements SimulationService {
oldSimulationOptional.ifPresent(simulation -> simulationManager.destroy(simulation.getId()));
}
return createSimulation(mapId, mapFunctionVO, mapFunctionVO.getParamVO(), loginInfo, createUserType);
return createSimulation(mapId, mapFunctionVO, mapFunctionVO.getParamVO(), loginInfo,
createUserType);
}
@Override
@ -344,32 +382,39 @@ public class SimulationServiceImpl implements SimulationService {
@Override
public SimulationVO querySimulationJoinedByUser(long userId) {
Optional<club.joylink.rtss.simulation.Simulation> optional = simulationManager.getSimulationStream(null)
Optional<club.joylink.rtss.simulation.Simulation> optional = simulationManager.getSimulationStream(
null)
.filter(simulation -> simulation.querySimulationUserById(String.valueOf(userId)) != null)
.findFirst();
return optional.map(simulation -> groupSimulationService.getSimulationBasicInfo(simulation.getId())).orElse(null);
return optional.map(
simulation -> groupSimulationService.getSimulationBasicInfo(simulation.getId()))
.orElse(null);
}
@Override
public List<SimulationInfoVO> listSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO) {
Stream<Simulation> stream = this.simulationManager.getSimulationStream(Simulation.class);
stream = stream.filter(simulation -> Objects.equals(topOrgId, simulation.getBuildParams().getLoginUserInfo().getTopOrgId()));
stream = stream.filter(simulation -> Objects.equals(topOrgId,
simulation.getBuildParams().getLoginUserInfo().getTopOrgId()));
if (StringUtils.hasText(queryVO.getGroup())) {
stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup()));
}
if (StringUtils.hasText(queryVO.getUserName())) {
stream = stream.filter(simulation -> simulation.getSimulationUsers().stream().anyMatch(user -> user.getName().contains(queryVO.getUserName())));
stream = stream.filter(simulation -> simulation.getSimulationUsers().stream()
.anyMatch(user -> user.getName().contains(queryVO.getUserName())));
}
return stream.map(Simulation::convertToVO).collect(Collectors.toList());
}
@Override
public PageVO<SimulationInfoVO> pagedSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO) {
public PageVO<SimulationInfoVO> pagedSimulationByOrg(Long topOrgId,
SimulationInfoQueryVO queryVO) {
List<SimulationInfoVO> list = listSimulationByOrg(topOrgId, queryVO);
Stream<SimulationInfoVO> stream = list.stream();
int skipNum = (queryVO.getPageNum() - 1) * queryVO.getPageSize();
List<SimulationInfoVO> collect = stream.skip(skipNum).limit(queryVO.getPageSize()).collect(Collectors.toList());
List<SimulationInfoVO> collect = stream.skip(skipNum).limit(queryVO.getPageSize())
.collect(Collectors.toList());
return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), list.size(), collect);
}
@ -385,4 +430,22 @@ public class SimulationServiceImpl implements SimulationService {
stompMessageService.sendToUser(member.getUserId(), message);
}
}
@Override
public List<SimulationInfoVO> listAllSimulation(SimulationInfoQueryVO queryVO) {
List<Simulation> simulationList = this.simulationManager.getSimulationList();
Stream<Simulation> stream = simulationList.stream();
if (StringUtils.hasText(queryVO.getGroup())) {
stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup()));
}
if (StringUtils.hasText(queryVO.getUserName())) {
stream = stream.filter(simulation -> simulation.getSimulationUsers().stream()
.anyMatch(user -> user.getName().contains(queryVO.getUserName())));
}
if (queryVO.getFunctionId() != null) {
stream = stream.filter(
simulation -> Objects.equals(queryVO.getFunctionId(), simulation.getMapFunctionId()));
}
return stream.map(Simulation::convertToVO).collect(Collectors.toList());
}
}

View File

@ -1,22 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.communication.vo;
//
//import com.fasterxml.jackson.databind.annotation.JsonSerialize;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
//import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer;
//import lombok.Getter;
//
///**
// * 站台屏蔽门开/关门控制消息
// */
//@Getter
//public class PsdSwitch extends ControllableDevice {
//
// /** true-开门 false-关门 */
// @JsonSerialize(using = Boolean2NumSerializer.class)
// private boolean open;
//
// public PsdSwitch(VirtualRealityScreenDoor psd, boolean open) {
// super(psd.getCode(), psd.getDeviceType());
// this.open = open;
// }
//}

View File

@ -1,25 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.communication.vo;
//
//import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
//import lombok.Getter;
//
///**
// * 信号机点灯状态
// */
//@Getter
//public class SignalLight extends ControllableDevice {
// /**
// * 信号显示
// */
// private SignalAspect aspect;
//
// public SignalLight(VirtualRealitySignal signal) {
// super(signal.getCode(), signal.getDeviceType());
// if (signal.getCommand() != null) {
// this.aspect = signal.getCommand();
// } else {
// this.aspect = signal.getAspect();
// }
// }
//}

View File

@ -1,22 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.communication.vo;
//
//import com.fasterxml.jackson.databind.annotation.JsonSerialize;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
//import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer;
//import lombok.Getter;
//
///**
// * 道岔开始转动消息
// */
//@Getter
//public class SwitchTurn extends ControllableDevice {
//
// /** true-转到定位 false-转到反位 */
// @JsonSerialize(using = Boolean2NumSerializer.class)
// private boolean normal;
//
// public SwitchTurn(VirtualRealitySwitch vrSwitch, boolean normal) {
// super(vrSwitch.getCode(), vrSwitch.getDeviceType());
// this.normal = normal;
// }
//}

View File

@ -1,22 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.data.support;
//
//import club.joylink.rtss.simulation.cbtc.data.map.Section;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
//import lombok.Getter;
//
///**
// * 列车停稳消息
// */
//@Getter
//public class TrainStopMessage {
//
// private VirtualRealityTrain train;
//
// private Section section;
//
// public TrainStopMessage(VirtualRealityTrain train) {
// this.train = train;
// this.section = train.getHeadPosition().getSection();
// }
//
//}

View File

@ -1,44 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy;
//
//import club.joylink.rtss.simulation.cbtc.Simulation;
//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter;
//import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
//import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.PlcGateway;
//import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
//import club.joylink.rtss.vo.client.project.cgy.CgySectionConfigVO;
//import club.joylink.rtss.vo.client.project.say.SaySectionConfigVO;
//import io.netty.buffer.ByteBuf;
//import org.springframework.stereotype.Service;
//
//@Service
//public class CgySectionServiceImpl implements RealDeviceService {
//
// @Override
// public boolean canHandle(RealDeviceConfig deviceConfig) {
// return deviceConfig instanceof CgySectionConfig;
// }
//
// @Override
// public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
//
// }
//
// @Override
// public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
// PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
// if (plcGateway == null) {
// return;
// }
// CgySectionConfig config = (CgySectionConfig) deviceConfig;
// VirtualRealitySectionAxleCounter vrAxleCounter = (VirtualRealitySectionAxleCounter) config.getMapElement();
// if (vrAxleCounter == null) {
// return;
// }
// CgySectionConfigVO configVO = config.getConfigVO();
// ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
// configVO.getQuantity());
//
// boolean r_clear = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_clear());
// vrAxleCounter.setOccupy(!r_clear);
// }
//}

View File

@ -1,356 +0,0 @@
//package club.joylink.rtss.simulation.cbtc.passenger.strategy.service;
//
//import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
//import club.joylink.rtss.simulation.cbtc.data.map.Stand;
//import club.joylink.rtss.simulation.cbtc.data.plan.RealRun;
//import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan;
//import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan;
//import club.joylink.rtss.simulation.cbtc.passenger.strategy.Config;
//import club.joylink.rtss.simulation.cbtc.passenger.strategy.data.*;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import org.springframework.util.CollectionUtils;
//
//import java.time.LocalDateTime;
//import java.time.LocalTime;
//import java.util.*;
//
//@Slf4j
//@Component
//public class JumpAndParkTimeStrategyServiceImpl implements StrategyService<JumpAndParkTimeStrategy> {
//
// @Override
// public List<JumpAndParkTimeStrategy> generateStrategy(StrategyCalculateData data) {
// List<JumpAndParkTimeStrategy> list = new ArrayList<>();
// List<StandPassenger> lpfList = data.queryLpfList();
// if (CollectionUtils.isEmpty(lpfList)) {
// return null;
// }
// // 暂时按一个站大客流处理
// StandPassenger standPassenger = lpfList.get(0);
// Stand stand = standPassenger.getStand();
// Map<String, List<TripPlan>> planMap = data.getPlanMap();
// int planParkTime = 0; // 计划停站时间
// for (List<TripPlan> planList : planMap.values()) {
// for (TripPlan tripPlan : planList) {
// List<StationPlan> stationPlanList = tripPlan.getPlanList();
// for (StationPlan stationPlan : stationPlanList) {
// if (Objects.equals(stationPlan.getSection(), stand.getSection()) &&
// stationPlan.getParkTime() > 0) {
// planParkTime = stationPlan.getParkTime();
// break;
// }
// }
// }
// if (planParkTime > 0) {
// break;
// }
// }
// if (planParkTime <= 0) {
// throw new IllegalArgumentException(String.format("计划或站台[%s]数据异常,找到的计划停站时间异常:为[%s]", stand.debugStr(), planParkTime));
// }
// // 最大停站时间内每隔5秒生成一个策略策略的停站时间为计划停站时间+5*i
// int iter = (Config.STAND_MAX_STOP_TIME - planParkTime) / 5;
// for (int i = 1; i <= iter; i++) {
// list.add(new JumpAndParkTimeStrategy(stand, planParkTime + i * 5));
// }
// List<Stand> leftStandList = data.getLeftStandList();
// List<Stand> rightStandList = data.getRightStandList();
// boolean right = false;
// int index = leftStandList.indexOf(stand);
// if (index < 0) {
// // 不是左向站台
// right = true;
// index = rightStandList.indexOf(stand);
// }
// BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(index >= 0, String.format("未找到站台[%s]", stand.debugStr()));
// log.debug(String.format("[%s]第[%s]个站台大客流", right?"右向":"左向", (index+1)));
//
// boolean hasJump = false;
// if (index == 0) {
// // 第一站不生成跳停策略
// log.debug(String.format("第一个站,不生成跳停策略"));
// }
// List<Stand> jumpableStandList;
// if (right) {
// jumpableStandList = rightStandList.subList(0, index);
// } else {
// jumpableStandList = leftStandList.subList(0, index);
// }
// List<TrainPassenger> trainPassengerList = data.getTrainPassengerList();
// for (int i = jumpableStandList.size()-1; i > 0; i--) { // 起始站不跳停
// Stand s = jumpableStandList.get(i);
// // 该站台人数是否支持跳停
// StandPassenger sp = data.getStandPassengerByStand(s);
// if (sp.getWait() >= Config.STAND_JUMP_MAX) {
// log.debug(String.format("站台[%s]客流数[%s]>=站台跳停最大客流量[%s],不能跳停",
// s.debugStr(), sp.getWait(), Config.STAND_JUMP_MAX));
// continue;
// }
// // 该站是否被前列车跳过
// RealRun jumpRun = this.isJustJumped(data, s);
// if (jumpRun != null) {
// log.debug(String.format("站台[%s]刚被跳停,不生成", s.debugStr()));
// continue;
// }
// // 前一站是否刚跳停
// if (i - 1 > 0) {
// Stand pre = jumpableStandList.get(i - 1);
// jumpRun = this.isJustJumped(data, pre);
// if (jumpRun != null) {
// boolean jump = false;
// List<RealRun> realRuns = data.queryRealRuns(jumpRun.getGroupNumber());
// int i1 = realRuns.indexOf(jumpRun);
// for (int j = i1; j < realRuns.size(); j++) {
// RealRun realRun = realRuns.get(j);
// if (Objects.equals(realRun.getSectionCode(), s.getSection().getCode())) {
// if (!realRun.isArrive()) {
// jump = true;
// }
// break;
// }
// }
// if (jump) {
// log.debug(String.format("站台[%s]的前一站台[%s]刚被跳停,不生成", s.debugStr(), pre.debugStr()));
// continue;
// }
// }
// }
// hasJump = true;
// for (JumpAndParkTimeStrategy jumpAndParkTimeStrategy : list) {
// jumpAndParkTimeStrategy.setJumpStand(s);
// }
// }
// if (!hasJump) {
// list.clear();
// }
// log.debug(String.format("生成跳停+停站时间策略[%s]个", list.size()));
// return list;
// }
//
// private RealRun isJustJumped(StrategyCalculateData data, Stand stand) {
// List<TrainPassenger> trainPassengerList = data.getTrainPassengerList();
// StationPlan plan = null;
// boolean jump = false;
// RealRun standLastRun = null;
// for (TrainPassenger trainPassenger : trainPassengerList) {
// String groupNumber = trainPassenger.getGroupNumber();
// TripPlan tripPlan = data.queryTripPlan(trainPassenger.getServiceNumber(), trainPassenger.getTripNumber());
// if (tripPlan == null) {
// log.warn(String.format("列车[%s-%s|%s]没有找到车次计划",
// groupNumber, trainPassenger.getServiceNumber(), trainPassenger.getTripNumber()));
// continue;
// }
// int index = tripPlan.getPlanIndex(stand.getSection());
// if (index < 0) { // 没有对应站台计划无需判断跳停
// continue;
// }
// List<RealRun> realRunList = data.queryRealRuns(groupNumber);
// if (!CollectionUtils.isEmpty(realRunList)) {
// realRunList.sort(Comparator.comparing(RealRun::getTime));
// RealRun last = realRunList.get(realRunList.size() - 1);
// int lastRunIndex = tripPlan.getPlanIndex(last.getSectionCode());
// if (lastRunIndex < index) { // 列车实际运行未过站台
// StationPlan stationPlan = tripPlan.getPlanList().get(index);
// if (plan == null || plan.getArriveTime().isAfter(stationPlan.getArriveTime())) {
// plan = stationPlan;
// }
// continue;
// }
// for (int i = realRunList.size() - 1; i >= 0; i--) {
// RealRun realRun = realRunList.get(i);
// if (!Objects.equals(realRun.getServiceNumber(), trainPassenger.getServiceNumber()) ||
// !Objects.equals(realRun.getTripNumber(), trainPassenger.getTripNumber())) {
// break;
// }
// if (Objects.equals(realRun.getSectionCode(), stand.getSection().getCode())) {
// if (!realRun.isArrive() && i > 0) {
// RealRun pre = realRunList.get(i - 1);
// if (pre.isArrive() &&
// Objects.equals(pre.getSectionCode(), stand.getSection().getCode())) {
// if (standLastRun == null || standLastRun.getTime().isAfter(pre.getTime())) {
// jump = false;
// standLastRun = pre;
// }
// } else {
// if (standLastRun == null || standLastRun.getTime().isAfter(realRun.getTime())) {
// jump = true;
// standLastRun = realRun;
// }
// }
// }
// }
// }
// }
// }
// if (jump) {
// return standLastRun;
// }
// return null;
// }
//
// @Override
// public void calculate(StrategyCalculateData data, JumpAndParkTimeStrategy strategy) {
// List<TrainPassenger> trainPassengerList = data.getTrainPassengerList();
// LocalDateTime systemTime = data.getSystemTime();
// LocalDateTime startTime = systemTime;
// LocalDateTime endTime = systemTime.plusMinutes(Config.STRATEGY_CAL_TIME);
// boolean jump = false;
// int i = 0;
// while (startTime.isBefore(endTime) && i < 1000) {
// ++i;
// LocalDateTime nextTime = null;
// for (TrainPassenger trainPassenger : trainPassengerList) {
// String groupNumber = trainPassenger.getGroupNumber();
// List<RealRun> realRunList = data.queryRealRuns(groupNumber);
// if (CollectionUtils.isEmpty(realRunList)) {
// TripPlan tripPlan = data.queryTripPlan(trainPassenger.getServiceNumber(), trainPassenger.getTripNumber());
// if (tripPlan == null) {
// log.warn(String.format("列车[%s-%s|%s]没有找到车次计划",
// groupNumber, trainPassenger.getServiceNumber(), trainPassenger.getTripNumber()));
// continue;
// }
// if (tripPlan.isBackup()) {
// continue;
// }
// List<StationPlan> planList = tripPlan.getPlanList();
// for (StationPlan stationPlan : planList) {
// if (stationPlan.getArriveTime().compareTo(systemTime.toLocalTime()) >= 0) {
// this.handleTrainRun(data, strategy, trainPassenger, tripPlan, stationPlan);
// break;
// }
// }
// realRunList = data.queryRealRuns(groupNumber);
// if (CollectionUtils.isEmpty(realRunList)) {
// log.error(String.format("列车[%s-%s|%s],车次[%s],时间[%s]",
// groupNumber, trainPassenger.getServiceNumber(), trainPassenger.getTripNumber(),
// tripPlan.debugStr(), systemTime.toString()));
// }
// } else {
// RealRun lastRun = realRunList.get(realRunList.size() - 1);
// TripPlan tripPlan = data.queryTripPlan(lastRun.getServiceNumber(), lastRun.getTripNumber());
// StationPlan stationPlan = tripPlan.queryStationPlanByStationCode(lastRun.getStationCode());
// BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(stationPlan);
// if (lastRun.isArrive()) {
// this.handleTrainRun(data, strategy, trainPassenger, tripPlan, stationPlan);
// } else {
// if (tripPlan.isLastPlan(stationPlan)) {
// TripPlan nextTripPlan = data.queryNextTripPlan(tripPlan);
// if (nextTripPlan != null) {
// StationPlan nextStationPlan = nextTripPlan.getFirstStationPlan();
// this.handleTrainRun(data, strategy, trainPassenger, nextTripPlan, nextStationPlan);
// }
// } else {
// StationPlan nextStationPlan = tripPlan.queryNextStationPlan(stationPlan.getStation());
// this.handleTrainRun(data, strategy, trainPassenger, tripPlan, nextStationPlan);
// }
// }
// }
// // 更新nextTime
// if (!CollectionUtils.isEmpty(realRunList)) {
// RealRun last = realRunList.get(realRunList.size() - 1);
// if (nextTime == null || nextTime.isAfter(last.getTime())) {
// nextTime = last.getTime();
// }
// }
// }
// systemTime = nextTime;
// }
// }
//
// private void handleTrainRun(StrategyCalculateData data,
// JumpAndParkTimeStrategy strategy,
// TrainPassenger trainPassenger,
// TripPlan tripPlan, StationPlan stationPlan) {
// Stand stand = strategy.getJumpStand();
// String groupNumber = trainPassenger.getGroupNumber();
// List<RealRun> realRunList = data.queryRealRuns(groupNumber);
// RealRun lastRun = null;
// int offset = 0;
// if (!CollectionUtils.isEmpty(realRunList)) {
// // 获取上一个实际运行并计算时间偏移
// lastRun = realRunList.get(realRunList.size() - 1);
// TripPlan lastTripPlan = data.queryTripPlan(lastRun.getServiceNumber(), lastRun.getTripNumber());
// StationPlan lastStationPlan = lastTripPlan.queryStationPlanByStationCode(lastRun.getStationCode());
// if (lastRun.isArrive()) {
// offset = lastRun.getTime().toLocalTime().toSecondOfDay() - lastStationPlan.getArriveTime().toSecondOfDay();
// } else {
// offset = lastRun.getTime().toLocalTime().toSecondOfDay() - lastStationPlan.getLeaveTime().toSecondOfDay();
// }
// }
// if (Objects.equals(stand.getSection(), stationPlan.getSection()) && !strategy.isJumped()) { // 跳停站台计划
// // 跳停策略指定的跳停站台构建跳停运行并更新策略
// RealRun passing = this.buildRealRun(groupNumber, tripPlan, stationPlan, false,
// stationPlan.getArriveTime(), offset, data.getSystemTime());
// data.addRealRun(passing);
// strategy.jumpedByTrain(groupNumber, tripPlan);
// strategy.addOffset(-Config.TRAIN_PASS_SAVE_TIME);
// StandPassenger standPassenger = data.getStandPassengerByStand(stand);
// strategy.addEffectTrain(groupNumber);
// strategy.addExtraNum(standPassenger.getWait());
// return;
// }
// // 非跳停根据计划更新预测运行
// if (lastRun == null ||
// !Objects.equals(stationPlan.getStation().getCode(), lastRun.getStationCode())) {
// RealRun arrive = this.buildRealRun(groupNumber, tripPlan, stationPlan, true,
// stationPlan.getArriveTime(), offset, data.getSystemTime());
// data.addRealRun(arrive);
// }
// int parkTime = stationPlan.getParkTime();
// // 列车到站乘客上车更新列车上人数
// if (stationPlan.getSection().getStandList().size() == 0) {
// return;
// }
// Stand parkStand = strategy.getParkStand();
// LocalTime arriveTime = stationPlan.getArriveTime();
// LocalTime leaveTime = stationPlan.getLeaveTime();
// // 列车到站乘客上车更新列车上人数
// StandPassenger standPassenger = data.getStandPassengerByStand(stationPlan.getSection().getStandList().get(0));
// int wait = standPassenger.getWait(); // 站台等待乘客数
// int normal = (parkTime - Config.INVALID_BOARD_TIME) * Config.PASSENGER_BOARD_SPEED; // 根据停站预测的可上车人数
// int remain = Config.TRAIN_CAPACITY - trainPassenger.getNum(); // 列车上剩余可载人数
// // 大客流站计算指标
// if (Objects.equals(stationPlan.getSection(), parkStand.getSection())) {
// // 时刻表偏差
// parkTime = strategy.getTime();
// leaveTime = arriveTime.plusSeconds(parkTime);
//// strategy.addTarget1(parkTime - stationPlan.getParkTime());
//// // 乘客等待时间(按人数统计不考虑时间)
//// strategy.addTarget2(standPassenger.getWait());
// //
// strategy.addEffectTrain(groupNumber);
// int extraTime = strategy.getTime() - stationPlan.getParkTime();
// strategy.addOffset(extraTime);
// int extraNum = extraTime * Config.PASSENGER_BOARD_SPEED;
// int extra = extraNum;
// if (normal + extraNum > remain) {
// if (normal < remain) {
// extra = remain - normal;
// } else {
// extra = 0;
// }
// }
// strategy.addExtraNum(extra);
// normal += extraNum;
// }
// float min = Math.min(Math.min(wait, normal), remain); // 实际上车人数
// standPassenger.minus(min);
// trainPassenger.plus(min);
//// // 大客流站计算指标
//// if (data.isLpfStand(stationPlan.getSection())) {
//// // 乘客等待时间(按人数统计不考虑时间)
//// strategy.addTarget2(standPassenger.getWait());
//// }
// // 生成预测实际运行图
// RealRun leave = this.buildRealRun(trainPassenger.getGroupNumber(), tripPlan, stationPlan, false,
// leaveTime, offset, data.getSystemTime());
// data.addRealRun(leave);
// }
//
// @Override
// public String getName() {
// return "跳停策略服务";
// }
//
//}

View File

@ -0,0 +1,23 @@
package club.joylink.rtss.vo.client.cgy;
import javax.validation.constraints.NotEmpty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class CgyThirdPartyLoginInfoVO {
@NotEmpty(message = "appId不能为空")
private String appId;
private String sessionId;
private Long timeStamp;
@NotEmpty(message = "账号不能为空")
private String account;
@NotEmpty(message = "用户名不能为空")
private String name;
private String parentAccount;
}

View File

@ -0,0 +1,16 @@
package club.joylink.rtss.vo.client.simulationUsage;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SimulationUsageRecordQueryVO {
private Long uid;
private Long functionId;
}

View File

@ -9,9 +9,12 @@ import lombok.Setter;
@Setter
@NoArgsConstructor
public class SimulationInfoQueryVO extends PageQueryVO {
private String project;
private String group;
private String userName;
private Long functionId;
}

View File

@ -1,27 +0,0 @@
/*
package club.joylink.rtss.vo.permission;
import club.joylink.rtss.vo.permission.subject.PermissionSubjectVO;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PermissionRefParamVO {
private Long distributeId;
private Long permissionId;
public static List<PermissionRefParamVO> convert(List<PermissionSubjectVO> vo){
List<PermissionRefParamVO> list = Lists.newArrayList();
for (PermissionSubjectVO subjectVO : vo) {
list.add(new PermissionRefParamVO(subjectVO.getDistributeId(),subjectVO.getPermissionId()));
}
return list;
}
}
*/

View File

@ -0,0 +1,204 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="club.joylink.rtss.dao.CgyViewDAO">
<resultMap id="BaseResultMap" type="club.joylink.rtss.entity.CgyView">
<id column="app_id" jdbcType="VARCHAR" property="appId" />
<result column="app_secret" jdbcType="VARCHAR" property="appSecret" />
<result column="function_id" jdbcType="BIGINT" property="functionId" />
<result column="view_count" jdbcType="BIGINT" property="viewCount" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
app_id, app_secret, function_id, view_count
</sql>
<select id="selectByExample" parameterType="club.joylink.rtss.entity.CgyViewExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from cgy_view
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limit != null">
<if test="offset != null">
limit ${offset}, ${limit}
</if>
<if test="offset == null">
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from cgy_view
where app_id = #{appId,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from cgy_view
where app_id = #{appId,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="club.joylink.rtss.entity.CgyViewExample">
delete from cgy_view
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="club.joylink.rtss.entity.CgyView">
insert into cgy_view (app_id, app_secret, function_id,
view_count)
values (#{appId,jdbcType=VARCHAR}, #{appSecret,jdbcType=VARCHAR}, #{functionId,jdbcType=BIGINT},
#{viewCount,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="club.joylink.rtss.entity.CgyView">
insert into cgy_view
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="appId != null">
app_id,
</if>
<if test="appSecret != null">
app_secret,
</if>
<if test="functionId != null">
function_id,
</if>
<if test="viewCount != null">
view_count,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="appId != null">
#{appId,jdbcType=VARCHAR},
</if>
<if test="appSecret != null">
#{appSecret,jdbcType=VARCHAR},
</if>
<if test="functionId != null">
#{functionId,jdbcType=BIGINT},
</if>
<if test="viewCount != null">
#{viewCount,jdbcType=BIGINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="club.joylink.rtss.entity.CgyViewExample" resultType="java.lang.Long">
select count(*) from cgy_view
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update cgy_view
<set>
<if test="record.appId != null">
app_id = #{record.appId,jdbcType=VARCHAR},
</if>
<if test="record.appSecret != null">
app_secret = #{record.appSecret,jdbcType=VARCHAR},
</if>
<if test="record.functionId != null">
function_id = #{record.functionId,jdbcType=BIGINT},
</if>
<if test="record.viewCount != null">
view_count = #{record.viewCount,jdbcType=BIGINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update cgy_view
set app_id = #{record.appId,jdbcType=VARCHAR},
app_secret = #{record.appSecret,jdbcType=VARCHAR},
function_id = #{record.functionId,jdbcType=BIGINT},
view_count = #{record.viewCount,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="club.joylink.rtss.entity.CgyView">
update cgy_view
<set>
<if test="appSecret != null">
app_secret = #{appSecret,jdbcType=VARCHAR},
</if>
<if test="functionId != null">
function_id = #{functionId,jdbcType=BIGINT},
</if>
<if test="viewCount != null">
view_count = #{viewCount,jdbcType=BIGINT},
</if>
</set>
where app_id = #{appId,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="club.joylink.rtss.entity.CgyView">
update cgy_view
set app_secret = #{appSecret,jdbcType=VARCHAR},
function_id = #{functionId,jdbcType=BIGINT},
view_count = #{viewCount,jdbcType=BIGINT}
where app_id = #{appId,jdbcType=VARCHAR}
</update>
</mapper>