package com.liquidnet.service.dragon.utils;

import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.dragon.constant.DragonConstant;
import com.liquidnet.service.dragon.dto.DragonOrdersDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DataUtils {
    @Autowired
    private RedisUtil redisUtil;

    public void createPayOrder(String orderCode, String code, DragonOrdersDto ordersDto) {
        if (redisUtil.hasKey(DragonConstant.REDIS_KET_PAY_ORDERCODE + orderCode)) {
        } else {
            redisUtil.set(DragonConstant.REDIS_KET_PAY_ORDERCODE + orderCode, code);
            redisUtil.set(DragonConstant.REDIS_KET_PAY_CODE + code, ordersDto);
        }
    }
    
    public DragonOrdersDto getPayOrderByCode(String code){
        if (!redisUtil.hasKey(DragonConstant.REDIS_KET_PAY_CODE + code)) {
            //TODO 是否降级处理
        }
        return (DragonOrdersDto) redisUtil.get(DragonConstant.REDIS_KET_PAY_CODE + code);
    }

    public DragonOrdersDto getPayOrderByOrderCode(String orderCode){
        if (!redisUtil.hasKey(DragonConstant.REDIS_KET_PAY_ORDERCODE + orderCode)) {
            //TODO 是否降级处理
        } 
        //获取支付订单号
        String code = (String)redisUtil.get(DragonConstant.REDIS_KET_PAY_ORDERCODE + orderCode);
        
        return (DragonOrdersDto) redisUtil.get(DragonConstant.REDIS_KET_PAY_CODE + code);
    }

    public void updateOrderStatus(String code,DragonOrdersDto dragonOrdersDto){
        redisUtil.set(DragonConstant.REDIS_KET_PAY_CODE + code, dragonOrdersDto);
    }
}
