package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.InfoContent;
import com.ruoyi.abuwx.service.IInfoContentService;
import com.ruoyi.abuwx.vo.InfoContentVo;
import com.ruoyi.common.annotation.Anonymous;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 lujie
 * @date 2024-12-27
 */
@Api(tags = "咨询信息")
@RestController
@RequestMapping("/info/infoContent")
public class InfoContentController extends BaseController {
    @Autowired
    private IInfoContentService infoContentService;

    /**
     * 查询资讯信息列表
     */
    @Anonymous
    @ApiOperation("查询资讯信息列表")
    @GetMapping("/list")
    public TableDataInfo list(InfoContent infoContent) {
        startPage();
        List<InfoContentVo> infoContentVoList = infoContentService.selectInfoContentVoList(infoContent);
        return getDataTable(infoContentVoList);
    }

    /**
     * 导出资讯信息列表
     */
    @PreAuthorize("@ss.hasPermi('info:InfoContent:export')")
    @Log(title = "资讯信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoContent infoContent) {
        List<InfoContent> list = infoContentService.selectInfoContentList(infoContent);
        ExcelUtil<InfoContent> util = new ExcelUtil<InfoContent>(InfoContent.class);
        util.exportExcel(response, list, "资讯信息数据");
    }

    /**
     * 获取资讯信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:InfoContent:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoContentService.selectInfoContentById(id));
    }

    /**
     * 新增资讯信息
     */
    @PreAuthorize("@ss.hasPermi('info:InfoContent:add')")
    @Log(title = "资讯信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoContent infoContent) {
        return toAjax(infoContentService.insertInfoContent(infoContent));
    }

    /**
     * 修改资讯信息
     */
    @PreAuthorize("@ss.hasPermi('info:InfoContent:edit')")
    @Log(title = "资讯信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoContent infoContent) {
        return toAjax(infoContentService.updateInfoContent(infoContent));
    }

    /**
     * 删除资讯信息
     */
    @PreAuthorize("@ss.hasPermi('info:InfoContent:remove')")
    @Log(title = "资讯信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoContentService.deleteInfoContentByIds(ids));
    }
}
