feat(ui): 新增本地上传

--story=1013573 --user=郭雨琦
https://www.tapd.cn/55049933/prong/stories/view/1155049933001013573
This commit is contained in:
guoyuqi 2023-11-13 15:06:25 +08:00 committed by 刘瑞斌
parent 6b7a529c40
commit 9dcbaae2b5
5 changed files with 56 additions and 3 deletions

View File

@ -11,6 +11,11 @@ export function getFileModules(projectId) {
return get(url);
}
export function getTypeNodeByProjectId(projectId, moduleType) {
let url = '/file/module/type/list/' + projectId + "/" + moduleType;
return get(url);
}
export function getMetadataTypes() {
let url = '/file/metadata/get/type/all';
return get(url);

View File

@ -11,6 +11,8 @@ public interface BaseFileModuleMapper {
List<FileModuleVo> getNodeTreeByProjectId(@Param("projectId") String projectId);
List<FileModuleVo> getTypeNodeTreeByProjectId(@Param("projectId") String projectId, @Param("moduleType") String moduleType);
void updatePos(String id, Double pos);
String getNameById(String moduleId);

View File

@ -17,6 +17,16 @@
where file_module.project_id = #{projectId}
order by file_module.pos asc
</select>
<select id="getTypeNodeTreeByProjectId" resultType="io.metersphere.metadata.vo.FileModuleVo">
select
<include refid="io.metersphere.base.mapper.FileModuleMapper.Base_Column_List"/>
from file_module
where file_module.project_id = #{projectId} and file_module.module_type = #{moduleType}
order by file_module.pos asc
</select>
<select id="getNameById" resultType="java.lang.String">
select name from file_module
where id = #{0}

View File

@ -30,6 +30,12 @@ public class FileModuleController {
return fileModuleService.getNodeTreeByProjectId(projectId);
}
@GetMapping("/type/list/{projectId}/{moduleType}")
public List<FileModuleVo> getTypeNodeByProjectId(@PathVariable String projectId, @PathVariable String moduleType) {
baseCheckPermissionService.checkProjectOwner(projectId);
return fileModuleService.getTypeNodeByProjectId(projectId, moduleType);
}
@PostMapping("/add")
@RequiresPermissions("PROJECT_FILE:READ+UPLOAD+JAR")
@MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.CREATE, title = "#node.name", content = "#msClass.getLogDetails(#node)", msClass = FileModuleService.class)

View File

@ -10,9 +10,7 @@ import io.metersphere.base.mapper.ext.BaseFileMetadataMapper;
import io.metersphere.base.mapper.ext.BaseFileModuleMapper;
import io.metersphere.commons.constants.ApiTestConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.commons.utils.*;
import io.metersphere.i18n.Translator;
import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
@ -389,4 +387,36 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
return baseFileModuleMapper.getNameById(moduleId);
}
public List<FileModuleVo> getTypeNodeByProjectId(String projectId, String moduleType) {
// 判断当前项目下是否有默认模块没有添加默认模块
FileModule fileModule = this.initDefaultNode(projectId);
FileModuleVo fileModuleVo = new FileModuleVo();
BeanUtils.copyBean(fileModuleVo, fileModule);
List<FileModuleVo> modules = baseFileModuleMapper.getTypeNodeTreeByProjectId(projectId, moduleType);
if (StringUtils.equals(moduleType, "module")) {
modules.add(0, fileModuleVo);
}
List<String> ids = modules.stream().map(FileModuleVo::getId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(ids)) {
return getNodeTrees(modules);
}
List<Map<String, Object>> moduleCounts = baseFileMetadataMapper.moduleCountByMetadataIds(ids);
Map<String, Integer> moduleCountMap = this.nodeCalculate(moduleCounts);
// 逐层统计
if (MapUtils.isNotEmpty(moduleCountMap)) {
modules.forEach(node -> {
int countNum = 0;
List<String> moduleIds = new ArrayList<>();
moduleIds = this.nodeList(modules, node.getId(), moduleIds);
moduleIds.add(node.getId());
for (String moduleId : moduleIds) {
if (moduleCountMap.containsKey(moduleId)) {
countNum += moduleCountMap.get(moduleId).intValue();
}
}
node.setCaseNum(countNum);
});
}
return getNodeTrees(modules);
}
}