YPZ преди 3 седмици
родител
ревизия
87a4de88e6

+ 4 - 0
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/entity/MarketEmailsEntity.java

@@ -120,4 +120,8 @@ public class MarketEmailsEntity extends SysBaseField {
     @TableField("protect_reason")
     private String protectReason;
 
+    @ApiModelProperty(value = "是否是第一封邮件(1首次发送2第二次发送)")
+    @TableField("has_first")
+    private Integer hasFirst;
+
 }

+ 16 - 25
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/service/impl/MarketEmailsServiceImpl.java

@@ -25,6 +25,7 @@ import com.storlead.trade.entity.*;
 import com.storlead.trade.mapper.MarketEmailsMapper;
 import com.storlead.trade.service.*;
 import com.storlead.trade.vo.*;
+import org.apache.commons.lang.time.DateUtils;
 import org.slf4j.Logger;
 import org.springframework.beans.BeanUtils;
 import org.springframework.context.annotation.Lazy;
@@ -1034,6 +1035,7 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
             queryWrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
             queryWrapper.eq(MarketEmailsEntity::getHasProtect,0);
             queryWrapper.eq(MarketEmailsEntity::getHasSuspend,0);
+            queryWrapper.eq(MarketEmailsEntity::getHasFirst,1);
             queryWrapper.eq(MarketEmailsEntity::getMarketingCampaignId, marketingCampaignEntity.getId());
             List<MarketEmailsEntity> marketEmailList = this.list(queryWrapper);
 
@@ -1042,33 +1044,22 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
             }
             log.info("queryWrapper: {}", queryWrapper);
             log.info("marketEmailList: {}", marketEmailList);
-            for (MarketEmailsEntity marketEmail : marketEmailList){
-                MktSendMailRemoteDTO dto = new MktSendMailRemoteDTO();
-                List<String> recipientls = new ArrayList<>();
-                recipientls.add(marketEmail.getRecipient());
-                dto.setRecipientls(recipientls);
-                dto.setSubject(marketEmail.getSubject());
-                dto.setContent(marketEmail.getContent());
-                dto.setIsTrack(1);
-    //            dto.setDelaySendTime(marketEmail.getExpectSendTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime());
-                Result result = mktMailRemoteClient.send(dto);
-                if (result.isSuccess()) {
-                    // 远程返回 result 是 LinkedHashMap(Jackson 默认反序列化),按 Map 取字段
-                    Map<String, Object> sentMail = (Map<String, Object>) result.getResult();
-                    //将邮件id写入MarketEmailsEntity
-                    marketEmail.setEmailId(((Number) sentMail.get("id")).longValue());
-                    marketEmail.setStatus((Integer) sentMail.get("status"));
-                    log.info("id为:{}", sentMail.get("id"));
-                    log.info("status为:{}", sentMail.get("status"));
-                    log.info("邮件发送成功,邮件ID:{}", marketEmail.getId());
-                } else {
-                    log.error("邮件发送失败,邮件ID:{},错误信息:{}", marketEmail.getId(), result.getMessage());
-                }
 
-    //            123
+            List<MarketEmailsEntity> newMarketEmailList = new ArrayList<>();
+            //新增一条需要发送的邮件记录
+            for (MarketEmailsEntity marketEmail : marketEmailList){
+                MarketEmailsEntity newMarketEmail = new MarketEmailsEntity();
+                BeanUtils.copyProperties(marketEmail, newMarketEmail);
+                newMarketEmail.setId(null);
+                newMarketEmail.setStatus(-1);
+                //取当前时间30分钟后
+                Date expectSendTime = DateUtils.addMinutes(new Date(), 30);
+                newMarketEmail.setExpectSendTime(expectSendTime);
+                newMarketEmail.setHasFirst(2);
+                newMarketEmailList.add(newMarketEmail);
             }
-            if (!CollectionUtils.isEmpty(marketEmailList)){
-                this.updateBatchById(marketEmailList);
+            if (!CollectionUtils.isEmpty(newMarketEmailList)){
+                this.saveBatch(newMarketEmailList);
             }
 
         }

+ 17 - 8
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/service/impl/MarketingCampaignServiceImpl.java

@@ -139,12 +139,19 @@ public class MarketingCampaignServiceImpl
                     "count(*) as cnt", qw -> qw.eq("status", -1));
             Map<Long, Long> sentMap = countEmailsByCampaign(marketingCampaignIdList,
                     "count(*) as cnt", qw -> qw.eq("status", 1));
-            Map<Long, Long> sentCustomerMap = countEmailsByCampaign(marketingCampaignIdList,
-                    "count(distinct customer_id) as cnt", qw -> qw.eq("status", 1));
+            Map<Long, Long> firstSentMap = countEmailsByCampaign(marketingCampaignIdList,
+                    "count(*) as cnt", qw -> qw.eq("status", 1).eq("has_first", 1));
+            Map<Long, Long> openedEmailMap = countEmailsByCampaign(marketingCampaignIdList,
+                    "count(*) as cnt", qw -> qw.eq("has_reader", 1));
+            Map<Long, Long> repliedEmailMap = countEmailsByCampaign(marketingCampaignIdList,
+                    "count(*) as cnt", qw -> qw.eq("has_reply", 1));
             Map<Long, Long> cancelledMap = countEmailsByCampaign(marketingCampaignIdList,
                     "count(*) as cnt", qw -> qw.eq("status", -3));
             Map<Long, Long> totalEmailMap = countEmailsByCampaign(marketingCampaignIdList,
                     "count(*) as cnt", qw -> { });
+
+            Map<Long, Long> firstTotalEmailMap = countEmailsByCampaign(marketingCampaignIdList,
+                    "count(*) as cnt", qw -> qw.eq("has_first", 1));
             for (MarketingCampaignVO vo : marketingCampaignVOList) {
                 Long id = vo.getId();
                 vo.setOpenedCustomerCount(toInt(openedMap.get(id)));
@@ -152,17 +159,18 @@ public class MarketingCampaignServiceImpl
                 vo.setProtectWhitelistCount(toInt(protectMap.get(id)));
                 int pending = toInt(pendingMap.get(id));
                 int sent = toInt(sentMap.get(id));
+                int firstSent = toInt(firstSentMap.get(id));
                 int cancelled = toInt(cancelledMap.get(id));
                 vo.setPendingEmailCount(pending);
                 vo.setSentEmailCount(sent);
                 vo.setCancelledEmailCount(cancelled);
                 vo.setEmailCountStats(pending + sent + cancelled);
                 int totalEmail = toInt(totalEmailMap.get(id));
-                vo.setSentRate(totalEmail > 0 ? (double) vo.getOpenedCustomerCount() / totalEmail : 0.0);
-                int sentCustomer = toInt(sentCustomerMap.get(id));
-                vo.setSentCustomerCount(sentCustomer);
-                vo.setOpenRateText(buildRate(toInt(openedMap.get(id)), sentCustomer));
-                vo.setReplyRateText(buildRate(toInt(repliedMap.get(id)), sentCustomer));
+
+                int firstTotalEmail = toInt(firstTotalEmailMap.get(id));
+                vo.setSentRate(totalEmail > 0 ? (double) firstSent / firstTotalEmail : 0.0);
+                vo.setOpenRateText(buildRate(toInt(openedEmailMap.get(id)), sent));
+                vo.setReplyRateText(buildRate(toInt(repliedEmailMap.get(id)), sent));
             }
         }
 
@@ -183,6 +191,7 @@ public class MarketingCampaignServiceImpl
         qw.select("marketing_campaign_id, " + selectExpr);
         qw.in("marketing_campaign_id", campaignIds);
         qw.eq("is_delete", CommonConstant.DEL_FLAG_0);
+//        qw.eq("has_first", 1);
         if (extra != null) {
             extra.accept(qw);
         }
@@ -318,7 +327,7 @@ public class MarketingCampaignServiceImpl
         // 回复率 = replyCount / sentCount
         stats.setReplyRate(sentCount > 0 ? Math.round(replyCount * 100f / sentCount) : 0);
         // 达成率 = openCountLong / emailCount
-        stats.setAchievementRate(openCountLong > 0 ? Math.round(openCountLong * 100f / emailCount) : 0);
+        stats.setAchievementRate(sentCount > 0 ? Math.round(sentCount * 100f / emailCount) : 0);
 
         detailVO.setStats(stats);
 

+ 2 - 5
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/vo/MarketingCampaignVO.java

@@ -182,12 +182,9 @@ public class MarketingCampaignVO extends SysBaseField {
     @ApiModelProperty(value = "统计:已发邮件占比(已发/总,不含删除,0~1)")
     private Double sentRate;
 
-    @ApiModelProperty(value = "统计:已发送客户数(去重 customer_id, status=1)")
-    private Integer sentCustomerCount;
-
-    @ApiModelProperty(value = "统计:打开率(百分比字符串,如 45%,客户维度)")
+    @ApiModelProperty(value = "统计:打开率(百分比字符串,如 45%,邮件维度:opened 邮件数 / sent 邮件数)")
     private String openRateText;
 
-    @ApiModelProperty(value = "统计:回复率(百分比字符串,如 8%,客户维度)")
+    @ApiModelProperty(value = "统计:回复率(百分比字符串,如 8%,邮件维度:replied 邮件数 / sent 邮件数)")
     private String replyRateText;
 }