package cn.newfeifan.mall.module.distri.config;

import cn.newfeifan.mall.framework.common.util.json.JsonUtils;
import cn.newfeifan.mall.module.distri.controller.admin.orderpercentage.vo.OrderPercentageRedisVO;
import cn.newfeifan.mall.module.distri.dal.dataobject.orderpercentage.OrderPercentageDO;
import cn.newfeifan.mall.module.distri.service.orderpercentage.OrderPercentageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import static cn.newfeifan.mall.module.distri.constant.DistriConstants.DISTRI_ORDER_PERCENTAGE;

/**
 * 身价配置,服务器启动时，缓存到服务器的全局静态变量中
 */
@Slf4j
@Component
public class orderPercentageConfig {

    @Resource
    private OrderPercentageService orderPercentageService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @PostConstruct
    public void init(){
        OrderPercentageDO orderPercentageDO = orderPercentageService.queryStatus();
        OrderPercentageRedisVO build = OrderPercentageRedisVO
                .builder()
                .signInSocialStatus(orderPercentageDO.getSignInSocialStatus())
                .signInSocialStatusMax(orderPercentageDO.getSignInSocialStatusMax())
                .build();
        stringRedisTemplate.opsForValue().set(DISTRI_ORDER_PERCENTAGE, JsonUtils.toJsonString(build));
        log.info("======初始化身价配置成功======");
    }
}
