package com.ygtx.gxt.controller;

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

import com.ygtx.common.annotation.Excel;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ygtx.common.annotation.Log;
import com.ygtx.common.core.controller.BaseController;
import com.ygtx.common.core.domain.AjaxResult;
import com.ygtx.common.enums.BusinessType;
import com.ygtx.gxt.domain.GxtScoreRuntime;
import com.ygtx.gxt.service.IGxtScoreRuntimeService;
import com.ygtx.common.utils.poi.ExcelUtil;
import com.ygtx.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

/**
 * 运行时长分值配置Controller
 * 
 * @author ygtx
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/gxt/scoreruntime")
@Api(tags = "运行时长分值配置")
public class GxtScoreRuntimeController extends BaseController
{
    @Autowired
    private IGxtScoreRuntimeService gxtScoreRuntimeService;

    /**
     * 查询运行时长分值配置列表
     */
    @PreAuthorize("@ss.hasPermi('gxt:scoreruntime:list')")
    @ApiOperation("查询运行时长分值配置列表")
    @GetMapping("/list")
    public TableDataInfo list(GxtScoreRuntime gxtScoreRuntime)
    {
        startPage();
        List<GxtScoreRuntime> list = gxtScoreRuntimeService.selectGxtScoreRuntimeList(gxtScoreRuntime);
        return getDataTable(list);
    }

    /**
     * 导出运行时长分值配置列表
     */
    @PreAuthorize("@ss.hasPermi('gxt:scoreruntime:export')")
    @Log(title = "运行时长分值配置", businessType = BusinessType.EXPORT)
    @ApiOperation("导出运行时长分值配置列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxtScoreRuntime gxtScoreRuntime,
                       @RequestParam(value = "exportFields", required = false) String exportFieldsStr)
    {
        List<GxtScoreRuntime> list = gxtScoreRuntimeService.selectGxtScoreRuntimeList(gxtScoreRuntime);
        ExcelUtil<GxtScoreRuntime> util = new ExcelUtil<GxtScoreRuntime>(GxtScoreRuntime.class);
        if (exportFieldsStr != null && !exportFieldsStr.isEmpty()) {
            // 将字符串分割成数组
            String[] exportFields = exportFieldsStr.split(",");
            util.showColumn(exportFields);
        }
        util.exportExcel(response, list, "运行时长分值配置数据");
    }

    /**
     * 获取运行时长分值配置导出字段列表
     */
    @GetMapping("/exportFields")
    @ApiOperation("获取运行时长分值配置导出字段列表")
    public AjaxResult getExportFields() {
        ExcelUtil<GxtScoreRuntime> util = new ExcelUtil<GxtScoreRuntime>(GxtScoreRuntime.class);
        util.init(null, "运行时长分值配置", "", Excel.Type.EXPORT);
        return success(util.getExportFields());
    }

    /**
     * 获取运行时长分值配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('gxt:scoreruntime:query')")
    @ApiOperation("获取运行时长分值配置详细信息")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "Long", paramType = "path", dataTypeClass = Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gxtScoreRuntimeService.selectGxtScoreRuntimeById(id));
    }

    /**
     * 新增运行时长分值配置
     */
    @PreAuthorize("@ss.hasPermi('gxt:scoreruntime:add')")
    @Log(title = "运行时长分值配置", businessType = BusinessType.INSERT)
    @ApiOperation("新增运行时长分值配置")
    @PostMapping
    public AjaxResult add(@RequestBody GxtScoreRuntime gxtScoreRuntime)
    {
        return toAjax(gxtScoreRuntimeService.insertGxtScoreRuntime(gxtScoreRuntime));
    }

    /**
     * 修改运行时长分值配置
     */
    @PreAuthorize("@ss.hasPermi('gxt:scoreruntime:edit')")
    @Log(title = "运行时长分值配置", businessType = BusinessType.UPDATE)
    @ApiOperation("修改运行时长分值配置")
    @PutMapping
    public AjaxResult edit(@RequestBody GxtScoreRuntime gxtScoreRuntime)
    {
        return toAjax(gxtScoreRuntimeService.updateGxtScoreRuntime(gxtScoreRuntime));
    }

    /**
     * 删除运行时长分值配置
     */
    @PreAuthorize("@ss.hasPermi('gxt:scoreruntime:remove')")
    @Log(title = "运行时长分值配置", businessType = BusinessType.DELETE)
    @ApiOperation("删除运行时长分值配置")
    @ApiImplicitParam(name = "ids", value = "主键ID数组", required = true, dataType = "Long[]", paramType = "path", dataTypeClass = Long[].class)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gxtScoreRuntimeService.deleteGxtScoreRuntimeByIds(ids));
    }
}