package com.ruoyi.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.Notify;
import com.ruoyi.project.system.service.INotifyService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 通知管理Controller
 *
 * @author yf
 * @date 2020-07-07
 */
@Api("通知模块")
@RestController
@RequestMapping("/system/notify")
public class NotifyController extends BaseController
{
    @Autowired
    private INotifyService notifyService;

    /**
     * 查询通知管理列表
     */
    @ApiOperation("已发列表")
    @PreAuthorize("@ss.hasPermi('system:notify:list')")
    @GetMapping("/list")
    public TableDataInfo list(Notify notify)
    {
        startPage();
        List<Notify> list = notifyService.selectNotifyList(notify);
        return getDataTable(list);
    }
    /**
     * 查询通知管理列表
     */
    @ApiOperation("收取列表-个人")
    @PreAuthorize("@ss.hasPermi('system:notify:recvList')")
    @GetMapping("/recvPerList")
    public TableDataInfo recvPerList(Notify notify)
    {
        startPage();
        List<Notify> list = notifyService.selectRecvNotifyList(notify,Long.parseLong("0"));
        return getDataTable(list);
    }
    @ApiOperation("收取列表-部门")
    @PreAuthorize("@ss.hasPermi('system:notify:recvList')")
    @GetMapping("/recvDeptList")
    public TableDataInfo recvDeptList(Notify notify)
    {
        startPage();
        List<Notify> list = notifyService.selectRecvNotifyList(notify,Long.parseLong("1"));
        return getDataTable(list);
    }

    /**
     * 导出通知管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:notify:export')")
    @Log(title = "通知管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Notify notify)
    {
        List<Notify> list = notifyService.selectNotifyList(notify);
        ExcelUtil<Notify> util = new ExcelUtil<Notify>(Notify.class);
        return util.exportExcel(list, "notify");
    }

    /**
     * 获取通知管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:notify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(notifyService.selectNotifyById(id));
    }

    /**
     * 新增通知管理
     */
    @PreAuthorize("@ss.hasPermi('system:notify:add')")
    @Log(title = "通知管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Notify notify)
    {
        return toAjax(notifyService.insertNotify(notify));
    }

    /**
     * 修改通知管理
     */
    @PreAuthorize("@ss.hasPermi('system:notify:edit')")
    @Log(title = "通知管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Notify notify)
    {
        return toAjax(notifyService.updateNotify(notify));
    }

    /**
     * 删除通知管理
     */
    @PreAuthorize("@ss.hasPermi('system:notify:remove')")
    @Log(title = "通知管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(notifyService.deleteNotifyByIds(ids));
    }
}
