package com.younike.admin;

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.younike.common.annotation.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.system.domain.IndexBanner;
import com.younike.system.service.IIndexBannerService;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.common.core.page.TableDataInfo;

/**
 * 首页轮播Controller
 * 
 * @author elev
 * @date 2022-01-13
 */
@Api("首页轮播接口")
@RestController
@RequestMapping("/admin/banner")
public class AdminIndexBannerController extends BaseController {
    @Autowired
    private IIndexBannerService indexBannerService;

    /**
     * 查询首页轮播列表
     */
    @ApiOperation("查询首页轮播列表")
    @PreAuthorize("@ss.hasPermi('system:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(IndexBanner indexBanner) {
        startPage();
        List<IndexBanner> list = indexBannerService.selectIndexBannerList(indexBanner);
        return getDataTable(list);
    }

    /**
     * 导出首页轮播列表
     */
    @ApiOperation("导出首页轮播列表")
    @PreAuthorize("@ss.hasPermi('system:banner:export')")
    @Log(title = "首页轮播", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(IndexBanner indexBanner) {
        List<IndexBanner> list = indexBannerService.selectIndexBannerList(indexBanner);
        ExcelUtil<IndexBanner> util = new ExcelUtil<IndexBanner>(IndexBanner.class);
        return util.exportExcel(list, "首页轮播数据");
    }

    /**
     * 获取首页轮播详细信息
     */
    @ApiOperation("获取首页轮播详细信息")
    @PreAuthorize("@ss.hasPermi('system:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(indexBannerService.selectIndexBannerById(id));
    }

    /**
     * 新增首页轮播
     */
    @ApiOperation("新增首页轮播")
    @PreAuthorize("@ss.hasPermi('system:banner:add')")
    @Log(title = "首页轮播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IndexBanner indexBanner) {
        return toAjax(indexBannerService.insertIndexBanner(indexBanner));
    }

    /**
     * 修改首页轮播
     */
    @ApiOperation("修改首页轮播")
    @PreAuthorize("@ss.hasPermi('system:banner:edit')")
    @Log(title = "首页轮播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IndexBanner indexBanner) {
        return toAjax(indexBannerService.updateIndexBanner(indexBanner));
    }

    /**
     * 删除首页轮播
     */
    @ApiOperation("删除首页轮播")
    @PreAuthorize("@ss.hasPermi('system:banner:remove')")
    @Log(title = "首页轮播", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(indexBannerService.deleteIndexBannerByIds(ids));
    }
}
