package com.web.controller.notify;

import com.alibaba.fastjson.JSONObject;
import com.hai.config.WxMsgConfig;
import com.hai.entity.*;
import com.hai.enum_type.OrderStatusEnum;
import com.hai.enum_type.RechargePayType;
import com.hai.order.service.OrderService;
import com.hai.order.type.OrderChildStatus;
import com.hai.service.*;
import com.hai.service.impl.OutRechargeOrderServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Controller
@RequestMapping(value = "/mobileRechargeNotify")
@Api(value = "通知")
public class MobileRechargeNotifyController {

    private static Logger log = LoggerFactory.getLogger(OutRechargeOrderServiceImpl.class);



    @RequestMapping(value = "/rechargeCallbackByJj", method = RequestMethod.POST)
    @ApiOperation(value = "尖椒充值回调")
    @ResponseBody
    public void rechargeCallbackByJj(@RequestBody String reqBodyStr, HttpServletRequest request, HttpServletResponse response) {
        try {

            JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class);

            log.info("============回调任务Start=============");
            log.info("尖椒订单充值-回调参数: " + dataObject);
            log.info("============回调任务End=============");


            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=utf-8");
            PrintWriter writer= response.getWriter();
            writer.write("SUCCESS");


        } catch (Exception e) {
            log.error("WechatPayController --> wechatNotify() error!", e);
        }
    }


    @RequestMapping(value = "/rechargeCallbackByLy", method = RequestMethod.POST)
    @ApiOperation(value = "龙阅充值回调")
    @ResponseBody
    public void rechargeCallbackByLy(
            @RequestParam(name = "out_trade_num", required = true) String out_trade_num,
            @RequestParam(name = "userid", required = true) Long userid,
            @RequestParam(name = "state", required = true) Long state,
            @RequestBody String reqBodyStr ,
            HttpServletRequest request, HttpServletResponse response) {
        try {

            log.info("============回调任务Start=============");
            log.info("龙阅订单充值-回调参数: " + reqBodyStr);
            log.info("============回调任务End=============");


            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=utf-8");
            PrintWriter writer= response.getWriter();
            writer.write("SUCCESS");


        } catch (Exception e) {
            log.error("WechatPayController --> wechatNotify() error!", e);
        }
    }

    @RequestMapping(value = "/rechargeCallbackByHg", method = RequestMethod.POST)
    @ApiOperation(value = "畅停充值回调")
    @ResponseBody
    public void rechargeCallbackByHg(
            @RequestParam(name = "mchid", required = false) String mchid,
            @RequestParam(name = "out_order_id", required = false) String out_order_id,
            @RequestParam(name = "orderid", required = true) String orderid,
            @RequestParam(name = "return_time", required = false) String return_time,
            @RequestParam(name = "return_price", required = false) String return_price,
            @RequestParam(name = "recharge_price", required = false) String recharge_price,
            @RequestParam(name = "price", required = false) String price,
            @RequestParam(name = "status", required = true) String status,
            @RequestParam(name = "phone", required = false) String phone,
            @RequestParam(name = "secret_key", required = false) String secret_key,
            HttpServletResponse response) {
        try {



            JSONObject dataObject = new JSONObject();

            dataObject.put("mchid" , mchid);
            dataObject.put("out_order_id" , out_order_id);
            dataObject.put("orderid" , orderid);
            dataObject.put("return_time" , return_time);
            dataObject.put("return_price" , return_price);
            dataObject.put("recharge_price" , recharge_price);
            dataObject.put("price" , price);
            dataObject.put("status" , status);
            dataObject.put("phone" , phone);
            dataObject.put("secret_key" , secret_key);

            log.info("============回调任务Start=============");
            log.info("畅停订单充值-回调参数: " + dataObject);
            log.info("============回调任务End=============");


            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=utf-8");
            PrintWriter writer= response.getWriter();
            writer.write("success");


        } catch (Exception e) {
            log.error("WechatPayController --> wechatNotify() error!", e);
        }
    }


}
