diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReourcePoolMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReourcePoolMapper.java deleted file mode 100644 index 17877364f20a0a3c6573d2f5f123b7e7d3ac0ab5..0000000000000000000000000000000000000000 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReourcePoolMapper.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.metersphere.base.mapper.ext; - -import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest; -import io.metersphere.dto.TestResourcePoolDTO; -import org.apache.ibatis.annotations.Param; - -import java.util.List; - -public interface ExtTestReourcePoolMapper { - List listResourcePools(@Param("request") QueryResourcePoolRequest request); - -// List listResourcesByPoolId(@Param("poolId") String poolId); -} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReourcePoolMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReourcePoolMapper.xml deleted file mode 100644 index f6b84f52bb8077505b6299f54274939f991ed2e8..0000000000000000000000000000000000000000 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestReourcePoolMapper.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptorConfig.java b/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptorConfig.java index 27dc39450174db0fbbacf389ea8bc8c56f4dc9cb..47979d7586f07c9c47435cfcbaa7b1c5e10949d1 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptorConfig.java +++ b/backend/src/main/java/io/metersphere/commons/utils/MybatisInterceptorConfig.java @@ -1,5 +1,10 @@ package io.metersphere.commons.utils; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter public class MybatisInterceptorConfig { private String modelName; private String attrName; @@ -9,7 +14,6 @@ public class MybatisInterceptorConfig { private String undoClass; private String undoMethod; - public MybatisInterceptorConfig() { } @@ -17,100 +21,25 @@ public class MybatisInterceptorConfig { * 用时需谨慎!!!!! * 主要配置多个的时候,参数少一点 * - * @param modelName + * @param modelClass * @param attrName */ - public MybatisInterceptorConfig(String modelName, String attrName) { - this.modelName = modelName; + public MybatisInterceptorConfig(Class modelClass, String attrName) { + this.modelName = modelClass.getName(); this.attrName = attrName; - this.interceptorClass = "io.metersphere.commons.utils.EncryptUtils"; + this.interceptorClass = EncryptUtils.class.getName(); this.interceptorMethod = "aesEncrypt"; - this.undoClass = "io.metersphere.commons.utils.EncryptUtils"; + this.undoClass = EncryptUtils.class.getName(); this.undoMethod = "aesDecrypt"; } - public MybatisInterceptorConfig(String modelName, String attrName, String attrNameForList) { - this.modelName = modelName; - this.attrName = attrName; - this.attrNameForList = attrNameForList; - this.interceptorClass = "io.metersphere.commons.utils.EncryptUtils"; - this.interceptorMethod = "aesEncrypt"; - this.undoClass = "io.metersphere.commons.utils.EncryptUtils"; - this.undoMethod = "aesDecrypt"; - } - - public MybatisInterceptorConfig(String modelName, String attrName, String interceptorClass, String interceptorMethod, String undoMethod) { - this.modelName = modelName; - this.attrName = attrName; - this.interceptorClass = interceptorClass; - this.interceptorMethod = interceptorMethod; - this.undoClass = interceptorClass; - this.undoMethod = undoMethod; - } - - public MybatisInterceptorConfig(String modelName, String attrName, String attrNameForList, String interceptorClass, String interceptorMethod, String undoMethod) { - this.modelName = modelName; - this.attrName = attrName; - this.attrNameForList = attrNameForList; - this.interceptorClass = interceptorClass; - this.interceptorMethod = interceptorMethod; - this.undoClass = interceptorClass; - this.undoMethod = undoMethod; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getAttrName() { - return attrName; - } - - public void setAttrName(String attrName) { + public MybatisInterceptorConfig(Class modelClass, String attrName, Class interceptorClass, String interceptorMethod, String undoMethod) { + this.modelName = modelClass.getName(); this.attrName = attrName; - } - - public String getAttrNameForList() { - return attrNameForList; - } - - public void setAttrNameForList(String attrNameForList) { - this.attrNameForList = attrNameForList; - } - - public String getInterceptorMethod() { - return interceptorMethod; - } - - public void setInterceptorMethod(String interceptorMethod) { + this.interceptorClass = interceptorClass.getName(); this.interceptorMethod = interceptorMethod; - } - - public String getUndoMethod() { - return undoMethod; - } - - public void setUndoMethod(String undoMethod) { + this.undoClass = interceptorClass.getName(); this.undoMethod = undoMethod; } - public String getInterceptorClass() { - return interceptorClass; - } - - public void setInterceptorClass(String interceptorClass) { - this.interceptorClass = interceptorClass; - } - - public String getUndoClass() { - return undoClass; - } - - public void setUndoClass(String undoClass) { - this.undoClass = undoClass; - } } diff --git a/backend/src/main/java/io/metersphere/config/MybatisConfig.java b/backend/src/main/java/io/metersphere/config/MybatisConfig.java index dc7e90967def8a8c07f39fdb45b0d774654d0d3f..0d8b6eba2120c53408fb459bd90d339501297ed5 100644 --- a/backend/src/main/java/io/metersphere/config/MybatisConfig.java +++ b/backend/src/main/java/io/metersphere/config/MybatisConfig.java @@ -1,6 +1,9 @@ package io.metersphere.config; import com.github.pagehelper.PageInterceptor; +import io.metersphere.base.domain.FileContent; +import io.metersphere.base.domain.TestResource; +import io.metersphere.commons.utils.CompressUtils; import io.metersphere.commons.utils.MybatisInterceptorConfig; import io.metersphere.interceptor.MybatisInterceptor; import org.mybatis.spring.annotation.MapperScan; @@ -37,7 +40,8 @@ public class MybatisConfig { public MybatisInterceptor dbInterceptor() { MybatisInterceptor interceptor = new MybatisInterceptor(); List configList = new ArrayList<>(); - configList.add(new MybatisInterceptorConfig("io.metersphere.base.domain.FileContent", "file", "io.metersphere.commons.utils.CompressUtils", "zip", "unzip")); + configList.add(new MybatisInterceptorConfig(FileContent.class, "file", CompressUtils.class, "zip", "unzip")); + configList.add(new MybatisInterceptorConfig(TestResource.class, "configuration")); interceptor.setInterceptorConfigList(configList); return interceptor; } diff --git a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java index cd454e60e87963c209921011c3ba87ac92f23c56..ce74519c3862c5f509ce60fb8d105add2f3341d3 100644 --- a/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java +++ b/backend/src/main/java/io/metersphere/service/TestResourcePoolService.java @@ -7,15 +7,16 @@ import io.metersphere.base.domain.TestResourcePool; import io.metersphere.base.domain.TestResourcePoolExample; import io.metersphere.base.mapper.TestResourceMapper; import io.metersphere.base.mapper.TestResourcePoolMapper; -import io.metersphere.base.mapper.ext.ExtTestReourcePoolMapper; import io.metersphere.commons.constants.ResourcePoolTypeEnum; import io.metersphere.commons.constants.ResourceStatusEnum; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.controller.request.resourcepool.QueryResourcePoolRequest; import io.metersphere.dto.NodeDTO; import io.metersphere.dto.TestResourcePoolDTO; import io.metersphere.engine.kubernetes.provider.KubernetesProvider; import io.metersphere.i18n.Translator; +import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpStatus; @@ -25,6 +26,8 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; @@ -46,8 +49,6 @@ public class TestResourcePoolService { @Resource private TestResourceMapper testResourceMapper; @Resource - private ExtTestReourcePoolMapper extTestReourcePoolMapper; - @Resource private RestTemplate restTemplate; public TestResourcePoolDTO addTestResourcePool(TestResourcePoolDTO testResourcePool) { @@ -72,7 +73,27 @@ public class TestResourcePoolService { } public List listResourcePools(QueryResourcePoolRequest request) { - return extTestReourcePoolMapper.listResourcePools(request); + TestResourcePoolExample example = new TestResourcePoolExample(); + TestResourcePoolExample.Criteria criteria = example.createCriteria(); + if (StringUtils.isNotBlank(request.getName())) { + criteria.andNameLike(StringUtils.wrapIfMissing(request.getName(), "%")); + } + List testResourcePools = testResourcePoolMapper.selectByExample(example); + List testResourcePoolDTOS = new ArrayList<>(); + testResourcePools.forEach(pool -> { + TestResourceExample example2 = new TestResourceExample(); + example2.createCriteria().andTestResourcePoolIdEqualTo(pool.getId()); + List testResources = testResourceMapper.selectByExampleWithBLOBs(example2); + TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO(); + try { + BeanUtils.copyProperties(testResourcePoolDTO, pool); + testResourcePoolDTO.setResources(testResources); + testResourcePoolDTOS.add(testResourcePoolDTO); + } catch (IllegalAccessException | InvocationTargetException e) { + LogUtil.error(e); + } + }); + return testResourcePoolDTOS; } private void validateTestResourcePool(TestResourcePoolDTO testResourcePool) {