/*
 * 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.bean.Tbl_HardWare_Type;
import com.ifish.bean.Tbl_Vender;
import com.ifish.mapper.Tbl_Hardware_Type_Mapper;
import com.ifish.util.IfishUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * @author Administrator
 */
@Component
public class HardWareTypeHelper implements HardWareTypeHelperI {

    /**
     * 所有tbl_Hardware_Type表的操作方法接口
     */
    @Autowired
    private Tbl_Hardware_Type_Mapper tbl_Hardware_Type_Mapper;

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

    @Autowired
    private RedisKeyHelperI redisKeyHelperI;

    @Override
    public Tbl_HardWare_Type getHardwareTypeByTypeCode(String code) throws Exception {
        Tbl_HardWare_Type hardwareType = null;
        String key = redisKeyHelperI.getTbl_HardWare_TypeRedisKeyByTypeCode(code);
        String redisString = redisHelperI.getRedis(key);
        if (StringUtils.isNotBlank(redisString)) {
            hardwareType = (Tbl_HardWare_Type) IfishUtil.JsonToBean(redisString, Tbl_HardWare_Type.class);
        } else {
            hardwareType = tbl_Hardware_Type_Mapper.getHardwareTypeByTypeCode(code);
            if (hardwareType != null && StringUtils.isNotBlank(hardwareType.getHardwareType())) {
                redisHelperI.setRedis(key, IfishUtil.ObjectToJson(hardwareType));
            }
        }
        return hardwareType;
    }

    @Override
    public Tbl_Vender getVenderListByBrandCode(String code) throws Exception {
        Tbl_Vender venderList = new Tbl_Vender();
        String key = redisKeyHelperI.getTbl_Vender_ListRedisKeyByCode(code);
        String redisString = redisHelperI.getRedis(key);
        if (StringUtils.isNotBlank(redisString)) {
            venderList = (Tbl_Vender) IfishUtil.JsonToBean(redisString, Tbl_Vender.class);
        } else {
            venderList = tbl_Hardware_Type_Mapper.getVenderListByBrandCode(code);
            redisHelperI.setRedis(key, IfishUtil.ObjectToJson(venderList));
        }
        return venderList;
    }
}
