package com.hzs.bonus.component.load;

import com.hzs.common.core.constant.CacheConstants;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.core.utils.DateUtils;
import com.hzs.common.domain.member.achieve.CuMemberSettlePeriod;
import com.hzs.bonus.achieve.service.ICuMemberSettlePeriodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Description:
 * @Author: sui q
 * @Time: 2022/9/6 17:50
 * @Classname: RedisComponent
 * @PackageName: com.hzs.system.component.load
 */
@Component
@Slf4j
class RedisComponent {

    private RedisService redisService;
    private ICuMemberSettlePeriodService memberSettlePeriodService;

    @Autowired
    public void setMemberSettlePeriodService(ICuMemberSettlePeriodService memberSettlePeriodService) {
        this.memberSettlePeriodService = memberSettlePeriodService;
    }

    @Autowired
    public void setRedisService(RedisService redisService) {
        this.redisService = redisService;
    }

    public void initConfig() {
        // 会员结算期间
        List<CuMemberSettlePeriod> cuMemberSettlePeriodList = memberSettlePeriodService.queryCuMemberSettlePeriod();
        cuMemberSettlePeriodList.forEach(cuMemberSettlePeriod -> {
            String tomorrow = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, cuMemberSettlePeriod.getSettleDate());
            String key = CacheConstants.CU_MEMBER_SETTLE_PERIOD + tomorrow;
            redisService.setCacheObject(key, cuMemberSettlePeriod);
        });
    }

}
