package com.icloud.server.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

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

/** redis---支付链接
 * @Author : yang
 * @Date : 2022-07-15 00:30
 * @Version : 2.1.2
 */

@Component
public class pushred {
    @Autowired
    StringRedisTemplate stringredistemplate;

    public Map putall(PayRedis pr){
        HashMap<String, String> hmap = new HashMap<String, String>();
        //处理用户存储
        hmap.put( "uid", pr.getUid() );
        hmap.put( "goodsid", pr.getGoodsid() );
        hmap.put( "studentid", pr.getStudentid() );
        hmap.put( "starttime", pr.getStarttime() );
        hmap.put( "price", pr.getPrice() );
        hmap.put( "url", pr.getUrl() );
        hmap.put( "expire", pr.getExpire());
        String k="goods_"+ pr.getGoodsid()+"_"+pr.getStudentid();
//        HashCode hashCode = new HashCode(k);
        String key = String.valueOf(k.hashCode());
        stringredistemplate.opsForHash().putAll(key,hmap);
        stringredistemplate.expire(key,300000 , TimeUnit.MILLISECONDS);

        return hmap;
    }
    public Map<Object, Object>  getorder(String goodid,String studentid){
        String k="goods_"+ goodid+"_"+studentid;
        String key = String.valueOf(k.hashCode());
        Map<Object, Object> entries = stringredistemplate.opsForHash().entries(key);
        return entries;
    }

}
