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.school.atlas.service.CoreAtlasManagementService;
import com.yida.data.school.dto.atlas.AtlasSaveDTO;
import com.yida.data.school.dto.atlas.AtlasSelectPageDTO;
import com.yida.data.school.vo.atlas.AtlasDetailVO;
import com.yida.data.school.vo.atlas.AtlasSelectPageVO;
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/9/2
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "图集-后台")
@RequestMapping(value = "/atlas/atlasManagement", produces = MediaType.APPLICATION_JSON_VALUE)
public class CoreAtlasManagementController {

    private final CoreAtlasManagementService coreAtlasManagementService;

    /**
     * 查询图集列表数据
     *
     * @param atlasSelectPageDTO 图集后台列表请求类
     * @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 11:08
     */
    @PostMapping(value = "/listAtlasPage")
    @ApiOperation(value = "查询图集列表数据", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<IPage<AtlasSelectPageVO>> listAtlasPage(@Valid AtlasSelectPageDTO atlasSelectPageDTO) {
        return this.coreAtlasManagementService.listAtlasPage(atlasSelectPageDTO);
    }

    /**
     * 保存图集数据
     *
     * @param atlasSaveDTO 保存图集请求类
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/2 13:31
     */
    @PostMapping(value = "/saveAtlas", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "保存图集数据", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> saveAtlas(@Valid @RequestBody AtlasSaveDTO atlasSaveDTO) {
        return this.coreAtlasManagementService.saveAtlas(atlasSaveDTO);
    }

    /**
     * 获取图集详情
     *
     * @param atlasId 图集id
     * @return com.yida.data.common.core.common.ResultBean<com.yida.data.atlas.vo.AtlasDetailVO>
     * @author ZYJ
     * @date 2021/9/2 13:48
     */
    @ApiOperation("获取图集详情")
    @GetMapping(value = "/getAtlasInfo")
    public ResultBean<AtlasDetailVO> getAtlasInfo(
            @ApiParam(value = "图集id", required = true) @RequestParam Long atlasId) {
        return this.coreAtlasManagementService.getAtlasInfo(atlasId);
    }

    /**
     * 批量删除图集
     *
     * @param ids 数据id集合
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/2 13:56
     */
    @ApiOperation(value = "批量删除图集", consumes = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/deleteAtlasBatch", consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResultBean<String> deleteAtlasBatch(
            @ApiParam(value = "数据id集合", required = true) @RequestBody Long[] ids) {
        return this.coreAtlasManagementService.deleteAtlasBatch(ids);
    }

    /**
     * 启用或停用图集
     *
     * @param atlasId      图集id
     * @param enableStatus 需要设置的启用或停用状态
     * @return com.yida.data.common.core.common.ResultBean<java.lang.String>
     * @author ZYJ
     * @date 2021/9/2 14:34
     */
    @PostMapping(value = "/updateEnableStatus")
    @ApiOperation(value = "启用或停用图集", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public ResultBean<String> updateEnableStatus(
            @ApiParam(value = "图集id", required = true) @RequestParam Long atlasId,
            @ApiParam(value = "需要设置的启用或停用状态. 启用图集: 1, 停用图集: 0", required = true) @RequestParam Integer enableStatus) {
        return this.coreAtlasManagementService.updateEnableStatus(atlasId, enableStatus);
    }
}
