refactor(系统设置): 新增站点信息初始化接口

This commit is contained in:
WangXu10 2023-07-28 15:58:14 +08:00 committed by 刘瑞斌
parent 8a10eeb3f5
commit 407039162c
16 changed files with 62 additions and 21 deletions

View File

@ -50,7 +50,7 @@ public interface ParamConstants {
FROM("smtp.from"),
PASSWORD("smtp.password"),
SSL("smtp.ssl"),
TLS("smtp.tls"),
TSL("smtp.tsl"),
RECIPIENTS("smtp.recipient");
private String value;

View File

@ -0,0 +1,8 @@
package io.metersphere.sdk.mapper;
import org.apache.ibatis.annotations.Param;
public interface BaseSystemParameterMapper {
void saveBaseUrl(@Param("baseUrl") String baseUrl);
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.sdk.mapper.BaseSystemParameterMapper">
<update id="saveBaseUrl">
UPDATE system_parameter SET param_value = #{baseUrl}
WHERE param_key = 'base.url' AND (param_value LIKE 'http://127%' OR param_value = '' OR param_value IS NULL)
</update>
</mapper>

View File

@ -29,8 +29,8 @@ public class MailNoticeSender extends AbstractNoticeSender {
javaMailSender.setProtocol("smtps");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
}
if (BooleanUtils.toBoolean(paramMap.get(ParamConstants.MAIL.TLS.getValue()))) {
String result = BooleanUtils.toString(BooleanUtils.toBoolean(paramMap.get(ParamConstants.MAIL.TLS.getValue())), "true", "false");
if (BooleanUtils.toBoolean(paramMap.get(ParamConstants.MAIL.TSL.getValue()))) {
String result = BooleanUtils.toString(BooleanUtils.toBoolean(paramMap.get(ParamConstants.MAIL.TSL.getValue())), "true", "false");
props.put("mail.smtp.starttls.enable", result);
props.put("mail.smtp.starttls.required", result);
}

View File

@ -8,6 +8,7 @@ import io.metersphere.sdk.dto.LogDTO;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.log.constants.OperationLogModule;
import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.mapper.BaseSystemParameterMapper;
import io.metersphere.sdk.notice.sender.impl.MailNoticeSender;
import io.metersphere.sdk.util.EncryptUtils;
import io.metersphere.sdk.util.JSON;
@ -40,6 +41,9 @@ public class SystemParameterService {
@Resource
MailNoticeSender mailNoticeSender;
@Resource
BaseSystemParameterMapper baseSystemParameterMapper;
public void saveBaseInfo(List<SystemParameter> parameters) {
SystemParameterExample example = new SystemParameterExample();
parameters.forEach(param -> {
@ -122,7 +126,7 @@ public class SystemParameterService {
mailInfo.setPassword(password);
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.SSL.getValue())) {
mailInfo.setSsl(param.getParamValue());
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.TLS.getValue())) {
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.TSL.getValue())) {
mailInfo.setTsl(param.getParamValue());
} else if (StringUtils.equals(param.getParamKey(), ParamConstants.MAIL.RECIPIENTS.getValue())) {
mailInfo.setRecipient(param.getParamValue());
@ -261,4 +265,8 @@ public class SystemParameterService {
});
return originalValue;
}
public void saveBaseUrl(String baseUrl) {
baseSystemParameterMapper.saveBaseUrl(baseUrl);
}
}

View File

@ -10,7 +10,7 @@ import io.metersphere.sdk.log.vo.OperationLogRequest;
import io.metersphere.sdk.log.vo.OperationLogResponse;
import io.metersphere.sdk.util.PageUtils;
import io.metersphere.sdk.util.Pager;
import io.metersphere.system.dto.OrganizationProjectOptionsDto;
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
import io.metersphere.system.dto.response.OrganizationProjectOptionsResponse;
import io.metersphere.system.service.OrganizationService;
import io.metersphere.system.service.SystemProjectService;
@ -46,9 +46,9 @@ public class OperationLogController {
public OrganizationProjectOptionsResponse getOptions() {
//获取全部组织
List<OrganizationProjectOptionsDto> organizationList = organizationService.getOrganizationOptions();
List<OrganizationProjectOptionsDTO> organizationList = organizationService.getOrganizationOptions();
//获取全部项目
List<OrganizationProjectOptionsDto> projectList = systemProjectService.getProjectOptions();
List<OrganizationProjectOptionsDTO> projectList = systemProjectService.getProjectOptions();
OrganizationProjectOptionsResponse optionsResponse = new OrganizationProjectOptionsResponse();
optionsResponse.setOrganizationList(organizationList);

View File

@ -68,4 +68,10 @@ public class SystemParameterController {
systemParameterService.testEmailConnection(hashMap);
}
@GetMapping("/save/base-url")
public void saveBaseurl(@RequestParam("baseUrl") String baseUrl) {
systemParameterService.saveBaseUrl(baseUrl);
}
}

View File

@ -4,7 +4,7 @@ package io.metersphere.system.dto;
import lombok.Data;
@Data
public class OrganizationProjectOptionsDto {
public class OrganizationProjectOptionsDTO {
String id;
String name;
}

View File

@ -1,6 +1,6 @@
package io.metersphere.system.dto.response;
import io.metersphere.system.dto.OrganizationProjectOptionsDto;
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
import lombok.Data;
import java.util.List;
@ -8,6 +8,6 @@ import java.util.List;
@Data
public class OrganizationProjectOptionsResponse {
List<OrganizationProjectOptionsDto> organizationList;
List<OrganizationProjectOptionsDto> projectList;
List<OrganizationProjectOptionsDTO> organizationList;
List<OrganizationProjectOptionsDTO> projectList;
}

View File

@ -3,7 +3,7 @@ package io.metersphere.system.mapper;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.OrgUserExtend;
import io.metersphere.system.dto.OrganizationDTO;
import io.metersphere.system.dto.OrganizationProjectOptionsDto;
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
import io.metersphere.system.dto.UserExtend;
import io.metersphere.system.request.OrganizationDeleteRequest;
import io.metersphere.system.request.OrganizationRequest;
@ -74,5 +74,5 @@ public interface ExtOrganizationMapper {
* 获取组织列表(下拉框)
* @return 组织列表数据
*/
List<OrganizationProjectOptionsDto> selectOrganizationOptions();
List<OrganizationProjectOptionsDTO> selectOrganizationOptions();
}

View File

@ -74,7 +74,7 @@
where urr.role_id = 'org_admin'and urr.source_id = #{orgId}
</select>
<select id="selectOrganizationOptions" resultType="io.metersphere.system.dto.OrganizationProjectOptionsDto">
<select id="selectOrganizationOptions" resultType="io.metersphere.system.dto.OrganizationProjectOptionsDTO">
select id, name from organization order by create_time desc
</select>

View File

@ -2,7 +2,7 @@ package io.metersphere.system.mapper;
import io.metersphere.sdk.dto.ProjectDTO;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.OrganizationProjectOptionsDto;
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
import io.metersphere.system.dto.UserExtend;
import io.metersphere.system.request.ProjectMemberRequest;
import io.metersphere.system.request.ProjectRequest;
@ -18,5 +18,5 @@ public interface ExtSystemProjectMapper {
List<User> getProjectAdminList(String projectId);
List<OrganizationProjectOptionsDto> selectProjectOptions();
List<OrganizationProjectOptionsDTO> selectProjectOptions();
}

View File

@ -53,7 +53,7 @@
</select>
<select id="selectProjectOptions" resultType="io.metersphere.system.dto.OrganizationProjectOptionsDto">
<select id="selectProjectOptions" resultType="io.metersphere.system.dto.OrganizationProjectOptionsDTO">
select id, name from project order by create_time desc
</select>

View File

@ -16,7 +16,7 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.*;
import io.metersphere.system.dto.OrgUserExtend;
import io.metersphere.system.dto.OrganizationDTO;
import io.metersphere.system.dto.OrganizationProjectOptionsDto;
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
import io.metersphere.system.dto.UserExtend;
import io.metersphere.system.mapper.*;
import io.metersphere.system.request.*;
@ -207,7 +207,7 @@ public class OrganizationService {
return organizationDTOS;
}
public List<OrganizationProjectOptionsDto> getOrganizationOptions() {
public List<OrganizationProjectOptionsDTO> getOrganizationOptions() {
return extOrganizationMapper.selectOrganizationOptions();
}

View File

@ -20,7 +20,7 @@ import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.User;
import io.metersphere.system.domain.UserRoleRelation;
import io.metersphere.system.domain.UserRoleRelationExample;
import io.metersphere.system.dto.OrganizationProjectOptionsDto;
import io.metersphere.system.dto.OrganizationProjectOptionsDTO;
import io.metersphere.system.dto.UserExtend;
import io.metersphere.system.mapper.ExtSystemProjectMapper;
import io.metersphere.system.mapper.UserMapper;
@ -302,7 +302,7 @@ public class SystemProjectService {
userRoleRelationMapper.deleteByExample(userGroupExample);
}
public List<OrganizationProjectOptionsDto> getProjectOptions() {
public List<OrganizationProjectOptionsDTO> getProjectOptions() {
return extSystemProjectMapper.selectProjectOptions();
}

View File

@ -41,11 +41,21 @@ public class SystemParameterControllerTests extends BaseTest {
public static final String EMAIL_INFO_TEST_CONNECT_URL = "/system/parameter/test/email";
public static final String SAVE_BASE_URL = "/system/parameter/save/base-url";
public static final String BASE_URL = "http://www.baidu.com";
private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError();
@Test
@Order(1)
public void testSaveBaseUrl() throws Exception {
this.requestGet(SAVE_BASE_URL + "?baseUrl=" + BASE_URL);
}
@Test
@Order(2)
public void testSaveBaseInfo() throws Exception {
List<SystemParameter> systemParameters = new ArrayList<>() {{