package com.ruoyi.controller;

import com.ruoyi.response.ResponseData;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.ISysNoticeService;
import com.ruoyi.vo.BodyIdReq;
import com.ruoyi.vo.RyController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 公告
 */
@CrossOrigin
@RestController
@RequestMapping("/api/notice")
@Api(tags = "公告")
public class ApiNoticeController extends RyController {


    @Autowired
    private ISysNoticeService sysNoticeService;

    @PostMapping("/noticeList")
    @ApiOperation(value = "公告", notes = "公告")
    public ResponseData<List<SysNotice>> noticeList(@RequestBody(required = false) String noticeType) {

        SysNotice sysNotice = new SysNotice();
        sysNotice.setNoticeType(noticeType);
        sysNotice.setIsApp(2);
        sysNotice.setStatus("0");
        List<SysNotice> sysNotices = sysNoticeService.selectNoticeList(sysNotice);
        return ResponseData.success(sysNotices);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "公告详情", notes = "公告详情")
    public ResponseData<SysNotice> detail(@Valid @NotNull(message = "id不能为空") @RequestBody BodyIdReq req) {
        return ResponseData.success(this.sysNoticeService.selectNoticeById(req.getId()));
    }

}
