Browse Source

Merge branch 'dev_web_config' into dev

master
dashan 1 year ago
parent
commit
3b6e5e3955
  1. 3
      .idea/compiler.xml
  2. 3
      .idea/encodings.xml
  3. 48
      ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/DsWebInterceptor.java
  4. 3
      ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/MiniAppsApplication.java
  5. 36
      ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/api/dummyinfo/DummyInfoApi.java
  6. 4
      ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/service/dummyinfo/DummyInfoService.java
  7. 4
      ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/service/impl/dummyinfo/DummyInfoServiceImpl.java
  8. 18
      ds-biz/ds-miniapps/ds-miniapps-biz/src/main/resources/application.yml
  9. 13
      ds-biz/ds-miniapps/ds-miniapps-model/src/main/java/com/ds/miniapps/model/entity/dummyinfo/DummyInfo.java
  10. 18
      ds-biz/pom.xml
  11. 58
      ds-commons/ds-config/ds-web-config/pom.xml
  12. 38
      ds-commons/ds-config/ds-web-config/src/main/java/com/ds/commons/web/config/swagger/SwaggerConfig.java
  13. 44
      ds-commons/ds-config/ds-web-config/src/main/java/com/ds/commons/web/config/swagger/SwaggerYml.java
  14. 24
      ds-commons/ds-config/pom.xml
  15. 1
      ds-commons/pom.xml
  16. 21
      pom.xml

3
.idea/compiler.xml

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
<module name="ds-utils" />
<module name="ds-miniapps-api" />
<module name="ds-basemodel" />
<module name="ds-web-config" />
<module name="ds-miniapps-model" />
<module name="ds-miniapps-biz" />
<module name="ds-gateway" />
@ -23,6 +24,7 @@ @@ -23,6 +24,7 @@
<module name="ds-basemodel" options="-parameters" />
<module name="ds-biz" options="" />
<module name="ds-commons" options="" />
<module name="ds-config" options="" />
<module name="ds-gateway" options="-parameters" />
<module name="ds-miniapps" options="" />
<module name="ds-miniapps-api" options="-parameters" />
@ -30,6 +32,7 @@ @@ -30,6 +32,7 @@
<module name="ds-miniapps-model" options="-parameters" />
<module name="ds-timer-task" options="-parameters" />
<module name="ds-utils" options="-parameters" />
<module name="ds-web-config" options="-parameters" />
</option>
</component>
</project>

3
.idea/encodings.xml

@ -9,6 +9,9 @@ @@ -9,6 +9,9 @@
<file url="file://$PROJECT_DIR$/ds-biz/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-biz/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-basemodel/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/ds-web-config/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-config/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/ds-utils/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ds-commons/src/main/resources" charset="UTF-8" />

48
ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/DsWebInterceptor.java

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
package com.ds.miniapps.biz;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
/**
* @author ds
* @since 2023/8/29
*/
@Slf4j
public class DsWebInterceptor implements HandlerInterceptor {
private static final ThreadLocal<Long> START_THREAD_LOCAL = new ThreadLocal<>();
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
String uri = request.getRequestURI();
log.info(uri + " preHandle");
Long startTime = System.currentTimeMillis(); //获取开始时间
START_THREAD_LOCAL.set(startTime); //线程绑定变量(该数据只有当前请求的线程可见)
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
String uri = request.getRequestURI();
log.info(uri + " postHandle");
Long startTime = START_THREAD_LOCAL.get();//得到线程绑定的局部变量(开始时间)
Long endTime = System.currentTimeMillis(); //2、结束时间
Long time = endTime - startTime;
log.info("http request all time: " + time + "ms");
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
Exception ex) throws Exception {
String uri = request.getRequestURI();
log.info(uri + " afterCompletion");
if (START_THREAD_LOCAL != null) {
START_THREAD_LOCAL.remove(); // 移除ThreadLocal中的局部变量
}
}
}

3
ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/MiniAppsApplication.java

@ -1,13 +1,16 @@ @@ -1,13 +1,16 @@
package com.ds.miniapps.biz;
import com.ds.commons.web.config.swagger.SwaggerConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
/**
* @author ds
* @since 2023/8/27
*/
@SpringBootApplication
@Import(SwaggerConfig.class)
public class MiniAppsApplication {
public static void main(String[] args) {

36
ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/api/dummyinfo/DummyInfoApi.java

@ -0,0 +1,36 @@ @@ -0,0 +1,36 @@
package com.ds.miniapps.biz.api.dummyinfo;
import com.ds.miniapps.biz.service.dummyinfo.DummyInfoService;
import com.ds.miniapps.model.entity.dummyinfo.DummyInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Min;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author ds
* @since 2023/8/28
*/
@RestController
@AllArgsConstructor
@Tag(name = "虚拟人信息")
@RequestMapping("/dummy_info")
@Validated
public class DummyInfoApi {
private DummyInfoService dummyInfoService;
@GetMapping("/get_list")
@Operation(summary = "获取指定数量虚拟人信息")
public List<DummyInfo> getDummyInfoList(
@RequestParam("num") @Min(message = "数量不能小于1",value = 1) Integer num
){
return dummyInfoService.randCreateDummyInfo(num);
}
}

4
ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/service/dummyinfo/DummyInfoService.java

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
package com.ds.miniapps.biz.service.dummyinfo;
import com.ds.miniapps.model.entity.dummyinfo.DummyInfo;
import jakarta.validation.constraints.NotNull;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
@ -15,5 +15,5 @@ public interface DummyInfoService { @@ -15,5 +15,5 @@ public interface DummyInfoService {
* @param num 数量
* @return 假人集合
*/
List<DummyInfo> randCreateDummyInfo(@NotNull(message = "数量不能为空")Integer num);
List<DummyInfo> randCreateDummyInfo(@NotNull(message = "数量不允许为空") Integer num);
}

4
ds-biz/ds-miniapps/ds-miniapps-biz/src/main/java/com/ds/miniapps/biz/service/impl/dummyinfo/DummyInfoServiceImpl.java

@ -5,9 +5,9 @@ import com.ds.commons.utils.stringutil.RandInitPhoneNumbersUtils; @@ -5,9 +5,9 @@ import com.ds.commons.utils.stringutil.RandInitPhoneNumbersUtils;
import com.ds.miniapps.biz.service.dummyinfo.DummyInfoService;
import com.ds.miniapps.model.entity.dummyinfo.DummyInfo;
import com.ds.miniapps.model.enums.dummyinfo.TelecomOperatorsEnum;
import jakarta.validation.constraints.NotNull;
import org.springframework.stereotype.Service;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@ -19,7 +19,7 @@ import java.util.Random; @@ -19,7 +19,7 @@ import java.util.Random;
@Service
public class DummyInfoServiceImpl implements DummyInfoService {
@Override
public List<DummyInfo> randCreateDummyInfo(@NotNull(message = "数量不为空") Integer num) {
public List<DummyInfo> randCreateDummyInfo(@NotNull(message = "数量不允许为空") Integer num) {
if (num>1000){
num=1000;
}

18
ds-biz/ds-miniapps/ds-miniapps-biz/src/main/resources/application.yml

@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
server:
port: 15101
spring:
application:
name: ds-mini-apps
cloud:
nacos:
server-addr: @nacosAddress@
username: nacos
password: nacos
discovery:
namespace: @nacosNamespace@
config:
file-extension: yml
namespace: @nacosNamespace@
config:
import:
- optional:nacos:${spring.application.name}.${spring.cloud.nacos.config.file-extension}

13
ds-biz/ds-miniapps/ds-miniapps-model/src/main/java/com/ds/miniapps/model/entity/dummyinfo/DummyInfo.java

@ -3,8 +3,7 @@ package com.ds.miniapps.model.entity.dummyinfo; @@ -3,8 +3,7 @@ package com.ds.miniapps.model.entity.dummyinfo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.ds.miniapps.model.enums.dummyinfo.TelecomOperatorsConvert;
import com.ds.miniapps.model.enums.dummyinfo.TelecomOperatorsEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
@ -12,20 +11,20 @@ import lombok.Data; @@ -12,20 +11,20 @@ import lombok.Data;
* @since 2023/8/27
*/
@Data
@ApiModel("假人信息类")
@Schema(name = "假人信息类")
public class DummyInfo {
@ApiModelProperty("姓名")
@Schema(name = "姓名")
private String name;
@ApiModelProperty("手机号")
@Schema(name = "手机号")
private String phone;
@ApiModelProperty("运营商信息")
@Schema(name = "运营商信息")
@ExcelProperty(converter = TelecomOperatorsConvert.class)
private TelecomOperatorsEnum telecomOperator;
@ApiModelProperty("性别")
@Schema(name = "性别")
private String sex;
}

18
ds-biz/pom.xml

@ -26,25 +26,15 @@ @@ -26,25 +26,15 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<groupId>com.ds.common.web.config</groupId>
<artifactId>ds-web-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>

58
ds-commons/ds-config/ds-web-config/pom.xml

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ds</groupId>
<artifactId>ds-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.ds.common.web.config</groupId>
<artifactId>ds-web-config</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!--注册中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--配置中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
</dependencies>
</project>

38
ds-commons/ds-config/ds-web-config/src/main/java/com/ds/commons/web/config/swagger/SwaggerConfig.java

@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
package com.ds.commons.web.config.swagger;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
/**
* @author ds
* @since 2023/8/28
*/
@Configuration
@Import(SwaggerYml.class)
public class SwaggerConfig {
private final SwaggerYml swaggerYml;
public SwaggerConfig(SwaggerYml swaggerYml) {
this.swaggerYml = swaggerYml;
}
private Info info(){
SwaggerYml.Contact contact = swaggerYml.getContact();
return new Info().title(swaggerYml.getTitle())
.termsOfService(swaggerYml.getServerUrl())
.description(swaggerYml.getDescription())
.contact(new Contact().url(contact.getUrl()).name(contact.getName()).email(contact.getEmail()))
.version(swaggerYml.getVersion());
}
@Bean
public OpenAPI openAPI() {
return new OpenAPI().info(info());
}
}

44
ds-commons/ds-config/ds-web-config/src/main/java/com/ds/commons/web/config/swagger/SwaggerYml.java

@ -0,0 +1,44 @@ @@ -0,0 +1,44 @@
package com.ds.commons.web.config.swagger;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author ds
* @since 2023/8/28
*/
@Data
@Component
@ConfigurationProperties(prefix = "swagger")
public class SwaggerYml {
private String version;
private String title;
private String description;
private String serverUrl;
private Contact contact;
@Data
public static class Contact{
private String url;
private String email;
private String name;
}
public SwaggerYml getInstance(){
return this;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}

24
ds-commons/ds-config/pom.xml

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.ds</groupId>
<artifactId>ds-commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ds-config</artifactId>
<packaging>pom</packaging>
<modules>
<module>ds-web-config</module>
</modules>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

1
ds-commons/pom.xml

@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
<modules>
<module>ds-utils</module>
<module>ds-basemodel</module>
<module>ds-config</module>
</modules>
<properties>

21
pom.xml

@ -26,9 +26,8 @@ @@ -26,9 +26,8 @@
<spring.boot.version>3.1.0</spring.boot.version>
<spring.cloud.version>2022.0.2</spring.cloud.version>
<spring.cloud.alibaba.version>2022.0.0.0-RC2</spring.cloud.alibaba.version>
<knife4j.version>3.0.3</knife4j.version>
<swagger-bootstrap-ui.version>1.8.5</swagger-bootstrap-ui.version>
<springfox.version>3.0.0</springfox.version>
<springdoc.version>2.1.0</springdoc.version>
<knife4j.version>4.3.0</knife4j.version>
</properties>
<dependencyManagement>
@ -55,19 +54,19 @@ @@ -55,19 +54,19 @@
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${springfox.version}</version>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>swagger-bootstrap-ui</artifactId>
<version>${swagger-bootstrap-ui.version}</version>
<artifactId>knife4j-openapi3-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Loading…
Cancel
Save