|
|
@@ -0,0 +1,45 @@
|
|
|
+package com.qingjian.module.dm.clean;
|
|
|
+
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.ReUtil;
|
|
|
+import cn.hutool.core.util.ReflectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.qingjian.common.base.Cleaned;
|
|
|
+import com.qingjian.common.cache.GlobalCache;
|
|
|
+import com.qingjian.common.model.dm.dto.TableRuleDTO;
|
|
|
+import com.qingjian.module.dm.clean.func.FunProcess;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+public abstract class AbstractExternalDataCleaner<T extends Cleaned> extends AbstractDataCleaner<T> {
|
|
|
+
|
|
|
+ protected abstract T createEntity();
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected CleanResult<T> doClean(Map<Integer, String> rowData, Integer lineNo) {
|
|
|
+ CleanResult<T> cleanResult = new CleanResult<>();
|
|
|
+ T data = createEntity();
|
|
|
+ for (TableRuleDTO rule : tableRules) {
|
|
|
+ int fileColIndex = rule.getFileColIndex();
|
|
|
+ String content = getContent(rowData, fileColIndex, rule.getColumnRule());
|
|
|
+ if (StrUtil.isEmpty(content)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String copyContent = ReUtil.replaceAll(content.trim(), GlobalCache.SPECIAL_CHARS_PATTERN, "");
|
|
|
+ FunProcess funProcess = FunProcess.create().onException((e) -> log.error("清洗函数字段处理异常: {}", content, e));
|
|
|
+ if (funProcess.isExecute()) {
|
|
|
+ copyContent = funProcess.process(copyContent);
|
|
|
+ }
|
|
|
+ ReflectUtil.setFieldValue(data, rule.getFieldNameEn(), copyContent);
|
|
|
+ }
|
|
|
+ if (cleanResult.isValid()) {
|
|
|
+ data.setId(IdUtil.getSnowflakeNextId());
|
|
|
+ data.setFileId(fileId);
|
|
|
+ data.setSheetId(sheetId);
|
|
|
+ cleanResult.setData(data);
|
|
|
+ }
|
|
|
+ return cleanResult;
|
|
|
+ }
|
|
|
+}
|