Преглед на файлове

feat:模板配置-兼容模板适用性规则为空的情况

mozuwen преди 7 месеца
родител
ревизия
4e600a879e
променени са 1 файла, в които са добавени 10 реда и са изтрити 8 реда
  1. 10 8
      service-daq/src/main/java/com/simuwang/daq/service/EmailTemplateService.java

+ 10 - 8
service-daq/src/main/java/com/simuwang/daq/service/EmailTemplateService.java

@@ -293,12 +293,12 @@ public class EmailTemplateService {
         }
         Map<Integer, EmailTemplateInfoDO> templateIdDirectionMap = emailTemplateInfoDOList.stream()
                 .collect(Collectors.toMap(EmailTemplateInfoDO::getId, v -> v, (oldValue, newValue) -> newValue));
-        // 查询模版适用性规则 -> 判断邮件是否满足模板适用性规则
+        // 查询模版适用性规则 -> 判断邮件是否满足模板适用性规则(模板的适应性规则允许为空 -> 这种情况下满足模板的适用条件)
         List<EmailTemplateApplicationRuleDO> templateApplicationRuleDOList = emailTemplateApplicationRuleMapper.queryByTemplateId(templateIdList);
-        if (CollUtil.isEmpty(templateApplicationRuleDOList)) {
-            return templateDetailDTOList;
+        Map<Integer, List<EmailTemplateApplicationRuleDO>> templateIdApplicationRuleMap = MapUtil.newHashMap();
+        if (CollUtil.isNotEmpty(templateApplicationRuleDOList)) {
+            templateIdApplicationRuleMap = templateApplicationRuleDOList.stream().collect(Collectors.groupingBy(EmailTemplateApplicationRuleDO::getTemplateId));
         }
-        Map<Integer, List<EmailTemplateApplicationRuleDO>> templateIdApplicationRuleMap = templateApplicationRuleDOList.stream().collect(Collectors.groupingBy(EmailTemplateApplicationRuleDO::getTemplateId));
         // 查询模版数据规则
         List<EmailTemplateDataRuleDO> templateDataRuleDOList = emailTemplateDataRuleMapper.queryByTemplateId(templateIdList);
         if (CollUtil.isEmpty(templateDataRuleDOList)) {
@@ -309,9 +309,8 @@ public class EmailTemplateService {
                 .filter(e -> (e.getRow() != null && StrUtil.isNotBlank(e.getColumn())) || StrUtil.isNotBlank(e.getFieldRule()))
                 .collect(Collectors.groupingBy(EmailTemplateDataRuleDO::getTemplateId));
 
-        for (Map.Entry<Integer, List<EmailTemplateApplicationRuleDO>> templateIdApplicationRule : templateIdApplicationRuleMap.entrySet()) {
-            Integer templateId = templateIdApplicationRule.getKey();
-            List<EmailTemplateApplicationRuleDO> applicationRuleDOList = templateIdApplicationRule.getValue();
+        for (Integer templateId : templateIdList) {
+            List<EmailTemplateApplicationRuleDO> applicationRuleDOList = templateIdApplicationRuleMap.get(templateId);
             // 判断是否满足模板适用性规则
             boolean isMatchTemplate = isMatchTemplate(textContent, emailContentInfoDTO.getEmailTitle(), emailContentInfoDTO.getFileName(), filePath, applicationRuleDOList);
             if (!isMatchTemplate) {
@@ -340,11 +339,14 @@ public class EmailTemplateService {
      * @param emailTitle            邮件主题
      * @param fileName              附件名称
      * @param filePath              文件路径(邮件正文html转成)
-     * @param applicationRuleDOList 模板配置的适用性规则列表
+     * @param applicationRuleDOList 模板配置的适用性规则列表(为空时 -> 返回true)
      * @return true or false
      */
     private boolean isMatchTemplate(String emailContent, String emailTitle, String fileName,
                                     String filePath, List<EmailTemplateApplicationRuleDO> applicationRuleDOList) {
+        if (CollUtil.isEmpty(applicationRuleDOList)) {
+            return true;
+        }
         return applicationRuleDOList.stream()
                 .allMatch(e -> isMathApplicationRule(e, emailContent, emailTitle, fileName, filePath));
     }