package com.ruoyi.web.controller.portal;

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.annotation.Anonymous;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/portal/notice")
public class PortalNoticeController extends BaseController {

    @Autowired
    private ISysNoticeService noticeService;

    @Anonymous
    @GetMapping("/list")
    public TableDataInfo getNoticeList(SysNotice notice) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    @Anonymous
    @GetMapping("/{id}")
    public AjaxResult getNoticeDetail(@PathVariable("id") Long id) {
        SysNotice notice = noticeService.selectNoticeById(id);
        return AjaxResult.success(notice);
    }

    @Anonymous
    @GetMapping("/search")
    public AjaxResult searchNotice(@RequestParam String keyword) {
        SysNotice notice = new SysNotice();
        notice.setNoticeTitle(keyword);
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return AjaxResult.success(list);
    }

    @Anonymous
    @GetMapping("/hot")
    public AjaxResult getHotNoticeList() {
        SysNotice notice = new SysNotice();
        notice.setStatus("0");
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return AjaxResult.success(list);
    }

    @Anonymous
    @GetMapping("/archive")
    public AjaxResult getArchiveList() {
        Map<String, Object> archiveData = new HashMap<>();
        archiveData.put("2024", 25);
        archiveData.put("2023", 156);
        archiveData.put("2022", 128);
        archiveData.put("2021", 98);
        return AjaxResult.success(archiveData);
    }

    /**
     * 获取通知公告列表（无分页）
     */
    @Anonymous
    @GetMapping("/list/all")
    public AjaxResult getNoticeListAll(SysNotice notice) {
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return AjaxResult.success(list);
    }
}
