package com.ruoyi.ibs.list.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.ibs.list.domain.CustDeptUserGrid;
import com.ruoyi.ibs.list.service.ICustDeptUserGridService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 客户与机构，用户，网格关联关系（暂时存放假的管户关系）Controller
 *
 * @author ruoyi
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/system/grid")
public class CustDeptUserGridController extends BaseController {
    @Autowired
    private ICustDeptUserGridService custDeptUserGridService;

    /**
     * 查询客户与机构，用户，网格关联关系（暂时存放假的管户关系）列表
     */
    @PreAuthorize("@ss.hasPermi('system:grid:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustDeptUserGrid custDeptUserGrid) {
        startPage();
        List<CustDeptUserGrid> list = custDeptUserGridService.selectCustDeptUserGridList(custDeptUserGrid);
        return getDataTable(list);
    }

    /**
     * 导出客户与机构，用户，网格关联关系（暂时存放假的管户关系）列表
     */
    @PreAuthorize("@ss.hasPermi('system:grid:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustDeptUserGrid custDeptUserGrid) {
        List<CustDeptUserGrid> list = custDeptUserGridService.selectCustDeptUserGridList(custDeptUserGrid);
        ExcelUtil<CustDeptUserGrid> util = new ExcelUtil<CustDeptUserGrid>(CustDeptUserGrid.class);
        util.exportExcel(response, list, "客户与机构，用户，网格关联关系（暂时存放假的管户关系）数据");
    }

    /**
     * 获取客户与机构，用户，网格关联关系（暂时存放假的管户关系）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:grid:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(custDeptUserGridService.selectCustDeptUserGridById(id));
    }

    /**
     * 新增客户与机构，用户，网格关联关系（暂时存放假的管户关系）
     */
    @PreAuthorize("@ss.hasPermi('system:grid:add')")
    @PostMapping
    public AjaxResult add(@RequestBody CustDeptUserGrid custDeptUserGrid) {
        return toAjax(custDeptUserGridService.insertCustDeptUserGrid(custDeptUserGrid));
    }

    /**
     * 修改客户与机构，用户，网格关联关系（暂时存放假的管户关系）
     */
    @PreAuthorize("@ss.hasPermi('system:grid:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody CustDeptUserGrid custDeptUserGrid) {
        return toAjax(custDeptUserGridService.updateCustDeptUserGrid(custDeptUserGrid));
    }

    /**
     * 删除客户与机构，用户，网格关联关系（暂时存放假的管户关系）
     */
    @PreAuthorize("@ss.hasPermi('system:grid:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(custDeptUserGridService.deleteCustDeptUserGridByIds(ids));
    }
}
