From bef6dda6b28eb4708e33aaf8a721dd539f0ee7bb Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Tue, 7 May 2024 16:47:32 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=E6=88=90=E5=B7=A5=E9=99=A2?= =?UTF-8?q?=E8=99=9A=E4=BB=BF=E5=B9=B3=E5=8F=B0=E5=AF=B9=E6=8E=A5=E7=9A=84?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3=E3=80=81=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=B9=B6=E5=90=8C=E6=AD=A5=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../club/joylink/rtss/aop/CgyViewAspect.java | 41 + .../club/joylink/rtss/bo/cgy/CgyStatsBO.java | 32 + .../joylink/rtss/constants/ProjectCode.java | 1 + .../rtss/controller/LoginController.java | 226 +-- .../simulation/SimulationV1Controller.java | 13 +- .../club/joylink/rtss/dao/CgyViewDAO.java | 12 + .../club/joylink/rtss/dao/CompanyDAO.java | 12 - .../club/joylink/rtss/entity/CgyView.java | 107 ++ .../joylink/rtss/entity/CgyViewExample.java | 482 +++++ .../rtss/services/ISysUserService.java | 15 +- .../joylink/rtss/services/LearnService.java | 838 +++++---- .../joylink/rtss/services/SysUserService.java | 101 +- .../services/auth/AuthenticateService.java | 23 +- .../services/auth/IAuthenticateService.java | 203 ++- .../rtss/services/cgy/CgyStatsService.java | 175 ++ .../user/UserSimulationRecordService.java | 30 +- .../voice/huawei/HuaweiVoiceServiceImpl.java | 78 - .../SimulationCommonController.java | 154 -- .../cbtc/ATP/ground/ZCLogicLoop.java | 687 ------- .../cbtc/CI/service/AutoSignalService.java | 59 - .../cbtc/CI/service/RouteService.java | 1618 ----------------- .../cbtc/CI/service/SectionService.java | 120 -- .../cbtc/CI/service/SignalService.java | 180 -- .../cbtc/CI/service/StandService.java | 185 -- .../cbtc/CI/service/SwitchService.java | 263 --- .../CI/service/VrSignalControlService.java | 100 - .../cbtc/ISCS/OnBoardPisService.java | 39 - .../simulation/cbtc/SimulationService.java | 116 +- .../cbtc/SimulationServiceImpl.java | 651 ++++--- .../cbtc/communication/vo/PsdSwitch.java | 22 - .../cbtc/communication/vo/SignalLight.java | 25 - .../cbtc/communication/vo/SwitchTurn.java | 22 - .../cbtc/data/support/TrainStopMessage.java | 22 - .../modbustcp/cgy/CgySectionServiceImpl.java | 44 - .../JumpAndParkTimeStrategyServiceImpl.java | 356 ---- .../client/cgy/CgyThirdPartyLoginInfoVO.java | 23 + .../SimulationUsageRecordQueryVO.java | 16 + .../simulationv1/SimulationInfoQueryVO.java | 9 +- .../vo/permission/PermissionRefParamVO.java | 27 - .../resources/mybatis/mapper/CgyViewDAO.xml | 204 +++ 40 files changed, 2303 insertions(+), 5028 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/aop/CgyViewAspect.java create mode 100644 src/main/java/club/joylink/rtss/bo/cgy/CgyStatsBO.java create mode 100644 src/main/java/club/joylink/rtss/dao/CgyViewDAO.java delete mode 100644 src/main/java/club/joylink/rtss/dao/CompanyDAO.java create mode 100644 src/main/java/club/joylink/rtss/entity/CgyView.java create mode 100644 src/main/java/club/joylink/rtss/entity/CgyViewExample.java create mode 100644 src/main/java/club/joylink/rtss/services/cgy/CgyStatsService.java delete mode 100644 src/main/java/club/joylink/rtss/services/voice/huawei/HuaweiVoiceServiceImpl.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/SimulationCommonController.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/ZCLogicLoop.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/AutoSignalService.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/RouteService.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SectionService.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SignalService.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/StandService.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SwitchService.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/VrSignalControlService.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ISCS/OnBoardPisService.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/PsdSwitch.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/SignalLight.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/SwitchTurn.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/data/support/TrainStopMessage.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/cgy/CgySectionServiceImpl.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/JumpAndParkTimeStrategyServiceImpl.java create mode 100644 src/main/java/club/joylink/rtss/vo/client/cgy/CgyThirdPartyLoginInfoVO.java create mode 100644 src/main/java/club/joylink/rtss/vo/client/simulationUsage/SimulationUsageRecordQueryVO.java delete mode 100644 src/main/java/club/joylink/rtss/vo/permission/PermissionRefParamVO.java create mode 100644 src/main/resources/mybatis/mapper/CgyViewDAO.xml diff --git a/src/main/java/club/joylink/rtss/aop/CgyViewAspect.java b/src/main/java/club/joylink/rtss/aop/CgyViewAspect.java new file mode 100644 index 000000000..5155128ed --- /dev/null +++ b/src/main/java/club/joylink/rtss/aop/CgyViewAspect.java @@ -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()); + } +} diff --git a/src/main/java/club/joylink/rtss/bo/cgy/CgyStatsBO.java b/src/main/java/club/joylink/rtss/bo/cgy/CgyStatsBO.java new file mode 100644 index 000000000..64ae32a69 --- /dev/null +++ b/src/main/java/club/joylink/rtss/bo/cgy/CgyStatsBO.java @@ -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 userSet = new HashSet<>(); + //实训时长 + private AtomicLong duration; +} diff --git a/src/main/java/club/joylink/rtss/constants/ProjectCode.java b/src/main/java/club/joylink/rtss/constants/ProjectCode.java index 90f04c2e9..9913547dc 100644 --- a/src/main/java/club/joylink/rtss/constants/ProjectCode.java +++ b/src/main/java/club/joylink/rtss/constants/ProjectCode.java @@ -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"; } diff --git a/src/main/java/club/joylink/rtss/controller/LoginController.java b/src/main/java/club/joylink/rtss/controller/LoginController.java index c053c1385..0b10cd260 100644 --- a/src/main/java/club/joylink/rtss/controller/LoginController.java +++ b/src/main/java/club/joylink/rtss/controller/LoginController.java @@ -7,136 +7,148 @@ 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") public class LoginController { - @Autowired - private IAuthenticateService iAuthenticateService; + @Autowired + private IAuthenticateService iAuthenticateService; - @PostMapping(path = "/third") - public String thirdPartyLogin(@RequestBody @Validated(ThirdLoginInfoCheck.class) LoginUserVO loginInfo) { - return this.iAuthenticateService.thirdPartyLogin(loginInfo); - } + @PostMapping("/cgy/third") + public String cgyThirdPartyLogin(@RequestBody @Validated CgyThirdPartyLoginInfoVO loginInfo) { + return this.iAuthenticateService.cgyThirdPartyLogin(loginInfo); + } - /** - * 获取微信小程序登陆二维码 - */ - @GetMapping(path = "/wmurl") - public LoginStatusVO getWmLoginUrl(@NotBlank String clientId, @NotBlank String secret, - String project, @RequestParam(required = false) String deviceCode) { - try { - return this.iAuthenticateService.getWmLoginUrl(clientId, secret, project, deviceCode); - } catch (BaseException e) { - throw e; - } catch (Exception e) { - throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("获取登录二维码失败"); - } - } + @PostMapping(path = "/third") + public String thirdPartyLogin( + @RequestBody @Validated(ThirdLoginInfoCheck.class) LoginUserVO loginInfo) { + return this.iAuthenticateService.thirdPartyLogin(loginInfo); + } - /** - * 用户微信小程序扫登陆二维码 - */ - @GetMapping(path = "/scan/wmLoginUrl") - public AccountVO scanWmLoginQrCode(String code, String state) { - return this.iAuthenticateService.scanWmLoginQrCode(code, state); + /** + * 获取微信小程序登陆二维码 + */ + @GetMapping(path = "/wmurl") + public LoginStatusVO getWmLoginUrl(@NotBlank String clientId, @NotBlank String secret, + String project, @RequestParam(required = false) String deviceCode) { + try { + return this.iAuthenticateService.getWmLoginUrl(clientId, secret, project, deviceCode); + } catch (BaseException e) { + throw e; + } catch (Exception e) { + throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("获取登录二维码失败"); } + } - /** - * 微信小程序确认登陆接口 - */ - @PostMapping(path = "/wm") - public void wmConfirmLogin(String code, String state) { - this.iAuthenticateService.wmConfirmClientLogin(code, state); - } + /** + * 用户微信小程序扫登陆二维码 + */ + @GetMapping(path = "/scan/wmLoginUrl") + public AccountVO scanWmLoginQrCode(String code, String state) { + return this.iAuthenticateService.scanWmLoginQrCode(code, state); + } - @PostMapping() - public String loginWithPwd(@RequestBody @Validated(LoginInfoCheck.class) LoginUserVO loginUser) { - return iAuthenticateService.loginWithPwd(loginUser); - } + /** + * 微信小程序确认登陆接口 + */ + @PostMapping(path = "/wm") + public void wmConfirmLogin(String code, String state) { + this.iAuthenticateService.wmConfirmClientLogin(code, state); + } - @GetMapping("/preLogout") - public void preLogout(String token) { - this.iAuthenticateService.preLogout(token); - } + @PostMapping() + public String loginWithPwd(@RequestBody @Validated(LoginInfoCheck.class) LoginUserVO loginUser) { + return iAuthenticateService.loginWithPwd(loginUser); + } - @GetMapping(path = "/logout") - public void logout(String token) { - this.iAuthenticateService.logout(token); - } + @GetMapping("/preLogout") + public void preLogout(String token) { + this.iAuthenticateService.preLogout(token); + } - @GetMapping(path = "/checkStatus") - public LoginStatusVO checkStatus(@NotBlank String sessionId) { - return iAuthenticateService.checkStatus(sessionId); - } + @GetMapping(path = "/logout") + public void logout(String token) { + this.iAuthenticateService.logout(token); + } - /** - * 获取用户信息 - 通过token - * - * @param token - * @return - */ - @GetMapping(path = "/getUserInfo") - public AccountVO getUserInfo(String token) { - LoginUserInfoVO loginUserInfoVO = this.iAuthenticateService.getLoginUserInfoByToken(token); - return loginUserInfoVO.getAccountVO(); - } + @GetMapping(path = "/checkStatus") + public LoginStatusVO checkStatus(@NotBlank String sessionId) { + return iAuthenticateService.checkStatus(sessionId); + } - /** - * 获取用户登录信息(包含登录的项目/客户端等) - * - * @param token - * @return - */ - @GetMapping("/loginUserInfo") - public LoginUserInfoVO getLoginUserInfo(String token) { - return this.iAuthenticateService.getLoginUserInfoByToken(token); - } + /** + * 获取用户信息 - 通过token + * + * @param token + * @return + */ + @GetMapping(path = "/getUserInfo") + public AccountVO getUserInfo(String token) { + LoginUserInfoVO loginUserInfoVO = this.iAuthenticateService.getLoginUserInfoByToken(token); + return loginUserInfoVO.getAccountVO(); + } - /** - * <玖琏科技>微信小程序code换取token - */ - @GetMapping(path = "/wm/token") - public String getTokenByWmCode(String code) { - return this.iAuthenticateService.getTokenByWmCode(code); - } + /** + * 获取用户登录信息(包含登录的项目/客户端等) + * + * @param token + * @return + */ + @GetMapping("/loginUserInfo") + public LoginUserInfoVO getLoginUserInfo(String token) { + return this.iAuthenticateService.getLoginUserInfoByToken(token); + } - /** - * 到那儿了小程序code换token - * - * @param code - * @return - */ - @GetMapping(path = "/wm2/token") - public String getTokenByWmCode2(String code) { - return this.iAuthenticateService.getTokenByWmCode2(code); - } + /** + * <玖琏科技>微信小程序code换取token + */ + @GetMapping(path = "/wm/token") + public String getTokenByWmCode(String code) { + return this.iAuthenticateService.getTokenByWmCode(code); + } - /** - * 郑州共赢小程序code换token - * - * @param code - * @return - */ - @GetMapping(path = "/wm/zzww/token") - public String getTokenByWmCode3(String code) { - return this.iAuthenticateService.getTokenByWmCode3(code); - } + /** + * 到那儿了小程序code换token + * + * @param code + * @return + */ + @GetMapping(path = "/wm2/token") + public String getTokenByWmCode2(String code) { + return this.iAuthenticateService.getTokenByWmCode2(code); + } - /** - * token是否过期 - */ - @GetMapping(path = "/{token}/isExpired") - public boolean isTokenExpired(@PathVariable String token) { - return this.iAuthenticateService.isTokenExpired(token); - } + /** + * 郑州共赢小程序code换token + * + * @param code + * @return + */ + @GetMapping(path = "/wm/zzww/token") + public String getTokenByWmCode3(String code) { + return this.iAuthenticateService.getTokenByWmCode3(code); + } + + /** + * token是否过期 + */ + @GetMapping(path = "/{token}/isExpired") + public boolean isTokenExpired(@PathVariable String token) { + return this.iAuthenticateService.isTokenExpired(token); + } } diff --git a/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java b/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java index a18b81ac4..70245d710 100644 --- a/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java +++ b/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java @@ -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 queryInfo(SimulationInfoQueryVO queryVO) { - List simulationList = this.simulationManager.getSimulationList(); - Stream 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); } /** diff --git a/src/main/java/club/joylink/rtss/dao/CgyViewDAO.java b/src/main/java/club/joylink/rtss/dao/CgyViewDAO.java new file mode 100644 index 000000000..e0855a1ab --- /dev/null +++ b/src/main/java/club/joylink/rtss/dao/CgyViewDAO.java @@ -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 { +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/dao/CompanyDAO.java b/src/main/java/club/joylink/rtss/dao/CompanyDAO.java deleted file mode 100644 index c9c986d2d..000000000 --- a/src/main/java/club/joylink/rtss/dao/CompanyDAO.java +++ /dev/null @@ -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 { -////} diff --git a/src/main/java/club/joylink/rtss/entity/CgyView.java b/src/main/java/club/joylink/rtss/entity/CgyView.java new file mode 100644 index 000000000..8bcf7a9f7 --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/CgyView.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/entity/CgyViewExample.java b/src/main/java/club/joylink/rtss/entity/CgyViewExample.java new file mode 100644 index 000000000..d425ee627 --- /dev/null +++ b/src/main/java/club/joylink/rtss/entity/CgyViewExample.java @@ -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 oredCriteria; + + private Integer limit; + + private Long offset; + + public CgyViewExample() { + oredCriteria = new ArrayList(); + } + + 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 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 criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List 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 values) { + addCriterion("app_id in", values, "appId"); + return (Criteria) this; + } + + public Criteria andAppIdNotIn(List 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 values) { + addCriterion("app_secret in", values, "appSecret"); + return (Criteria) this; + } + + public Criteria andAppSecretNotIn(List 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 values) { + addCriterion("function_id in", values, "functionId"); + return (Criteria) this; + } + + public Criteria andFunctionIdNotIn(List 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 values) { + addCriterion("view_count in", values, "viewCount"); + return (Criteria) this; + } + + public Criteria andViewCountNotIn(List 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); + } + } +} \ No newline at end of file diff --git a/src/main/java/club/joylink/rtss/services/ISysUserService.java b/src/main/java/club/joylink/rtss/services/ISysUserService.java index 7d4d7560f..378eb824b 100644 --- a/src/main/java/club/joylink/rtss/services/ISysUserService.java +++ b/src/main/java/club/joylink/rtss/services/ISysUserService.java @@ -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 queryAdminsAndSuperAdmins(); - AccountVO queryOrCreateThirdAccount(String parentAccount, String account); + AccountVO queryOrCreateThirdAccount(String parentAccount, String account, @NotEmpty String name); AccountVO getThirdAccount(String account); diff --git a/src/main/java/club/joylink/rtss/services/LearnService.java b/src/main/java/club/joylink/rtss/services/LearnService.java index 5c0caaee0..d5bb48030 100644 --- a/src/main/java/club/joylink/rtss/services/LearnService.java +++ b/src/main/java/club/joylink/rtss/services/LearnService.java @@ -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,362 +33,374 @@ 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 public class LearnService implements ILearnService { - @Autowired - private LearnPostDAO learnPostDAO; + @Autowired + private LearnPostDAO learnPostDAO; - @Autowired - private LearnCommentDAO learnCommentDAO; + @Autowired + private LearnCommentDAO learnCommentDAO; - @Autowired - private ISysUserService iSysUserService; + @Autowired + private ISysUserService iSysUserService; - @Autowired - private RestTemplate restTemplate; + @Autowired + private WeChatConfig weChatConfig; - @Autowired - private WeChatConfig weChatConfig; + @Autowired + private MiniProgramService miniProgramService; - @Autowired - private MiniProgramService miniProgramService; + @Autowired + private LearnMessageDAO learnMessageDAO; - @Autowired - private LearnMessageDAO learnMessageDAO; + @Autowired + private OtherConfig otherConfig; - @Autowired - private OtherConfig otherConfig; - - @Override - public PageVO queryPagedPost(LearnPostPagedQueryVO queryVO) { - PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); - LearnPostExample example = new LearnPostExample(); - if (queryVO.getProject() != null) { - example.createCriteria().andProjectEqualTo(queryVO.getProject()); - } - Page page = (Page) learnPostDAO.selectByExample(example); - List vos = page.getResult().stream().map(LearnPostVO::new).collect(Collectors.toList()); - return PageVO.convert(page, vos); + @Override + public PageVO queryPagedPost(LearnPostPagedQueryVO queryVO) { + PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); + LearnPostExample example = new LearnPostExample(); + if (queryVO.getProject() != null) { + example.createCriteria().andProjectEqualTo(queryVO.getProject()); } + Page page = (Page) learnPostDAO.selectByExample(example); + List vos = page.getResult().stream().map(LearnPostVO::new) + .collect(Collectors.toList()); + return PageVO.convert(page, vos); + } - @Override - public Long createPost(LearnPostCreateVO createVO, AccountVO user) { - //校验 - String title = createVO.getTitle(); - String project = createVO.getProject(); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(title, "名称不能为空"); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(project, "所属项目不能为空"); - confirmPostIsNotExist(project); - //添加 - LearnPost post = new LearnPost(); - post.setProject(project); - post.setTitle(title); - post.setCreatorId(user.getId()); - post.setCreateTime(LocalDateTime.now()); - post.setTopping(false); - post.setLike(0); - post.setUnlike(0); - learnPostDAO.insert(post); - return post.getId(); - } + @Override + public Long createPost(LearnPostCreateVO createVO, AccountVO user) { + //校验 + String title = createVO.getTitle(); + String project = createVO.getProject(); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(title, "名称不能为空"); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(project, "所属项目不能为空"); + confirmPostIsNotExist(project); + //添加 + LearnPost post = new LearnPost(); + post.setProject(project); + post.setTitle(title); + post.setCreatorId(user.getId()); + post.setCreateTime(LocalDateTime.now()); + post.setTopping(false); + post.setLike(0); + post.setUnlike(0); + learnPostDAO.insert(post); + return post.getId(); + } - @Override - @Transactional - public void likePost(Long postId, AccountVO accountVO) { - LearnPost post = getPostEntity(postId); - post.setLike(post.getLike() + 1); - learnPostDAO.updateByPrimaryKey(post); - } + @Override + @Transactional + public void likePost(Long postId, AccountVO accountVO) { + LearnPost post = getPostEntity(postId); + post.setLike(post.getLike() + 1); + learnPostDAO.updateByPrimaryKey(post); + } - @Override - @Transactional - public void unlikePost(Long postId, AccountVO accountVO) { - LearnPost post = getPostEntity(postId); - post.setUnlike(post.getUnlike() + 1); - learnPostDAO.updateByPrimaryKey(post); - } + @Override + @Transactional + public void unlikePost(Long postId, AccountVO accountVO) { + LearnPost post = getPostEntity(postId); + post.setUnlike(post.getUnlike() + 1); + learnPostDAO.updateByPrimaryKey(post); + } - @Override - public LearnPostVO getPostInfo(Long postId) { - LearnPost post = getPostEntity(postId); - LearnPostVO postVO = new LearnPostVO(post); - // 用户昵称 - AccountVO user = iSysUserService.findUserById(post.getCreatorId()); - postVO.setUserNickname(user.getNickname()); - postVO.setAvatarPath(user.getAvatarPath()); - return postVO; - } + @Override + public LearnPostVO getPostInfo(Long postId) { + LearnPost post = getPostEntity(postId); + LearnPostVO postVO = new LearnPostVO(post); + // 用户昵称 + AccountVO user = iSysUserService.findUserById(post.getCreatorId()); + postVO.setUserNickname(user.getNickname()); + postVO.setAvatarPath(user.getAvatarPath()); + return postVO; + } - @Override - public PageVO pagedQueryComment(Long messageId, PageQueryVO queryVO) { - checkMessageExist(messageId); - List commentVOList = new ArrayList<>(); - PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); - LearnCommentExample commentExample = new LearnCommentExample(); - commentExample.setOrderByClause("id"); - commentExample.createCriteria().andMessageIdEqualTo(messageId); - Page page = (Page) learnCommentDAO.selectByExample(commentExample); - page.getResult().forEach(comment -> commentVOList.add(convertComment(comment))); - return PageVO.convert(page, commentVOList); - } + @Override + public PageVO pagedQueryComment(Long messageId, PageQueryVO queryVO) { + checkMessageExist(messageId); + List commentVOList = new ArrayList<>(); + PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); + LearnCommentExample commentExample = new LearnCommentExample(); + commentExample.setOrderByClause("id"); + commentExample.createCriteria().andMessageIdEqualTo(messageId); + Page page = (Page) learnCommentDAO.selectByExample(commentExample); + page.getResult().forEach(comment -> commentVOList.add(convertComment(comment))); + return PageVO.convert(page, commentVOList); + } - @Override - public List queryCommentList(Long messageId) { - LearnCommentExample commentExample = new LearnCommentExample(); - commentExample.createCriteria().andMessageIdEqualTo(messageId); - List comments = learnCommentDAO.selectByExample(commentExample); - List commentVOList = new ArrayList<>(); - comments.forEach(comment -> commentVOList.add(convertComment(comment))); - return commentVOList; - } + @Override + public List queryCommentList(Long messageId) { + LearnCommentExample commentExample = new LearnCommentExample(); + commentExample.createCriteria().andMessageIdEqualTo(messageId); + List comments = learnCommentDAO.selectByExample(commentExample); + List commentVOList = new ArrayList<>(); + comments.forEach(comment -> commentVOList.add(convertComment(comment))); + return commentVOList; + } - /** - * 回复数据完善 - * - * @param comment - * @return - */ - private LearnCommentVO convertComment(LearnComment comment) { - LearnCommentVO commentVO = new LearnCommentVO(comment); - // 用户昵称 - if (comment.getCreatorId() != null) { - String nickname = iSysUserService.findUserById(comment.getCreatorId()).getNickname(); - commentVO.setUserNickname(nickname); - } - // 回复的用户的昵称 - if (comment.getParentId() != null) { - commentVO.setReplyUserNickName(iSysUserService.findUserById(comment.getParentId()).getNickname()); - } - // 回复数 - LearnCommentExample learnCommentExample = new LearnCommentExample(); - learnCommentExample.createCriteria().andMessageIdEqualTo(comment.getMessageId()).andRootIdEqualTo(comment.getId()); - commentVO.setCommentCount(learnCommentDAO.countByExample(learnCommentExample)); - return commentVO; + /** + * 回复数据完善 + * + * @param comment + * @return + */ + private LearnCommentVO convertComment(LearnComment comment) { + LearnCommentVO commentVO = new LearnCommentVO(comment); + // 用户昵称 + if (comment.getCreatorId() != null) { + String nickname = iSysUserService.findUserById(comment.getCreatorId()).getNickname(); + commentVO.setUserNickname(nickname); } + // 回复的用户的昵称 + if (comment.getParentId() != null) { + commentVO.setReplyUserNickName( + iSysUserService.findUserById(comment.getParentId()).getNickname()); + } + // 回复数 + LearnCommentExample learnCommentExample = new LearnCommentExample(); + learnCommentExample.createCriteria().andMessageIdEqualTo(comment.getMessageId()) + .andRootIdEqualTo(comment.getId()); + commentVO.setCommentCount(learnCommentDAO.countByExample(learnCommentExample)); + return commentVO; + } - @Override - public void addComment(Long messageId, LearnCreateVO commentCreateVO, AccountVO accountVO) { - checkMessageExist(messageId); - if (SystemEnv.isPrdEnv(otherConfig.getEnv())) { - this.checkContent(commentCreateVO.getContent()); - } - LearnComment comment = new LearnComment(); - comment.setContent(commentCreateVO.getContent()); - comment.setMessageId(messageId); - comment.setCreatorId(accountVO.getId()); - comment.setCreateTime(LocalDateTime.now()); - learnCommentDAO.insertSelective(comment); + @Override + public void addComment(Long messageId, LearnCreateVO commentCreateVO, AccountVO accountVO) { + checkMessageExist(messageId); + if (SystemEnv.isPrdEnv(otherConfig.getEnv())) { + this.checkContent(commentCreateVO.getContent()); } + LearnComment comment = new LearnComment(); + comment.setContent(commentCreateVO.getContent()); + comment.setMessageId(messageId); + comment.setCreatorId(accountVO.getId()); + comment.setCreateTime(LocalDateTime.now()); + learnCommentDAO.insertSelective(comment); + } - @Override - public void addComment(Long messageId, Long commentId, LearnCreateVO postCreateVO, AccountVO accountVO) { - checkMessageExist(messageId); - if (SystemEnv.isPrdEnv(otherConfig.getEnv())) { - this.checkContent(postCreateVO.getContent()); - } - LearnComment comment = new LearnComment(); - comment.setContent(postCreateVO.getContent()); - comment.setMessageId(messageId); - LearnComment parentComment = learnCommentDAO.selectByPrimaryKey(commentId); - if (Objects.isNull(parentComment.getRootId())) { // 对评论的回复 - comment.setRootId(commentId); - } else { // 对回复的回复 - comment.setRootId(parentComment.getRootId()); - } - comment.setParentId(parentComment.getCreatorId()); - comment.setCreatorId(accountVO.getId()); - comment.setCreateTime(LocalDateTime.now()); - learnCommentDAO.insertSelective(comment); + @Override + public void addComment(Long messageId, Long commentId, LearnCreateVO postCreateVO, + AccountVO accountVO) { + checkMessageExist(messageId); + if (SystemEnv.isPrdEnv(otherConfig.getEnv())) { + this.checkContent(postCreateVO.getContent()); } + LearnComment comment = new LearnComment(); + comment.setContent(postCreateVO.getContent()); + comment.setMessageId(messageId); + LearnComment parentComment = learnCommentDAO.selectByPrimaryKey(commentId); + if (Objects.isNull(parentComment.getRootId())) { // 对评论的回复 + comment.setRootId(commentId); + } else { // 对回复的回复 + comment.setRootId(parentComment.getRootId()); + } + comment.setParentId(parentComment.getCreatorId()); + comment.setCreatorId(accountVO.getId()); + comment.setCreateTime(LocalDateTime.now()); + learnCommentDAO.insertSelective(comment); + } - @Override - @Transactional - public void likeComment(Long commentId, AccountVO accountVO) { - LearnComment comment = getCommentEntity(commentId); - comment.setLike(comment.getLike() + 1); - learnCommentDAO.updateByPrimaryKey(comment); - } + @Override + @Transactional + public void likeComment(Long commentId, AccountVO accountVO) { + LearnComment comment = getCommentEntity(commentId); + comment.setLike(comment.getLike() + 1); + learnCommentDAO.updateByPrimaryKey(comment); + } - @Override - @Transactional - public void unlikeComment(Long commentId, AccountVO accountVO) { - LearnComment comment = getCommentEntity(commentId); - comment.setUnlike(comment.getUnlike() + 1); - learnCommentDAO.updateByPrimaryKey(comment); - } + @Override + @Transactional + public void unlikeComment(Long commentId, AccountVO accountVO) { + LearnComment comment = getCommentEntity(commentId); + comment.setUnlike(comment.getUnlike() + 1); + learnCommentDAO.updateByPrimaryKey(comment); + } - @Override - public void top(Long postId, AccountVO accountVO) { - LearnPost post = topCheck(postId, accountVO); - post.setTopping(true); - learnPostDAO.updateByPrimaryKey(post); - } + @Override + public void top(Long postId, AccountVO accountVO) { + LearnPost post = topCheck(postId, accountVO); + post.setTopping(true); + learnPostDAO.updateByPrimaryKey(post); + } - @Override - public void unTop(Long postId, AccountVO accountVO) { - LearnPost post = topCheck(postId, accountVO); - post.setTopping(false); - learnPostDAO.updateByPrimaryKey(post); - } + @Override + public void unTop(Long postId, AccountVO accountVO) { + LearnPost post = topCheck(postId, accountVO); + post.setTopping(false); + learnPostDAO.updateByPrimaryKey(post); + } - @Override - public void deletePost(Long postId, AccountVO accountVO) { - topCheck(postId, accountVO); - //删除留言 - LearnMessageExample messageExample = new LearnMessageExample(); - messageExample.createCriteria().andPostIdEqualTo(postId); - List messageIds = learnMessageDAO.selectByExample(messageExample).stream().map(LearnMessage::getId).collect(Collectors.toList()); - learnMessageDAO.deleteByExample(messageExample); - //删除评论 - LearnCommentExample commentExample = new LearnCommentExample(); - commentExample.createCriteria().andMessageIdIn(messageIds); - learnCommentDAO.deleteByExample(commentExample); - learnPostDAO.deleteByPrimaryKey(postId); - } + @Override + public void deletePost(Long postId, AccountVO accountVO) { + topCheck(postId, accountVO); + //删除留言 + LearnMessageExample messageExample = new LearnMessageExample(); + messageExample.createCriteria().andPostIdEqualTo(postId); + List messageIds = learnMessageDAO.selectByExample(messageExample).stream() + .map(LearnMessage::getId).collect(Collectors.toList()); + learnMessageDAO.deleteByExample(messageExample); + //删除评论 + LearnCommentExample commentExample = new LearnCommentExample(); + commentExample.createCriteria().andMessageIdIn(messageIds); + learnCommentDAO.deleteByExample(commentExample); + learnPostDAO.deleteByPrimaryKey(postId); + } - @Override - public void adminDeleteComment(Long commentId, AccountVO user) { - iSysUserService.confirmAdmin(user); - learnCommentDAO.deleteByPrimaryKey(commentId); - } + @Override + public void adminDeleteComment(Long commentId, AccountVO user) { + iSysUserService.confirmAdmin(user); + learnCommentDAO.deleteByPrimaryKey(commentId); + } - @Override - public void userDeleteComment(Long commentId, AccountVO user) { - LearnComment comment = getCommentEntity(commentId); - if (!comment.getCreatorId().equals(user.getId())) { - log.error(String.format("用户[%s]意外尝试删除别人的评论[%s]", user.getId(), commentId)); - throw BusinessExceptionAssertEnum.INVALID_OPERATION.exception("无法删除非本人的评论"); - } - learnCommentDAO.deleteByPrimaryKey(commentId); + @Override + public void userDeleteComment(Long commentId, AccountVO user) { + LearnComment comment = getCommentEntity(commentId); + if (!comment.getCreatorId().equals(user.getId())) { + log.error(String.format("用户[%s]意外尝试删除别人的评论[%s]", user.getId(), commentId)); + throw BusinessExceptionAssertEnum.INVALID_OPERATION.exception("无法删除非本人的评论"); } + learnCommentDAO.deleteByPrimaryKey(commentId); + } - @Override - public long createMessage(LearnMessageCreateVO messageCreateVO, AccountVO user) { - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(StringUtils.hasText(messageCreateVO.getContent()), - "内容不能空白"); - if (SystemEnv.isPrdEnv(otherConfig.getEnv())) { - this.checkContent(messageCreateVO.getContent()); - } - LearnMessage message = messageCreateVO.convert2DB(user.getId()); - learnMessageDAO.insert(message); - LearnMessageExample example = new LearnMessageExample(); - example.createCriteria().andPostIdEqualTo(messageCreateVO.getPostId()); - return learnMessageDAO.countByExample(example); + @Override + public long createMessage(LearnMessageCreateVO messageCreateVO, AccountVO user) { + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue( + StringUtils.hasText(messageCreateVO.getContent()), + "内容不能空白"); + if (SystemEnv.isPrdEnv(otherConfig.getEnv())) { + this.checkContent(messageCreateVO.getContent()); } + LearnMessage message = messageCreateVO.convert2DB(user.getId()); + learnMessageDAO.insert(message); + LearnMessageExample example = new LearnMessageExample(); + example.createCriteria().andPostIdEqualTo(messageCreateVO.getPostId()); + return learnMessageDAO.countByExample(example); + } - @Override - public PageVO pagedQueryMessageByPostId(Long postId, LearnMessagePagedQueryVO queryVO) { - PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); - Page page = (Page) learnMessageDAO.select(postId, queryVO); - for (LearnMessageVO vo : page.getResult()) { - vo.setComments(pagedQueryComment(vo.getId(), new PageQueryVO(1, 3))); - } - return PageVO.convert(page); + @Override + public PageVO pagedQueryMessageByPostId(Long postId, + LearnMessagePagedQueryVO queryVO) { + PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); + Page page = (Page) learnMessageDAO.select(postId, queryVO); + for (LearnMessageVO vo : page.getResult()) { + vo.setComments(pagedQueryComment(vo.getId(), new PageQueryVO(1, 3))); } + return PageVO.convert(page); + } - @Override - public void adminDeleteMessage(Long messageId, AccountVO user) { - iSysUserService.confirmAdmin(user); - deleteMessage(messageId); - } + @Override + public void adminDeleteMessage(Long messageId, AccountVO user) { + iSysUserService.confirmAdmin(user); + deleteMessage(messageId); + } - @Override - public void userDeleteMessage(Long messageId, AccountVO user) { - LearnMessage message = getMessageEntity(messageId); - if (!message.getCreatorId().equals(user.getId())) { - log.error(String.format("用户[%s]意外尝试删除别人的留言[%s]", user.getId(), messageId)); - throw BusinessExceptionAssertEnum.INVALID_OPERATION.exception("无法删除非本人的留言"); - } - deleteMessage(messageId); + @Override + public void userDeleteMessage(Long messageId, AccountVO user) { + LearnMessage message = getMessageEntity(messageId); + if (!message.getCreatorId().equals(user.getId())) { + log.error(String.format("用户[%s]意外尝试删除别人的留言[%s]", user.getId(), messageId)); + throw BusinessExceptionAssertEnum.INVALID_OPERATION.exception("无法删除非本人的留言"); } + deleteMessage(messageId); + } - @Override - public LearnPostVO queryPost(String project) { - LearnPostExample example = new LearnPostExample(); - example.createCriteria().andProjectEqualTo(project); - List learnPosts = learnPostDAO.selectByExample(example); - if (CollectionUtils.isEmpty(learnPosts)) { - return null; - } - return new LearnPostVO(learnPosts.get(0)); + @Override + public LearnPostVO queryPost(String project) { + LearnPostExample example = new LearnPostExample(); + example.createCriteria().andProjectEqualTo(project); + List learnPosts = learnPostDAO.selectByExample(example); + if (CollectionUtils.isEmpty(learnPosts)) { + return null; } + return new LearnPostVO(learnPosts.get(0)); + } - @Override - public PageVO pagedQueryMessageByProject(String project, LearnMessagePagedQueryVO queryVO) { - LearnPostVO post = queryPost(project); - if (post == null) { - log.error(String.format("项目[%s]的留言板不存在", project)); - throw new SimulationException(SimulationExceptionType.System_Fault, "该项目的留言板不存在"); - } - return pagedQueryMessageByPostId(post.getId(), queryVO); + @Override + public PageVO pagedQueryMessageByProject(String project, + LearnMessagePagedQueryVO queryVO) { + LearnPostVO post = queryPost(project); + if (post == null) { + log.error(String.format("项目[%s]的留言板不存在", project)); + throw new SimulationException(SimulationExceptionType.System_Fault, "该项目的留言板不存在"); } + return pagedQueryMessageByPostId(post.getId(), queryVO); + } - @Override - public void updatePost(Long postId, LearnPostUpdateVO updateVO, AccountVO user) { - iSysUserService.confirmAdmin(user); - LearnPost entity = getPostEntity(postId); - if (Objects.equals(updateVO.getTitle(), entity.getTitle())) - return; - entity.setTitle(updateVO.getTitle()); - learnPostDAO.updateByPrimaryKey(entity); + @Override + public void updatePost(Long postId, LearnPostUpdateVO updateVO, AccountVO user) { + iSysUserService.confirmAdmin(user); + LearnPost entity = getPostEntity(postId); + 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()), - "内容不能空白"); - LearnMessage message = messageCreateVO.convert2DB(1L); - message.setCreatorId(null); - message.setUserName(messageCreateVO.getUserName()); - learnMessageDAO.insert(message); - LearnMessageExample example = new LearnMessageExample(); - example.createCriteria().andPostIdEqualTo(messageCreateVO.getPostId()); - return learnMessageDAO.countByExample(example); - } + @Override + public long cgyCreateMessage(LearnMessageCreateVO messageCreateVO) { + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue( + StringUtils.hasText(messageCreateVO.getContent()), + "内容不能空白"); + LearnMessage message = messageCreateVO.convert2DB(1L); + message.setCreatorId(null); + message.setUserName(messageCreateVO.getUserName()); + learnMessageDAO.insert(message); + LearnMessageExample example = new LearnMessageExample(); + example.createCriteria().andPostIdEqualTo(messageCreateVO.getPostId()); + return learnMessageDAO.countByExample(example); + } - @Override - public void cgyAddComment(Long messageId, LearnCreateVO commentCreateVO) { - checkMessageExist(messageId); - LearnComment comment = new LearnComment(); - comment.setContent(commentCreateVO.getContent()); - comment.setMessageId(messageId); - comment.setCreateTime(LocalDateTime.now()); - comment.setUserName(commentCreateVO.getUserName()); - learnCommentDAO.insertSelective(comment); - } + @Override + public void cgyAddComment(Long messageId, LearnCreateVO commentCreateVO) { + checkMessageExist(messageId); + LearnComment comment = new LearnComment(); + comment.setContent(commentCreateVO.getContent()); + comment.setMessageId(messageId); + comment.setCreateTime(LocalDateTime.now()); + comment.setUserName(commentCreateVO.getUserName()); + learnCommentDAO.insertSelective(comment); + } - @Override - public void adminUpdateMessage(LearnMessageUpdateVO messageUpdateVO) { - LearnMessage messageEntity = getMessageEntity(messageUpdateVO.getId()); - messageEntity.setContent(messageUpdateVO.getContent()); - messageEntity.setCreateTime(messageUpdateVO.getCreateTime()); - learnMessageDAO.updateByPrimaryKey(messageEntity); - } + @Override + public void adminUpdateMessage(LearnMessageUpdateVO messageUpdateVO) { + LearnMessage messageEntity = getMessageEntity(messageUpdateVO.getId()); + messageEntity.setContent(messageUpdateVO.getContent()); + messageEntity.setCreateTime(messageUpdateVO.getCreateTime()); + learnMessageDAO.updateByPrimaryKey(messageEntity); + } - @Override - public void adminUpdateComment(LearnCommentUpdateVO commentUpdateVO) { - LearnComment commentEntity = getCommentEntity(commentUpdateVO.getId()); - commentEntity.setMessageId(commentUpdateVO.getMessageId()); - commentEntity.setContent(commentUpdateVO.getContent()); - commentEntity.setCreatorId(commentUpdateVO.getCreatorId()); - commentEntity.setCreateTime(commentUpdateVO.getCreateTime()); - learnCommentDAO.updateByPrimaryKey(commentEntity); - } + @Override + public void adminUpdateComment(LearnCommentUpdateVO commentUpdateVO) { + LearnComment commentEntity = getCommentEntity(commentUpdateVO.getId()); + commentEntity.setMessageId(commentUpdateVO.getMessageId()); + commentEntity.setContent(commentUpdateVO.getContent()); + commentEntity.setCreatorId(commentUpdateVO.getCreatorId()); + commentEntity.setCreateTime(commentUpdateVO.getCreateTime()); + learnCommentDAO.updateByPrimaryKey(commentEntity); + } // @Transactional // @Override @@ -400,50 +423,55 @@ public class LearnService implements ILearnService { // } // } - @Transactional - @Override - public void cgyUpdateMessageTime() { - LearnMessageExample example = new LearnMessageExample(); - example.createCriteria().andPostIdEqualTo(27L); - List allMessage = learnMessageDAO.selectByExample(example); - //删重复数据 - List list = allMessage.stream().collect(Collectors.toMap(LearnMessage::getContent, Function.identity(), (old, newValue) -> old)) - .values().stream().sorted(Comparator.comparingLong(LearnMessage::getId)).collect(Collectors.toList()); - HashSet distinctSet = new HashSet<>(list); - List deleteIds = allMessage.stream().filter(message -> !distinctSet.contains(message)).map(LearnMessage::getId).collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(deleteIds)) { - example.clear(); - example.createCriteria().andIdIn(deleteIds); - learnMessageDAO.deleteByExample(example); - } - //修改时间 - int day = 365 * 4; - Random random = new Random(); - List dayOffsetList = new ArrayList<>(); - for (LearnMessage ignored : list) { - dayOffsetList.add(random.nextInt(day)); - } - dayOffsetList.sort((i1, i2) -> i2 - i1); - Map 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()) { - List secondsOffsetList = new ArrayList<>(); - Long dayCount = dayCountMap.get(dayOffset); - for (int i = 0; i < dayCount; i++) { - secondsOffsetList.add(random.nextInt(24 * 3600 - 8 * 3600) + 8 * 3600); - secondsOffsetList.sort(Integer::compareTo); - } - for (int i = startIndex; i < startIndex + dayCount; i++) { - LearnMessage message = list.get(i); - message.setCreateTime(now.minusDays(dayOffset).plusSeconds(secondsOffsetList.get(i - startIndex))); - learnMessageDAO.updateByPrimaryKey(message); - } - startIndex += dayCount; - } + @Transactional + @Override + public void cgyUpdateMessageTime() { + LearnMessageExample example = new LearnMessageExample(); + example.createCriteria().andPostIdEqualTo(27L); + List allMessage = learnMessageDAO.selectByExample(example); + //删重复数据 + List list = allMessage.stream().collect( + Collectors.toMap(LearnMessage::getContent, Function.identity(), (old, newValue) -> old)) + .values().stream().sorted(Comparator.comparingLong(LearnMessage::getId)) + .collect(Collectors.toList()); + HashSet distinctSet = new HashSet<>(list); + List deleteIds = allMessage.stream().filter(message -> !distinctSet.contains(message)) + .map(LearnMessage::getId).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(deleteIds)) { + example.clear(); + example.createCriteria().andIdIn(deleteIds); + learnMessageDAO.deleteByExample(example); } + //修改时间 + int day = 365 * 4; + Random random = new Random(); + List dayOffsetList = new ArrayList<>(); + for (LearnMessage ignored : list) { + dayOffsetList.add(random.nextInt(day)); + } + dayOffsetList.sort((i1, i2) -> i2 - i1); + Map 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()) { + List secondsOffsetList = new ArrayList<>(); + Long dayCount = dayCountMap.get(dayOffset); + for (int i = 0; i < dayCount; i++) { + secondsOffsetList.add(random.nextInt(24 * 3600 - 8 * 3600) + 8 * 3600); + secondsOffsetList.sort(Integer::compareTo); + } + for (int i = startIndex; i < startIndex + dayCount; i++) { + LearnMessage message = list.get(i); + message.setCreateTime( + now.minusDays(dayOffset).plusSeconds(secondsOffsetList.get(i - startIndex))); + learnMessageDAO.updateByPrimaryKey(message); + } + startIndex += dayCount; + } + } - // @Override + // @Override // public Integer likeMessage(Long messageId) { // LearnMessageWithBLOBs message = getMessage(messageId); // message.setLike(message.getLike() == null ? 0 : message.getLike() + 1); @@ -459,38 +487,38 @@ public class LearnService implements ILearnService { // return message.getUnlike(); // } - private LearnComment findCommentEntity(Long commentId) { - return learnCommentDAO.selectByPrimaryKey(commentId); - } + private LearnComment findCommentEntity(Long commentId) { + return learnCommentDAO.selectByPrimaryKey(commentId); + } - private LearnComment getCommentEntity(Long commentId) { - LearnComment comment = findCommentEntity(commentId); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(comment, - "该评论不存在或已被删除"); - return comment; - } + private LearnComment getCommentEntity(Long commentId) { + LearnComment comment = findCommentEntity(commentId); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(comment, + "该评论不存在或已被删除"); + return comment; + } - private void deleteMessage(Long messageId) { - learnMessageDAO.deleteByPrimaryKey(messageId); - deleteCommentByMessageId(messageId); - } + private void deleteMessage(Long messageId) { + learnMessageDAO.deleteByPrimaryKey(messageId); + deleteCommentByMessageId(messageId); + } - private void deleteCommentByMessageId(Long messageId) { - LearnCommentExample example = new LearnCommentExample(); - example.createCriteria().andMessageIdEqualTo(messageId); - learnCommentDAO.deleteByExample(example); - } + private void deleteCommentByMessageId(Long messageId) { + LearnCommentExample example = new LearnCommentExample(); + example.createCriteria().andMessageIdEqualTo(messageId); + learnCommentDAO.deleteByExample(example); + } - private LearnPost topCheck(Long postId, AccountVO accountVO) { - iSysUserService.confirmAdmin(accountVO); - LearnPost post = getPostEntity(postId); - return post; - } + private LearnPost topCheck(Long postId, AccountVO accountVO) { + iSysUserService.confirmAdmin(accountVO); + LearnPost post = getPostEntity(postId); + return post; + } - private void checkContent(String content) { - WxError wxError = this.miniProgramService.msgSecCheck(content); - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(wxError.isError(), - String.format("内容校验不通过: [%s]", wxError.toString())); + private void checkContent(String content) { + WxError wxError = this.miniProgramService.msgSecCheck(content); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(wxError.isError(), + String.format("内容校验不通过: [%s]", wxError.toString())); // Map param = new HashMap<>(); // param.put("content", content); // WxBaseResp resp = restTemplate.postForObject(weChatConfig.getMsgSecCheckUrl(), param, WxBaseResp.class); @@ -502,44 +530,46 @@ public class LearnService implements ILearnService { // } else { // throw new BusinessException(ExceptionMapping.SERVER_CALL_EXCEPTION); // } - } + } - /** - * 留言检查 - */ - private void checkMessageExist(Long messageId) { - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(findMessageEntity(messageId), - String.format("id为[%s]的留言不存在", messageId)); - } + /** + * 留言检查 + */ + private void checkMessageExist(Long messageId) { + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(findMessageEntity(messageId), + String.format("id为[%s]的留言不存在", messageId)); + } - private LearnMessage findMessageEntity(Long messageId) { - return learnMessageDAO.selectByPrimaryKey(messageId); - } + private LearnMessage findMessageEntity(Long messageId) { + return learnMessageDAO.selectByPrimaryKey(messageId); + } - private LearnMessage getMessageEntity(Long messageId) { - LearnMessage message = findMessageEntity(messageId); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(message, String.format("id为[%s]的留言不存在", messageId)); - return message; - } + private LearnMessage getMessageEntity(Long messageId) { + LearnMessage message = findMessageEntity(messageId); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(message, + String.format("id为[%s]的留言不存在", messageId)); + return message; + } - private LearnPost findPostEntity(Long postId) { - return learnPostDAO.selectByPrimaryKey(postId); - } + private LearnPost findPostEntity(Long postId) { + return learnPostDAO.selectByPrimaryKey(postId); + } - private LearnPost getPostEntity(Long postId) { - LearnPost post = findPostEntity(postId); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(post); - return post; - } + private LearnPost getPostEntity(Long postId) { + LearnPost post = findPostEntity(postId); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(post); + return post; + } - /** - * 确认该项目的留言板不存在 - */ - private void confirmPostIsNotExist(String project) { - LearnPostExample example = new LearnPostExample(); - example.createCriteria().andProjectEqualTo(project); - BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue(learnPostDAO.countByExample(example) == 0, - String.format("项目[%s]下留言板已存在", project)); - } + /** + * 确认该项目的留言板不存在 + */ + private void confirmPostIsNotExist(String project) { + LearnPostExample example = new LearnPostExample(); + example.createCriteria().andProjectEqualTo(project); + BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertTrue( + learnPostDAO.countByExample(example) == 0, + String.format("项目[%s]下留言板已存在", project)); + } } diff --git a/src/main/java/club/joylink/rtss/services/SysUserService.java b/src/main/java/club/joylink/rtss/services/SysUserService.java index 6259b10c9..599380893 100644 --- a/src/main/java/club/joylink/rtss/services/SysUserService.java +++ b/src/main/java/club/joylink/rtss/services/SysUserService.java @@ -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 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 users = sysAccountDAO.selectByExample(example); - List voList = users.stream().map(account -> new AccountVO(account)).collect(Collectors.toList()); + List 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 getUsersWithEmail() { SysAccountExample example = new SysAccountExample(); - example.createCriteria().andMobileIsNotNull().andNationcodeIsNotNull().andStatusEqualTo(BusinessConsts.STATUS_USE); + example.createCriteria().andMobileIsNotNull().andNationcodeIsNotNull() + .andStatusEqualTo(BusinessConsts.STATUS_USE); List sysUsers = sysAccountDAO.selectByExample(example); List 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); - sysAccount.setNickname(String.format("第三方账户%s", account)); + 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 loginUserInfoVOS = loginSessionManager.queryLoginInfoByUserId(account.getId()); + List loginUserInfoVOS = loginSessionManager.queryLoginInfoByUserId( + account.getId()); if (!CollectionUtils.isEmpty(loginUserInfoVOS)) { for (LoginUserInfoVO loginInfo : loginUserInfoVOS) { AccountVO oldAccountVO = loginInfo.getAccountVO(); diff --git a/src/main/java/club/joylink/rtss/services/auth/AuthenticateService.java b/src/main/java/club/joylink/rtss/services/auth/AuthenticateService.java index 9171dd629..63a14d6c4 100644 --- a/src/main/java/club/joylink/rtss/services/auth/AuthenticateService.java +++ b/src/main/java/club/joylink/rtss/services/auth/AuthenticateService.java @@ -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()); // 构造登陆用户信息 diff --git a/src/main/java/club/joylink/rtss/services/auth/IAuthenticateService.java b/src/main/java/club/joylink/rtss/services/auth/IAuthenticateService.java index 961c0d580..3e30a2ae8 100644 --- a/src/main/java/club/joylink/rtss/services/auth/IAuthenticateService.java +++ b/src/main/java/club/joylink/rtss/services/auth/IAuthenticateService.java @@ -5,120 +5,127 @@ 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 { - /** - * 获取登陆状态/token - * - * @param sessionId - * @return - */ - LoginStatusVO checkStatus(String sessionId); + /** + * 获取登陆状态/token + * + * @param sessionId + * @return + */ + LoginStatusVO checkStatus(String sessionId); - /** - * 通过密码登陆 - * - * @param loginUser - */ - String loginWithPwd(LoginUserVO loginUser); + /** + * 通过密码登陆 + * + * @param loginUser + */ + String loginWithPwd(LoginUserVO loginUser); - /** - * 第三方登录 - * - * @param loginInfo - * @return - */ - String thirdPartyLogin(LoginUserVO loginInfo); + /** + * 第三方登录 + * + * @param loginInfo + * @return + */ + String thirdPartyLogin(LoginUserVO loginInfo); - /** - * 登出 - * - * @param token - */ - void logout(String token); + /** + * 登出 + * + * @param token + */ + void logout(String token); - /** - * 微信小程序扫登陆二维码 - * - * @param code - * @param state - * @return - */ - AccountVO scanWmLoginQrCode(String code, String state); + /** + * 微信小程序扫登陆二维码 + * + * @param code + * @param state + * @return + */ + AccountVO scanWmLoginQrCode(String code, String state); - /** - * 获取微信小程序登陆url - * - * @param clientId - * @param secret - * @param project - * @param deviceCode - * @return - */ - // LoginStatusVO getWmLoginUrl(String clientId, String secret, Project project, String deviceCode); + /** + * 获取微信小程序登陆url + * + * @param clientId + * @param secret + * @param project + * @param deviceCode + * @return + */ + // LoginStatusVO getWmLoginUrl(String clientId, String secret, Project project, String deviceCode); - /** - * TODO 20220922 用于替换上方方法 占位 - *

- * 测试文档后删除相关注释 - */ - LoginStatusVO getWmLoginUrl(String clientId, String secret, String projectCode, String deviceCode); + /** + * TODO 20220922 用于替换上方方法 占位 + *

+ * 测试文档后删除相关注释 + */ + LoginStatusVO getWmLoginUrl(String clientId, String secret, String projectCode, + String deviceCode); - /** - * 微信小程序确认登陆 - * - * @param code - * @param state - */ - void wmConfirmClientLogin(String code, String state); + /** + * 微信小程序确认登陆 + * + * @param code + * @param state + */ + void wmConfirmClientLogin(String code, String state); - /** - * 通过token获取登陆用户信息 - * - * @param token - */ - LoginUserInfoVO getLoginUserInfoByToken(String token); + /** + * 通过token获取登陆用户信息 + * + * @param token + */ + LoginUserInfoVO getLoginUserInfoByToken(String token); - /** - * 根据微信小程序code获取用户(若不存在,创建用户);若已登录,则绑定微信 - * - * @param code - * @return - */ - AccountVO getOrCreateUserByWmcode(WxApiService.MiniApp miniApp, String code); + /** + * 根据微信小程序code获取用户(若不存在,创建用户);若已登录,则绑定微信 + * + * @param code + * @return + */ + AccountVO getOrCreateUserByWmcode(WxApiService.MiniApp miniApp, String code); - /** - * 玖琏科技小程序code换token - * - * @param code - * @return - */ - String getTokenByWmCode(String code); + /** + * 玖琏科技小程序code换token + * + * @param code + * @return + */ + String getTokenByWmCode(String code); - /** - * 到那儿了小程序code换token - * - * @param code - * @return - */ - String getTokenByWmCode2(String code); + /** + * 到那儿了小程序code换token + * + * @param code + * @return + */ + String getTokenByWmCode2(String code); - /** - * 郑州共赢小程序code换token - * - * @param code - * @return - */ - String getTokenByWmCode3(String code); + /** + * 郑州共赢小程序code换token + * + * @param code + * @return + */ + String getTokenByWmCode3(String code); - boolean isTokenExpired(String token); + boolean isTokenExpired(String token); - /** - * 预登出(前端在刷新/关闭标签页的时候调用) - * - * @param token - */ - void preLogout(String token); + /** + * 预登出(前端在刷新/关闭标签页的时候调用) + * + * @param token + */ + void preLogout(String token); + + /** + * 成工业虚仿平台跳转登录接口 + */ + String cgyThirdPartyLogin(CgyThirdPartyLoginInfoVO loginInfo); } diff --git a/src/main/java/club/joylink/rtss/services/cgy/CgyStatsService.java b/src/main/java/club/joylink/rtss/services/cgy/CgyStatsService.java new file mode 100644 index 000000000..9985a7e33 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/cgy/CgyStatsService.java @@ -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 appStatsMap = new ConcurrentHashMap<>(); + private final ConcurrentHashMap functionStatsMap = new ConcurrentHashMap<>(); + + @PostConstruct + public void makeCache() { + List 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 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 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 httpEntity = new HttpEntity<>(JsonUtils.writeValueAsString(body), + httpHeaders); + + Map 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 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)); //实训时长 + } +} diff --git a/src/main/java/club/joylink/rtss/services/user/UserSimulationRecordService.java b/src/main/java/club/joylink/rtss/services/user/UserSimulationRecordService.java index c76da09fb..f33b790ac 100644 --- a/src/main/java/club/joylink/rtss/services/user/UserSimulationRecordService.java +++ b/src/main/java/club/joylink/rtss/services/user/UserSimulationRecordService.java @@ -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 queryByMapAndUserIds(Long mapId, List 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 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()), "开始时间不能晚于结束时间"); } diff --git a/src/main/java/club/joylink/rtss/services/voice/huawei/HuaweiVoiceServiceImpl.java b/src/main/java/club/joylink/rtss/services/voice/huawei/HuaweiVoiceServiceImpl.java deleted file mode 100644 index 2fb3ea259..000000000 --- a/src/main/java/club/joylink/rtss/services/voice/huawei/HuaweiVoiceServiceImpl.java +++ /dev/null @@ -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); - } -} -*/ diff --git a/src/main/java/club/joylink/rtss/simulation/SimulationCommonController.java b/src/main/java/club/joylink/rtss/simulation/SimulationCommonController.java deleted file mode 100644 index 1abbdb07b..000000000 --- a/src/main/java/club/joylink/rtss/simulation/SimulationCommonController.java +++ /dev/null @@ -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 superviseSimulation(@RequestAttribute(name=LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO, SimulationInfoQueryVO queryVO) { -// List simulationList = this.simulationManager.getSimulationList(); -// Stream 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 queryInfo(SimulationInfoQueryVO queryVO) { -// List simulationList = this.simulationManager.getSimulationList(); -// Stream 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 getSimulationUsers(@PathVariable String id) { -// return this.simulationManager.getSimulationUsers(id).stream() -// .map(SimulationUser::convertToVO) -// .collect(Collectors.toList()); -// } -// -// @GetMapping("/{id}/members") -// public List 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 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)); -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/ZCLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/ZCLogicLoop.java deleted file mode 100644 index f43c8acee..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/ZCLogicLoop.java +++ /dev/null @@ -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 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 trainList) { -// // 查找移动授权终端列表 -// List 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 findMaEnd(Simulation simulation, VirtualRealityTrain train, List trainList) { -// // 从车尾开始找(车尾主要查看是否在站台轨上,且站台轨屏蔽门开放) -// boolean right = train.isRight(); -// SectionPosition headPosition = train.getHeadPosition(); -// SectionPosition tailPosition = train.calculateTailPosition(); -// Section tailSection = tailPosition.getSection(); -// MovementAuthority.End openPsdEnd = checkPsdOpenOrClose(tailSection); -// List 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

occupiedLogicSectionList = simulation.getRepository().queryTrainOccupyAtpSectionList(train.getGroupNumber()); -// Set
occupiedLogicSectionSet; -// if (!CollectionUtils.isEmpty(occupiedLogicSectionList)) { -// occupiedLogicSectionSet = new HashSet<>(occupiedLogicSectionList); -// } else { -// occupiedLogicSectionSet = new HashSet<>(); -// } -// List
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
occupiedLogicSectionSet) { -// List
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 flsList = route.getFlsList(); -// if (!CollectionUtils.isEmpty(flsList)) { -// List 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 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 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 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 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 findItcMaEnd(SectionPosition position, boolean right) { -// List 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 endList) { -// return compareAndBuildMa(train.isRight(), endList); -// } -// -// /** -// * 比较并构建移动授权数据 -// * -// * @param endList -// * @return -// */ -// private MovementAuthority compareAndBuildMa(boolean right, List 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 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 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 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 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 switches) { -// List collect = route.getSwitchList().stream() -// .filter(element -> switches.contains(element.getASwitch())) -// .collect(Collectors.toList()); -// return routeService.checkRouteSwitchPosition(collect); -// } -// -// private boolean isFlsCheckPass(List flsList, List switches) { -// if (!CollectionUtils.isEmpty(flsList) && !CollectionUtils.isEmpty(switches)) { -// List collect = flsList.stream().filter(fls -> switches.contains(fls.getBase().getASwitch())).collect(Collectors.toList()); -// return routeService.isFlsCheckPass(collect); -// } -// return true; -// } -// -// /** -// * 筛选前方的道岔 -// */ -// private List screenSwitchesInFront(Route route, Section section) { -// boolean right = route.isRight(); -// List
sectionList = route.getSectionList(); -// List 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 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); -//// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/AutoSignalService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/AutoSignalService.java deleted file mode 100644 index b4d69e11c..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/AutoSignalService.java +++ /dev/null @@ -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
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); -//// } -// } -// -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/RouteService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/RouteService.java deleted file mode 100644 index c217e97bb..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/RouteService.java +++ /dev/null @@ -1,1618 +0,0 @@ -//package club.joylink.rtss.simulation.cbtc.CI.service; -// -//import club.joylink.rtss.exception.BusinessExceptionAssertEnum; -//import club.joylink.rtss.simulation.cbtc.Simulation; -//import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; -//import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; -//import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; -//import club.joylink.rtss.simulation.cbtc.data.map.*; -//import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; -//import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; -//import club.joylink.rtss.simulation.cbtc.exception.SimulationException; -//import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.stereotype.Component; -//import org.springframework.util.CollectionUtils; -// -//import java.time.LocalDateTime; -//import java.util.*; -//import java.util.stream.Collectors; -// -///** -// * 进路操作服务 -// */ -//@Component -//@Slf4j -//public class RouteService { -// -// @Autowired -// private SwitchService switchService; -// -// @Autowired -// private SignalService signalService; -// -// /** -// * 进路办理条件检查 -// * -// * @param simulation -// * @param route -// * @return -// */ -// public static Route.CheckFailMessage check(Simulation simulation, Route route) { -// Route.CheckFailMessage failMessage = baseCheck(simulation, route); -// if (Objects.nonNull(failMessage)) { -// return failMessage; -// } -//// // 区间运行方向检查 -//// failMessage = this.directionRodCheck(simulation, route); -//// if (Objects.nonNull(failMessage)) { -//// return failMessage; -//// } -// // 共用道岔的冲突进路检查 -// failMessage = switchUseCheck(simulation, route); -// if (Objects.nonNull(failMessage)) { -// return failMessage; -// } -// // 进路区段是否占用 -// if (!route.isCbtcMode() || route.isGround() || route.isAtp()) { -// failMessage = ciLevelCheck(route); -// } -// // 进路区段是否故障占用 -// for (Section section : route.getSectionList()) { -// for (int i = 0; i < 3; i++) { -// if (section.getParent() == null || section.isAxleCounter()) -// break; -// section = section.getParent(); -// } -// if (Section.AxleFault.FAULT.equals(section.getFault())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SectionFaultOccupied, section); -// } -// } -// return failMessage; -// } -// -// private Route.CheckFailMessage directionRodCheck(Simulation simulation, Route route) { -// List directionRodList = simulation.getRepository() -// .getListByType(MapElement.DeviceType.DIRECTION_ROD, DirectionRod.class); -// if (!CollectionUtils.isEmpty(directionRodList)) { -// for (DirectionRod directionRod : directionRodList) { -// if (directionRod.getDeviceStationList().contains(route.getInterlockStation())) { -// for (Section section : route.getSectionList()) { -// if (directionRod.getSectionList().contains(section) -// && directionRod.allowRight() != route.getStart().isRight()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.DirectionRodLimit, route); -// } -// } -// } -// } -// } -// return null; -// } -// -// /** -// * 共用道岔冲突进路检查 -// * -// * @param simulation -// * @param route -// * @return -// */ -// private static Route.CheckFailMessage switchUseCheck(Simulation simulation, Route route) { -// List routeList = simulation.getRepository().getSettingRoutes(); -// for (Route other : routeList) { -//// if (Objects.equals(other, route) && !route.isCbtcMode()) { -//// return new Route.CheckFailMessage(Route.CheckFailReason.RouteSetting, other); -//// } -// if ((Objects.nonNull(other.getOverlap()) && -// (other.getOverlap().isSetting() || other.getOverlap().isLock())) || -// checkCanOverlapSet(simulation, other)) { -// SectionPath sectionPath = other.getOverlap().selectPath(); -// if (Objects.nonNull(sectionPath)) { -// if (route.containConflictSwitch(sectionPath.getSwitchList())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.ConflictingRouteSetting, other); -// } -// } -// } -// if (checkCanOverlapSet(simulation, route)) { -// SectionPath sectionPath = route.getOverlap().selectPath(); -// if (Objects.nonNull(sectionPath)) { -// if (other.containConflictSwitch(sectionPath.getSwitchList())) { -// for (SwitchElement switchElement : other.getSwitchList()) { -// if (!switchElement.getASwitch().isRouteLock()) { -// continue; -// } -// for (SwitchElement element : sectionPath.getSwitchList()) { -// if (Objects.equals(element.getASwitch(), switchElement.getASwitch()) && -// !Objects.equals(switchElement.isNormal(), element.isNormal())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.ConflictingRouteSetting, other); -// } -// } -// } -// } -// } -// } -// if (other.isNormalUnlock()) { -// continue; -// } -// if (route.containConflictSwitch(other.getSwitchList())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.ConflictingRouteSetting, other); -// } else if (route.isOppositeTo(other) && -// other.containSameSection(route.getSectionList())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.ConflictingRouteSetting, other); -// } -// } -// return null; -// } -// -// /** -// * 进路CBTC/联锁办理条件公有检查 -// * -// * @param simulation -// * @param route -// * @return -// */ -// private static Route.CheckFailMessage baseCheck(Simulation simulation, Route route) { -// MapConfig config = simulation.getRepository().getConfig(); -// Signal start = route.getStart(); -// if (!config.isSignalBlockRouteSettable()) { -// // 信号封锁,不能办理 -// if (start.isBlockade()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.StartSignalBlockade, start); -// } -// } -// // 判断是否侧防锁闭 -// if (start.isFpl()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.StartSignalFlankProtectLock, start); -// } -//// else if (route.getDestination().isBlockade()) { -//// return new Route.CheckFailMessage(Route.CheckFailReason.StartSignalBlockade, route.getDestination()); -//// } -// // 进路内区段封锁/锁闭方向检查 -// List
sectionList = route.getSectionList(); -// for (Section section : sectionList) { -// // 封锁状态 -// if (section.isBlockade()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SectionBlockade, section); -// } else if (!CollectionUtils.isEmpty(section.getLogicList())) { -// for (Section logicSection : section.getLogicList()) { -// if (logicSection.isBlockade()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SectionBlockade, logicSection); -// } -// } -// } -// if (section.getParent() != null) { -// if (section.getParent().isCross() && section.getParent().isBlockade()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SectionBlockade, section); -// } -// } -// // 进路内区段锁闭方向不是此进路方向 -// if ((section.isRouteLock() || section.isOverlapLock()) && -// !Objects.equals(section.isLockRight(), start.isRight())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SectionLockOppositeDirection, section); -// } -// } -// // 进路内道岔封锁/锁闭/占用位置检查 -// List switchList = route.getSwitchList(); -// for (SwitchElement element : switchList) { -// Switch aSwitch = element.getASwitch(); -// // 封锁中,不能排列 -// if (aSwitch.isBlockade()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchBlockade, aSwitch); -// } -// // 是否被征用到相反位置 -// if (aSwitch.isCiUseOnOppositePosition(element.isNormal())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchCiUseOnOppositePosition, aSwitch); -// } -// // 是否锁闭在另一方向 -// if (aSwitch.isLocked() && !aSwitch.isOnPosition(element.isNormal())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchLockPositionError, aSwitch); -// } -// // 是否占用在另一个位置 -// if (aSwitch.isSectionOccupied() && !aSwitch.isOnPosition(element.isNormal())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchOccupiedPositionError, aSwitch); -// } -//// // 道岔是否故障 -//// if (aSwitch.isFaultOnPosition(element.isNormal()) && aSwitch.isLoss()) { -//// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchFault, aSwitch); -//// } -// } -// // 敌对进路办理中或已锁闭,不能办理 -// List conflictingRouteList = route.getConflictingRouteList(); -// for (Route conflict : conflictingRouteList) { -// if (conflict.isSetting() || conflict.isLock()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.ConflictingRouteSetting, conflict); -// } -// } -// return null; -// } -// -// /** -// * 进路CBTC/联锁办理条件公有检查 -// * -// * @param route -// * @return -// */ -// private Route.CheckFailMessage guideRouteCheck(Route route) { -// // 信号封锁,不能办理 -// if (route.getStart().isBlockade()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.StartSignalBlockade, route.getStart()); -// } -// // 进路内区段封锁/锁闭方向检查 -// List
sectionList = route.getSectionList(); -// for (Section section : sectionList) { -// // 封锁状态 -// if (section.isBlockade()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SectionBlockade, section); -// } -// // 进路内区段锁闭方向不是此进路方向 -// if ((section.isRouteLock() || section.isOverlapLock()) && -// !Objects.equals(section.isLockRight(), route.getStart().isRight())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SectionLockOppositeDirection, section); -// } -// } -// // 进路要经过的道岔的检测 -// List switchList = route.getSwitchList(); -// Set sectionRelSwitches = sectionList.stream().map(Section::getRelSwitch).collect(Collectors.toSet()); -// switchList = switchList.stream().filter(switchElement -> sectionRelSwitches.contains(switchElement.getASwitch())).collect(Collectors.toList()); -// for (SwitchElement element : switchList) { -// Switch aSwitch = element.getASwitch(); -// // 封锁中,不能排列 -// if (aSwitch.isBlockade()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchBlockade, aSwitch); -// } -// // 是否锁闭在另一方向 -// if (aSwitch.isLocked() && !aSwitch.isOnPosition(element.isNormal())) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchLockPositionError, aSwitch); -// } -// // 道岔是否故障 -// if (aSwitch.isFaultOnPosition(element.isNormal()) && aSwitch.isLoss()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchFault, aSwitch); -// } -// } -// // 敌对进路办理中或已锁闭,不能办理 -// List conflictingRouteList = route.getConflictingRouteList(); -// for (Route conflict : conflictingRouteList) { -// if (conflict.isSetting() || conflict.isLock()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.ConflictingRouteSetting, conflict); -// } -// } -// return null; -// } -// -// /** -// * 联锁级进路办理条件检查 -// * -// * @param route -// * @return -// */ -// private static Route.CheckFailMessage ciLevelCheck(Route route) { -// // 进路内区段占用检查 -// List
sectionList = route.getSectionList(); -// for (Section section : sectionList) { -// if (section.isOccupied()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SectionNotFree, section); -// } -//// if (section.isOccupied() && !section.isPreReset()) { -//// if (section.isSwitchTrack()) { -//// if (!section.getRelSwitch().isPreReset()) { -//// return new Route.CheckFailMessage(Route.CheckFailReason.SectionNotFree, section); -//// } -//// } else { -//// return new Route.CheckFailMessage(Route.CheckFailReason.SectionNotFree, section); -//// } -//// } -// } -// // 延续保护检查 -// RouteOverlap overlap = route.getOverlap(); -// if (Objects.nonNull(overlap)) { -// SectionPath sectionPath = overlap.selectPath(); -// List switchList = sectionPath.getSwitchList(); -// if (!CollectionUtils.isEmpty(switchList)) { -// for (SwitchElement element : switchList) { -// if (!element.getASwitch().isOnPosition(element.isNormal()) && element.getASwitch().isLocked()) { -// return new Route.CheckFailMessage(Route.CheckFailReason.SwitchLockPositionError, element.getASwitch()); -// } -// } -// } -// } -// return null; -// } -// -// /** -// * 进路办理 -// * -// * @param simulation -// * @param route -// * @return -// */ -// public Route.CheckFailMessage setting(Simulation simulation, Route route) { -// Route.CheckFailMessage check = this.check(simulation, route); -// if (Objects.nonNull(check)) { -// log.info(String.format("进路[%s]排列检查失败,无法排列:%s", route.debugStr(), check.debugStr())); -// return check; -// } -// if (route.isLock() && !route.isFleetMode()) { -// log.info(String.format("进路[%s]已经锁闭", route.debugStr())); -// return null; -// } -// // 进路开始办理 -// LocalDateTime systemTime = simulation.getSystemTime(); -// route.startSetting(systemTime); -// // 道岔征用 -// for (SwitchElement switchElement : route.getSwitchList()) { -// switchElement.getASwitch().ciUse(switchElement.isNormal()); -// } -// if (this.checkCanOverlapSet(simulation, route)) { -// route.getOverlap().startSetting(systemTime); -// SectionPath sectionPath = route.getOverlap().selectPath(); -// for (SwitchElement switchElement : sectionPath.getSwitchList()) { -// switchElement.getASwitch().ciUse(switchElement.isNormal()); -// } -// } -// simulation.getRepository().addSettingRoute(route); -// return null; -// } -// -// public static boolean checkCanOverlapSet(Simulation simulation, Route route) { -//// boolean overlapLock = false; -// MapConfig config = simulation.getRepository().getConfig(); -// RouteOverlap overlap = route.getOverlap(); -// if (Objects.isNull(overlap)) return false; -// if (Objects.nonNull(overlap)) { -// if (route.isCbtcMode() && !route.isSetOverlapInCtc()) { -// // CTC模式不办理判断 -// return false; -// } -// if (overlap.isLock() || overlap.isSetting() || overlap.isForbidden()) { -// return false; -// } -// Section section = overlap.getSection(); -// if (section.isNormalStandTrack() && section.getStandList().get(0).isTrainParking()) { -// // 列车停靠,不办理 -// return false; -// } -// SectionPath sectionPath = overlap.selectPath(); -// List switchList = sectionPath.getSwitchList(); -// if (!CollectionUtils.isEmpty(switchList)) { -// for (SwitchElement switchElement : switchList) { -// if (switchElement.getASwitch().isFaultOnPosition(switchElement.isNormal()) && switchElement.getASwitch().isLoss()) { -// // 道岔指定位置故障且失表,不再触发 -// return false; -// } else if (switchElement.getASwitch().isLocked() && !switchElement.getASwitch().isOnPosition(switchElement.isNormal())) { -// return false; -// } -// } -// } -// } -// return true; -// } -// -// /** -// * 进路办理过程 -// * -// * @param simulation -// * @param route -// */ -// public void settingProgress(Simulation simulation, Route route) { -// if (route.isSetting()) { // 进路排列中 -// MapConfig config = simulation.getRepository().getConfig(); -// if (!config.isRouteSettingNoFail()) { -// if (Objects.isNull(route.getSettingStartTime())) {//旧数据兼容逻辑 -// route.setSettingStartTime(simulation.getSystemTime()); -// } -// if (simulation.getSystemTime().isAfter(route.getSettingStartTime().plusSeconds(SimulationConstants.ROUTE_SETTING_TIMEOUT))) { -// route.settingFailed(); -//// simulation.getRepository().removeSettingRoute(route); -// route.setLock(false); -// log.info(String.format("进路[%s]办理失败,取消办理2", route.debugStr())); -// return; -// } -// } -// route.setLock(true); -// route.getStart().setLockedRoute(route); -// boolean right = route.getStart().isRight(); -// // 预先锁闭 -// if (config.isLockFirst()) { -// // 进路排列区段预先锁闭 -// List
sectionList = route.getSectionList(); -// for (Section section : sectionList) { -// if (section.isSwitchTrack()) { -// Switch relSwitch = section.getRelSwitch(); -// relSwitch.getA().routeLocking(route, right); -// if (relSwitch.isNormalPosition()) { // 定位 -// relSwitch.getB().routeLocking(route, right); -// relSwitch.getC().routeUnlocking(route); -// } else if (relSwitch.isReversePosition()) { // 反位 -// relSwitch.getC().routeLocking(route, right); -// relSwitch.getB().routeUnlocking(route); -// } else { // 失表 -// relSwitch.getB().routeLocking(route, right); -// relSwitch.getC().routeLocking(route, right); -// } -// } else { -// section.routeLocking(route, right); -// } -//// log.debug(section.debugStr() + "因<预先锁闭>锁闭"); -// } -// } -// // 征用设备 -// // 道岔位置转换 -// List switchList = route.getSwitchList(); -// this.routeSwitchTurn(simulation, switchList); -// this.routeFlsControl(simulation, route.getFlsList()); -// if (config.isLockFirst()) { -// for (SwitchElement switchElement : switchList) { -// switchElement.getASwitch().routeLock(route); -// } -// if (!CollectionUtils.isEmpty(route.getFlsList())) { -// for (RouteFls routeFls : route.getFlsList()) { -// routeFls.lock(); -// } -// } -// } -// // 设备已征用,检查进路条件 -// boolean onPosition = this.checkSwitchPosition(simulation, route); -// if (!onPosition) { // 还未转换到位置 -// return; -// } -// -// // 所有道岔已经到进路指定位值,执行区段锁闭 -// this.sectionLock(simulation, route); -// route.getStart().setLevel(Signal.LEVEL_Guide); -// // 侧防检查 -// boolean flsOnPosition = this.isFlsCheckPass(route.getFlsList()); -// if (flsOnPosition) { -// // 侧防锁闭 -// this.routeFlsLock(route.getFlsList()); -// } -// if (simulation.getSystemTime().isAfter(route.getSettingStartTime().plusSeconds(SimulationConstants.ROUTE_SETTING_TIMEOUT))) { -// route.settingFinish(); -// log.info(String.format("进路[%s]办理超时,结束", route.debugStr())); -// return; -// } -// // 联锁网络检查 -// if (this.isInterlocked(route)) { -// if (route.getStart().isBlockade()) { -// route.settingFinish(); -// return; -// } -// // 联锁检查通过,开放信号 -// this.routeOpen(simulation, route); -// if (route.getStart().isNormalOpen()) { -// log.debug(String.format("进路[%s]锁闭,始端信号机已开放", route.debugStr())); -// route.settingFinish(); -// } -// } -// } -// } -// -// private void routeFlsControl(Simulation simulation, List flsList) { -// // 侧防道岔转换 -// if (!CollectionUtils.isEmpty(flsList)) { -// List switchElementList = new ArrayList<>(); -// for (RouteFls routeFls : flsList) { -// List level1List = routeFls.getLevel1List(); -// for (RouteFls.FlsElement flsElement : level1List) { -// SwitchElement pSwitch = flsElement.getPSwitch(); -// if (pSwitch != null) { -// switchElementList.add(pSwitch); -// } -//// else if (flsElement.getFpae() != null) { -//// switchElementList.add(flsElement.getFpae()); -//// } -// } -// } -// this.routeSwitchTurn(simulation, switchElementList); -// } -// } -// -// private boolean checkSwitchPosition(Simulation simulation, Route route) { -// Set sectionRelSwitches = route.getSectionList().stream().map(Section::getRelSwitch).collect(Collectors.toSet()); -// List switchList; -// if (route.isOpenGuide()) { -// switchList = route.getSwitchList().stream().filter(element -> sectionRelSwitches.contains(element.getASwitch())).collect(Collectors.toList()); -// } else { -// switchList = route.getSwitchList(); -// } -// boolean onPosition = this.checkRouteSwitchPosition(switchList); -// if (!onPosition) return false; -//// if (!route.isCbtcMode()) { // 检查进路延续保护 -//// RouteOverlap overlap = route.getOverlap(); -//// if (Objects.nonNull(overlap) && !overlap.isLock()) { -//// return false; -//// } -//// } -// return true; -// } -// -// /** -// * 延续保护进路办理过程 -// * -// * @param simulation -// * @param overlap -// */ -// public void overlapSettingProcess(Simulation simulation, RouteOverlap overlap) { -// if (Objects.isNull(overlap) || !overlap.isSetting()) { -// return; -// } -// SectionPath sectionPath = overlap.selectPath(); -// List switchList = sectionPath.getSwitchList(); -// if (!CollectionUtils.isEmpty(switchList)) { // 判断道岔是否此延续保护征用的位置,若不是,尝试征用 -// for (SwitchElement switchElement : switchList) { -// if (!switchElement.getASwitch().ciUse(switchElement.isNormal())) { // 未征用至指定位置,返回 -// return; -// } -// } -// } -// MapConfig config = simulation.getRepository().getConfig(); -// if (!config.isRouteSettingNoFail()) { -// if (simulation.getSystemTime().isAfter(overlap.getSettingStartTime().plusSeconds(SimulationConstants.ROUTE_SETTING_TIMEOUT))) { -// overlap.settingFailed(); -// log.info(String.format("进路延续保护[%s]办理失败", overlap.debugStr())); -// return; -// } -// } -// boolean right = overlap.isRight(); -// // 延续保护区段预先锁闭 -// List
logicList = sectionPath.getLogicList(); -// if (config.isLockFirst()) { -// if (!CollectionUtils.isEmpty(logicList)) { -// for (Section section : logicList) { -// section.overlapLocking(right); -// } -// } else { -// List
sectionList = sectionPath.getSectionList(); -// for (Section section : sectionList) { -// if (section.isSwitchTrack()) { -// Switch relSwitch = section.getRelSwitch(); -// relSwitch.getA().overlapLocking(right); -// if (relSwitch.isNormalPosition()) { // 定位 -// relSwitch.getB().overlapLocking(right); -// relSwitch.getC().overlapUnlocking(); -// } else if (relSwitch.isReversePosition()) { // 反位 -// relSwitch.getC().overlapLocking(right); -// relSwitch.getB().overlapUnlocking(); -// } else { // 失表 -// relSwitch.getB().overlapLocking(right); -// relSwitch.getC().overlapLocking(right); -// } -// } else { -// section.overlapLocking(right); -// } -// } -// } -// } -// List flsList = sectionPath.getFlsList(); -// // 延续保护位置转动 -// this.routeSwitchTurn(simulation, switchList); -// this.routeFlsControl(simulation, flsList); -// if (config.isLockFirst()) { -// for (SwitchElement switchElement : switchList) { -// if (!switchElement.isOnPosition() && -// (switchElement.getASwitch().isSectionOccupied() || switchElement.getASwitch().isLocked())) { -// continue; -// } -// switchElement.getASwitch().overlapLock(); -// } -// if (!CollectionUtils.isEmpty(flsList)) { -// for (RouteFls routeFls : flsList) { -// routeFls.lock(); -// } -// } -// } -// // 道岔是否转换到位置 -// boolean onPosition = this.checkRouteSwitchPosition(switchList) && this.isFlsCheckPass(flsList); -// if (!onPosition) return; // 未到位,返回 -// if (!overlap.getSection().isRouteLock()) { -// return; -// } -// this.overlapLock(sectionPath, right); -// overlap.settingFinish(); -// log.debug(String.format("进路延续保护[%s]办理成功", overlap.debugStr())); -// } -// -// /** -// * 侧防检查是否通过 -// */ -// public boolean isFlsCheckPass(List flsList) { -// if (!CollectionUtils.isEmpty(flsList)) { -// for (RouteFls routeFls : flsList) { -// List level1List = routeFls.getLevel1List(); -// for (RouteFls.FlsElement flsElement : level1List) { -// SwitchElement pSwitch = flsElement.getPSwitch(); -// if (pSwitch != null && !pSwitch.getASwitch().isOnPosition(pSwitch.isNormal())) { -// return false; -// } -// Signal pSignal = flsElement.getPSignal(); -// if (pSignal != null && !pSignal.isClose()) { -// SwitchElement fpae = flsElement.getFpae(); -// if (fpae != null) { -// if (fpae.getASwitch().isOnPosition(fpae.isNormal())) { -// return false; -// } -// } else { -// return false; -// } -// } -//// else { -//// SwitchElement fpae = flsElement.getFpae(); -//// if (fpae != null && !fpae.getASwitch().isOnPosition(fpae.isNormal())) { -//// return false; -//// } -//// } -// } -// } -// } -// return true; -// } -// -// public boolean checkRouteSwitchPosition(Collection switchList) { -// if (!CollectionUtils.isEmpty(switchList)) { -// for (SwitchElement switchElement : switchList) { -// if (!switchElement.getASwitch().isOnPosition(switchElement.isNormal())) { -// return false; -// } -// } -// } -// return true; -// } -// -// /** -// * 进路信号开放 -// * -// * @param simulation -// * @param route -// */ -// public void routeOpen(Simulation simulation, Route route) { -// if (route.isOpenGuide() || route.isGuide()) { -// route.getStart().changeLightType(false); -// this.signalService.openGuideSignal(simulation, route.getStart()); -// log.debug(String.format("进路始端信号机[%s(%s)]开[引导信号]", -// route.getStart().getName(), route.getStart().getCode())); -// } else { -// if (route.isCbtcMode() && !route.isGround()) { -// // cbtc下,关灯 -// route.getStart().changeLightType(true); -// } else { -// route.getStart().changeLightType(false); -// } -// if (route.isOpenGreen()) { -// this.signalService.openGreenSignal(simulation, route.getStart()); -// } else { -// this.signalService.openYellowSignal(simulation, route.getStart()); -// } -// log.debug(String.format("进路始端信号机[%s(%s)]开[%s]", -// route.getStart().getName(), route.getStart().getCode(), -// route.isOpenGreen() ? "绿灯" : "黄灯")); -// } -// } -// -// /** -// * 进路始端信号关闭 -// * -// * @param simulation -// * @param route -// */ -// private void routeClose(Simulation simulation, Route route) { -// this.signalService.close(simulation, route.getStart()); -// } -// -// private void sectionLock(Simulation simulation, Route route) { -// boolean right = route.getStart().isRight(); -// // 进路区段锁闭 -// for (Section section : route.getSectionList()) { -// section.routeLocking(route, right); -// if (section.isSwitchTrack()) { -// // 道岔锁闭 -// Switch relSwitch = section.getRelSwitch(); -// if (relSwitch.isNormalPosition()) { -// relSwitch.getC().routeUnlocking(route); -// } else if (relSwitch.isReversePosition()) { -// relSwitch.getB().routeUnlocking(route); -// } -// } -//// log.debug(section.debugStr() + "在进路办理过程中锁闭"); -// } -// // 道岔锁闭 -// for (SwitchElement element : route.getSwitchList()) { -// Switch aSwitch = element.getASwitch(); -// aSwitch.routeLock(route); -// } -// -// // 延续保护 -//// if (!route.isCbtcMode()) { -//// RouteOverlap overlap = route.getOverlap(); -//// if (Objects.nonNull(overlap) && overlap.isSetting()) { -//// SectionPath sectionPath = overlap.selectPath(); -//// for (Section section : sectionPath.getSectionList()) { -//// section.overlapLocking(right); -//// if (section.isSwitchTrack()) { -//// Switch relSwitch = section.getRelSwitch(); -//// relSwitch.overlapLock(); -//// } -//// } -//// for (SwitchElement element : sectionPath.getSwitchList()) { -//// element.getASwitch().overlapLock(); -//// } -//// overlap.settingFinish(); -//// } -//// } -// } -// -// private void routeFlsLock(List flsList) { -// if (!CollectionUtils.isEmpty(flsList)) { -// for (RouteFls routeFls : flsList) { -// routeFls.lock(); -// } -// } -// } -// -// private boolean routeSwitchTurn(Simulation simulation, List routeSwitchList) { -// boolean onPosition = true; -// if (!CollectionUtils.isEmpty(routeSwitchList)) { -// for (SwitchElement element : routeSwitchList) { -// Switch aSwitch = element.getASwitch(); -// if (!aSwitch.isOnPosition(element.isNormal())) { -// // 道岔没有到达进路所需位置 -// onPosition = false; -// // 道岔需要转动 -// if (element.isNormal()) { -// this.switchService.turn2NormalPosition(simulation, aSwitch); -// } else { -// this.switchService.turn2ReversePosition(simulation, aSwitch); -// } -// } -// } -// } -// return onPosition; -// } -// -// /** -// * 取消 -// * -// * @param simulation -// * @param route -// */ -// public boolean cancelNoApproachLock(Simulation simulation, Route route) { -// if (route.isTransferRoute() && simulation.getRepository().getConfig().isTransferRouteCanOnlyFaultUnlock()) { -// throw BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.exception("转换轨进路只能通过区故解取消"); -// } -// if (route.isLock()) { // 进路锁闭 -// // 取消进路逻辑 -// if (simulation.getRepository().getConfig().isCancelAtsControlOfAllRoutesWhenCancelRoute()) { -// route.getStart().getRouteList().forEach(aRoute -> { -// aRoute.setAtsControl(false); -// aRoute.setCiControl(false); -// }); -// } else { -// route.setAtsControl(false); -// } -// if (!route.isDelayUnlocking()) { -// this.cancelWithoutCheck(simulation, route); -// } -// } else { -// log.info(String.format("进路[%s(%s)]未锁闭,不需要取消进路。", -// route.getName(), route.getCode())); -// return false; -// } -// return true; -// } -// -// /** -// * 解锁进路 -// * -// * @param simulation -// * @param route -// */ -// public void cancelWithoutCheck(Simulation simulation, Route route) { -// // 取消自动进路 -// this.cancelFleet(route); -// // 关闭始端信号机 -// this.routeClose(simulation, route); -// log.debug(String.format("取消进路,信号机[%s(%s)]关灯", -// route.getStart().getName(), route.getStart().getCode())); -// route.getStart().setLevel(Signal.LEVEL_Close); -// // 始端信号机锁闭进路置为null -// route.getStart().setLockedRoute(null); -// // 进路区段取消锁闭 -// boolean right = route.getStart().isRight(); -// List
sectionList = route.getSectionList(); -// sectionList.forEach(section -> { -// if (section.isSwitchTrack()) { -// Switch relSwitch = section.getRelSwitch(); -// relSwitch.getA().routeUnlocking(route); -// relSwitch.getB().routeUnlocking(route); -// relSwitch.getC().routeUnlocking(route); -// } else { -// section.routeUnlocking(route); -// } -// log.debug(section.debugStr() + "因取消进路解锁"); -// }); -// // 进路道岔取消锁闭 -// List switchList = route.getSwitchList(); -// if (!CollectionUtils.isEmpty(switchList)) { -// switchList.forEach(switchElement -> { -// Switch aSwitch = switchElement.getASwitch(); -// aSwitch.routeUnlock(); -// }); -// } -// // 进路侧防取消锁闭 -// List flsList = route.getFlsList(); -// if (!CollectionUtils.isEmpty(flsList)) { -// for (RouteFls routeFls : flsList) { -// routeFls.unlock(); -// } -// } -// // 进路延续保护解锁 -// RouteOverlap overlap = route.getOverlap(); -// if (Objects.nonNull(overlap)) { -// overlap.releaseImmediately(); -// log.debug(overlap.debugStr() + "因取消进路解锁"); -// } -// //进路解锁 -// route.setLock(false); -// route.setSetting(false); -// simulation.getRepository().removeSettingRoute(route); -// } -// -// /** -// * 人解 -// * -// * @param simulation -// * @param route -// */ -// public boolean humanCancel(Simulation simulation, Route route) { -// if (route.isTransferRoute() && simulation.getRepository().getConfig().isTransferRouteCanOnlyFaultUnlock()) { -// throw BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.exception("转换轨进路只能通过区故解取消"); -// } -// if (route.isGuideSignalOpen()) { //根据宁波一HMI教学视频添加该分支 -// this.cancelGuideRoute(simulation, route); -// } else { -// if (route.isDelayUnlocking()) { // 已经在延时解锁中 -// throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, -// String.format("正在延时解锁")); -// } -// if (simulation.getRepository().getConfig().isCancelAtsControlOfAllRoutesWhenCancelRoute()) { -// route.getStart().getRouteList().forEach(aRoute -> { -// aRoute.setAtsControl(false); -// aRoute.setCiControl(false); -// }); -// } else { -// route.setAtsControl(false); -// } -// // 关闭始端信号 -// this.routeClose(simulation, route); -// log.debug(String.format("人解进路,信号机[%s(%s)]关灯", -// route.getStart().getName(), route.getStart().getCode())); -// // 设置延时 -// route.getStart().setDelayTime(route.getDelayReleaseTime() * 1000); -// route.setDelayUnlocking(true); -// route.getLogicSections().forEach(section -> section.setDelayUnlock(true)); -// } -// return true; -// } -// -// /** -// * 人解进路执行进度 -// * -// * @param simulation -// * @param route -// */ -// public void humanCancelProgress(Simulation simulation, Route route) { -// if (route.isDelayUnlocking()) { // 进路延时解锁中 -// Signal start = route.getStart(); -// int delayTime = start.getDelayTime(); -// delayTime -= SimulationModule.CI.getRateMs(); -// if (delayTime <= 0) { // 延时完毕,执行解锁 -// this.cancelWithoutCheck(simulation, route); -// // 进路解锁完成 -// route.setDelayUnlocking(false); -// start.setDelayTime(0); -// route.getLogicSections().forEach(section -> section.setDelayUnlock(false)); -// } else { -// start.setDelayTime(delayTime); -// } -// } -// } -// -// /** -// * 进路始端信号机开放的联锁条件是否满足 -// * -// * @param route -// * @return -// */ -// public boolean isInterlocked(Route route) { -//// Route.CheckFailMessage failMessage; -//// if (route.isOpenGuide()) { -//// failMessage = this.guideRouteCheck(route); -//// } else { -//// failMessage = this.baseCheck(route); -//// } -//// if (Objects.nonNull(failMessage)) { -//// log.debug(String.format("联锁网络检查失败:[%s]", failMessage.toJson())); -//// return false; -//// } -// int level = checkRouteLevel(route); -// route.getStart().setLevel(level); -// if (level != Signal.LEVEL_Main) { -// -// if (route.isOpen()) { -// log.info(String.format("进路[%s]联锁检查等级为[%s]", route.debugStr(), level)); -// } -// return false; -// } -// return true; -// } -// -// private int checkRouteLevel(Route route) { -// int level = Signal.LEVEL_Close; -// if (route.isNormalUnlock()) { -// return level; -// } -// // 屏蔽门检查 -// Signal start = route.getStart(); -// Section signalSection = start.getSection(); -// if (signalSection.isNormalStandTrack()) { -// Stand stand = signalSection.getStandList().get(0); -// if (Stand.Fault.PSD_CANNOT_BE_CLOSED.equals(stand.getFault()) && !stand.isInterlockRelease()) { -// return level; -// } -// } -// // 进路区段检查 -// boolean right = start.isRight(); -// List
sectionList = route.getSectionList(); -// for (Section section : sectionList) { -// if (!section.isRouteLockOn(right)) { -// log.info(String.format("进路[%s]连锁条件检查失败:区段[%s]锁闭方向错误", route.debugStr(), -// section.debugStr())); -// return level; -// } -// if (section.isNoStatus()) { -// log.info(String.format("进路[%s]连锁条件检查失败:区段[%s]连锁无状态", route.debugStr(), -// section.debugStr())); -// return level; -// } -// } -// // 道岔位置一致检查 -// Set sectionRelSwitches = sectionList.stream().map(Section::getRelSwitch).collect(Collectors.toSet()); -// for (SwitchElement element : route.getSwitchList()) { -// if (route.isOpenGuide() && !sectionRelSwitches.contains(element.getASwitch())) { //引导进路只检查进路区段经过的道岔 -// continue; -// } -// if (!element.getASwitch().isOnPosition(element.isNormal())) { -// String p; -// if (element.getASwitch().isNormalPosition()) { -// p = "定位"; -// } else if (element.getASwitch().isReversePosition()) { -// p = "反位"; -// } else { -// p = "失表"; -// } -// log.info(String.format("进路[%s]连锁条件检查失败:道岔[%s(%s)]位置[%s]", -// route.debugStr(), -// element.getASwitch().getName(), element.getASwitch().getCode(), p)); -// return level; -// } -// } -// level = Signal.LEVEL_Guide; // 引导级 -//// if (route.getStart().isBlockade()) { -//// log.info(String.format("进路[%s]连锁条件检查失败:始端信号机封锁", route.debugStr())); -//// return level; -//// } -// //超限区段检查 -// for (SwitchElement element : route.getSwitchList()) { -// if (route.isOpenGuide() && !sectionRelSwitches.contains(element.getASwitch())) { //引导进路只检查进路区段经过的道岔 -// continue; -// } -// RouteOverrun overrun = route.findOverrunBySwitch(element.getASwitch()); -// if (overrun != null) { -// if (overrun.getSection() != null && overrun.getSection().hasNctOccupy()) { -// log.info(String.format("进路[%s]连锁条件检查失败:超限区段[%s]被占用", -// route.debugStr(), overrun.getCode())); -// return level; -// } -// SwitchElement overrunSE = overrun.getSwitchElement(); -// if (overrunSE != null && overrunSE.isOnPosition()) { -// if (overrunSE.getASwitch().getAllSections().stream().anyMatch(Section::hasNctOccupy)) { -// log.info(String.format("进路[%s]连锁条件检查失败:超限区段[%s]被占用", -// route.debugStr(), overrun.getCode())); -// return level; -// } -// } -// } -// } -// // 进路侧防检查 -// List flsList = route.getFlsList(); -// if (!route.isOpenGuide() && !CollectionUtils.isEmpty(flsList)) { -// boolean level1Result = true; -// for (RouteFls routeFls : flsList) { -// List level1List = routeFls.getLevel1List(); -// for (RouteFls.FlsElement flsElement : level1List) { -// SwitchElement pSwitch = flsElement.getPSwitch(); -// if (pSwitch != null && !pSwitch.getASwitch().isOnPosition(pSwitch.isNormal())) { -// level1Result = false; -// break; -// } else { -// SwitchElement fpae = flsElement.getFpae(); -// Signal pSignal = flsElement.getPSignal(); -// if (pSignal != null && !pSignal.isClose()) { -// if (fpae != null) { -// if (fpae.getASwitch().isOnPosition(fpae.isNormal())) { -// level1Result = false; -// } -// } else { -// level1Result = false; -// } -// } -//// if ((pSignal != null && !pSignal.isClose()) || -//// (fpae != null && !fpae.getASwitch().isOnPosition(fpae.isNormal()))) { -//// level1Result = false; -//// break; -//// } -// } -// } -// } -// if (!level1Result) { -// log.info(String.format("进路[%s]连锁条件检查失败:侧防不满足", route.debugStr())); -// return level; -// } -// } -// // 站台紧急停车 -// if (!CollectionUtils.isEmpty(route.getEspList())) { -// for (ESP esp : route.getEspList()) { -// if (esp.isEffective()) { -// log.info(String.format("进路[%s]连锁条件检查失败:站台紧急停车按钮[%s]按下", route.debugStr(), -// esp.debugStr())); -// return level; -// } -// } -// } -// // 首区段检查 -// Section firstRouteSection = route.getFirstRouteSection(); -// if (route.isCbtcMode()) { // CTC模式检查 -// // CTC模式检查进路首区段(可能是逻辑区段)是否占用 -// if (!CollectionUtils.isEmpty(firstRouteSection.getLogicList())) { -// ArrayList
logicList = new ArrayList<>(firstRouteSection.getLogicList()); -// if (!right) { -// Collections.reverse(logicList); -// } -// if (logicList.get(0).isOccupied()) { -// log.info(String.format("进路[%s]连锁条件检查失败:CTC模式首个区段占用", route.debugStr())); -// return level; -// } -// } else { -// if (firstRouteSection.isOccupied()) { -// log.info(String.format("进路[%s]连锁条件检查失败:CTC模式首个区段占用", route.debugStr())); -// return level; -// } -// } -// } else { // 后备模式检查 -// // 区段占用检查 -// Route.CheckFailMessage checkFailMessage = this.ciLevelCheck(route); -// if (Objects.nonNull(checkFailMessage)) { -// log.info(String.format("进路[%s]连锁条件检查失败:[%s]", -// route.debugStr(), checkFailMessage.toJson())); -// return level; -// } -// for (Section section : route.getSectionList()) { -// if (section.getSpeedUpLimit() != -1) { -// log.info(String.format("进路[%s]连锁条件检查失败:区段[%s]限速", -// route.debugStr(), section.debugStr())); -// return level; -// } -// if (!CollectionUtils.isEmpty(section.getLogicList())) { -// for (Section logic : section.getLogicList()) { -// if (logic.getSpeedUpLimit() != -1) { -// log.info(String.format("进路[%s]连锁条件检查失败:区段[%s]限速", -// route.debugStr(), logic.debugStr())); -// return level; -// } -// } -// } -// } -//// // 屏蔽门 -//// if (!CollectionUtils.isEmpty(route.getPsdList())) { -//// for (PSD psd : route.getPsdList()) { -//// if (!psd.isCloseAndLock()) { -//// log.debug(String.format("联锁网络检查失败:站台[%s(%s)]屏蔽门[%s(%s)]未关闭", -//// psd.getStand().getName(), psd.getStand().getCode(), -//// psd.getName(), psd.getCode())); -//// return level; -//// } -//// } -//// } -// // 站台扣车 -// if (!CollectionUtils.isEmpty(route.getStandHoldList())) { -// for (Stand stand : route.getStandHoldList()) { -// if (stand.isHoldTrain()) { -// log.info(String.format("进路[%s]连锁条件检查失败:站台[%s(%s)]扣车", -// route.debugStr(), -// stand.getName(), stand.getCode())); -// return level; -// } -// } -// } -// // 延续保护 -// RouteOverlap overlap = route.getOverlap(); -// if (overlap != null && !overlap.isLock()) { -// log.info(String.format("进路[%s]连锁条件检查失败: 延续保护未锁闭", route.debugStr())); -// return level; -// } -// } -// level = Signal.LEVEL_Main; // 主信号级 -// return level; -// } -// -// /** -// * 设置自动进路模式 -// * -// * @param route -// */ -// public void setFleet(Route route) { -// if (route.isFlt()) { -// throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, -// String.format("不是自动进路,不能设置自动进路")); -// } -// if (route.isCiControl()) { // 如果联锁自动控制 -// throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, -// String.format("进路联锁自动触发模式中,不能设置自动进路")); -// } -// if (!route.isFleetMode()) { -// route.setFleetMode(true); -// } -// } -// -// /** -// * 取消自动进路模式 -// * -// * @param route -// */ -// public void cancelFleet(Route route) { -// if (route.isFleetMode()) { -// route.setFleetMode(false); -// } -// } -// -// /** -// * 设置进路为CI自动触发 -// * -// * @param route -// */ -// public void setCIAutoTrigger(Route route) { -// if (route.isFleetMode()) { -// throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, -// String.format("进路处于自动进路模式中,不能设置联锁自动触发")); -// } -// if (route.isArs()) { -// throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, -// String.format("进路不具有该功能,无法设置为联锁自动触发")); -// } -// if (!route.isCiControl()) { -// route.setCiControl(true); -// } -// } -// -// /** -// * 取消进路CI自动触发 -// * -// * @param route -// */ -// public void cancelCIAutoTrigger(Route route) { -// if (route.isCiControl()) { -// route.setCiControl(false); -// } -// } -// -// /** -// * 引导进路办理 -// * -// * @param simulation -// * @param route -// */ -// public void settingGuideRoute(Simulation simulation, Route route) { -// // 进路排列条件校验 -// Route.CheckFailMessage checkFailMessage = this.guideRouteCheck(route); -// if (Objects.nonNull(checkFailMessage)) { -// throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, checkFailMessage.toJson()); -// } -// // 办理引导进路开始 -// route.startSetting(simulation.getSystemTime()); -// route.setOpenGuide(true); -// simulation.getRepository().addSettingRoute(route); -// } -// -// /** -// * 取消引导进路 -// * -// * @param simulation -// * @param route -// */ -// public void cancelGuideRoute(Simulation simulation, Route route) { -// route.setOpenGuide(false); -// this.cancelNoApproachLock(simulation, route); -// } -// -// /** -// * 进路正常解锁逻辑 -// * -// * @param simulation -// * @param route -// */ -// public void normalUnlock(Simulation simulation, Route route) { -// if (!route.isNormalUnlock()) { -// return; -// } -// if (!route.isFleetMode()) { // 连续通过进路不解锁,非连续通过进路随最后一辆车的运行而解锁 -// boolean right = route.getStart().isRight(); -// // 区段是顺序的(否则会有问题) -// boolean allUnlock = true; -// boolean overlapRelock = true; -// if (Objects.isNull(route.getUnlockedSection())) { -// log.error(String.format("进路[%s(%s)]正常解锁异常", route.getName(), route.getCode())); -// return; -// } -// List
sectionList = route.getSectionList(); -// for (int i = 0; i < sectionList.size(); i++) { -// Section section = sectionList.get(i); -// if (!Objects.equals(route.getUnlockedSection(), section)) { -// continue; -// } -// if (route.isLastRouteSection(section)) { -// overlapRelock = false; -// } -// Switch relSwitch = section.getRelSwitch(); -// if (section.isOccupied()) { -// // 区段逻辑占用,且有逻辑区段 -// if (section.isOccupied() && !CollectionUtils.isEmpty(section.getLogicList())) { -// // 逻辑区段占用,根据逻辑区段占用位置解锁 -// List
logicList = section.getLogicList(); -// if (!right) { // 向左,逻辑区段列表reverse -// logicList = new ArrayList<>(section.getLogicList()); -// Collections.reverse(logicList); -// } -// for (Section logic : logicList) { -// if (!logic.isOccupied()) { -// logic.routeUnlocking(route); -// } else { -// break; -// } -// } -// } -// allUnlock = false; -// break; -// } else { -// if (section.isSwitchTrack()) { // 如果是道岔区段,解锁道岔 -// section.routeUnlocking(route); -// if (section.getParent() != null && section.getParent().isCross()) { -// section.getParent().routeUnlocking(route); -// } -// relSwitch.routeUnlock(); -// // 侧防解锁 -// route.unlockRouteFlsOfSwitch(relSwitch); -// //检查道岔的联动道岔和计轴关联道岔是否可以解锁 -// for (SwitchElement switchElement : route.getSwitchList()) { -// if (switchElement.getASwitch().equals(relSwitch)) { -// continue; -// } -// Switch aSwitch = switchElement.getASwitch(); -// if (route.isRouteSection(aSwitch.getA())) { -// continue; -// } -// if (relSwitch.isLinkedSwitch(aSwitch) || relSwitch.isBConnectTo(aSwitch)) { -// if (!aSwitch.getA().isRouteLock()) { -// aSwitch.routeUnlock(); -// } -// } -// } -// } else { -// section.routeUnlocking(route); -// } -// log.debug(section.debugStr() + "因正常解锁解锁"); -// } -// if (!section.isRouteLock() && (i + 1) < sectionList.size()) { -// // 区段已经解锁,更新解锁区段 -// route.updateUnlockedSection(sectionList.get(i + 1)); -// } else if (section.isRouteLock() && (i + 1) >= sectionList.size()) { -// allUnlock = true; -// } -// } -// Section firstRouteSection = route.getFirstRouteSection(); -// if (firstRouteSection.isFree()) { -// route.getStart().setReblockade(false); -// } -// if (allUnlock) { // 进路所有区段都已经解锁,解锁完成 -// route.normalUnlockOver(); -// simulation.getRepository().removeSettingRoute(route); -// log.debug(String.format("进路[%s(%s)-%s]解锁完毕,移除", route.getName(), route.getCode(), route.isTurnBack() ? "Z" : "B")); -// } -// if (overlapRelock) { -// // 延续保护重新锁闭 -// this.checkAndSetLockedRouteOverlap(simulation, route); -// } -// } -// } -// -// private void overlapLock(SectionPath sectionPath, boolean right) { -// List
sectionList = sectionPath.getSectionList(); -// if (!CollectionUtils.isEmpty(sectionPath.getLogicList())) { -// sectionList = sectionPath.getLogicList(); -// } -// for (Section section : sectionList) { -// if (section.isSwitchTrack()) { -// Switch relSwitch = section.getRelSwitch(); -// relSwitch.overlapLock(); -// relSwitch.getA().overlapLocking(right); -// if (relSwitch.isNormalPosition()) { -// relSwitch.getB().overlapLocking(right); -// relSwitch.getC().overlapUnlocking(); -// } else { -// relSwitch.getC().overlapLocking(right); -// relSwitch.getB().overlapUnlocking(); -// } -// } else { -// if (!section.isOverlapLock()) { -// section.overlapLocking(right); -// } -// } -// } -// // 侧防锁闭 -// this.routeFlsLock(sectionPath.getFlsList()); -// } -// -// public void normalUnlockStart(Simulation simulation, Route lockedRoute) { -// if (lockedRoute.isNormalUnlock()) { -// return; -// } -// if (lockedRoute.isOpen()) { -// // 关闭始端信号 -// this.routeClose(simulation, lockedRoute); -// lockedRoute.getStart().setLevel(Signal.LEVEL_Close);// 关闭 -// log.debug(String.format("正常解锁,信号机[%s(%s)]关灯", -// lockedRoute.getStart().getName(), lockedRoute.getStart().getCode())); -// } -// if (lockedRoute.isFleetMode()) { // 进路车队模式,不解锁 -// return; -// } -// // 进路解锁开始信号 -// lockedRoute.setSetting(false); -// lockedRoute.normalUnlockStart(); -// lockedRoute.setLock(false); -// } -// -// /** -// * 进路开放后,持续检查联锁条件满足,若不满足,需关闭信号 -// * -// * @param simulation -// * @param route -// */ -// public void lockedRouteCheck(Simulation simulation, Route route) { -// // 区段锁闭在进路方向上 -// boolean right = route.getStart().isRight(); -// for (Section section : route.getSectionList()) { -// if (!section.isRouteLock()) { -// section.routeLocking(route, right); -// } -// } -// // 判断是否列车进入正常解锁 -// Section firstLogicSection = route.getFirstLogicSection(); -// if (firstLogicSection.isCtOccupied() || firstLogicSection.isNctOccupied()) { -// this.normalUnlockStart(simulation, route); -// return; -// } -// if (route.isOpen()) { -// boolean interlocked = this.isInterlocked(route); -// if (!interlocked) { -// // 进路信号开放,联锁逻辑不满足,需关闭信号 -// if (route.getStart().getLevel() == Signal.LEVEL_Guide) { -// route.getStart().setReblockade(true); -// } -// if (route.isOpen()) { -// this.routeClose(simulation, route); -// log.info(String.format("进路[%s]始端信号联锁条件不满足,信号机[%s(%s)]关灯", -// route.debugStr(), route.getStart().getName(), route.getStart().getCode())); -// } -// } -// } -// RouteOverlap overlap = route.getOverlap(); -// if (route.isOpen()) { -// if (this.checkCanOverlapSet(simulation, route) && !overlap.isLock()) { -// this.checkAndSetLockedRouteOverlap(simulation, route); -// } -// } -// } -// -// /** -// * 延续保护取消锁闭 -// */ -// public void overlapCancelLock(RouteOverlap overlap) { -// SectionPath sectionPath = overlap.selectPath(); -// List switchList = sectionPath.getSwitchList(); -// List flsList = sectionPath.getFlsList(); -// boolean onPosition = this.checkRouteSwitchPosition(switchList) && this.isFlsCheckPass(flsList); -// if (!onPosition) { -// overlap.setLock(false); -// } -// } -// -// public void checkAndSetLockedRouteOverlap(Simulation simulation, Route route) { -// RouteOverlap overlap = route.getOverlap(); -// if (route.isCbtcMode() && this.checkCanOverlapSet(simulation, route)) { -// overlap.startSetting(simulation.getSystemTime()); -// } -// } -// -// public void overlapUnlock(Simulation simulation, RouteOverlap overlap) { -// if (!overlap.isLock()) { -// return; -// } -// SectionPath sectionPath = overlap.selectPath(); -// if (Objects.nonNull(sectionPath)) { -//// boolean routeLock = true; -//// for (Section section : sectionPath.getSectionList()) { -//// if (!section.isRouteLock()) { -//// routeLock = false; -//// break; -//// } -//// } -//// if (routeLock) { // 延续保护区段进路锁闭,立即解锁 -//// overlap.releaseImmediately(); -//// } else -// if (overlap.getSection().isRouteLock() && -// overlap.getSection().isOccupied()) { // 前方进路最后子进路占用,触发/解锁执行 -// if (!overlap.isReleasing()) { -// log.debug(String.format("[%s]延续保护[%s],触发区段[%s(%s)]触发开始解锁", -// overlap.isRight() ? "右向" : "左向", overlap.getName(), -// overlap.getSection().getName(), overlap.getSection().getCode())); -// overlap.startReleasing(); -// } else { -// overlap.releaseProgress(); -// } -// } else if (!overlap.getSection().isRouteLock()) { -// // 最后子进路解锁,则延续保护解锁 -// overlap.releaseImmediately(); -// log.debug(overlap.debugStr() + "因前方进路最后子进路解锁而解锁"); -// } else { -// boolean allUnlock = true; -// -// List
logicList = sectionPath.getLogicList(); -// if (!CollectionUtils.isEmpty(logicList)) { -// for (Section section : logicList) { -// if (section.isOverlapLock()) { -// allUnlock = false; -// break; -// } -// } -// } else { -// for (Section section : sectionPath.getSectionList()) { -// if (section.isOverlapLock()) { -// allUnlock = false; -// break; -// } -// } -// } -// if (allUnlock) { -// overlap.releaseImmediately(); -// log.debug(overlap.debugStr() + "因关联区段全部非延续保护锁闭,故解锁"); -// } -// } -// } -// } -// -// public void checkLockOverlap(Simulation simulation, RouteOverlap overlap) { -// if (!overlap.isLock()) { -// boolean right = overlap.isRight(); -// // 延续保护前方进路最后子进路锁闭,且无占用,延续保护触发区段占用,则尝试触发设置 -// if (overlap.getSection().isRouteLockOn(right) && -// !overlap.getSection().isOccupied() && -// overlap.isTriggerSectionOccupied()) { -// // 查找延续保护道岔位置正确的路径,进行延续保护设置 -// List pathList = overlap.getPathList(); -// SectionPath settingPath = null; -// for (SectionPath path : pathList) { -// boolean setting = true; -// List switchList = path.getSwitchList(); -// for (SwitchElement element : switchList) { -// if (!element.getASwitch().isOnPosition(element.isNormal())) { -// setting = false; -// break; -// } -// } -// List
logicList = path.getLogicList(); -// if (!CollectionUtils.isEmpty(logicList)) { -// for (Section section : logicList) { -// if (section.isLockedOn(!right)) { -// // 区段锁闭在相反方向 -// setting = false; -// break; -// } -// } -// } else { -// List
sectionList = path.getSectionList(); -// for (Section section : sectionList) { -// if (section.isLockedOn(!right)) { -// // 区段锁闭在相反方向 -// setting = false; -// break; -// } -// } -// } -// if (setting) { -// settingPath = path; -// break; -// } -// } -// if (Objects.nonNull(settingPath)) { -// for (SwitchElement element : settingPath.getSwitchList()) { -// element.getASwitch().overlapLock(); -// } -// List
logicList = settingPath.getLogicList(); -// if (!CollectionUtils.isEmpty(logicList)) { -// for (Section section : logicList) { -// section.overlapLocking(right); -// } -// } else { -// for (Section section : settingPath.getSectionList()) { -// section.overlapLocking(right); -// } -// } -// overlap.setLock(true); -// } -// } -// } -// } -// -// public void handleTrainStopMessage(Simulation simulation, VirtualRealityTrain train) { -// // 进路最后一个区段通信车停车,进路延续保护立即解锁 -// Section section = train.getHeadPosition().getSection(); -// if (!section.isRouteLock()) -// return; -// if (!train.isParkingAt()) -// return; -// List overlapList = simulation.getRepository() -// .getListByType(MapElement.DeviceType.OVERLAP, RouteOverlap.class); -// for (RouteOverlap routeOverlap : overlapList) { -// if (routeOverlap.allSectionsOl() && -// section.isRouteLockOn(routeOverlap.isRight()) && routeOverlap.isRouteLastSection(section)) { -// // 是此延续保护的解锁区段,立即解锁 -// routeOverlap.releaseImmediately(); -// log.debug(String.format("收到列车[%s]停稳消息,[%s]延续保护[%s],触发区段[%s(%s)]立即解锁", -// train.getGroupNumber(), -// routeOverlap.isRight() ? "右向" : "左向", routeOverlap.getName(), -// routeOverlap.getSection().getName(), routeOverlap.getSection().getCode())); -// break; -// } -// } -// } -// -// public void checkAndAllowOverlap(Simulation simulation, RouteOverlap overlap) { -// if (overlap.isForbidden()) { -// if (!overlap.getSection().isOccupied()) { -// overlap.allowLock(); -// } else { -// SectionPath sectionPath = overlap.selectPath(); -// if (Objects.nonNull(sectionPath)) { -// for (Section section : sectionPath.getSectionList()) { -// if (section.isOccupied()) { -// overlap.allowLock(); -// break; -// } -// } -// } -// } -// } -// } -// -// public void setOverlap(Simulation simulation, Signal signal, RouteOverlap overlap) { -// overlap.startSetting(simulation.getSystemTime()); -// } -// -// public boolean isApproachLock(SimulationDataRepository repository, Route route) { -// TrainInfo firstTrain = repository.querySignalApproachedFirstTrain(route.getStart()); -// if (route.getStart().isApproachLock()) { // 接近锁闭,总人解 -// if (firstTrain == null || !firstTrain.isStop()) { -// return true; -// } -// } -// return false; -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SectionService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SectionService.java deleted file mode 100644 index 50028bbdc..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SectionService.java +++ /dev/null @@ -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 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); -// } -// } -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SignalService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SignalService.java deleted file mode 100644 index 935ec154a..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SignalService.java +++ /dev/null @@ -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 routeList = signal.getRouteList(); -// if (!CollectionUtils.isEmpty(routeList)) { -// routeList.forEach(route -> route.setCbtcMode(cbtc)); -// applicationContext.publishEvent(new RouteModeChangeEvent(this, simulation, routeList)); -// } -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/StandService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/StandService.java deleted file mode 100644 index e59fd1097..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/StandService.java +++ /dev/null @@ -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); -// } -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SwitchService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SwitchService.java deleted file mode 100644 index 6f5cb2aa4..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/SwitchService.java +++ /dev/null @@ -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 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 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 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)); -// } -// } -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/VrSignalControlService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/VrSignalControlService.java deleted file mode 100644 index 7af5bf51a..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/VrSignalControlService.java +++ /dev/null @@ -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); -// } -// } -// -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ISCS/OnBoardPisService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ISCS/OnBoardPisService.java deleted file mode 100644 index a84ea74ec..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ISCS/OnBoardPisService.java +++ /dev/null @@ -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); -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java index 9a21e5d99..f62a7424b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java @@ -8,78 +8,82 @@ 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); - /** - * 给仿真添加功能 - */ - void addItems(String simulationId, Map itemMap); + /** + * 创建仿真 + */ + String createSimulation(long mapId, SimulationWorkParamVO workParamVO, + @NonNull LoginUserInfoVO loginUserInfoVO); - /** - * 从仿真中移除功能 - */ - void removeItems(String simulationId, List items, LoginUserInfoVO loginInfo); + /** + * 给仿真添加功能 + */ + void addItems(String simulationId, Map itemMap); - /** - * 按计划行车 - */ - void runAsPlan(String simulationId, RunAsPlanParam param); + /** + * 从仿真中移除功能 + */ + void removeItems(String simulationId, List items, + LoginUserInfoVO loginInfo); - /** - * 重置仿真 - */ - void reset(String simulationId); + /** + * 按计划行车 + */ + void runAsPlan(String simulationId, RunAsPlanParam param); - /** - * 根据地图和功能ID获取仿真GroupId - * - * @param mapId 地图ID - * @param mapFunctionId 功能ID - * @return 仿真GroupId - */ - String querySimulationByMapIdAndMapFunction(long mapId, long mapFunctionId); + /** + * 重置仿真 + */ + void reset(String simulationId); + + /** + * 根据地图和功能ID获取仿真GroupId + * + * @param mapId 地图ID + * @param mapFunctionId 功能ID + * @return 仿真GroupId + */ + String querySimulationByMapIdAndMapFunction(long mapId, long mapFunctionId); - /** - * 根据地图和功能ID获取仿真GroupId返回仿真对象 - * - * @param mapId 地图ID - * @param mapFunctionId 功能ID - * @return 仿真GroupId - */ - Simulation querySimulation(long mapId, long mapFunctionId); + /** + * 根据地图和功能ID获取仿真GroupId返回仿真对象 + * + * @param mapId 地图ID + * @param mapFunctionId 功能ID + * @return 仿真GroupId + */ + Simulation querySimulation(long mapId, long mapFunctionId); - /** - * 监控仿真 - */ - void monitor(String simulationId, AccountVO user); + /** + * 监控仿真 + */ + void monitor(String simulationId, AccountVO user); - /** - * 后台创建仿真 - * - * @param mapFunctionId mapFunctionId 功能ID - * @param loginInfo 登录信息 - * @param checkAuth 是否检查权限 - * @return 仿真对象 - */ - Simulation createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth); + /** + * 后台创建仿真 + * + * @param mapFunctionId mapFunctionId 功能ID + * @param loginInfo 登录信息 + * @param checkAuth 是否检查权限 + * @return 仿真对象 + */ + Simulation createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth); - void loadDraftRunPlan(String simulationId, long draftRunPlanId); + void loadDraftRunPlan(String simulationId, long draftRunPlanId); - SimulationVO querySimulationJoinedByUser(long userId); + SimulationVO querySimulationJoinedByUser(long userId); - List listSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO); + List listSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO); - PageVO pagedSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO); + PageVO pagedSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO); - void sendUnreceivedMessages(String simulationId, String memberId); + void sendUnreceivedMessages(String simulationId, String memberId); + + List listAllSimulation(SimulationInfoQueryVO queryVO); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java index c59bae9d4..372a1ce4b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java @@ -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,58 +51,58 @@ 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 - private SimulationWorkServiceManager simulationWorkServiceManager; - @Autowired - private GroupSimulationService groupSimulationService; - @Autowired - private ApplicationContext applicationContext; - @Autowired - private DefaultMessageSender defaultMessageSender; - @Autowired - private RtsMapFunctionService rtsMapFunctionService; - @Autowired - private StompMessageService stompMessageService; - @Autowired - private RunPlanDraftService runPlanDraftService; - @Autowired - private SimulationLifeCycleService simulationLifeCycleService; - @Autowired - private PermissionSubjectService subjectService; + @Autowired + private SimulationManager simulationManager; + @Autowired + private SimulationWorkServiceManager simulationWorkServiceManager; + @Autowired + private GroupSimulationService groupSimulationService; + @Autowired + private ApplicationContext applicationContext; + @Autowired + private DefaultMessageSender defaultMessageSender; + @Autowired + private RtsMapFunctionService rtsMapFunctionService; + @Autowired + private StompMessageService stompMessageService; + @Autowired + private RunPlanDraftService runPlanDraftService; + @Autowired + private SimulationLifeCycleService simulationLifeCycleService; - @Autowired - private ISysUserService iSysUserService; + @Autowired + private PermissionSubjectService subjectService; - @Autowired - private IVoiceDiscriminateRule discriminateRule; + @Autowired + private ISysUserService iSysUserService; + + @Autowired + private IVoiceDiscriminateRule discriminateRule; - @Override - public String createSimulation(long mapId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO) { - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(workParamVO.containsRealDeviceItem(), "此途径创建的仿真不能连接真实设备"); - return createSimulation(mapId, null, workParamVO, loginUserInfoVO, null).getId(); - } + @Override + 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 filterUserPermission(List subjectVOList, MapFunctionVO functionVO, LoginUserInfoVO loginUserInfoVO) { - List newVoList = Lists.newArrayList(); - for (PermissionSubjectVO subjectVO : subjectVOList) { - if (subjectVO.getStartTime().isAfter(LocalDateTime.now())) { - log.info("权限主体id:[{}] 用户id:[{}] 开始时间:[{}]未到时间", subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getStartTime()); - continue; - } - if (!CollectionUtils.isEmpty(subjectVO.getSystemAbilityList())) { + //只获取所有与该功能相关的权限信息 + private List filterUserPermission(List subjectVOList, + MapFunctionVO functionVO, LoginUserInfoVO loginUserInfoVO) { + List newVoList = Lists.newArrayList(); + for (PermissionSubjectVO subjectVO : subjectVOList) { + if (subjectVO.getStartTime().isAfter(LocalDateTime.now())) { + log.info("权限主体id:[{}] 用户id:[{}] 开始时间:[{}]未到时间", subjectVO.getId(), + subjectVO.getSubjectId(), subjectVO.getStartTime()); + continue; + } + if (!CollectionUtils.isEmpty(subjectVO.getSystemAbilityList())) { /* if(Objects.equals(PermissionTypeEnum.PROJECT.getValue(),subjectVO.getPermissionType())){ if(Objects.equals(subjectVO.getPermissionProjectCode(),loginUserInfoVO.getProject().toLowerCase())){ newVoList.add(subjectVO); @@ -104,285 +113,339 @@ public class SimulationServiceImpl implements SimulationService { newVoList.add(subjectVO); } }else{*/ - for (PermissionSystemAbilityVO permissionSystemAbilityVO : subjectVO.getSystemAbilityList()) { - if (Objects.equals(permissionSystemAbilityVO.getAbilityId(), functionVO.getId())) { - newVoList.add(subjectVO); - break; - } - } + for (PermissionSystemAbilityVO permissionSystemAbilityVO : subjectVO.getSystemAbilityList()) { + if (Objects.equals(permissionSystemAbilityVO.getAbilityId(), functionVO.getId())) { + newVoList.add(subjectVO); + break; + } + } // } - } else { - log.error("权限主体对应的功能是空 主体id:[{}],subjectId:[{}],subjectType:[{}]", subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getSubjectType()); - } - } - return newVoList; + } else { + log.error("权限主体对应的功能是空 主体id:[{}],subjectId:[{}],subjectType:[{}]", + subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getSubjectType()); + } + } + return newVoList; + } + + /** + * 检测用户对应的权限是否满足 + * + * @param functionVO + * @param loginInfo + */ + private Map 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), + "未找到主账号相关权限"); + newLoginUser = new LoginUserInfoVO(); + user.setCompanyId(loginInfo.getAccountVO().getCompanyId()); + newLoginUser.setAccountVO(user); + newLoginUser.setProjectInfo(loginInfo.getProjectInfo()); } - /** - * 检测用户对应的权限是否满足 - * - * @param functionVO - * @param loginInfo - */ - private Map 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), "未找到主账号相关权限"); - newLoginUser = new LoginUserInfoVO(); - user.setCompanyId(loginInfo.getAccountVO().getCompanyId()); - newLoginUser.setAccountVO(user); - newLoginUser.setProjectInfo(loginInfo.getProjectInfo()); - } + List subjectVOList = this.subjectService.findPermissionWithMapIdAndUserInfo( + functionVO.getMapId(), newLoginUser); - List subjectVOList = this.subjectService.findPermissionWithMapIdAndUserInfo(functionVO.getMapId(), newLoginUser); - - List newVOLIst = this.filterUserPermission(subjectVOList, functionVO, newLoginUser); - if (CollectionUtils.isEmpty(newVOLIst)) { - log.error("未找到对应的权限数据mapId[{}],functionId[{}],userId[{}]", functionVO.getMapId(), functionVO.getId(), newLoginUser.getAccountVO().getId()); - BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(true, "未找到该权限"); - } - Map resultMap2 = Maps.newHashMap(); - Map> subjectMapList = newVOLIst.stream().collect(Collectors.groupingBy(PermissionSubjectVO::getSubjectType)); - for (PermissionSubjectTypeEnum st : PermissionSubjectTypeEnum.SORT_ENUM) { - List tmpSubjectVOList = subjectMapList.get(st.name()); - if (CollectionUtils.isEmpty(tmpSubjectVOList)) { - continue; - } - List 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 findSimList = this.simulationManager.finder(key); - resultMap2.put(key, false); - if (findSimList.size() + 1 <= subjectVO.getAmount()) { - resultMap2.put(key, true); - break; - } - } - if (resultMap2.values().stream().anyMatch(d -> Objects.equals(true, d))) { - break; - } - } - BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(resultMap2.values().stream().allMatch(d -> Objects.equals(false, d)), "仿真生成数量过载"); - return resultMap2; + List newVOLIst = this.filterUserPermission(subjectVOList, functionVO, + newLoginUser); + if (CollectionUtils.isEmpty(newVOLIst)) { + log.error("未找到对应的权限数据mapId[{}],functionId[{}],userId[{}]", functionVO.getMapId(), + functionVO.getId(), newLoginUser.getAccountVO().getId()); + BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(true, "未找到该权限"); } - - private List findCanUsedPermission(List newVOLIst, MapFunctionVO functionVO, LoginUserInfoVO loginInfo) { - List canUseSubjectList = newVOLIst.stream().filter(d -> Objects.equals(true, d.getForever())).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(canUseSubjectList)) { - List 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()); - return Collections.emptyList(); - } - canUseSubjectList = newVOLIst.stream().filter(d -> timeOverIdList.contains(d.getId())).collect(Collectors.toList()); + Map resultMap2 = Maps.newHashMap(); + Map> subjectMapList = newVOLIst.stream() + .collect(Collectors.groupingBy(PermissionSubjectVO::getSubjectType)); + for (PermissionSubjectTypeEnum st : PermissionSubjectTypeEnum.SORT_ENUM) { + List tmpSubjectVOList = subjectMapList.get(st.name()); + if (CollectionUtils.isEmpty(tmpSubjectVOList)) { + continue; + } + List 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 findSimList = this.simulationManager.finder(key); + resultMap2.put(key, false); + if (findSimList.size() + 1 <= subjectVO.getAmount()) { + resultMap2.put(key, true); + break; } - return canUseSubjectList; + } + if (resultMap2.values().stream().anyMatch(d -> Objects.equals(true, d))) { + break; + } } + BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue( + resultMap2.values().stream().allMatch(d -> Objects.equals(false, d)), "仿真生成数量过载"); + return resultMap2; + } - @Override - public void addItems(@NonNull String simulationId, Map itemMap) { - if (!CollectionUtils.isEmpty(itemMap)) { - Simulation simulation = simulationManager.getById(simulationId, Simulation.class); - Simulation.Type simulationType = simulation.getType(); - SimulationWorkService initService = simulationWorkServiceManager.getWorkService(simulationType); + private List findCanUsedPermission(List newVOLIst, + MapFunctionVO functionVO, LoginUserInfoVO loginInfo) { + List canUseSubjectList = newVOLIst.stream() + .filter(d -> Objects.equals(true, d.getForever())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(canUseSubjectList)) { + List 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()); + return Collections.emptyList(); + } + canUseSubjectList = newVOLIst.stream().filter(d -> timeOverIdList.contains(d.getId())) + .collect(Collectors.toList()); + } + return canUseSubjectList; + } + + @Override + public void addItems(@NonNull String simulationId, + Map itemMap) { + if (!CollectionUtils.isEmpty(itemMap)) { + Simulation simulation = simulationManager.getById(simulationId, Simulation.class); + Simulation.Type simulationType = simulation.getType(); + 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 workParamMessage = SocketMessageFactory - .buildSimulationWorkParamMessage(simulationId, simulation.getBuildParams().getWorkParamVO()); - Set users = simulation.getSimulationUserIds(); - stompMessageService.sendToUser(users, workParamMessage); - } + initService.addItems(simulation, itemMap); + SocketMessageVO workParamMessage = SocketMessageFactory + .buildSimulationWorkParamMessage(simulationId, + simulation.getBuildParams().getWorkParamVO()); + Set users = simulation.getSimulationUserIds(); + stompMessageService.sendToUser(users, workParamMessage); } + } - @Override - public void removeItems(@NonNull String simulationId, List items, LoginUserInfoVO loginInfo) { - if (!CollectionUtils.isEmpty(items)) { - Simulation simulation = simulationManager.getById(simulationId, Simulation.class); - Simulation.Type simulationType = simulation.getType(); - SimulationWorkService initService = simulationWorkServiceManager.getWorkService(simulationType); + @Override + public void removeItems(@NonNull String simulationId, List items, + LoginUserInfoVO loginInfo) { + if (!CollectionUtils.isEmpty(items)) { + Simulation simulation = simulationManager.getById(simulationId, Simulation.class); + Simulation.Type simulationType = simulation.getType(); + SimulationWorkService initService = simulationWorkServiceManager.getWorkService( + simulationType); // if (StringUtils.hasText(simulation.getCreatorId())) { // BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertEquals(loginInfo.getAccountVO().getIdStr(), simulation.getCreatorId(), // "非仿真创建者不能使用该功能"); // } - initService.removeFunctions(simulation, items); - } + initService.removeFunctions(simulation, items); + } + } + + @Override + public void runAsPlan(String simulationId, RunAsPlanParam param) { + Simulation simulation = simulationManager.getById(simulationId, Simulation.class); + 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()); + initService.reset(simulation); + } + + /** + * 根据地图、功能ID获取仿真ID + * + * @param mapId 地图ID + * @param mapFunctionId 功能ID + * @return 仿真ID + */ + @Override + public String querySimulationByMapIdAndMapFunction(long mapId, long mapFunctionId) { + return querySimulation(mapId, mapFunctionId).getId(); + } + + /** + * 根据地图、功能ID获取仿真信息获取实体 + */ + public Simulation querySimulation(long mapId, long mapFunctionId) { + Simulation targetSimulation = simulationManager.getSimulationList().stream().filter(s -> { + Simulation simulation = (Simulation) s; + return simulation.getMapFunctionId() != null && simulation.getMapFunctionId() == mapFunctionId + && simulation.getBuildParams().getMap().getId() == mapId; + }).findFirst().map(s -> (Simulation) s).orElse(null); + if (targetSimulation != null) { + return targetSimulation; + } + throw new SimulationException(SimulationExceptionType.Simulation_Not_Exist); + } + + @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); + simulationWorkServiceManager.addSimulationUser(simulation, simulationUser); + } + + private Simulation createSimulation(long mapId, MapFunctionVO mapFunctionVO, + @NonNull SimulationWorkParamVO workParamVO, + @NonNull LoginUserInfoVO loginUserInfoVO, Map createUserType) { + //获取仿真工作服务 + SimulationWorkService initService = simulationWorkServiceManager.getWorkService( + workParamVO.getType()); + + //创建仿真 + String simulationId = SimulationIdGenerator.generateGroup( + loginUserInfoVO.getAccountVO().getId(), mapId); + Simulation simulation = initService.create(mapId, workParamVO, loginUserInfoVO, simulationId); + + //语音配置数据 + List ruleList = this.discriminateRule.findRuleByMapId(mapId); + simulation.setVoiceRuleList(ruleList); + + simulation.setMapFunctionVO(mapFunctionVO); + simulation.setCreateUserType(createUserType); + LoginUserInfoVO loginUserInfo = simulation.getBuildParams().getLoginUserInfo(); + if (Objects.nonNull(loginUserInfo)) { + simulation.setCreatorId(loginUserInfo.getAccountVO().getIdStr()); + simulation.setProject(loginUserInfo.getProject()); + simulation.setProjectVO(loginUserInfo.getProjectInfo()); + } + // 删除旧仿真,保存新仿真 + simulation.setMessageSender(this.defaultMessageSender); // 设置默认的消息发布器 + simulation.loadModule(); // 加载通用模块 + groupSimulationService.clearSimulation(simulation.getId()); + simulationManager.saveNew(simulation); + initService.loadData(simulation); + initService.addJobs(simulation); + initService.addMessagePublisher(simulation); + initService.init(simulation); + if (!CollectionUtils.isEmpty(workParamVO.getItemMap())) { + initService.addItems(simulation, workParamVO.getItemMap()); + } + applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation)); + // 群组配置信息 + simulation.initDefaultConversationGroupMap(); + // 仿真开始运行 + simulationManager.start(simulation.getId()); + return simulation; + } + + @Override + public Simulation createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo, + boolean checkAuth) { + MapFunctionVO mapFunctionVO = rtsMapFunctionService.get(mapFunctionId); + Long mapId = mapFunctionVO.getMapId(); + Map createUserType = Maps.newHashMap(); + if (checkAuth) { + createUserType = this.checkUserPermission(mapFunctionVO, loginInfo); + } + SimulationWorkParamVO workParamVO = mapFunctionVO.getParamVO(); + + if (workParamVO.containsRealDeviceItem()) { + //有实体设备加载项的地图功能(实训室)同时只能存在一个 + Stream stream = simulationManager.getSimulationStream(Simulation.class); + Optional oldSimulationOptional = stream + .filter(sim -> Objects.equals(sim.getMapFunctionId(), mapFunctionId)) + .findFirst(); + oldSimulationOptional.ifPresent(simulation -> simulationManager.destroy(simulation.getId())); } - @Override - public void runAsPlan(String simulationId, RunAsPlanParam param) { - Simulation simulation = simulationManager.getById(simulationId, Simulation.class); - SimulationWorkService initService = simulationWorkServiceManager.getWorkService(simulation.getType()); - initService.runAsPlan(simulation, param); + return createSimulation(mapId, mapFunctionVO, mapFunctionVO.getParamVO(), loginInfo, + createUserType); + } + + @Override + public void loadDraftRunPlan(String simulationId, long draftRunPlanId) { + Simulation simulation = simulationManager.getById(simulationId, Simulation.class); + if (simulation.isPlanRunning()) { + throw new SimulationException(SimulationExceptionType.Operation_Cannot_handed, + String.format("计划运行中,无法重新加载运行计划")); } + RunPlanVO runPlanVO = runPlanDraftService.getById(draftRunPlanId); + // 重新加载运行计划匹配的派班计划 + this.simulationLifeCycleService.reloadRunPlan(simulation, runPlanVO, null); + simulation.getRepository().clearChangeTrips(); //清除掉之前的车次计划变化信息 + } - @Override - public void reset(String simulationId) { - Simulation simulation = simulationManager.getById(simulationId, Simulation.class); - SimulationWorkService initService = simulationWorkServiceManager.getWorkService(simulation.getType()); - initService.reset(simulation); + @Override + public SimulationVO querySimulationJoinedByUser(long userId) { + Optional optional = simulationManager.getSimulationStream( + null) + .filter(simulation -> simulation.querySimulationUserById(String.valueOf(userId)) != null) + .findFirst(); + return optional.map( + simulation -> groupSimulationService.getSimulationBasicInfo(simulation.getId())) + .orElse(null); + } + + @Override + public List listSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO) { + Stream stream = this.simulationManager.getSimulationStream(Simulation.class); + 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())); } - - /** - * 根据地图、功能ID获取仿真ID - * - * @param mapId 地图ID - * @param mapFunctionId 功能ID - * @return 仿真ID - */ - @Override - public String querySimulationByMapIdAndMapFunction(long mapId, long mapFunctionId) { - return querySimulation(mapId, mapFunctionId).getId(); + 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()); + } - /** - * 根据地图、功能ID获取仿真信息获取实体 - */ - public Simulation querySimulation(long mapId, long mapFunctionId) { - Simulation targetSimulation = simulationManager.getSimulationList().stream().filter(s -> { - Simulation simulation = (Simulation) s; - return simulation.getMapFunctionId() != null && simulation.getMapFunctionId() == mapFunctionId - && simulation.getBuildParams().getMap().getId() == mapId; - }).findFirst().map(s -> (Simulation) s).orElse(null); - if (targetSimulation != null) { - return targetSimulation; - } - throw new SimulationException(SimulationExceptionType.Simulation_Not_Exist); + @Override + public PageVO pagedSimulationByOrg(Long topOrgId, + SimulationInfoQueryVO queryVO) { + List list = listSimulationByOrg(topOrgId, queryVO); + Stream stream = list.stream(); + int skipNum = (queryVO.getPageNum() - 1) * queryVO.getPageSize(); + List collect = stream.skip(skipNum).limit(queryVO.getPageSize()) + .collect(Collectors.toList()); + return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), list.size(), collect); + } + + @Override + public void sendUnreceivedMessages(String simulationId, String memberId) { + Simulation simulation = simulationManager.getById(simulationId, Simulation.class); + SimulationMember member = simulation.getSimulationMemberById(memberId); + while (true) { + SocketMessageVO message = member.getUnreceivedMessages().poll(); + if (message == null) { + break; + } + stompMessageService.sendToUser(member.getUserId(), message); } + } - @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); - simulationWorkServiceManager.addSimulationUser(simulation, simulationUser); + @Override + public List listAllSimulation(SimulationInfoQueryVO queryVO) { + List simulationList = this.simulationManager.getSimulationList(); + Stream stream = simulationList.stream(); + if (StringUtils.hasText(queryVO.getGroup())) { + stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup())); } - - private Simulation createSimulation(long mapId, MapFunctionVO mapFunctionVO, @NonNull SimulationWorkParamVO workParamVO, - @NonNull LoginUserInfoVO loginUserInfoVO, Map createUserType) { - //获取仿真工作服务 - SimulationWorkService initService = simulationWorkServiceManager.getWorkService(workParamVO.getType()); - - //创建仿真 - String simulationId = SimulationIdGenerator.generateGroup(loginUserInfoVO.getAccountVO().getId(), mapId); - Simulation simulation = initService.create(mapId, workParamVO, loginUserInfoVO, simulationId); - - //语音配置数据 - List ruleList = this.discriminateRule.findRuleByMapId(mapId); - simulation.setVoiceRuleList(ruleList); - - simulation.setMapFunctionVO(mapFunctionVO); - simulation.setCreateUserType(createUserType); - LoginUserInfoVO loginUserInfo = simulation.getBuildParams().getLoginUserInfo(); - if (Objects.nonNull(loginUserInfo)) { - simulation.setCreatorId(loginUserInfo.getAccountVO().getIdStr()); - simulation.setProject(loginUserInfo.getProject()); - simulation.setProjectVO(loginUserInfo.getProjectInfo()); - } - // 删除旧仿真,保存新仿真 - simulation.setMessageSender(this.defaultMessageSender); // 设置默认的消息发布器 - simulation.loadModule(); // 加载通用模块 - groupSimulationService.clearSimulation(simulation.getId()); - simulationManager.saveNew(simulation); - initService.loadData(simulation); - initService.addJobs(simulation); - initService.addMessagePublisher(simulation); - initService.init(simulation); - if (!CollectionUtils.isEmpty(workParamVO.getItemMap())) { - initService.addItems(simulation, workParamVO.getItemMap()); - } - applicationContext.publishEvent(new SimulationCreateSuccessEvent(this, simulation)); - // 群组配置信息 - simulation.initDefaultConversationGroupMap(); - // 仿真开始运行 - simulationManager.start(simulation.getId()); - return simulation; + if (StringUtils.hasText(queryVO.getUserName())) { + stream = stream.filter(simulation -> simulation.getSimulationUsers().stream() + .anyMatch(user -> user.getName().contains(queryVO.getUserName()))); } - - @Override - public Simulation createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth) { - MapFunctionVO mapFunctionVO = rtsMapFunctionService.get(mapFunctionId); - Long mapId = mapFunctionVO.getMapId(); - Map createUserType = Maps.newHashMap(); - if (checkAuth) { - createUserType = this.checkUserPermission(mapFunctionVO, loginInfo); - } - SimulationWorkParamVO workParamVO = mapFunctionVO.getParamVO(); - - if (workParamVO.containsRealDeviceItem()) { - //有实体设备加载项的地图功能(实训室)同时只能存在一个 - Stream stream = simulationManager.getSimulationStream(Simulation.class); - Optional oldSimulationOptional = stream - .filter(sim -> Objects.equals(sim.getMapFunctionId(), mapFunctionId)) - .findFirst(); - oldSimulationOptional.ifPresent(simulation -> simulationManager.destroy(simulation.getId())); - } - - return createSimulation(mapId, mapFunctionVO, mapFunctionVO.getParamVO(), loginInfo, createUserType); - } - - @Override - public void loadDraftRunPlan(String simulationId, long draftRunPlanId) { - Simulation simulation = simulationManager.getById(simulationId, Simulation.class); - if (simulation.isPlanRunning()) { - throw new SimulationException(SimulationExceptionType.Operation_Cannot_handed, - String.format("计划运行中,无法重新加载运行计划")); - } - RunPlanVO runPlanVO = runPlanDraftService.getById(draftRunPlanId); - // 重新加载运行计划匹配的派班计划 - this.simulationLifeCycleService.reloadRunPlan(simulation, runPlanVO, null); - simulation.getRepository().clearChangeTrips(); //清除掉之前的车次计划变化信息 - } - - @Override - public SimulationVO querySimulationJoinedByUser(long userId) { - Optional optional = simulationManager.getSimulationStream(null) - .filter(simulation -> simulation.querySimulationUserById(String.valueOf(userId)) != null) - .findFirst(); - return optional.map(simulation -> groupSimulationService.getSimulationBasicInfo(simulation.getId())).orElse(null); - } - - @Override - public List listSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO) { - Stream stream = this.simulationManager.getSimulationStream(Simulation.class); - 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()))); - } - return stream.map(Simulation::convertToVO).collect(Collectors.toList()); - } - - @Override - public PageVO pagedSimulationByOrg(Long topOrgId, SimulationInfoQueryVO queryVO) { - List list = listSimulationByOrg(topOrgId, queryVO); - Stream stream = list.stream(); - int skipNum = (queryVO.getPageNum() - 1) * queryVO.getPageSize(); - List collect = stream.skip(skipNum).limit(queryVO.getPageSize()).collect(Collectors.toList()); - return new PageVO<>(queryVO.getPageNum(), queryVO.getPageSize(), list.size(), collect); - } - - @Override - public void sendUnreceivedMessages(String simulationId, String memberId) { - Simulation simulation = simulationManager.getById(simulationId, Simulation.class); - SimulationMember member = simulation.getSimulationMemberById(memberId); - while (true) { - SocketMessageVO message = member.getUnreceivedMessages().poll(); - if (message == null) { - break; - } - stompMessageService.sendToUser(member.getUserId(), message); - } + if (queryVO.getFunctionId() != null) { + stream = stream.filter( + simulation -> Objects.equals(queryVO.getFunctionId(), simulation.getMapFunctionId())); } + return stream.map(Simulation::convertToVO).collect(Collectors.toList()); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/PsdSwitch.java b/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/PsdSwitch.java deleted file mode 100644 index d3f6ec7f4..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/PsdSwitch.java +++ /dev/null @@ -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; -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/SignalLight.java b/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/SignalLight.java deleted file mode 100644 index 4af3767b0..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/SignalLight.java +++ /dev/null @@ -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(); -// } -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/SwitchTurn.java b/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/SwitchTurn.java deleted file mode 100644 index ab17efe37..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/communication/vo/SwitchTurn.java +++ /dev/null @@ -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; -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/TrainStopMessage.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/TrainStopMessage.java deleted file mode 100644 index 0c329264c..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/TrainStopMessage.java +++ /dev/null @@ -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(); -// } -// -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/cgy/CgySectionServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/cgy/CgySectionServiceImpl.java deleted file mode 100644 index 91fe825e9..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/cgy/CgySectionServiceImpl.java +++ /dev/null @@ -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); -// } -//} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/JumpAndParkTimeStrategyServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/JumpAndParkTimeStrategyServiceImpl.java deleted file mode 100644 index 269d357ae..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/passenger/strategy/service/JumpAndParkTimeStrategyServiceImpl.java +++ /dev/null @@ -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 { -// -// @Override -// public List generateStrategy(StrategyCalculateData data) { -// List list = new ArrayList<>(); -// List lpfList = data.queryLpfList(); -// if (CollectionUtils.isEmpty(lpfList)) { -// return null; -// } -// // 暂时按一个站大客流处理 -// StandPassenger standPassenger = lpfList.get(0); -// Stand stand = standPassenger.getStand(); -// Map> planMap = data.getPlanMap(); -// int planParkTime = 0; // 计划停站时间 -// for (List planList : planMap.values()) { -// for (TripPlan tripPlan : planList) { -// List 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 leftStandList = data.getLeftStandList(); -// List 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 jumpableStandList; -// if (right) { -// jumpableStandList = rightStandList.subList(0, index); -// } else { -// jumpableStandList = leftStandList.subList(0, index); -// } -// List 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 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 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 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 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 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 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 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 "跳停策略服务"; -// } -// -//} diff --git a/src/main/java/club/joylink/rtss/vo/client/cgy/CgyThirdPartyLoginInfoVO.java b/src/main/java/club/joylink/rtss/vo/client/cgy/CgyThirdPartyLoginInfoVO.java new file mode 100644 index 000000000..2226f4221 --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/client/cgy/CgyThirdPartyLoginInfoVO.java @@ -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; +} diff --git a/src/main/java/club/joylink/rtss/vo/client/simulationUsage/SimulationUsageRecordQueryVO.java b/src/main/java/club/joylink/rtss/vo/client/simulationUsage/SimulationUsageRecordQueryVO.java new file mode 100644 index 000000000..eec88b017 --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/client/simulationUsage/SimulationUsageRecordQueryVO.java @@ -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; +} diff --git a/src/main/java/club/joylink/rtss/vo/client/simulationv1/SimulationInfoQueryVO.java b/src/main/java/club/joylink/rtss/vo/client/simulationv1/SimulationInfoQueryVO.java index 5298d6b5b..59ac61265 100644 --- a/src/main/java/club/joylink/rtss/vo/client/simulationv1/SimulationInfoQueryVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/simulationv1/SimulationInfoQueryVO.java @@ -9,9 +9,12 @@ import lombok.Setter; @Setter @NoArgsConstructor public class SimulationInfoQueryVO extends PageQueryVO { - private String project; - private String group; + private String project; - private String userName; + private String group; + + private String userName; + + private Long functionId; } diff --git a/src/main/java/club/joylink/rtss/vo/permission/PermissionRefParamVO.java b/src/main/java/club/joylink/rtss/vo/permission/PermissionRefParamVO.java deleted file mode 100644 index 7e00e5d7b..000000000 --- a/src/main/java/club/joylink/rtss/vo/permission/PermissionRefParamVO.java +++ /dev/null @@ -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 convert(List vo){ - List list = Lists.newArrayList(); - for (PermissionSubjectVO subjectVO : vo) { - list.add(new PermissionRefParamVO(subjectVO.getDistributeId(),subjectVO.getPermissionId())); - } - return list; - } -} -*/ diff --git a/src/main/resources/mybatis/mapper/CgyViewDAO.xml b/src/main/resources/mybatis/mapper/CgyViewDAO.xml new file mode 100644 index 000000000..e8b8867e3 --- /dev/null +++ b/src/main/resources/mybatis/mapper/CgyViewDAO.xml @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + app_id, app_secret, function_id, view_count + + + + + delete from cgy_view + where app_id = #{appId,jdbcType=VARCHAR} + + + delete from cgy_view + + + + + + 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 into cgy_view + + + app_id, + + + app_secret, + + + function_id, + + + view_count, + + + + + #{appId,jdbcType=VARCHAR}, + + + #{appSecret,jdbcType=VARCHAR}, + + + #{functionId,jdbcType=BIGINT}, + + + #{viewCount,jdbcType=BIGINT}, + + + + + + update cgy_view + + + app_id = #{record.appId,jdbcType=VARCHAR}, + + + app_secret = #{record.appSecret,jdbcType=VARCHAR}, + + + function_id = #{record.functionId,jdbcType=BIGINT}, + + + view_count = #{record.viewCount,jdbcType=BIGINT}, + + + + + + + + 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} + + + + + + update cgy_view + + + app_secret = #{appSecret,jdbcType=VARCHAR}, + + + function_id = #{functionId,jdbcType=BIGINT}, + + + view_count = #{viewCount,jdbcType=BIGINT}, + + + where app_id = #{appId,jdbcType=VARCHAR} + + + 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} + + \ No newline at end of file