Commit a5f55127 by 王祖波

群发结果刷新

parent 965ae5a9
package com.gic.haoban.manage.api.dto.send;
import java.io.Serializable;
import java.util.Date;
/**
* Created by wangzubo on 2025/3/25.
*/
public class DealQwSendDTO implements Serializable {
/**
* 处理类型 1 获取msgId 2 刷新发送结果
*/
private Integer refreshType;
/**
* 获取msgId数据
*/
private FinishQwSendBO finishQwSend;
/**
* 刷新发送结果数据
*/
private QwSendMsgBO qwSendMsg;
public static class FinishQwSendBO implements Serializable{
/**
* 导购id
*/
private String clerkId;
/**
* 成员id
*/
private String staffId;
/**
* 发送时间
*/
private Date sendTime;
/**
* 业务类型 1素材分享 2商品推荐
*/
private Integer bizType;
/**
* 好办企业id
*/
private String wxEnterpriseId;
/**
* 企业id
*/
private String enterpriseId;
public FinishQwSendBO() {
}
public FinishQwSendBO(String clerkId, String staffId, Date sendTime, Integer bizType, String wxEnterpriseId, String enterpriseId) {
this.clerkId = clerkId;
this.staffId = staffId;
this.sendTime = sendTime;
this.bizType = bizType;
this.wxEnterpriseId = wxEnterpriseId;
this.enterpriseId = enterpriseId;
}
public String getClerkId() {
return clerkId;
}
public void setClerkId(String clerkId) {
this.clerkId = clerkId;
}
public String getStaffId() {
return staffId;
}
public void setStaffId(String staffId) {
this.staffId = staffId;
}
public Date getSendTime() {
return sendTime;
}
public void setSendTime(Date sendTime) {
this.sendTime = sendTime;
}
public Integer getBizType() {
return bizType;
}
public void setBizType(Integer bizType) {
this.bizType = bizType;
}
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
}
public static class QwSendMsgBO implements Serializable {
/**
* 主键id
*/
private Long id;
/**
* 导购id
*/
private String clerkId;
/**
* 成员id
*/
private String staffId;
/**
* msgId
*/
private String msgId;
/**
* 发送时间
*/
private Date sendTime;
/**
* 业务类型 1素材分享 2商品推荐
*/
private Integer bizType;
/**
* 好办企业id
*/
private String wxEnterpriseId;
/**
* 企业id
*/
private String enterpriseId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getClerkId() {
return clerkId;
}
public void setClerkId(String clerkId) {
this.clerkId = clerkId;
}
public String getStaffId() {
return staffId;
}
public void setStaffId(String staffId) {
this.staffId = staffId;
}
public String getMsgId() {
return msgId;
}
public void setMsgId(String msgId) {
this.msgId = msgId;
}
public Date getSendTime() {
return sendTime;
}
public void setSendTime(Date sendTime) {
this.sendTime = sendTime;
}
public Integer getBizType() {
return bizType;
}
public void setBizType(Integer bizType) {
this.bizType = bizType;
}
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
}
public Integer getRefreshType() {
return refreshType;
}
public void setRefreshType(Integer refreshType) {
this.refreshType = refreshType;
}
public FinishQwSendBO getFinishQwSend() {
return finishQwSend;
}
public void setFinishQwSend(FinishQwSendBO finishQwSend) {
this.finishQwSend = finishQwSend;
}
public QwSendMsgBO getQwSendMsg() {
return qwSendMsg;
}
public void setQwSendMsg(QwSendMsgBO qwSendMsg) {
this.qwSendMsg = qwSendMsg;
}
}
package com.gic.haoban.manage.api.service.send;
import com.gic.api.base.commons.ServiceResponse;
public interface QwSendApiService {
/**
* 刷新企微发送记录
* @param message
* @return
*/
ServiceResponse<Void> qwSendRefreshByMQ(String message);
}
package com.gic.haoban.manage.service.dao.mapper.send;
import com.gic.haoban.manage.service.entity.send.TabQwSendLog;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* 企微群发明细表(TabQwSendLog)表数据库访问层
*
* @author makejava
* @since 2025-03-25 13:48:01
*/
public interface QwSendLogMapper {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
TabQwSendLog queryById(Long id);
/**
* 查询指定行数据
*
* @param tabQwSendLog 查询条件
* @param pageable 分页对象
* @return 对象列表
*/
List<TabQwSendLog> queryAllByLimit(TabQwSendLog tabQwSendLog, @Param("pageable") Pageable pageable);
/**
* 统计总行数
*
* @param tabQwSendLog 查询条件
* @return 总行数
*/
long count(TabQwSendLog tabQwSendLog);
/**
* 新增数据
*
* @param tabQwSendLog 实例对象
* @return 影响行数
*/
int insert(TabQwSendLog tabQwSendLog);
/**
* 批量新增数据(MyBatis原生foreach方法)
*
* @param entities List<TabQwSendLog> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<TabQwSendLog> entities);
/**
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
*
* @param entities List<TabQwSendLog> 实例对象列表
* @return 影响行数
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
*/
int insertOrUpdateBatch(@Param("entities") List<TabQwSendLog> entities);
/**
* 修改数据
*
* @param tabQwSendLog 实例对象
* @return 影响行数
*/
int update(TabQwSendLog tabQwSendLog);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Long id);
}
package com.gic.haoban.manage.service.dao.mapper.send;
import com.gic.haoban.manage.service.entity.send.TabQwSendMsg;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* 企微群发msgid表(TabQwSendMsg)表数据库访问层
*
* @author makejava
* @since 2025-03-25 13:48:05
*/
public interface QwSendMsgMapper {
/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
TabQwSendMsg queryById(Long id);
TabQwSendMsg queryByMsgId(String msgId);
/**
* 查询指定行数据
*
* @param tabQwSendMsg 查询条件
* @param pageable 分页对象
* @return 对象列表
*/
List<TabQwSendMsg> queryAllByLimit(TabQwSendMsg tabQwSendMsg, @Param("pageable") Pageable pageable);
/**
* 统计总行数
*
* @param tabQwSendMsg 查询条件
* @return 总行数
*/
long count(TabQwSendMsg tabQwSendMsg);
/**
* 新增数据
*
* @param tabQwSendMsg 实例对象
* @return 影响行数
*/
int insert(TabQwSendMsg tabQwSendMsg);
/**
* 批量新增数据(MyBatis原生foreach方法)
*
* @param entities List<TabQwSendMsg> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<TabQwSendMsg> entities);
/**
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
*
* @param entities List<TabQwSendMsg> 实例对象列表
* @return 影响行数
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
*/
int insertOrUpdateBatch(@Param("entities") List<TabQwSendMsg> entities);
/**
* 修改数据
*
* @param tabQwSendMsg 实例对象
* @return 影响行数
*/
int update(TabQwSendMsg tabQwSendMsg);
/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Long id);
}
package com.gic.haoban.manage.service.entity.send;
import java.util.Date;
import java.io.Serializable;
/**
* 企微群发明细表(TabQwSendLog)实体类
*
* @author makejava
* @since 2025-03-25 13:48:03
*/
public class TabQwSendLog implements Serializable {
private static final long serialVersionUID = -43606899312408812L;
/**
* 主键id
*/
private Long id;
/**
* 会员id
*/
private String memberId;
/**
* 会员外部联系人id
*/
private String externalUserId;
/**
* 导购id
*/
private String clerkId;
/**
* 成员id
*/
private String staffId;
/**
* msgId
*/
private String msgId;
/**
* 发送状态, 0 : 待发送, 1 : 发送成功, 2 : 发送失败
*/
private Integer sendStatus;
/**
* 发送时间
*/
private Date sendTime;
/**
* 2 : 因客户不是好友导致发送失败 3 : 因客户已经收到其他群发消息导致发送失败
*/
private Integer failReasonType;
/**
* 好办企业id
*/
private String wxEnterpriseId;
/**
* 企业id
*/
private String enterpriseId;
/**
* 是否删除
*/
private Integer deleteFlag;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改时间
*/
private Date updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMemberId() {
return memberId;
}
public void setMemberId(String memberId) {
this.memberId = memberId;
}
public String getExternalUserId() {
return externalUserId;
}
public void setExternalUserId(String externalUserId) {
this.externalUserId = externalUserId;
}
public String getClerkId() {
return clerkId;
}
public void setClerkId(String clerkId) {
this.clerkId = clerkId;
}
public String getStaffId() {
return staffId;
}
public void setStaffId(String staffId) {
this.staffId = staffId;
}
public String getMsgId() {
return msgId;
}
public void setMsgId(String msgId) {
this.msgId = msgId;
}
public Integer getSendStatus() {
return sendStatus;
}
public void setSendStatus(Integer sendStatus) {
this.sendStatus = sendStatus;
}
public Date getSendTime() {
return sendTime;
}
public void setSendTime(Date sendTime) {
this.sendTime = sendTime;
}
public Integer getFailReasonType() {
return failReasonType;
}
public void setFailReasonType(Integer failReasonType) {
this.failReasonType = failReasonType;
}
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
package com.gic.haoban.manage.service.entity.send;
import java.util.Date;
import java.io.Serializable;
/**
* 企微群发msgid表(TabQwSendMsg)实体类
*
* @author makejava
* @since 2025-03-25 13:48:06
*/
public class TabQwSendMsg implements Serializable {
private static final long serialVersionUID = -62451866180002438L;
/**
* 主键id
*/
private Long id;
/**
* 导购id
*/
private String clerkId;
/**
* 成员id
*/
private String staffId;
/**
* msgId
*/
private String msgId;
/**
* 发送时间
*/
private Date sendTime;
/**
* 业务类型 1素材分享 2商品推荐
*/
private Integer bizType;
/**
* 好办企业id
*/
private String wxEnterpriseId;
/**
* 企业id
*/
private String enterpriseId;
/**
* 是否删除
*/
private Integer deleteFlag;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改时间
*/
private Date updateTime;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getClerkId() {
return clerkId;
}
public void setClerkId(String clerkId) {
this.clerkId = clerkId;
}
public String getStaffId() {
return staffId;
}
public void setStaffId(String staffId) {
this.staffId = staffId;
}
public String getMsgId() {
return msgId;
}
public void setMsgId(String msgId) {
this.msgId = msgId;
}
public Date getSendTime() {
return sendTime;
}
public void setSendTime(Date sendTime) {
this.sendTime = sendTime;
}
public Integer getBizType() {
return bizType;
}
public void setBizType(Integer bizType) {
this.bizType = bizType;
}
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
}
package com.gic.haoban.manage.service.pojo.bo.send;
import lombok.Data;
import java.util.Date;
/**
* Created by wangzubo on 2025/3/25.
*/
@Data
public class FinishQwSendBO {
/**
* 导购id
*/
private String clerkId;
/**
* 成员id
*/
private String staffId;
/**
* 发送时间
*/
private Date sendTime;
/**
* 业务类型 1素材分享 2商品推荐
*/
private Integer bizType;
/**
* 好办企业id
*/
private String wxEnterpriseId;
/**
* 企业id
*/
private String enterpriseId;
}
package com.gic.haoban.manage.service.pojo.bo.send;
import java.io.Serializable;
import java.util.Date;
/**
* @author : lingfeng
* @time : 2021-05-18
* @description : 群发发送结果
*/
public class GroupSendResultBO implements Serializable {
private static final long serialVersionUID = 1953943358823216399L;
/**
* 外部联系人id
*/
private String externalUserid;
/**
* 企业服务人员的userid
*/
private String userId;
/**
* 发送状态:0-未发送 1-已发送 2-因客户不是好友导致发送失败 3-因客户已经收到其他群发消息导致发送失败
*/
private Integer status;
/**
* 发送时间,未发送时不返回
*/
private Date sendTime;
public String getExternalUserid() {
return externalUserid;
}
public void setExternalUserid(String externalUserid) {
this.externalUserid = externalUserid;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Date getSendTime() {
return sendTime;
}
public void setSendTime(Date sendTime) {
this.sendTime = sendTime;
}
@Override
public String toString() {
return "GroupSendResultDTO{" +
"externalUserid='" + externalUserid + '\'' +
", userId='" + userId + '\'' +
", status=" + status +
", sendTime=" + sendTime +
'}';
}
}
package com.gic.haoban.manage.service.service.out.impl.send;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.send.DealQwSendDTO;
import com.gic.haoban.manage.api.service.send.QwSendApiService;
import com.gic.haoban.manage.service.service.send.QwSendMsgService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
/**
* Created by wangzubo on 2022/11/1.
*/
@Service("qwSendApiService")
@Slf4j
public class QwSendApiServiceImpl implements QwSendApiService {
@Autowired
private QwSendMsgService qwSendMsgService;
@Override
public ServiceResponse<Void> qwSendRefreshByMQ(String message) {
if (StringUtils.isBlank(message)) {
return ServiceResponse.success();
}
log.info("刷新企微发送记录:{}", message);
DealQwSendDTO dealQwSendDTO = JSONObject.parseObject(message, DealQwSendDTO.class);
Integer refreshType = dealQwSendDTO.getRefreshType();
if (Objects.equals(refreshType,1)) {
qwSendMsgService.finishQwSend(dealQwSendDTO.getFinishQwSend());
} else if (Objects.equals(refreshType, 2)) {
qwSendMsgService.refreshQwSendLog(dealQwSendDTO.getQwSendMsg());
}
return ServiceResponse.success();
}
}
package com.gic.haoban.manage.service.service.send;
import com.gic.haoban.manage.api.dto.send.DealQwSendDTO;
import com.gic.haoban.manage.service.entity.send.TabQwSendMsg;
import com.gic.haoban.manage.service.pojo.bo.send.FinishQwSendBO;
/**
* 企微群发msgid表(TabQwSendMsg)表服务接口
*
* @author makejava
* @since 2025-03-25 13:48:06
*/
public interface QwSendMsgService {
/**
* 完成企微群发获取msgId
* @param finishQwSendBO
*/
void finishQwSend(DealQwSendDTO.FinishQwSendBO finishQwSendBO);
/**
* 刷新企微群结果
* @param qwSendMsg
*/
void refreshQwSendLog(DealQwSendDTO.QwSendMsgBO qwSendMsg);
}
package com.gic.haoban.manage.service.service.send.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.BusinessException;
import com.gic.api.base.commons.JSONResponse;
import com.gic.commons.util.UniqueIdUtils;
import com.gic.content.api.utils.MqUtils;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.manage.api.dto.send.DealQwSendDTO;
import com.gic.haoban.manage.api.qdto.contact.ContactFollowBatchQDTO;
import com.gic.haoban.manage.api.service.MemberUnionidRelatedApiService;
import com.gic.haoban.manage.api.service.MessageApiService;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanExternalClerkRelatedMapper;
import com.gic.haoban.manage.service.dao.mapper.send.QwSendLogMapper;
import com.gic.haoban.manage.service.dao.mapper.send.QwSendMsgMapper;
import com.gic.haoban.manage.service.entity.TabHaobanExternalClerkRelated;
import com.gic.haoban.manage.service.entity.send.TabQwSendLog;
import com.gic.haoban.manage.service.entity.send.TabQwSendMsg;
import com.gic.haoban.manage.service.pojo.bo.send.FinishQwSendBO;
import com.gic.haoban.manage.service.pojo.bo.send.GroupSendResultBO;
import com.gic.haoban.manage.service.service.chat.GroupChatPlanService;
import com.gic.haoban.manage.service.service.content.impl.GroupMessageServiceImpl;
import com.gic.haoban.manage.service.service.send.QwSendMsgService;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
/**
* 企微群发msgid表(TabQwSendMsg)表服务实现类
*
* @author makejava
* @since 2025-03-25 13:48:06
*/
@Service
@Slf4j
public class QwSendMsgServiceImpl implements QwSendMsgService {
@Autowired
private QwSendMsgMapper qwSendMsgMapper;
@Autowired
private QwSendLogMapper qwSendLogMapper;
@Autowired
private TabHaobanExternalClerkRelatedMapper externalClerkRelatedMapper;
@Autowired
private GroupChatPlanService groupChatPlanService;
@Autowired
private MemberUnionidRelatedApiService memberUnionidRelatedApiService;
@Autowired
private MessageApiService messageApiService;
@Override
public void finishQwSend(DealQwSendDTO.FinishQwSendBO finishQwSendBO) {
String clerkId = finishQwSendBO.getClerkId();
String staffId = finishQwSendBO.getStaffId();
Date sendTime = finishQwSendBO.getSendTime();
String qwMsgId = groupChatPlanService.getQwMsgId(staffId, sendTime, GroupMessageServiceImpl.GroupMsgChatType.single);
if (StringUtils.isNotBlank(qwMsgId)) {
TabQwSendMsg qwSendMsg = qwSendMsgMapper.queryByMsgId(qwMsgId);
if (qwSendMsg != null) {
log.error("数据已处理过qwMsgId:{}", qwMsgId);
return;
}
qwSendMsg = new TabQwSendMsg();
qwSendMsg.setId(UniqueIdUtils.uniqueLong());
qwSendMsg.setClerkId(clerkId);
qwSendMsg.setStaffId(staffId);
qwSendMsg.setMsgId(qwMsgId);
qwSendMsg.setSendTime(sendTime);
qwSendMsg.setBizType(finishQwSendBO.getBizType());
qwSendMsg.setWxEnterpriseId(finishQwSendBO.getWxEnterpriseId());
qwSendMsg.setEnterpriseId(finishQwSendBO.getEnterpriseId());
qwSendMsgMapper.insert(qwSendMsg);
DealQwSendDTO dealQwSendDTO = new DealQwSendDTO();
dealQwSendDTO.setRefreshType(2);
DealQwSendDTO.QwSendMsgBO qwSendMsgBO = EntityUtil.changeEntityByJSON(DealQwSendDTO.QwSendMsgBO.class, qwSendMsg);
dealQwSendDTO.setQwSendMsg(qwSendMsgBO);
MqUtils.sendMessageToMQ("qwSendRefreshByMQ", JSON.toJSONString(dealQwSendDTO));
}else {
// 重新刷新
DealQwSendDTO dealQwSendDTO = new DealQwSendDTO();
dealQwSendDTO.setRefreshType(1);
dealQwSendDTO.setFinishQwSend(finishQwSendBO);
MqUtils.sendMessageToMQ("qwSendRefreshByMQ", JSON.toJSONString(dealQwSendDTO),60);
}
}
@Override
public void refreshQwSendLog(DealQwSendDTO.QwSendMsgBO qwSendMsg) {
List<GroupSendResultBO> sendResultList = getSendResultList(qwSendMsg);
if (CollectionUtils.isEmpty(sendResultList)) {
return;
}
log.info("刷新企微群发结果:{}", qwSendMsg.getMsgId());
List<TabQwSendLog> entities;
List<List<GroupSendResultBO>> partition = Lists.partition(sendResultList, 1000);
for (List<GroupSendResultBO> groupSendResultBOS : partition) {
List<String> externalUseridList = groupSendResultBOS.stream().map(GroupSendResultBO::getExternalUserid).collect(Collectors.toList());
List<TabHaobanExternalClerkRelated> list = externalClerkRelatedMapper.listByExternalUserIdList(qwSendMsg.getStaffId(), qwSendMsg.getEnterpriseId(), externalUseridList);
if (CollectionUtil.isEmpty(list)) {
continue;
}
Map<String, String> map = list.stream().collect(Collectors.toMap(TabHaobanExternalClerkRelated::getExternalUserId, TabHaobanExternalClerkRelated::getMemberId, (e, x) -> e));
entities = sendResultList.stream().map(o -> {
String externalUserid = o.getExternalUserid();
String memberId = map.get(externalUserid);
if (StringUtils.isBlank(memberId)) {
return null;
}
TabQwSendLog qwSendLog = new TabQwSendLog();
qwSendLog.setId(UniqueIdUtils.uniqueLong());
qwSendLog.setMemberId(memberId);
qwSendLog.setExternalUserId(externalUserid);
qwSendLog.setClerkId(qwSendMsg.getClerkId());
qwSendLog.setStaffId(qwSendMsg.getStaffId());
qwSendLog.setMsgId(qwSendMsg.getMsgId());
qwSendLog.setSendStatus(Objects.equals(o.getStatus(), 1) ? 1 : 2);
qwSendLog.setSendTime(o.getSendTime());
qwSendLog.setFailReasonType(o.getStatus());
qwSendLog.setWxEnterpriseId(qwSendMsg.getWxEnterpriseId());
qwSendLog.setEnterpriseId(qwSendMsg.getEnterpriseId());
return qwSendLog;
}).filter(Objects::nonNull).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(entities)) {
qwSendLogMapper.insertBatch(entities);
List<ContactFollowBatchQDTO.MemberFollow> memberList = new ArrayList<>();
entities.forEach(log ->{
if (!Objects.equals(log.getSendStatus(), 1)) {
return;
}
if (StringUtils.isBlank(log.getMemberId())) {
return;
}
memberList.add(new ContactFollowBatchQDTO.MemberFollow(log.getMemberId(), log.getSendTime()));
});
saveFollowMQ(qwSendMsg.getClerkId(), memberList);
}
entities.clear();
}
}
private List<GroupSendResultBO> getSendResultList(DealQwSendDTO.QwSendMsgBO qwSendMsg) {
String newWxUserId = messageApiService.getNewWxUserIdByStaffId(qwSendMsg.getWxEnterpriseId(), qwSendMsg.getStaffId());
log.info("查询{},{},{}", qwSendMsg.getWxEnterpriseId(), qwSendMsg.getStaffId(), newWxUserId);
if (StringUtils.isBlank(newWxUserId)) {
log.error("未查询到userid");
return Collections.emptyList();
}
List<GroupSendResultBO> sendResultList = getSendResult(qwSendMsg.getWxEnterpriseId(), qwSendMsg.getMsgId(), newWxUserId);
//判断是否已经发送
return sendResultList.stream().filter(dto -> !Objects.equals(dto.getStatus(), 0))
.collect(Collectors.toList());
}
public List<GroupSendResultBO> getSendResult(String wxEnterpriseId, String msgId, String userId) {
List<GroupSendResultBO> sendResultList = new ArrayList<>();
//油标
String nextCursor = null;
//计数器
int count = 1;
//循环获取
while (count <= 20) {
JSONResponse jsonResponse = memberUnionidRelatedApiService.resultExternalMessage(wxEnterpriseId, msgId, nextCursor, userId);
List<GroupSendResultBO> groupSendResultList = null;
try {
groupSendResultList = this.getUserIdList(jsonResponse);
} catch (BusinessException e) {
log.error("获取群发结果异常:{}", e.getMsg());
}
if (groupSendResultList != null) {
sendResultList.addAll(groupSendResultList);
}
//游标不存在, 直接结束循环
if (!jsonResponse.getReturnMap().containsKey("next_cursor")
|| StringUtils.isBlank(jsonResponse.getReturnMap().get("next_cursor").toString())) {
break;
}
//游标修改
nextCursor = jsonResponse.getReturnMap().get("next_cursor").toString();
//计数器递增
count++;
}
return sendResultList;
}
private List<GroupSendResultBO> getUserIdList(JSONResponse jsonResponse) throws BusinessException{
log.info("errorCode:{}, message:{}", jsonResponse.getErrorCode(), jsonResponse.getErrorMessage());
if (jsonResponse.getErrorCode() == 41063) {
log.info("异常-群发消息正在被派发中:{}", JSONObject.toJSONString(jsonResponse));
throw new BusinessException("41063","群发消息正在被派发中,请稍后再试");
} else if (jsonResponse.getErrorCode() == 45033) {
log.info("异常-接口超出限制:需要重新执行");
throw new BusinessException("45033","接口超出限制:需要重新执行");
} else if (jsonResponse.getErrorCode() == 40003) {
log.info("该导购已不是企微员工,无法刷新群发结果");
throw new BusinessException("40003","该导购已不是企微员工,无法刷新群发结果");
} else if (jsonResponse.getErrorCode() == 60111) {
log.info("UserID不存在,无法刷新群发结果");
throw new BusinessException("60111","UserID不存在,无法刷新群发结果");
} else if(jsonResponse.getErrorCode() == 41047) {
// 无效的企业群发消息id
log.info("无效的企业群发消息id");
throw new BusinessException("41047","无效的企业群发消息id");
}else if (jsonResponse.getErrorCode() != 0) {
log.info("异常-:{}", JSONObject.toJSONString(jsonResponse));
throw new BusinessException("-1","群发消息异常");
}
List<?> list = jsonResponse.getList();
if (CollectionUtils.isEmpty(list)) {
return null;
}
return EntityUtil.changeEntityListByJSON(GroupSendResultBO.class, list);
}
private void saveFollowMQ(String clerkId,List<ContactFollowBatchQDTO.MemberFollow> memberList) {
if (org.apache.commons.collections.CollectionUtils.isEmpty(memberList)) {
return;
}
ContactFollowBatchQDTO batchQDTO = new ContactFollowBatchQDTO();
batchQDTO.setMemberList(memberList);
batchQDTO.setClerkId(clerkId);
batchQDTO.setFollowRemark("通过企微群发向客户发送了消息");
MqUtils.sendMessageToMQ("saveBatchFollowForMQ", JSON.toJSONString(batchQDTO));
}
}
......@@ -147,6 +147,7 @@
<dubbo:service interface="com.gic.haoban.manage.api.service.contact.ContactFollowApiService" ref="contactFollowApiService"/>
<dubbo:service interface="com.gic.haoban.manage.api.service.contact.ContactLogApiService" ref="contactLogApiService"/>
<dubbo:service interface="com.gic.haoban.manage.api.service.contact.ContactOrderApiService" ref="contactOrderApiService"/>
<dubbo:service interface="com.gic.haoban.manage.api.service.send.QwSendApiService" ref="qwSendApiService"/>
<dubbo:reference interface="com.gic.enterprise.api.service.DepartmentService" id="gicDepartmentService"/>
<dubbo:reference interface="com.gic.wechat.api.service.qywx.QywxDepartmentApiService"
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gic.haoban.manage.service.dao.mapper.send.QwSendLogMapper">
<resultMap type="com.gic.haoban.manage.service.entity.send.TabQwSendLog" id="TabQwSendLogMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="memberId" column="member_id" jdbcType="VARCHAR"/>
<result property="externalUserId" column="external_user_id" jdbcType="VARCHAR"/>
<result property="clerkId" column="clerk_id" jdbcType="VARCHAR"/>
<result property="staffId" column="staff_id" jdbcType="VARCHAR"/>
<result property="msgId" column="msg_id" jdbcType="VARCHAR"/>
<result property="sendStatus" column="send_status" jdbcType="INTEGER"/>
<result property="sendTime" column="send_time" jdbcType="TIMESTAMP"/>
<result property="failReasonType" column="fail_reason_type" jdbcType="INTEGER"/>
<result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
<result property="enterpriseId" column="enterprise_id" jdbcType="VARCHAR"/>
<result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="TabQwSendLogMap">
select
id, member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
from tab_qw_send_log
where id = #{id}
and delete_flag = 0
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="TabQwSendLogMap">
select
id, member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
from tab_qw_send_log
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="memberId != null and memberId != ''">
and member_id = #{memberId}
</if>
<if test="externalUserId != null and externalUserId != ''">
and external_user_id = #{externalUserId}
</if>
<if test="clerkId != null and clerkId != ''">
and clerk_id = #{clerkId}
</if>
<if test="staffId != null and staffId != ''">
and staff_id = #{staffId}
</if>
<if test="msgId != null and msgId != ''">
and msg_id = #{msgId}
</if>
<if test="sendStatus != null">
and send_status = #{sendStatus}
</if>
<if test="failReasonType != null">
and fail_reason_type = #{failReasonType}
</if>
<if test="wxEnterpriseId != null and wxEnterpriseId != ''">
and wx_enterprise_id = #{wxEnterpriseId}
</if>
<if test="enterpriseId != null and enterpriseId != ''">
and enterprise_id = #{enterpriseId}
</if>
<if test="deleteFlag != null">
and delete_flag = #{deleteFlag}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
and delete_flag = 0
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from tab_qw_send_log
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="memberId != null and memberId != ''">
and member_id = #{memberId}
</if>
<if test="externalUserId != null and externalUserId != ''">
and external_user_id = #{externalUserId}
</if>
<if test="clerkId != null and clerkId != ''">
and clerk_id = #{clerkId}
</if>
<if test="staffId != null and staffId != ''">
and staff_id = #{staffId}
</if>
<if test="msgId != null and msgId != ''">
and msg_id = #{msgId}
</if>
<if test="sendStatus != null">
and send_status = #{sendStatus}
</if>
<if test="failReasonType != null">
and fail_reason_type = #{failReasonType}
</if>
<if test="wxEnterpriseId != null and wxEnterpriseId != ''">
and wx_enterprise_id = #{wxEnterpriseId}
</if>
<if test="enterpriseId != null and enterpriseId != ''">
and enterprise_id = #{enterpriseId}
</if>
<if test="deleteFlag != null">
and delete_flag = #{deleteFlag}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
and delete_flag = 0
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into
tab_qw_send_log(id,member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id)
values
(#{id},#{memberId}, #{externalUserId}, #{clerkId}, #{staffId}, #{msgId}, #{sendStatus}, #{sendTime}, #{failReasonType}, #{wxEnterpriseId}, #{enterpriseId})
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into
tab_qw_send_log(id,member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.id},#{entity.memberId}, #{entity.externalUserId}, #{entity.clerkId}, #{entity.staffId}, #{entity.msgId}, #{entity.sendStatus}, #{entity.sendTime}, #{entity.failReasonType}, #{entity.wxEnterpriseId}, #{entity.enterpriseId})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into
tab_qw_send_log(id,member_id, external_user_id, clerk_id, staff_id, msg_id, send_status,send_time, fail_reason_type, wx_enterprise_id, enterprise_id)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.id},#{entity.memberId}, #{entity.externalUserId}, #{entity.clerkId}, #{entity.staffId}, #{entity.msgId}, #{entity.sendStatus},#{entity.sendTime}, #{entity.failReasonType}, #{entity.wxEnterpriseId}, #{entity.enterpriseId})
</foreach>
on duplicate key update
member_id = values(member_id), external_user_id = values(external_user_id), clerk_id = values(clerk_id), staff_id = values(staff_id), msg_id = values(msg_id), send_status = values(send_status),send_time = values(send_time), fail_reason_type = values(fail_reason_type), wx_enterprise_id = values(wx_enterprise_id), enterprise_id = values(enterprise_id)
</insert>
</mapper>
\ No newline at end of file
<mapper namespace="com.gic.haoban.manage.service.dao.mapper.send.QwSendMsgMapper">
<resultMap type="com.gic.haoban.manage.service.entity.send.TabQwSendMsg" id="TabQwSendMsgMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="clerkId" column="clerk_id" jdbcType="VARCHAR"/>
<result property="staffId" column="staff_id" jdbcType="VARCHAR"/>
<result property="msgId" column="msg_id" jdbcType="VARCHAR"/>
<result property="sendTime" column="send_time" jdbcType="TIMESTAMP"/>
<result property="bizType" column="biz_type" jdbcType="INTEGER"/>
<result property="wxEnterpriseId" column="wx_enterprise_id" jdbcType="VARCHAR"/>
<result property="enterpriseId" column="enterprise_id" jdbcType="VARCHAR"/>
<result property="deleteFlag" column="delete_flag" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
</resultMap>
<!--查询单个-->
<select id="queryById" resultMap="TabQwSendMsgMap">
select
id, clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
from tab_qw_send_msg
where id = #{id}
and delete_flag = 0
</select>
<select id="queryByMsgId" resultMap="TabQwSendMsgMap">
select
id, clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
from tab_qw_send_msg
where msg_id = #{msgId}
and delete_flag = 0
</select>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="TabQwSendMsgMap">
select
id, clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
from tab_qw_send_msg
<where>
delete_flag = 0
<if test="id != null">
and id = #{id}
</if>
<if test="clerkId != null and clerkId != ''">
and clerk_id = #{clerkId}
</if>
<if test="staffId != null and staffId != ''">
and staff_id = #{staffId}
</if>
<if test="msgId != null and msgId != ''">
and msg_id = #{msgId}
</if>
<if test="sendTime != null">
and send_time = #{sendTime}
</if>
<if test="bizType != null">
and biz_type = #{bizType}
</if>
<if test="wxEnterpriseId != null and wxEnterpriseId != ''">
and wx_enterprise_id = #{wxEnterpriseId}
</if>
<if test="enterpriseId != null and enterpriseId != ''">
and enterprise_id = #{enterpriseId}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from tab_qw_send_msg
<where>
delete_flag = 0
<if test="id != null">
and id = #{id}
</if>
<if test="clerkId != null and clerkId != ''">
and clerk_id = #{clerkId}
</if>
<if test="staffId != null and staffId != ''">
and staff_id = #{staffId}
</if>
<if test="msgId != null and msgId != ''">
and msg_id = #{msgId}
</if>
<if test="sendTime != null">
and send_time = #{sendTime}
</if>
<if test="bizType != null">
and biz_type = #{bizType}
</if>
<if test="wxEnterpriseId != null and wxEnterpriseId != ''">
and wx_enterprise_id = #{wxEnterpriseId}
</if>
<if test="enterpriseId != null and enterpriseId != ''">
and enterprise_id = #{enterpriseId}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into tab_qw_send_msg (
clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
) values (
#{clerkId}, #{staffId}, #{msgId}, #{sendTime}, #{bizType}, #{wxEnterpriseId}, #{enterpriseId}, #{deleteFlag}, #{createTime}, #{updateTime}
)
</insert>
<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into tab_qw_send_msg (
clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
) values
<foreach collection="entities" item="entity" separator=",">
(#{entity.clerkId}, #{entity.staffId}, #{entity.msgId}, #{entity.sendTime}, #{entity.bizType}, #{entity.wxEnterpriseId}, #{entity.enterpriseId}, #{entity.deleteFlag}, #{entity.createTime}, #{entity.updateTime})
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into tab_qw_send_msg (
clerk_id, staff_id, msg_id, send_time, biz_type, wx_enterprise_id, enterprise_id, delete_flag, create_time, update_time
) values
<foreach collection="entities" item="entity" separator=",">
(#{entity.clerkId}, #{entity.staffId}, #{entity.msgId}, #{entity.sendTime}, #{entity.bizType}, #{entity.wxEnterpriseId}, #{entity.enterpriseId}, #{entity.deleteFlag}, #{entity.createTime}, #{entity.updateTime})
</foreach>
on duplicate key update
clerk_id = values(clerk_id),
staff_id = values(staff_id),
msg_id = values(msg_id),
send_time = values(send_time),
biz_type = values(biz_type),
wx_enterprise_id = values(wx_enterprise_id),
enterprise_id = values(enterprise_id),
delete_flag = values(delete_flag),
create_time = values(create_time),
update_time = values(update_time)
</insert>
<!--通过主键修改数据-->
<update id="update">
update tab_qw_send_msg
<set>
<if test="clerkId != null and clerkId != ''">clerk_id = #{clerkId},</if>
<if test="staffId != null and staffId != ''">staff_id = #{staffId},</if>
<if test="msgId != null and msgId != ''">msg_id = #{msgId},</if>
<if test="sendTime != null">send_time = #{sendTime},</if>
<if test="bizType != null">biz_type = #{bizType},</if>
<if test="wxEnterpriseId != null and wxEnterpriseId != ''">wx_enterprise_id = #{wxEnterpriseId},</if>
<if test="enterpriseId != null and enterpriseId != ''">enterprise_id = #{enterpriseId},</if>
<if test="deleteFlag != null">delete_flag = #{deleteFlag},</if>
<if test="updateTime != null">update_time = #{updateTime}</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from tab_qw_send_msg where id = #{id}
</delete>
</mapper>
\ No newline at end of file
package com.gic.haoban.manage.web.controller.content;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
......@@ -11,8 +12,10 @@ import com.gic.content.api.dto.material.ProductInfoDTO;
import com.gic.content.api.qdto.material.ContentMaterialLandingPageQDTO;
import com.gic.content.api.qdto.share.MaterialLinkShareQDTO;
import com.gic.content.api.service.ContentMaterialShareApiService;
import com.gic.content.api.utils.MqUtils;
import com.gic.haoban.manage.api.dto.anaylsis.ClerkShareGoodsLogDTO;
import com.gic.haoban.manage.api.dto.content.log.ClerkShareMaterialLogDTO;
import com.gic.haoban.manage.api.dto.send.DealQwSendDTO;
import com.gic.haoban.manage.api.enums.content.ShareBizType;
import com.gic.haoban.manage.api.service.content.MaterialShareLogApiService;
import com.gic.haoban.manage.web.qo.content.ContentMaterialBaseQO;
......@@ -40,6 +43,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
......@@ -83,6 +87,17 @@ public class ClerkMaterialShareController {
temp.setExternalUserId(materialShareLogQo.getExternalUserId());
temp.setExtend(materialShareLogQo.getExtend());
ServiceResponse<Long> serviceResponse = materialShareLogApiService.saveClerkShareMaterialLog(temp);
if (Objects.equals(materialShareLogQo.getShareType(), 2)) {
// 群发结果记录
DealQwSendDTO.FinishQwSendBO finishQwSendBO = new DealQwSendDTO.FinishQwSendBO(
materialShareLogQo.getClerkId(),
materialShareLogQo.getStaffId(),
DateUtil.date(),
1,
materialShareLogQo.getWxEnterpriseId(),
materialShareLogQo.getEnterpriseId());
dealQwSendMsg(finishQwSendBO);
}
if (serviceResponse.isSuccess()) {
return RestResponse.successResult(serviceResponse.getResult());
}
......@@ -135,6 +150,16 @@ public class ClerkMaterialShareController {
ServiceResponse<Long> serviceResponse = materialShareLogApiService.saveClerkShareRecommendLog(list);
// 群发结果记录
DealQwSendDTO.FinishQwSendBO finishQwSendBO = new DealQwSendDTO.FinishQwSendBO(
recommendShareLogQO.getClerkId(),
recommendShareLogQO.getStaffId(),
DateUtil.date(),
2,
recommendShareLogQO.getWxEnterpriseId(),
recommendShareLogQO.getEnterpriseId());
dealQwSendMsg(finishQwSendBO);
if (!serviceResponse.isSuccess()) {
return RestResponse.failure("-701", "系统异常");
}
......@@ -153,6 +178,12 @@ public class ClerkMaterialShareController {
return RestResponse.successResult();
}
private void dealQwSendMsg(DealQwSendDTO.FinishQwSendBO finishQwSend) {
DealQwSendDTO dealQwSendDTO = new DealQwSendDTO();
dealQwSendDTO.setRefreshType(1);
dealQwSendDTO.setFinishQwSend(finishQwSend);
MqUtils.sendMessageToMQ("qwSendRefreshByMQ", JSON.toJSONString(dealQwSendDTO));
}
/**
* 查询素材落地页信息
......
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