package com.ruoyi.web.controller.notice;

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

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.notice.InfoPinglun;
import com.ruoyi.system.domain.notice.XiaoyuanInfo;
import com.ruoyi.system.service.notice.IXiaoyuanInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.common.core.page.TableDataInfo;

/**
 * 校园安全信息Controller
 * 
 * @author boman
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/system/xiaoYuanInfo")
public class XiaoyuanInfoController extends BaseController
{
    @Autowired
    private IXiaoyuanInfoService xiaoyuanInfoService;

    /**
     * 查询校园安全信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:xiaoYuanInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(XiaoyuanInfo xiaoyuanInfo)
    {
        List<XiaoyuanInfo> list = xiaoyuanInfoService.selectXiaoyuanInfoList(xiaoyuanInfo);
        return getDataTable(list);
    }

    /**
     * 导出校园安全信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:xiaoYuanInfo:export')")
    @Log(title = "校园安全信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XiaoyuanInfo xiaoyuanInfo)
    {
        List<XiaoyuanInfo> list = xiaoyuanInfoService.selectXiaoyuanInfoList(xiaoyuanInfo);
        ExcelUtil<XiaoyuanInfo> util = new ExcelUtil<XiaoyuanInfo>(XiaoyuanInfo.class);
        util.exportExcel(response, list, "校园安全信息数据");
    }

    /**
     * 获取校园安全信息详细信息
     */
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return success(xiaoyuanInfoService.selectXiaoyuanInfoByInfoId(infoId));
    }

    /**
     * 新增校园安全信息
     */
    @PreAuthorize("@ss.hasPermi('system:xiaoYuanInfo:add')")
    @Log(title = "校园安全信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody XiaoyuanInfo xiaoyuanInfo)
    {
        return toAjax(xiaoyuanInfoService.insertXiaoyuanInfo(xiaoyuanInfo));
    }

    /**
     * 修改校园安全信息
     */
    @PreAuthorize("@ss.hasPermi('system:xiaoYuanInfo:edit')")
    @Log(title = "校园安全信息", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody XiaoyuanInfo xiaoyuanInfo)
    {
        return toAjax(xiaoyuanInfoService.updateXiaoyuanInfo(xiaoyuanInfo));
    }

    /**
     * 删除校园安全信息
     */
    @PreAuthorize("@ss.hasPermi('system:xiaoYuanInfo:remove')")
    @Log(title = "校园安全信息", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(xiaoyuanInfoService.deleteXiaoyuanInfoByInfoIds(infoIds));
    }


    /**
     * 新增校园安全信息评论
     */
    @PostMapping("/pingLun")
    public AjaxResult pingLun(@RequestBody InfoPinglun infoPinglun)
    {
        return toAjax(xiaoyuanInfoService.insertInfoPingLun(infoPinglun));
    }

    /**
     * 删除校园安全信息评论
     */
    @PostMapping("/delete/pingLun")
    public AjaxResult deletePingLun(@RequestBody InfoPinglun infoPinglun)
    {
        return toAjax(xiaoyuanInfoService.deletePingLun(infoPinglun));
    }

    /**
     * 新增校园安全信息点赞接口/取消点赞
     */
    @PostMapping("/dianZan")
    public AjaxResult dianZan(@RequestBody XiaoyuanInfo xiaoyuanInfo)
    {
        return xiaoyuanInfoService.dianZan(xiaoyuanInfo);
    }

    /**
     * 新增校园安全信息转发接口
     */
    @PostMapping("/zhuanFa")
    public AjaxResult zhuanFa(@RequestBody XiaoyuanInfo xiaoyuanInfo)
    {
        return xiaoyuanInfoService.zhuanFa(xiaoyuanInfo);
    }

}
