Commit 1863fc31 by songyinghui

feat: 销售线索通知

parent 22f111f6
...@@ -11,6 +11,7 @@ public enum NoticeMessageCategoryTypeEnum { ...@@ -11,6 +11,7 @@ public enum NoticeMessageCategoryTypeEnum {
TASK(1, "任务相关"), TASK(1, "任务相关"),
ACTIVITY(2, "活动相关"), ACTIVITY(2, "活动相关"),
MATERIAL(4, "素材相关"), MATERIAL(4, "素材相关"),
POTENTIAL_CUSTOMER(5, "销售线索"),
OTHER(3, "其它"),; OTHER(3, "其它"),;
private int type; private int type;
private String name; private String name;
......
...@@ -61,6 +61,8 @@ public enum NoticeMessageTypeEnum { ...@@ -61,6 +61,8 @@ public enum NoticeMessageTypeEnum {
MATERIAL_NEW_NOTIFY(6001, "素材上新通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_new_notify", "/pages/route/index?pageType=", "hbapp_material_center"), MATERIAL_NEW_NOTIFY(6001, "素材上新通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_new_notify", "/pages/route/index?pageType=", "hbapp_material_center"),
MATERIAL_WEEK_REPORT(6002, "素材周报通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_week_notify", "/pages/route/index?pageType=", "hbapp_material_report"), MATERIAL_WEEK_REPORT(6002, "素材周报通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_week_notify", "/pages/route/index?pageType=", "hbapp_material_report"),
POTENTIAL_CUSTOMER_NOTIFY(6003, "销售线索通知", NoticeMessageCategoryTypeEnum.POTENTIAL_CUSTOMER.getType(), "potential_customer_notify", "/pages/route/index?pageType=", "hbapp_sales_clue_center");
; ;
/** /**
* 消息类型 * 消息类型
......
...@@ -52,4 +52,11 @@ public interface QywxGroupMsgTaskApiService { ...@@ -52,4 +52,11 @@ public interface QywxGroupMsgTaskApiService {
* @return * @return
*/ */
ServiceResponse<Void> doHandlerMaterialOneStaffReportMQ(String params); ServiceResponse<Void> doHandlerMaterialOneStaffReportMQ(String params);
/**
* 销售线索 通知job
* @param params
* @return
*/
ServiceResponse<Void> potentialCustomerJob(String params);
} }
...@@ -120,5 +120,5 @@ public interface TabHaobanStaffClerkRelationMapper { ...@@ -120,5 +120,5 @@ public interface TabHaobanStaffClerkRelationMapper {
List<StaffClerkRelationDTO> listByStoreIds(@Param("wxEnterpriseId") String wxEnterpriseId,@Param("storeIds") List<String> storeIds); List<StaffClerkRelationDTO> listByStoreIds(@Param("wxEnterpriseId") String wxEnterpriseId,@Param("storeIds") List<String> storeIds);
List<StaffClerkRelationDTO> listAllRelationDtosByEnterpriseId(@Param("enterpriseId") String enterpriseId); List<String> listAllClerkIdsByEnterpriseId(@Param("enterpriseId") String enterpriseId);
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ package com.gic.haoban.manage.service.dao.mapper.content; ...@@ -2,6 +2,7 @@ package com.gic.haoban.manage.service.dao.mapper.content;
import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord; import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord;
import com.gic.haoban.manage.service.entity.content.TabHaobanPotentialCustomer; import com.gic.haoban.manage.service.entity.content.TabHaobanPotentialCustomer;
import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerStaticsBO;
import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO; import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -97,5 +98,12 @@ public interface TabHaobanInteractRecordMapper { ...@@ -97,5 +98,12 @@ public interface TabHaobanInteractRecordMapper {
*/ */
List<TabHaobanInteractRecord> queryInteractRecordList(InteractRecordQO interactRecordQO); List<TabHaobanInteractRecord> queryInteractRecordList(InteractRecordQO interactRecordQO);
/**
* 统计互动记录总数
* @param interactRecordQO
* @return
*/
List<PotentialCustomerStaticsBO> staticsClerkInteractRecordNew(InteractRecordQO interactRecordQO);
} }
package com.gic.haoban.manage.service.pojo.bo.content;
import lombok.Data;
import java.io.Serializable;
/**
* @Author MUSI
* @Date 2023/3/30 11:12 AM
* @Description
* @Version
**/
@Data
public class PotentialCustomerStaticsBO implements Serializable {
/**
* 导购id
*/
private String clerkId;
/**
* 数量
*/
private Integer num;
}
package com.gic.haoban.manage.service.pojo.bo.content.context;
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;
import lombok.Builder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum.MATERIAL_WEEK_REPORT;
import static com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum.POTENTIAL_CUSTOMER_NOTIFY;
/**
* @Author MUSI
* @Date 2023/3/30 10:55 AM
* @Description
* @Version
**/
@Slf4j
@Data
@Builder
public class PotentialCustomerNotifyContext {
/**
* 开始时间
*/
private Date startTime;
/**
* 结束时间
*/
private Date endTime;
/**
* 企业id
*/
private String enterpriseId;
/**
* 企业下的导购id
*/
private List<String> clerkIds;
/**
* 导购关联关系
*/
private List<StaffClerkRelationDTO> staffClerkRelations;
List<PotentialCustomerStaticsBO> customerStaticsBos;
public static NoticeMessageBO buildMessage(String clerkId, int count) {
NoticeMessageBO noticeMessageBO = new NoticeMessageBO();
// noticeMessageBO.setCategoryType(POTENTIAL_CUSTOMER_NOTIFY.getCategory());
// noticeMessageBO.setMessageType(POTENTIAL_CUSTOMER_NOTIFY.getType());
// noticeMessageBO.setClerkId(clerkId);
// noticeMessageBO.setStoreId("");
// noticeMessageBO.setTitle("销售线索通知");
// noticeMessageBO.setTemplateCode(POTENTIAL_CUSTOMER_NOTIFY.getTemplateCode());
// noticeMessageBO.setDescription(String.format("新增%s个客户的销售线索,请及时跟进", count));
// noticeMessageBO.setEnterpriseId(this.enterpriseId);
// noticeMessageBO.setRelationId(this.clerkId);
// noticeMessageBO.setMessageContent();
return noticeMessageBO;
}
public List<NoticeMessageBO> buildNoticeMessage() {
if (CollectionUtils.isEmpty(this.customerStaticsBos)) {
return Collections.emptyList();
}
if (CollectionUtils.isEmpty(this.staffClerkRelations)) {
return Collections.emptyList();
}
Map<String, Integer> customerStaticsMap = this.customerStaticsBos.stream()
.collect(Collectors.toMap(PotentialCustomerStaticsBO::getClerkId,
item -> Optional.ofNullable(item.getNum()).orElse(0),
(v1, v2) -> v1));
return this.staffClerkRelations
.stream()
.filter(item -> customerStaticsMap.get(item.getClerkId()) > 0)
.map(item -> {
NoticeMessageBO noticeMessageBO = new NoticeMessageBO();
noticeMessageBO.setCategoryType(POTENTIAL_CUSTOMER_NOTIFY.getCategory());
noticeMessageBO.setMessageType(POTENTIAL_CUSTOMER_NOTIFY.getType());
noticeMessageBO.setClerkId(item.getClerkId());
noticeMessageBO.setStoreId(StringUtils.isNotBlank(item.getStoreId()) ? item.getStoreId() : "-1");
noticeMessageBO.setTitle("销售线索通知");
noticeMessageBO.setTemplateCode(POTENTIAL_CUSTOMER_NOTIFY.getTemplateCode());
noticeMessageBO.setDescription(String.format("新增%s个客户的销售线索,请及时跟进", customerStaticsMap.get(item.getClerkId())));
noticeMessageBO.setEnterpriseId(this.enterpriseId);
noticeMessageBO.setRelationId(item.getClerkId());
noticeMessageBO.setMessageContent("");
return noticeMessageBO;
})
.collect(Collectors.toList());
}
}
...@@ -14,6 +14,8 @@ import java.util.Date; ...@@ -14,6 +14,8 @@ import java.util.Date;
@Data @Data
public class InteractRecordQO extends BasePageInfo { public class InteractRecordQO extends BasePageInfo {
private String enterpriseId;
/** /**
* 导购id * 导购id
*/ */
...@@ -30,8 +32,13 @@ public class InteractRecordQO extends BasePageInfo { ...@@ -30,8 +32,13 @@ public class InteractRecordQO extends BasePageInfo {
private String unionId; private String unionId;
/** /**
* 开始时间 * 开始时间-创建时间
*/ */
private Date startTime; private Date startTime;
/**
* 结束时间-创建时间
*/
private Date endTime;
} }
...@@ -176,5 +176,5 @@ public interface StaffClerkRelationService { ...@@ -176,5 +176,5 @@ public interface StaffClerkRelationService {
* @param enterpriseId * @param enterpriseId
* @return * @return
*/ */
List<StaffClerkRelationDTO> listAllRelationDtosByEnterpriseId(String enterpriseId); List<String> listAllClerkIdsByEnterpriseId(String enterpriseId);
} }
...@@ -2,8 +2,11 @@ package com.gic.haoban.manage.service.service.content; ...@@ -2,8 +2,11 @@ package com.gic.haoban.manage.service.service.content;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.haoban.manage.service.pojo.bo.content.InteractRecordBO; import com.gic.haoban.manage.service.pojo.bo.content.InteractRecordBO;
import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerStaticsBO;
import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO; import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO;
import java.util.List;
/** /**
* 互动记录明细(TabHaobanInteractRecord)表服务接口 * 互动记录明细(TabHaobanInteractRecord)表服务接口
* *
...@@ -40,4 +43,12 @@ public interface InteractRecordService { ...@@ -40,4 +43,12 @@ public interface InteractRecordService {
* @return * @return
*/ */
Long saveOrUpdateInteractRecord(InteractRecordBO interactRecordBO); Long saveOrUpdateInteractRecord(InteractRecordBO interactRecordBO);
/**
* 统计导购的互动记录总数
* @param interactRecordQO
* @return
*/
List<PotentialCustomerStaticsBO> staticsClerkNewInteractRecord(InteractRecordQO interactRecordQO);
} }
...@@ -2,6 +2,7 @@ package com.gic.haoban.manage.service.service.content; ...@@ -2,6 +2,7 @@ package com.gic.haoban.manage.service.service.content;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerBO; import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerBO;
import com.gic.haoban.manage.service.pojo.bo.content.context.PotentialCustomerNotifyContext;
import com.gic.haoban.manage.service.pojo.qo.content.PotentialCustomerQO; import com.gic.haoban.manage.service.pojo.qo.content.PotentialCustomerQO;
/** /**
...@@ -48,4 +49,10 @@ public interface PotentialCustomerService { ...@@ -48,4 +49,10 @@ public interface PotentialCustomerService {
* @return * @return
*/ */
Long saveOrUpdatePotentialCustomer(PotentialCustomerBO potentialCustomerBO); Long saveOrUpdatePotentialCustomer(PotentialCustomerBO potentialCustomerBO);
/**
* 销售线索通知
* @param context
*/
void sendPotentialCustomerNotice(PotentialCustomerNotifyContext context);
} }
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;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.entity.TabHaobanClerkMainStoreRelated;
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.context.PotentialCustomerNotifyContext;
import com.gic.haoban.manage.service.service.ClerkMainStoreRelatedService;
import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.service.notify.NoticeMessageService;
import com.gic.wechat.api.dto.qywx.ItemDTO;
import com.gic.wechat.api.dto.qywx.QywxNewsArticleMessageDTO;
import com.gic.wechat.api.dto.qywx.QywxNewsSendMessageDTO;
import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author MUSI
* @Date 2023/3/30 10:58 AM
* @Description
* @Version
**/
@Slf4j
@Component
public class PotentialCustomerNotifyBuilder {
@Autowired
StaffClerkRelationService staffClerkRelationService;
@Autowired
private ClerkMainStoreRelatedService clerkMainStoreRelatedService;
@Autowired
private NoticeMessageService noticeMessageService;
@Autowired
private QywxSuiteApiService qywxSuiteApiService;
@Autowired
private WxEnterpriseService wxEnterpriseService;
@Autowired
private Config config;
@Autowired
private StaffApiService staffApiService;
/**
* 获取企业下所有导购id
*
* @param context
*/
public void buildEnterpriseClerkIds(PotentialCustomerNotifyContext context) {
if (StringUtils.isBlank(context.getEnterpriseId())) {
return;
}
List<String> clerkIds =
staffClerkRelationService.listAllClerkIdsByEnterpriseId(context.getEnterpriseId());
if (CollectionUtils.isEmpty(clerkIds)) {
return;
}
context.setClerkIds(clerkIds);
}
/**
* 获取导购的绑定关系
*
* @param context
*/
public void buildClerkRelations(PotentialCustomerNotifyContext context) {
List<String> clerkIds = context.getCustomerStaticsBos()
.stream()
.map(PotentialCustomerStaticsBO::getClerkId)
.collect(Collectors.toList());
context.setClerkIds(clerkIds);
List<StaffClerkRelationDTO> staffClerkRelations = staffClerkRelationService.listByClerkIds(context.getClerkIds());
context.setStaffClerkRelations(staffClerkRelations);
}
/**
* 过滤区经
*
* @param context
*/
public void filterAreaManage(PotentialCustomerNotifyContext context) {
List<StaffClerkRelationDTO> clerkRelations = context.getStaffClerkRelations()
.stream()
.filter(item -> !Objects.equals(2, item.getClerkType()))
.collect(Collectors.toList());
context.setStaffClerkRelations(clerkRelations);
}
/**
* 发送好办小程序消息
*
* @param context
*/
public void sendHaoBanNotifyMessage(PotentialCustomerNotifyContext context) {
List<NoticeMessageBO> noticeMessageBos = context.buildNoticeMessage();
if (CollectionUtils.isEmpty(noticeMessageBos)) {
return;
}
noticeMessageService.addNoticeMessageBatch(noticeMessageBos);
}
/**
* 发送应用消息
*
* @param context
*/
public void sendApplicationMessage(PotentialCustomerNotifyContext context) {
if (CollectionUtils.isEmpty(context.getCustomerStaticsBos()) || CollectionUtils.isEmpty(context.getStaffClerkRelations())) {
return;
}
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()) {
String staffId = staffClerkRelation.getStaffId();
TabHaobanClerkMainStoreRelated temp = clerkMainStoreMap.get(staffId);
if (temp != null) {
if (StringUtils.isBlank(temp.getStoreId())) {
// 该成员无主门店
continue;
}
if (StringUtils.isBlank(temp.getStoreId())) {
log.info("成员不存在主门店 {}", staffId);
continue;
}
PotentialCustomerStaticsBO customerStaticsBO = customerStaticsBOMap.get(staffClerkRelation.getClerkId());
if (customerStaticsBO == null || customerStaticsBO.getNum() == null || customerStaticsBO.getNum() == 0) {
return;
}
// 需要发送应用消息
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) {
return;
}
QywxXcxSendMessageDTO messageDTO = this.buildApplicationMessage(staffClerkRelation, wxEnterpriseQwDTO, customerStaticsBO.getNum());
qywxSuiteApiService.sendMessage(wxEnterpriseQwDTO.getThirdCorpid(), config.getWxSuiteid(), messageDTO);
continue;
}
TabHaobanClerkMainStoreRelated tabHaobanClerkMainStoreRelated = clerkMainStoreRelatedService.selectByWxEnterpriseIdAndStoreId(staffId, staffClerkRelation.getWxEnterpriseId());
if (tabHaobanClerkMainStoreRelated == null) {
tabHaobanClerkMainStoreRelated = new TabHaobanClerkMainStoreRelated();
}
clerkMainStoreMap.put(staffId, tabHaobanClerkMainStoreRelated);
}
}
public QywxXcxSendMessageDTO buildApplicationMessage(StaffClerkRelationDTO staffClerkRelation, WxEnterpriseQwDTO wxEnterpriseQwDTO, int count) {
StaffDTO staffDTO = staffApiService.selectById(staffClerkRelation.getStaffId());
String wxUserId = staffDTO.getWxUserId();
if (wxEnterpriseQwDTO.needOpenUserId3th()) {
wxUserId = staffDTO.getWxOpenUseId();
}
QywxXcxSendMessageDTO messageDTO = new QywxXcxSendMessageDTO();
ItemDTO itemDTO = new ItemDTO();
itemDTO.setKey("事件");
itemDTO.setValue(String.format("新增%s个客户的销售线索,请及时跟进", count));
ArrayList<String> list = new ArrayList<>();
list.add(wxUserId);
messageDTO.setAppid(config.getAppid());
messageDTO.setUserIds(list);
messageDTO.setPage("/pageurl?");
messageDTO.setTitle("销售线索通知");
messageDTO.setItems(Collections.singletonList(itemDTO));
return messageDTO;
}
}
...@@ -7,6 +7,7 @@ import com.gic.commons.util.UniqueIdUtils; ...@@ -7,6 +7,7 @@ import com.gic.commons.util.UniqueIdUtils;
import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanInteractRecordMapper; import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanInteractRecordMapper;
import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord; import com.gic.haoban.manage.service.entity.content.TabHaobanInteractRecord;
import com.gic.haoban.manage.service.pojo.bo.content.InteractRecordBO; import com.gic.haoban.manage.service.pojo.bo.content.InteractRecordBO;
import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerStaticsBO;
import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO; import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO;
import com.gic.haoban.manage.service.service.content.InteractRecordService; import com.gic.haoban.manage.service.service.content.InteractRecordService;
import com.gic.haoban.manage.service.service.content.adaptor.InteractRecordBuilder; import com.gic.haoban.manage.service.service.content.adaptor.InteractRecordBuilder;
...@@ -140,4 +141,15 @@ public class InteractRecordServiceImpl implements InteractRecordService { ...@@ -140,4 +141,15 @@ public class InteractRecordServiceImpl implements InteractRecordService {
} }
return temp.getId(); return temp.getId();
} }
/**
* 统计导购的互动记录总数
*
* @param interactRecordQO
* @return
*/
@Override
public List<PotentialCustomerStaticsBO> staticsClerkNewInteractRecord(InteractRecordQO interactRecordQO) {
return this.tabHaobanInteractRecordMapper.staticsClerkInteractRecordNew(interactRecordQO);
}
} }
...@@ -5,18 +5,30 @@ import com.gic.commons.util.UniqueIdUtils; ...@@ -5,18 +5,30 @@ import com.gic.commons.util.UniqueIdUtils;
import com.gic.haoban.common.utils.PageUtil; import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanPotentialCustomerMapper; import com.gic.haoban.manage.service.dao.mapper.content.TabHaobanPotentialCustomerMapper;
import com.gic.haoban.manage.service.entity.content.TabHaobanPotentialCustomer; import com.gic.haoban.manage.service.entity.content.TabHaobanPotentialCustomer;
import com.gic.haoban.manage.service.pojo.bo.NoticeMessageBO;
import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerBO; import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerBO;
import com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerStaticsBO;
import com.gic.haoban.manage.service.pojo.bo.content.context.PotentialCustomerNotifyContext;
import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO;
import com.gic.haoban.manage.service.pojo.qo.content.PotentialCustomerQO; import com.gic.haoban.manage.service.pojo.qo.content.PotentialCustomerQO;
import com.gic.haoban.manage.service.service.content.InteractRecordService;
import com.gic.haoban.manage.service.service.content.PotentialCustomerService; import com.gic.haoban.manage.service.service.content.PotentialCustomerService;
import com.gic.haoban.manage.service.service.content.adaptor.PotentialCustomerNotifyBuilder;
import com.gic.haoban.manage.service.service.notify.NoticeMessageService;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* 销售线索(TabHaobanPotentialCustomer)表服务实现类 * 销售线索(TabHaobanPotentialCustomer)表服务实现类
...@@ -30,6 +42,12 @@ public class PotentialCustomerServiceImpl implements PotentialCustomerService { ...@@ -30,6 +42,12 @@ public class PotentialCustomerServiceImpl implements PotentialCustomerService {
@Resource @Resource
private TabHaobanPotentialCustomerMapper potentialCustomerMapper; private TabHaobanPotentialCustomerMapper potentialCustomerMapper;
@Autowired
private PotentialCustomerNotifyBuilder potentialCustomerNotifyBuilder;
@Autowired
private InteractRecordService interactRecordService;
@Autowired
private NoticeMessageService noticeMessageService;
/** /**
...@@ -123,9 +141,38 @@ public class PotentialCustomerServiceImpl implements PotentialCustomerService { ...@@ -123,9 +141,38 @@ public class PotentialCustomerServiceImpl implements PotentialCustomerService {
if (temp.getId() == null) { if (temp.getId() == null) {
temp.setId(UniqueIdUtils.uniqueLong()); temp.setId(UniqueIdUtils.uniqueLong());
potentialCustomerMapper.insert(temp); potentialCustomerMapper.insert(temp);
}else { } else {
potentialCustomerMapper.update(temp); potentialCustomerMapper.update(temp);
} }
return temp.getId(); return temp.getId();
} }
/**
* 销售线索通知
*
* @param context
*/
@Override
public void sendPotentialCustomerNotice(PotentialCustomerNotifyContext context) {
// 根据企业id + 时间 循环查询时间段内的有新互动记录的导购id 去重
InteractRecordQO searchQo = new InteractRecordQO();
searchQo.setEnterpriseId(context.getEnterpriseId());
searchQo.setStartTime(context.getStartTime());
searchQo.setEndTime(context.getEndTime());
List<PotentialCustomerStaticsBO> customerStaticsBos = interactRecordService.staticsClerkNewInteractRecord(searchQo);
if (CollectionUtils.isEmpty(customerStaticsBos)) {
return;
}
context.setCustomerStaticsBos(customerStaticsBos);
// 获取导购与成员关联关联关系
potentialCustomerNotifyBuilder.buildClerkRelations(context);
// 获取成员的主门店
// 区经 忽略
potentialCustomerNotifyBuilder.filterAreaManage(context);
// 构建应用内消息
potentialCustomerNotifyBuilder.sendHaoBanNotifyMessage(context);
// 如果该导购id是成员在主门店时的导购id 发送应用消息
potentialCustomerNotifyBuilder.sendApplicationMessage(context);
}
} }
...@@ -112,7 +112,6 @@ public class InteractRecordMessageService { ...@@ -112,7 +112,6 @@ public class InteractRecordMessageService {
potentialCustomerBO.setDurationTime(interactRecordBO.getDurationTime()); potentialCustomerBO.setDurationTime(interactRecordBO.getDurationTime());
potentialCustomerBO.setTimes(interactRecordBO.getTimes()); potentialCustomerBO.setTimes(interactRecordBO.getTimes());
potentialCustomerService.saveOrUpdatePotentialCustomer(potentialCustomerBO); potentialCustomerService.saveOrUpdatePotentialCustomer(potentialCustomerBO);
// 累计 该导购 + 时间段内 未读数量
} }
} }
......
package com.gic.haoban.manage.service.service.impl; package com.gic.haoban.manage.service.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.clerk.api.dto.ClerkDTO; import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.clerk.api.service.ClerkService; import com.gic.clerk.api.service.ClerkService;
...@@ -421,7 +420,7 @@ public class StaffClerkRelationServiceImpl implements StaffClerkRelationService ...@@ -421,7 +420,7 @@ public class StaffClerkRelationServiceImpl implements StaffClerkRelationService
* @return * @return
*/ */
@Override @Override
public List<StaffClerkRelationDTO> listAllRelationDtosByEnterpriseId(String enterpriseId) { public List<String> listAllClerkIdsByEnterpriseId(String enterpriseId) {
return this.mapper.listAllRelationDtosByEnterpriseId(enterpriseId); return this.mapper.listAllClerkIdsByEnterpriseId(enterpriseId);
} }
} }
package com.gic.haoban.manage.service.service.out.impl.content.task; package com.gic.haoban.manage.service.service.out.impl.content.task;
import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.DateUtil; import com.gic.commons.util.DateUtil;
...@@ -10,18 +11,22 @@ import com.gic.haoban.manage.api.enums.content.MaterialReportType; ...@@ -10,18 +11,22 @@ import com.gic.haoban.manage.api.enums.content.MaterialReportType;
import com.gic.haoban.manage.api.enums.content.TriggerCustomerChannelType; import com.gic.haoban.manage.api.enums.content.TriggerCustomerChannelType;
import com.gic.haoban.manage.api.service.content.task.QywxGroupMsgTaskApiService; import com.gic.haoban.manage.api.service.content.task.QywxGroupMsgTaskApiService;
import com.gic.haoban.manage.service.pojo.bo.content.GroupMessageInfoBo; import com.gic.haoban.manage.service.pojo.bo.content.GroupMessageInfoBo;
import com.gic.haoban.manage.service.pojo.bo.content.context.PotentialCustomerNotifyContext;
import com.gic.haoban.manage.service.service.StaffService; import com.gic.haoban.manage.service.service.StaffService;
import com.gic.haoban.manage.service.service.WxEnterpriseService; import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.service.content.GroupMessageService; import com.gic.haoban.manage.service.service.content.GroupMessageService;
import com.gic.haoban.manage.service.service.content.MaterialReportService; import com.gic.haoban.manage.service.service.content.MaterialReportService;
import com.gic.haoban.manage.service.service.content.PotentialCustomerService;
import com.gic.haoban.manage.service.task.RouterConstant; import com.gic.haoban.manage.service.task.RouterConstant;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.Now;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -43,6 +48,8 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic ...@@ -43,6 +48,8 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic
private StaffService staffService; private StaffService staffService;
@Autowired @Autowired
private WxEnterpriseService wxEnterpriseService; private WxEnterpriseService wxEnterpriseService;
@Autowired
private PotentialCustomerService potentialCustomerService;
@Override @Override
public ServiceResponse<Void> groupMsgTaskJob(String params) { public ServiceResponse<Void> groupMsgTaskJob(String params) {
...@@ -115,6 +122,7 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic ...@@ -115,6 +122,7 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic
/** /**
* 发送企业周报/月报素材 * 发送企业周报/月报素材
*
* @param reportType * @param reportType
* @return * @return
*/ */
...@@ -153,9 +161,9 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic ...@@ -153,9 +161,9 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic
/** /**
* 处理单成员素材使用周报/月报 * 处理单成员素材使用周报/月报
* *
* @see RouterConstant#DEAL_ONE_STAFF_MATERIAL_REPORT
* @param params * @param params
* @return * @return
* @see RouterConstant#DEAL_ONE_STAFF_MATERIAL_REPORT
*/ */
@Override @Override
public ServiceResponse<Void> doHandlerMaterialOneStaffReportMQ(String params) { public ServiceResponse<Void> doHandlerMaterialOneStaffReportMQ(String params) {
...@@ -171,6 +179,7 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic ...@@ -171,6 +179,7 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic
/** /**
* 发送成员使用素材消息MQ * 发送成员使用素材消息MQ
*
* @param materialReportDTO * @param materialReportDTO
* @return * @return
*/ */
...@@ -179,9 +188,70 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic ...@@ -179,9 +188,70 @@ public class QywxGroupMsgTaskApiServiceImpl implements QywxGroupMsgTaskApiServic
GICMQClientUtil.getClientInstance() GICMQClientUtil.getClientInstance()
.sendMessage(RouterConstant.DEAL_ONE_STAFF_MATERIAL_REPORT, JSON.toJSONString(materialReportDTO)); .sendMessage(RouterConstant.DEAL_ONE_STAFF_MATERIAL_REPORT, JSON.toJSONString(materialReportDTO));
return true; return true;
}catch (Exception ex){ } catch (Exception ex) {
log.warn("发送成员使用素材周报/月报MQ异常, 参数: {}", JSON.toJSONString(materialReportDTO), ex); log.warn("发送成员使用素材周报/月报MQ异常, 参数: {}", JSON.toJSONString(materialReportDTO), ex);
} }
return false; return false;
} }
/**
* 销售线索 通知job
*
* @param params
* @return 每半小时通知一次,提醒时间段:当天 8:00~23:00
* 当天23:00~第二天8:00产生的线索动态,第二天 8:00 提醒
* 区经不发应用、小程序消息
* 导购、店长 应用只发主门店数据的应用消息
*/
@Override
public ServiceResponse<Void> potentialCustomerJob(String params) {
Date now = new Date();
int currentHour = cn.hutool.core.date.DateUtil.hour(now, true);
if (currentHour >= 23 || currentHour < 8) {
log.info("当前时间处于消息禁发时间, 忽略{}", cn.hutool.core.date.DateUtil.format(now, "yyyy-MM-dd HH:mm:ss"));
return ServiceResponse.success();
}
List<String> enterpriseIds = groupMessageService.hasMaterialRightEnterprise();
if (CollectionUtils.isEmpty(enterpriseIds)) {
return ServiceResponse.success();
}
Date startTime = cn.hutool.core.date.DateUtil.offsetMinute(now, -30).toJdkDate();
// 如果是8点那次的执行 需要获取 23 ~ 8点的数据
if (checkIsTodayFirst(now)) {
log.info("本次执行为当天第一次执行 {}", cn.hutool.core.date.DateUtil.format(now, "yyyy-MM-dd HH:mm:ss"));
Date yesterday = cn.hutool.core.date.DateUtil.yesterday().toJdkDate();
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setTime(yesterday);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
startTime = calendar.getTime();
}
for (String enterpriseId : enterpriseIds) {
PotentialCustomerNotifyContext context = PotentialCustomerNotifyContext.builder()
.enterpriseId(enterpriseId)
.startTime(startTime)
.endTime(now)
.build();
potentialCustomerService.sendPotentialCustomerNotice(context);
}
return ServiceResponse.success();
}
/**
* 判断是否是当天第一次
* 执行时间处于 8:00 ~ 8:30
*
* @param now
* @return
*/
int hour_sec = 30 * 60 + 1;
private boolean checkIsTodayFirst(Date now) {
DateTime temp = cn.hutool.core.date.DateUtil.offsetSecond(now, -(hour_sec + 1));
return cn.hutool.core.date.DateUtil.hour(temp, true) < 8;
}
} }
...@@ -447,9 +447,10 @@ ...@@ -447,9 +447,10 @@
</if> </if>
</select> </select>
<select id="listAllRelationDtosByEnterpriseId" resultType="com.gic.haoban.manage.api.dto.StaffClerkRelationDTO"> <select id="listAllClerkIdsByEnterpriseId" resultType="java.lang.String">
<include refid="leftJoinStaffSQL"/> select a.clerk_id clerkId
where a.enterprise_id = #{wxEnterpriseId} and a.status_flag=1 and b.status_flag = 1 from tab_haoban_staff_clerk_relation a inner join tab_haoban_staff b on b.staff_id = a.staff_id
where a.enterprise_id = #{enterpriseId} and a.status_flag=1 and b.status_flag = 1
</select> </select>
</mapper> </mapper>
\ No newline at end of file
...@@ -268,9 +268,32 @@ ...@@ -268,9 +268,32 @@
<if test="startTime != null"> <if test="startTime != null">
and create_time >= #{startTime} and create_time >= #{startTime}
</if> </if>
<if test="endTime != null">
and create_time <![CDATA[ <= ]]> #{endTime}
</if>
</where> </where>
order by id desc order by id desc
</select> </select>
<select id="staticsClerkInteractRecordNew" resultType="com.gic.haoban.manage.service.pojo.bo.content.PotentialCustomerStaticsBO">
select clerk_id clerkId, count(1) num
from tab_haoban_interact_record
where delete_flag = 0
<if test="clerkId != null and clerkId != ''">
and clerk_id = #{clerkId}
</if>
<if test="enterpriseId != null and enterpriseId != ''">
and enterprise_id = #{enterpriseId}
</if>
<if test="startTime != null">
and create_time >= #{startTime}
</if>
<if test="endTime != null">
and create_time <![CDATA[ <= ]]> #{endTime}
</if>
group by clerk_id
order by null
</select>
</mapper> </mapper>
import cn.hutool.crypto.digest.MD5; import cn.hutool.crypto.digest.MD5;
import com.gic.haoban.manage.api.dto.chat.ChatOwnerTotalDTO;
import com.gic.haoban.manage.api.dto.qdto.chat.GroupChatPlanSearchQDTO;
import com.gic.haoban.manage.api.enums.content.MaterialInteractRecordEventType; import com.gic.haoban.manage.api.enums.content.MaterialInteractRecordEventType;
import com.gic.haoban.manage.api.enums.content.TriggerCustomerChannelType; import com.gic.haoban.manage.api.enums.content.TriggerCustomerChannelType;
import com.gic.haoban.manage.service.dao.mapper.chat.GroupChatPlanOwnerLogMapper;
import com.gic.haoban.manage.service.pojo.bo.content.message.InteractRecordMessageBO; import com.gic.haoban.manage.service.pojo.bo.content.message.InteractRecordMessageBO;
import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO; import com.gic.haoban.manage.service.pojo.qo.content.InteractRecordQO;
import com.gic.haoban.manage.service.service.content.InteractRecordService; import com.gic.haoban.manage.service.service.content.InteractRecordService;
...@@ -13,6 +16,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -13,6 +16,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.UUID; import java.util.UUID;
/** /**
...@@ -69,4 +73,14 @@ public class InteractRecordTest { ...@@ -69,4 +73,14 @@ public class InteractRecordTest {
System.out.println(MD5.create().digestHex("song")); System.out.println(MD5.create().digestHex("song"));
} }
} }
@Autowired
GroupChatPlanOwnerLogMapper groupChatPlanOwnerLogMapper;
@Test
public void caseWhenTest(){
GroupChatPlanSearchQDTO search = new GroupChatPlanSearchQDTO();
search.setWxEnterpriseId("f5f8c78e395e4ca1a493707316096097");
List<ChatOwnerTotalDTO> chatOwnerTotalDTOS = groupChatPlanOwnerLogMapper.listOwnerLogPageForWxaTotal(search);
}
} }
...@@ -25,11 +25,16 @@ public class PotentialCustomerVO implements Serializable { ...@@ -25,11 +25,16 @@ public class PotentialCustomerVO implements Serializable {
private Long potentialCustomerId; private Long potentialCustomerId;
/** /**
* 会员 * 会员
*/ */
private String memberName; private String memberName;
/** /**
* 会员昵称
*/
private String memberNickName;
/**
* 会员头像 * 会员头像
*/ */
private String memberImageUrl; private String memberImageUrl;
......
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