package com.ruoyi.web.controller.iit;

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.common.utils.poi.ExcelUtil;
import com.ruoyi.iit.domain.IitPushUserRel;
import com.ruoyi.iit.service.IIitPushUserRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 消息管理Controller
 *
 * @author Hao Li
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/iit/message")
public class IitPushUserRelController extends BaseController {
    @Autowired
    private IIitPushUserRelService iitPushUserRelService;

    /**
     * 查询消息管理列表
     */
    @PreAuthorize("@ss.hasPermi('iit:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(IitPushUserRel iitPushUserRel) {
        startPage();
        List<IitPushUserRel> list = iitPushUserRelService.selectIitPushUserRelList(iitPushUserRel);
        return getDataTable(list);
    }

    /**
     * 查询消息管理列表
     */
    @PreAuthorize("@ss.hasPermi('iit:message:list')")
    @GetMapping("/list/page")
    public TableDataInfo pageList(IitPushUserRel iitPushUserRel) {
        startPage();
        List<IitPushUserRel> list = iitPushUserRelService.selectIitPushUserRelListV2(iitPushUserRel);
        return getDataTable(list);
    }

    /**
     * 导出消息管理列表
     */
    @PreAuthorize("@ss.hasPermi('iit:message:export')")
    @Log(title = "消息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IitPushUserRel iitPushUserRel) {
        List<IitPushUserRel> list = iitPushUserRelService.selectIitPushUserRelList(iitPushUserRel);
        ExcelUtil<IitPushUserRel> util = new ExcelUtil<IitPushUserRel>(IitPushUserRel.class);
        util.exportExcel(response, list, "消息管理数据");
    }

    /**
     * 获取消息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('iit:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(iitPushUserRelService.selectIitPushUserRelById(id));
    }

    /**
     * 获取消息管理详细信息,更新已读状态
     */
    @PreAuthorize("@ss.hasPermi('iit:message:query')")
    @GetMapping(value = "/info/{id}")
    public AjaxResult getMessageInfo(@PathVariable("id") Long id) {
        return success(iitPushUserRelService.getMessageInfo(id));
    }

    /**
     * 新增消息管理
     */
    @PreAuthorize("@ss.hasPermi('iit:message:add')")
    @Log(title = "消息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IitPushUserRel iitPushUserRel) {
        return toAjax(iitPushUserRelService.insertIitPushUserRel(iitPushUserRel));
    }

    /**
     * 修改消息管理
     */
    @PreAuthorize("@ss.hasPermi('iit:message:edit')")
    @Log(title = "消息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IitPushUserRel iitPushUserRel) {
        return toAjax(iitPushUserRelService.updateIitPushUserRel(iitPushUserRel));
    }

    /**
     * 删除消息管理
     */
    @PreAuthorize("@ss.hasPermi('iit:message:remove')")
    @Log(title = "消息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iitPushUserRelService.deleteIitPushUserRelByIds(ids));
    }
}
