package com.ruoyi.manage.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manage.domain.BaseLocation;
import com.ruoyi.manage.service.IBaseLocationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库位信息维护Controller
 * 
 * @author wh
 * @date 2023-12-11
 */
@Controller
@RequestMapping("/manage/base_aircraft_stand")
public class BaseAircraftStandController extends BaseController
{
    private String prefix = "manage/base_aircraft_stand";

    @Autowired
    private IBaseLocationService baseLocationService;

    @RequiresPermissions("manage:base_aircraft_stand:view")
    @GetMapping()
    public String base_location()
    {
        return prefix + "/base_aircraft_stand";
    }

    /**
     * 查询库位信息维护列表
     */
    @RequiresPermissions("manage:base_aircraft_stand:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseLocation baseLocation)
    {
        startPage();
        baseLocation.setStoteTag(2L);
        List<BaseLocation> list = baseLocationService.selectBaseLocationList(baseLocation);
        return getDataTable(list);
    }

    /**
     * 导出库位信息维护列表
     */
    @RequiresPermissions("manage:base_aircraft_stand:export")
    @Log(title = "库位信息维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseLocation baseLocation)
    {
        List<BaseLocation> list = baseLocationService.selectBaseLocationList(baseLocation);
        ExcelUtil<BaseLocation> util = new ExcelUtil<BaseLocation>(BaseLocation.class);
        return util.exportExcel(list, "库位信息维护数据");
    }

    /**
     * 新增库位信息维护
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存库位信息维护
     */
    @RequiresPermissions("manage:base_aircraft_stand:add")
    @Log(title = "库位信息维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseLocation baseLocation)
    {
        return toAjax(baseLocationService.insertBaseLocation(baseLocation));
    }

    /**
     * 修改库位信息维护
     */
    @RequiresPermissions("manage:base_aircraft_stand:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap)
    {
        BaseLocation baseLocation = baseLocationService.selectBaseLocationByObjid(objid);
        mmap.put("baseLocation", baseLocation);
        return prefix + "/edit";
    }

    /**
     * 修改保存库位信息维护
     */
    @RequiresPermissions("manage:base_aircraft_stand:edit")
    @Log(title = "库位信息维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseLocation baseLocation)
    {
        return toAjax(baseLocationService.updateBaseLocation(baseLocation));
    }

    /**
     * 删除库位信息维护
     */
    @RequiresPermissions("manage:base_aircraft_stand:remove")
    @Log(title = "库位信息维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseLocationService.deleteBaseLocationByObjids(ids));
    }
}
