refactor(系统设置): 个人中心本地执行去掉校验接口

This commit is contained in:
AgAngle 2024-02-27 16:23:29 +08:00 committed by 刘瑞斌
parent 95586e1efa
commit ee9928ebca
3 changed files with 2 additions and 51 deletions

View File

@ -31,12 +31,6 @@ public class UserLocalConfigController {
return userLocalConfigService.add(request, SessionUtils.getUserId()); return userLocalConfigService.add(request, SessionUtils.getUserId());
} }
@GetMapping("/validate/{id}")
@Operation(summary = "系统设置-个人中心-我的设置-本地执行-验证是否通过")
public boolean validate(@PathVariable String id) {
return userLocalConfigService.validate(id);
}
@GetMapping("/get") @GetMapping("/get")
@Operation(summary = "系统设置-个人中心-我的设置-本地执行-获取本地执行") @Operation(summary = "系统设置-个人中心-我的设置-本地执行-获取本地执行")
public List<UserLocalConfig> get() { public List<UserLocalConfig> get() {

View File

@ -21,8 +21,6 @@ import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.List; import java.util.List;
@Service @Service
@ -73,24 +71,6 @@ public class UserLocalConfigService {
} }
public boolean validate(String id) {
UserLocalConfig userLocalConfig = checkResourceById(id);
HttpURLConnection connection = null;
try {
URI url = new URI(userLocalConfig.getUserUrl());
connection = (HttpURLConnection) url.toURL().openConnection();
connection.setConnectTimeout(3000);
return connection.getResponseCode() == HttpURLConnection.HTTP_OK;
} catch (Exception e) {
return false;
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
public List<UserLocalConfig> get(String userId) { public List<UserLocalConfig> get(String userId) {
UserLocalConfigExample userLocalConfigExample = new UserLocalConfigExample(); UserLocalConfigExample userLocalConfigExample = new UserLocalConfigExample();
userLocalConfigExample.createCriteria().andCreateUserEqualTo(userId); userLocalConfigExample.createCriteria().andCreateUserEqualTo(userId);
@ -99,12 +79,8 @@ public class UserLocalConfigService {
public void enable(String id) { public void enable(String id) {
UserLocalConfig userLocalConfig = checkResourceById(id); UserLocalConfig userLocalConfig = checkResourceById(id);
if (validate(id)) { userLocalConfig.setEnable(true);
userLocalConfig.setEnable(true); userLocalConfigMapper.updateByPrimaryKeySelective(userLocalConfig);
userLocalConfigMapper.updateByPrimaryKeySelective(userLocalConfig);
} else {
throw new MSException(Translator.get("current_user_local_config_not_validate"));
}
} }
public void disable(String id) { public void disable(String id) {

View File

@ -79,21 +79,6 @@ public class UserLocalConfigControllerTests extends BaseTest {
} }
@Test
@Order(2)
public void testValidate() throws Exception {
UserLocalConfigExample userLocalConfigExample = new UserLocalConfigExample();
userLocalConfigExample.createCriteria().andCreateUserEqualTo("admin").andTypeEqualTo("API");
UserLocalConfig userLocalConfig = userLocalConfigMapper.selectByExample(userLocalConfigExample).get(0);
requestGet(String.format(VALIDATE, userLocalConfig.getId()));
userLocalConfigExample.clear();
userLocalConfigExample.createCriteria().andCreateUserEqualTo("admin").andTypeEqualTo("UI");
userLocalConfig = userLocalConfigMapper.selectByExample(userLocalConfigExample).get(0);
requestGet(String.format(VALIDATE, userLocalConfig.getId()));
//不存在的
requestGet(String.format(VALIDATE, UUID.randomUUID().toString()), status().is5xxServerError());
}
@Test @Test
@Order(3) @Order(3)
public void testUpdate() throws Exception { public void testUpdate() throws Exception {
@ -134,10 +119,6 @@ public class UserLocalConfigControllerTests extends BaseTest {
checkLog(userLocalConfig.getId(), OperationLogType.UPDATE); checkLog(userLocalConfig.getId(), OperationLogType.UPDATE);
//不存在的 //不存在的
requestGet(String.format(ENABLE, UUID.randomUUID().toString()), status().is5xxServerError()); requestGet(String.format(ENABLE, UUID.randomUUID().toString()), status().is5xxServerError());
userLocalConfigExample.clear();
userLocalConfigExample.createCriteria().andCreateUserEqualTo("admin").andTypeEqualTo("UI");
userLocalConfig = userLocalConfigMapper.selectByExample(userLocalConfigExample).get(0);
requestGet(String.format(ENABLE, userLocalConfig.getId())).andExpect(status().is5xxServerError());
} }
@Test @Test