package com.ots.project.tool.report.MAQ.base; import com.ots.common.enums.LangTypeEnum; import com.ots.project.exam.domain.TLibraryCode; import com.ots.project.tool.CacheServiceFactory; import lombok.extern.slf4j.Slf4j; import java.util.Arrays; import java.util.Map; import java.util.Objects; @Slf4j public abstract class BaseCondition { public static final String IMAGE_PREFIX = "_waterDrops"; public abstract String getName(); public abstract TLibraryCode calculate(Map map, LangTypeEnum langType); public abstract Map getMAQwaterDropsImages(); protected String selectTrueObject(Map calculateMap) { for (Map.Entry entry : calculateMap.entrySet()) { Boolean mapKey = entry.getKey(); if (mapKey) { return entry.getValue(); } } return null; } protected boolean checkParamsNonNull(String... value) { return !checkParamsIsNull(value); } protected boolean checkParamsIsNull(String... value) { for (int i = 0; i < value.length; i++) { if (Objects.isNull(value[i])) { return true; } } return false; } public TLibraryCode getMaqReportLibrary(Map map, String codeId, LangTypeEnum langType) { if (Objects.isNull(codeId)) { return null; } StringBuilder content = new StringBuilder(); String[] split = codeId.split(","); TLibraryCode result = new TLibraryCode(); Arrays.stream(split).forEach(item -> { TLibraryCode maqReportLibrary = CacheServiceFactory.getInstance().getMAQReportLibrary(item); if (Objects.isNull(maqReportLibrary)) { log.warn("************** LibraryCode 没有配置 code = {} ***********", item); } else { content.append(maqReportLibrary.getLangTypeContext(langType)); result.setDictType(maqReportLibrary.getDictType()); result.setIcon(maqReportLibrary.getIcon()); result.setLibraryCode(maqReportLibrary.getLibraryCode()); } }); result.setLangTypeContext(content.toString(), langType); dynamicParameterSubstitution(map, result, langType); return result; } public void dynamicParameterSubstitution(Map map, TLibraryCode maqReportLibrary, LangTypeEnum langType) { map.forEach((key, value) -> { String content = maqReportLibrary.getLangTypeContext(langType); String replaceStr = "%" + key + "%"; maqReportLibrary.setLangTypeContext(content.replace(replaceStr, "" + value + ""), langType); }); } }