package com.fs.doctor.controller;

import java.util.List;

import com.fs.common.config.LoginContextManager;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.doctor.domain.WithdrawRecords;
import com.fs.doctor.service.IWithdrawRecordsService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 医生提现记录Controller
 *
 * @author fs
 * @date 2026-01-27
 */
@RestController
@RequestMapping("/doctor/records")
public class WithdrawRecordsController extends BaseController
{
    @Autowired
    private IWithdrawRecordsService withdrawRecordsService;

    /**
     * 查询医生提现记录列表
     */
    @PreAuthorize("@ss.hasPermi('doctor:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(WithdrawRecords withdrawRecords)
    {
        startPage();
        List<WithdrawRecords> list = withdrawRecordsService.selectWithdrawRecordsList(withdrawRecords);
        return getDataTable(list);
    }

    /**
     * 导出医生提现记录列表
     */
    @PreAuthorize("@ss.hasPermi('doctor:records:export')")
    @Log(title = "医生提现记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WithdrawRecords withdrawRecords)
    {
        List<WithdrawRecords> list = withdrawRecordsService.selectWithdrawRecordsList(withdrawRecords);
        ExcelUtil<WithdrawRecords> util = new ExcelUtil<WithdrawRecords>(WithdrawRecords.class);
        return util.exportExcel(list, "医生提现记录数据");
    }

    /**
     * 获取医生提现记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('doctor:records:query')")
    @GetMapping(value = "/{withdrawId}")
    public AjaxResult getInfo(@PathVariable("withdrawId") Long withdrawId)
    {
        return AjaxResult.success(withdrawRecordsService.selectWithdrawRecordsByWithdrawId(withdrawId));
    }

    /**
     * 新增医生提现记录
     */
    @PreAuthorize("@ss.hasPermi('doctor:records:add')")
    @Log(title = "医生提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WithdrawRecords withdrawRecords)
    {
        return toAjax(withdrawRecordsService.insertWithdrawRecords(withdrawRecords));
    }

    /**
     * 修改医生提现记录
     */
    @PreAuthorize("@ss.hasPermi('doctor:records:edit')")
    @Log(title = "医生提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WithdrawRecords withdrawRecords)
    {
        return toAjax(withdrawRecordsService.updateWithdrawRecords(withdrawRecords));
    }

    /**
     * 删除医生提现记录
     */
    @PreAuthorize("@ss.hasPermi('doctor:records:remove')")
    @Log(title = "医生提现记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{withdrawIds}")
    public AjaxResult remove(@PathVariable String[] withdrawIds)
    {
        return toAjax(withdrawRecordsService.deleteWithdrawRecordsByWithdrawIds(withdrawIds));
    }


    @PreAuthorize("@ss.hasPermi('doctor:records:audit')")
    @Log(title = "医生提现记录", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody WithdrawRecords withdrawRecords)
    {
        return toAjax(withdrawRecordsService.auditWithdraw(withdrawRecords));
    }

    @PreAuthorize("@ss.hasPermi('doctor:records:query')")
    @Log(title = "提现审核详情", businessType = BusinessType.OTHER)
    @GetMapping("/auditInfo/{withdrawId}")
    public AjaxResult auditInfo(@PathVariable Long withdrawId) {
        Long currentCompanyId = LoginContextManager.getCurrentCompanyId();

        return AjaxResult.success(withdrawRecordsService.getRecordAuditInfo(withdrawId));
    }

}
