package com.ruoyi.web.controller.back;

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.domain.entity.ConsultInfo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IConsultInfoService;
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 ruoyi
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/system/info")
public class ConsultInfoController extends BaseController
{
    @Autowired
    private IConsultInfoService consultInfoService;

    /**
     * 查询咨询列列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConsultInfo consultInfo)
    {
        startPage();
        List<ConsultInfo> list = consultInfoService.selectConsultInfoList(consultInfo);
        return getDataTable(list);
    }

    /**
     * 导出咨询列列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "咨询列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConsultInfo consultInfo)
    {
        List<ConsultInfo> list = consultInfoService.selectConsultInfoList(consultInfo);
        ExcelUtil<ConsultInfo> util = new ExcelUtil<ConsultInfo>(ConsultInfo.class);
        util.exportExcel(response, list, "咨询列数据");
    }

    /**
     * 获取咨询列详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(consultInfoService.selectConsultInfoById(id));
    }

    /**
     * 新增咨询列
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "咨询列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConsultInfo consultInfo)
    {
        return toAjax(consultInfoService.insertConsultInfo(consultInfo));
    }

    /**
     * 修改咨询列
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "咨询列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConsultInfo consultInfo)
    {
        return toAjax(consultInfoService.updateConsultInfo(consultInfo));
    }

    /**
     * 删除咨询列
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "咨询列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(consultInfoService.deleteConsultInfoByIds(ids));
    }
}
