package cclotus.cloud.gateway.web

import com.ruoyi.system.service.ISysNoticeService
import com.ruoyi.common.core.domain.AjaxResult
import com.ruoyi.common.core.page.TableDataInfo
import com.ruoyi.common.reqParam.PageParam
import com.ruoyi.common.utils.PageUtils.startPage
import com.ruoyi.common.utils.TableDataInfoUtil.getDataTable
import com.ruoyi.system.domain.SysNotice
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
 * 微信小程序端通知公告接口
 */
@RestController
@RequestMapping("/notice")
class NoticeController {

    @Autowired
    lateinit var noticeService: ISysNoticeService

    /**
     * 获取最新公告详细信息
     */
    @GetMapping(value = ["/newest"])
    fun getNewest(): AjaxResult {
        return AjaxResult.success(noticeService.selectNewestNotice())
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @GetMapping(value = ["/{noticeId}"])
    fun getInfo(@PathVariable(name = "noticeId", required = true) noticeId: Long): AjaxResult {
        return AjaxResult.success(noticeService.selectNoticeById(noticeId))
    }

    /**
     * 获取通知公告列表
     */
    @GetMapping("/list")
    fun list(notice: SysNotice, pageParam: PageParam): TableDataInfo {
        startPage(pageParam)
        val list: List<SysNotice> = noticeService.selectNoticeList(notice)
        return getDataTable(list)
    }

}
