package com.bonus.zlpt.home.controller;

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.BmCarouselDto;
import com.bonus.zlpt.home.pojo.BmCarouselSet;
import com.bonus.zlpt.home.service.BmCarouselSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 轮播图配置(BmCarouselSet)表控制层
 *
 * @author makejava
 * @since 2023-12-03 15:24:10
 */
@Api(value = " 轮播图配置",tags = {"轮播图"})
@RestController
@RequestMapping("bmCarouselSet")
public class BmCarouselSetController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private BmCarouselSetService bmCarouselSetService;

    /**
     * 获取轮播图列表
     * @param
     * @return
     */
    @ApiOperation("获取轮播图列表")
    @PostMapping("/list")
    public TableDataInfo getCarouselChartList(@RequestBody BmCarouselDto bmCarouselDto)
    {
        startPage(bmCarouselDto.getPageNum(), bmCarouselDto.getPageSize());
        List<BmCarouselSet> list = bmCarouselSetService.selectBmCarouseList(bmCarouselDto);
        return getDataTable(list);
    }

    /**
     * 新增轮播图信息
     * @param bmCarouselSet
     * @return
     */
    @ApiOperation("新增轮播图信息")
    @PostMapping("/add")
    public AjaxResult addCarouselChartInfo(@RequestBody BmCarouselSet bmCarouselSet)
    {
        Long userId = SecurityUtils.getUserId();
        bmCarouselSet.setCreator(userId.intValue());
        return toAjax(bmCarouselSetService.insertConfig(bmCarouselSet));
    }

    /**
     * 根据id查询轮播图信息
     * @param id
     * @return
     */
    @ApiOperation("根据id查询轮播图信息")
    @GetMapping("/{id}")
    public AjaxResult getCarouselChartInfo(@PathVariable("id") int id)
    {
        BmCarouselSet bmCarouselSet = bmCarouselSetService.selectListById(id);
        return success(bmCarouselSet);
    }

    /**
     * 编辑轮播图信息
     * @param bmCarouselSet
     * @return
     */
    @ApiOperation("编辑轮播图信息")
    @PutMapping("/update")
    public AjaxResult updateCarouselChartInfo(@RequestBody BmCarouselSet bmCarouselSet)
    {
        return toAjax(bmCarouselSetService.update(bmCarouselSet));
    }

    /**
     * 删除轮播图信息
     * @param id
     * @return
     */
    @ApiOperation("删除轮播图信息")
    @DeleteMapping("/{id}")
    public AjaxResult delCarouselChartInfo(@PathVariable("id") String id)
    {
        return toAjax(bmCarouselSetService.deleteById(id));
    }
}

