package com.ruoyi.frequency.platformanswer.controller;

import java.util.List;
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.frequency.platformanswer.entity.PlatformAnswer;
import com.ruoyi.frequency.platformanswer.service.PlatformAnswerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台有问必答Controller
 *
 * @author liwenlong
 * @date 2024-01-24
 */
@RestController
@RequestMapping("/frequency/platformanswer")
public class PlatformAnswerController extends BaseController
{
    @Autowired
    private PlatformAnswerService platformAnswerService;

    /**
     * 查询平台有问必答列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformanswer:list')")
    @PostMapping("/list")
    public TableDataInfo<PlatformAnswer> list(@RequestBody PlatformAnswer platformAnswer)
    {
        startPage();
        List<PlatformAnswer> list = platformAnswerService.selectPlatformAnswerList(platformAnswer);
        return getDataTable(list);
    }

    /**
     * 导出平台有问必答列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformanswer:export')")
    @Log(title = "平台有问必答", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PlatformAnswer platformAnswer)
    {
        List<PlatformAnswer> list = platformAnswerService.selectPlatformAnswerList(platformAnswer);
        ExcelUtil<PlatformAnswer> util = new ExcelUtil<PlatformAnswer>(PlatformAnswer.class);
        return util.exportExcel(list, "平台有问必答数据");
    }

    /**
     * 获取平台有问必答详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformanswer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<PlatformAnswer> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(platformAnswerService.selectPlatformAnswerById(id));
    }

    /**
     * 新增平台有问必答
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformanswer:add')")
    @Log(title = "平台有问必答", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlatformAnswer platformAnswer)
    {
        return toAjax(platformAnswerService.insertPlatformAnswer(platformAnswer));
    }

    /**
     * 修改平台有问必答
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformanswer:edit')")
    @Log(title = "平台有问必答", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlatformAnswer platformAnswer)
    {
        return toAjax(platformAnswerService.updatePlatformAnswer(platformAnswer));
    }

    /**
     * 删除平台有问必答
     */
    @PreAuthorize("@ss.hasPermi('frequency:platformanswer:remove')")
    @Log(title = "平台有问必答", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(platformAnswerService.deletePlatformAnswerByIds(ids,delFlag));
    }
}
