package com.ics.system.controller;

import com.ics.common.core.controller.BaseController;
import com.ics.common.core.domain.R;
import com.ics.system.domain.Notice;
import com.ics.system.log.annotation.OperLog;
import com.ics.system.log.enums.BusinessType;
import com.ics.system.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wf.jwtp.annotation.RequiresPermissions;

/**
 * 通知公告 提供者
 *
 */
@RestController
@RequestMapping("system/notice")
public class NoticeController extends BaseController {

    @Autowired
    private INoticeService noticeService;

    /**
     * 查询通知公告
     */
    @RequiresPermissions("system:notice:query")
    @GetMapping("get/{noticeId}")
    public Notice get(@PathVariable("noticeId") Long noticeId) {
        return noticeService.selectNoticeById(noticeId);

    }

    /**
     * 查询通知公告列表
     */
    @RequiresPermissions("system:notice:list")
    @GetMapping("list")
    public R list(Notice notice) {
        startPage();
        return result(noticeService.selectNoticeList(notice));
    }


    /**
     * 新增保存通知公告
     */
    @RequiresPermissions("system:notice:add")
    @OperLog(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping("save")
    public R addSave(@RequestBody Notice notice) {
        notice.setCreateBy(getLoginName());
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改保存通知公告
     */
    @RequiresPermissions("system:notice:edit")
    @OperLog(title = "通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public R editSave(@RequestBody Notice notice) {
        notice.setUpdateBy(getLoginName());
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    @RequiresPermissions("system:notice:remove")
    @OperLog(title = "通知公告", businessType = BusinessType.DELETE)
    @PostMapping("remove")
    public R remove(String ids) {
        return toAjax(noticeService.deleteNoticeByIds(ids));
    }

}
