|
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
@@ -157,9 +158,9 @@ public class EmailTemplateService {
|
|
return CollUtil.newArrayList();
|
|
return CollUtil.newArrayList();
|
|
}
|
|
}
|
|
|
|
|
|
- List<Map<String, String>> fieldValueMapList = CollUtil.newArrayList();
|
|
|
|
Map<String, Pair<Integer, Integer>> fieldPositionMap = MapUtil.newHashMap();
|
|
Map<String, Pair<Integer, Integer>> fieldPositionMap = MapUtil.newHashMap();
|
|
- Map<String, String> fieldPatternMap = MapUtil.newHashMap();
|
|
|
|
|
|
+ Map<String, String> fieldPatternMap = MapUtil.newHashMap(8);
|
|
|
|
+ Map<String, BigDecimal> fieldUnitConvertMap = MapUtil.newHashMap(8);
|
|
for (TemplateDataRuleDTO dataRuleDTO : dataRuleDTOS) {
|
|
for (TemplateDataRuleDTO dataRuleDTO : dataRuleDTOS) {
|
|
Integer row = dataRuleDTO.getRow() - 1;
|
|
Integer row = dataRuleDTO.getRow() - 1;
|
|
int column = columnLetterToIndex(dataRuleDTO.getColumn());
|
|
int column = columnLetterToIndex(dataRuleDTO.getColumn());
|
|
@@ -168,7 +169,12 @@ public class EmailTemplateService {
|
|
if (StrUtil.isNotBlank(dataRuleDTO.getFieldRule())) {
|
|
if (StrUtil.isNotBlank(dataRuleDTO.getFieldRule())) {
|
|
fieldPatternMap.put(FILE_TYPE_MAP.get(dataRuleDTO.getFieldName()), dataRuleDTO.getFieldRule());
|
|
fieldPatternMap.put(FILE_TYPE_MAP.get(dataRuleDTO.getFieldName()), dataRuleDTO.getFieldRule());
|
|
}
|
|
}
|
|
|
|
+ if (dataRuleDTO.getUnitConvert() != null) {
|
|
|
|
+ fieldUnitConvertMap.put(FILE_TYPE_MAP.get(dataRuleDTO.getFieldName()), dataRuleDTO.getUnitConvert());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ List<Map<String, String>> fieldValueMapList = CollUtil.newArrayList();
|
|
if (direction.equals(EmailDataDirectionConst.ROW_DIRECTION_TYPE)) {
|
|
if (direction.equals(EmailDataDirectionConst.ROW_DIRECTION_TYPE)) {
|
|
int startRow = fieldPositionMap.values().stream().map(Pair::getKey).min(Integer::compareTo).orElse(0);
|
|
int startRow = fieldPositionMap.values().stream().map(Pair::getKey).min(Integer::compareTo).orElse(0);
|
|
for (int i = startRow + 1; i <= sheet.getLastRowNum(); i++) {
|
|
for (int i = startRow + 1; i <= sheet.getLastRowNum(); i++) {
|
|
@@ -179,10 +185,13 @@ public class EmailTemplateService {
|
|
}
|
|
}
|
|
for (Map.Entry<String, Pair<Integer, Integer>> fieldEntry : fieldPositionMap.entrySet()) {
|
|
for (Map.Entry<String, Pair<Integer, Integer>> fieldEntry : fieldPositionMap.entrySet()) {
|
|
String fieldName = fieldEntry.getKey();
|
|
String fieldName = fieldEntry.getKey();
|
|
- String fieldRule = fieldPatternMap.get(fieldName);
|
|
|
|
int columnIndex = fieldEntry.getValue().getValue();
|
|
int columnIndex = fieldEntry.getValue().getValue();
|
|
Cell cell = row.getCell(columnIndex);
|
|
Cell cell = row.getCell(columnIndex);
|
|
|
|
+ String fieldRule = fieldPatternMap.get(fieldName);
|
|
String cellValue = getValueByPattern(ExcelUtil.getCellValue(cell), fieldRule);
|
|
String cellValue = getValueByPattern(ExcelUtil.getCellValue(cell), fieldRule);
|
|
|
|
+
|
|
|
|
+ BigDecimal unitConvert = fieldUnitConvertMap.get(fieldName);
|
|
|
|
+ cellValue = getValueAfterUnitConvert(cellValue, unitConvert);
|
|
fieldValueMap.put(fieldName, cellValue);
|
|
fieldValueMap.put(fieldName, cellValue);
|
|
}
|
|
}
|
|
fieldValueMapList.add(fieldValueMap);
|
|
fieldValueMapList.add(fieldValueMap);
|
|
@@ -194,15 +203,18 @@ public class EmailTemplateService {
|
|
Map<String, String> fieldValueMap = MapUtil.newHashMap();
|
|
Map<String, String> fieldValueMap = MapUtil.newHashMap();
|
|
for (Map.Entry<String, Pair<Integer, Integer>> fieldEntry : fieldPositionMap.entrySet()) {
|
|
for (Map.Entry<String, Pair<Integer, Integer>> fieldEntry : fieldPositionMap.entrySet()) {
|
|
String fieldName = fieldEntry.getKey();
|
|
String fieldName = fieldEntry.getKey();
|
|
- String fieldRule = fieldPatternMap.get(fieldName);
|
|
|
|
Integer rowIndex = fieldEntry.getValue().getKey();
|
|
Integer rowIndex = fieldEntry.getValue().getKey();
|
|
- Integer columnIndex = fieldEntry.getValue().getValue();
|
|
|
|
Row row = sheet.getRow(rowIndex);
|
|
Row row = sheet.getRow(rowIndex);
|
|
if (row == null) {
|
|
if (row == null) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+ Integer columnIndex = fieldEntry.getValue().getValue();
|
|
Cell cell = row.getCell(columnIndex);
|
|
Cell cell = row.getCell(columnIndex);
|
|
|
|
+ String fieldRule = fieldPatternMap.get(fieldName);
|
|
String cellValue = getValueByPattern(ExcelUtil.getCellValue(cell), fieldRule);
|
|
String cellValue = getValueByPattern(ExcelUtil.getCellValue(cell), fieldRule);
|
|
|
|
+
|
|
|
|
+ BigDecimal unitConvert = fieldUnitConvertMap.get(fieldName);
|
|
|
|
+ cellValue = getValueAfterUnitConvert(cellValue, unitConvert);
|
|
fieldValueMap.put(fieldName, cellValue);
|
|
fieldValueMap.put(fieldName, cellValue);
|
|
}
|
|
}
|
|
fieldValueMapList.add(fieldValueMap);
|
|
fieldValueMapList.add(fieldValueMap);
|
|
@@ -213,7 +225,7 @@ public class EmailTemplateService {
|
|
Map<String, String> fieldValueMap = MapUtil.newHashMap();
|
|
Map<String, String> fieldValueMap = MapUtil.newHashMap();
|
|
for (Map.Entry<String, Pair<Integer, Integer>> fieldEntry : fieldPositionMap.entrySet()) {
|
|
for (Map.Entry<String, Pair<Integer, Integer>> fieldEntry : fieldPositionMap.entrySet()) {
|
|
String fieldName = fieldEntry.getKey();
|
|
String fieldName = fieldEntry.getKey();
|
|
- String fieldRule = fieldPatternMap.get(fieldName);
|
|
|
|
|
|
+
|
|
Integer rowIndex = fieldEntry.getValue().getKey();
|
|
Integer rowIndex = fieldEntry.getValue().getKey();
|
|
Integer columnIndex = fieldEntry.getValue().getValue();
|
|
Integer columnIndex = fieldEntry.getValue().getValue();
|
|
Row row = sheet.getRow(rowIndex);
|
|
Row row = sheet.getRow(rowIndex);
|
|
@@ -221,35 +233,19 @@ public class EmailTemplateService {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
Cell cell = row.getCell(columnIndex);
|
|
Cell cell = row.getCell(columnIndex);
|
|
|
|
+ String fieldRule = fieldPatternMap.get(fieldName);
|
|
String cellValue = getValueByPattern(ExcelUtil.getCellValue(cell), fieldRule);
|
|
String cellValue = getValueByPattern(ExcelUtil.getCellValue(cell), fieldRule);
|
|
|
|
+
|
|
|
|
+ BigDecimal unitConvert = fieldUnitConvertMap.get(fieldName);
|
|
|
|
+ cellValue = getValueAfterUnitConvert(cellValue, unitConvert);
|
|
fieldValueMap.put(fieldName, cellValue);
|
|
fieldValueMap.put(fieldName, cellValue);
|
|
}
|
|
}
|
|
fieldValueMapList.add(fieldValueMap);
|
|
fieldValueMapList.add(fieldValueMap);
|
|
}
|
|
}
|
|
-
|
|
|
|
return fieldValueMapList;
|
|
return fieldValueMapList;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 根据正则表达式提取内容
|
|
|
|
- *
|
|
|
|
- * @param text 文本
|
|
|
|
- * @param fieldRule 正则表达式
|
|
|
|
- * @return 内容
|
|
|
|
- */
|
|
|
|
- private String getValueByPattern(String text, String fieldRule) {
|
|
|
|
- if (StrUtil.isBlank(text) || StrUtil.isBlank(fieldRule)) {
|
|
|
|
- return text;
|
|
|
|
- }
|
|
|
|
- Pattern pattern = Pattern.compile(fieldRule);
|
|
|
|
- Matcher matcher = pattern.matcher(text);
|
|
|
|
- while (matcher.find()) {
|
|
|
|
- return matcher.group(1);
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
* 封装解析的数据为净值数据
|
|
* 封装解析的数据为净值数据
|
|
*
|
|
*
|
|
* @param textFieldValueMap 从正文表格中解析到的数据
|
|
* @param textFieldValueMap 从正文表格中解析到的数据
|
|
@@ -290,11 +286,12 @@ public class EmailTemplateService {
|
|
int type = StrUtil.isNotBlank(emailContentInfoDTO.getFilePath()) && ExcelUtil.isHTML(emailContentInfoDTO.getFilePath()) ? 2 : 1;
|
|
int type = StrUtil.isNotBlank(emailContentInfoDTO.getFilePath()) && ExcelUtil.isHTML(emailContentInfoDTO.getFilePath()) ? 2 : 1;
|
|
// 查询邮箱配置的模板Id
|
|
// 查询邮箱配置的模板Id
|
|
List<EmailTemplateInfoDO> emailTemplateInfoDOList = emailTemplateMappingMapper.queryByEmail(senderEmail, type);
|
|
List<EmailTemplateInfoDO> emailTemplateInfoDOList = emailTemplateMappingMapper.queryByEmail(senderEmail, type);
|
|
- List<Integer> templateIdList = emailTemplateInfoDOList.stream().map(EmailTemplateInfoDO::getId).collect(Collectors.toList());
|
|
|
|
|
|
+ List<Integer> templateIdList = emailTemplateInfoDOList.stream().map(EmailTemplateInfoDO::getId).distinct().collect(Collectors.toList());
|
|
if (CollUtil.isEmpty(templateIdList)) {
|
|
if (CollUtil.isEmpty(templateIdList)) {
|
|
return templateDetailDTOList;
|
|
return templateDetailDTOList;
|
|
}
|
|
}
|
|
- Map<Integer, EmailTemplateInfoDO> templateIdDirectionMap = emailTemplateInfoDOList.stream().collect(Collectors.toMap(EmailTemplateInfoDO::getId, v -> v));
|
|
|
|
|
|
+ Map<Integer, EmailTemplateInfoDO> templateIdDirectionMap = emailTemplateInfoDOList.stream()
|
|
|
|
+ .collect(Collectors.toMap(EmailTemplateInfoDO::getId, v -> v, (oldValue, newValue) -> newValue));
|
|
// 查询模版适用性规则 -> 判断邮件是否满足模板适用性规则
|
|
// 查询模版适用性规则 -> 判断邮件是否满足模板适用性规则
|
|
List<EmailTemplateApplicationRuleDO> templateApplicationRuleDOList = emailTemplateApplicationRuleMapper.queryByTemplateId(templateIdList);
|
|
List<EmailTemplateApplicationRuleDO> templateApplicationRuleDOList = emailTemplateApplicationRuleMapper.queryByTemplateId(templateIdList);
|
|
if (CollUtil.isEmpty(templateApplicationRuleDOList)) {
|
|
if (CollUtil.isEmpty(templateApplicationRuleDOList)) {
|
|
@@ -415,6 +412,44 @@ public class EmailTemplateService {
|
|
return isMatch;
|
|
return isMatch;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 进行单位转换
|
|
|
|
+ *
|
|
|
|
+ * @param cellValue 待进行单位转换的值
|
|
|
|
+ * @param unitConvert 转换单位
|
|
|
|
+ * @return 单位转换后的值
|
|
|
|
+ */
|
|
|
|
+ private String getValueAfterUnitConvert(String cellValue, BigDecimal unitConvert) {
|
|
|
|
+ if (unitConvert == null) {
|
|
|
|
+ return cellValue;
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(cellValue);
|
|
|
|
+ return String.valueOf(bigDecimal.multiply(unitConvert));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ return cellValue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据正则表达式提取内容
|
|
|
|
+ *
|
|
|
|
+ * @param text 文本
|
|
|
|
+ * @param fieldRule 正则表达式
|
|
|
|
+ * @return 内容
|
|
|
|
+ */
|
|
|
|
+ private String getValueByPattern(String text, String fieldRule) {
|
|
|
|
+ if (StrUtil.isBlank(text) || StrUtil.isBlank(fieldRule)) {
|
|
|
|
+ return text;
|
|
|
|
+ }
|
|
|
|
+ Pattern pattern = Pattern.compile(fieldRule);
|
|
|
|
+ Matcher matcher = pattern.matcher(text);
|
|
|
|
+ while (matcher.find()) {
|
|
|
|
+ return matcher.group(1);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
private EmailFundNavDTO buildEmailFundNavDTO(Map<String, String> excelFieldValueMap, Map<String, String> textFieldValueMap) {
|
|
private EmailFundNavDTO buildEmailFundNavDTO(Map<String, String> excelFieldValueMap, Map<String, String> textFieldValueMap) {
|
|
EmailFundNavDTO fundNavDTO = new EmailFundNavDTO();
|
|
EmailFundNavDTO fundNavDTO = new EmailFundNavDTO();
|
|
String registerNumber = MapUtil.isNotEmpty(excelFieldValueMap) && StrUtil.isNotBlank(excelFieldValueMap.get(EmailFieldConst.REGISTER_NUMBER))
|
|
String registerNumber = MapUtil.isNotEmpty(excelFieldValueMap) && StrUtil.isNotBlank(excelFieldValueMap.get(EmailFieldConst.REGISTER_NUMBER))
|