|
@@ -38,6 +38,8 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.function.Consumer;
|
|
import java.util.function.Consumer;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
|
|
|
|
@@ -377,12 +379,12 @@ public class MarketingCampaignServiceImpl
|
|
|
Integer replyCount = replyCountLong == null ? 0 : replyCountLong.intValue();
|
|
Integer replyCount = replyCountLong == null ? 0 : replyCountLong.intValue();
|
|
|
stats.setReplyCount(replyCount);
|
|
stats.setReplyCount(replyCount);
|
|
|
|
|
|
|
|
- // 打开率 = openCount / sentCount
|
|
|
|
|
- stats.setOpenRate(sentCount > 0 ? Math.round(openCount * 100f / sentCount) : 0);
|
|
|
|
|
- // 回复率 = replyCount / sentCount
|
|
|
|
|
- stats.setReplyRate(sentCount > 0 ? Math.round(replyCount * 100f / sentCount) : 0);
|
|
|
|
|
- // 达成率 = 已发送数 / 全部未删邮件数(与 getList sentRate 口径一致)
|
|
|
|
|
- stats.setAchievementRate(emailCountAll > 0 ? Math.round(sentCount * 100f / emailCountAll) : 0);
|
|
|
|
|
|
|
+ // 打开率 = openCount / sentCount,保留两位小数
|
|
|
|
|
+ stats.setOpenRate(calcRatePercent(openCount, sentCount));
|
|
|
|
|
+ // 回复率 = replyCount / sentCount,保留两位小数
|
|
|
|
|
+ stats.setReplyRate(calcRatePercent(replyCount, sentCount));
|
|
|
|
|
+ // 达成率 = 已发送数 / 全部未删邮件数(与 getList sentRate 口径一致),保留两位小数
|
|
|
|
|
+ stats.setAchievementRate(calcRatePercent(sentCount, emailCountAll));
|
|
|
|
|
|
|
|
// 已打开邮件的客户数(distinct customer_id where hasReader=1)
|
|
// 已打开邮件的客户数(distinct customer_id where hasReader=1)
|
|
|
List<MarketEmailsEntity> openedEmailList = marketEmailsService.lambdaQuery()
|
|
List<MarketEmailsEntity> openedEmailList = marketEmailsService.lambdaQuery()
|
|
@@ -409,6 +411,21 @@ public class MarketingCampaignServiceImpl
|
|
|
return Result.result(detailVO);
|
|
return Result.result(detailVO);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 计算百分比(0-100,保留两位小数):numerator / denominator * 100,四舍五入(HALF_UP)。
|
|
|
|
|
+ * denominator <= 0 时返回 0.00(避免除零)。
|
|
|
|
|
+ */
|
|
|
|
|
+ private BigDecimal calcRatePercent(int numerator, int denominator) {
|
|
|
|
|
+// numerator =1;
|
|
|
|
|
+// denominator = 3;
|
|
|
|
|
+ if (denominator <= 0) {
|
|
|
|
|
+ return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
+ }
|
|
|
|
|
+ return BigDecimal.valueOf(numerator)
|
|
|
|
|
+ .multiply(BigDecimal.valueOf(100))
|
|
|
|
|
+ .divide(BigDecimal.valueOf(denominator), 2, RoundingMode.HALF_UP);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Result<Object> addMarket(MarketingCampaignDTO marketingCampaignDTO) {
|
|
public Result<Object> addMarket(MarketingCampaignDTO marketingCampaignDTO) {
|