package com.neusoft.smart.pos.mq.payment;

import com.neusoft.smart.pos.dto.order.response.GetAllOrderInfoResponse;
import org.apache.commons.lang3.SerializationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.neusoft.smart.pos.dto.user.LoginInfo;
import com.neusoft.smart.pos.mq.util.JsonUtil;
import com.neusoft.smart.pos.payment.dto.request.FumaoLoginRequest;
import com.neusoft.smart.pos.payment.service.FumaoPayService;

@Component
public class PaymentMQReceiverHelper {
 
    private static Logger logger = LoggerFactory.getLogger(PaymentMQReceiverHelper.class);

	@Autowired
    FumaoPayService fumaoPayService;

	//rabbitmq
    public void processLoginMessage(byte[] content) {
    	logger.info("消息接收者接收到来自【login队列一】的消息，消息内容:{}",content);
    	LoginInfo info = (LoginInfo)SerializationUtils.deserialize(content);
    	logger.info("反序列化消息内容:{}",info);
    	processLoginMessage(info);
    }
    
    //aliyunRocketMq
    public void processLoginStringMessage(String content) {
    	logger.info("消息接收者接收到来自【login队列一】的消息，消息内容:{}",content);
    	LoginInfo info = (LoginInfo)JsonUtil.readValue(content, LoginInfo.class);
    	logger.info("反序列化消息内容:{}",info);
    	processLoginMessage(info);
    }
    
    private void processLoginMessage(LoginInfo info) {
    	FumaoLoginRequest fumaoLoginRequest = new FumaoLoginRequest();
        fumaoLoginRequest.setPhone(info.getUsername());
        fumaoLoginRequest.setPassword(info.getPassword());
        fumaoLoginRequest.setSn(info.getSn());
        fumaoPayService.fumaoCheckUser(fumaoLoginRequest);
    }

    //rabbitmq
    public void processOrderCompleteMessage(byte[] content) {
        logger.info("消息接收者接收到来自【order.complete队列一】的消息，消息内容:{}",content);
        GetAllOrderInfoResponse info = (GetAllOrderInfoResponse)SerializationUtils.deserialize(content);
        logger.info("反序列化消息内容:{}",info);
        fumaoPayService.posOrderSync(info);
    }
    
    //aliyunRocketMq
    public void processOrderCompleteStringMessage(String content) {
        logger.info("消息接收者接收到来自【order.complete队列一】的消息，消息内容:{}",content);
        GetAllOrderInfoResponse info = (GetAllOrderInfoResponse)JsonUtil.readValue(content, GetAllOrderInfoResponse.class);
        logger.info("反序列化消息内容:{}",info);
        fumaoPayService.posOrderSync(info);
    }
    
    
}