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.CoreAtlasManagementDetailsService;
import com.yida.data.school.dto.atlas.AtlasDetailsSaveDTO;
import com.yida.data.school.dto.atlas.AtlasDetailsSelectPageDTO;
import com.yida.data.school.vo.atlas.AtlasDetailsSelectPageVO;
import com.yida.data.school.vo.atlas.AtlasDetailsVO;
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;
import java.util.List;

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

    private final CoreAtlasManagementDetailsService coreAtlasManagementDetailsService;

    /**
     * 查询图集作品列表数据
     *
     * @param atlasDetailsSelectPageDTO 图集作品后台列表请求类
     * @return com.yida.data.common.core.common.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < com.yida.data.atlas.vo.AtlasDetailsSelectPageVO>>
     * @author ZYJ
     * @date 2021/9/2 15:18
     */
    @PostMapping(value = "/listAtlasDetailsPage")
    @ApiOperation(value = "查询图集作品列表数据", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<IPage<AtlasDetailsSelectPageVO>> listAtlasDetailsPage(
            @Valid AtlasDetailsSelectPageDTO atlasDetailsSelectPageDTO) {
        try {
            return this.coreAtlasManagementDetailsService.listAtlasDetailsPage(atlasDetailsSelectPageDTO);
        } catch (Exception e) {
            log.error("查询图集作品列表数据失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

    /**
     * 保存图集作品数据
     *
     * @param list 保存图集作品请求类集合
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/2 15:19
     */
    @PostMapping(value = "/saveAtlasDetails", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "保存图集作品数据", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> saveAtlasDetails(@RequestBody List<AtlasDetailsSaveDTO> list) {
        try {
            return this.coreAtlasManagementDetailsService.saveAtlasDetails(list);
        } catch (Exception e) {
            log.error("保存图集作品数据失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.SAVE_FAIL.getValue());
        }
    }

    /**
     * 获取图集作品数据
     *
     * @param atlasDetailsId 图集作品id
     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.atlas.vo.AtlasDetailsVO>
     * @author ZYJ
     * @date 2021/9/2 15:21
     */
    @ApiOperation("获取图集作品数据")
    @GetMapping(value = "/getAtlasDetailsInfo")
    public ResultBean<AtlasDetailsVO> getAtlasDetailsInfo(
            @ApiParam(value = "图集作品id", required = true) @RequestParam Long atlasDetailsId) {
        try {
            return this.coreAtlasManagementDetailsService.getAtlasDetailsInfo(atlasDetailsId);
        } catch (Exception e) {
            log.error("获取图集作品数据失败: {}", e.getMessage(), e);
            return ResultBean.buildError(ResultMsgType.QUERY_FAIL.getValue());
        }
    }

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