fix: jar包管理重名校验

--bug=1013124 --user=陈建星 【项目设置】文件管理-上传jar包,名称校验有问题 https://www.tapd.cn/55049933/s/1157010
This commit is contained in:
chenjianxing 2022-05-12 16:07:50 +08:00 committed by jianxing
parent 810652fc98
commit f27f6dee53
7 changed files with 30 additions and 11 deletions

View File

@ -8,4 +8,6 @@ import java.util.List;
public interface ExtJarConfigMapper {
List<JarConfig> list(@Param("request") JarConfigRequest request);
int checkExist(@Param("request") JarConfigRequest request);
}

View File

@ -1,6 +1,19 @@
<?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.base.mapper.ext.ExtJarConfigMapper">
<select id="checkExist" resultType="integer">
select count(*) from jar_config jc
<where>
jc.name = #{request.name}
and jc.id != #{request.id}
<if test="request.resourceType == 'WORKSPACE'">
and jc.resource_id = #{request.resourceId}
</if>
<if test="request.resourceType == 'PROJECT'">
and (jc.resource_id = #{request.resourceId} or jc.resource_id = #{request.workspaceId})
</if>
</where>
</select>
<select id="list" resultType="io.metersphere.base.domain.JarConfig">
select * from jar_config jc

View File

@ -7,6 +7,7 @@ import lombok.Setter;
@Getter
@Setter
public class JarConfigRequest extends BaseQueryRequest {
private String id;
private String resourceId;
private String resourceType;
}

View File

@ -19,7 +19,6 @@ import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.system.SystemReference;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@ -51,6 +50,12 @@ public class JarConfigService {
}
public Pager<List<JarConfig>> list(JarConfigRequest request, int pageNum, int pageSize) {
buildQueryRequest(request);
Page<Object> page = PageHelper.startPage(pageNum, pageSize, true);
return PageUtils.setPageInfo(page, extJarConfigMapper.list(request));
}
public void buildQueryRequest(JarConfigRequest request) {
if (request.getResourceId() == null || request.getResourceType() == null) {
MSException.throwException("resourceId or resourceType could not be null!");
}
@ -58,8 +63,6 @@ public class JarConfigService {
Project project = projectService.getProjectById(request.getResourceId());
request.setWorkspaceId(project.getWorkspaceId());
}
Page<Object> page = PageHelper.startPage(pageNum, pageSize, true);
return PageUtils.setPageInfo(page, extJarConfigMapper.list(request));
}
public JarConfig get(String id) {
@ -119,14 +122,11 @@ public class JarConfigService {
private void checkExist(JarConfig jarConfig) {
if (jarConfig.getName() != null) {
JarConfigExample example = new JarConfigExample();
JarConfigExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(jarConfig.getName());
if (StringUtils.isNotBlank(jarConfig.getId())) {
criteria.andIdNotEqualTo(jarConfig.getId());
}
if (jarConfigMapper.selectByExample(example).size() > 0) {
MSException.throwException(Translator.get("already_exists"));
JarConfigRequest request = new JarConfigRequest();
BeanUtils.copyBean(request, jarConfig);
buildQueryRequest(request);
if (extJarConfigMapper.checkExist(request) > 0) {
MSException.throwException(Translator.get("name_already_exists"));
}
}
}

View File

@ -10,6 +10,7 @@ delete_fail=Delete fail
start_engine_fail=Start fail
upload_fail=Upload fail
invalid_parameter=Invalid parameter!
name_already_exists=Name already exists
#user related
user_email_already_exists=User email already exists
user_id_is_null=User ID cannot be null

View File

@ -9,6 +9,7 @@ delete_fail=删除失败
start_engine_fail=启动失败
upload_fail=文件上传失败
invalid_parameter=非法的参数
name_already_exists=该名称已经存在
#user related
user_email_already_exists=用户邮箱已存在
user_id_is_null=用户ID不能为空

View File

@ -9,6 +9,7 @@ delete_fail=刪除失敗
start_engine_fail=啟動失敗
upload_fail=文件上傳失敗
invalid_parameter=非法的參數
name_already_exists=該名稱已經存在
#user related
user_email_already_exists=用戶郵箱已存在
user_id_is_null=用戶ID不能為空