package com.zehong.web.controller.debit;

import java.util.List;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.zehong.common.annotation.Log;
import com.zehong.common.core.controller.BaseController;
import com.zehong.common.core.domain.AjaxResult;
import com.zehong.common.enums.BusinessType;
import com.zehong.system.domain.TDebitCredit;
import com.zehong.system.service.ITDebitCreditService;
import com.zehong.common.utils.poi.ExcelUtil;
import com.zehong.common.core.page.TableDataInfo;

/**
 * 借贷Controller
 * 
 * @author zehong
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/debit/credit")
public class TDebitCreditController extends BaseController
{
    @Autowired
    private ITDebitCreditService tDebitCreditService;

    /**
     * 查询借贷列表
     */
    @PreAuthorize("@ss.hasPermi('system:credit:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDebitCredit tDebitCredit)
    {
        startPage();
        List<TDebitCredit> list = tDebitCreditService.selectTDebitCreditList(tDebitCredit);
        return getDataTable(list);
    }

    /**
     * 导出借贷列表
     */
    @PreAuthorize("@ss.hasPermi('system:credit:export')")
    @Log(title = "借贷", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TDebitCredit tDebitCredit)
    {
        List<TDebitCredit> list = tDebitCreditService.selectTDebitCreditList(tDebitCredit);
        ExcelUtil<TDebitCredit> util = new ExcelUtil<TDebitCredit>(TDebitCredit.class);
        return util.exportExcel(list, "借贷数据");
    }

    /**
     * 获取借贷详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:credit:query')")
    @GetMapping(value = "/{debitId}")
    public AjaxResult getInfo(@PathVariable("debitId") Long debitId)
    {
        return AjaxResult.success(tDebitCreditService.selectTDebitCreditById(debitId));
    }

    /**
     * 新增借贷
     */
    @PreAuthorize("@ss.hasPermi('system:credit:add')")
    @Log(title = "借贷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDebitCredit tDebitCredit)
    {
        return toAjax(tDebitCreditService.insertTDebitCredit(tDebitCredit));
    }

    /**
     * 修改借贷
     */
    @PreAuthorize("@ss.hasPermi('system:credit:edit')")
    @Log(title = "借贷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDebitCredit tDebitCredit)
    {
        return toAjax(tDebitCreditService.updateTDebitCredit(tDebitCredit));
    }

    /**
     * 删除借贷
     */
    @PreAuthorize("@ss.hasPermi('system:credit:remove')")
    @Log(title = "借贷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{debitIds}")
    public AjaxResult remove(@PathVariable Long[] debitIds)
    {
        return toAjax(tDebitCreditService.deleteTDebitCreditByIds(debitIds));
    }
}
