Browse Source
Merge in DESIGN/design from ~DESTINY.LIN/design:release/11.0 to release/11.0 * commit '31c30d8c4fb900e368ee2ef4b6037fe8705f82ad': REPORT-80695 模板全局级别查找替换二期 为了通过插件校验,增加一下注释 REPORT-80695 模板全局级别查找替换二期 校验newui
Destiny.Lin-林锦龙
2 years ago
6 changed files with 169 additions and 14 deletions
@ -0,0 +1,135 @@
|
||||
package com.fr.design.actions.replace.action; |
||||
|
||||
import com.fr.design.actions.replace.info.Info; |
||||
import com.fr.design.i18n.Toolkit; |
||||
import org.jetbrains.annotations.Nullable; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 校验JS、公式、控件、组件 |
||||
* 比较用户的所有对应类别的改动,不论是否选中要替换,只要整体类别改动过就算模板内容改动过 |
||||
* |
||||
* @author Destiny.Lin |
||||
* @version 11.0 |
||||
* created by Destiny.Lin on 2022-11-03 |
||||
*/ |
||||
public enum ITChecker { |
||||
/** |
||||
* 控件 |
||||
*/ |
||||
WIDGET_CHECK_TAG(Toolkit.i18nText("Fine-Design_Basic_Widget")), |
||||
/** |
||||
* 公式 |
||||
*/ |
||||
FORMULA_CHECK_TAG(Toolkit.i18nText("Fine-Design_Basic_Formula")), |
||||
/** |
||||
* JS |
||||
*/ |
||||
JS_CHECK_TAG(Toolkit.i18nText("Fine-Design_Replace_JS")), |
||||
/** |
||||
* 组件 |
||||
*/ |
||||
COMPONENT_CHECK_TAG(Toolkit.i18nText("Fine-Design_Replace_Component")) |
||||
; |
||||
|
||||
|
||||
String name; |
||||
|
||||
ITChecker(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 匹配 |
||||
* |
||||
* @param name 对应的检查类型 |
||||
* @return 对应的检查checker |
||||
*/ |
||||
@Nullable |
||||
public static ITChecker match(String name) { |
||||
ITChecker[] values = ITChecker.values(); |
||||
for (ITChecker value : values) { |
||||
if (value.name.equals(name)) { |
||||
return value; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public static List<? extends Info> checkList = new ArrayList<>(); |
||||
public static Map<String, Integer> appearTimesMap = new HashMap<>(); |
||||
|
||||
|
||||
/** |
||||
* 更新对应的check列表 |
||||
* |
||||
* @param list 查找后的searchList |
||||
*/ |
||||
public static void updateCheckInfo(List<? extends Info> list) { |
||||
checkList = list; |
||||
updateCheckMapFromList(list); |
||||
} |
||||
|
||||
/** |
||||
* 根据列表来更新对应元素的匹配Map |
||||
* |
||||
* @param list 更新后的checkList |
||||
*/ |
||||
private static void updateCheckMapFromList(List<? extends Info> list) { |
||||
appearTimesMap.clear(); |
||||
for (Info info : list) { |
||||
String showStr = info.getContent().getOldShowStr(); |
||||
if (appearTimesMap.containsKey(showStr)) { |
||||
//如果已经存过了就个数+1
|
||||
appearTimesMap.put(showStr, appearTimesMap.get(showStr) + 1); |
||||
} else { |
||||
//没有的话就把个数初始化为1个
|
||||
appearTimesMap.put(showStr, 1); |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 判断是否修改过 |
||||
* |
||||
* @param list 重新获取的当前模板最新的list |
||||
* @return 修改过返回true |
||||
*/ |
||||
public boolean isChanged(List<? extends Info> list) { |
||||
if (list.size() != checkList.size()) { |
||||
//如果总的数据的数量变了,就说明肯定修改过,没必要再进行下一步
|
||||
return true; |
||||
} |
||||
return isChangedCheckByMap(list); |
||||
} |
||||
|
||||
/** |
||||
* 通过检查Map来比较是否修改过 |
||||
* |
||||
* @param list 传入的用于比较的list |
||||
* @return 修改过则返回true |
||||
*/ |
||||
private boolean isChangedCheckByMap(List<? extends Info> list) { |
||||
for (Info info : list) { |
||||
String showStr = info.getContent().getOldShowStr(); |
||||
if (appearTimesMap.containsKey(showStr)) { |
||||
//如果map中存在对应的值,就抵消,个数-1
|
||||
appearTimesMap.put(showStr, appearTimesMap.get(showStr) - 1); |
||||
if (appearTimesMap.get(showStr) < 0) { |
||||
//如果map中的值小于0了,就说明数量对不上,修改过
|
||||
return true; |
||||
} |
||||
} else { |
||||
//如果存在map中没存的值就没必要继续下去了,肯定改过
|
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
} |
Loading…
Reference in new issue