package com.ruoyi.web.controller.proprietorHouse;

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.system.domain.proprietorHouse.ProprietorHouse;
import com.ruoyi.system.service.IProprietorHouseService;
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 boman
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/wuYe/house")
public class ProprietorHouseController extends BaseController
{
    @Autowired
    private IProprietorHouseService proprietorHouseService;

/**
 * 查询业主房屋管理列表
 */
@PreAuthorize("@ss.hasPermi('wuYe:house:list')")
@GetMapping("/list")
    public TableDataInfo list(ProprietorHouse proprietorHouse)
    {
        startPage();
        List<ProprietorHouse> list = proprietorHouseService.selectProprietorHouseList(proprietorHouse);
        return getDataTable(list);
    }

    /**
     * 导出业主房屋管理列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:house:export')")
    @Log(title = "业主房屋管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProprietorHouse proprietorHouse)
    {
        List<ProprietorHouse> list = proprietorHouseService.selectProprietorHouseList(proprietorHouse);
        ExcelUtil<ProprietorHouse> util = new ExcelUtil<ProprietorHouse>(ProprietorHouse.class);
        util.exportExcel(response, list, "业主房屋管理数据");
    }

    /**
     * 获取业主房屋管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:house:query')")
    @GetMapping(value = "/{proprietorId}")
    public AjaxResult getInfo(@PathVariable("proprietorId") Long proprietorId)
    {
        return success(proprietorHouseService.selectProprietorHouseByProprietorId(proprietorId));
    }

    /**
     * 新增业主房屋管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:house:add')")
    @Log(title = "业主房屋管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProprietorHouse proprietorHouse)
    {
        return toAjax(proprietorHouseService.insertProprietorHouse(proprietorHouse));
    }

    /**
     * 修改业主房屋管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:house:edit')")
    @Log(title = "业主房屋管理", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ProprietorHouse proprietorHouse)
    {
        return toAjax(proprietorHouseService.updateProprietorHouse(proprietorHouse));
    }

    /**
     * 删除业主房屋管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:house:remove')")
    @Log(title = "业主房屋管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{proprietorIds}")
    public AjaxResult remove(@PathVariable Long[] proprietorIds)
    {
        return toAjax(proprietorHouseService.deleteProprietorHouseByProprietorIds(proprietorIds));
    }
}
