|
@@ -7,13 +7,11 @@ import com.simuwang.base.common.conts.Constants;
|
|
|
import com.simuwang.base.mapper.EmailFieldMappingMapper;
|
|
|
import com.simuwang.base.pojo.dos.EmailFieldMappingDO;
|
|
|
import com.simuwang.base.pojo.dto.report.ReportData;
|
|
|
-import com.smppw.common.pojo.ValueLabelVO;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
public abstract class AbstractReportParser<T extends ReportData> implements ReportParser<T> {
|
|
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@@ -22,7 +20,7 @@ public abstract class AbstractReportParser<T extends ReportData> implements Repo
|
|
|
/**
|
|
|
* 字段匹配规则
|
|
|
*/
|
|
|
- protected List<ValueLabelVO> fieldMapper;
|
|
|
+ protected Map<String, String> fieldMapper;
|
|
|
|
|
|
public AbstractReportParser(EmailFieldMappingMapper fieldMappingMapper) {
|
|
|
this.fieldMappingMapper = fieldMappingMapper;
|
|
@@ -35,7 +33,13 @@ public abstract class AbstractReportParser<T extends ReportData> implements Repo
|
|
|
this.logger.error("未设置报告解析规则!");
|
|
|
return;
|
|
|
}
|
|
|
- this.fieldMapper = emailFieldMapping.stream().map(e -> new ValueLabelVO(e.getCode(), e.getName())).collect(Collectors.toList());
|
|
|
+ for (EmailFieldMappingDO mapping : emailFieldMapping) {
|
|
|
+ String code = mapping.getCode();
|
|
|
+ List<String> names = StrUtil.split(mapping.getName(), ",");
|
|
|
+ for (String name : names) {
|
|
|
+ this.fieldMapper.putIfAbsent(name, code);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -46,37 +50,28 @@ public abstract class AbstractReportParser<T extends ReportData> implements Repo
|
|
|
*/
|
|
|
protected void buildInfo(Map<String, Object> extInfoMap, Object info) {
|
|
|
for (Map.Entry<String, Object> entry : extInfoMap.entrySet()) {
|
|
|
- String k = entry.getKey();
|
|
|
- Object v = entry.getValue();
|
|
|
- String fieldValue = StrUtil.toStringOrNull(v);
|
|
|
- if (fieldValue.startsWith("-") || fieldValue.endsWith("-")) {
|
|
|
- fieldValue = null;
|
|
|
+ String k = this.cleaningValue(entry.getKey());
|
|
|
+ String fieldValue = this.cleaningValue(entry.getValue());
|
|
|
+ String fieldName = this.fieldMapper.get(k);
|
|
|
+ if (StrUtil.isBlank(fieldName)) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (fieldValue != null) {
|
|
|
- fieldValue = fieldValue.replace("\r", Constants.EMPTY);
|
|
|
- }
|
|
|
- for (ValueLabelVO vo : this.fieldMapper) {
|
|
|
- String fieldName = vo.getValue();
|
|
|
- List<String> labels = StrUtil.split(vo.getLabel(), ",");
|
|
|
- if (labels.contains(k)) {
|
|
|
- try {
|
|
|
- ReflectUtil.setFieldValue(info, fieldName, fieldValue);
|
|
|
- } catch (Exception e) {
|
|
|
- this.logger.warn("{} 字段值设置错误:{}", fieldName, e.getMessage());
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- for (String label : labels) {
|
|
|
- if (k.contains(label)) {
|
|
|
- try {
|
|
|
- ReflectUtil.setFieldValue(info, fieldName, fieldValue);
|
|
|
- } catch (Exception e) {
|
|
|
- this.logger.warn("{} 字段值设置错误:{}", fieldName, e.getMessage());
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ try {
|
|
|
+ ReflectUtil.setFieldValue(info, fieldName, fieldValue);
|
|
|
+ } catch (Exception e) {
|
|
|
+ this.logger.warn("{} 字段值设置错误:{}", fieldName, e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private String cleaningValue(Object value) {
|
|
|
+ String fieldValue = StrUtil.toStringOrNull(value);
|
|
|
+ if (fieldValue.startsWith("-") || fieldValue.endsWith("-")) {
|
|
|
+ fieldValue = null;
|
|
|
+ }
|
|
|
+ if (fieldValue != null) {
|
|
|
+ fieldValue = fieldValue.replace("\r", Constants.EMPTY);
|
|
|
+ }
|
|
|
+ return StrUtil.isBlank(fieldValue) ? null : fieldValue;
|
|
|
+ }
|
|
|
}
|