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.GxtSafeOperationReward;
import com.ygtx.gxt.service.IGxtSafeOperationRewardService;
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 2026-01-07
 */
@RestController
@RequestMapping("/gxt/safeoperationreward")
@Api(tags = "安全运行奖励")
public class GxtSafeOperationRewardController extends BaseController
{
    @Autowired
    private IGxtSafeOperationRewardService gxtSafeOperationRewardService;

    /**
     * 查询安全运行奖励列表
     */
    @PreAuthorize("@ss.hasPermi('gxt:safeoperationreward:list')")
    @ApiOperation("查询安全运行奖励列表")
    @GetMapping("/list")
    public TableDataInfo list(GxtSafeOperationReward gxtSafeOperationReward)
    {
        startPage();
        List<GxtSafeOperationReward> list = gxtSafeOperationRewardService.selectGxtSafeOperationRewardList(gxtSafeOperationReward);
        return getDataTable(list);
    }

    /**
     * 导出安全运行奖励列表
     */
    @PreAuthorize("@ss.hasPermi('gxt:safeoperationreward:export')")
    @Log(title = "安全运行奖励", businessType = BusinessType.EXPORT)
    @ApiOperation("导出安全运行奖励列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxtSafeOperationReward gxtSafeOperationReward,
                       @RequestParam(value = "exportFields", required = false) String exportFieldsStr)
    {
        List<GxtSafeOperationReward> list = gxtSafeOperationRewardService.selectGxtSafeOperationRewardList(gxtSafeOperationReward);
        ExcelUtil<GxtSafeOperationReward> util = new ExcelUtil<GxtSafeOperationReward>(GxtSafeOperationReward.class);
        if (exportFieldsStr != null && !exportFieldsStr.isEmpty()) {
            // 将字符串分割成数组
            String[] exportFields = exportFieldsStr.split(",");
            util.showColumn(exportFields);
        }
        util.exportExcel(response, list, "安全运行奖励数据");
    }

    /**
     * 获取安全运行奖励导出字段列表
     */
    @GetMapping("/exportFields")
    @ApiOperation("获取安全运行奖励导出字段列表")
    public AjaxResult getExportFields() {
        ExcelUtil<GxtSafeOperationReward> util = new ExcelUtil<GxtSafeOperationReward>(GxtSafeOperationReward.class);
        util.init(null, "安全运行奖励", "", Excel.Type.EXPORT);
        return success(util.getExportFields());
    }

    /**
     * 获取安全运行奖励详细信息
     */
    @PreAuthorize("@ss.hasPermi('gxt:safeoperationreward: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(gxtSafeOperationRewardService.selectGxtSafeOperationRewardById(id));
    }

    /**
     * 新增安全运行奖励
     */
    @PreAuthorize("@ss.hasPermi('gxt:safeoperationreward:add')")
    @Log(title = "安全运行奖励", businessType = BusinessType.INSERT)
    @ApiOperation("新增安全运行奖励")
    @PostMapping
    public AjaxResult add(@RequestBody GxtSafeOperationReward gxtSafeOperationReward)
    {
        return toAjax(gxtSafeOperationRewardService.insertGxtSafeOperationReward(gxtSafeOperationReward));
    }

    /**
     * 修改安全运行奖励
     */
    @PreAuthorize("@ss.hasPermi('gxt:safeoperationreward:edit')")
    @Log(title = "安全运行奖励", businessType = BusinessType.UPDATE)
    @ApiOperation("修改安全运行奖励")
    @PutMapping
    public AjaxResult edit(@RequestBody GxtSafeOperationReward gxtSafeOperationReward)
    {
        return toAjax(gxtSafeOperationRewardService.updateGxtSafeOperationReward(gxtSafeOperationReward));
    }

    /**
     * 删除安全运行奖励
     */
    @PreAuthorize("@ss.hasPermi('gxt:safeoperationreward: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(gxtSafeOperationRewardService.deleteGxtSafeOperationRewardByIds(ids));
    }
}