package com.ruoyi.invest.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.invest.domain.InstallmentHistoryDetail;
import com.ruoyi.invest.domain.dto.InstallmentHistoryDetailDto;
import com.ruoyi.invest.domain.vo.InstallmentHistoryDetailVo;
import com.ruoyi.invest.service.IInstallmentHistoryDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * 分期历史明细Controller
 *
 * @author tianyongbao
 * @date 2024-03-23
 */
@Api(tags=" 分期历史明细")
@RestController
@RequestMapping("/installmentDetail")
public class InstallmentHistoryDetailController extends BaseController
{
    @Resource
    private IInstallmentHistoryDetailService installmentHistoryDetailService;

    /**
     * 查询分期历史明细列表
     */
    @ApiOperation(value="查询分期历史明细列表",response = InstallmentHistoryDetailVo.class)
    @RequiresPermissions("invest:installmentHistory:list")
    @GetMapping("/list")
    public TableDataInfo list(InstallmentHistoryDetailDto installmentHistoryDetailDto)
    {
        startPage();
        List<InstallmentHistoryDetailVo> list = installmentHistoryDetailService.selectInstallmentHistoryDetailList(installmentHistoryDetailDto);
        return getDataTable(list);
    }

    /**
     * 导出分期历史明细列表
     */
    @ApiOperation(value="导出分期历史明细列表")
    @RequiresPermissions("invest:installmentHistory:export")
    @Log(title = "分期历史明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InstallmentHistoryDetailDto installmentHistoryDetailDto)
    {
        List<InstallmentHistoryDetailVo> list = installmentHistoryDetailService.selectInstallmentHistoryDetailList(installmentHistoryDetailDto);
        ExcelUtil<InstallmentHistoryDetailVo> util = new ExcelUtil<InstallmentHistoryDetailVo>(InstallmentHistoryDetailVo.class);
        util.exportExcel(response, list, "分期历史明细数据");
    }

    /**
     * 获取分期历史明细详细信息
     */
    @ApiOperation(value="获取分期历史明细详细信息")
    @RequiresPermissions("invest:installmentHistory:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(installmentHistoryDetailService.selectInstallmentHistoryDetailById(id));
    }

    /**
     * 新增分期历史明细
     */
    @ApiOperation(value="新增分期历史明细")
    @RequiresPermissions("invest:installmentHistory:add")
    @Log(title = "分期历史明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InstallmentHistoryDetail installmentHistoryDetail)
    {
        return toAjax(installmentHistoryDetailService.insertInstallmentHistoryDetail(installmentHistoryDetail));
    }

    /**
     * 修改分期历史明细
     */
    @ApiOperation(value="修改分期历史明细")
    @RequiresPermissions("invest:installmentHistory:edit")
    @Log(title = "分期历史明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InstallmentHistoryDetail installmentHistoryDetail)
    {
        return toAjax(installmentHistoryDetailService.updateInstallmentHistoryDetail(installmentHistoryDetail));
    }

    /**
     * 删除分期历史明细
     */
    @ApiOperation(value="删除分期历史明细")
    @RequiresPermissions("invest:installmentHistory:remove")
    @Log(title = "分期历史明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(installmentHistoryDetailService.deleteInstallmentHistoryDetailByIds(ids));
    }
}
