|
|
@@ -18,6 +18,8 @@ import com.storlead.knowledge.service.ChatService;
|
|
|
import com.storlead.knowledge.service.WorkflowsService;
|
|
|
import com.storlead.mail.pojo.entity.MktMailStatusEntity;
|
|
|
import com.storlead.mail.service.MktMailStatusService;
|
|
|
+import com.storlead.mail.webclient.client.MktMailRemoteClient;
|
|
|
+import com.storlead.mail.webclient.dto.MktSendMailRemoteDTO;
|
|
|
import com.storlead.trade.dto.MarketEmailsDTO;
|
|
|
import com.storlead.trade.entity.*;
|
|
|
import com.storlead.trade.mapper.MarketEmailsMapper;
|
|
|
@@ -32,6 +34,8 @@ import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
@@ -72,6 +76,9 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
@Resource
|
|
|
private MktMailStatusService mktMailStatusService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private MktMailRemoteClient mktMailRemoteClient;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public Result<Object> getList(MarketEmailsDTO dto) {
|
|
|
@@ -720,12 +727,12 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
markerEmailUpdateWrapper.set(MarketEmailsEntity::getStatus, marketEmailsCustomerVO.getStatus());
|
|
|
this.update(null, markerEmailUpdateWrapper);
|
|
|
|
|
|
- if (!CollectionUtils.isEmpty(emailIdList) && !ObjectUtils.isEmpty(marketEmailsCustomerVO.getStatus())){
|
|
|
- LambdaUpdateWrapper<MktMailStatusEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.in(MktMailStatusEntity::getId, emailIdList);
|
|
|
- updateWrapper.set(MktMailStatusEntity::getSendStatus, marketEmailsCustomerVO.getStatus());
|
|
|
- mktMailStatusService.update(null, updateWrapper);
|
|
|
- }
|
|
|
+// if (!CollectionUtils.isEmpty(emailIdList) && !ObjectUtils.isEmpty(marketEmailsCustomerVO.getStatus())){
|
|
|
+// LambdaUpdateWrapper<MktMailStatusEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+// updateWrapper.in(MktMailStatusEntity::getId, emailIdList);
|
|
|
+// updateWrapper.set(MktMailStatusEntity::getSendStatus, marketEmailsCustomerVO.getStatus());
|
|
|
+// mktMailStatusService.update(null, updateWrapper);
|
|
|
+// }
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -847,6 +854,7 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
MarketEmailsEntity marketEmail = new MarketEmailsEntity();
|
|
|
marketEmail.setMarketingCampaignId(marketingCampaignEntity.getId());
|
|
|
marketEmail.setCustomerId(customerVO.getCustomerId());
|
|
|
+ marketEmail.setRecipient(customerVO.getEmail());
|
|
|
marketEmail.setMarketingCampaignSopDetailId(marketingCampaignSopDetail.getId());
|
|
|
marketEmail.setExpectSendTime(scheduleStage.getBeijingDatetime());
|
|
|
marketEmailList.add(marketEmail);
|
|
|
@@ -859,16 +867,80 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
}
|
|
|
if (!marketEmailList.isEmpty()){
|
|
|
//删除原有营销关联的邮件信息
|
|
|
- LambdaUpdateWrapper<MarketEmailsEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(MarketEmailsEntity::getMarketingCampaignId, marketingCampaignEntity.getId());
|
|
|
- updateWrapper.set(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_1);
|
|
|
- this.update(updateWrapper);
|
|
|
+ LambdaQueryWrapper<MarketEmailsEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(MarketEmailsEntity::getMarketingCampaignId, marketingCampaignEntity.getId());
|
|
|
+ queryWrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
+ List<MarketEmailsEntity> marketEmailsOldList = this.list(queryWrapper);
|
|
|
+ marketEmailsOldList.forEach(marketEmail -> marketEmail.setIsDelete(CommonConstant.DEL_FLAG_1));
|
|
|
+ this.updateBatchById(marketEmailsOldList);
|
|
|
+ //删除原有关联邮件记录
|
|
|
+// List<Long> emailIdList = marketEmailsOldList.stream().map(MarketEmailsEntity::getEmailId).collect(Collectors.toList());
|
|
|
+// LambdaUpdateWrapper<MktMailStatusEntity> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+// updateWrapper.in(MktMailStatusEntity::getId, emailIdList);
|
|
|
+// updateWrapper.set(MktMailStatusEntity::getIsDelete, CommonConstant.DEL_FLAG_1);
|
|
|
+// mktMailStatusService.update(updateWrapper);
|
|
|
+
|
|
|
+ marketEmailList.forEach(
|
|
|
+ marketEmail -> {
|
|
|
+ marketEmail.setIsDelete(CommonConstant.DEL_FLAG_0);
|
|
|
+ }
|
|
|
+ );
|
|
|
this.saveBatch(marketEmailList);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void send() {
|
|
|
+ LambdaQueryWrapper<MarketEmailsEntity> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+// queryWrapper.eq(MarketEmailsEntity::getExpectSendTime, new Date());
|
|
|
+ // get start and end of current minute
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime start = now.withSecond(0).withNano(0);
|
|
|
+ LocalDateTime end = now.withSecond(59).withNano(999_999_999);
|
|
|
+ queryWrapper.between(MarketEmailsEntity::getExpectSendTime, start, end);
|
|
|
+
|
|
|
+ queryWrapper.eq(MarketEmailsEntity::getStatus, -1);
|
|
|
+ queryWrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
+ List<MarketEmailsEntity> marketEmailList = this.list(queryWrapper);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(marketEmailList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ 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.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(1);
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(marketEmailList)){
|
|
|
+ this.updateBatchById(marketEmailList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 调用 AI workflow 并解析调度阶段,带重试。
|
|
|
* 入参 chatDTO 经 workflowsService.AiWorkflows 返回 Result<Object>,
|