package com.ruoyi.web.controller.guarantee;

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

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.guarantee.GuaranteeInfo;
import com.ruoyi.system.service.guarantee.IGuaranteeInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 反担保基础信息Controller
 *
 * @author boman
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/guarantee/info")
public class GuaranteeInfoController extends BaseController
{
    @Autowired
    private IGuaranteeInfoService guaranteeInfoService;

/**
 * 查询反担保基础信息列表
 */
@PreAuthorize("@ss.hasPermi('guarantee:info:list')")
@GetMapping("/list")
    public TableDataInfo list(GuaranteeInfo guaranteeInfo)
    {
        startPage();
        List<GuaranteeInfo> list = guaranteeInfoService.selectGuaranteeInfoList(guaranteeInfo);
        return getDataTable(list);
    }

    /**
     * 导出反担保基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('guarantee:info:export')")
    @Log(title = "反担保基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GuaranteeInfo guaranteeInfo)
    {
        List<GuaranteeInfo> list = guaranteeInfoService.selectGuaranteeInfoList(guaranteeInfo);
        ExcelUtil<GuaranteeInfo> util = new ExcelUtil<GuaranteeInfo>(GuaranteeInfo.class);
        util.exportExcel(response, list, "反担保基础信息数据");
    }

    /**
     * 获取反担保基础信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('guarantee:info:query')")
    @GetMapping(value = "/{guaranteeInfoId}")
    public AjaxResult getInfo(@PathVariable("guaranteeInfoId") Long guaranteeInfoId)
    {
        return success(guaranteeInfoService.selectGuaranteeInfoByGuaranteeInfoId(guaranteeInfoId));
    }

    /**
     * 新增反担保基础信息
     */
    @PreAuthorize("@ss.hasPermi('guarantee:info:add')")
    @Log(title = "反担保基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GuaranteeInfo guaranteeInfo)
    {
        return toAjax(guaranteeInfoService.insertGuaranteeInfo(guaranteeInfo));
    }

    /**
     * 修改反担保基础信息
     */
    @PreAuthorize("@ss.hasPermi('guarantee:info:edit')")
    @Log(title = "反担保基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody GuaranteeInfo guaranteeInfo)
    {
        return toAjax(guaranteeInfoService.updateGuaranteeInfo(guaranteeInfo));
    }

    /**
     * 删除反担保基础信息
     */
    @PreAuthorize("@ss.hasPermi('guarantee:info:remove')")
    @Log(title = "反担保基础信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{guaranteeInfoIds}")
    public AjaxResult remove(@PathVariable Long[] guaranteeInfoIds)
    {
        return toAjax(guaranteeInfoService.deleteGuaranteeInfoByGuaranteeInfoIds(guaranteeInfoIds));
    }
}
