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

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.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.blocked.domain.BlockedBootPersonnelTenure;
import com.sundot.airport.blocked.service.IBlockedBootPersonnelTenureService;
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-16
 */
@RestController
@RequestMapping("/blocked/tenure")
public class BlockedBootPersonnelTenureController extends BaseController {
    @Autowired
    private IBlockedBootPersonnelTenureService blockedBootPersonnelTenureService;

    /**
     * 查询开机人员年限分布列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:tenure:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlockedBootPersonnelTenure blockedBootPersonnelTenure) {
        startPage();
        List<BlockedBootPersonnelTenure> list = blockedBootPersonnelTenureService.selectBlockedBootPersonnelTenureList(blockedBootPersonnelTenure);
        return getDataTable(list);
    }

    /**
     * 导出开机人员年限分布列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:tenure:export')")
    @Log(title = "导出开机人员年限分布列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlockedBootPersonnelTenure blockedBootPersonnelTenure) {
        List<BlockedBootPersonnelTenure> list = blockedBootPersonnelTenureService.selectBlockedBootPersonnelTenureList(blockedBootPersonnelTenure);
        ExcelUtil<BlockedBootPersonnelTenure> util = new ExcelUtil<BlockedBootPersonnelTenure>(BlockedBootPersonnelTenure.class);
        util.exportExcel(response, list, "开机人员年限分布数据");
    }

    /**
     * 导入开机人员年限分布列表
     */
    @PreAuthorize("@ss.hasPermi('blocked:rate:import')")
    @Log(title = "导入开机人员年限分布列表", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<BlockedBootPersonnelTenure> util = new ExcelUtil<>(BlockedBootPersonnelTenure.class);
        List<BlockedBootPersonnelTenure> list = util.importExcel(file.getInputStream());
        String message = blockedBootPersonnelTenureService.importData(list, updateSupport);
        return success(message);
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<BlockedBootPersonnelTenure> util = new ExcelUtil<>(BlockedBootPersonnelTenure.class);
        util.importTemplateExcel(response, "开机人员年限分布数据导入模板");
    }

    /**
     * 获取开机人员年限分布详细信息
     */
    @PreAuthorize("@ss.hasPermi('blocked:tenure:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(blockedBootPersonnelTenureService.selectBlockedBootPersonnelTenureById(id));
    }

    /**
     * 新增开机人员年限分布
     */
    @PreAuthorize("@ss.hasPermi('blocked:tenure:add')")
    @Log(title = "开机人员年限分布", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BlockedBootPersonnelTenure blockedBootPersonnelTenure) {
        blockedBootPersonnelTenure.setCreateBy(getUsername());
        return toAjax(blockedBootPersonnelTenureService.insertBlockedBootPersonnelTenure(blockedBootPersonnelTenure));
    }

    /**
     * 修改开机人员年限分布
     */
    @PreAuthorize("@ss.hasPermi('blocked:tenure:edit')")
    @Log(title = "开机人员年限分布", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BlockedBootPersonnelTenure blockedBootPersonnelTenure) {
        blockedBootPersonnelTenure.setUpdateBy(getUsername());
        return toAjax(blockedBootPersonnelTenureService.updateBlockedBootPersonnelTenure(blockedBootPersonnelTenure));
    }

    /**
     * 删除开机人员年限分布
     */
    @PreAuthorize("@ss.hasPermi('blocked:tenure:remove')")
    @Log(title = "开机人员年限分布", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(blockedBootPersonnelTenureService.deleteBlockedBootPersonnelTenureByIds(ids));
    }

    /**
     * 查询开机人员年限分布列表全量
     */
    @PreAuthorize("@ss.hasPermi('blocked:tenure:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(BlockedBootPersonnelTenure blockedBootPersonnelTenure) {
        List<BlockedBootPersonnelTenure> list = blockedBootPersonnelTenureService.selectBlockedBootPersonnelTenureList(blockedBootPersonnelTenure);
        return success(list);
    }
}
