package com.yida.data.school.atlas.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.common.ResultMsgType;
import com.yida.data.school.atlas.service.CoreAtlasManagementDetailsCommentReplyService;
import com.yida.data.school.atlas.service.CoreAtlasManagementDetailsCommentService;
import com.yida.data.school.dto.atlas.AtlasDetailsCommentReplySelectPageDTO;
import com.yida.data.school.dto.atlas.AtlasDetailsCommentSelectPageDTO;
import com.yida.data.school.dto.atlas.CheckCommentDTO;
import com.yida.data.school.dto.atlas.CheckCommentReplyDTO;
import com.yida.data.school.vo.atlas.AtlasDetailsCommentInfoVO;
import com.yida.data.school.vo.atlas.AtlasDetailsCommentReplyInfoVO;
import com.yida.data.school.vo.atlas.AtlasDetailsCommentReplySelectPageVO;
import com.yida.data.school.vo.atlas.AtlasDetailsCommentSelectPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 学校图集作品评论后台接口
 *
 * @author ZYJ
 * @date 2021/10/13
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "图集-后台-评论")
@RequestMapping(value = "/atlas/atlasComment", produces = MediaType.APPLICATION_JSON_VALUE)
public class CoreAtlasManagementDetailsCommentController {

    private final CoreAtlasManagementDetailsCommentService coreAtlasManagementDetailsCommentService;

    private final CoreAtlasManagementDetailsCommentReplyService coreAtlasManagementDetailsCommentReplyService;

    /**
     * 查询作品评论列表数据
     *
     * @param atlasDetailsCommentSelectPageDTO 图集作品评论列表请求类
     * @return com.yida.data.common.core.common.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < com.yida.data.atlas.vo.AtlasDetailsCommentSelectPageVO>>
     * @author ZYJ
     * @date 2021/10/13 11:06
     */
    @PostMapping(value = "/listAtlasDetailsCommentPage")
    @ApiOperation(value = "查询作品评论列表数据", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<IPage<AtlasDetailsCommentSelectPageVO>> listAtlasDetailsCommentPage(
            @Valid AtlasDetailsCommentSelectPageDTO atlasDetailsCommentSelectPageDTO) {
        try {
            return this.coreAtlasManagementDetailsCommentService.listAtlasDetailsCommentPage(atlasDetailsCommentSelectPageDTO);
        } catch (Exception e) {
            log.error("查询作品评论列表数据失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 获取图集作品评论详情
     *
     * @param commentId 评论id
     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.atlas.vo.AtlasDetailsCommentInfoVO>
     * @author ZYJ
     * @date 2021/10/13 14:42
     */
    @ApiOperation("获取图集作品评论详情")
    @GetMapping(value = "/getAtlasDetailsCommentInfo")
    public ResultBean<AtlasDetailsCommentInfoVO> getAtlasDetailsCommentInfo(
            @ApiParam(value = "评论id", required = true) @RequestParam Long commentId) {
        try {
            return this.coreAtlasManagementDetailsCommentService.getAtlasDetailsCommentInfo(commentId);
        } catch (Exception e) {
            log.error("获取图集作品评论详情失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 作品评论审核接口
     *
     * @param checkCommentDTO 作品评论审核请求类
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/10/13 15:16
     */
    @PostMapping(value = "/checkComment", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "作品评论审核接口", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> checkComment(@RequestBody @Valid CheckCommentDTO checkCommentDTO) {
        try {
            return this.coreAtlasManagementDetailsCommentService.checkComment(checkCommentDTO);
        } catch (Exception e) {
            log.error("作品评论审核接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
        }
    }

    /**
     * 批量删除作品评论
     *
     * @param ids 评论id集合
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/10/13 15:06
     */
    @PostMapping(value = "/deleteCommentBatch", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "批量删除作品评论", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> deleteCommentBatch(
            @ApiParam(value = "评论id集合", required = true) @RequestBody Long[] ids) {
        try {
            return this.coreAtlasManagementDetailsCommentService.deleteCommentBatch(ids);
        } catch (Exception e) {
            log.error("批量删除作品评论失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.DELETE_FAIL.getValue());
        }
    }

    /**
     * 查询评论回复列表数据
     *
     * @param atlasDetailsCommentReplySelectPageDTO 评论回复列表返回数据
     * @return com.yida.data.common.core.common.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < com.yida.data.atlas.vo.AtlasDetailsCommentReplySelectPageVO>>
     * @author ZYJ
     * @date 2021/10/13 15:47
     */
    @PostMapping(value = "/listAtlasDetailsCommentReplyPage")
    @ApiOperation(value = "查询评论回复列表数据", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<IPage<AtlasDetailsCommentReplySelectPageVO>> listAtlasDetailsCommentReplyPage(
            @Valid AtlasDetailsCommentReplySelectPageDTO atlasDetailsCommentReplySelectPageDTO) {
        try {
            return this.coreAtlasManagementDetailsCommentReplyService.listAtlasDetailsCommentReplyPage(atlasDetailsCommentReplySelectPageDTO);
        } catch (Exception e) {
            log.error("查询评论回复列表数据失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 获取评论回复详情
     *
     * @param commentReplyId 评论回复id
     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.atlas.vo.AtlasDetailsCommentReplyInfoVO>
     * @author ZYJ
     * @date 2021/10/13 15:51
     */
    @ApiOperation("获取评论回复详情")
    @GetMapping(value = "/getCommentReplyInfo")
    public ResultBean<AtlasDetailsCommentReplyInfoVO> getCommentReplyInfo(
            @ApiParam(value = "评论回复id", required = true) @RequestParam Long commentReplyId) {
        try {
            return this.coreAtlasManagementDetailsCommentReplyService.getCommentReplyInfo(commentReplyId);
        } catch (Exception e) {
            log.error("获取评论回复详情失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 评论回复审核接口
     *
     * @param checkCommentReplyDTO 作品评论审核请求类
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/10/13 15:55
     */
    @PostMapping(value = "/checkCommentReply", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "评论回复审核接口", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> checkCommentReply(@RequestBody @Valid CheckCommentReplyDTO checkCommentReplyDTO) {
        try {
            return this.coreAtlasManagementDetailsCommentReplyService.checkCommentReply(checkCommentReplyDTO);
        } catch (Exception e) {
            log.error("评论回复审核接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
        }
    }

    /**
     * 批量删除评论回复数据
     *
     * @param ids 回复id集合
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/10/13 15:57
     */
    @PostMapping(value = "/deleteCommentReplyBatch", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "批量删除评论回复数据", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> deleteCommentReplyBatch(
            @ApiParam(value = "回复id集合", required = true) @RequestBody Long[] ids) {
        try {
            return this.coreAtlasManagementDetailsCommentReplyService.deleteCommentReplyBatch(ids);
        } catch (Exception e) {
            log.error("批量删除评论回复数据失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.DELETE_FAIL.getValue());
        }
    }
}
