升级spring-boot 2.4.12、wx-java 4.2.0、pom文件优化、swagger文档升级到3.0.0,邮费计算优化
This commit is contained in:
38
pom.xml
38
pom.xml
@ -28,20 +28,30 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.4.11</version>
|
<version>2.4.12</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<jedis.version>2.9.0</jedis.version>
|
<jedis.version>3.3.0</jedis.version>
|
||||||
<swagger.version>2.9.2</swagger.version>
|
<swagger.version>3.0.0</swagger.version>
|
||||||
<fastjson.version>1.2.78</fastjson.version>
|
<fastjson.version>1.2.78</fastjson.version>
|
||||||
<druid.version>1.2.6</druid.version>
|
<druid.version>1.2.6</druid.version>
|
||||||
<hutool.version>5.5.7</hutool.version>
|
<hutool.version>5.5.7</hutool.version>
|
||||||
|
<poi.version>4.1.2</poi.version>
|
||||||
<commons-pool2.version>2.5.0</commons-pool2.version>
|
<commons-pool2.version>2.5.0</commons-pool2.version>
|
||||||
<mapstruct.version>1.2.0.Final</mapstruct.version>
|
<mapstruct.version>1.2.0.Final</mapstruct.version>
|
||||||
|
<swagger-annotations.version>1.5.21</swagger-annotations.version>
|
||||||
|
<swagger-models.version>1.5.24</swagger-models.version>
|
||||||
|
<github-xiaoymin.version>3.0.3</github-xiaoymin.version>
|
||||||
|
<xerces.version>2.11.0</xerces.version>
|
||||||
|
<javax.version>1</javax.version>
|
||||||
|
<whvcse.version>1.6.2</whvcse.version>
|
||||||
|
<bitwalker.version>1.20</bitwalker.version>
|
||||||
|
<validator.version>6.1.6.Final</validator.version>
|
||||||
|
<gson.version>2.8.0</gson.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +69,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate.validator</groupId>
|
<groupId>org.hibernate.validator</groupId>
|
||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>hibernate-validator</artifactId>
|
||||||
<version>6.1.6.Final</version>
|
<version>${validator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -85,7 +95,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>redis.clients</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>${jedis.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Spring boot end-->
|
<!--Spring boot end-->
|
||||||
@ -125,18 +135,18 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
<artifactId>swagger-annotations</artifactId>
|
<artifactId>swagger-annotations</artifactId>
|
||||||
<version>1.5.21</version>
|
<version>${swagger-annotations.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger</groupId>
|
<groupId>io.swagger</groupId>
|
||||||
<artifactId>swagger-models</artifactId>
|
<artifactId>swagger-models</artifactId>
|
||||||
<version>1.5.21</version>
|
<version>${swagger-models.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--单应用-->
|
<!--单应用-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.xiaoymin</groupId>
|
<groupId>com.github.xiaoymin</groupId>
|
||||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||||
<version>2.0.1</version>
|
<version>${github-xiaoymin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--Mysql依赖包-->
|
<!--Mysql依赖包-->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -168,18 +178,18 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi</artifactId>
|
<artifactId>poi</artifactId>
|
||||||
<version>3.17</version>
|
<version>${poi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.poi</groupId>
|
<groupId>org.apache.poi</groupId>
|
||||||
<artifactId>poi-ooxml</artifactId>
|
<artifactId>poi-ooxml</artifactId>
|
||||||
<version>3.17</version>
|
<version>${poi.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
|
<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xerces</groupId>
|
<groupId>xerces</groupId>
|
||||||
<artifactId>xercesImpl</artifactId>
|
<artifactId>xercesImpl</artifactId>
|
||||||
<version>2.11.0</version>
|
<version>${xerces.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- fastjson -->
|
<!-- fastjson -->
|
||||||
@ -208,17 +218,17 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.whvcse</groupId>
|
<groupId>com.github.whvcse</groupId>
|
||||||
<artifactId>easy-captcha</artifactId>
|
<artifactId>easy-captcha</artifactId>
|
||||||
<version>1.6.2</version>
|
<version>${whvcse.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>eu.bitwalker</groupId>
|
<groupId>eu.bitwalker</groupId>
|
||||||
<artifactId>UserAgentUtils</artifactId>
|
<artifactId>UserAgentUtils</artifactId>
|
||||||
<version>1.20</version>
|
<version>${bitwalker.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<version>2.8.0</version>
|
<version>${gson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|||||||
@ -116,8 +116,8 @@ public class OnlineUserService {
|
|||||||
* @throws Exception /
|
* @throws Exception /
|
||||||
*/
|
*/
|
||||||
public void kickOutT(String key) throws Exception {
|
public void kickOutT(String key) throws Exception {
|
||||||
String[] split = StrUtil.split(key, ":");
|
String[] split = StrUtil.split(key, StrUtil.COLON);
|
||||||
String keyt = ShopConstants.YSHOP_APP_LOGIN_USER + split[0] + ":" + EncryptUtils.desDecrypt(split[1]);
|
String keyt = ShopConstants.YSHOP_APP_LOGIN_USER + split[0] + StrUtil.COLON + EncryptUtils.desDecrypt(split[1]);
|
||||||
redisUtils.del(keyt);
|
redisUtils.del(keyt);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ public class FilterConfig
|
|||||||
FilterRegistrationBean registration = new FilterRegistrationBean();
|
FilterRegistrationBean registration = new FilterRegistrationBean();
|
||||||
registration.setDispatcherTypes(DispatcherType.REQUEST);
|
registration.setDispatcherTypes(DispatcherType.REQUEST);
|
||||||
registration.setFilter(new XssFilter());
|
registration.setFilter(new XssFilter());
|
||||||
registration.addUrlPatterns(StrUtil.split(urlPatterns, ","));
|
registration.addUrlPatterns(StrUtil.split(urlPatterns, StrUtil.COMMA));
|
||||||
registration.setName("xssFilter");
|
registration.setName("xssFilter");
|
||||||
registration.setOrder(Integer.MAX_VALUE);
|
registration.setOrder(Integer.MAX_VALUE);
|
||||||
Map<String, String> initParameters = new HashMap<String, String>();
|
Map<String, String> initParameters = new HashMap<String, String>();
|
||||||
|
|||||||
@ -264,11 +264,7 @@ public class AuthService {
|
|||||||
.nickname(nickname)
|
.nickname(nickname)
|
||||||
.openid(wxMpUser.getOpenId())
|
.openid(wxMpUser.getOpenId())
|
||||||
.unionId(wxMpUser.getUnionId())
|
.unionId(wxMpUser.getUnionId())
|
||||||
.sex(wxMpUser.getSex())
|
|
||||||
.language(wxMpUser.getLanguage())
|
.language(wxMpUser.getLanguage())
|
||||||
.city(wxMpUser.getCity())
|
|
||||||
.province(wxMpUser.getProvince())
|
|
||||||
.country(wxMpUser.getCountry())
|
|
||||||
.headimgurl(wxMpUser.getHeadImgUrl())
|
.headimgurl(wxMpUser.getHeadImgUrl())
|
||||||
.subscribe(wxMpUser.getSubscribe())
|
.subscribe(wxMpUser.getSubscribe())
|
||||||
.subscribeTime(wxMpUser.getSubscribeTime())
|
.subscribeTime(wxMpUser.getSubscribeTime())
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
<artifactId>yshop-common</artifactId>
|
<artifactId>yshop-common</artifactId>
|
||||||
<name>公共模块</name>
|
<name>公共模块</name>
|
||||||
<properties>
|
<properties>
|
||||||
<weixin-java.version>4.1.0</weixin-java.version>
|
<weixin-java.version>4.2.0</weixin-java.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -84,7 +84,7 @@ public class SwaggerConfig {
|
|||||||
.apiInfo(apiInfo())
|
.apiInfo(apiInfo())
|
||||||
.select()
|
.select()
|
||||||
.apis(RequestHandlerSelectors.basePackage("co.yixiang.modules"))
|
.apis(RequestHandlerSelectors.basePackage("co.yixiang.modules"))
|
||||||
.paths(Predicates.not(PathSelectors.regex("/error.*")))
|
.paths(PathSelectors.regex("/error.*").negate())
|
||||||
.build()
|
.build()
|
||||||
.globalOperationParameters(pars);
|
.globalOperationParameters(pars);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,426 +0,0 @@
|
|||||||
package com.github.xiaoymin.knife4j.spring.web;
|
|
||||||
|
|
||||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSort;
|
|
||||||
import com.github.xiaoymin.knife4j.annotations.ApiSort;
|
|
||||||
import com.github.xiaoymin.knife4j.spring.common.SwaggerBootstrapUiHostNameProvider;
|
|
||||||
import com.github.xiaoymin.knife4j.spring.model.MarkdownFiles;
|
|
||||||
import com.github.xiaoymin.knife4j.spring.model.RestHandlerMapping;
|
|
||||||
import com.github.xiaoymin.knife4j.spring.model.SwaggerBootstrapUi;
|
|
||||||
import com.github.xiaoymin.knife4j.spring.model.SwaggerBootstrapUiPath;
|
|
||||||
import com.github.xiaoymin.knife4j.spring.model.SwaggerBootstrapUiTag;
|
|
||||||
import com.github.xiaoymin.knife4j.spring.model.SwaggerExt;
|
|
||||||
import com.github.xiaoymin.knife4j.spring.util.SwaggerUtil;
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import com.google.common.collect.FluentIterable;
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import io.swagger.models.Model;
|
|
||||||
import io.swagger.models.Swagger;
|
|
||||||
import io.swagger.models.properties.Property;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
|
||||||
import org.springframework.web.method.HandlerMethod;
|
|
||||||
import org.springframework.web.servlet.HandlerMapping;
|
|
||||||
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
|
|
||||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
|
||||||
import org.springframework.web.util.UriComponents;
|
|
||||||
import springfox.documentation.RequestHandler;
|
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
import springfox.documentation.service.Documentation;
|
|
||||||
import springfox.documentation.service.Tag;
|
|
||||||
import springfox.documentation.spi.service.RequestHandlerProvider;
|
|
||||||
import springfox.documentation.spring.web.DocumentationCache;
|
|
||||||
import springfox.documentation.spring.web.WebMvcRequestHandler;
|
|
||||||
import springfox.documentation.spring.web.json.Json;
|
|
||||||
import springfox.documentation.spring.web.json.JsonSerializer;
|
|
||||||
import springfox.documentation.swagger.common.HostNameProvider;
|
|
||||||
import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author LionCitys
|
|
||||||
*/
|
|
||||||
@Controller
|
|
||||||
@ApiIgnore
|
|
||||||
public class Knife4jController {
|
|
||||||
private static final String DEFAULT_SORT_URL = "/v2/api-docs-ext";
|
|
||||||
private static final String HAL_MEDIA_TYPE = "application/hal+json";
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Knife4jController.class);
|
|
||||||
private final ServiceModelToSwagger2Mapper mapper;
|
|
||||||
private final DocumentationCache documentationCache;
|
|
||||||
private final JsonSerializer jsonSerializer;
|
|
||||||
private final String hostNameOverride;
|
|
||||||
private final List<RequestHandlerProvider> handlerProviders;
|
|
||||||
private final MarkdownFiles markdownFiles;
|
|
||||||
private ArrayList<RestHandlerMapping> globalHandlerMappings = new ArrayList<>();
|
|
||||||
private final RequestMethod[] globalRequestMethods;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public Knife4jController(Environment environment, ServiceModelToSwagger2Mapper mapper, DocumentationCache documentationCache, JsonSerializer jsonSerializer, List<RequestHandlerProvider> handlerProviders, ObjectProvider<MarkdownFiles> markdownFilesObjectProvider) {
|
|
||||||
this.globalRequestMethods = new RequestMethod[]{RequestMethod.POST, RequestMethod.GET, RequestMethod.PUT, RequestMethod.DELETE, RequestMethod.PATCH, RequestMethod.OPTIONS, RequestMethod.HEAD};
|
|
||||||
this.mapper = mapper;
|
|
||||||
this.documentationCache = documentationCache;
|
|
||||||
this.jsonSerializer = jsonSerializer;
|
|
||||||
this.hostNameOverride = environment.getProperty("springfox.documentation.swagger.v2.host", "DEFAULT");
|
|
||||||
this.handlerProviders = handlerProviders;
|
|
||||||
this.markdownFiles = markdownFilesObjectProvider.getIfAvailable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Function<RequestHandlerProvider, ? extends Iterable<RequestHandler>> handlers() {
|
|
||||||
return (Function<RequestHandlerProvider, Iterable<RequestHandler>>) input -> input.requestHandlers();
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(value = DEFAULT_SORT_URL,
|
|
||||||
method = RequestMethod.GET,
|
|
||||||
produces = {APPLICATION_JSON_VALUE, HAL_MEDIA_TYPE})
|
|
||||||
@ResponseBody
|
|
||||||
public ResponseEntity<Json> apiSorts(@RequestParam(value = "group",required = false) String swaggerGroup, HttpServletRequest request) {
|
|
||||||
String groupName = Optional.ofNullable(swaggerGroup).orElse("default");
|
|
||||||
Documentation documentation = this.documentationCache.documentationByGroup(groupName);
|
|
||||||
if (documentation == null) {
|
|
||||||
LOGGER.warn("Unable to find specification for group {},use default", groupName);
|
|
||||||
documentation = this.documentationCache.documentationByGroup("default");
|
|
||||||
if (documentation == null) {
|
|
||||||
LOGGER.warn("Unable to find specification for group default");
|
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Swagger swagger = this.mapper.mapDocumentation(documentation);
|
|
||||||
UriComponents uriComponents = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
uriComponents = HostNameProvider.componentsFrom(request, swagger.getBasePath());
|
|
||||||
} catch (Throwable var9) {
|
|
||||||
LOGGER.error(var9.getClass().getName() + ":" + var9.getMessage());
|
|
||||||
if (var9 instanceof NoClassDefFoundError) {
|
|
||||||
String msg = var9.getMessage();
|
|
||||||
if (msg != null && !"".equals(msg) && msg.endsWith("HostNameProvider")) {
|
|
||||||
uriComponents = SwaggerBootstrapUiHostNameProvider.componentsFrom(request, swagger.getBasePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
swagger.basePath(Strings.isNullOrEmpty(uriComponents.getPath()) ? "/" : uriComponents.getPath());
|
|
||||||
if (Strings.isNullOrEmpty(swagger.getHost())) {
|
|
||||||
swagger.host(this.hostName(uriComponents));
|
|
||||||
}
|
|
||||||
extend(swagger);
|
|
||||||
SwaggerExt swaggerExt = new SwaggerExt(swagger);
|
|
||||||
swaggerExt.setSwaggerBootstrapUi(this.initSwaggerBootstrapUi(request, documentation, swaggerExt));
|
|
||||||
return new ResponseEntity<>(this.jsonSerializer.toJson(swaggerExt), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
private SwaggerBootstrapUi initSwaggerBootstrapUi(HttpServletRequest request, Documentation documentation, SwaggerExt swaggerExt) {
|
|
||||||
SwaggerBootstrapUi swaggerBootstrapUi = new SwaggerBootstrapUi();
|
|
||||||
WebApplicationContext wc = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
|
|
||||||
if (wc == null) {
|
|
||||||
String msg = "WebApplicationContext is Empty~!,Enable SwaggerBootstrapUi fun fail~!";
|
|
||||||
LOGGER.warn(msg);
|
|
||||||
swaggerBootstrapUi.setErrorMsg(msg);
|
|
||||||
return swaggerBootstrapUi;
|
|
||||||
} else {
|
|
||||||
Iterator<Tag> tags = documentation.getTags().iterator();
|
|
||||||
this.initGlobalRequestMappingArray(swaggerExt);
|
|
||||||
List<SwaggerBootstrapUiTag> targetTagLists = Lists.newArrayList();
|
|
||||||
|
|
||||||
ArrayList targetPathLists;
|
|
||||||
SwaggerBootstrapUiTag tag;
|
|
||||||
label64:
|
|
||||||
for(targetPathLists = Lists.newArrayList(); tags.hasNext(); targetTagLists.add(tag)) {
|
|
||||||
Tag sourceTag = tags.next();
|
|
||||||
String tagName = sourceTag.getName();
|
|
||||||
int order = 2147483647;
|
|
||||||
tag = new SwaggerBootstrapUiTag(order);
|
|
||||||
tag.name(tagName).description(sourceTag.getDescription());
|
|
||||||
Api tagApi = null;
|
|
||||||
RestHandlerMapping tagMapping = null;
|
|
||||||
Iterator<RestHandlerMapping> var15 = this.globalHandlerMappings.iterator();
|
|
||||||
while(true) {
|
|
||||||
while(true) {
|
|
||||||
while(var15.hasNext()) {
|
|
||||||
RestHandlerMapping rhm = var15.next();
|
|
||||||
Api api = (Api)rhm.getBeanType().getAnnotation(Api.class);
|
|
||||||
if (api != null) {
|
|
||||||
api.tags();
|
|
||||||
if (api.tags().length > 0) {
|
|
||||||
if (Lists.newArrayList(api.tags()).contains(tagName)) {
|
|
||||||
tagApi = api;
|
|
||||||
tagMapping = rhm;
|
|
||||||
this.createPathInstance(rhm, targetPathLists);
|
|
||||||
} else {
|
|
||||||
String firstTag = api.tags()[0];
|
|
||||||
if (StringUtils.isEmpty(firstTag) && this.checkExists(tagName, rhm.getBeanType())) {
|
|
||||||
tagApi = api;
|
|
||||||
tagMapping = rhm;
|
|
||||||
this.createPathInstance(rhm, targetPathLists);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (this.checkExists(tagName, rhm.getBeanType())) {
|
|
||||||
if (!StringUtils.isEmpty(api.value())) {
|
|
||||||
tag.name(api.value());
|
|
||||||
}
|
|
||||||
tagApi = api;
|
|
||||||
tagMapping = rhm;
|
|
||||||
this.createPathInstance(rhm, targetPathLists);
|
|
||||||
}
|
|
||||||
} else if (this.checkExists(tagName, rhm.getBeanType())) {
|
|
||||||
tagMapping = rhm;
|
|
||||||
this.createPathInstance(rhm, targetPathLists);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tagMapping != null) {
|
|
||||||
tag.setOrder(this.getRestTagOrder(tagMapping.getBeanType(), tagApi));
|
|
||||||
}
|
|
||||||
continue label64;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(targetTagLists, new Comparator<SwaggerBootstrapUiTag>() {
|
|
||||||
@Override
|
|
||||||
public int compare(SwaggerBootstrapUiTag o1, SwaggerBootstrapUiTag o2) {
|
|
||||||
return o1.getOrder().compareTo(o2.getOrder());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
targetPathLists.sort(new Comparator<SwaggerBootstrapUiPath>() {
|
|
||||||
@Override
|
|
||||||
public int compare(SwaggerBootstrapUiPath o1, SwaggerBootstrapUiPath o2) {
|
|
||||||
return o1.getOrder().compareTo(o2.getOrder());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
swaggerBootstrapUi.setTagSortLists(targetTagLists);
|
|
||||||
swaggerBootstrapUi.setPathSortLists(targetPathLists);
|
|
||||||
if (this.markdownFiles != null) {
|
|
||||||
swaggerBootstrapUi.setMarkdownFiles(this.markdownFiles.getMarkdownFiles());
|
|
||||||
}
|
|
||||||
|
|
||||||
return swaggerBootstrapUi;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initGlobalRequestMappingArray(SwaggerExt swaggerExt) {
|
|
||||||
if (this.globalHandlerMappings.size() == 0) {
|
|
||||||
String parentPath = "";
|
|
||||||
if (!StringUtils.isEmpty(swaggerExt.getBasePath()) && !"/".equals(swaggerExt.getBasePath())) {
|
|
||||||
parentPath = parentPath + swaggerExt.getBasePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
List<RequestHandler> requestHandlers = FluentIterable.from(this.handlerProviders).transformAndConcat(this.handlers()).toList();
|
|
||||||
Iterator<RequestHandler> var4 = requestHandlers.iterator();
|
|
||||||
|
|
||||||
while(true) {
|
|
||||||
RequestHandler requestHandler;
|
|
||||||
do {
|
|
||||||
if (!var4.hasNext()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
requestHandler = var4.next();
|
|
||||||
} while(!(requestHandler instanceof WebMvcRequestHandler));
|
|
||||||
|
|
||||||
WebMvcRequestHandler webMvcRequestHandler = (WebMvcRequestHandler)requestHandler;
|
|
||||||
Set<String> patterns = webMvcRequestHandler.getRequestMapping().getPatternsCondition().getPatterns();
|
|
||||||
Set<RequestMethod> restMethods = webMvcRequestHandler.getRequestMapping().getMethodsCondition().getMethods();
|
|
||||||
HandlerMethod handlerMethod = webMvcRequestHandler.getHandlerMethod();
|
|
||||||
Class<?> controllerClazz = ClassUtils.getUserClass(handlerMethod.getBeanType());
|
|
||||||
Method method = ClassUtils.getMostSpecificMethod(handlerMethod.getMethod(), controllerClazz);
|
|
||||||
|
|
||||||
String url;
|
|
||||||
for(Iterator<String> var12 = patterns.iterator(); var12.hasNext(); this.globalHandlerMappings.add(new RestHandlerMapping(parentPath + url, controllerClazz, method, restMethods))) {
|
|
||||||
url = var12.next();
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("url:" + url + "\r\nclass:" + controllerClazz.toString() + "\r\nmethod:" + method.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception var14) {
|
|
||||||
LOGGER.error(var14.getMessage(), var14);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @deprecated */
|
|
||||||
@Deprecated
|
|
||||||
private void initGlobalRequestMappingArray(WebApplicationContext wc, SwaggerExt swaggerExt) {
|
|
||||||
if (this.globalHandlerMappings.size() == 0) {
|
|
||||||
String parentPath = "";
|
|
||||||
if (!StringUtils.isEmpty(swaggerExt.getBasePath()) && !"/".equals(swaggerExt.getBasePath())) {
|
|
||||||
parentPath = parentPath + swaggerExt.getBasePath();
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, HandlerMapping> requestMappings = BeanFactoryUtils.beansOfTypeIncludingAncestors(wc, HandlerMapping.class, true, false);
|
|
||||||
Iterator<HandlerMapping> var5 = requestMappings.values().iterator();
|
|
||||||
|
|
||||||
while(true) {
|
|
||||||
HandlerMapping handlerMapping;
|
|
||||||
do {
|
|
||||||
if (!var5.hasNext()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handlerMapping = var5.next();
|
|
||||||
} while(!(handlerMapping instanceof RequestMappingHandlerMapping));
|
|
||||||
RequestMappingHandlerMapping rmhMapping = (RequestMappingHandlerMapping)handlerMapping;
|
|
||||||
Map<RequestMappingInfo, HandlerMethod> handlerMethods = rmhMapping.getHandlerMethods();
|
|
||||||
for (RequestMappingInfo rmi : handlerMethods.keySet()) {
|
|
||||||
PatternsRequestCondition prc = rmi.getPatternsCondition();
|
|
||||||
Set<RequestMethod> restMethods = rmi.getMethodsCondition().getMethods();
|
|
||||||
Set<String> patterns = prc.getPatterns();
|
|
||||||
HandlerMethod handlerMethod = (HandlerMethod) handlerMethods.get(rmi);
|
|
||||||
|
|
||||||
String url;
|
|
||||||
Class clazz;
|
|
||||||
Method method;
|
|
||||||
for (Iterator<String> var15 = patterns.iterator(); var15.hasNext(); this.globalHandlerMappings.add(new RestHandlerMapping(parentPath + url, clazz, method, restMethods))) {
|
|
||||||
url = var15.next();
|
|
||||||
clazz = ClassUtils.getUserClass(handlerMethod.getBeanType());
|
|
||||||
method = ClassUtils.getMostSpecificMethod(handlerMethod.getMethod(), clazz);
|
|
||||||
if (LOGGER.isDebugEnabled()) {
|
|
||||||
LOGGER.debug("url:" + url + "\r\nclass:" + clazz.toString() + "\r\nmethod:" + method.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createPathInstance(RestHandlerMapping rhm, List<SwaggerBootstrapUiPath> targetPathLists) {
|
|
||||||
if (rhm.getRequestMethods() != null && rhm.getRequestMethods().size() != 0) {
|
|
||||||
Iterator<RequestMethod> var7 = rhm.getRequestMethods().iterator();
|
|
||||||
|
|
||||||
while(var7.hasNext()) {
|
|
||||||
RequestMethod requestMethod = var7.next();
|
|
||||||
targetPathLists.add(new SwaggerBootstrapUiPath(rhm.getUrl(), requestMethod.name().toUpperCase(), this.getRestMethodOrder(rhm.getBeanOfMethod())));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
RequestMethod[] var3 = this.globalRequestMethods;
|
|
||||||
int var4 = var3.length;
|
|
||||||
|
|
||||||
for(int var5 = 0; var5 < var4; ++var5) {
|
|
||||||
RequestMethod requestMethod = var3[var5];
|
|
||||||
targetPathLists.add(new SwaggerBootstrapUiPath(rhm.getUrl(), requestMethod.name().toUpperCase(), this.getRestMethodOrder(rhm.getBeanOfMethod())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getRestTagOrder(Class<?> aClass, Api api) {
|
|
||||||
int order = 2147483647;
|
|
||||||
if (api != null) {
|
|
||||||
int post = api.position();
|
|
||||||
if (post == 0) {
|
|
||||||
if (aClass != null) {
|
|
||||||
ApiSort annotation = (ApiSort) ClassUtils.getUserClass(aClass).getAnnotation(ApiSort.class);
|
|
||||||
if (annotation != null) {
|
|
||||||
order = annotation.value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
order = post;
|
|
||||||
}
|
|
||||||
} else if (aClass != null) {
|
|
||||||
ApiSort annotation = (ApiSort) ClassUtils.getUserClass(aClass).getAnnotation(ApiSort.class);
|
|
||||||
if (annotation != null) {
|
|
||||||
order = annotation.value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getRestMethodOrder(Method target) {
|
|
||||||
int pathOrder = 2147483647;
|
|
||||||
ApiOperation apiOperation = (ApiOperation)target.getAnnotation(ApiOperation.class);
|
|
||||||
ApiOperationSort apiOperationSort;
|
|
||||||
if (apiOperation != null) {
|
|
||||||
if (apiOperation.position() != 0) {
|
|
||||||
pathOrder = apiOperation.position();
|
|
||||||
} else {
|
|
||||||
apiOperationSort = (ApiOperationSort)target.getAnnotation(ApiOperationSort.class);
|
|
||||||
if (apiOperationSort != null) {
|
|
||||||
pathOrder = apiOperationSort.value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
apiOperationSort = (ApiOperationSort)target.getAnnotation(ApiOperationSort.class);
|
|
||||||
if (apiOperationSort != null) {
|
|
||||||
pathOrder = apiOperationSort.value();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pathOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkExists(String tagName, Class<?> aClass) {
|
|
||||||
boolean flag = false;
|
|
||||||
if (!StringUtils.isEmpty(tagName)) {
|
|
||||||
String regexStr = tagName.replaceAll("-", ".*?");
|
|
||||||
Pattern pattern = Pattern.compile(regexStr, 2);
|
|
||||||
if (pattern.matcher(aClass.getSimpleName()).matches()) {
|
|
||||||
flag = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String hostName(UriComponents uriComponents) {
|
|
||||||
if ("DEFAULT".equals(hostNameOverride)) {
|
|
||||||
String host = uriComponents.getHost();
|
|
||||||
int port = uriComponents.getPort();
|
|
||||||
if (port > -1) {
|
|
||||||
return String.format("%s:%d", host, port);
|
|
||||||
}
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
return hostNameOverride;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void extend(Swagger swagger) {
|
|
||||||
// 响应返回参数增强
|
|
||||||
for (Map.Entry<String, Model> entry : swagger.getDefinitions().entrySet()) {
|
|
||||||
Model model = entry.getValue();
|
|
||||||
String key = entry.getKey();
|
|
||||||
if (key.contains("ApiResult") && !SwaggerUtil.getRealType(key).contains("ApiResult")) {
|
|
||||||
Map<String, Property> props = model.getProperties();
|
|
||||||
Property dataProp = props.get("data");
|
|
||||||
Property newProp = SwaggerUtil.getNewProp(dataProp, SwaggerUtil.getRealType(key), swagger.getDefinitions());
|
|
||||||
props.put("data", newProp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,117 +0,0 @@
|
|||||||
package springfox.documentation.swagger2.web;
|
|
||||||
|
|
||||||
import com.github.xiaoymin.knife4j.spring.util.SwaggerUtil;
|
|
||||||
import com.google.common.base.Strings;
|
|
||||||
import io.swagger.models.Model;
|
|
||||||
import io.swagger.models.Swagger;
|
|
||||||
import io.swagger.models.properties.Property;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.util.UriComponents;
|
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
import springfox.documentation.service.Documentation;
|
|
||||||
import springfox.documentation.spring.web.DocumentationCache;
|
|
||||||
import springfox.documentation.spring.web.PropertySourcedMapping;
|
|
||||||
import springfox.documentation.spring.web.json.JsonSerializer;
|
|
||||||
import springfox.documentation.swagger.common.HostNameProvider;
|
|
||||||
import springfox.documentation.swagger2.mappers.ServiceModelToSwagger2Mapper;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Swagger2控制器
|
|
||||||
*
|
|
||||||
* @author LionCitys
|
|
||||||
* @date 2020/01/07
|
|
||||||
*/
|
|
||||||
@Controller
|
|
||||||
@ApiIgnore
|
|
||||||
public class Swagger2Controller {
|
|
||||||
private static final String DEFAULT_URL = "/v2/api-docs";
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Swagger2Controller.class);
|
|
||||||
private static final String HAL_MEDIA_TYPE = "application/hal+json";
|
|
||||||
private final String hostNameOverride;
|
|
||||||
private final DocumentationCache documentationCache;
|
|
||||||
private final ServiceModelToSwagger2Mapper mapper;
|
|
||||||
private final JsonSerializer jsonSerializer;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public Swagger2Controller(Environment environment, DocumentationCache documentationCache, ServiceModelToSwagger2Mapper mapper, JsonSerializer jsonSerializer) {
|
|
||||||
this.hostNameOverride = environment.getProperty("springfox.documentation.swagger.v2.host", "DEFAULT");
|
|
||||||
this.documentationCache = documentationCache;
|
|
||||||
this.mapper = mapper;
|
|
||||||
this.jsonSerializer = jsonSerializer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping(
|
|
||||||
value = {DEFAULT_URL},
|
|
||||||
method = {RequestMethod.GET},
|
|
||||||
produces = {APPLICATION_JSON_VALUE, HAL_MEDIA_TYPE}
|
|
||||||
)
|
|
||||||
@PropertySourcedMapping(
|
|
||||||
value = "${springfox.documentation.swagger.v2.path}",
|
|
||||||
propertyKey = "springfox.documentation.swagger.v2.path"
|
|
||||||
)
|
|
||||||
@ResponseBody
|
|
||||||
public ResponseEntity getDocumentation(@RequestParam(value = "group",required = false) String swaggerGroup, HttpServletRequest servletRequest) {
|
|
||||||
String groupName = (String) Optional.ofNullable(swaggerGroup).orElse("default");
|
|
||||||
Documentation documentation = this.documentationCache.documentationByGroup(groupName);
|
|
||||||
if (documentation == null) {
|
|
||||||
LOGGER.warn("Unable to find specification for group {}", groupName);
|
|
||||||
return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
||||||
} else {
|
|
||||||
Swagger swagger = this.mapper.mapDocumentation(documentation);
|
|
||||||
UriComponents uriComponents = HostNameProvider.componentsFrom(servletRequest, swagger.getBasePath());
|
|
||||||
swagger.basePath(Strings.isNullOrEmpty(uriComponents.getPath()) ? "/" : uriComponents.getPath());
|
|
||||||
if (Strings.isNullOrEmpty(swagger.getHost())) {
|
|
||||||
swagger.host(this.hostName(uriComponents));
|
|
||||||
}
|
|
||||||
// 扩展
|
|
||||||
swagger = extend(swagger);
|
|
||||||
|
|
||||||
return new ResponseEntity(this.jsonSerializer.toJson(swagger), HttpStatus.OK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String hostName(UriComponents uriComponents) {
|
|
||||||
return getString(uriComponents, this.hostNameOverride);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getString(UriComponents uriComponents, String hostNameOverride) {
|
|
||||||
if ("DEFAULT".equals(hostNameOverride)) {
|
|
||||||
String host = uriComponents.getHost();
|
|
||||||
int port = uriComponents.getPort();
|
|
||||||
return port > -1 ? String.format("%s:%d", host, port) : host;
|
|
||||||
} else {
|
|
||||||
return hostNameOverride;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Swagger extend(Swagger swagger) {
|
|
||||||
// 响应返回参数增强
|
|
||||||
for (Map.Entry<String, Model> entry : swagger.getDefinitions().entrySet()) {
|
|
||||||
Model model = entry.getValue();
|
|
||||||
String key = entry.getKey();
|
|
||||||
if (key.contains("ApiResult") && !SwaggerUtil.getRealType(key).contains("ApiResult")) {
|
|
||||||
Map<String, Property> props = model.getProperties();
|
|
||||||
Property dataProp = props.get("data");
|
|
||||||
Property newProp = SwaggerUtil.getNewProp(dataProp, SwaggerUtil.getRealType(key), swagger.getDefinitions());
|
|
||||||
props.put("data", newProp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return swagger;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2055,7 +2055,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
|||||||
}
|
}
|
||||||
|
|
||||||
//处理包邮情况
|
//处理包邮情况
|
||||||
for (Map.Entry<Integer, TemplateDto> entry : templateDTOMap.entrySet()) {
|
jj: for (Map.Entry<Integer, TemplateDto> entry : templateDTOMap.entrySet()) {
|
||||||
Integer mapKey = entry.getKey();
|
Integer mapKey = entry.getKey();
|
||||||
TemplateDto mapValue = entry.getValue();
|
TemplateDto mapValue = entry.getValue();
|
||||||
|
|
||||||
@ -2067,6 +2067,7 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
|||||||
//满足包邮条件剔除
|
//满足包邮条件剔除
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
templateDTOMap.remove(mapKey);
|
templateDTOMap.remove(mapKey);
|
||||||
|
break jj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2079,17 +2080,17 @@ public class YxStoreOrderServiceImpl extends BaseServiceImpl<StoreOrderMapper, Y
|
|||||||
storePostage = NumberUtil.round(NumberUtil.add(storePostage,
|
storePostage = NumberUtil.round(NumberUtil.add(storePostage,
|
||||||
templateDTO.getFirstPrice()), 2);
|
templateDTO.getFirstPrice()), 2);
|
||||||
} else {
|
} else {
|
||||||
BigDecimal fristPrice = NumberUtil.add(storePostage, templateDTO.getFirstPrice());
|
BigDecimal firstPrice = NumberUtil.add(storePostage, templateDTO.getFirstPrice());
|
||||||
|
|
||||||
if (templateDTO.get_continue() <= 0) {
|
if (templateDTO.get_continue() <= 0) {
|
||||||
storePostage = fristPrice;
|
storePostage = firstPrice;
|
||||||
} else {
|
} else {
|
||||||
//续件平均值且向上取整数
|
//续件平均值且向上取整数
|
||||||
double average = Math.ceil(NumberUtil.div(NumberUtil.sub(templateDTO.getNumber(),
|
double average = Math.ceil(NumberUtil.div(NumberUtil.sub(templateDTO.getNumber(),
|
||||||
templateDTO.getFirst()),
|
templateDTO.getFirst()),
|
||||||
templateDTO.get_continue().doubleValue()));
|
templateDTO.get_continue().doubleValue()));
|
||||||
//最终邮费
|
//最终邮费
|
||||||
storePostage = NumberUtil.add(fristPrice, NumberUtil.mul(average,
|
storePostage = NumberUtil.add(firstPrice, NumberUtil.mul(average,
|
||||||
templateDTO.getContinuePrice()));
|
templateDTO.getContinuePrice()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user