Commit 5e13c07c by songyinghui

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

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