fix(系统设置): 插件列表创建人显示的是ID
--task=1012390 --user=陈建星 系统设置-系统-插件管理-后台 https://www.tapd.cn/55049933/s/1408086
This commit is contained in:
parent
383e3fcf78
commit
5754dd1783
|
@ -33,4 +33,5 @@ public interface BaseUserMapper {
|
||||||
|
|
||||||
List<ExcludeOptionDTO> getExcludeSelectOption();
|
List<ExcludeOptionDTO> getExcludeSelectOption();
|
||||||
|
|
||||||
|
List<OptionDTO> getSelectOptionByIds(List<String> ids);
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,4 +96,13 @@
|
||||||
select id, name
|
select id, name
|
||||||
from user
|
from user
|
||||||
</select>
|
</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>
|
</mapper>
|
|
@ -107,6 +107,7 @@ public class BaseUserService {
|
||||||
throw new UnauthorizedException(Translator.get("not_authorized") + e.getMessage());
|
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);
|
User user = userMapper.selectByPrimaryKey(userId);
|
||||||
|
@ -428,10 +429,29 @@ public class BaseUserService {
|
||||||
return baseUserMapper.getExcludeSelectOption();
|
return baseUserMapper.getExcludeSelectOption();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<OptionDTO> getSelectOptionByIds(List<String> ids) {
|
||||||
|
return baseUserMapper.getSelectOptionByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, String> getUserNameMap() {
|
public Map<String, String> getUserNameMap() {
|
||||||
List<ExcludeOptionDTO> excludeSelectOption = getExcludeSelectOption();
|
List<ExcludeOptionDTO> excludeSelectOption = getExcludeSelectOption();
|
||||||
Map<String, String> nameMap = new HashMap<>();
|
Map<String, String> nameMap = new HashMap<>();
|
||||||
excludeSelectOption.forEach(option -> nameMap.put(option.getId(), option.getName()));
|
excludeSelectOption.forEach(option -> nameMap.put(option.getId(), option.getName()));
|
||||||
return nameMap;
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import io.metersphere.sdk.constants.PluginScenarioType;
|
||||||
import io.metersphere.sdk.controller.handler.result.CommonResultCode;
|
import io.metersphere.sdk.controller.handler.result.CommonResultCode;
|
||||||
import io.metersphere.sdk.dto.OptionDTO;
|
import io.metersphere.sdk.dto.OptionDTO;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
|
import io.metersphere.sdk.service.BaseUserService;
|
||||||
import io.metersphere.sdk.service.JdbcDriverPluginService;
|
import io.metersphere.sdk.service.JdbcDriverPluginService;
|
||||||
import io.metersphere.sdk.service.PluginLoadService;
|
import io.metersphere.sdk.service.PluginLoadService;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
|
@ -58,18 +59,27 @@ public class PluginService {
|
||||||
JdbcDriverPluginService jdbcDriverPluginService;
|
JdbcDriverPluginService jdbcDriverPluginService;
|
||||||
@Resource
|
@Resource
|
||||||
private KafkaTemplate<String, String> kafkaTemplate;
|
private KafkaTemplate<String, String> kafkaTemplate;
|
||||||
|
@Resource
|
||||||
|
private BaseUserService baseUserService;
|
||||||
|
|
||||||
public List<PluginDTO> list() {
|
public List<PluginDTO> list() {
|
||||||
List<PluginDTO> plugins = extPluginMapper.getPlugins();
|
List<PluginDTO> plugins = extPluginMapper.getPlugins();
|
||||||
List<String> pluginIds = plugins.stream().map(Plugin::getId).toList();
|
List<String> pluginIds = plugins.stream().map(Plugin::getId).toList();
|
||||||
Map<String, List<OptionDTO>> scripteMap = pluginScriptService.getScripteMap(pluginIds);
|
Map<String, List<OptionDTO>> scripteMap = pluginScriptService.getScripteMap(pluginIds);
|
||||||
Map<String, List<OptionDTO>> orgMap = pluginOrganizationService.getOrgMap(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 -> {
|
plugins.forEach(plugin -> {
|
||||||
List<OptionDTO> pluginForms = scripteMap.get(plugin.getId());
|
List<OptionDTO> pluginForms = scripteMap.get(plugin.getId());
|
||||||
List<OptionDTO> organizations = orgMap.get(plugin.getId());
|
List<OptionDTO> organizations = orgMap.get(plugin.getId());
|
||||||
plugin.setPluginForms(pluginForms == null ? new ArrayList<>(0) : pluginForms);
|
plugin.setPluginForms(pluginForms == null ? new ArrayList<>(0) : pluginForms);
|
||||||
plugin.setOrganizations(organizations == null ? new ArrayList<>(0) : organizations);
|
plugin.setOrganizations(organizations == null ? new ArrayList<>(0) : organizations);
|
||||||
|
plugin.setCreateUser(userNameMap.get(plugin.getCreateUser()));
|
||||||
});
|
});
|
||||||
|
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,14 @@ import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
import io.metersphere.sdk.constants.PluginScenarioType;
|
import io.metersphere.sdk.constants.PluginScenarioType;
|
||||||
import io.metersphere.sdk.dto.OptionDTO;
|
import io.metersphere.sdk.dto.OptionDTO;
|
||||||
import io.metersphere.sdk.log.constants.OperationLogType;
|
import io.metersphere.sdk.log.constants.OperationLogType;
|
||||||
|
import io.metersphere.sdk.service.BaseUserService;
|
||||||
import io.metersphere.sdk.service.JdbcDriverPluginService;
|
import io.metersphere.sdk.service.JdbcDriverPluginService;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.system.controller.param.PluginUpdateRequestDefinition;
|
import io.metersphere.system.controller.param.PluginUpdateRequestDefinition;
|
||||||
import io.metersphere.system.domain.*;
|
import io.metersphere.system.domain.*;
|
||||||
import io.metersphere.system.dto.OrganizationDTO;
|
import io.metersphere.system.dto.OrganizationDTO;
|
||||||
import io.metersphere.system.dto.PluginDTO;
|
import io.metersphere.system.dto.PluginDTO;
|
||||||
|
import io.metersphere.system.mapper.ExtPluginMapper;
|
||||||
import io.metersphere.system.mapper.PluginMapper;
|
import io.metersphere.system.mapper.PluginMapper;
|
||||||
import io.metersphere.system.mapper.PluginOrganizationMapper;
|
import io.metersphere.system.mapper.PluginOrganizationMapper;
|
||||||
import io.metersphere.system.mapper.PluginScriptMapper;
|
import io.metersphere.system.mapper.PluginScriptMapper;
|
||||||
|
@ -25,10 +27,8 @@ import org.springframework.test.web.servlet.MvcResult;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
import java.util.stream.Collectors;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.FILE_NAME_ILLEGAL;
|
import static io.metersphere.sdk.controller.handler.result.CommonResultCode.FILE_NAME_ILLEGAL;
|
||||||
import static io.metersphere.system.controller.result.SystemResultCode.*;
|
import static io.metersphere.system.controller.result.SystemResultCode.*;
|
||||||
|
@ -48,6 +48,10 @@ public class PluginControllerTests extends BaseTest {
|
||||||
@Resource
|
@Resource
|
||||||
private PluginMapper pluginMapper;
|
private PluginMapper pluginMapper;
|
||||||
@Resource
|
@Resource
|
||||||
|
private ExtPluginMapper extPluginMapper;
|
||||||
|
@Resource
|
||||||
|
private BaseUserService baseUserService;
|
||||||
|
@Resource
|
||||||
private PluginOrganizationMapper pluginOrganizationMapper;
|
private PluginOrganizationMapper pluginOrganizationMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private PluginScriptMapper pluginScriptMapper;
|
private PluginScriptMapper pluginScriptMapper;
|
||||||
|
@ -260,10 +264,21 @@ public class PluginControllerTests extends BaseTest {
|
||||||
// 校验数据是否正确
|
// 校验数据是否正确
|
||||||
List<PluginDTO> pluginList = getResultDataArray(mvcResult, PluginDTO.class);
|
List<PluginDTO> pluginList = getResultDataArray(mvcResult, PluginDTO.class);
|
||||||
Assertions.assertEquals(3, pluginList.size());
|
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) {
|
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);
|
Plugin plugin = JSON.parseObject(JSON.toJSONString(pluginDTO), Plugin.class);
|
||||||
List<String> scriptIds = pluginDTO.getPluginForms().stream().map(OptionDTO::getId).toList();
|
List<String> scriptIds = pluginDTO.getPluginForms().stream().map(OptionDTO::getId).toList();
|
||||||
|
comparePlugin.setCreateUser(userNameMap.get(comparePlugin.getCreateUser()));
|
||||||
Assertions.assertEquals(plugin, comparePlugin);
|
Assertions.assertEquals(plugin, comparePlugin);
|
||||||
Assertions.assertEquals(scriptIds, getScriptIdsByPlugId(plugin.getId()));
|
Assertions.assertEquals(scriptIds, getScriptIdsByPlugId(plugin.getId()));
|
||||||
List<OptionDTO> orgList = Optional.ofNullable(pluginDTO.getOrganizations()).orElse(new ArrayList<>(0));
|
List<OptionDTO> orgList = Optional.ofNullable(pluginDTO.getOrganizations()).orElse(new ArrayList<>(0));
|
||||||
|
|
Loading…
Reference in New Issue