package com.ruoyi.szxc.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.szxc.domain.SzxcCsFw;
import com.ruoyi.szxc.service.ISzxcCsFwService;
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 hs
 * @date 2024-03-30
 */
@RestController
@RequestMapping("/szxc/cs_fw")
public class SzxcCsFwController extends BaseController
{
    @Autowired
    private ISzxcCsFwService szxcCsFwService;

    /**
     * 查询场所房屋关联列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:cs_fw:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcCsFw szxcCsFw)
    {
        startPage();
        List<SzxcCsFw> list = szxcCsFwService.selectSzxcCsFwList(szxcCsFw);
        return getDataTable(list);
    }

    /**
     * 导出场所房屋关联列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:cs_fw:export')")
    @Log(title = "场所房屋关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcCsFw szxcCsFw)
    {
        List<SzxcCsFw> list = szxcCsFwService.selectSzxcCsFwList(szxcCsFw);
        ExcelUtil<SzxcCsFw> util = new ExcelUtil<SzxcCsFw>(SzxcCsFw.class);
        util.exportExcel(response, list, "场所房屋关联数据");
    }

    /**
     * 获取场所房屋关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:cs_fw:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcCsFwService.selectSzxcCsFwById(id));
    }

    /**
     * 新增场所房屋关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:cs_fw:add')")
    @Log(title = "场所房屋关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcCsFw szxcCsFw)
    {
        return toAjax(szxcCsFwService.insertSzxcCsFw(szxcCsFw));
    }

    /**
     * 修改场所房屋关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:cs_fw:edit')")
    @Log(title = "场所房屋关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcCsFw szxcCsFw)
    {
        return toAjax(szxcCsFwService.updateSzxcCsFw(szxcCsFw));
    }

    /**
     * 删除场所房屋关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:cs_fw:remove')")
    @Log(title = "场所房屋关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcCsFwService.deleteSzxcCsFwByIds(ids));
    }
}
