package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.es.service.DocumentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: 31966
 * @Project: mall-product
 * @Package: com.bwie.es.controller
 * @ClassName: DocumentController
 * @Description: 请在此处填写具体描述
 * @Date: 2024/4/22 20:57
 */
@RestController
@RequestMapping("/doc")
@Api(tags = "es文档接口")
public class DocumentController {

    @Resource(name = "documentServiceImpl")
    private DocumentService documentService;

    @PostMapping("/{indexName}")
    @ApiOperation(value = "条件查询文档数据")
    public R queryList(@PathVariable String indexName, @RequestBody Map<String,Object> conditions){
        return documentService.queryList(indexName,conditions);
    }

    @PutMapping("/{indexName}")
    @ApiOperation(value = "批量操作数据")
    public R batchDocument(@PathVariable String indexName, @RequestBody Map<String,Object> dataJson){
        documentService.batchOperation(indexName,dataJson);
        return R.ok(null, "批量操作成功");
    }

    @DeleteMapping("/{indexName}")
    @ApiOperation(value = "批量删除")
    public R batchDeleteDocument(@PathVariable String indexName, @RequestBody List<String> dataJson){
        documentService.batchDeletion(indexName,dataJson);
        return R.ok(null, "批量删除成功");
    }

}
