package com.ruoyi.web.controller.dxp.system.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.aspectj.weaver.loadtime.Aj;
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.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dxp.domain.Notice;
import com.ruoyi.dxp.service.INoticeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通知Controller
 * 
 * @author jy
 * @date 2023-01-06
 */
@RestController
@RequestMapping("/system/base/notice")
public class NoticeController extends BaseController
{
    @Autowired
    private INoticeService noticeService;

    /**
     * 查询通知列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Notice notice)
    {
        startPage();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        notice.setUserId(loginUser.getUserId());
        List<Notice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 查询通知数量
     */
    @GetMapping("/count")
    public AjaxResult count(Notice notice)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        notice.setUserId(loginUser.getUserId());
        int i = noticeService.selectNoticeCount(notice);
        return success(i);
    }

    /**
     * 获取通知详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(noticeService.selectNoticeById(id));
    }

    /**
     * 读取
     */
    @GetMapping("/read")
    public AjaxResult read(Long id) {
        Notice notice = noticeService.selectNoticeById(id);
        if (notice == null) {
            return error("通知不存在");
        }

        notice.setStatus("1");
        noticeService.updateNotice(notice);
        return success();
    }

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