package com.srs.web.controller.comprehensive;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.srs.common.annotation.Log;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.enums.BusinessType;
import com.srs.comprehensive.domain.CphMsg;
import com.srs.comprehensive.service.ICphMsgService;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.core.page.TableDataInfo;

/**
 * 消息Controller
 *
 * @author srs
 * @date 2023-07-12
 */
@RestController
@RequestMapping("/system/msg")
public class CphMsgController extends BaseController
{
    @Autowired
    private ICphMsgService cphMsgService;

    /**
     * 查询消息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        CphMsg cphMsg = new CphMsg();
        cphMsg.setReceiver(getUserId());
        startPage();
        List<CphMsg> list = cphMsgService.selectCphMsgList(cphMsg);
        return getDataTable(list);
    }

    /**
     * 导出消息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:msg:export')")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CphMsg cphMsg)
    {
        List<CphMsg> list = cphMsgService.selectCphMsgList(cphMsg);
        ExcelUtil<CphMsg> util = new ExcelUtil<CphMsg>(CphMsg.class);
        util.exportExcel(response, list, "消息数据");
    }

    /**
     * 获取消息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:msg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cphMsgService.selectCphMsgById(id));
    }

    /**
     * 新增消息
     */
//    @PreAuthorize("@ss.hasPermi('system:msg:add')")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CphMsg cphMsg)
    {
        return toAjax(cphMsgService.insertCphMsg(cphMsg));
    }

    /**
     * 修改消息
     */
//    @PreAuthorize("@ss.hasPermi('system:msg:edit')")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody CphMsg cphMsg)
    {
        return toAjax(cphMsgService.updateCphMsg(cphMsg));
    }

    /**
     * 删除消息
     */
//    @PreAuthorize("@ss.hasPermi('system:msg:remove')")
    @Log(title = "消息", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cphMsgService.deleteCphMsgByIds(ids));
    }

    /**
     * 根据学号查询用户ID
     */
    @GetMapping("/getUserIdByStuNo/{stuNo}")
    public AjaxResult getUserIdByStuNo(@PathVariable("stuNo") String stuNo)
    {
        return success(cphMsgService.getUserIdByStuNo(stuNo));
    }
}
