|
@@ -1,4 +1,4 @@
|
|
|
-package com.storlead.trade.service.impl;
|
|
|
|
|
|
|
+package com.storlead.trade.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
@@ -23,6 +23,7 @@ import com.storlead.trade.service.*;
|
|
|
import com.storlead.trade.vo.MarketEmailsCustomerVO;
|
|
import com.storlead.trade.vo.MarketEmailsCustomerVO;
|
|
|
import com.storlead.trade.vo.MarketEmailsOpenVO;
|
|
import com.storlead.trade.vo.MarketEmailsOpenVO;
|
|
|
import com.storlead.trade.vo.ScheduleStageVO;
|
|
import com.storlead.trade.vo.ScheduleStageVO;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -35,12 +36,14 @@ import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
+import static org.slf4j.LoggerFactory.getLogger;
|
|
|
|
|
+
|
|
|
@Service
|
|
@Service
|
|
|
public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMapper, MarketEmailsEntity>
|
|
public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMapper, MarketEmailsEntity>
|
|
|
implements MarketEmailsService {
|
|
implements MarketEmailsService {
|
|
|
|
|
|
|
|
- private static final org.slf4j.Logger log =
|
|
|
|
|
- org.slf4j.LoggerFactory.getLogger(MarketEmailsServiceImpl.class);
|
|
|
|
|
|
|
+ private static final Logger log =
|
|
|
|
|
+ getLogger(MarketEmailsServiceImpl.class);
|
|
|
|
|
|
|
|
/** AI workflow 单次排期最多重试次数(应对模型思考被截断、未吐出 JSON 的情况) */
|
|
/** AI workflow 单次排期最多重试次数(应对模型思考被截断、未吐出 JSON 的情况) */
|
|
|
private static final int WORKFLOW_MAX_RETRY = 3;
|
|
private static final int WORKFLOW_MAX_RETRY = 3;
|
|
@@ -120,6 +123,27 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
return Result.ok();
|
|
return Result.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result<Object> edit(MarketEmailsDTO dto) {
|
|
|
|
|
+ if (ObjectUtils.isEmpty(dto.getId())) {
|
|
|
|
|
+ return Result.error("id不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ MarketEmailsEntity entity = this.getById(dto.getId());
|
|
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
|
|
+ return Result.error("记录不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ BeanUtils.copyProperties(dto, entity);
|
|
|
|
|
+ boolean isOk = this.updateById(entity);
|
|
|
|
|
+ if (!isOk) {
|
|
|
|
|
+ return Result.error("修改失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!ObjectUtils.isEmpty(entity.getContent())){
|
|
|
|
|
+ //写入邮件内容,替换客户名
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public Result<Object> getOpenList(MarketEmailsDTO dto) {
|
|
public Result<Object> getOpenList(MarketEmailsDTO dto) {
|
|
|
if (dto == null) {
|
|
if (dto == null) {
|
|
@@ -140,12 +164,13 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
wrapper.ne(MarketEmailsEntity::getRecipient, "");
|
|
wrapper.ne(MarketEmailsEntity::getRecipient, "");
|
|
|
// 只查需要的列,减少数据传输
|
|
// 只查需要的列,减少数据传输
|
|
|
wrapper.select(MarketEmailsEntity::getRecipient,
|
|
wrapper.select(MarketEmailsEntity::getRecipient,
|
|
|
|
|
+ MarketEmailsEntity::getCustomerId,
|
|
|
MarketEmailsEntity::getFirstOpenTime,
|
|
MarketEmailsEntity::getFirstOpenTime,
|
|
|
MarketEmailsEntity::getHasProtect,
|
|
MarketEmailsEntity::getHasProtect,
|
|
|
MarketEmailsEntity::getHasSuspend);
|
|
MarketEmailsEntity::getHasSuspend);
|
|
|
List<MarketEmailsEntity> all = this.list(wrapper);
|
|
List<MarketEmailsEntity> all = this.list(wrapper);
|
|
|
// 按 recipient 聚合
|
|
// 按 recipient 聚合
|
|
|
- java.util.Map<String, com.storlead.trade.vo.MarketEmailsOpenVO> aggMap = new java.util.LinkedHashMap<>();
|
|
|
|
|
|
|
+ Map<String, com.storlead.trade.vo.MarketEmailsOpenVO> aggMap = new HashMap<>();
|
|
|
if (!CollectionUtils.isEmpty(all)) {
|
|
if (!CollectionUtils.isEmpty(all)) {
|
|
|
for (MarketEmailsEntity e : all) {
|
|
for (MarketEmailsEntity e : all) {
|
|
|
String r = e.getRecipient();
|
|
String r = e.getRecipient();
|
|
@@ -159,10 +184,11 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
return v;
|
|
return v;
|
|
|
});
|
|
});
|
|
|
vo.setClickCount(vo.getClickCount() + 1);
|
|
vo.setClickCount(vo.getClickCount() + 1);
|
|
|
- // 取最早首次打开时间
|
|
|
|
|
|
|
+ // 取最早首次打开时间,同时记下该条记录所属的 customerId
|
|
|
if (e.getFirstOpenTime() != null) {
|
|
if (e.getFirstOpenTime() != null) {
|
|
|
if (vo.getFirstOpenTime() == null || e.getFirstOpenTime().before(vo.getFirstOpenTime())) {
|
|
if (vo.getFirstOpenTime() == null || e.getFirstOpenTime().before(vo.getFirstOpenTime())) {
|
|
|
vo.setFirstOpenTime(e.getFirstOpenTime());
|
|
vo.setFirstOpenTime(e.getFirstOpenTime());
|
|
|
|
|
+ vo.setCustomerId(e.getCustomerId());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// MAX(has_protect) / MAX(has_suspend) 语义
|
|
// MAX(has_protect) / MAX(has_suspend) 语义
|
|
@@ -175,7 +201,7 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// 按首次打开时间倒序
|
|
// 按首次打开时间倒序
|
|
|
- java.util.List<com.storlead.trade.vo.MarketEmailsOpenVO> sorted = new java.util.ArrayList<>(aggMap.values());
|
|
|
|
|
|
|
+ List<com.storlead.trade.vo.MarketEmailsOpenVO> sorted = new java.util.ArrayList<>(aggMap.values());
|
|
|
sorted.sort((a, b) -> {
|
|
sorted.sort((a, b) -> {
|
|
|
if (a.getFirstOpenTime() == null && b.getFirstOpenTime() == null) return 0;
|
|
if (a.getFirstOpenTime() == null && b.getFirstOpenTime() == null) return 0;
|
|
|
if (a.getFirstOpenTime() == null) return 1;
|
|
if (a.getFirstOpenTime() == null) return 1;
|
|
@@ -188,10 +214,40 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
long total = sorted.size();
|
|
long total = sorted.size();
|
|
|
long from = Math.min((pageIndex - 1) * pageSize, total);
|
|
long from = Math.min((pageIndex - 1) * pageSize, total);
|
|
|
long to = Math.min(from + pageSize, total);
|
|
long to = Math.min(from + pageSize, total);
|
|
|
- java.util.List<com.storlead.trade.vo.MarketEmailsOpenVO> pageList = sorted.subList((int) from, (int) to);
|
|
|
|
|
|
|
+ List<com.storlead.trade.vo.MarketEmailsOpenVO> pageList = sorted.subList((int) from, (int) to);
|
|
|
com.baomidou.mybatisplus.core.metadata.IPage<com.storlead.trade.vo.MarketEmailsOpenVO> page =
|
|
com.baomidou.mybatisplus.core.metadata.IPage<com.storlead.trade.vo.MarketEmailsOpenVO> page =
|
|
|
new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageIndex, pageSize, total);
|
|
new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageIndex, pageSize, total);
|
|
|
page.setRecords(pageList);
|
|
page.setRecords(pageList);
|
|
|
|
|
+ // 回填客户名称(批量查 customer 表)
|
|
|
|
|
+ if (pageList != null && !pageList.isEmpty()) {
|
|
|
|
|
+ java.util.Set<Long> customerIdSet = new java.util.LinkedHashSet<>();
|
|
|
|
|
+ for (com.storlead.trade.vo.MarketEmailsOpenVO v : pageList) {
|
|
|
|
|
+ if (v.getCustomerId() != null) {
|
|
|
|
|
+ customerIdSet.add(v.getCustomerId());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!customerIdSet.isEmpty()) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ java.util.List<com.storlead.trade.entity.CustomerEntity> customers =
|
|
|
|
|
+ customerTradeService.listByIds(new java.util.ArrayList<>(customerIdSet));
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(customers)) {
|
|
|
|
|
+ java.util.Map<Long, String> idToName = new java.util.HashMap<>(customers.size());
|
|
|
|
|
+ for (com.storlead.trade.entity.CustomerEntity c : customers) {
|
|
|
|
|
+ if (c.getId() != null) {
|
|
|
|
|
+ idToName.put(c.getId(), c.getCustomerName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for (com.storlead.trade.vo.MarketEmailsOpenVO v : pageList) {
|
|
|
|
|
+ if (v.getCustomerId() != null) {
|
|
|
|
|
+ v.setCustomerName(idToName.get(v.getCustomerId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
|
+ log.warn("查询客户名称失败,customerIds={} err={}", customerIdSet, ex.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return Result.result(page);
|
|
return Result.result(page);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -219,6 +275,16 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
if (!ok) {
|
|
if (!ok) {
|
|
|
return Result.error("保护失败");
|
|
return Result.error("保护失败");
|
|
|
}
|
|
}
|
|
|
|
|
+ // 同步更新 emails 表的 has_protect
|
|
|
|
|
+ LambdaQueryWrapper<MarketEmailsEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ queryWrapper.in(MarketEmailsEntity::getId, ids);
|
|
|
|
|
+ queryWrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
|
|
+ List<MarketEmailsEntity> list = this.list(queryWrapper);
|
|
|
|
|
+ List<Long> emailIdList = list.stream().filter(e -> e.getEmailId() != null)
|
|
|
|
|
+ .map(MarketEmailsEntity::getEmailId).collect(Collectors.toList());
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(emailIdList)) {
|
|
|
|
|
+// emailService.updateEmailHasProtect(emailIdList, dto.getHasProtect());
|
|
|
|
|
+ }
|
|
|
return Result.ok();
|
|
return Result.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -249,28 +315,6 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
return Result.ok();
|
|
return Result.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- @Transactional(rollbackFor = Throwable.class)
|
|
|
|
|
- public Result<Object> edit(MarketEmailsDTO dto) {
|
|
|
|
|
- if (ObjectUtils.isEmpty(dto.getId())) {
|
|
|
|
|
- return Result.error("id不能为空");
|
|
|
|
|
- }
|
|
|
|
|
- MarketEmailsEntity entity = this.getById(dto.getId());
|
|
|
|
|
- if (ObjectUtils.isEmpty(entity)) {
|
|
|
|
|
- return Result.error("记录不存在");
|
|
|
|
|
- }
|
|
|
|
|
- BeanUtils.copyProperties(dto, entity);
|
|
|
|
|
- boolean isOk = this.updateById(entity);
|
|
|
|
|
- if (!isOk) {
|
|
|
|
|
- return Result.error("修改失败");
|
|
|
|
|
- }
|
|
|
|
|
- if(!ObjectUtils.isEmpty(entity.getContent())){
|
|
|
|
|
- //写入邮件内容,替换客户名
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- return Result.ok();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void addSendTime(MarketingCampaignEntity marketingCampaignEntity) {
|
|
public void addSendTime(MarketingCampaignEntity marketingCampaignEntity) {
|