| New file |
| | |
| | | package org.springblade.es.controller; |
| | | |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.secure.annotation.PreAuth; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.RoleConstant; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.es.service.ElasticsearchDocumentService; |
| | | import org.springblade.es.vo.EsParam; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** |
| | | * es 全文检索 |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/es/es") |
| | | @AllArgsConstructor |
| | | @Api(value = "es 全文检索", tags = "es 全文检索") |
| | | public class EsController { |
| | | |
| | | private final ElasticsearchDocumentService elasticsearchDocumentService; |
| | | |
| | | /** |
| | | * 查询 |
| | | */ |
| | | @GetMapping("/page") |
| | | @ApiOperationSupport(order = 1) |
| | | public R page(EsParam esParam, Query query) { |
| | | return R.data(elasticsearchDocumentService.selectDocumentPage(Condition.getPage(query), esParam)); |
| | | } |
| | | |
| | | /** |
| | | * 初始化 |
| | | */ |
| | | @GetMapping("/init") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) |
| | | @ApiOperationSupport(order = 2) |
| | | public R init(EsParam esParam) { |
| | | return R.status(elasticsearchDocumentService.init(esParam)); |
| | | } |
| | | |
| | | // /** |
| | | // * 新增数据 |
| | | // */ |
| | | // @GetMapping("/add") |
| | | // @ApiOperationSupport(order = 3) |
| | | // public R add(EsParam esParam) { |
| | | // return R.status(elasticsearchDocumentService.add(esParam,null)); |
| | | // } |
| | | // |
| | | // /** |
| | | // * 修改数据 |
| | | // */ |
| | | // @GetMapping("/update") |
| | | // @ApiOperationSupport(order = 4) |
| | | // public R update(EsParam esParam) { |
| | | // elasticsearchDocumentService.update(esParam,null,null); |
| | | // return R.status(true); |
| | | // } |
| | | |
| | | /** |
| | | * 根据索引删除 |
| | | */ |
| | | @PostMapping("/removeBatchByIndexNames") |
| | | @ApiOperationSupport(order = 5) |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) |
| | | public R removeBatchByIndexNames(@RequestParam String indexNames) { |
| | | return R.status(elasticsearchDocumentService.removeBatchByIndexNames(Func.toStrList(indexNames))); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件删除 |
| | | */ |
| | | @PostMapping("/removeByQuery") |
| | | @PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR) |
| | | @ApiOperationSupport(order = 6) |
| | | public R removeByQuery(EsParam esParam) { |
| | | return R.status(elasticsearchDocumentService.removeByQuery(esParam)); |
| | | } |
| | | } |