package cn.iocoder.yudao.module.jx.controller.admin;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolCoach;
import cn.iocoder.yudao.module.jx.payment.entity.PayEntity;
import cn.iocoder.yudao.module.jx.payment.vo.PayNumberVo;
import cn.iocoder.yudao.module.jx.payment.vo.PayVo;
import cn.iocoder.yudao.module.jx.payment.vo.SchoolCourseVo;
import cn.iocoder.yudao.module.jx.service.DrivePayService;
import cn.iocoder.yudao.module.jx.vo.RecentlyDateVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/driving")
public class DrivePayController {

    @Resource
    private DrivePayService drivePayService;


    @PostMapping("/pay")
    public CommonResult UserPay(@RequestBody PayEntity PayEntity) {
        if (PayEntity.getStartPay().equalsIgnoreCase("1")) {
            log.info("微信支付================>>>>{}", PayEntity);
            Integer id = drivePayService.insertPayInfo(PayEntity);
            log.info("打印到数据为 =========>><>>{}", id);

        } else {
            Integer id = drivePayService.insertPayInfo(PayEntity);
        }
        return CommonResult.success("ok");
    }

    @GetMapping("/findPayListAll")
    public List<PayVo> findPayListAll(Integer state) {
        return drivePayService.findPayListAll(state);
    }

    @GetMapping("/findPayKcInfo")
    public SchoolCourseVo findPayKcInfo(Long courseId, Long jlId, Long userId) {
        return drivePayService.findPayByBookingId(courseId, jlId, userId);
    }

    /**
     * 根据 档期时间 查询报名人数
     * @param currentDate 当前时间
     * @return 返回最近一周列表
     */
    @GetMapping("findAfternoonNumber/{currentDate}")
    public PayNumberVo findAfternoonNumber(@PathVariable("currentDate") String currentDate) throws Exception {
        return drivePayService.findPayListAllNumber(currentDate);
    }

    @GetMapping("/insertBookingInfo/{currentDate}/{period}/{jlId}")
    public void insertBookingInfo(@PathVariable("currentDate") String currentDate, @PathVariable("period") Integer period, @PathVariable("jlId") Integer jlId) {
        period = period +1;
        drivePayService.insertBookingInfo(currentDate, period, jlId);
    }



    @GetMapping("/findSelfJl")
    public DriveSchoolCoach  findSelfJl() {
            return drivePayService.findSelfJl();
    }

    @GetMapping("/findSelfInfo")
    public PayVo findSelfInfo() {
        return drivePayService.findSelfInfo();
    }

    @GetMapping("/findRecentlyDate")
    public List<RecentlyDateVo> findRecentlyDate() {
        return drivePayService.findRecentlyDate();
    }




}
