fix(系统设置): 插件列表创建人显示的是ID

--task=1012390 --user=陈建星 系统设置-系统-插件管理-后台 https://www.tapd.cn/55049933/s/1408086
This commit is contained in:
jianxing 2023-08-24 16:14:45 +08:00 committed by 刘瑞斌
parent 383e3fcf78
commit 5754dd1783
5 changed files with 63 additions and 8 deletions

View File

@ -33,4 +33,5 @@ public interface BaseUserMapper {
List<ExcludeOptionDTO> getExcludeSelectOption();
List<OptionDTO> getSelectOptionByIds(List<String> ids);
}

View File

@ -96,4 +96,13 @@
select id, name
from user
</select>
<select id="getSelectOptionByIds" resultType="io.metersphere.sdk.dto.OptionDTO">
SELECT id, name
FROM user
WHERE id IN
<foreach collection="ids" item="id" index="index"
open="(" close=")" separator=",">
#{id}
</foreach>
</select>
</mapper>

View File

@ -107,8 +107,9 @@ public class BaseUserService {
throw new UnauthorizedException(Translator.get("not_authorized") + e.getMessage());
}
}
//保存日志
public void saveLog(String userId, String method, String path, String content, String type){
public void saveLog(String userId, String method, String path, String content, String type) {
User user = userMapper.selectByPrimaryKey(userId);
LogDTO dto = new LogDTO(
OperationLogConstants.SYSTEM,
@ -428,10 +429,29 @@ public class BaseUserService {
return baseUserMapper.getExcludeSelectOption();
}
public List<OptionDTO> getSelectOptionByIds(List<String> ids) {
return baseUserMapper.getSelectOptionByIds(ids);
}
public Map<String, String> getUserNameMap() {
List<ExcludeOptionDTO> excludeSelectOption = getExcludeSelectOption();
Map<String, String> nameMap = new HashMap<>();
excludeSelectOption.forEach(option -> nameMap.put(option.getId(), option.getName()));
return nameMap;
}
/**
* 根据用户ID列表获取用户
*
* @param userIds
* @return
*/
public Map<String, String> getUserNameMap(List<String> userIds) {
if (CollectionUtils.isEmpty(userIds)) {
return Collections.emptyMap();
}
return getSelectOptionByIds(userIds)
.stream()
.collect(Collectors.toMap(OptionDTO::getId, OptionDTO::getName));
}
}

View File

@ -8,6 +8,7 @@ import io.metersphere.sdk.constants.PluginScenarioType;
import io.metersphere.sdk.controller.handler.result.CommonResultCode;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.service.BaseUserService;
import io.metersphere.sdk.service.JdbcDriverPluginService;
import io.metersphere.sdk.service.PluginLoadService;
import io.metersphere.sdk.util.BeanUtils;
@ -58,18 +59,27 @@ public class PluginService {
JdbcDriverPluginService jdbcDriverPluginService;
@Resource
private KafkaTemplate<String, String> kafkaTemplate;
@Resource
private BaseUserService baseUserService;
public List<PluginDTO> list() {
List<PluginDTO> plugins = extPluginMapper.getPlugins();
List<String> pluginIds = plugins.stream().map(Plugin::getId).toList();
Map<String, List<OptionDTO>> scripteMap = pluginScriptService.getScripteMap(pluginIds);
Map<String, List<OptionDTO>> orgMap = pluginOrganizationService.getOrgMap(pluginIds);
// 获取用户ID和名称的映射
List<String> userIds = plugins.stream().map(PluginDTO::getCreateUser).toList();
Map<String, String> userNameMap = baseUserService.getUserNameMap(userIds);
plugins.forEach(plugin -> {
List<OptionDTO> pluginForms = scripteMap.get(plugin.getId());
List<OptionDTO> organizations = orgMap.get(plugin.getId());
plugin.setPluginForms(pluginForms == null ? new ArrayList<>(0) : pluginForms);
plugin.setOrganizations(organizations == null ? new ArrayList<>(0) : organizations);
plugin.setCreateUser(userNameMap.get(plugin.getCreateUser()));
});
return plugins;
}

View File

@ -5,12 +5,14 @@ import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.PluginScenarioType;
import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.log.constants.OperationLogType;
import io.metersphere.sdk.service.BaseUserService;
import io.metersphere.sdk.service.JdbcDriverPluginService;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.controller.param.PluginUpdateRequestDefinition;
import io.metersphere.system.domain.*;
import io.metersphere.system.dto.OrganizationDTO;
import io.metersphere.system.dto.PluginDTO;
import io.metersphere.system.mapper.ExtPluginMapper;
import io.metersphere.system.mapper.PluginMapper;
import io.metersphere.system.mapper.PluginOrganizationMapper;
import io.metersphere.system.mapper.PluginScriptMapper;
@ -25,10 +27,8 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.util.MultiValueMap;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.FILE_NAME_ILLEGAL;
import static io.metersphere.system.controller.result.SystemResultCode.*;
@ -48,6 +48,10 @@ public class PluginControllerTests extends BaseTest {
@Resource
private PluginMapper pluginMapper;
@Resource
private ExtPluginMapper extPluginMapper;
@Resource
private BaseUserService baseUserService;
@Resource
private PluginOrganizationMapper pluginOrganizationMapper;
@Resource
private PluginScriptMapper pluginScriptMapper;
@ -231,7 +235,7 @@ public class PluginControllerTests extends BaseTest {
// @@重名校验异常
request.setName(anotherAddPlugin.getName());
assertErrorCode( this.requestPost(DEFAULT_UPDATE, request), PLUGIN_EXIST);
assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), PLUGIN_EXIST);
// @@校验日志
checkLog(request.getId(), OperationLogType.UPDATE);
@ -260,10 +264,21 @@ public class PluginControllerTests extends BaseTest {
// 校验数据是否正确
List<PluginDTO> pluginList = getResultDataArray(mvcResult, PluginDTO.class);
Assertions.assertEquals(3, pluginList.size());
// 获取数据库数据
List<String> pluginIds = pluginList.stream().map(PluginDTO::getId).toList();
PluginExample example = new PluginExample();
example.createCriteria().andPluginIdNotIn(pluginIds);
List<Plugin> dbPlugins = pluginMapper.selectByExample(example);
List<String> userIds = dbPlugins.stream().map(Plugin::getCreateUser).toList();
Map<String, String> userNameMap = baseUserService.getUserNameMap(userIds);
Map<String, Plugin> dbPluginMap = dbPlugins.stream().collect(Collectors.toMap(Plugin::getId, i -> i));
for (PluginDTO pluginDTO : pluginList) {
Plugin comparePlugin = pluginMapper.selectByPrimaryKey(pluginDTO.getId());
Plugin comparePlugin = dbPluginMap.get(pluginDTO.getId());
Plugin plugin = JSON.parseObject(JSON.toJSONString(pluginDTO), Plugin.class);
List<String> scriptIds = pluginDTO.getPluginForms().stream().map(OptionDTO::getId).toList();
comparePlugin.setCreateUser(userNameMap.get(comparePlugin.getCreateUser()));
Assertions.assertEquals(plugin, comparePlugin);
Assertions.assertEquals(scriptIds, getScriptIdsByPlugId(plugin.getId()));
List<OptionDTO> orgList = Optional.ofNullable(pluginDTO.getOrganizations()).orElse(new ArrayList<>(0));
@ -281,7 +296,7 @@ public class PluginControllerTests extends BaseTest {
mockMvc.perform(getRequestBuilder(PLUGIN_IMAGE, anotherAddPlugin.getId(), "/static/jira.jpg"))
.andExpect(status().isOk());
assertErrorCode( this.requestGet(PLUGIN_IMAGE, anotherAddPlugin.getId(), "/static/jira.doc"), FILE_NAME_ILLEGAL);
assertErrorCode(this.requestGet(PLUGIN_IMAGE, anotherAddPlugin.getId(), "/static/jira.doc"), FILE_NAME_ILLEGAL);
}
@Test