新增路由类型修改

This commit is contained in:
WenG 2021-05-11 23:05:37 +08:00
parent 0f583af56d
commit b15e672eb3
3 changed files with 55 additions and 14 deletions

View File

@ -6,6 +6,7 @@ import ink.wgink.gateway.handler.BaseHandler;
import ink.wgink.gateway.pojo.result.SuccessResult;
import ink.wgink.gateway.pojo.routetype.RouteType;
import ink.wgink.gateway.util.RequestFieldCheckUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.http.MediaType;
@ -54,10 +55,10 @@ public class RouteTypeHandler extends BaseHandler {
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));
});
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));
}
/**
@ -69,19 +70,43 @@ public class RouteTypeHandler extends BaseHandler {
public Mono<ServerResponse> delete(ServerRequest serverRequest) {
String ids = serverRequest.pathVariable("ids");
List<String> 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));
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<ServerResponse> update(ServerRequest serverRequest) {
String id = serverRequest.pathVariable("id");
Mono<RouteType> routeTypeMono = serverRequest.bodyToMono(RouteType.class);
return routeTypeDao.findById(id).flatMap(routeType -> routeTypeMono.flatMap(rt -> {
RouteType routeTypeExample = new RouteType();
routeTypeExample.setTitle(rt.getTitle());
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny().withMatcher("title", ExampleMatcher.GenericPropertyMatcher::exact).withIgnoreCase("id");
Example example = Example.of(routeTypeExample, exampleMatcher);
})).switchIfEmpty(ServerResponse.notFound().build());
// 查询ID是否存在
return routeTypeDao.findById(id).flatMap(routeType -> {
setUpdate(routeType);
return routeTypeMono.flatMap(rt -> {
routeType.setTitle(rt.getTitle());
routeType.setSummary(rt.getSummary());
RequestFieldCheckUtil.check(rt);
rt.setSummary(null );
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny()
.withMatcher("title", ExampleMatcher.GenericPropertyMatcher::exact)
.withIgnoreCase("id");
Example example = Example.of(rt, exampleMatcher);
// 查询title是否存在
return routeTypeDao.findOne(example).flatMap(ert -> {
RouteType existRouteType = (RouteType) ert;
// 如果已经存在
if (!StringUtils.equals(existRouteType.getUuid(), id)) {
return Mono.error(new SearchException("类型已经存在"));
}
return routeTypeDao.save(routeType);
}).switchIfEmpty(routeTypeDao.save(routeType));
});
}).switchIfEmpty(ServerResponse.notFound().build()).then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(new SuccessResult()), SuccessResult.class));
}
/**
@ -108,4 +133,17 @@ public class RouteTypeHandler extends BaseHandler {
}
return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(routeTypeDao.findAll(example), RouteType.class);
}
/**
* 详情
*
* @param serverRequest
* @return
*/
public Mono<ServerResponse> get(ServerRequest serverRequest) {
String id = serverRequest.pathVariable("id");
return routeTypeDao.findById(id).flatMap(
routeType -> ServerResponse.ok().body(Mono.just(routeType), RouteType.class)
).switchIfEmpty(ServerResponse.notFound().build());
}
}

View File

@ -28,7 +28,10 @@ public class RouteTypeRouter extends BaseRouter {
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));
.andRoute(RequestPredicates.DELETE("/delete/{ids}"), routeTypeHandler::delete)
.andRoute(RequestPredicates.PUT("/update/{id}"), routeTypeHandler::update)
.andRoute(RequestPredicates.GET("/list"), routeTypeHandler::list)
.andRoute(RequestPredicates.GET("/get/{id}"), routeTypeHandler::get));
}
}

View File

@ -84,7 +84,7 @@
top.dialog.confirm(top.dataMessage.commit, function(index) {
top.dialog.close(index);
var loadLayerIndex;
top.restAjax.put(top.restAjax.path('api/route/update-type/{uuid}', [uuid]), formData.field, null, function(code, data) {
top.restAjax.put(top.restAjax.path('api/route-type/update/{uuid}', [uuid]), formData.field, null, function(code, data) {
var layerIndex = top.dialog.msg(top.dataMessage.updateSuccess, {
time: 0,
btn: [top.dataMessage.button.yes, top.dataMessage.button.no],