新增路由类型修改
This commit is contained in:
parent
0f583af56d
commit
b15e672eb3
@ -6,6 +6,7 @@ import ink.wgink.gateway.handler.BaseHandler;
|
|||||||
import ink.wgink.gateway.pojo.result.SuccessResult;
|
import ink.wgink.gateway.pojo.result.SuccessResult;
|
||||||
import ink.wgink.gateway.pojo.routetype.RouteType;
|
import ink.wgink.gateway.pojo.routetype.RouteType;
|
||||||
import ink.wgink.gateway.util.RequestFieldCheckUtil;
|
import ink.wgink.gateway.util.RequestFieldCheckUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.data.domain.Example;
|
import org.springframework.data.domain.Example;
|
||||||
import org.springframework.data.domain.ExampleMatcher;
|
import org.springframework.data.domain.ExampleMatcher;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@ -54,10 +55,10 @@ public class RouteTypeHandler extends BaseHandler {
|
|||||||
routeTypeExample.setTitle(routeType.getTitle().trim());
|
routeTypeExample.setTitle(routeType.getTitle().trim());
|
||||||
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny().withMatcher("title", ExampleMatcher.GenericPropertyMatcher::exact).withIgnoreCase("id");
|
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny().withMatcher("title", ExampleMatcher.GenericPropertyMatcher::exact).withIgnoreCase("id");
|
||||||
Example example = Example.of(routeTypeExample, exampleMatcher);
|
Example example = Example.of(routeTypeExample, exampleMatcher);
|
||||||
return routeTypeDao.findOne(example).flatMap(r -> Mono.error(new SearchException("类型已经存在")))
|
return routeTypeDao.findOne(example).flatMap(
|
||||||
.switchIfEmpty(routeTypeDao.save(routeType))
|
r -> Mono.error(new SearchException("类型已经存在"))
|
||||||
.then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Flux.just(new SuccessResult()), SuccessResult.class));
|
).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) {
|
public Mono<ServerResponse> delete(ServerRequest serverRequest) {
|
||||||
String ids = serverRequest.pathVariable("ids");
|
String ids = serverRequest.pathVariable("ids");
|
||||||
List<String> idList = Arrays.asList(ids.split(","));
|
List<String> idList = Arrays.asList(ids.split(","));
|
||||||
return routeTypeDao.findAllById(idList).flatMap(route -> routeTypeDao.delete(route))
|
return routeTypeDao.findAllById(idList).flatMap(route -> routeTypeDao.delete(route)).then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(new SuccessResult()), SuccessResult.class));
|
||||||
.then(ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8).body(Mono.just(new SuccessResult()), SuccessResult.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*
|
||||||
|
* @param serverRequest
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public Mono<ServerResponse> update(ServerRequest serverRequest) {
|
public Mono<ServerResponse> update(ServerRequest serverRequest) {
|
||||||
String id = serverRequest.pathVariable("id");
|
String id = serverRequest.pathVariable("id");
|
||||||
Mono<RouteType> routeTypeMono = serverRequest.bodyToMono(RouteType.class);
|
Mono<RouteType> routeTypeMono = serverRequest.bodyToMono(RouteType.class);
|
||||||
return routeTypeDao.findById(id).flatMap(routeType -> routeTypeMono.flatMap(rt -> {
|
|
||||||
RouteType routeTypeExample = new RouteType();
|
// 查询ID是否存在
|
||||||
routeTypeExample.setTitle(rt.getTitle());
|
return routeTypeDao.findById(id).flatMap(routeType -> {
|
||||||
ExampleMatcher exampleMatcher = ExampleMatcher.matchingAny().withMatcher("title", ExampleMatcher.GenericPropertyMatcher::exact).withIgnoreCase("id");
|
setUpdate(routeType);
|
||||||
Example example = Example.of(routeTypeExample, exampleMatcher);
|
return routeTypeMono.flatMap(rt -> {
|
||||||
})).switchIfEmpty(ServerResponse.notFound().build());
|
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);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,10 @@ public class RouteTypeRouter extends BaseRouter {
|
|||||||
return RouterFunctions.nest(RequestPredicates.path(ISystemConst.ADMIN_ROUTER_PREFIX + "/api/route-type"),
|
return RouterFunctions.nest(RequestPredicates.path(ISystemConst.ADMIN_ROUTER_PREFIX + "/api/route-type"),
|
||||||
RouterFunctions
|
RouterFunctions
|
||||||
.route(RequestPredicates.POST("/save"), routeTypeHandler::save)
|
.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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@
|
|||||||
top.dialog.confirm(top.dataMessage.commit, function(index) {
|
top.dialog.confirm(top.dataMessage.commit, function(index) {
|
||||||
top.dialog.close(index);
|
top.dialog.close(index);
|
||||||
var loadLayerIndex;
|
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, {
|
var layerIndex = top.dialog.msg(top.dataMessage.updateSuccess, {
|
||||||
time: 0,
|
time: 0,
|
||||||
btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
|
btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
|
||||||
|
Loading…
Reference in New Issue
Block a user