package com.ruoyi.web.work.controller;

import com.ruoyi.common.annotation.Log;
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.enums.BusinessType;
import com.ruoyi.web.work.domain.Notice;
import com.ruoyi.web.work.domain.vo.NoticeVoList;
import com.ruoyi.web.work.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 通知公告
 * @author lsw
 * @date 2024-08-20
 */
@RestController
@RequestMapping("/work/notice")
public class NoticeController extends BaseController {
    @Autowired
    private INoticeService noticeService;

    @PreAuthorize("@ss.hasPermi('work:notice:list')")
    @GetMapping("/list")
    public TableDataInfo list(Notice notice){
        startPage();
        List<NoticeVoList> list = noticeService.selectList(notice);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('work:notice:query')")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id){
        return AjaxResult.success(noticeService.getById(id));
    }

    @PreAuthorize("@ss.hasPermi('work:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Notice notice){
        return toAjax(noticeService.save(notice));
    }

    @PreAuthorize("@ss.hasPermi('work:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Notice notice){
        return toAjax(noticeService.updateById(notice));
    }

    @PreAuthorize("@ss.hasPermi('work:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(noticeService.removeByIds(Arrays.asList(ids)));
    }
}
