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.SzxcJmHouse;
import com.ruoyi.szxc.service.ISzxcJmHouseService;
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/jmhouse")
public class SzxcJmHouseController extends BaseController
{
    @Autowired
    private ISzxcJmHouseService szxcJmHouseService;

    /**
     * 查询居民房屋关联列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmhouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcJmHouse szxcJmHouse)
    {
        startPage();
        List<SzxcJmHouse> list = szxcJmHouseService.selectSzxcJmHouseList(szxcJmHouse);
        return getDataTable(list);
    }

    /**
     * 导出居民房屋关联列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmhouse:export')")
    @Log(title = "居民房屋关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcJmHouse szxcJmHouse)
    {
        List<SzxcJmHouse> list = szxcJmHouseService.selectSzxcJmHouseList(szxcJmHouse);
        ExcelUtil<SzxcJmHouse> util = new ExcelUtil<SzxcJmHouse>(SzxcJmHouse.class);
        util.exportExcel(response, list, "居民房屋关联数据");
    }

    /**
     * 获取居民房屋关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmhouse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcJmHouseService.selectSzxcJmHouseById(id));
    }

    /**
     * 新增居民房屋关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmhouse:add')")
    @Log(title = "居民房屋关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcJmHouse szxcJmHouse)
    {
        return toAjax(szxcJmHouseService.insertSzxcJmHouse(szxcJmHouse));
    }

    /**
     * 修改居民房屋关联
     */
    @PreAuthorize("@ss.hasPermi('szxc:jmhouse:edit')")
    @Log(title = "居民房屋关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcJmHouse szxcJmHouse)
    {
        return toAjax(szxcJmHouseService.updateSzxcJmHouse(szxcJmHouse));
    }

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