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

/**
 * 位置Controller
 *
 * @author ruoyi
 * @date 2025-07-09
 */
@RestController
@RequestMapping("/system/position")
public class BasePositionController extends BaseController {
    @Autowired
    private IBasePositionService basePositionService;

    /**
     * 查询位置列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:list')")
    @GetMapping("/list")
    public AjaxResult list(BasePosition basePosition) {
        List<BasePosition> list = basePositionService.selectBasePositionList(basePosition);
        return success(list);
    }

    /**
     * 导出位置列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:export')")
    @Log(title = "位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasePosition basePosition) {
        List<BasePosition> list = basePositionService.selectBasePositionList(basePosition);
        ExcelUtil<BasePosition> util = new ExcelUtil<BasePosition>(BasePosition.class);
        util.exportExcel(response, list, "位置数据");
    }

    /**
     * 获取位置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(basePositionService.selectBasePositionById(id));
    }

    /**
     * 新增位置
     */
    @PreAuthorize("@ss.hasPermi('system:position:add')")
    @Log(title = "位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasePosition basePosition) {
        basePosition.setCreateBy(getUsername());
        return toAjax(basePositionService.insertBasePosition(basePosition));
    }

    /**
     * 修改位置
     */
    @PreAuthorize("@ss.hasPermi('system:position:edit')")
    @Log(title = "位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasePosition basePosition) {
        basePosition.setUpdateBy(getUsername());
        return toAjax(basePositionService.updateBasePosition(basePosition));
    }

    /**
     * 删除位置
     */
    @PreAuthorize("@ss.hasPermi('system:position:remove')")
    @Log(title = "位置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(basePositionService.deleteBasePositionByIds(ids));
    }

    /**
     * 查询位置列表树形结构
     */
    @PreAuthorize("@ss.hasPermi('system:position:list')")
    @GetMapping("/listTree")
    public AjaxResult listTree(BasePosition basePosition) {
        return success(basePositionService.selectBasePositionListTree(basePosition));
    }
}
