package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.sign.Base64;
import com.ruoyi.system.domain.XysArticle;
import com.ruoyi.system.domain.XysCategory;
import com.ruoyi.system.domain.XysImg;
import com.ruoyi.system.mapper.XysArticleMapper;
import com.ruoyi.system.mapper.XysCategoryMapper;
import com.ruoyi.system.service.IXysArticleService;
import com.ruoyi.system.service.IXysCategoryService;
import com.ruoyi.system.service.IXysImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 門戶Controller
 *
 * @author libao
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/door")
public class DoorController extends BaseController
{
    @Autowired
    private IXysArticleService xysArticleService;
    @Autowired
    private IXysImgService xysImgService;
    @Autowired
    private IXysCategoryService categoryService;
    @Autowired
    private XysArticleMapper articleMapper;
    @Autowired
    private XysCategoryMapper categoryMapper;


    /**
     * 首页文章
     */
    @GetMapping("/getHomeArticleList")
    public TableDataInfo getHomeArticleList(XysArticle xysArticle)
    {
        List<XysArticle> list = xysArticleService.selectHomeArticleList(xysArticle);
        return getDataTable(list);
    }

    /**
     * 查询文章列表
     */
    @GetMapping("/getArticleList")
    public TableDataInfo getArticleList(XysArticle xysArticle)
    {
        startPage();
        List<XysArticle> list = xysArticleService.selectXysArticleList(xysArticle);
        return getDataTable(list);
    }

    /**
     * 查询图片列表
     */
    @GetMapping("/getImgList")
    public TableDataInfo getImgList(XysImg xysImg)
    {
        startPage();
        List<XysImg> list = xysImgService.selectXysImgList(xysImg);
        return getDataTable(list);
    }

    /**
     * 获取文章管理详细信息
     */
    @GetMapping(value = "/getArticle/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(xysArticleService.selectXysArticleById(id));
    }

    /**
     * 获取文章管理详细信息
     */
    @GetMapping(value = "/getCategory/{parentId}")
    public AjaxResult getCategory(@PathVariable("parentId") Long parentId)
    {
        XysCategory category = new XysCategory();
        category.setParentId(parentId);
        return success(categoryService.selectXysCategoryList(category));
    }

    /**
     * 下一篇
     */
    @GetMapping(value = "/getNext")
    public AjaxResult getNext(XysArticle xysArticle)
    {
        return success(articleMapper.getNext(xysArticle));
    }

    /**
     * 上一篇
     */
    @GetMapping(value = "/getUp")
    public AjaxResult getUp(XysArticle xysArticle)
    {
        return success(articleMapper.getUp(xysArticle));
    }

    /**
     * 下一篇
     */
    @GetMapping(value = "/getNextCat")
    public AjaxResult getNextCat(XysCategory xysCategory)
    {
        return success(categoryMapper.getNextCat(xysCategory));
    }

    /**
     * 上一篇
     */
    @GetMapping(value = "/getUpCat")
    public AjaxResult getUpCat(XysCategory xysCategory)
    {
        return success(categoryMapper.getUpCat(xysCategory));
    }


    /**
     *
     */
    @GetMapping(value = "/getCategoryById/{id}")
    public AjaxResult getCategoryById(@PathVariable("id") Long Id)
    {
        return success(categoryService.selectXysCategoryById(Id));
    }
}
