package com.fzm.mall.server.front.order.service.impl;

import com.alibaba.fastjson.JSON;
import com.fzm.mall.server.front.enums.GoodsRedisEnum;
import com.fzm.mall.server.front.order.model.Config;
import com.fzm.mall.server.front.order.mapper.ConfigMapper;
import com.fzm.mall.server.front.order.service.IConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.mall.server.front.user.service.IRedisService;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单中心-订单设置 服务实现类
 * </p>
 *
 * @author fzm
 * @since 2021-04-13
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements IConfigService {

    @Autowired
    private IRedisService redisService;

    @Autowired
    private ConfigMapper configMapper;

    @Override
    public Config getConfig() {
        String key = redisService.getKey(GoodsRedisEnum.ORDER_CONFIG_KEY.value());
        if(StringUtil.isNullOrEmpty(key)){
            Config config = configMapper.getConfig();
            redisService.setKey(GoodsRedisEnum.ORDER_CONFIG_KEY.value(), JSON.toJSONString(config));
            return config;
        }else{
            return JSON.parseObject(key,Config.class);
        }

    }
}
