package com.ym.mec.teacher.controller;

import io.swagger.annotations.Api;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.ym.mec.biz.dal.dao.SysConfigDao;
import com.ym.mec.biz.dal.dao.TenantPaymentOrderDao;
import com.ym.mec.biz.dal.entity.TenantPaymentOrder;
import com.ym.mec.biz.dal.enums.DealStatusEnum;
import com.ym.mec.biz.service.TenantPaymentOrderService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.thirdparty.yqpay.Msg;
import com.ym.mec.thirdparty.yqpay.YqPayFeignService;

@RequestMapping("teacherOrder")
@Api(tags = "订单回调")
@RestController
public class TeacherOrderController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(TeacherOrderController.class);
	@Autowired
	private YqPayFeignService yqPayFeignService;
	@Autowired
	private TenantPaymentOrderDao tenantPaymentOrderDao;
	@Autowired
	private SysConfigDao sysConfigDao;
	@Autowired
	private TenantPaymentOrderService tenantPaymentOrderService;

	@RequestMapping("paymentResult")
	public void paymentResult(HttpServletResponse response, String orderNo) {
		try {
			String baseApiUrl = sysConfigDao.findConfigValue("teacher_base_url");
			response.sendRedirect(baseApiUrl + "/#/paymentresult?orderNo=" + orderNo);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

    @GetMapping("/queryByOrderNo")
    public Object query(String orderNo){
        TenantPaymentOrder order = tenantPaymentOrderService.queryByOrderNo(orderNo);
        if(order == null){
        	return failed("订单不存在");
        }
        return succeed(order);
    }

}
