修改二维码url分割符;非测试/正式环境不生成二维码url;补充controller注释

This commit is contained in:
thesai 2022-01-05 17:16:01 +08:00
parent d0813d027d
commit 2de4d9b089
9 changed files with 240 additions and 44 deletions

View File

@ -349,7 +349,7 @@ public class OrgController {
* 获取绑定组织二维码
*/
@GetMapping("/{orgId}/qrCode")
public String getBindQrCode(@PathVariable Long orgId, @PathVariable LoginUserInfoVO loginInfo) {
public String getBindQrCode(@PathVariable Long orgId, @RequestAttribute LoginUserInfoVO loginInfo) {
return iOrgService.getBindQrCode(orgId, loginInfo.getProject());
}

View File

@ -12,7 +12,7 @@ import javax.validation.constraints.NotBlank;
import java.util.List;
/**
* 驾驶操作接口
* 三维驾驶操作接口
*/
@RestController
@RequestMapping("/simulation/driving")
@ -25,7 +25,7 @@ public class DrivingOperationController {
private DrivingService drivingService;
/**
* 获取在运行的列车列表
* 获取在正线运行的列车列表
* @param group
* @return
*/

View File

@ -26,6 +26,9 @@ public class SchedulingSimulationController {
@Autowired
private SchedulingService schedulingService;
/**
* 获取当前派班计划
*/
@GetMapping(path = "/{group}/current")
public SchedulingPlanNewVO getCurrentSchedulingPlan(@PathVariable String group) {
return this.schedulingService.queryCurrentSchedulingPlan(group);

View File

@ -50,6 +50,9 @@ public class SimulationManageController {
this.simulationManageService.destroySimulation(group, user);
}
/**
* 压力测试非业务接口
*/
@Role(RoleEnum.SuperAdmin)
@PostMapping("/stressTest/{mapId}")
public int stressTest(@PathVariable Long mapId, @RequestAttribute AccountVO user) {

View File

@ -24,10 +24,13 @@ public class QRCodeManager {
* 登录二维码
*/
public String getLoginCode(String clientId, Project project, String sessionId) {
String envName = this.otherConfig.getEnv();
if (!SystemEnv.isPrdEnv(envName) && !SystemEnv.isTestEnv(envName)) {
return "";
}
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(project, "登录二维码project不可为null");
String envId = SystemEnv.getSystemEnvIdByName(this.otherConfig.getEnv());
String pro = selectProject(this.otherConfig.getEnv(), project);
AuthenticateService.LoginScanParam param = new AuthenticateService.LoginScanParam(envId, sessionId, clientId, pro);
String pro = selectProject(envName, project);
AuthenticateService.LoginScanParam param = new AuthenticateService.LoginScanParam(sessionId, clientId, pro);
String state = param.toParam();
return weChatConfig.getWmLoginUrl(state);
}
@ -36,10 +39,14 @@ public class QRCodeManager {
* 权限分发二维码
*/
public String getDistributeCode(long id, Project project) {
String envName = this.otherConfig.getEnv();
if (!SystemEnv.isPrdEnv(envName) && !SystemEnv.isTestEnv(envName)) {
return "";
}
if (project == null) {
project = Project.DEFAULT;
}
String pro = selectProject(this.otherConfig.getEnv(), project);
String pro = selectProject(envName, project);
String state = buildState(String.valueOf(id), pro);
return this.weChatConfig.getPermissionDistributeUrl(state);
}
@ -48,8 +55,11 @@ public class QRCodeManager {
* 综合演练二维码
*/
public String getSimulationCode(String group, Project project) {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(project, "综合演练二维码project不可为null");
String envName = this.otherConfig.getEnv();
if (!SystemEnv.isPrdEnv(envName) && !SystemEnv.isTestEnv(envName)) {
return "";
}
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(project, "综合演练二维码project不可为null");
String pro = selectProject(envName, project);
String state = buildState(group, pro);
return this.weChatConfig.getWmSimulationUrl(state);
@ -59,18 +69,24 @@ public class QRCodeManager {
* 微信绑定账号二维码
*/
public String getWeChatBindUrl(long accountId, Project project) {
String envName = this.otherConfig.getEnv();
if (!SystemEnv.isPrdEnv(envName) && !SystemEnv.isTestEnv(envName)) {
return "";
}
if (project == null)
project = Project.DEFAULT;
String envName = this.otherConfig.getEnv();
String pro = selectProject(envName, project);
String state = buildState(String.valueOf(accountId), pro);
return this.weChatConfig.getWmBindUrl(state);
}
public String getOrgBindCode(long orgId, Project project) {
String envName = this.otherConfig.getEnv();
if (!SystemEnv.isPrdEnv(envName) && !SystemEnv.isTestEnv(envName)) {
return "";
}
if (project == null)
project = Project.DEFAULT;
String envName = this.otherConfig.getEnv();
String pro = selectProject(envName, project);
String state = buildState(String.valueOf(orgId), pro);
return this.weChatConfig.getOrgBindCode(state);
@ -86,16 +102,11 @@ public class QRCodeManager {
} else if (SystemEnv.isTestEnv(envName)) {
return Project.TEST.name();
}
return "";
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("环境异常");
}
private String buildState(String... args) {
String separator = "_";
StringBuilder builder = new StringBuilder();
for (String arg : args) {
builder.append(arg).append(separator);
}
builder.deleteCharAt(builder.length() - 1);
return builder.toString();
String separator = "__";
return String.join(separator, args);
}
}

View File

@ -302,7 +302,7 @@ public class AuthenticateService implements IAuthenticateService {
case DEPOT:
case DRIVE:
case CW:
case SCHEDULING:{
case SCHEDULING: {
// 工作站登录
this.projectJointSimulationService.handleWorkStationLogin(loginUserInfo);
break;
@ -375,7 +375,7 @@ public class AuthenticateService implements IAuthenticateService {
public String thirdPartyLogin(LoginUserVO loginInfo) {
BusinessExceptionAssertEnum.INVALID_OPERATION
.assertTrue(this.iSysUserService.isThirdParentAccountExist(loginInfo.getParentAccount()),
String.format("第三方企业账号不存在: %s", loginInfo.getParentAccount()));
String.format("第三方企业账号不存在: %s", loginInfo.getParentAccount()));
AccountVO accountVO = this.iSysUserService.queryOrCreateThirdAccount(loginInfo.getParentAccount(),
loginInfo.getAccount());
Client client = Client.getByIdAndSecret(loginInfo.getClientId(), loginInfo.getSecret());
@ -452,9 +452,9 @@ public class AuthenticateService implements IAuthenticateService {
}
loginStatusVO.updateQueryTime();
return LoginStatusVO.builder()
.status(loginStatusVO.getStatus())
.token(loginStatusVO.getToken())
.build();
.status(loginStatusVO.getStatus())
.token(loginStatusVO.getToken())
.build();
}
private void checkAndHandleSpecialDeviceLogin(LoginStatusVO loginStatusVO) {
@ -506,14 +506,12 @@ public class AuthenticateService implements IAuthenticateService {
@Getter
@Setter
public static class LoginScanParam {
private static final String Splitter = "_";
private String envId;
private static final String Splitter = "__";
private String sessionId;
private String clientId;
private String project;
public LoginScanParam(String envId, String sessionId, String clientId, String project) {
this.envId = envId;
public LoginScanParam(String sessionId, String clientId, String project) {
this.sessionId = sessionId;
this.clientId = clientId;
this.project = project;
@ -528,15 +526,12 @@ public class AuthenticateService implements IAuthenticateService {
log.info("扫码login参数" + state);
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertHasText(state);
String[] split = state.split(Splitter);
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(split.length, 4);
return new LoginScanParam(split[1], split[2]);
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(split.length, 3);
return new LoginScanParam(split[0], split[1]);
}
public String toParam() {
if (Objects.isNull(this.envId)) {
return this.sessionId + Splitter + this.clientId + Splitter + project;
}
return this.envId + Splitter + this.sessionId + Splitter + this.clientId + Splitter + project;
return this.sessionId + Splitter + this.clientId + Splitter + project;
}
}
}

View File

@ -11,6 +11,7 @@ import club.joylink.rtss.vo.project.ProjectServerQueryVO;
import club.joylink.rtss.vo.project.ProjectServerVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -18,7 +19,6 @@ import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
@Slf4j
@Service
@ -28,7 +28,7 @@ public class ServerServiceImpl implements ServerService {
private ProjectServerDAO projectServerDAO;
@Override
public ProjectServerVO getByProject(Project project) {
public ProjectServerVO getByProject(@NonNull Project project) {
ProjectServerExample example = new ProjectServerExample();
example.createCriteria()
.andProjectEqualTo(project.name());
@ -59,9 +59,9 @@ public class ServerServiceImpl implements ServerService {
@Override
public String create(ProjectServerVO vo, AccountVO accountVO) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(vo.getProject(),"项目不能为null");
BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertNotTrue(this.isProjectDataExist(vo.getProject()),
String.format("项目[%s]的域名数据已经存在", vo.getProject()));
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(vo.getProject(), "项目不能为null");
BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertNotTrue(this.isProjectDataExist(vo.getProject()),
String.format("项目[%s]的域名数据已经存在", vo.getProject()));
ProjectServer db = vo.toDB4Create();
db.setCreateUserId(accountVO.getId());
db.setCreateTime(LocalDateTime.now());
@ -79,12 +79,11 @@ public class ServerServiceImpl implements ServerService {
@Override
public void update(Long id, ProjectServerVO vo, AccountVO accountVO) {
ProjectServer projectServer = this.projectServerDAO.selectByPrimaryKey(id);
if (!Objects.equals(vo.getDomainName(), projectServer.getDomainName())) {
projectServer.setDomainName(vo.getDomainName());
projectServer.setUpdateUserId(accountVO.getId());
projectServer.setUpdateTime(LocalDateTime.now());
this.projectServerDAO.updateByPrimaryKey(projectServer);
}
projectServer.setDomainName(vo.getDomainName());
projectServer.setResourcesDomainName(vo.getResourcesDomainName());
projectServer.setUpdateUserId(accountVO.getId());
projectServer.setUpdateTime(LocalDateTime.now());
this.projectServerDAO.updateByPrimaryKey(projectServer);
}
@Override

View File

@ -0,0 +1,153 @@
package club.joylink.rtss.services;
import club.joylink.rtss.configuration.configProp.OtherConfig;
import club.joylink.rtss.constants.Project;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
class QRCodeManagerTest {
@Autowired
private QRCodeManager qrCodeManager;
@Autowired
private OtherConfig otherConfig;
@Test
void getLoginCode() {
String[] envArr = new String[]{"dev", "test", "prd"};
for (String env : envArr) {
otherConfig.setEnv(env);
for (Project project : Project.values()) {
String result = qrCodeManager.getLoginCode(null, project, null);
switch (env) {
case "dev":
assertEquals("", result);
break;
case "test": {
String[] split = result.split("__");
assertEquals(Project.TEST.name(), split[split.length - 1]);
break;
}
case "prd":
String[] split = result.split("__");
assertEquals(project.name(), split[split.length - 1]);
break;
default:
throw new IllegalStateException("Unexpected value: " + env);
}
}
}
}
@Test
void getDistributeCode() {
String[] envArr = new String[]{"dev", "test", "prd"};
for (String env : envArr) {
otherConfig.setEnv(env);
for (Project project : Project.values()) {
String result = qrCodeManager.getDistributeCode(1, project);
switch (env) {
case "dev":
assertEquals("", result);
break;
case "test": {
String[] split = result.split("\\?");
assertEquals(split[1], "state=1__TEST");
break;
}
case "prd":
String[] split = result.split("\\?");
assertEquals(split[1], "state=1__" + project.name());
break;
default:
throw new IllegalStateException("Unexpected value: " + env);
}
}
}
}
@Test
void getSimulationCode() {
String[] envArr = new String[]{"dev", "test", "prd"};
for (String env : envArr) {
otherConfig.setEnv(env);
for (Project project : Project.values()) {
String result = qrCodeManager.getSimulationCode("42-10086", project);
switch (env) {
case "dev":
assertEquals("", result);
break;
case "test": {
String[] split = result.split("\\?");
assertEquals(split[1], "state=42-10086__TEST");
break;
}
case "prd":
String[] split = result.split("\\?");
assertEquals(split[1], "state=42-10086__" + project.name());
break;
default:
throw new IllegalStateException("Unexpected value: " + env);
}
}
}
}
@Test
void getWeChatBindUrl() {
String[] envArr = new String[]{"dev", "test", "prd"};
for (String env : envArr) {
otherConfig.setEnv(env);
for (Project project : Project.values()) {
String result = qrCodeManager.getWeChatBindUrl(1, project);
switch (env) {
case "dev":
assertEquals("", result);
break;
case "test": {
String[] split = result.split("\\?");
assertEquals(split[1], "state=1__TEST");
break;
}
case "prd":
String[] split = result.split("\\?");
assertEquals(split[1], "state=1__" + project.name());
break;
default:
throw new IllegalStateException("Unexpected value: " + env);
}
}
}
}
@Test
void getOrgBindCode() {
String[] envArr = new String[]{"dev", "test", "prd"};
for (String env : envArr) {
otherConfig.setEnv(env);
for (Project project : Project.values()) {
String result = qrCodeManager.getOrgBindCode(1, project);
switch (env) {
case "dev":
assertEquals("", result);
break;
case "test": {
String[] split = result.split("\\?");
assertEquals(split[1], "state=1__TEST");
break;
}
case "prd":
String[] split = result.split("\\?");
assertEquals(split[1], "state=1__" + project.name());
break;
default:
throw new IllegalStateException("Unexpected value: " + env);
}
}
}
}
}

View File

@ -0,0 +1,32 @@
package club.joylink.rtss.services.project;
import club.joylink.rtss.constants.Project;
import club.joylink.rtss.vo.project.ProjectServerVO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class ServerServiceImplTest {
@Autowired
private ServerService serverService;
@Test
void getByProject() {
for (Project project : Project.values()) {
serverService.getByProject(project);
}
try {
serverService.getByProject(null);
} catch (Exception e) {
assertTrue(e instanceof NullPointerException);
}
ProjectServerVO xtyProjectVO = serverService.getByProject(Project.XTY);
assertEquals(xtyProjectVO.getDomainName(), "test.joylink.club/jlcloud");
assertEquals(xtyProjectVO.getResourcesDomainName(), "joylink.club/oss/joylink");
ProjectServerVO drtsProjectVO = serverService.getByProject(Project.DRTS);
assertNull(drtsProjectVO);
}
}