package com.changhong.epc.rely.api.tool; import com.changhong.epc.constter.base.BaseConst; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.redis.service.CacheUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; /** * 版本号过滤器 */ @Service @Slf4j public class VersionFilterApi implements BaseConst { public static void filter(String defineCode, Object tenantId, Object companyId) { String key; if(ObjectUtil.notEmpty(tenantId) && ObjectUtil.notEmpty(companyId)){ CacheUtils.del(key = getKey(defineCode, tenantId, companyId)); }else { key = String.format("version:master:%s:********************************", getDefineCode(defineCode)); CacheUtils.del(CacheUtils.keys(key).stream().toArray(String[]::new)); } log.debug("更新缓存版本号:{}", key); } public static String getKey(String defineCode, Object tenantId, Object companyId){ return String.format("version:master:%s:%s", getDefineCode(defineCode), MD5.GetMD5Code(tenantId+""+companyId)); } public static String getDefineCode(String defineCode){ int size = 10 - defineCode.length(); StringBuilder res = new StringBuilder(); for (int i = 0; i < size; i++) { res.append('0'); } res.append(defineCode); return res.toString(); } public static void main(String[] args) { for (int i = 0; i < 32; i++) { System.out.print('*'); } } }