package com.ruoyi.web.controller.loan;

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

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.loan.LoanApplicationFj;
import com.ruoyi.system.service.loan.ILoanApplicationFjService;
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-04-24
 */
@RestController
@RequestMapping("/fj")
public class LoanApplicationFjController extends BaseController {
    @Autowired
    private ILoanApplicationFjService loanApplicationFjService;

    /**
     * 查询贷款申请_附件列表
     */
    //@PreAuthorize("@ss.hasPermi('system:fj:list')")
    @GetMapping("/list")
    public TableDataInfo list(LoanApplicationFj loanApplicationFj) {
        startPage();
        List<LoanApplicationFj> list = loanApplicationFjService.selectLoanApplicationFjList(loanApplicationFj);
        return getDataTable(list);
    }

    /**
     * 查询贷款申请_附件列表(二维码)
     */
    //@PreAuthorize("@ss.hasPermi('system:fj:list')")
    @GetMapping("/ewmList")
    public AjaxResult ewmList(LoanApplicationFj loanApplicationFj) {
        return loanApplicationFjService.ewmList(loanApplicationFj);
    }

    /**
     * 导出贷款申请_附件列表
     */
    @PreAuthorize("@ss.hasPermi('system:fj:export')")
    @Log(title = "贷款申请_附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LoanApplicationFj loanApplicationFj) {
        List<LoanApplicationFj> list = loanApplicationFjService.selectLoanApplicationFjList(loanApplicationFj);
        ExcelUtil<LoanApplicationFj> util = new ExcelUtil<LoanApplicationFj>(LoanApplicationFj.class);
        util.exportExcel(response, list, "贷款申请_附件数据");
    }

    /**
     * 获取贷款申请_附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fj:query')")
    @GetMapping(value = "/{fjId}")
    public AjaxResult getInfo(@PathVariable("fjId") Long fjId) {
        return success(loanApplicationFjService.selectLoanApplicationFjByFjId(fjId));
    }

    /**
     * 新增贷款申请_附件
     */
    @PreAuthorize("@ss.hasPermi('system:fj:add')")
    @Log(title = "贷款申请_附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<LoanApplicationFj> loanApplicationFj) {
        return toAjax(loanApplicationFjService.insertLoanApplicationFj(loanApplicationFj));
    }

    /**
     * 修改贷款申请_附件
     */
    @PreAuthorize("@ss.hasPermi('system:fj:edit')")
    @Log(title = "贷款申请_附件", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody List<LoanApplicationFj> loanApplicationFj) {
        return toAjax(loanApplicationFjService.updateLoanApplicationFj(loanApplicationFj));
    }

    /**
     * 删除贷款申请_附件
     */
    @PreAuthorize("@ss.hasPermi('system:fj:remove')")
    @Log(title = "贷款申请_附件", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{fjIds}")
    public AjaxResult remove(@PathVariable Long[] fjIds) {
        return toAjax(loanApplicationFjService.deleteLoanApplicationFjByFjIds(fjIds));
    }
}
