package com.pcloud.book.es.facade;

import com.pcloud.book.base.exception.BookBizException;
import com.pcloud.book.es.biz.ESBookAndAdviserBiz;
import com.pcloud.book.es.entity.ESBookAndAdviser;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author ruansiyuan
 * @Date 2019/6/13 16:43
 **/
@RestController("eesBookAndAdviserFacade")
@RequestMapping("esBookAndAdviser")
public class ESBookAndAdviserFacade {


    @Autowired
    private ESBookAndAdviserBiz esBookAndAdviserBiz;

    @ApiOperation("添加所有的书和编辑书到es")
    @PostMapping("addAllBookAndAdviserToES")
    public ResponseDto<?> addAllBookAndAdviserToES() throws BizException {
        esBookAndAdviserBiz.addAllBookAndAdviserToES();
        return new ResponseDto<>();
    }

    @ApiOperation("从es中获取编辑书")
    @GetMapping("getAdviserBooks4ES")
    public List<ESBookAndAdviser> getAdviserBooks4ES(
            @RequestParam(value = "keyword", required = false) String keyword,
            @RequestParam(value = "templetId", required = false) Long templetId,
            @RequestParam(value = "secondTempletId", required = false) Long secondTempletId,
            @RequestParam(value = "thirdTempletId", required = false) Long thirdTempletId,
            @RequestParam(value = "currentPage") Integer currentPage,
            @RequestParam(value = "numPerPage") Integer numPerPage
    ) throws BizException {
        if (currentPage == null || numPerPage == null || currentPage < 0 || numPerPage < 0) {
            throw BookBizException.PAGE_PARAM_DELETION;
        }
        return esBookAndAdviserBiz.getAdviserBooks4ES("0", keyword,templetId,secondTempletId,thirdTempletId,currentPage,numPerPage).getList();
    }

    @ApiOperation("es中删除部分测试图书")
    @GetMapping("deleteAdviserBooks4ES")
    public ResponseDto<?> deleteAdviserBooks4ES() throws BizException {
        throw new BizException("接口已下线 - deleteAdviserBooks4ES");
    }

    @ApiOperation("es中删除选中图书")
    @GetMapping("deleteChoosedAdviserBooks4ES")
    public ResponseDto<?> deleteChoosedAdviserBooks4ES(@RequestParam(value = "keyword") String keyword) throws BizException {
        throw new BizException("接口已下线 - deleteChoosedAdviserBooks4ES");
    }

    @ApiOperation("查询ES有而BOOK表没有的书")
    @GetMapping("getNotFoundBookId")
    public ResponseDto<?> getNotFoundBookId(@RequestParam(value = "lastBookId") String lastBookId) throws Exception {
        return new ResponseDto<>(esBookAndAdviserBiz.getNotFoundBookId(lastBookId));
    }

    @ApiOperation("停止查询ES有而BOOK表没有的书")
    @GetMapping("stopNotFoundBookId")
    public ResponseDto<?> stopNotFoundBookId() throws BizException {
        esBookAndAdviserBiz.stopNotFoundBookId();
        return new ResponseDto<>();
    }

    @ApiOperation("ES同步图书分类信息 - 慎点 参数为接口名")
    @GetMapping("/syncBookAdviserTemplet4ES")
    public ResponseDto<Void> syncBookAdviserTemplet4ES(@RequestParam("conten") String content){
        throw new BizException("接口已下线 - syncBookAdviserTemplet4ES");
    }

    @ApiOperation("更新es书刊")
    @PostMapping("updateBookAndAdviserToES")
    public ResponseDto<?> updateBookAndAdviserToES(@RequestBody List<Long> bookIds) {
        esBookAndAdviserBiz.updateBookAndAdviserToES(bookIds);
        return new ResponseDto<>();
    }
}
