package com.usky.system.controller.web;

import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.common.security.annotation.RequiresPermissions;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.common.core.bean.ApiResult;
import com.usky.system.controller.web.page.TableDataInfo;
import com.usky.system.domain.SysNotice;
import com.usky.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 信息操作处理
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/notice")
public class SysNoticeController extends BaseController
{
    @Autowired
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    @GetMapping("/list")
    public ApiResult<TableDataInfo> list(SysNotice notice)
    {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return ApiResult.success(getDataTable(list));
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    @GetMapping(value = "/{noticeId}")
    public ApiResult getInfo(@PathVariable Long noticeId)
    {
        return ApiResult.success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    @Log(title = "新增-通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@Validated @RequestBody SysNotice notice)
    {
        notice.setCreateBy(SecurityUtils.getUsername());
        return ApiResult.success(toAjax(noticeService.insertNotice(notice)));
    }

    /**
     * 修改通知公告
     */
    @Log(title = "修改-通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@Validated @RequestBody SysNotice notice)
    {
        notice.setUpdateBy(SecurityUtils.getUsername());
        return ApiResult.success(toAjax(noticeService.updateNotice(notice)));
    }

    /**
     * 删除通知公告
     */
    @Log(title = "删除-通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public ApiResult remove(@PathVariable Long[] noticeIds)
    {
        return ApiResult.success(toAjax(noticeService.deleteNoticeByIds(noticeIds)));
    }
}
