package com.xinelu.manage.controller.basesportinfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.basesportinfo.BaseSportInfo;
import com.xinelu.manage.service.basesportinfo.IBaseSportInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 运动知识库Controller
 *
 * @author xinelu
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/system/baseSport")
public class BaseSportInfoController extends BaseController {
    @Resource
    private IBaseSportInfoService baseSportInfoService;

    /**
     * 查询运动知识库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseSport:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSportInfo baseSportInfo) {
        startPage();
        List<BaseSportInfo> list = baseSportInfoService.selectBaseSportInfoList(baseSportInfo);
        return getDataTable(list);
    }

    /**
     * 导出运动知识库列表
     */
    @PreAuthorize("@ss.hasPermi('system:baseSport:export')")
    @Log(title = "运动知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseSportInfo baseSportInfo) {
        List<BaseSportInfo> list = baseSportInfoService.selectBaseSportInfoList(baseSportInfo);
        ExcelUtil<BaseSportInfo> util = new ExcelUtil<>(BaseSportInfo.class);
        util.exportExcel(response, list, "运动知识库数据");
    }

    /**
     * 获取运动知识库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:baseSport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(baseSportInfoService.selectBaseSportInfoById(id));
    }

    /**
     * 新增运动知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseSport:add')")
    @Log(title = "运动知识库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BaseSportInfo baseSportInfo) {
        return toAjax(baseSportInfoService.insertBaseSportInfo(baseSportInfo));
    }

    /**
     * 修改运动知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseSport:edit')")
    @Log(title = "运动知识库", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody BaseSportInfo baseSportInfo) {
        return toAjax(baseSportInfoService.updateBaseSportInfo(baseSportInfo));
    }

    /**
     * 删除运动知识库
     */
    @PreAuthorize("@ss.hasPermi('system:baseSport:remove')")
    @Log(title = "运动知识库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseSportInfoService.deleteBaseSportInfoByIds(ids));
    }
}
