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.dto.ReLocationDto;
import com.vctgo.system.api.domain.SysReLocationClass;
import com.vctgo.system.service.ISysReLocationClassService;
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("/sysReLocationClass")
public class SysReLocationClassController extends BaseController
{
    @Autowired
    private ISysReLocationClassService sysReLocationClassService;

    /**
     * 查询位置与班级关联列表
     */
    @RequiresPermissions("system:sysReLocationClass:page")
    @GetMapping("/page")
    public AjaxResult pageList(SysReLocationClass sysReLocationClass)
    {
        IPage<SysReLocationClass> list = sysReLocationClassService.selectSysReLocationClassPage(sysReLocationClass);
        return AjaxResult.success(list);
    }

    /**
     * 查询位置与班级关联列表
     */
    @GetMapping("/external/list")
    public AjaxResult locationDataList(ReLocationDto reLocationDto)
    {
        List<ReLocationDto> reLocationDtoList = sysReLocationClassService.selectLocationInfoByParam(reLocationDto);
        return AjaxResult.success(reLocationDtoList);
    }

    /**
     * 导出位置与班级关联列表
     */
    @RequiresPermissions("system:sysReLocationClass:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysReLocationClass sysReLocationClass)
    {
        List<SysReLocationClass> list = sysReLocationClassService.selectSysReLocationClassList(sysReLocationClass);
        ExcelUtil<SysReLocationClass> util = new ExcelUtil<SysReLocationClass>(SysReLocationClass.class);
        util.exportExcel(response, list, "位置与班级关联数据");
    }

    /**
     * 获取位置与班级关联详细信息
     */
    @RequiresPermissions("system:sysReLocationClass:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success((sysReLocationClassService.selectSysReLocationClassById(id)));
    }

    /**
     * 新增位置与班级关联
     */
    @RequiresPermissions("system:sysReLocationClass:add")
    @PostMapping
    public AjaxResult add(@RequestBody SysReLocationClass sysReLocationClass)
    {
        return toAjax(sysReLocationClassService.insertSysReLocationClass(sysReLocationClass));
    }

    /**
     * 修改位置与班级关联
     */
    @RequiresPermissions("system:sysReLocationClass:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SysReLocationClass sysReLocationClass)
    {
        return toAjax(sysReLocationClassService.updateSysReLocationClass(sysReLocationClass));
    }

    /**
     * 删除位置与班级关联
     */
    @RequiresPermissions("system:sysReLocationClass:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysReLocationClassService.deleteSysReLocationClassByIds(ids));
    }
}
