package com.ruoyi.controller;

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

import com.ruoyi.cs.domain.template.CsRenewalRecordTemplate;
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.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.cs.domain.CsRenewalRecord;
import com.ruoyi.cs.service.ICsRenewalRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 续期记录Controller
 *
 * @author ruoyi
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/cs/csRenewalRecord")
public class CsRenewalRecordController extends BaseController
{
    @Resource
    private ICsRenewalRecordService csRenewalRecordService;

    /**
     * 查询续期记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csRenewalRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsRenewalRecord csRenewalRecord)
    {
        startPage();
        csRenewalRecord.setDelFlag("0");
        List<CsRenewalRecord> list = csRenewalRecordService.selectCsRenewalRecordList(csRenewalRecord);
        return getDataTable(list);
    }

    /**
     * 导出续期记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csRenewalRecord:export')")
    @Log(title = "续期记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsRenewalRecord csRenewalRecord)
    {
        List<CsRenewalRecord> list = csRenewalRecordService.selectCsRenewalRecordList(csRenewalRecord);
        ExcelUtil<CsRenewalRecord> util = new ExcelUtil<CsRenewalRecord>(CsRenewalRecord.class);
        util.exportExcel(response, list, "续期记录数据");
    }

    /**
     * 导出续期记录列表模版
     */
    @Log(title = "续期记录模版", businessType = BusinessType.EXPORT)
    @PostMapping("/exportTemplate")
    public void exportTemplate(HttpServletResponse response)
    {
        ExcelUtil<CsRenewalRecordTemplate> util = new ExcelUtil<CsRenewalRecordTemplate>(CsRenewalRecordTemplate.class);
        util.exportExcel(response, null, "续期记录数据模版");
    }

    /**
     * 获取续期记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csRenewalRecord:query')")
    @GetMapping(value = "/{renewalRecordId}")
    public AjaxResult getInfo(@PathVariable("renewalRecordId") String renewalRecordId)
    {
        return AjaxResult.success(csRenewalRecordService.selectCsRenewalRecordByRenewalRecordId(renewalRecordId));
    }

    /**
     * 新增续期记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csRenewalRecord:add')")
    @Log(title = "续期记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsRenewalRecord csRenewalRecord)
    {
        return toAjax(csRenewalRecordService.insertCsRenewalRecord(csRenewalRecord));
    }

    /**
     * 修改续期记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csRenewalRecord:edit')")
    @Log(title = "续期记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsRenewalRecord csRenewalRecord)
    {
        return toAjax(csRenewalRecordService.updateCsRenewalRecord(csRenewalRecord));
    }

    /**
     * 删除续期记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csRenewalRecord:remove')")
    @Log(title = "续期记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{renewalRecordIds}")
    public AjaxResult remove(@PathVariable String[] renewalRecordIds)
    {
        return toAjax(csRenewalRecordService.deleteCsRenewalRecordByRenewalRecordIds(renewalRecordIds));
    }
}
