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

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.AppAtlasService;
import com.yida.data.school.dto.atlas.app.*;
import com.yida.data.school.vo.atlas.AtlasSelectPageVO;
import com.yida.data.school.vo.atlas.app.AppAtlasInfoVO;
import com.yida.data.school.vo.atlas.app.AppAtlasWorkBaseVO;
import com.yida.data.school.vo.atlas.app.AppAtlasWorkCommentPageVO;
import com.yida.data.school.vo.atlas.app.AppAtlasWorkCommentReplyPageVO;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 学校图集管理app接口
 *
 * @author ZYJ
 * @date 2021/9/2
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "图集-前台")
@RequestMapping(value = "/atlas/app/atlasManagement", produces = MediaType.APPLICATION_JSON_VALUE)
public class AppCoreAtlasManagementController {

    private final AppAtlasService appAtlasService;

    /**
     * 查询图集分页数据接口
     *
     * @param schoolId 学校id
     * @param pageNo   当前页码
     * @param pageSize 页面大小
     * @return com.yida.data.common.core.common.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < com.yida.data.atlas.vo.AtlasSelectPageVO>>
     * @author ZYJ
     * @date 2021/9/2 17:41
     */
    @PostMapping(value = "/listAtlasPage")
    @ApiOperation(value = "查询图集分页数据接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<IPage<AtlasSelectPageVO>> listAtlasPage(
            @ApiParam(value = "学校id", required = true) @RequestParam Long schoolId,
            @ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNo,
            @ApiParam(value = "页面大小", required = true) @RequestParam Integer pageSize) {

        try {
            return this.appAtlasService.listAtlasPage(schoolId, pageNo, pageSize);
        } catch (Exception e) {
            log.error("app查询图集分页数据接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 获取图集详情接口
     *
     * @param appAtlasInfoDTO app获取图集详情接口请求类
     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.atlas.vo.app.AppAtlasInfoVO>
     * @author ZYJ
     * @date 2021/9/6 10:47
     */
    @PostMapping(value = "/getAtlasInfo")
    @ApiOperation(value = "获取图集详情接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<AppAtlasInfoVO> getAtlasInfo(@Valid AppAtlasInfoDTO appAtlasInfoDTO) {

        try {
            return this.appAtlasService.getAtlasInfo(appAtlasInfoDTO);
        } catch (Exception e) {
            log.error("app获取图集详情接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 根据类型查询图集作品分页数据接口
     *
     * @param appAtlasWorkListDTO app根据类型查询图集作品分页数据请求类
     * @return com.yida.data.common.core.common.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < com.yida.data.atlas.vo.app.AppAtlasWorkBaseVO>>
     * @author ZYJ
     * @date 2021/9/6 17:29
     */
    @PostMapping(value = "/getAtlasWorkByType")
    @ApiOperation(value = "根据类型查询图集作品分页数据接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<IPage<AppAtlasWorkBaseVO>> listAtlasWorkByType(
            @Valid AppAtlasWorkListDTO appAtlasWorkListDTO) {
        try {
            return this.appAtlasService.listAtlasWorkByType(appAtlasWorkListDTO);
        } catch (Exception e) {
            log.error("app根据类型查询图集作品分页数据接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 获取图集作品作品详情接口
     *
     * @param appAtlasWorkInfoDTO app获取图集作品详情接口请求类
     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.atlas.vo.app.AppAtlasWorkBaseVO>
     * @author ZYJ
     * @date 2021/9/6 17:46
     */
    @PostMapping(value = "/getAtlasWorkInfo")
    @ApiOperation(value = "获取图集作品作品详情接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<AppAtlasWorkBaseVO> getAtlasWorkInfo(@Valid AppAtlasWorkInfoDTO appAtlasWorkInfoDTO) {

        try {
            return this.appAtlasService.getAtlasWorkInfo(appAtlasWorkInfoDTO);
        } catch (Exception e) {
            log.error("app获取图集作品作品详情接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 图集作品点赞接口
     *
     * @param appAtlasWorkLikeDTO app图集作品点赞/取消点赞请求类
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/7 9:50
     */
    @PostMapping(value = "/likeAtlasWork")
    @ApiOperation(value = "图集作品点赞接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<String> likeAtlasWork(@Valid AppAtlasWorkLikeDTO appAtlasWorkLikeDTO) {

        try {
            return this.appAtlasService.likeAtlasWork(appAtlasWorkLikeDTO);
        } catch (Exception e) {
            log.error("app图集作品点赞失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
        }
    }

    /**
     * 图集作品取消点赞接口
     *
     * @param appAtlasWorkLikeDTO app图集作品点赞/取消点赞请求类
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/7 15:55
     */
    @PostMapping(value = "/cancelLikeAtlasWork")
    @ApiOperation(value = "图集作品取消点赞接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<String> cancelLikeAtlasWork(@Valid AppAtlasWorkLikeDTO appAtlasWorkLikeDTO) {

        try {
            return this.appAtlasService.cancelLikeAtlasWork(appAtlasWorkLikeDTO);
        } catch (Exception e) {
            log.error("app图集作品取消点赞失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
        }
    }

    /**
     * app分页查询图集作品评论列表接口
     *
     * @param appAtlasWorkCommentSelectDTO app分页查询图集作品评论列表接口请求类
     * @return com.yida.data.common.core.common.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < com.yida.data.atlas.vo.app.AppAtlasWorkCommentPageVO>>
     * @author ZYJ
     * @date 2021/9/7 16:43
     */
    @PostMapping(value = "/listAtlasWorkCommentPage")
    @ApiOperation(value = "分页查询图集作品评论列表接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<IPage<AppAtlasWorkCommentPageVO>> listAtlasWorkCommentPage(
            @Valid AppAtlasWorkCommentSelectDTO appAtlasWorkCommentSelectDTO) {
        try {
            return this.appAtlasService.listAtlasWorkCommentPage(appAtlasWorkCommentSelectDTO);
        } catch (Exception e) {
            log.error("app分页查询图集作品评论列表接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * app保存图集作品评论接口
     *
     * @param appAtlasWorkCommentSaveDTO app保存图集作品评论接口请求类
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/7 17:00
     */
    @PostMapping(value = "/saveAtlasWorkComment")
    @ApiOperation(value = "保存图集作品评论接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<String> saveAtlasWorkComment(
            @Valid AppAtlasWorkCommentSaveDTO appAtlasWorkCommentSaveDTO) {
        try {
            return this.appAtlasService.saveAtlasWorkComment(appAtlasWorkCommentSaveDTO);
        } catch (Exception e) {
            log.error("app保存图集作品评论接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
        }
    }

    /**
     * app分页查询评论回复列表接口
     *
     * @param appAtlasWorkCommentReplySelectDTO app分页查询评论回复列表接口请求类
     * @return com.yida.data.common.core.common.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < com.yida.data.atlas.vo.app.AppAtlasWorkCommentReplyPageVO>>
     * @author ZYJ
     * @date 2021/9/7 17:32
     */
    @PostMapping(value = "/listAtlasWorkCommentReplyPage")
    @ApiOperation(value = "分页查询评论回复列表接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<IPage<AppAtlasWorkCommentReplyPageVO>> listAtlasWorkCommentReplyPage(
            @Valid AppAtlasWorkCommentReplySelectDTO appAtlasWorkCommentReplySelectDTO) {
        try {
            return this.appAtlasService.listAtlasWorkCommentReplyPage(appAtlasWorkCommentReplySelectDTO);
        } catch (Exception e) {
            log.error("app分页查询评论回复列表接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * app保存评论回复接口
     *
     * @param appAtlasWorkCommentReplySaveDTO app保存评论回复接口请求类
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/7 17:37
     */
    @PostMapping(value = "/saveAtlasWorkCommentReply")
    @ApiOperation(value = "保存评论回复接口", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<String> saveAtlasWorkCommentReply(
            @Valid AppAtlasWorkCommentReplySaveDTO appAtlasWorkCommentReplySaveDTO) {
        try {
            return this.appAtlasService.saveAtlasWorkCommentReply(appAtlasWorkCommentReplySaveDTO);
        } catch (Exception e) {
            log.error("app保存评论回复接口失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
        }
    }
}
