package com.ruoyi.web.controller.landlord;

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.landlord.HouseLandlord;
import com.ruoyi.system.service.IHouseLandlordService;
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/landlord")
public class HouseLandlordController extends BaseController
{
    @Autowired
    private IHouseLandlordService houseLandlordService;

/**
 * 查询业主管理列表
 */
@PreAuthorize("@ss.hasPermi('wuYe:landlord:list')")
@GetMapping("/list")
    public TableDataInfo list(HouseLandlord houseLandlord)
    {
        startPage();
        List<HouseLandlord> list = houseLandlordService.selectHouseLandlordList(houseLandlord);
        return getDataTable(list);
    }

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

    /**
     * 获取业主管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:landlord:query')")
    @GetMapping(value = "/{houseLandlordId}")
    public AjaxResult getInfo(@PathVariable("houseLandlordId") Long houseLandlordId)
    {
        return success(houseLandlordService.selectHouseLandlordByHouseLandlordId(houseLandlordId));
    }

    /**
     * 新增业主管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:landlord:add')")
    @Log(title = "业主管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseLandlord houseLandlord)
    {
        return toAjax(houseLandlordService.insertHouseLandlord(houseLandlord));
    }

    /**
     * 修改业主管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:landlord:edit')")
    @Log(title = "业主管理", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody HouseLandlord houseLandlord)
    {
        return toAjax(houseLandlordService.updateHouseLandlord(houseLandlord));
    }

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