package com.cyksj.service.mange.impl;

import com.cyksj.redis.RedisService;
import com.cyksj.service.mange.RefreshCacheService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * 项目名: yhlxj2
 * 文件名: RefreshCacheServiceImpl
 * 创建者: JavaZou
 * 创建时间:2024/2/22 16:28
 */
@Service
@RequiredArgsConstructor
public class RefreshCacheServiceImpl implements RefreshCacheService {
	private final RedisService redisService;

	@Override
	public void refreshYhHomePageCache() {
		Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "*");
		redisService.del(keys.toArray(String[]::new));
	}

	@Override
	public void refreshYhHomeCategoryPageCache() {
		Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "category" + "*");
		Set<String> shoKeys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + "category" + "*");
		redisService.del(keys.toArray(String[]::new));
		redisService.del(shoKeys.toArray(String[]::new));
	}

	@Override
	public void refreshGoodsSkuSubsidyPageCache() {
		Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "subsidy" + "*");
		redisService.del(keys.toArray(String[]::new));
	}

	@Override
	public void refreshShopUserIdCacheByYshId(Long yhsId) {
		String yhShopCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + "*";
		Set<String> keys = redisService.keys(yhShopCacheKey);
		redisService.del(keys.toArray(String[]::new));
	}

	@Override
	public void refreshUserShopMangeCache(String customId) {
		Set<String> keys = redisService.keys(RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + customId + "*");
		redisService.del(keys.toArray(String[]::new));
	}
}
