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

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

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.BasePerformanceIndicator;
import com.sundot.airport.system.service.IBasePerformanceIndicatorService;
import com.sundot.airport.common.utils.poi.ExcelUtil;
import com.sundot.airport.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 考核指标Controller
 *
 * @author ruoyi
 * @date 2026-04-28
 */
@RestController
@RequestMapping("/system/indicator")
public class BasePerformanceIndicatorController extends BaseController {
    @Autowired
    private IBasePerformanceIndicatorService basePerformanceIndicatorService;

    /**
     * 查询考核指标列表
     */
    @PreAuthorize("@ss.hasPermi('system:indicator:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasePerformanceIndicator basePerformanceIndicator) {
        startPage();
        List<BasePerformanceIndicator> list = basePerformanceIndicatorService.selectBasePerformanceIndicatorList(basePerformanceIndicator);
        return getDataTable(list);
    }

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

    /**
     * 导入考核指标列表
     */
    @PreAuthorize("@ss.hasPermi('system:indicator:import')")
    @Log(title = "导入考核指标列表", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<BasePerformanceIndicator> util = new ExcelUtil<>(BasePerformanceIndicator.class);
        List<BasePerformanceIndicator> list = util.importExcel(file.getInputStream());
        String message = basePerformanceIndicatorService.importData(list, updateSupport);
        return success(message);
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<BasePerformanceIndicator> util = new ExcelUtil<>(BasePerformanceIndicator.class);
        util.importTemplateExcel(response, "考核指标数据导入模板");
    }

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

    /**
     * 新增考核指标
     */
    @PreAuthorize("@ss.hasPermi('system:indicator:add')")
    @Log(title = "考核指标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasePerformanceIndicator basePerformanceIndicator) {
        basePerformanceIndicator.setCreateBy(getUsername());
        return toAjax(basePerformanceIndicatorService.insertBasePerformanceIndicator(basePerformanceIndicator));
    }

    /**
     * 修改考核指标
     */
    @PreAuthorize("@ss.hasPermi('system:indicator:edit')")
    @Log(title = "考核指标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasePerformanceIndicator basePerformanceIndicator) {
        basePerformanceIndicator.setUpdateBy(getUsername());
        return toAjax(basePerformanceIndicatorService.updateBasePerformanceIndicator(basePerformanceIndicator));
    }

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