package com.leromro.core.controller;

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

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.leromro.common.utils.SecurityUtils;
import com.leromro.core.domain.VolunteerInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.leromro.common.core.domain.R;
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.leromro.common.annotation.Log;
import com.leromro.common.core.controller.BaseController;
import com.leromro.common.core.domain.AjaxResult;
import com.leromro.common.enums.BusinessType;
import com.leromro.core.domain.VolunteerTakeRecord;
import com.leromro.core.service.IVolunteerTakeRecordService;
import com.leromro.common.utils.poi.ExcelUtil;
import com.leromro.common.core.page.TableDataInfo;

/**
 * 志愿者提现申请记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-15
 */
@RestController
@Api(tags = "志愿者提现申请记录")
@RequestMapping("/core/volunteer/take")
public class VolunteerTakeRecordController extends BaseController
{
    @Autowired
    private IVolunteerTakeRecordService volunteerTakeRecordService;

    /**
     * 查询志愿者提现申请记录列表
     */
    @ApiOperation(value = "查询志愿者提现申请记录列表",notes = "payType传2代表支付宝提现申请单")
    @GetMapping("/list")
    public TableDataInfo<VolunteerTakeRecord> list(VolunteerTakeRecord volunteerTakeRecord)
    {
        startPage();
        List<VolunteerTakeRecord> list = volunteerTakeRecordService.selectVolunteerTakeRecordList(volunteerTakeRecord);
        return getDataTable(list);
    }


    /**
     * 获取志愿者提现申请记录详细信息
     */
    @ApiOperation("获取志愿者提现申请记录详细信息")
    @GetMapping(value = "/{volunteerTakeRecordId}")
    public R<VolunteerTakeRecord> getInfo(@PathVariable("volunteerTakeRecordId") Long volunteerTakeRecordId)
    {
        return R.ok(volunteerTakeRecordService.selectVolunteerTakeRecordByVolunteerTakeRecordId(volunteerTakeRecordId));
    }

    /**
     * 提现审批
     */
    @ApiOperation(value = "提现审批",notes = "传入当前行主键volunteerTakeRecordId，审批状态appStatus:2通过，3拒绝,驳回原因rejectReason,状态为3则必填")
    @PostMapping("/approval")
    public R approval(@RequestBody VolunteerTakeRecord takeRecord){
        String appStatus = takeRecord.getAppStatus();
        if ("3".equals(appStatus) && StrUtil.isBlank(takeRecord.getRejectReason())){
            return R.fail("请填写驳回原因");
        }
        volunteerTakeRecordService.update(new LambdaUpdateWrapper<VolunteerTakeRecord>()
                .eq(VolunteerTakeRecord::getVolunteerTakeRecordId,takeRecord.getVolunteerTakeRecordId())
                .set(VolunteerTakeRecord::getAppStatus,takeRecord.getAppStatus())
                .set(StrUtil.isNotBlank(takeRecord.getRejectReason()),VolunteerTakeRecord::getRejectReason,takeRecord.getRejectReason())
                .set(VolunteerTakeRecord::getAppUserId, SecurityUtils.getUserId())
                .set(VolunteerTakeRecord::getAppUserName,SecurityUtils.getUsername()));
        return R.ok();
    }

}
