From 4f62d30d1284f665e2aae54a3e7119438c0ef11e Mon Sep 17 00:00:00 2001 From: WenG <450292408@qq.com> Date: Sat, 8 May 2021 14:12:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B7=AF=E7=94=B1=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/dao/routetype/IRouteTypeDao.java | 20 ++ .../gateway/handler/route/RouteHandler.java | 19 +- .../handler/routetype/RouteTypeHandler.java | 103 ++++++++ .../java/ink/wgink/gateway/pojo/BasePOJO.java | 42 +++- .../ink/wgink/gateway/pojo/route/Route.java | 43 +++- .../gateway/pojo/routetype/RouteType.java | 44 ++++ .../router/routetype/RouteTypeRouter.java | 34 +++ src/main/resources/static/wg/index.html | 17 +- .../static/wg/route/route-type/list.html | 226 ++++++++++++++++++ .../static/wg/route/route-type/save.html | 102 ++++++++ .../static/wg/route/route-type/update.html | 117 +++++++++ .../resources/static/wg/route/route/list.html | 6 +- 12 files changed, 748 insertions(+), 25 deletions(-) create mode 100644 src/main/java/ink/wgink/gateway/dao/routetype/IRouteTypeDao.java create mode 100644 src/main/java/ink/wgink/gateway/handler/routetype/RouteTypeHandler.java create mode 100644 src/main/java/ink/wgink/gateway/pojo/routetype/RouteType.java create mode 100644 src/main/java/ink/wgink/gateway/router/routetype/RouteTypeRouter.java create mode 100644 src/main/resources/static/wg/route/route-type/list.html create mode 100644 src/main/resources/static/wg/route/route-type/save.html create mode 100644 src/main/resources/static/wg/route/route-type/update.html diff --git a/src/main/java/ink/wgink/gateway/dao/routetype/IRouteTypeDao.java b/src/main/java/ink/wgink/gateway/dao/routetype/IRouteTypeDao.java new file mode 100644 index 0000000..065d927 --- /dev/null +++ b/src/main/java/ink/wgink/gateway/dao/routetype/IRouteTypeDao.java @@ -0,0 +1,20 @@ +package ink.wgink.gateway.dao.routetype; + +import ink.wgink.gateway.pojo.routetype.RouteType; +import org.springframework.data.mongodb.repository.ReactiveMongoRepository; +import org.springframework.stereotype.Repository; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IRouteTypeDao + * @Description: 路由类型 + * @Author: WangGeng + * @Date: 2021/5/8 12:10 + * @Version: 1.0 + **/ +@Repository +public interface IRouteTypeDao extends ReactiveMongoRepository { + String COLLECTION_NAME = "sys_route_type"; +} diff --git a/src/main/java/ink/wgink/gateway/handler/route/RouteHandler.java b/src/main/java/ink/wgink/gateway/handler/route/RouteHandler.java index e1a4409..c295d92 100644 --- a/src/main/java/ink/wgink/gateway/handler/route/RouteHandler.java +++ b/src/main/java/ink/wgink/gateway/handler/route/RouteHandler.java @@ -7,29 +7,21 @@ import ink.wgink.gateway.handler.BaseHandler; import ink.wgink.gateway.pojo.result.SuccessResult; import ink.wgink.gateway.pojo.route.Route; import ink.wgink.gateway.util.RequestFieldCheckUtil; -import ink.wgink.gateway.util.UUIDUtil; -import org.apache.commons.lang3.StringUtils; import org.springframework.cloud.gateway.event.RefreshRoutesEvent; -import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition; -import org.springframework.cloud.gateway.route.RouteDefinition; -import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; -import org.springframework.core.annotation.Order; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher; -import org.springframework.data.domain.Page; import org.springframework.http.MediaType; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; -import org.springframework.web.util.UriComponentsBuilder; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.util.*; -import java.util.concurrent.TimeUnit; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; /** * When you feel like quitting. Think about why you started @@ -124,8 +116,9 @@ public class RouteHandler extends BaseHandler implements ApplicationEventPublish Route route = new Route(); Example example = Example.of(route); if (keywords.isPresent()) { - route.setTitle(keywords.get()); - route.setSummary(keywords.get()); + String keywordTrim = keywords.get().trim(); + route.setTitle(keywordTrim); + route.setSummary(keywordTrim); ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny() .withMatcher("title", ExampleMatcher.GenericPropertyMatcher::contains) diff --git a/src/main/java/ink/wgink/gateway/handler/routetype/RouteTypeHandler.java b/src/main/java/ink/wgink/gateway/handler/routetype/RouteTypeHandler.java new file mode 100644 index 0000000..da49d1f --- /dev/null +++ b/src/main/java/ink/wgink/gateway/handler/routetype/RouteTypeHandler.java @@ -0,0 +1,103 @@ +package ink.wgink.gateway.handler.routetype; + +import ink.wgink.gateway.consts.ISystemConst; +import ink.wgink.gateway.dao.routetype.IRouteTypeDao; +import ink.wgink.gateway.exception.ParamsException; +import ink.wgink.gateway.exception.SearchException; +import ink.wgink.gateway.handler.BaseHandler; +import ink.wgink.gateway.pojo.result.SuccessResult; +import ink.wgink.gateway.pojo.route.Route; +import ink.wgink.gateway.pojo.routetype.RouteType; +import ink.wgink.gateway.util.RequestFieldCheckUtil; +import org.springframework.data.domain.Example; +import org.springframework.data.domain.ExampleMatcher; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: RouteTypeHandler + * @Description: 路由类型 + * @Author: WangGeng + * @Date: 2021/5/8 12:09 + * @Version: 1.0 + **/ +@Service +public class RouteTypeHandler extends BaseHandler { + + private IRouteTypeDao routeTypeDao; + + public RouteTypeHandler(IRouteTypeDao routeTypeDao) { + this.routeTypeDao = routeTypeDao; + } + + /** + * 保存 + * + * @param serverRequest + * @return + */ + public Mono save(ServerRequest serverRequest) { + Mono routeTypeMono = serverRequest.bodyToMono(RouteType.class); + return routeTypeMono.flatMap(routeType -> { + RequestFieldCheckUtil.check(routeType); + setSave(routeType); + + RouteType routeTypeExample = new RouteType(); + routeTypeExample.setTitle(routeType.getTitle().trim()); + ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny().withMatcher("title", ExampleMatcher.GenericPropertyMatcher::exact).withIgnoreCase("id"); + Example example = Example.of(routeTypeExample, exampleMatcher); + return routeTypeDao.findOne(example).flatMap(r -> Mono.error(new SearchException("类型已经存在"))) + .switchIfEmpty(routeTypeDao.save(routeType)) + .then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Flux.just(new SuccessResult()), SuccessResult.class)); + }); + } + + /** + * 删除 + * + * @param serverRequest + * @return + */ + public Mono delete(ServerRequest serverRequest) { + String ids = serverRequest.pathVariable("ids"); + List idList = Arrays.asList(ids.split(",")); + return routeTypeDao.findAllById(idList).flatMap(route -> routeTypeDao.delete(route)) + .then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(new SuccessResult()), SuccessResult.class)); + } + + /** + * 列表 + * + * @param serverRequest + * @return + */ + public Mono list(ServerRequest serverRequest) { + Optional keywords = serverRequest.queryParam("keywords"); + + RouteType routeType = new RouteType(); + Example example = Example.of(routeType); + if (keywords.isPresent()) { + String keywordTrim = keywords.get().trim(); + routeType.setTitle(keywordTrim); + routeType.setSummary(keywordTrim); + + ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny() + .withMatcher("title", ExampleMatcher.GenericPropertyMatcher::contains) + .withMatcher("summary", ExampleMatcher.GenericPropertyMatcher::contains) + .withIgnoreCase("id"); + example = Example.of(routeType, exampleMatcher); + } + return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(routeTypeDao.findAll(example), RouteType.class); + } +} diff --git a/src/main/java/ink/wgink/gateway/pojo/BasePOJO.java b/src/main/java/ink/wgink/gateway/pojo/BasePOJO.java index 3c17f87..7fee2f9 100644 --- a/src/main/java/ink/wgink/gateway/pojo/BasePOJO.java +++ b/src/main/java/ink/wgink/gateway/pojo/BasePOJO.java @@ -1,7 +1,5 @@ package ink.wgink.gateway.pojo; -import lombok.Data; -import lombok.ToString; import org.springframework.data.annotation.Id; /** @@ -14,7 +12,6 @@ import org.springframework.data.annotation.Id; * @Date: 2021/4/13 5:56 下午 * @Version: 1.0 */ -@Data public class BasePOJO { @Id @@ -24,4 +21,43 @@ public class BasePOJO { private String gmtModified; private String modifier; + public String getUuid() { + return uuid == null ? "" : uuid.trim(); + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getGmtCreate() { + return gmtCreate == null ? "" : gmtCreate.trim(); + } + + public void setGmtCreate(String gmtCreate) { + this.gmtCreate = gmtCreate; + } + + public String getCreator() { + return creator == null ? "" : creator.trim(); + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public String getGmtModified() { + return gmtModified == null ? "" : gmtModified.trim(); + } + + public void setGmtModified(String gmtModified) { + this.gmtModified = gmtModified; + } + + public String getModifier() { + return modifier == null ? "" : modifier.trim(); + } + + public void setModifier(String modifier) { + this.modifier = modifier; + } } diff --git a/src/main/java/ink/wgink/gateway/pojo/route/Route.java b/src/main/java/ink/wgink/gateway/pojo/route/Route.java index 1ba1fc3..24ae9ed 100644 --- a/src/main/java/ink/wgink/gateway/pojo/route/Route.java +++ b/src/main/java/ink/wgink/gateway/pojo/route/Route.java @@ -19,13 +19,11 @@ import java.io.Serializable; * @Date: 2021/4/13 7:15 下午 * @Version: 1.0 */ -@Data -@ToString @Document(collection = IRouteDao.COLLECTION_NAME) public class Route extends BasePOJO implements Serializable { private static final long serialVersionUID = -4892456861969101733L; - @CheckEmptyAnnotation(name = "title") + @CheckEmptyAnnotation(name = "名称") private String title; @CheckEmptyAnnotation(name = "说明") private String summary; @@ -36,4 +34,43 @@ public class Route extends BasePOJO implements Serializable { @CheckEmptyAnnotation(name = "测试接口", verifyType = "path") private String testPath; + public String getTitle() { + return title == null ? "" : title.trim(); + } + + public void setTitle(String title) { + this.title = title; + } + + public String getSummary() { + return summary == null ? "" : summary.trim(); + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public String getPath() { + return path == null ? "" : path.trim(); + } + + public void setPath(String path) { + this.path = path; + } + + public String getUri() { + return uri == null ? "" : uri.trim(); + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getTestPath() { + return testPath == null ? "" : testPath.trim(); + } + + public void setTestPath(String testPath) { + this.testPath = testPath; + } } diff --git a/src/main/java/ink/wgink/gateway/pojo/routetype/RouteType.java b/src/main/java/ink/wgink/gateway/pojo/routetype/RouteType.java new file mode 100644 index 0000000..1c63efb --- /dev/null +++ b/src/main/java/ink/wgink/gateway/pojo/routetype/RouteType.java @@ -0,0 +1,44 @@ +package ink.wgink.gateway.pojo.routetype; + +import ink.wgink.gateway.annoation.CheckEmptyAnnotation; +import ink.wgink.gateway.dao.routetype.IRouteTypeDao; +import ink.wgink.gateway.pojo.BasePOJO; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.io.Serializable; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: RouteType + * @Description: 路由类型 + * @Author: WangGeng + * @Date: 2021/5/8 12:10 + * @Version: 1.0 + **/ +@Document(collection = IRouteTypeDao.COLLECTION_NAME) +public class RouteType extends BasePOJO implements Serializable { + + private static final long serialVersionUID = -4213129156239577757L; + @CheckEmptyAnnotation(name = "名称") + private String title; + @CheckEmptyAnnotation(name = "说明") + private String summary; + + public String getTitle() { + return title == null ? "" : title.trim(); + } + + public void setTitle(String title) { + this.title = title; + } + + public String getSummary() { + return summary == null ? "" : summary.trim(); + } + + public void setSummary(String summary) { + this.summary = summary; + } +} diff --git a/src/main/java/ink/wgink/gateway/router/routetype/RouteTypeRouter.java b/src/main/java/ink/wgink/gateway/router/routetype/RouteTypeRouter.java new file mode 100644 index 0000000..927a199 --- /dev/null +++ b/src/main/java/ink/wgink/gateway/router/routetype/RouteTypeRouter.java @@ -0,0 +1,34 @@ +package ink.wgink.gateway.router.routetype; + +import ink.wgink.gateway.consts.ISystemConst; +import ink.wgink.gateway.handler.routetype.RouteTypeHandler; +import ink.wgink.gateway.router.BaseRouter; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.RequestPredicates; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: RouteTypeRouter + * @Description: 路由类型 + * @Author: WangGeng + * @Date: 2021/5/8 13:14 + * @Version: 1.0 + **/ +@Component +public class RouteTypeRouter extends BaseRouter { + + @Bean + public RouterFunction routeTypeRouterFunction(RouteTypeHandler routeTypeHandler) { + return RouterFunctions.nest(RequestPredicates.path(ISystemConst.ADMIN_ROUTER_PREFIX + "/api/route-type"), + RouterFunctions + .route(RequestPredicates.POST("/save"), routeTypeHandler::save) + .andRoute(RequestPredicates.GET("/list"), routeTypeHandler::list)); + } + +} diff --git a/src/main/resources/static/wg/index.html b/src/main/resources/static/wg/index.html index 643034c..07f5801 100644 --- a/src/main/resources/static/wg/index.html +++ b/src/main/resources/static/wg/index.html @@ -19,7 +19,8 @@
  • 网关管理
    -
    映射管理
    +
    路由分类
    +
    映射管理
  • @@ -32,9 +33,8 @@
    @@ -65,6 +65,17 @@ window.onresize = resize; $('#defaultIFrame').attr('src', 'route/route/list.html'); + + $('.menu-item').on('click', function() { + $('#defaultIFrame').attr('src', this.dataset.href); + if($('#subBreadcrumbTitle').length > 0) { + $('#subBreadcrumbTitle').empty(); + $('#subBreadcrumbTitle').append(''+ this.text +''); + } else { + $('#breadcrumbTitle').append('/'+ this.text +''); + } + }) + $('#LAY-logout').on('click', function () { top.dialog.confirm('确认退出?', function () { window.location.href = 'logout'; diff --git a/src/main/resources/static/wg/route/route-type/list.html b/src/main/resources/static/wg/route/route-type/list.html new file mode 100644 index 0000000..d0b3da0 --- /dev/null +++ b/src/main/resources/static/wg/route/route-type/list.html @@ -0,0 +1,226 @@ + + + + + + + + + + + + + +
    +
    +
    + +
    +
    + +
    +
    +
    + + +
    + + + + \ No newline at end of file diff --git a/src/main/resources/static/wg/route/route-type/save.html b/src/main/resources/static/wg/route/route-type/save.html new file mode 100644 index 0000000..6c24733 --- /dev/null +++ b/src/main/resources/static/wg/route/route-type/save.html @@ -0,0 +1,102 @@ + + + + + + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/src/main/resources/static/wg/route/route-type/update.html b/src/main/resources/static/wg/route/route-type/update.html new file mode 100644 index 0000000..2280655 --- /dev/null +++ b/src/main/resources/static/wg/route/route-type/update.html @@ -0,0 +1,117 @@ + + + + + + + + + + + + +
    +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/src/main/resources/static/wg/route/route/list.html b/src/main/resources/static/wg/route/route/list.html index fc123ed..8f7d9a2 100644 --- a/src/main/resources/static/wg/route/route/list.html +++ b/src/main/resources/static/wg/route/route/list.html @@ -124,16 +124,16 @@ if (typeof (rowData) === 'undefined' || rowData == null || rowData == '') { return '-'; } - return rowData; + return ''+ rowData +''; } }, - {field: 'testPath', width: 100, title: '测试接口', align: 'center', sort: true, + {field: 'testPath', width: 180, title: '测试接口', align: 'center', sort: true, templet: function (row) { var rowData = row[this.field]; if (typeof (rowData) === 'undefined' || rowData == null || rowData == '') { return '-'; } - return '点击测试'; + return ''+ rowData +''; } }, {field: 'gmtCreate', width: 180, title: '添加时间', align: 'center', sort: true,