diff --git a/backend/app/src/main/resources/migration/3.0.0/ddl/V2__ddl.sql b/backend/app/src/main/resources/migration/3.0.0/ddl/V2__ddl.sql index 34d9b06689..66d4331dc8 100644 --- a/backend/app/src/main/resources/migration/3.0.0/ddl/V2__ddl.sql +++ b/backend/app/src/main/resources/migration/3.0.0/ddl/V2__ddl.sql @@ -10,3 +10,22 @@ CREATE TABLE IF NOT EXISTS `project` `system_id` VARCHAR(50) COMMENT '', PRIMARY KEY (id) ) COMMENT = '项目'; + + +CREATE TABLE IF NOT EXISTS `user` +( + `id` VARCHAR(50) NOT NULL COMMENT '用户ID', + `name` VARCHAR(64) NOT NULL COMMENT '用户名', + `email` VARCHAR(64) NOT NULL COMMENT '用户邮箱', + `password` VARCHAR(256) COMMENT '用户密码', + `status` VARCHAR(50) NOT NULL COMMENT '用户状态,启用或禁用', + `create_time` BIGINT NOT NULL COMMENT '创建时间', + `update_time` BIGINT NOT NULL COMMENT '更新时间', + `language` VARCHAR(30) COMMENT '语言', + `last_workspace_id` VARCHAR(50) COMMENT '当前工作空间ID', + `phone` VARCHAR(50) COMMENT '手机号', + `source` VARCHAR(50) NOT NULL COMMENT '来源:LOCAL OIDC CAS', + `last_project_id` VARCHAR(50) COMMENT '当前项目ID', + `create_user` VARCHAR(100) NOT NULL COMMENT '创建人', + PRIMARY KEY (id) +) COMMENT = '用户'; diff --git a/backend/framework/domain/src/main/java/io/metersphere/domain/User.java b/backend/framework/domain/src/main/java/io/metersphere/domain/User.java index 03e2059c65..2463622e06 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/domain/User.java +++ b/backend/framework/domain/src/main/java/io/metersphere/domain/User.java @@ -39,9 +39,5 @@ public class User implements Serializable { private String createUser; - private String platformInfo; - - private String seleniumServer; - private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java new file mode 100644 index 0000000000..f54802628e --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/UserController.java @@ -0,0 +1,23 @@ +package io.metersphere.system.controller; + + +import io.metersphere.domain.User; +import io.metersphere.system.service.UserService; +import jakarta.annotation.Resource; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/user") +public class UserController { + @Resource + private UserService userService; + + @GetMapping("/list-all") + public List listAll() { + return userService.list(); + } +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/domain/User.java b/backend/services/system-setting/src/main/java/io/metersphere/system/domain/User.java deleted file mode 100644 index 5a11cb9431..0000000000 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/domain/User.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.metersphere.system.domain; - -import lombok.Data; - -import java.io.Serializable; - -@Data -public class User implements Serializable { - private String id; - - private String name; - - private String email; - - private String password; - - private String status; - - private Long createTime; - - private Long updateTime; - - private String language; - - private String lastWorkspaceId; - - private String phone; - - private String source; - - private String lastProjectId; - - private String createUser; - - private String platformInfo; - - private String seleniumServer; - - private static final long serialVersionUID = 1L; -} \ No newline at end of file diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java new file mode 100644 index 0000000000..b852f90978 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java @@ -0,0 +1,11 @@ +package io.metersphere.system.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import io.metersphere.domain.User; +import io.metersphere.sdk.mapper.UserMapper; +import org.springframework.stereotype.Service; + +@Service +public class UserService extends ServiceImpl { + +} diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/Application.java b/backend/services/system-setting/src/test/java/io/metersphere/system/Application.java new file mode 100644 index 0000000000..fa63330927 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/Application.java @@ -0,0 +1,23 @@ +package io.metersphere.system; + +import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration; +import org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration; +import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration; +import org.springframework.boot.web.servlet.ServletComponentScan; + +@SpringBootApplication(exclude = { + QuartzAutoConfiguration.class, + LdapAutoConfiguration.class, + Neo4jAutoConfiguration.class, + MybatisAutoConfiguration.class +}) +@ServletComponentScan +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/config/MybatisConfig.java b/backend/services/system-setting/src/test/java/io/metersphere/system/config/MybatisConfig.java new file mode 100644 index 0000000000..6cfefec843 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/config/MybatisConfig.java @@ -0,0 +1,82 @@ +package io.metersphere.system.config; + +import com.fit2cloud.quartz.anno.QuartzDataSource; +import com.github.pagehelper.PageInterceptor; +import com.zaxxer.hikari.HikariDataSource; +import io.metersphere.sdk.interceptor.MybatisInterceptor; +import io.metersphere.sdk.interceptor.UserDesensitizationInterceptor; +import io.metersphere.sdk.util.MybatisInterceptorConfig; +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.jdbc.DataSourceBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +@Configuration +@MapperScan(basePackages = {"io.metersphere.*.mapper"}, sqlSessionFactoryRef = "sqlSessionFactory") +@EnableTransactionManagement +public class MybatisConfig { + @Bean + @ConditionalOnMissingBean + public PageInterceptor pageInterceptor() { + PageInterceptor pageInterceptor = new PageInterceptor(); + Properties properties = new Properties(); + properties.setProperty("helperDialect", "mysql"); + properties.setProperty("rowBoundsWithCount", "true"); + properties.setProperty("reasonable", "true"); + properties.setProperty("offsetAsPageNum", "true"); + properties.setProperty("pageSizeZero", "true"); + pageInterceptor.setProperties(properties); + return pageInterceptor; + } + + @Bean + @ConditionalOnMissingBean + public MybatisInterceptor dbInterceptor() { + MybatisInterceptor interceptor = new MybatisInterceptor(); + List configList = new ArrayList<>(); +// configList.add(new MybatisInterceptorConfig(FileContent.class, "file", CompressUtils.class, "zip", "unzip")); + interceptor.setInterceptorConfigList(configList); + return interceptor; + } + + @Bean + public UserDesensitizationInterceptor userDesensitizationInterceptor() { + return new UserDesensitizationInterceptor(); + } + + + @Bean + @Primary + @ConfigurationProperties(prefix = "spring.datasource.hikari") + public DataSource dataSource(DataSourceProperties properties) { + return DataSourceBuilder.create(properties.getClassLoader()).type(HikariDataSource.class) + .driverClassName(properties.determineDriverClassName()) + .url(properties.determineUrl()) + .username(properties.determineUsername()) + .password(properties.determinePassword()) + .build(); + } + + @Bean + @ConfigurationProperties(prefix = "spring.datasource.quartz.hikari") + @QuartzDataSource + public DataSource quartzDataSource(DataSourceProperties properties) { + return DataSourceBuilder.create(properties.getClassLoader()).type(HikariDataSource.class) + .driverClassName(properties.determineDriverClassName()) + .url(properties.determineUrl()) + .username(properties.determineUsername()) + .password(properties.determinePassword()) + .build(); + } + +} diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserControllerTests.java new file mode 100644 index 0000000000..46eb95a74b --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/UserControllerTests.java @@ -0,0 +1,31 @@ +package io.metersphere.system.controller; + +import jakarta.annotation.Resource; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + + +@SpringBootTest +@AutoConfigureMockMvc +public class UserControllerTests { + @Resource + private MockMvc mockMvc; + + @Test + public void testSelectAll() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/user/list-all")) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) +// .andExpect(jsonPath("$.person.name").value("Jason")) + .andDo(print()); + } + +} diff --git a/backend/services/system-setting/src/test/resources/application.properties b/backend/services/system-setting/src/test/resources/application.properties new file mode 100644 index 0000000000..14120a7a41 --- /dev/null +++ b/backend/services/system-setting/src/test/resources/application.properties @@ -0,0 +1,76 @@ +spring.application.name=metersphere +management.server.port=7071 +server.port=8081 +# ?? gzip ?? +server.compression.enabled=true +server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css,text/javascript,image/jpeg +server.compression.min-response-size=2048 +# +quartz.enabled=false +quartz.scheduler-name=msScheduler +quartz.thread-count=10 +quartz.properties.org.quartz.jobStore.acquireTriggersWithinLock=true +# +logging.file.path=/opt/metersphere/logs/metersphere +# Hikari +spring.datasource.url=jdbc:mysql://localhost:${embedded.mysql.port}/test?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8 +spring.datasource.username=${embedded.mysql.user} +spring.datasource.password=${embedded.mysql.password} +spring.datasource.type=com.zaxxer.hikari.HikariDataSource +spring.datasource.hikari.maximum-pool-size=100 +spring.datasource.hikari.minimum-idle=10 +spring.datasource.hikari.idle-timeout=300000 +spring.datasource.hikari.auto-commit=true +spring.datasource.hikari.pool-name=DatebookHikariCP +spring.datasource.hikari.max-lifetime=1800000 +spring.datasource.hikari.connection-timeout=30000 +spring.datasource.hikari.connection-test-query=SELECT 1 + +# +# spring.kafka +spring.kafka.bootstrap-servers=${kafka.bootstrap-servers} +spring.kafka.consumer.group-id=metersphere_group_id +spring.kafka.consumer.debug.group-id=metersphere_group_id_${random.uuid} +spring.kafka.listener.missing-topics-fatal=false +spring.kafka.producer.properties.max.request.size=32428800 +spring.kafka.producer.batch-size=16384 +spring.kafka.consumer.properties.max.partition.fetch.bytes=52428800 +# mybatis +mybatis.configuration.cache-enabled=true +mybatis.configuration.lazy-loading-enabled=false +mybatis.configuration.aggressive-lazy-loading=true +mybatis.configuration.multiple-result-sets-enabled=true +mybatis.configuration.use-column-label=true +mybatis.configuration.auto-mapping-behavior=full +mybatis.configuration.default-statement-timeout=25000 +mybatis.configuration.map-underscore-to-camel-case=true +# view +spring.mvc.throw-exception-if-no-handler-found=true +# flyway enable +spring.flyway.enabled=true +spring.flyway.baseline-on-migrate=true +spring.flyway.locations=filesystem:../../app/src/main/resources/migration +spring.flyway.table=metersphere_version +spring.flyway.baseline-version=0 +spring.flyway.encoding=UTF-8 +spring.flyway.validate-on-migrate=false +# jmeter +jmeter.home=/opt/jmeter +# file upload +spring.servlet.multipart.max-file-size=500MB +spring.servlet.multipart.max-request-size=500MB +# i18n +spring.messages.basename=i18n/messages,i18n/api,i18n/load,i18n/project,i18n/system,i18n/plan,i18n/track,i18n/ui,i18n/workstation +# actuator +management.endpoints.web.exposure.include=* +management.endpoints.enabled-by-default=false +# redis +spring.session.timeout=43200s +spring.data.redis.host=localhost +spring.data.redis.password=${embedded.redis.password} +spring.data.redis.port=${embedded.redis.port} +spring.session.redis.repository-type=indexed +# +spring.freemarker.check-template-location=false +spring.groovy.template.check-template-location=false +# diff --git a/backend/services/system-setting/src/test/resources/bootstrap.properties b/backend/services/system-setting/src/test/resources/bootstrap.properties new file mode 100644 index 0000000000..38cc3b010b --- /dev/null +++ b/backend/services/system-setting/src/test/resources/bootstrap.properties @@ -0,0 +1,9 @@ +# embedded config +embedded.containers.enabled=true +embedded.containers.forceShutdown=true +# mysql +embedded.mysql.enabled=true +embedded.mysql.encoding=utf8mb4 +embedded.mysql.collation=utf8mb4_general_ci +# redis +embedded.redis.enabled=true \ No newline at end of file