diff --git a/flyfish-user/src/main/java/com/flyfish/framework/controller/authorized/AuthorizedController.java b/flyfish-user/src/main/java/com/flyfish/framework/controller/authorized/AuthorizedController.java deleted file mode 100644 index 3f70cfc..0000000 --- a/flyfish-user/src/main/java/com/flyfish/framework/controller/authorized/AuthorizedController.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.flyfish.framework.controller.authorized; - -import com.flyfish.framework.annotations.Operation; -import com.flyfish.framework.bean.Result; -import com.flyfish.framework.bean.SyncVo; -import com.flyfish.framework.configuration.annotations.CurrentUser; -import com.flyfish.framework.configuration.annotations.PagedQuery; -import com.flyfish.framework.configuration.annotations.ValidRequestBody; -import com.flyfish.framework.constant.ReactiveConstants; -import com.flyfish.framework.context.UserContext; -import com.flyfish.framework.controller.SafeController; -import com.flyfish.framework.domain.authorized.AuthorizedDomain; -import com.flyfish.framework.domain.authorized.AuthorizedQo; -import com.flyfish.framework.domain.po.User; -import com.flyfish.framework.service.BaseReactiveService; -import com.flyfish.framework.service.BaseService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; -import reactor.core.publisher.Mono; - -import java.util.List; - -/** - * 通用RESTful的控制器,用于动态提供基础的RESTful接口 - * - * @author wangyu - * @create 2017-06-15 8:48 - */ -public abstract class AuthorizedController> implements SafeController { - - @Autowired - protected BaseService service; - @Autowired(required = false) - protected BaseReactiveService reactiveService; - @Autowired - protected UserContext userContext; - - @SuppressWarnings("unchecked") - public > S getService() { - return (S) service; - } - - @GetMapping("/exists") - public Result exists(@PagedQuery Q qo) { - return Result.accept(service.count(qo) != 0); - } - - @GetMapping("/count") - public Result count(@PagedQuery Q qo) { - return Result.accept(service.count(qo)); - } - - @PostMapping("") - @Operation.Create - public Result create(@ValidRequestBody T entity, @CurrentUser User user) { - userContext.setUser(user); - return Result.accept(service.create(entity)); - } - - @GetMapping("{id}") - public Result get(@PathVariable String id) { - return service.getById(id).map(Result::accept).orElse(Result.notFound()); - } - - @PutMapping("{id}") - @Operation.Update - public Result update(@ValidRequestBody T entity, @CurrentUser User user) { - userContext.setUser(user); - return Result.accept(service.updateSelectiveById(entity)); - } - - @PatchMapping("{id}") - @Operation.Update - public Result patch(@RequestBody T entity, @CurrentUser User user) { - userContext.setUser(user); - return Result.accept(service.updateSelectiveById(entity)); - } - - @PutMapping("") - @Operation.UpdateAll - public Result> updateList(@RequestBody List list, @CurrentUser User user) { - userContext.setUser(user); - return Result.accept(service.updateBatch(list)); - } - - @PutMapping("/sync") - @Operation.Sync - public Result> syncList(@RequestBody List list, @CurrentUser User user) { - userContext.setUser(user); - return Result.accept(service.sync(list)); - } - - @DeleteMapping("{id}") - @Operation.Delete - public Result remove(@PathVariable List id, @CurrentUser User user) { - userContext.setUser(user); - service.deleteBatchByIds(id); - return Result.ok(); - } - - @GetMapping("/all") - public Result> all(@PagedQuery Q qo) { - if (qo.isEmpty()) { - return Result.accept(service.getAll()); - } - return Result.accept(service.getList(qo)); - } - - @GetMapping("") - public Result> list(@PagedQuery Q qo) { - if (null != qo.getPageable()) { - return Result.accept(service.getPageList(qo)); - } - return Result.accept(service.getList(qo)); - } - - - @PutMapping(value = "{id}", headers = ReactiveConstants.USE_REACTIVE) - public Mono> reactiveUpdate(@ValidRequestBody T entity) { - return reactiveService.updateById(entity) - .map(Result::accept) - .defaultIfEmpty(Result.notFound()); - } - -} diff --git a/flyfish-user/src/main/java/com/flyfish/framework/controller/authorized/ReactiveAuthorizedController.java b/flyfish-user/src/main/java/com/flyfish/framework/controller/authorized/ReactiveAuthorizedController.java deleted file mode 100644 index 25f3c67..0000000 --- a/flyfish-user/src/main/java/com/flyfish/framework/controller/authorized/ReactiveAuthorizedController.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.flyfish.framework.controller.authorized; - -import com.flyfish.framework.annotations.Operation; -import com.flyfish.framework.bean.Result; -import com.flyfish.framework.bean.SyncVo; -import com.flyfish.framework.configuration.annotations.PagedQuery; -import com.flyfish.framework.configuration.annotations.ValidRequestBody; -import com.flyfish.framework.controller.SafeController; -import com.flyfish.framework.domain.authorized.AuthorizedDomain; -import com.flyfish.framework.domain.authorized.AuthorizedQo; -import com.flyfish.framework.service.BaseReactiveService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.util.CastUtils; -import org.springframework.web.bind.annotation.*; -import reactor.core.publisher.Mono; - -import java.util.List; - -/** - * 多租户带授权的控制器 - * - * @param 实体泛型 - * @param 查询实体泛型 - */ -public abstract class ReactiveAuthorizedController> implements SafeController { - - @Autowired - protected BaseReactiveService reactiveService; - - public > S getService() { - return CastUtils.cast(reactiveService); - } - - @GetMapping("/exists") - public Mono> exists(@PagedQuery Q qo) { - return reactiveService.exists(qo).map(Result::accept); - } - - @GetMapping("/count") - public Mono> count(@PagedQuery Q qo) { - return reactiveService.count(qo).map(Result::accept); - } - - @PostMapping("") - @Operation.Create - public Mono> create(@ValidRequestBody T entity) { - return reactiveService.create(entity).map(Result::accept); - } - - @GetMapping("{id}") - public Mono> get(@PathVariable String id) { - return reactiveService.getById(id).map(Result::accept).defaultIfEmpty(Result.notFound()); - } - - @PutMapping("{id}") - @Operation.Update - public Mono> update(@ValidRequestBody T entity) { - return reactiveService.updateSelectiveById(entity).map(Result::accept).defaultIfEmpty(Result.notFound()); - } - - @PatchMapping("{id}") - @Operation.Update - public Mono> patch(@RequestBody T entity) { - return reactiveService.updateSelectiveById(entity).map(Result::accept).defaultIfEmpty(Result.notFound()); - } - - @PutMapping("") - @Operation.UpdateAll - public Mono>> updateList(@RequestBody List list) { - return reactiveService.updateBatch(list).collectList().map(Result::accept).defaultIfEmpty(Result.emptyList()); - } - - @PutMapping("/sync") - @Operation.Sync - public Mono>> syncList(@RequestBody List list) { - return reactiveService.sync(list).map(Result::accept).defaultIfEmpty(Result.accept(SyncVo.builder().build())); - } - - @DeleteMapping("{id}") - @Operation.Delete - public Mono> remove(@PathVariable List id) { - return reactiveService.deleteBatchByIds(id).thenReturn(Result.ok()); - } - - @GetMapping("/all") - public Mono>> all(@PagedQuery Q qo) { - if (qo.isEmpty()) { - return reactiveService.getAll().collectList().map(Result::accept).defaultIfEmpty(Result.emptyList()); - } - return reactiveService.getList(qo).collectList().map(Result::accept).defaultIfEmpty(Result.emptyList()); - } - - @GetMapping("") - public Mono>> list(@PagedQuery Q qo) { - if (null != qo.getPageable() && qo.getPageable().isPaged()) { - return reactiveService.getPageList(qo).map(Result::accept).defaultIfEmpty(Result.emptyPage()); - } - return reactiveService.getList(qo).collectList().map(Result::accept).defaultIfEmpty(Result.emptyList()); - } -}