package com.ruoyi.manage.controller;

import java.util.List;

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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.BaseAreaUser;
import com.ruoyi.manage.service.IBaseAreaUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 机场区域用户绑定Controller
 *
 * @author wangh
 * @date 2024-01-25
 */
@Controller
@RequestMapping("/manage/base_area_user")
public class BaseAreaUserController extends BaseController {
    private String prefix = "manage/base_area_user";

    @Autowired
    private IBaseAreaUserService baseAreaUserService;

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

    /**
     * 查询机场区域用户绑定列表
     */
    @RequiresPermissions("manage:base_area_user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseAreaUser baseAreaUser) {
        startPage();
        List<BaseAreaUser> list = baseAreaUserService.selectBaseAreaUserList(baseAreaUser);
        return getDataTable(list);
    }

    /**
     * 导出机场区域用户绑定列表
     */
    @RequiresPermissions("manage:base_area_user:export")
    @Log(title = "机场区域用户绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseAreaUser baseAreaUser) {
        List<BaseAreaUser> list = baseAreaUserService.selectBaseAreaUserList(baseAreaUser);
        ExcelUtil<BaseAreaUser> util = new ExcelUtil<BaseAreaUser>(BaseAreaUser.class);
        return util.exportExcel(list, "机场区域用户绑定数据");
    }

    /**
     * 新增机场区域用户绑定
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存机场区域用户绑定
     */
    @RequiresPermissions("manage:base_area_user:add")
    @Log(title = "机场区域用户绑定", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseAreaUser baseAreaUser) {
        List<BaseAreaUser> list = baseAreaUserService.selectBaseAreaUserList(baseAreaUser);
        if (list == null || list.isEmpty()) {
            return toAjax(baseAreaUserService.insertBaseAreaUser(baseAreaUser));
        }
        return error("数据已经维护");
    }

    /**
     * 修改机场区域用户绑定
     */
    @RequiresPermissions("manage:base_area_user:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap) {
        BaseAreaUser baseAreaUser = baseAreaUserService.selectBaseAreaUserByObjid(objid);
        mmap.put("baseAreaUser", baseAreaUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存机场区域用户绑定
     */
    @RequiresPermissions("manage:base_area_user:edit")
    @Log(title = "机场区域用户绑定", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseAreaUser baseAreaUser) {
        List<BaseAreaUser> list = baseAreaUserService.selectBaseAreaUserList(baseAreaUser);
        if (list == null || list.isEmpty()) {
            return toAjax(baseAreaUserService.updateBaseAreaUser(baseAreaUser));
        }
        return error("数据已经维护");
    }

    /**
     * 删除机场区域用户绑定
     */
    @RequiresPermissions("manage:base_area_user:remove")
    @Log(title = "机场区域用户绑定", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(baseAreaUserService.deleteBaseAreaUserByObjids(ids));
    }
}
