package com.srs.web.controller.system;

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

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.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;

import com.srs.system.domain.SysDeptMap;
import com.srs.system.service.ISysDeptMapService;
import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.utils.poi.ExcelUtil;
import com.srs.common.enums.BusinessType;
import com.srs.common.annotation.Log;
import com.srs.common.core.page.TableDataInfo;

/**
 * 部门映射Controller
 *
 * @author srs
 * @date 2024-05-13
 */
@RestController
@RequestMapping("/system/deptmap")
@Api(value = "部门映射管理", tags = "部门映射管理")
public class SysDeptMapController extends BaseController {
    @Autowired
    private ISysDeptMapService sysDeptMapService;

    /**
     * 查询部门映射列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptmap:list')")
    @GetMapping("/list")
    @ApiOperation("查询部门映射列表")
    public TableDataInfo list(SysDeptMap sysDeptMap) {
        startPage();
        List<SysDeptMap> list = sysDeptMapService.selectSysDeptMapList(sysDeptMap);
        return getDataTable(list);
    }

    /**
     * 导出部门映射列表
     */
    @PreAuthorize("@ss.hasPermi('system:deptmap:export')")
    @Log(title = "部门映射", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出部门映射列表")
    public void export(HttpServletResponse response, SysDeptMap sysDeptMap) {
        List<SysDeptMap> list = sysDeptMapService.selectSysDeptMapList(sysDeptMap);
        ExcelUtil<SysDeptMap> util = new ExcelUtil<SysDeptMap>(SysDeptMap.class);
        util.exportExcel(response, list, "部门映射数据");
    }

    /**
     * 获取部门映射详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:deptmap:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取部门映射详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysDeptMapService.selectSysDeptMapById(id));
    }

    /**
     * 新增部门映射
     */
    @PreAuthorize("@ss.hasPermi('system:deptmap:add')")
    @Log(title = "部门映射", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增部门映射")
    public AjaxResult add(@RequestBody SysDeptMap sysDeptMap) {
        return toAjax(sysDeptMapService.insertSysDeptMap(sysDeptMap));
    }

    /**
     * 修改部门映射
     */
    @PreAuthorize("@ss.hasPermi('system:deptmap:edit')")
    @Log(title = "部门映射", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改部门映射")
    public AjaxResult edit(@RequestBody SysDeptMap sysDeptMap) {
        return toAjax(sysDeptMapService.updateSysDeptMap(sysDeptMap));
    }

    /**
     * 删除部门映射
     */
    @PreAuthorize("@ss.hasPermi('system:deptmap:remove')")
    @Log(title = "部门映射", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    @ApiOperation("删除部门映射")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysDeptMapService.deleteSysDeptMapByIds(ids));
    }
}
