package com.sundot.airport.web.controller.system;

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

import com.sundot.airport.system.domain.BasePerformanceIndicatorCategoryTreeDTO;
import com.sundot.airport.system.domain.BasePerformanceIndicatorCategoryTreeRequestDTO;
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.sundot.airport.common.annotation.Log;
import com.sundot.airport.common.core.controller.BaseController;
import com.sundot.airport.common.core.domain.AjaxResult;
import com.sundot.airport.common.enums.BusinessType;
import com.sundot.airport.system.domain.BasePerformanceIndicatorCategory;
import com.sundot.airport.system.service.IBasePerformanceIndicatorCategoryService;
import com.sundot.airport.common.utils.poi.ExcelUtil;

/**
 * 考核指标分类Controller
 *
 * @author ruoyi
 * @date 2026-04-28
 */
@RestController
@RequestMapping("/system/performanceIndicatorCategory")
public class BasePerformanceIndicatorCategoryController extends BaseController {
    @Autowired
    private IBasePerformanceIndicatorCategoryService basePerformanceIndicatorCategoryService;

    /**
     * 查询考核指标分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:list')")
    @GetMapping("/list")
    public AjaxResult list(BasePerformanceIndicatorCategory basePerformanceIndicatorCategory) {
        List<BasePerformanceIndicatorCategory> list = basePerformanceIndicatorCategoryService.selectBasePerformanceIndicatorCategoryList(basePerformanceIndicatorCategory);
        return success(list);
    }

    /**
     * 导出考核指标分类列表
     */
    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:export')")
    @Log(title = "考核指标分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasePerformanceIndicatorCategory basePerformanceIndicatorCategory) {
        List<BasePerformanceIndicatorCategory> list = basePerformanceIndicatorCategoryService.selectBasePerformanceIndicatorCategoryList(basePerformanceIndicatorCategory);
        ExcelUtil<BasePerformanceIndicatorCategory> util = new ExcelUtil<BasePerformanceIndicatorCategory>(BasePerformanceIndicatorCategory.class);
        util.exportExcel(response, list, "考核指标分类数据");
    }

    /**
     * 获取考核指标分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basePerformanceIndicatorCategoryService.selectBasePerformanceIndicatorCategoryById(id));
    }

    /**
     * 新增考核指标分类
     */
    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:add')")
    @Log(title = "考核指标分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasePerformanceIndicatorCategory basePerformanceIndicatorCategory) {
        basePerformanceIndicatorCategory.setCreateBy(getUsername());
        return toAjax(basePerformanceIndicatorCategoryService.insertBasePerformanceIndicatorCategory(basePerformanceIndicatorCategory));
    }

    /**
     * 修改考核指标分类
     */
    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:edit')")
    @Log(title = "考核指标分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasePerformanceIndicatorCategory basePerformanceIndicatorCategory) {
        basePerformanceIndicatorCategory.setUpdateBy(getUsername());
        return toAjax(basePerformanceIndicatorCategoryService.updateBasePerformanceIndicatorCategory(basePerformanceIndicatorCategory));
    }

    /**
     * 删除考核指标分类
     */
    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:remove')")
    @Log(title = "考核指标分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basePerformanceIndicatorCategoryService.deleteBasePerformanceIndicatorCategoryByIds(ids));
    }

    /**
     * 查询考核指标分类列表树形结构
     */
    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:list')")
    @GetMapping("/listTree")
    public AjaxResult listTree(BasePerformanceIndicatorCategory basePerformanceIndicatorCategory) {
        List<BasePerformanceIndicatorCategory> list = basePerformanceIndicatorCategoryService.selectBasePerformanceIndicatorCategoryListTree(basePerformanceIndicatorCategory);
        return success(list);
    }

    /**
     * 获取分类树及关联指标（支持模糊查询）
     */
    @PreAuthorize("@ss.hasPermi('system:performanceIndicatorCategory:list')")
    @PostMapping("/getCategoryTreeWithIndicatorList")
    public AjaxResult getCategoryTreeWithIndicatorList(@RequestBody BasePerformanceIndicatorCategoryTreeRequestDTO requestDTO) {
        List<BasePerformanceIndicatorCategoryTreeDTO> tree = basePerformanceIndicatorCategoryService.getCategoryTreeWithIndicatorList(requestDTO);
        return AjaxResult.success(tree);
    }
}
