package com.ruoyi.web.controller.oa;

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

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.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.oa.domain.CmcBorrowDetail;
import com.ruoyi.oa.service.ICmcBorrowDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * cmc借款明细Controller
 * 
 * @author cmc
 * @date 2024-04-07
 */
@RestController
@RequestMapping("/oa/borrowDetail")
public class CmcBorrowDetailController extends BaseController
{
    @Autowired
    private ICmcBorrowDetailService cmcBorrowDetailService;

    /**
     * 查询cmc借款明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcBorrowDetail cmcBorrowDetail)
    {
        startPage();
        List<CmcBorrowDetail> list = cmcBorrowDetailService.selectCmcBorrowDetailList(cmcBorrowDetail);
        return getDataTable(list);
    }

    /**
     * 导出cmc借款明细列表
     */
    @Log(title = "cmc借款明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcBorrowDetail cmcBorrowDetail)
    {
        List<CmcBorrowDetail> list = cmcBorrowDetailService.selectCmcBorrowDetailList(cmcBorrowDetail);
        ExcelUtil<CmcBorrowDetail> util = new ExcelUtil<CmcBorrowDetail>(CmcBorrowDetail.class);
        util.exportExcel(response, list, "cmc借款明细数据");
    }

    /**
     * 获取cmc借款明细详细信息
     */
    @GetMapping(value = "/{borrowId}")
    public AjaxResult getInfo(@PathVariable("borrowId") String borrowId)
    {
        return success(cmcBorrowDetailService.selectCmcBorrowDetailByBorrowId(borrowId));
    }

    /**
     * 新增cmc借款明细
     */
    @Log(title = "cmc借款明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcBorrowDetail cmcBorrowDetail)
    {
        return toAjax(cmcBorrowDetailService.insertCmcBorrowDetail(cmcBorrowDetail));
    }

    /**
     * 修改cmc借款明细
     */
    @Log(title = "cmc借款明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcBorrowDetail cmcBorrowDetail)
    {
        return toAjax(cmcBorrowDetailService.updateCmcBorrowDetail(cmcBorrowDetail));
    }

    /**
     * 删除cmc借款明细
     */
    @Log(title = "cmc借款明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{borrowIds}")
    public AjaxResult remove(@PathVariable String[] borrowIds)
    {
        return success(cmcBorrowDetailService.deleteCmcBorrowDetailByBorrowIds(borrowIds));
    }

    /**
     * 删除cmc借款明细通过borrowDetailId
     */
    @Log(title = "cmc借款明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/id/{borrowDetailId}")
    public AjaxResult removeByBorrowDetailId(@PathVariable String[] borrowDetailId)
    {
        return success(cmcBorrowDetailService.deleteCmcBorrowDetailByBorrowDetailId(borrowDetailId));
    }
}
