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.BaseCheckPoint;
import com.sundot.airport.system.service.IBaseCheckPointService;
import com.sundot.airport.common.utils.poi.ExcelUtil;

/**
 * 检查部位Controller
 *
 * @author ruoyi
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/system/point")
public class BaseCheckPointController extends BaseController {
    @Autowired
    private IBaseCheckPointService baseCheckPointService;

    /**
     * 查询检查部位列表
     */
    @PreAuthorize("@ss.hasPermi('system:point:list')")
    @GetMapping("/list")
    public AjaxResult list(BaseCheckPoint baseCheckPoint) {
        List<BaseCheckPoint> list = baseCheckPointService.selectBaseCheckPointList(baseCheckPoint);
        return success(list);
    }

    /**
     * 导出检查部位列表
     */
    @PreAuthorize("@ss.hasPermi('system:point:export')")
    @Log(title = "检查部位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseCheckPoint baseCheckPoint) {
        List<BaseCheckPoint> list = baseCheckPointService.selectBaseCheckPointList(baseCheckPoint);
        ExcelUtil<BaseCheckPoint> util = new ExcelUtil<BaseCheckPoint>(BaseCheckPoint.class);
        util.exportExcel(response, list, "检查部位数据");
    }

    /**
     * 获取检查部位详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:point:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(baseCheckPointService.selectBaseCheckPointById(id));
    }

    /**
     * 新增检查部位
     */
    @PreAuthorize("@ss.hasPermi('system:point:add')")
    @Log(title = "检查部位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseCheckPoint baseCheckPoint) {
        baseCheckPoint.setCreateBy(getUsername());
        return toAjax(baseCheckPointService.insertBaseCheckPoint(baseCheckPoint));
    }

    /**
     * 修改检查部位
     */
    @PreAuthorize("@ss.hasPermi('system:point:edit')")
    @Log(title = "检查部位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseCheckPoint baseCheckPoint) {
        baseCheckPoint.setUpdateBy(getUsername());
        return toAjax(baseCheckPointService.updateBaseCheckPoint(baseCheckPoint));
    }

    /**
     * 删除检查部位
     */
    @PreAuthorize("@ss.hasPermi('system:point:remove')")
    @Log(title = "检查部位", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(baseCheckPointService.deleteBaseCheckPointByIds(ids));
    }

    /**
     * 查询检查部位列表树形结构
     */
    @PreAuthorize("@ss.hasPermi('system:point:list')")
    @GetMapping("/listTree")
    public AjaxResult listTree(BaseCheckPoint baseCheckPoint) {
        List<BaseCheckPoint> list = baseCheckPointService.selectBaseCheckPointListTree(baseCheckPoint);
        return success(list);
    }
}
