Commit 5e13c07c by songyinghui

feat: 销售线索消息通知逻辑

parent 1f61fb82
package com.gic.haoban.manage.service.pojo.bo.content.context; package com.gic.haoban.manage.service.pojo.bo.content.context;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO; import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.service.pojo.bo.NoticeMessageBO; import com.gic.haoban.manage.service.pojo.bo.NoticeMessageBO;
import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerStaticsBO; import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerStaticsBO;
...@@ -61,9 +62,10 @@ public class PotentialCustomerNotifyContext { ...@@ -61,9 +62,10 @@ public class PotentialCustomerNotifyContext {
/** /**
* 构建小程序消息通知 * 构建小程序消息通知
*
* @return * @return
*/ */
public List<NoticeMessageBO> buildNoticeMessage() { public List<NoticeMessageBO> buildHaoBanNoticeMessage() {
if (CollectionUtils.isEmpty(this.customerStaticsBos)) { if (CollectionUtils.isEmpty(this.customerStaticsBos)) {
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -88,9 +90,20 @@ public class PotentialCustomerNotifyContext { ...@@ -88,9 +90,20 @@ public class PotentialCustomerNotifyContext {
noticeMessageBO.setDescription(String.format("新增%s个客户的销售线索,请及时跟进", customerStaticsMap.get(item.getClerkId()))); noticeMessageBO.setDescription(String.format("新增%s个客户的销售线索,请及时跟进", customerStaticsMap.get(item.getClerkId())));
noticeMessageBO.setEnterpriseId(this.enterpriseId); noticeMessageBO.setEnterpriseId(this.enterpriseId);
noticeMessageBO.setRelationId(item.getClerkId()); noticeMessageBO.setRelationId(item.getClerkId());
noticeMessageBO.setMessageContent(""); noticeMessageBO.setMessageContent(this.buildExtendParams(item.getStoreId()));
return noticeMessageBO; return noticeMessageBO;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* 构建跳转参数
* @param storeId
* @return
*/
public String buildExtendParams(String storeId) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("storeId", storeId);
return jsonObject.toJSONString();
}
} }
package com.gic.haoban.manage.service.service.content.adaptor; package com.gic.haoban.manage.service.service.content.adaptor;
import com.alibaba.fastjson.JSON;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO; import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.StaffDTO; import com.gic.haoban.manage.api.dto.StaffDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO; import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
...@@ -30,6 +31,7 @@ import java.util.HashMap; ...@@ -30,6 +31,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -110,7 +112,7 @@ public class PotentialCustomerNotifyBuilder { ...@@ -110,7 +112,7 @@ public class PotentialCustomerNotifyBuilder {
* @param context * @param context
*/ */
public void sendHaoBanNotifyMessage(PotentialCustomerNotifyContext context) { public void sendHaoBanNotifyMessage(PotentialCustomerNotifyContext context) {
List<NoticeMessageBO> noticeMessageBos = context.buildNoticeMessage(); List<NoticeMessageBO> noticeMessageBos = context.buildHaoBanNoticeMessage();
if (CollectionUtils.isEmpty(noticeMessageBos)) { if (CollectionUtils.isEmpty(noticeMessageBos)) {
log.info("好办消息为空"); log.info("好办消息为空");
return; return;
...@@ -120,66 +122,75 @@ public class PotentialCustomerNotifyBuilder { ...@@ -120,66 +122,75 @@ public class PotentialCustomerNotifyBuilder {
/** /**
* 发送应用消息 * 发送应用消息
* 批次中存在导购主门店数据的话 推送主门店数据
* 不存在主门店数据的话 随机推送一个有数据的门店
* *
* @param context * @param context
*/ */
public void sendApplicationMessage(PotentialCustomerNotifyContext context) { public void sendApplicationMessage(PotentialCustomerNotifyContext context) {
if (CollectionUtils.isEmpty(context.getCustomerStaticsBos()) || CollectionUtils.isEmpty(context.getStaffClerkRelations())) { if (CollectionUtils.isEmpty(context.getCustomerStaticsBos())) {
log.info("发送应用消息 参数缺失 {}"); log.info("发送应用消息不存在导购纬度的统计");
return; return;
} }
if (CollectionUtils.isEmpty(context.getStaffClerkRelations())) {
log.info("发送应用消息 不存在导购绑定关系 clerkIds: {}", JSON.toJSONString(context.getClerkIds()));
return;
}
Map<String, WxEnterpriseQwDTO> clerkEnterpriseCacheMap = new HashMap<>();
Map<String, PotentialCustomerStaticsBO> customerStaticsBOMap = context.getCustomerStaticsBos() Map<String, PotentialCustomerStaticsBO> customerStaticsBOMap = context.getCustomerStaticsBos()
.stream() .stream()
.collect(Collectors.toMap(PotentialCustomerStaticsBO::getClerkId, Function.identity(), (v1, v2) -> v1)); .collect(Collectors.toMap(PotentialCustomerStaticsBO::getClerkId, Function.identity(), (v1, v2) -> v1));
Map<String, TabHaobanClerkMainStoreRelated> clerkMainStoreMap = new HashMap<>(); Map<String, TabHaobanClerkMainStoreRelated> clerkMainStoreMap = new HashMap<>();
Map<String, WxEnterpriseQwDTO> clerkEnterpriseMap = new HashMap<>();
for (StaffClerkRelationDTO staffClerkRelation : context.getStaffClerkRelations()) { // 按staffId 聚合
PotentialCustomerStaticsBO customerStaticsBO = customerStaticsBOMap.get(staffClerkRelation.getClerkId()); Map<String, List<StaffClerkRelationDTO>> staffRelationMap = context.getStaffClerkRelations()
if (customerStaticsBO == null || customerStaticsBO.getNum() == null || customerStaticsBO.getNum() == 0) { .stream()
log.info("导购不存在新访问"); .filter(item -> {
PotentialCustomerStaticsBO staticsBO = customerStaticsBOMap.get(item.getClerkId());
return staticsBO != null && staticsBO.getNum() != null && staticsBO.getNum() > 0;
})
.collect(Collectors.groupingBy(StaffClerkRelationDTO::getStaffId));
for (Map.Entry<String, List<StaffClerkRelationDTO>> entry : staffRelationMap.entrySet()) {
if (CollectionUtils.isEmpty(entry.getValue())) {
log.info("成员不存在有数值的绑定关系 staffIf:{}", entry.getKey());
continue; continue;
} }
String staffId = staffClerkRelation.getStaffId(); String staffId = entry.getKey();
TabHaobanClerkMainStoreRelated temp = clerkMainStoreMap.get(staffId); String wxEnterpriseId = entry.getValue().get(0).getWxEnterpriseId();
if (temp == null) { TabHaobanClerkMainStoreRelated tabHaobanClerkMainStoreRelated = clerkMainStoreRelatedService.selectByWxEnterpriseIdAndStoreId(staffId, wxEnterpriseId);
TabHaobanClerkMainStoreRelated tabHaobanClerkMainStoreRelated = clerkMainStoreRelatedService.selectByWxEnterpriseIdAndStoreId(staffId, staffClerkRelation.getWxEnterpriseId()); if (tabHaobanClerkMainStoreRelated == null) {
if (tabHaobanClerkMainStoreRelated == null) { log.info("成员无主门店信息,不做处理 {}", staffId);
tabHaobanClerkMainStoreRelated = new TabHaobanClerkMainStoreRelated(); continue;
}
clerkMainStoreMap.put(staffId, tabHaobanClerkMainStoreRelated);
temp = clerkMainStoreMap.get(staffId);
} }
Optional<StaffClerkRelationDTO> mainStoreClerkRelation = entry.getValue()
if (temp != null) { .stream()
if (StringUtils.isBlank(temp.getStoreId())) { .filter(item -> StringUtils.equals(item.getStoreId(), tabHaobanClerkMainStoreRelated.getStoreId()))
// 该成员无主门店 .findFirst();
log.info("成员无主门店 {}", staffId); StaffClerkRelationDTO staffClerkRelation = entry.getValue().get(0);
continue; if (mainStoreClerkRelation.isPresent()) {
} staffClerkRelation = mainStoreClerkRelation.get();
if (StringUtils.isBlank(temp.getStoreId())) { }
log.info("成员不存在主门店 {}", staffId); log.info("发送应用消息的导购绑定关系 {}", JSON.toJSONString(staffClerkRelation));
continue; // 需要发送应用消息
} WxEnterpriseQwDTO wxEnterpriseQwDTO = clerkEnterpriseCacheMap.get(staffClerkRelation.getWxEnterpriseId());
// 需要发送应用消息 if (wxEnterpriseQwDTO == null) {
WxEnterpriseQwDTO wxEnterpriseQwDTO = clerkEnterpriseMap.get(staffClerkRelation.getWxEnterpriseId()); wxEnterpriseQwDTO = wxEnterpriseService.getQwInfo(staffClerkRelation.getWxEnterpriseId());
if (wxEnterpriseQwDTO == null) { clerkEnterpriseCacheMap.put(staffClerkRelation.getWxEnterpriseId(), wxEnterpriseQwDTO);
wxEnterpriseQwDTO = wxEnterpriseService.getQwInfo(staffClerkRelation.getWxEnterpriseId()); }
clerkEnterpriseMap.put(staffClerkRelation.getWxEnterpriseId(), wxEnterpriseQwDTO); wxEnterpriseQwDTO = clerkEnterpriseCacheMap.get(staffClerkRelation.getWxEnterpriseId());
} if (wxEnterpriseQwDTO == null) {
wxEnterpriseQwDTO = clerkEnterpriseMap.get(staffClerkRelation.getWxEnterpriseId()); log.info("企业信息不存在 {}", staffClerkRelation.getWxEnterpriseId());
if (wxEnterpriseQwDTO == null) { continue;
log.info("企业信息不存在 {}", staffClerkRelation.getWxEnterpriseId());
return;
}
QywxXcxSendMessageDTO messageDTO = this.buildApplicationMessage(staffClerkRelation, wxEnterpriseQwDTO, customerStaticsBO.getNum());
boolean sendMessage = qywxSuiteApiService.sendMessage(wxEnterpriseQwDTO.getThirdCorpid(), config.getWxSuiteid(), messageDTO);
log.info("发送应用消息结果 {}", sendMessage);
} }
QywxXcxSendMessageDTO messageDTO = this.buildApplicationMessage(staffClerkRelation, wxEnterpriseQwDTO,
customerStaticsBOMap.get(staffClerkRelation.getClerkId()).getNum(), context.buildExtendParams(staffClerkRelation.getStoreId()));
boolean sendMessage = qywxSuiteApiService.sendMessage(wxEnterpriseQwDTO.getThirdCorpid(), config.getWxSuiteid(), messageDTO);
log.info("发送销售线索应用消息结果 {}", sendMessage);
} }
} }
public QywxXcxSendMessageDTO buildApplicationMessage(StaffClerkRelationDTO staffClerkRelation, WxEnterpriseQwDTO wxEnterpriseQwDTO, int count) { public QywxXcxSendMessageDTO buildApplicationMessage(StaffClerkRelationDTO staffClerkRelation, WxEnterpriseQwDTO wxEnterpriseQwDTO, int count, String extendParams) {
StaffDTO staffDTO = staffApiService.selectById(staffClerkRelation.getStaffId()); StaffDTO staffDTO = staffApiService.selectById(staffClerkRelation.getStaffId());
String wxUserId = staffDTO.getWxUserId(); String wxUserId = staffDTO.getWxUserId();
...@@ -194,7 +205,7 @@ public class PotentialCustomerNotifyBuilder { ...@@ -194,7 +205,7 @@ public class PotentialCustomerNotifyBuilder {
list.add(wxUserId); list.add(wxUserId);
messageDTO.setAppid(config.getAppid()); messageDTO.setAppid(config.getAppid());
messageDTO.setUserIds(list); messageDTO.setUserIds(list);
messageDTO.setPage(NoticeMessageUtil.buildMiniAppUrl(NoticeMessageTypeEnum.MATERIAL_REPORT_NOTIFY, "")); messageDTO.setPage(NoticeMessageUtil.buildMiniAppUrl(NoticeMessageTypeEnum.MATERIAL_REPORT_NOTIFY, extendParams));
messageDTO.setTitle("销售线索通知"); messageDTO.setTitle("销售线索通知");
messageDTO.setItems(Collections.singletonList(itemDTO)); messageDTO.setItems(Collections.singletonList(itemDTO));
return messageDTO; return messageDTO;
......
...@@ -227,6 +227,7 @@ public class PotentialCustomerServiceImpl implements PotentialCustomerService { ...@@ -227,6 +227,7 @@ public class PotentialCustomerServiceImpl implements PotentialCustomerService {
// 构建应用内消息 // 构建应用内消息
potentialCustomerNotifyBuilder.sendHaoBanNotifyMessage(context); potentialCustomerNotifyBuilder.sendHaoBanNotifyMessage(context);
// 如果该导购id是成员在主门店时的导购id 发送应用消息 // 如果该导购id是成员在主门店时的导购id 发送应用消息
// 如果本批数据中无成员主门店数据 则不发送
potentialCustomerNotifyBuilder.sendApplicationMessage(context); potentialCustomerNotifyBuilder.sendApplicationMessage(context);
} }
......
...@@ -69,7 +69,7 @@ public class InteractRecordTest { ...@@ -69,7 +69,7 @@ public class InteractRecordTest {
message.setMemberId(memberId); message.setMemberId(memberId);
message.setUnionId(memberId); message.setUnionId(memberId);
message.setStoreId("ff8080818499a54801849ce85f9f003f"); message.setStoreId("ff8080818499a54801849ce85f9f003f");
message.setMaterialId("1232139123912"); message.setMaterialId("123213");
message.setChannelSource(TriggerCustomerChannelType.PYQ.getCode()); message.setChannelSource(TriggerCustomerChannelType.PYQ.getCode());
message.setEventType(MaterialInteractRecordEventType.VISIT_PRODUCT.getCode()); message.setEventType(MaterialInteractRecordEventType.VISIT_PRODUCT.getCode());
message.setGoodsId("fbc508e395f846ef9005852c420e1c23"); message.setGoodsId("fbc508e395f846ef9005852c420e1c23");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment