package com.xhpc.payment.controller;

import com.wechat.pay.java.core.RSAAutoCertificateConfig;;
import com.wechat.pay.java.core.notification.NotificationParser;
import com.xhpc.common.core.annotation.NoRepeatSubmit;
import com.xhpc.common.core.constant.HttpStatus;
import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.common.core.utils.WXPayUtil;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.domain.XhpcRefundOrder;
import com.xhpc.common.domain.XhpcSettingConfig;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.payment.domain.XhpcAppInternetUser;
import com.xhpc.payment.domain.XhpcAppUser;
import com.xhpc.payment.domain.XhpcRefundAudit;
import com.xhpc.payment.mapper.XhpcRefundOrderMapper;
import com.xhpc.payment.mapper.XhpcRefundOriginalOrderMapper;
import com.xhpc.payment.mapper.XhpcUserAccountStatementMapper;
import com.xhpc.payment.service.IXhpcCommonPayment;
import com.xhpc.payment.service.IXhpcRefundAuditService;
import com.xhpc.payment.service.IXhpcRefundOrderService;
import com.xhpc.payment.service.IXhpcRefundOriginalOrderService;
import com.xhpc.payment.util.AESUtil;
import com.xhpc.payment.util.TransferBatchNotifyData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * @author yuyang
 * @date 2023-08-23 16:51
 */
@RestController
@RequestMapping("/refundOriginalOrder")
@Api(value = "原路退回接口", tags = "原路退回接口")
public class XhpcRefundOriginalOrderController extends BaseController {

    @Resource
    private IXhpcRefundOriginalOrderService xhpcRefundOriginalOrderService;
    @Resource
    private XhpcRefundOriginalOrderMapper xhpcRefundOriginalOrderMapper;
    @Resource
    private XhpcUserAccountStatementMapper xhpcUserAccountStatementMapper;
    @Resource
    private IXhpcRefundAuditService iXhpcRefundAuditService;
    @Resource
    private IXhpcRefundOrderService iXhpcRefundOrderService;
    @Resource
    private XhpcRefundOrderMapper xhpcRefundOrderMapper;
    @Resource
    private IXhpcCommonPayment xhpcCommonPayment;



    private final ExecutorService executorService = Executors.newFixedThreadPool(40);

    private static final Logger logger = LoggerFactory.getLogger(XhpcRefundOriginalOrderController.class);

    @NoRepeatSubmit(lockTime = 3)
    @GetMapping("/refundOrder")
    @ApiOperation(value = "支付宝退款")
    public R refundOrder(Long refundOrderId) throws Exception {
        return xhpcRefundOriginalOrderService.zhbRefundOriginalOrder(refundOrderId);
    }

    @NoRepeatSubmit(lockTime = 3)
    @GetMapping("/refundWxOrder")
    @ApiOperation(value = "微信退款")
    public R refundWxOrder(Long refundOrderId) throws Exception {
        System.out.println("==========微信开始退款===================");
        return xhpcRefundOriginalOrderService.wxRefundOriginalOrder(refundOrderId);
    }


    /**
     * 微信回调Api(v3退款)
     */
    @PostMapping("/transferCallback")
    public String transferCallback(HttpServletRequest request) {
        try {
            // 1. 获取请求头
            String serialNumber = request.getHeader("Wechatpay-Serial");
            String timestamp = request.getHeader("Wechatpay-Timestamp");
            String nonce = request.getHeader("Wechatpay-Nonce");
            String signature = request.getHeader("Wechatpay-Signature");

            // 2. 获取请求体
            String body = request.getReader().lines().collect(Collectors.joining());
            // 3. 构建配置（与发起转账使用相同配置）
            XhpcSettingConfig config  = xhpcCommonPayment.getXhpcSettingConfigTenantId(UserTypeUtil.OPERATION_WX_TYPE, "000000");
            RSAAutoCertificateConfig  v3Config = new RSAAutoCertificateConfig.Builder()
                    .merchantId(config.getWxMchId())
                    .privateKeyFromPath(config.getWxApiclientKeyPem())
                    .merchantSerialNumber(config.getWxApiSerialNo())
                    .apiV3Key(config.getWxApiV3Key())
                    .build();
            // 4. 解析并验签
            com.wechat.pay.java.core.notification.RequestParam param = new com.wechat.pay.java.core.notification.RequestParam.Builder()
                    .serialNumber(serialNumber)
                    .timestamp(timestamp)
                    .nonce(nonce)
                    .signature(signature)
                    .body(body)
                    .build();

            NotificationParser parser = new NotificationParser(v3Config);

            // 解析通知
            TransferBatchNotifyData notifyData  = parser.parse(param, TransferBatchNotifyData.class);

            // 7. 处理业务逻辑
            String outBatchNo = notifyData.getOutBatchNo();
            String batchStatus = notifyData.getBatchStatus();
            logger.info("回调业务数据：outBatchNo={}, batchStatus={}, totalAmount={}分, totalNum={}",
                    outBatchNo, batchStatus, notifyData.getTotalAmount(), notifyData.getTotalNum());

            // 根据批次状态更新订单
            if ("FINISHED".equals(batchStatus)) {
                // 检查明细是否全部成功
                boolean allSuccess = notifyData.getTransferDetailList().stream()
                        .allMatch(d -> "SUCCESS".equals(d.getDetailStatus()));
                if (allSuccess) {
                    xhpcRefundOriginalOrderService.updateXhpcRefundOriginalOrderV3(notifyData);
                    logger.info("转账全部成功，订单更新成功，outBatchNo={}", outBatchNo);
                }
            }

            // 8. 返回成功应答（必须返回这个格式，否则微信会重试）
            return "{\"code\":\"SUCCESS\"}";

        }catch (Exception e){
            logger.error("处理转账回调异常", e);
            return "{\"code\":\"FAIL\",\"message\":\"" + e.getMessage() + "\"}";
        }
    }

    /**
     * 微信回调Api(v2退款)
     */
    @RequestMapping("/paymentCallback")
    public Object payNotify(HttpServletRequest request, HttpServletResponse response) {
        try {
            ServletInputStream in = null;
            BufferedReader reader = null;
            StringBuilder content = new StringBuilder();
            try {
                in = request.getInputStream();
                reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
                String itemStr = "";// 作为输出字符串的临时串，用于判断是否读取完毕
                while (null != (itemStr = reader.readLine())) {
                    content.append(itemStr);
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (null != reader)
                        reader.close();
                    if (null != in)
                        in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            //将xml转换成map
            Map<String, String> map = WXPayUtil.xmlToMap(content.toString());
            String return_code = map.get("return_code");
            //自定义参数  为json格式的字符串
            //如果返回成功
            if ("SUCCESS".equals(return_code)) {
                //将自定义参数转换成JSONObject对象，处理业务逻辑
                String req_info = map.get("req_info");
                Map<String, String> reqInfo = WXPayUtil.xmlToMap(AESUtil.decryptData(req_info,"sichuanxianghuakejiyouxiangongsi"));
                logger.info("=======退款回调=======reqInfo=========="+reqInfo.toString());
                xhpcRefundOriginalOrderService.updateXhpcRefundOriginalOrder(reqInfo);
            }else{
                //退款失败
                logger.info("===============退款失败==========");
                logger.info("===============退款失败======map===="+map.toString());
                logger.info("===============退款失败==========");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/xml; charset=utf-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.print("<xml>\n" +
                    "  <return_code><![CDATA[SUCCESS]]></return_code>\n" +
                    "  <return_msg><![CDATA[OK]]></return_msg>\n" +
                    "</xml>\n");
            out.close();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Log(title = "退款-审核", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    @ApiOperation(value = "退款审核")
    @Transactional
    public R info(@RequestBody XhpcRefundAudit xhpcRefundAudit) {

        Long refundOrderId = xhpcRefundAudit.getRefundOrderId();
        iXhpcRefundAuditService.insert(xhpcRefundAudit);
        XhpcRefundOrder xhpcRefundOrder = xhpcRefundOriginalOrderMapper.getXhpcRefundOrder(refundOrderId);
        if(xhpcRefundOrder==null){
            return R.fail(HttpStatus.DATA_ERROR, "退款订单不存在");
        }
        if(xhpcRefundAudit.getStatus()==2){
            xhpcRefundOriginalOrderService.updateXhpcRefundOrder(xhpcRefundOrder,null,2,3);
            xhpcRefundOrder.setRemark("订单已取消审核");
            return R.ok(null,"订单已取消审核");
        }
        if (!StatusConstants.REFUND_ORDER_STATUS_WAIT.equals(xhpcRefundOrder.getStatus())) {
            xhpcRefundOriginalOrderService.updateXhpcRefundOrder(xhpcRefundOrder,null,2,2);
            xhpcRefundOrder.setRemark("订单状态不能退款");
            return R.fail(HttpStatus.DATA_ERROR, "订单状态不能退款");
        }
        Integer source = xhpcRefundOrder.getSource();
        Long userId = xhpcRefundOrder.getUserId();
        String tenantId = xhpcRefundOrder.getTenantId();
        //是否有实时数据
        int k = iXhpcRefundOrderService.countXhpcRealTimeOrder(userId, source, tenantId);
        if (k > 0) {
            return R.fail(1103, "车辆正在充电,不能退款");
        }
        // 是否有异常订单
        int j = iXhpcRefundOrderService.countXhpcChargeOrder(userId, source, tenantId);
        if (j > 0) {
            return R.fail(1103, "你有异常订单未解决，请拨打客服电话进行解决");
        }
        if(UserTypeUtil.USER_TYPE.equals(source)){
            XhpcAppUser xhpcAppUser = new XhpcAppUser();
            xhpcAppUser.setAppUserId(userId);
            xhpcAppUser.setIsRefundApplication(0);
            int refundApplication = xhpcUserAccountStatementMapper.updateAppUserRefundApplication(xhpcAppUser);
            if (refundApplication == 0) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return  R.fail(HttpStatus.ERROR_STATUS,"修改用户信息失败");
            }
            Map<String, Object> appUserInfo = xhpcUserAccountStatementMapper.appUserInfo(userId);
            BigDecimal amount = new BigDecimal(appUserInfo.get("balance").toString());
            if(amount.compareTo(xhpcRefundOrder.getAmount()) !=0){
                xhpcRefundOrder.setStatus(2);
                xhpcRefundOrder.setRemark("订单金额出错");
                xhpcRefundOriginalOrderService.updateXhpcRefundOrder(xhpcRefundOrder,null,4,2);
                return  R.fail(HttpStatus.ERROR_STATUS,"订单金额出错");
            }
        }else if(UserTypeUtil.COMMUNIT_TYPE.equals(source)){
            int i = iXhpcRefundAuditService.updateCommunityPersonnelMoney(userId, null, 0);
            if (i == 0) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return  R.fail(HttpStatus.ERROR_STATUS,"获取社区用户失败");
            }
            Map<String, Object> communityPersonnel = iXhpcRefundAuditService.getCommunityPersonnelById(userId, xhpcRefundOrder.getTenantId());
            BigDecimal amount = new BigDecimal(communityPersonnel.get("balance").toString());
            if(xhpcRefundOrder.getSource()==1 && xhpcRefundOrder.getUserId()>10000){

            }
            if(amount.compareTo(xhpcRefundOrder.getAmount()) !=0){
                xhpcRefundOrder.setStatus(2);
                xhpcRefundOrder.setRemark("订单金额出错");
                xhpcRefundOriginalOrderService.updateXhpcRefundOrder(xhpcRefundOrder,null,4,2);
                return  R.fail(HttpStatus.ERROR_STATUS,"订单金额出错");
            }
        }else if(UserTypeUtil.INTERNET_TYPE.equals(source) && userId>10000){
            XhpcAppInternetUser xhpcAppUser = new XhpcAppInternetUser();
            xhpcAppUser.setAppInternetUserId(userId);
            xhpcAppUser.setIsRefundApplication(0);
            int refundApplication = xhpcUserAccountStatementMapper.updateAppInternetUserBalance(xhpcAppUser);
            if (refundApplication == 0) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return  R.fail(HttpStatus.ERROR_STATUS,"修改用户信息失败");
            }
            Map<String, Object> appUserInfo = xhpcUserAccountStatementMapper.getAppInternetUser(userId);
            BigDecimal amount = new BigDecimal(appUserInfo.get("balance").toString());
            if(amount.compareTo(xhpcRefundOrder.getAmount()) !=0){
                xhpcRefundOrder.setStatus(2);
                xhpcRefundOrder.setRemark("订单金额出错");
                xhpcRefundOriginalOrderService.updateXhpcRefundOrder(xhpcRefundOrder,null,4,2);
                return  R.fail(HttpStatus.ERROR_STATUS,"订单金额出错");
            }
        }else{
            AjaxResult.error(HttpStatus.DATA_ERROR, "该用户不能退款");
        }

        if(xhpcRefundOrder.getType() == UserTypeUtil.OPERATION_WX_TYPE){
            try {
                logger.info("=========进入微信退款============"+refundOrderId);
                R r = refundWxOrder(refundOrderId);
                if(r.getCode()==200){
                    return R.ok(null,"微信退款中");
                }else{
                    xhpcRefundOrder.setStatus(2);
                    xhpcRefundOrder.setRemark("订单金额出错");
                    xhpcRefundOriginalOrderService.updateXhpcRefundOrder(xhpcRefundOrder,null,4,2);
                    return R.fail(HttpStatus.ERROR_STATUS,r.getMsg());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else{
            try {
                logger.info("=========进入支付宝退款============"+refundOrderId);
                R r = refundOrder(refundOrderId);
                if(r.getCode()==200){
                    return R.ok(null,"支付宝退款中");
                }else{
                    xhpcRefundOrder.setStatus(2);
                    xhpcRefundOrder.setRemark("订单金额出错");
                    xhpcRefundOriginalOrderService.updateXhpcRefundOrder(xhpcRefundOrder,null,4,2);
                    return R.fail(HttpStatus.ERROR_STATUS,r.getMsg());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return R.fail("退款失败");
    }

    @GetMapping("/gesfsafas")
    @ApiOperation(value = "微信支付回调测试")
    public void gesfsafas(){
        Map<String, String> reqInfo =new HashMap<>();
        reqInfo.put("transaction_id","4200001936202308307731713155");
        reqInfo.put("refund_status","SUCCESS");
        reqInfo.put("out_refund_no","000001120230830140704122");
        reqInfo.put("settlement_refund_fee","100");
        reqInfo.put("success_time","2023-08-30 14:07:13");
        reqInfo.put("refund_recv_accout","支付用户零钱");
        reqInfo.put("refund_id","50301006912023083077521735575");
        reqInfo.put("out_trade_no","000000120230830114123118");
        reqInfo.put("refund_account","REFUND_SOURCE_RECHARGE_FUNDS");
        reqInfo.put("refund_fee","100");
        reqInfo.put("total_fee","100");
        reqInfo.put("settlement_total_fee","600");
        reqInfo.put("cash_refund_fee","100");
        reqInfo.put("refund_request_source","API");
        xhpcRefundOriginalOrderService.updateXhpcRefundOriginalOrder(reqInfo);
    }


    //平台退款快捷方式
    @PostMapping("/getUserApplyForBalance")
    @ApiOperation(value = "平台退款快捷方式")
    public R getUserApplyForBalance(HttpServletRequest request, @RequestBody Map<String, Object> map){
        String tenantId = StringUtils.valueOf(map.get("tenantId"));
        String userId = StringUtils.valueOf(map.get("userId"));
        String source = StringUtils.valueOf(map.get("source"));
        String amount = StringUtils.valueOf(map.get("balance"));
        String weixinOpenId = StringUtils.valueOf(map.get("weixinOpenId"));
        String alipayOpenId = StringUtils.valueOf(map.get("alipayOpenId"));
        String type = StringUtils.valueOf(map.get("type"));
        if (UserTypeUtil.CUSTOMERS_TYPE.equals(source)) {
            return R.fail(HttpStatus.ERROR_STATUS, "大客户不支持退款");
        }
        if (StringUtils.isEmpty(amount)) {
            return R.fail(HttpStatus.NOT_NULL, "退款金额不能为空");
        } else {
            if("1".equals(type)){
                if (new BigDecimal(0.3).compareTo(new BigDecimal(amount)) == 1) {
                    return R.fail(HttpStatus.NOT_NULL, "微信平台规定退款金额不能少于0.3元");
                }
            }
        }
        //用户信息id
        if (StringUtils.isEmpty(userId)) {
            return R.fail(HttpStatus.NOT_NULL, "用户信息不能为空");
        }
        //1 微信 2 支付宝
        if (StringUtils.isEmpty(type)) {
            return R.fail(HttpStatus.NOT_NULL, "退款渠道不能为空");
        }else{
            if("1".equals(type)){
                if("".equals(weixinOpenId) || weixinOpenId ==null){
                    return R.fail(HttpStatus.NOT_NULL, "该用户未登录微信小程序不能退款，请选择支付宝退款方式");
                }
            }else if("2".equals(type)){
                if("".equals(alipayOpenId) || alipayOpenId ==null){
                    return R.fail(HttpStatus.NOT_NULL, "该用户未登录支付宝小程序不能退款，请选择微信退款方式");
                }
            }else{
                return R.fail(HttpStatus.NOT_NULL, "该用户未登录微信或支付宝小程序不能退款");
            }
        }
        //是否有实时数据
        int i = iXhpcRefundOrderService.countXhpcRealTimeOrder(Long.valueOf(userId), Integer.valueOf(source), tenantId);
        if (i > 0) {
            return R.fail(1103, "车辆正在充电,不能退款");
        }
        // 是否有异常订单
        int j = iXhpcRefundOrderService.countXhpcChargeOrder(Long.valueOf(userId), Integer.valueOf(source), tenantId);
        if (j > 0) {
            return R.fail(1103, "有异常订单未解决，请拨打客服电话进行解决");
        }
        //生成退款订单
        String orderOutNumber = StringUtils.numFormat(Long.valueOf(userId), Integer.parseInt(type),
                StatusConstants.FLOWING_WATER_REFUND_TYPE);
        String remark = StringUtils.valueOf(map.get("remark"));

        XhpcRefundOrder xhpcRefundOrder = new XhpcRefundOrder();
        xhpcRefundOrder.setUserId(Long.valueOf(userId));
        xhpcRefundOrder.setAmount(new BigDecimal(amount));
        xhpcRefundOrder.setRefundOrderNumber(orderOutNumber);
        xhpcRefundOrder.setType(Integer.parseInt(type));
        xhpcRefundOrder.setRemark(remark);
        xhpcRefundOrder.setSource(Integer.valueOf(source));
        xhpcRefundOrder.setCreateTime(new Date());
        xhpcRefundOrder.setUpdateTime(new Date());
        xhpcRefundOrder.setTenantId(tenantId);
        if (StatusConstants.OPERATION_WX_TYPE.equals(type)) {
            xhpcRefundOrder.setOpenId(weixinOpenId);
        } else {
            xhpcRefundOrder.setAlipayId(alipayOpenId);
        }
        xhpcRefundOriginalOrderService.addXhpcRefundOrder(xhpcRefundOrder);

        executorService.execute(new Runnable() {
            @Override
            public void run() {
                XhpcRefundAudit xhpcRefundAudit =new XhpcRefundAudit();
                xhpcRefundAudit.setRefundOrderId(xhpcRefundOrder.getRefundOrderId());
                xhpcRefundAudit.setStatus(1);
                xhpcRefundAudit.setRemark("自动审核通过");
                info(xhpcRefundAudit);
            }
        });
        return R.ok(null,"申请退款成功");
    }

    @Scheduled(cron = "0/30 * * * * ? ")
    @GetMapping("/moneyPage")
    public void moneyPage(){
        logger.info("++++++++++++每30秒，扫描一次，退款订单金额小于200，自动审核通过++++++++++++++++");
        try {
            List<Long> list = iXhpcRefundOrderService.moneyPage(1);
            logger.info("++++++++++++有自动退款订单+++++list+++++++++++"+list.size());
            if(list !=null && list.size()>0){
                for (int i = 0; i <list.size() ; i++) {
                    Long aLong = list.get(i);
                    XhpcRefundAudit xhpcRefundAudit =new XhpcRefundAudit();
                    xhpcRefundAudit.setRefundOrderId(aLong);
                    xhpcRefundAudit.setStatus(1);
                    xhpcRefundAudit.setRemark("自动审核通过");
                    info(xhpcRefundAudit);
                    Thread.sleep(500);
                }
            }
        }catch (Exception e){
            logger.info("++++++++++++自动审核异常++++++++++++++++");
            e.printStackTrace();
            //后期可以增加短信通知
        }
    }


    //川逸充自动退款 每5分钟一次
    //@Scheduled(cron = "0 0/5 * * * ? ")
    @GetMapping("/cycMoneyPage")
    public void cycMoneyPage(){
        logger.info("++++++++++++川逸充没有充电订单自动退款 每5分钟一次++++++++++++++++");
        LocalDateTime localDate = LocalDateTime.now().minusDays(30);
        String time = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));//转为String类型
        //查询是否有未退款的川逸充用户
        List<Map<String, Object>> longList = iXhpcRefundOrderService.cycMoneyPage();
        if(longList !=null && longList.size()>0){
            for (int i = 0; i < longList.size(); i++) {
                Map<String, Object> map = longList.get(i);
                Long appInternetUserId = Long.valueOf(map.get("appInternetUserId").toString());
                int number = xhpcRefundOrderMapper.cycXhpcChargeOrder(appInternetUserId, time);
                if(number==0){
                    int count = xhpcRefundOrderMapper.cycXhpcrRefundOrder(appInternetUserId, time);
                    if(count==0){
                        //该用户可以退款
                        //生成退款订单
                        String orderOutNumber = StringUtils.numFormat(appInternetUserId, 1, StatusConstants.FLOWING_WATER_REFUND_TYPE);
                        String remark = StringUtils.valueOf("川逸充用户自动退款");
                        XhpcRefundOrder xhpcRefundOrder = new XhpcRefundOrder();
                        xhpcRefundOrder.setUserId(appInternetUserId);
                        xhpcRefundOrder.setAmount(new BigDecimal(map.get("balance").toString()));
                        xhpcRefundOrder.setRefundOrderNumber(orderOutNumber);
                        xhpcRefundOrder.setType(1);
                        xhpcRefundOrder.setRemark(remark);
                        xhpcRefundOrder.setSource(1);
                        xhpcRefundOrder.setCreateTime(new Date());
                        xhpcRefundOrder.setUpdateTime(new Date());
                        xhpcRefundOrder.setTenantId("000000");
                        xhpcRefundOriginalOrderService.addXhpcRefundOrder(xhpcRefundOrder);

                        executorService.execute(new Runnable() {
                            @Override
                            public void run() {
                                XhpcRefundAudit xhpcRefundAudit =new XhpcRefundAudit();
                                xhpcRefundAudit.setRefundOrderId(xhpcRefundOrder.getRefundOrderId());
                                xhpcRefundAudit.setStatus(1);
                                xhpcRefundAudit.setRemark("自动审核通过");
                                info(xhpcRefundAudit);
                            }
                        });
                    }
                }
            }
        }
    }


    @GetMapping("/getRefundOriginalOrderList")
    @ApiOperation(value = "退款页面")
    public R getRefundOriginalOrderList(Long refundOrderId){
        return xhpcRefundOriginalOrderService.getRefundOriginalOrderList(refundOrderId);
    }

    @GetMapping("/getTestSms")
    @ApiOperation(value = "短信测试")
    public void getTestSms(String number){
        xhpcRefundOriginalOrderService.getTestSms(number);
    }


    @GetMapping("/orderqueryUrl")
    @ApiOperation(value = "查看微信充值订单信息")
    public void orderqueryUrl(String transactionId){
        xhpcRefundOriginalOrderService.orderqueryUrl(transactionId);
    }

    @GetMapping("/refundqueryUrl")
    @ApiOperation(value = "查看微信退款订单信息")
    public void refundqueryUrl(String transactionId){
        xhpcRefundOriginalOrderService.refundqueryUrl(transactionId);
    }

}
