|
@@ -21,6 +21,7 @@ import com.storlead.trade.entity.*;
|
|
|
import com.storlead.trade.mapper.MarketEmailsMapper;
|
|
import com.storlead.trade.mapper.MarketEmailsMapper;
|
|
|
import com.storlead.trade.service.*;
|
|
import com.storlead.trade.service.*;
|
|
|
import com.storlead.trade.vo.MarketEmailsCustomerVO;
|
|
import com.storlead.trade.vo.MarketEmailsCustomerVO;
|
|
|
|
|
+import com.storlead.trade.vo.MarketEmailsManagementVO;
|
|
|
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.slf4j.Logger;
|
|
@@ -64,6 +65,10 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
@Resource
|
|
@Resource
|
|
|
private WorkflowsService workflowsService;
|
|
private WorkflowsService workflowsService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ @org.springframework.context.annotation.Lazy
|
|
|
|
|
+ private MarketingCampaignService marketingCampaignService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Result<Object> getList(MarketEmailsDTO dto) {
|
|
public Result<Object> getList(MarketEmailsDTO dto) {
|
|
@@ -315,6 +320,107 @@ public class MarketEmailsServiceImpl extends MyBaseServiceImpl<MarketEmailsMappe
|
|
|
return Result.ok();
|
|
return Result.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 取消发送邮件:status 置 -2(软取消,不删数据,isDelete 保持 0)
|
|
|
|
|
+ * 支持单条(dto.id)或批量(dto.idList)
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result<Object> cancel(MarketEmailsDTO dto) {
|
|
|
|
|
+ if (dto == null) {
|
|
|
|
|
+ return Result.error("请求体不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
|
|
+ if (!ObjectUtils.isEmpty(dto.getId())) {
|
|
|
|
|
+ ids.add(dto.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!CollectionUtils.isEmpty(dto.getIdList())) {
|
|
|
|
|
+ ids.addAll(dto.getIdList());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (ids.isEmpty()) {
|
|
|
|
|
+ return Result.error("id 或 idList 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LambdaUpdateWrapper<MarketEmailsEntity> wrapper = new LambdaUpdateWrapper<>();
|
|
|
|
|
+ wrapper.in(MarketEmailsEntity::getId, ids);
|
|
|
|
|
+ wrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
|
|
+ // status = -2 表示取消发送
|
|
|
|
|
+ wrapper.set(MarketEmailsEntity::getStatus, -2);
|
|
|
|
|
+ boolean ok = this.update(wrapper);
|
|
|
|
|
+ if (!ok) {
|
|
|
|
|
+ return Result.error("取消发送失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result<Object> getManagementDetail(Long marketingCampaignId) {
|
|
|
|
|
+ if (ObjectUtils.isEmpty(marketingCampaignId)) {
|
|
|
|
|
+ return Result.error("marketingCampaignId不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 营销活动名(用于拼接在卡片标题位置或返回顶部)
|
|
|
|
|
+ String campaignName = null;
|
|
|
|
|
+ MarketingCampaignEntity campaign = marketingCampaignService.getById(marketingCampaignId);
|
|
|
|
|
+ if (campaign != null) {
|
|
|
|
|
+ campaignName = campaign.getName();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查该营销活动下所有未软删的邮件
|
|
|
|
|
+ LambdaQueryWrapper<MarketEmailsEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(MarketEmailsEntity::getMarketingCampaignId, marketingCampaignId);
|
|
|
|
|
+ wrapper.eq(MarketEmailsEntity::getIsDelete, CommonConstant.DEL_FLAG_0);
|
|
|
|
|
+ wrapper.orderByAsc(MarketEmailsEntity::getExpectSendTime);
|
|
|
|
|
+ List<MarketEmailsEntity> entityList = this.list(wrapper);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(entityList)) {
|
|
|
|
|
+ return Result.ok(new ArrayList<MarketEmailsManagementVO>());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 批量收 ID,减少 N+1
|
|
|
|
|
+ java.util.Set<Long> customerIdSet = new java.util.HashSet<>();
|
|
|
|
|
+ java.util.Set<Long> sopDetailIdSet = new java.util.HashSet<>();
|
|
|
|
|
+ for (MarketEmailsEntity e : entityList) {
|
|
|
|
|
+ if (e.getCustomerId() != null) customerIdSet.add(e.getCustomerId());
|
|
|
|
|
+ if (e.getMarketingCampaignSopDetailId() != null) sopDetailIdSet.add(e.getMarketingCampaignSopDetailId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, CustomerEntity> customerMap = customerIdSet.isEmpty()
|
|
|
|
|
+ ? Collections.emptyMap()
|
|
|
|
|
+ : customerTradeService.listByIds(new java.util.ArrayList<>(customerIdSet)).stream()
|
|
|
|
|
+ .collect(Collectors.toMap(CustomerEntity::getId, c -> c, (a, c) -> a));
|
|
|
|
|
+ Map<Long, MarketingCampaignSopDetailEntity> sopDetailMap = sopDetailIdSet.isEmpty()
|
|
|
|
|
+ ? Collections.emptyMap()
|
|
|
|
|
+ : marketingCampaignSopDetailEntityService.listByIds(new java.util.ArrayList<>(sopDetailIdSet)).stream()
|
|
|
|
|
+ .collect(Collectors.toMap(MarketingCampaignSopDetailEntity::getId, s -> s, (a, c) -> a));
|
|
|
|
|
+
|
|
|
|
|
+ // 组装 VO
|
|
|
|
|
+ List<MarketEmailsManagementVO> voList = new ArrayList<>(entityList.size());
|
|
|
|
|
+ for (MarketEmailsEntity entity : entityList) {
|
|
|
|
|
+ MarketEmailsManagementVO vo = new MarketEmailsManagementVO();
|
|
|
|
|
+ BeanUtils.copyProperties(entity, vo);
|
|
|
|
|
+ // expectSendTime 是 DateTime,VO 是 Date,手动 set(BeanUtils 类型不一致不复制)
|
|
|
|
|
+ if (entity.getExpectSendTime() != null) {
|
|
|
|
|
+ vo.setExpectSendTime(entity.getExpectSendTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ vo.setCampaignName(campaignName);
|
|
|
|
|
+
|
|
|
|
|
+ CustomerEntity customer = customerMap.get(entity.getCustomerId());
|
|
|
|
|
+ if (customer != null) {
|
|
|
|
|
+ vo.setCustomerName(customer.getCustomerName());
|
|
|
|
|
+ vo.setCustomerContact(customer.getCollaborator());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ MarketingCampaignSopDetailEntity sopDetail = sopDetailMap.get(entity.getMarketingCampaignSopDetailId());
|
|
|
|
|
+ if (sopDetail != null) {
|
|
|
|
|
+ vo.setStageName(sopDetail.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ voList.add(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.ok(voList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void addSendTime(MarketingCampaignEntity marketingCampaignEntity) {
|
|
public void addSendTime(MarketingCampaignEntity marketingCampaignEntity) {
|