/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ifish.helper;

import com.ifish.entity.ShopsInfo;
import com.ifish.mapper.Tbl_Shops_Info_Mapper;
import com.ifish.util.RedisKey;
import com.ifish.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * @author Administrator
 */
@Component
public class ShopsInfoHelper implements ShopsInfoHelperI {

    /**
     * tbl_shops_info表操作方法接口
     */
    @Autowired
    private Tbl_Shops_Info_Mapper tbl_Shops_Info_Mapper;

    /**
     * redis缓存服务器方法接口
     */
    @Autowired
    private RedisHelperI redisHelperI;

    @Override
    public ShopsInfo getShopsInfoByUserId(Integer userId) throws Exception {
        ShopsInfo shopsInfo = null;
        String key = RedisKey.ShopsInfo_Key + userId;
        String shopString = redisHelperI.getRedis(key);
        if (StringUtils.isNotBlank(shopString)) {
            shopsInfo = (ShopsInfo) StringUtil.JsonToBean(shopString, ShopsInfo.class);
        } else {
            shopsInfo = tbl_Shops_Info_Mapper.getShopsInfoByUserId(userId);
            redisHelperI.setRedis(key, StringUtil.ObjectToJson(shopsInfo));
        }
        return shopsInfo;
    }

}
