package com.liquidnet.service.dragon.receiver;//package com.liquidnet.service.dragon.receiver;
//
//import com.liquidnet.commons.lang.util.HttpUtil;
//import com.liquidnet.commons.lang.util.JsonUtils;
//import com.liquidnet.service.dragon.bo.PayNotifyReqBo;
//import com.liquidnet.service.dragon.dto.PayNotifyDto;
//import com.liquidnet.service.dragon.utils.MqHandleUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.connection.stream.MapRecord;
//import org.springframework.data.redis.stream.StreamListener;
//import org.springframework.stereotype.Component;
//import org.springframework.util.LinkedMultiValueMap;
//import org.springframework.util.MultiValueMap;
//
//import java.time.LocalDateTime;
//
///**
// * 支付回调通知商户
// */
//@Slf4j
//@Component
//public class RedisPayNotifyReceiver implements StreamListener<String, MapRecord<String, String, String>> {
//
//    @Autowired
//    private MqHandleUtil mqHandleUtil;
//    @Override
//    public void onMessage(MapRecord<String, String, String> message) {
//        log.info("接受到来自redis notify 的消息");
//        log.info("message id "+message.getId());
//        log.info("stream "+message.getStream());
//        log.info("body "+message.getValue());
//        this.sendNotify(message.getValue().get("message"));
//    }
//
//    private void sendNotify(String message){
//        PayNotifyReqBo payNotifyReqBo = JsonUtils.fromJson(message, PayNotifyReqBo.class);
//        PayNotifyDto payNotifyDto = payNotifyReqBo.getPayNotifyDto();
//        LocalDateTime nowTime = LocalDateTime.now();
//        MultiValueMap<String, String> params = new LinkedMultiValueMap();
//        params.add("status", payNotifyDto.getStatus().toString());
//        params.add("type", payNotifyDto.getType());
//        params.add("code", payNotifyDto.getCode());
//        params.add("paymentId", payNotifyDto.getPaymentId());
//        params.add("orderCode", payNotifyDto.getOrderCode());
//        params.add("price", payNotifyDto.getPrice().toString());
//        params.add("paymentType", payNotifyDto.getPaymentType());
//        String response = HttpUtil.post(payNotifyReqBo.getNotifyUrl(), params);
//        log.debug("PAY RESPONSE=" + response);
//        if (response.equals("success")) {
////            MqHandleUtilsendMySqlRedis(
////                    SqlMapping.get("dragon_order_pay.update"),
////                    new Object[]{nowTime, DateUtil.Formatter.yyyyMMddHHmmss.format(nowTime), DragonConstant.RefundStatusEnum.STATUS_SUCCESS.getCode(), notifyUrlDto.getRefundCode()}
////            );
//        } else {
////            sendMySqlRedis(
////                    SqlMapping.get("dragon_order_pay.update"),
////                    new Object[]{nowTime, DateUtil.Formatter.yyyyMMddHHmmss.format(nowTime), DragonConstant.RefundStatusEnum.STATUS_FAIL.getCode(), notifyUrlDto.getRefundCode()}
////            );
//        }
//    }
//}
