package com.yida.data.mall.controller;

import cn.hutool.json.JSONUtil;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.FebsResponse;
import com.yida.data.mall.service.EduBillOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 缴费账单订单 Controller(不鉴权)
 *
 * @author ZYJ
 * @date 2022/4/14
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("in/eduBillOrder")
@Api(tags = "缴费账单后台api")
public class InEduBillOrderController {

    private final EduBillOrderService eduBillOrderService;

    @ApiOperation("微信支付通知结果回调 此接口暂时无用(需手动查询订单支付状态)")
    @PostMapping("/wxPayNotify")
    public FebsResponse wxPayNotify(@RequestBody Map<String, Object> res) {
        return new FebsResponse().put("code", "SUCCESS");
    }

    @ApiOperation("微信退款通知结果回调 此接口暂时无用(需手动查询订单退款状态)")
    @PostMapping("/wxRefundNotify")
    public FebsResponse wxRefundNotify(@RequestBody Map<String, Object> res) {
        return new FebsResponse().put("code", "SUCCESS");
    }

    @ApiOperation("银联支付通知结果回调")
    @PostMapping("/unionPayNotify")
    public String unionPayNotify(@RequestParam Map<String, Object> map) {
        log.info("银联支付通知结果回调, result: {}", JSONUtil.toJsonStr(map));
        return eduBillOrderService.unionPayNotify(map);
    }

    @GetMapping(value = "updateBillOrderStatus")
    @ApiOperation(value = "更新超时账单订单状态")
    public ResultBean<String> updateBillOrderStatus() {
        eduBillOrderService.updateBillOrderStatus();
        return ResultBean.buildSuccess();
    }

    @GetMapping(value = "updateRefundStatus")
    @ApiOperation(value = "更新退款订单状态")
    public ResultBean<String> updateRefundStatus() {
        eduBillOrderService.updateRefundStatus();
        return ResultBean.buildSuccess();
    }
}
