package cn.iocoder.yudao.module.payment.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.payment.entity.FzRecord;
import cn.iocoder.yudao.module.payment.service.IFzRecordService;
import cn.iocoder.yudao.util.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分账记录Controller
 *
 * @author zcy
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/admin-api/fzRecord/fzRecord")
public class FzRecordController extends BaseController
{
    @Autowired
    private IFzRecordService fzRecordService;

    /**
     * 查询分账记录列表
     */
//    @PreAuthorize("@ss.hasPermi('fzRecord:fzRecord:list')")
    @GetMapping("/list")
    public CommonResult list(FzRecord fzRecord,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<FzRecord> page = new Page<>(pageNum, pageSize);
        IPage<FzRecord> list = fzRecordService.selectFzRecordList(page,fzRecord);
        return success(list);
    }

    /**
     * 导出分账记录列表
     */
//    @PreAuthorize("@ss.hasPermi('fzRecord:fzRecord:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, FzRecord fzRecord,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<FzRecord> page = new Page<>(pageNum,pageSize);
        IPage<FzRecord> list = fzRecordService.selectFzRecordList(page,fzRecord);
        ExcelUtil<FzRecord> util = new ExcelUtil<FzRecord>(FzRecord.class);
        util.exportExcel(response, list.getRecords(), "分账记录数据");
    }

    /**
     * 获取分账记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('fzRecord:fzRecord:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(fzRecordService.selectFzRecordById(id));
    }

    /**
     * 新增分账记录
     */
//    @PreAuthorize("@ss.hasPermi('fzRecord:fzRecord:add')")
    @PostMapping
    public CommonResult add(@RequestBody FzRecord fzRecord)
    {
        return toAjax(fzRecordService.insertFzRecord(fzRecord));
    }

    /**
     * 修改分账记录
     */
//    @PreAuthorize("@ss.hasPermi('fzRecord:fzRecord:edit')")
    @PutMapping
    public CommonResult edit(@RequestBody FzRecord fzRecord)
    {
        return toAjax(fzRecordService.updateFzRecord(fzRecord));
    }

}
