package com.ygtx.gxt.controller;

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

import com.ygtx.common.annotation.Excel;
import com.ygtx.gxt.service.IGxtEquipmentService;
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.GxtFanInspectionScore;
import com.ygtx.gxt.service.IGxtFanInspectionScoreService;
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 ruoyi
 * @date 2025-11-06
 */
@RestController
@RequestMapping("/gxt/fanInspectionScore")
@Api(tags = "风机类型检查分值")
public class GxtFanInspectionScoreController extends BaseController
{
    @Autowired
    private IGxtFanInspectionScoreService gxtFanInspectionScoreService;

    @Autowired
    private IGxtEquipmentService gxtEquipmentService;

    /**
     * 查询风机类型检查分值列表
     */
    @PreAuthorize("@ss.hasPermi('gxt:scorefaninspection:list')")
    @ApiOperation("查询风机类型检查分值列表")
    @GetMapping("/list")
    public TableDataInfo list(GxtFanInspectionScore gxtFanInspectionScore)
    {
        startPage();
        List<GxtFanInspectionScore> list = gxtFanInspectionScoreService.selectGxtFanInspectionScoreList(gxtFanInspectionScore);
        return getDataTable(list);
    }

    /**
     * 导出风机类型检查分值列表
     */
    @PreAuthorize("@ss.hasPermi('gxt:scorefaninspection:export')")
    @Log(title = "风机类型检查分值", businessType = BusinessType.EXPORT)
    @ApiOperation("导出风机类型检查分值列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxtFanInspectionScore gxtFanInspectionScore,
                       @RequestParam(value = "exportFields", required = false) String exportFieldsStr)
    {
        List<GxtFanInspectionScore> list = gxtFanInspectionScoreService.selectGxtFanInspectionScoreList(gxtFanInspectionScore);
        ExcelUtil<GxtFanInspectionScore> util = new ExcelUtil<GxtFanInspectionScore>(GxtFanInspectionScore.class);
        if (exportFieldsStr != null && !exportFieldsStr.isEmpty()) {
            // 将字符串分割成数组
            String[] exportFields = exportFieldsStr.split(",");
            util.showColumn(exportFields);
        }
        util.exportExcel(response, list, "风机类型检查分值数据");
    }

    /**
     * 获取风机类型检查分值导出字段列表
     */
    @GetMapping("/exportFields")
    @ApiOperation("获取风机类型检查分值导出字段列表")
    public AjaxResult getExportFields() {
        ExcelUtil<GxtFanInspectionScore> util = new ExcelUtil<GxtFanInspectionScore>(GxtFanInspectionScore.class);
        util.init(null, "风机类型检查分值", "", Excel.Type.EXPORT);
        return success(util.getExportFields());
    }

    /**
     * 获取风机类型检查分值详细信息
     */
    @PreAuthorize("@ss.hasPermi('gxt:scorefaninspection: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(gxtFanInspectionScoreService.selectGxtFanInspectionScoreById(id));
    }

    /**
     * 新增风机类型检查分值
     */
    @PreAuthorize("@ss.hasPermi('gxt:scorefaninspection:add')")
    @Log(title = "风机类型检查分值", businessType = BusinessType.INSERT)
    @ApiOperation("新增风机类型检查分值")
    @PostMapping
    public AjaxResult add(@RequestBody GxtFanInspectionScore gxtFanInspectionScore)
    {
        return toAjax(gxtFanInspectionScoreService.insertGxtFanInspectionScore(gxtFanInspectionScore));
    }

    /**
     * 修改风机类型检查分值
     */
    @PreAuthorize("@ss.hasPermi('gxt:scorefaninspection:edit')")
    @Log(title = "风机类型检查分值", businessType = BusinessType.UPDATE)
    @ApiOperation("修改风机类型检查分值")
    @PutMapping
    public AjaxResult edit(@RequestBody GxtFanInspectionScore gxtFanInspectionScore)
    {
        return toAjax(gxtFanInspectionScoreService.updateGxtFanInspectionScore(gxtFanInspectionScore));
    }

    /**
     * 删除风机类型检查分值
     */
    @PreAuthorize("@ss.hasPermi('gxt:scorefaninspection: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(gxtFanInspectionScoreService.deleteGxtFanInspectionScoreByIds(ids));
    }

    /**
     * 获取所有风机类型列表（去重）
     */
    @ApiOperation("获取所有风机类型列表（去重）")
    @GetMapping("/fanTypes")
    public AjaxResult listFanTypes()
    {
        List<String> list = gxtEquipmentService.selectAllModels();
        return AjaxResult.success(list);
    }

    /**
     * 根据风机类型查询检查类型列表
     */
    @ApiOperation("根据风机类型查询检查类型列表")
    @ApiImplicitParam(name = "fanType", value = "风机类型", required = true, dataType = "String", paramType = "path", dataTypeClass = String.class)
    @GetMapping("/inspectionTypes/{fanType}")
    public AjaxResult listInspectionTypesByFanType(@PathVariable String fanType)
    {
        List<GxtFanInspectionScore> list = gxtFanInspectionScoreService.selectGxtFanInspectionScoreByFanType(fanType);
        return AjaxResult.success(list);
    }
}