package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cs.domain.CsOpenRecord;
import com.ruoyi.cs.domain.template.CsOpenRecordTemplate;
import com.ruoyi.cs.service.ICsOpenRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 开户记录Controller
 *
 * @author ruoyi
 * @date 2024-05-29
 */
@RestController
@RequestMapping("/cs/csOpenRecord")
public class CsOpenRecordController extends BaseController
{
    @Resource
    private ICsOpenRecordService csOpenRecordService;

    /**
     * 查询开户记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csOpenRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsOpenRecord csOpenRecord)
    {
        startPage();
        csOpenRecord.setDelFlag("0");
        List<CsOpenRecord> list = csOpenRecordService.selectCsOpenRecordList(csOpenRecord);
        return getDataTable(list);
    }

    /**
     * 导出开户记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csOpenRecord:export')")
    @Log(title = "开户记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsOpenRecord csOpenRecord)
    {
        csOpenRecord.setDelFlag("0");
        List<CsOpenRecord> list = csOpenRecordService.selectCsOpenRecordList(csOpenRecord);
        ExcelUtil<CsOpenRecord> util = new ExcelUtil<CsOpenRecord>(CsOpenRecord.class);
        util.exportExcel(response, list, "开户记录数据");
    }

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

    /**
     * 获取开户记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csOpenRecord:query')")
    @GetMapping(value = "/{openRecordId}")
    public AjaxResult getInfo(@PathVariable("openRecordId") String openRecordId)
    {
        return AjaxResult.success(csOpenRecordService.selectCsOpenRecordByOpenRecordId(openRecordId));
    }

    /**
     * 新增开户记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csOpenRecord:add')")
    @Log(title = "开户记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsOpenRecord csOpenRecord)
    {
        return toAjax(csOpenRecordService.insertCsOpenRecord(csOpenRecord));
    }

    /**
     * 修改开户记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csOpenRecord:edit')")
    @Log(title = "开户记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsOpenRecord csOpenRecord)
    {
        return toAjax(csOpenRecordService.updateCsOpenRecord(csOpenRecord));
    }

    /**
     * 删除开户记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csOpenRecord:remove')")
    @Log(title = "开户记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{openRecordIds}")
    public AjaxResult remove(@PathVariable String[] openRecordIds)
    {
        return toAjax(csOpenRecordService.deleteCsOpenRecordByOpenRecordIds(openRecordIds));
    }
}
