package org.springblade.gateway.common_gateway.service.impl;

import org.springblade.gateway.common_gateway.service.IOrderUrlAndColorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

@Service
public class SaveOrderUrlServiceImpl implements IOrderUrlAndColorService {
	@Autowired
	private StringRedisTemplate redisTemplate;

	public static final String YEEPAY_ORDERURL = "yeepay_orderUrl";
	public static final String BACKGROUND_COLOR = "background_color";
	public static final String ORDER_TYPE = "order_type";
	@Override
	public void SaveOrderUrlAndColor(Long orderId, String orderUrl, String color,String type) {
		String url_key = YEEPAY_ORDERURL.concat(":").concat(orderId.toString());
		String color_key = BACKGROUND_COLOR.concat(":").concat(orderId.toString());
		String type_key = ORDER_TYPE.concat(":").concat(orderId.toString());
		redisTemplate.opsForValue().set(url_key,orderUrl,600, TimeUnit.SECONDS);
		redisTemplate.opsForValue().set(color_key,color,600, TimeUnit.SECONDS);
		redisTemplate.opsForValue().set(type_key,type,600, TimeUnit.SECONDS);
	}

	@Override
	public HashMap<String, Object> getSaveOrderUrlAndColor(Long orderId) {
		String url_key = YEEPAY_ORDERURL.concat(":").concat(orderId.toString());
		String color_key = BACKGROUND_COLOR.concat(":").concat(orderId.toString());
		String type_key = ORDER_TYPE.concat(":").concat(orderId.toString());
		String url = redisTemplate.opsForValue().get(url_key);
		String color = redisTemplate.opsForValue().get(color_key);
		String type = redisTemplate.opsForValue().get(type_key);
		HashMap<String,Object> map = new HashMap<>();
		map.put("url",url);
		map.put("type",type);
		map.put("color",color);
		return map;
	}
}
