package com.vctgo.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.system.api.domain.SysReLocationArea;
import com.vctgo.system.service.ISysReLocationAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 位置与区域关联Controller
 *
 * @author caesar
 * @date 2023-05-30
 */
@RestController
@RequestMapping("/sysReLocationArea")
public class SysReLocationAreaController extends BaseController
{
    @Autowired
    private ISysReLocationAreaService sysReLocationAreaService;

    /**
     * 查询位置与区域关联列表
     */
    @RequiresPermissions("system:sysReLocationArea:page")
    @GetMapping("/page")
    public AjaxResult pageList(SysReLocationArea sysReLocationArea)
    {
        IPage<SysReLocationArea> list = sysReLocationAreaService.selectSysReLocationAreaPage(sysReLocationArea);
        return AjaxResult.success(list);
    }

    /**
     * 导出位置与区域关联列表
     */
    @RequiresPermissions("system:sysReLocationArea:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysReLocationArea sysReLocationArea)
    {
        List<SysReLocationArea> list = sysReLocationAreaService.selectSysReLocationAreaList(sysReLocationArea);
        ExcelUtil<SysReLocationArea> util = new ExcelUtil<SysReLocationArea>(SysReLocationArea.class);
        util.exportExcel(response, list, "位置与区域关联数据");
    }

    /**
     * 获取位置与区域关联详细信息
     */
    @RequiresPermissions("system:sysReLocationArea:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success((sysReLocationAreaService.selectSysReLocationAreaById(id)));
    }

    /**
     * 新增位置与区域关联
     */
    @RequiresPermissions("system:sysReLocationArea:add")
    @PostMapping
    public AjaxResult add(@RequestBody SysReLocationArea sysReLocationArea)
    {
        return toAjax(sysReLocationAreaService.insertSysReLocationArea(sysReLocationArea));
    }

    /**
     * 修改位置与区域关联
     */
    @RequiresPermissions("system:sysReLocationArea:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SysReLocationArea sysReLocationArea)
    {
        return toAjax(sysReLocationAreaService.updateSysReLocationArea(sysReLocationArea));
    }

    /**
     * 删除位置与区域关联
     */
    @RequiresPermissions("system:sysReLocationArea:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysReLocationAreaService.deleteSysReLocationAreaByIds(ids));
    }
}
