package com.bonus.zlpt.home.controller;

import com.bonus.zlpt.common.core.utils.poi.ExcelUtil;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.core.web.page.TableDataInfo;
import com.bonus.zlpt.common.security.utils.SecurityUtils;
import com.bonus.zlpt.home.pojo.BmCarouselSet;
import com.bonus.zlpt.home.pojo.BmTopicDto;
import com.bonus.zlpt.home.pojo.BmTopicInfo;
import com.bonus.zlpt.home.service.BmTopicInfoService;
import org.springframework.web.bind.annotation.*;

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


/**
 * 专题资讯表(BmTopicInfo)表控制层
 *
 * @author makejava
 * @since 2023-12-04 09:48:36
 */
@RestController
@RequestMapping("bmTopicInfo")
public class BmTopicInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private BmTopicInfoService bmTopicInfoService;

    /**
     * 获取专题资讯列表
     * @param bmTopicDto
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo getSpecialInfoList(@RequestBody BmTopicDto bmTopicDto)
    {
        startPage();
        List<BmTopicInfo> list = bmTopicInfoService.selectSpecialInfoList(bmTopicDto);
        return getDataTable(list);
    }

    /**
     * 新增专题资讯信息
     * @param bmTopicInfo
     * @return
     */
    @PostMapping
    public AjaxResult addCarouselChartInfo(@RequestBody BmTopicInfo bmTopicInfo)
    {
        return toAjax(bmTopicInfoService.insertConfig(bmTopicInfo));
    }

    /**
     * 根据id查询资讯信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getSpecialInfo(@PathVariable("id") String id)
    {
        return toAjax(bmTopicInfoService.selectListById(id));
    }

    /**
     * 编辑专题资讯信息
     * @param bmTopicInfo
     * @return
     */
    @PutMapping
    public AjaxResult updateCarouselChartInfo(@RequestBody BmTopicInfo bmTopicInfo)
    {
        return toAjax(bmTopicInfoService.update(bmTopicInfo));
    }

    /**
     * 删除专题资讯信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult delSpecialInfo(@PathVariable("id") String id)
    {
        return toAjax(bmTopicInfoService.deleteById(id));
    }

    /**
     * 导出专题资讯信息
     * @param response
     * @param bmTopicDto
     */
    @PostMapping("/export")
    public void expSpecialInfo(HttpServletResponse response, BmTopicDto bmTopicDto)
    {
        List<BmTopicInfo> list = bmTopicInfoService.selectSpecialInfoList(bmTopicDto);
        ExcelUtil<BmTopicInfo> util = new ExcelUtil<BmTopicInfo>(BmTopicInfo.class);
        util.exportExcel(response, list, "专题资讯信息");
    }
}

