Commit 932dda28 by 徐高华

群发

parent dcf8e802
...@@ -281,10 +281,10 @@ public class GroupChatHmServiceImpl implements GroupChatHmService { ...@@ -281,10 +281,10 @@ public class GroupChatHmServiceImpl implements GroupChatHmService {
if (CollectionUtils.isNotEmpty(relationList)) { if (CollectionUtils.isNotEmpty(relationList)) {
this.groupChatHmRelationMapper.insertBatch(relationList); this.groupChatHmRelationMapper.insertBatch(relationList);
// 更新群的企业id到活码的企业ID // 更新群的企业id到活码的企业ID
logger.info("自动更新群关联的GIC企业ID,eid={},addIdList={}",hm.getEnterpriseId(),addIdList); logger.info("自动更新群关联的GIC企业ID,eid={},addIdList={}", hm.getEnterpriseId(), addIdList);
this.groupChatMapper.updateChatEnterpriseId(wxEnterpriseId, hm.getEnterpriseId(), addIdList); this.groupChatMapper.updateChatEnterpriseId(wxEnterpriseId, hm.getEnterpriseId(), addIdList);
} }
} else { } else {
ServiceResponse<String> addResp = this.qywxChatApiService.addJoinWay(qwDTO.getDkCorpid(), ServiceResponse<String> addResp = this.qywxChatApiService.addJoinWay(qwDTO.getDkCorpid(),
secretSetting.getSecretVal(), joinDTO); secretSetting.getSecretVal(), joinDTO);
......
...@@ -27,8 +27,10 @@ import com.gic.commons.util.EntityUtil; ...@@ -27,8 +27,10 @@ import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.GICMQClientUtil; import com.gic.commons.util.GICMQClientUtil;
import com.gic.commons.util.PageHelperUtils; import com.gic.commons.util.PageHelperUtils;
import com.gic.commons.util.UniqueIdUtils; import com.gic.commons.util.UniqueIdUtils;
import com.gic.dubbo.entity.ProviderLocalTag;
import com.gic.enterprise.api.dto.StoreDTO; import com.gic.enterprise.api.dto.StoreDTO;
import com.gic.enterprise.api.service.StoreService; import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.common.utils.DingUtils;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO; import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.dto.chat.GroupChatPlanDTO; import com.gic.haoban.manage.api.dto.chat.GroupChatPlanDTO;
import com.gic.haoban.manage.api.dto.chat.GroupChatPlanLogDTO; import com.gic.haoban.manage.api.dto.chat.GroupChatPlanLogDTO;
...@@ -175,6 +177,7 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService { ...@@ -175,6 +177,7 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService {
@Override @Override
public void doPlan(Long planId) { public void doPlan(Long planId) {
logger.info("开始群群发发送{}", planId); logger.info("开始群群发发送{}", planId);
DingUtils.send("开始群群发发送,planId=" + planId + ",tranceid=" + ProviderLocalTag.tag.get().traceId, false);
TabGroupChatPlan plan = this.groupChatPlanMapper.selectById(planId); TabGroupChatPlan plan = this.groupChatPlanMapper.selectById(planId);
if (null == plan) { if (null == plan) {
logger.info("计划不存在,planid={}", planId); logger.info("计划不存在,planid={}", planId);
...@@ -190,36 +193,44 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService { ...@@ -190,36 +193,44 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService {
String chatContent = plan.getChatContent(); String chatContent = plan.getChatContent();
JSONArray jsonArr = JSONArray.parseArray(chatContent); JSONArray jsonArr = JSONArray.parseArray(chatContent);
List<String> madidList = new ArrayList<>(); List<String> madidList = new ArrayList<>();
GroupChatPlanSearchQDTO qdto = new GroupChatPlanSearchQDTO();
qdto.setWxEnterpriseId(wxEnterpriseId);
BasePageInfo basePageInfo = new BasePageInfo();
basePageInfo.setPageNum(1);
// todo
basePageInfo.setPageSize(1000);
Page<GroupChatPlanOwnerLogDTO> page = this.groupChatPlanOwnerLogService.listPage(planId, qdto, basePageInfo);
for (int i = 0; i < jsonArr.size(); i++) { for (int i = 0; i < jsonArr.size(); i++) {
JSONObject json = jsonArr.getJSONObject(i); JSONObject json = jsonArr.getJSONObject(i);
madidList.add(json.getString("relation_id")); madidList.add(json.getString("relation_id"));
} }
List<GroupChatPlanOwnerLogDTO> ownerList = page.getResult(); int currentPage = 1;
for (GroupChatPlanOwnerLogDTO dto : ownerList) { GroupChatPlanSearchQDTO qdto = new GroupChatPlanSearchQDTO();
String staffId = dto.getStaffId(); qdto.setWxEnterpriseId(wxEnterpriseId);
ServiceResponse<String> sendResp = qywxSendService.sendChatMessage(wxEnterpriseId, staffId, madidList); BasePageInfo basePageInfo = new BasePageInfo();
TabGroupChatPlanOwnerLog ownerLog = EntityUtil.changeEntityByJSON(TabGroupChatPlanOwnerLog.class, dto); basePageInfo.setPageNum(currentPage);
if (sendResp.isSuccess()) { basePageInfo.setPageSize(1);
String msgid = sendResp.getResult(); Page<GroupChatPlanOwnerLogDTO> page = this.groupChatPlanOwnerLogService.listPage(planId, qdto, basePageInfo);
ownerLog.setMsgid(msgid); while (page.getTotalPage() >= currentPage) {
ownerLog.setSendStatus(2); if (currentPage > 1) {
} else { basePageInfo.setPageNum(currentPage);
ownerLog.setRemark(sendResp.getMessage()); page = this.groupChatPlanOwnerLogService.listPage(planId, qdto, basePageInfo);
ownerLog.setSendStatus(0);
} }
ownerLog.setWxEnterpriseId(wxEnterpriseId); currentPage++;
this.groupChatPlanOwnerLogService.update(ownerLog); List<GroupChatPlanOwnerLogDTO> ownerList = page.getResult();
// 代办 for (GroupChatPlanOwnerLogDTO dto : ownerList) {
if (StringUtils.isNotBlank(ownerLog.getClerkId())) { String staffId = dto.getStaffId();
this.savePendTask(dto, plan); ServiceResponse<String> sendResp = qywxSendService.sendChatMessage(wxEnterpriseId, staffId, madidList);
TabGroupChatPlanOwnerLog ownerLog = EntityUtil.changeEntityByJSON(TabGroupChatPlanOwnerLog.class, dto);
if (sendResp.isSuccess()) {
String msgid = sendResp.getResult();
ownerLog.setMsgid(msgid);
ownerLog.setSendStatus(2);
} else {
ownerLog.setRemark(sendResp.getMessage());
ownerLog.setSendStatus(0);
}
ownerLog.setWxEnterpriseId(wxEnterpriseId);
this.groupChatPlanOwnerLogService.update(ownerLog);
// 代办
if (StringUtils.isNotBlank(ownerLog.getClerkId())) {
this.savePendTask(dto, plan);
}
} }
} }
} }
...@@ -241,6 +252,7 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService { ...@@ -241,6 +252,7 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService {
@Override @Override
public void doPlanSendInfoTimer(String params) { public void doPlanSendInfoTimer(String params) {
DingUtils.send("开始群群发统计(定时),params=" + params + ",tranceid=" + ProviderLocalTag.tag.get().traceId, false);
Long planId = Long.parseLong(params); Long planId = Long.parseLong(params);
List<Long> idList = this.groupChatPlanOwnerLogService.listForTimer(planId); List<Long> idList = this.groupChatPlanOwnerLogService.listForTimer(planId);
logger.info("定时处理群发结果,条数={}", idList.size()); logger.info("定时处理群发结果,条数={}", idList.size());
...@@ -276,8 +288,27 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService { ...@@ -276,8 +288,27 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService {
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
int sendCount = 0; int sendCount = 0;
int failCount = 0; int failCount = 0;
Long planId = ownerLog.getPlanId();
TabGroupChatPlan plan = this.groupChatPlanMapper.selectById(planId);
for (QywxSendMessageResultDTO item : list) { for (QywxSendMessageResultDTO item : list) {
TabGroupChatPlanLog entity = new TabGroupChatPlanLog(); TabGroupChatPlanLog entity = new TabGroupChatPlanLog();
Date sendTime = item.getSendTime();
String wxChatId = item.getChatId();
// 如果企微的发送时间晚于计划的结束时间,不记录此类数据
if (sendTime.after(plan.getEndTime())) {
logger.info("发送时间晚计划结束时间");
continue;
}
GroupChatBO chat = this.groupChatService.getByWxChatId(wxEnterpriseId, wxChatId);
if (null == chat || StringUtils.isBlank(chat.getEnterpriseId())) {
logger.info("群不存在,或未认领,wxChatId={}", wxChatId);
continue;
}
if (!chat.getEnterpriseId().equals(plan.getEnterpriseId())) {
logger.info("群的商户id和计划的商户id不一致{},{}", chat.getEnterpriseId(), plan.getEnterpriseId());
continue;
}
entity.setGroupChatId(chat.getGroupChatId());
// 企微返回成功 // 企微返回成功
// 0-未发送 1-已发送 2-因客户不是好友导致发送失败 3-因客户已经收到其他群发消息导致发送失败 // 0-未发送 1-已发送 2-因客户不是好友导致发送失败 3-因客户已经收到其他群发消息导致发送失败
if (item.getStatus() == 1) { if (item.getStatus() == 1) {
...@@ -289,22 +320,12 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService { ...@@ -289,22 +320,12 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService {
// 发送失败 // 发送失败
entity.setSendStatus(0); entity.setSendStatus(0);
} }
String wxChatId = item.getChatId();
Date sendTime = item.getSendTime();
entity.setLogId(UniqueIdUtils.uniqueLong()); entity.setLogId(UniqueIdUtils.uniqueLong());
entity.setPlanId(ownerLog.getPlanId()); entity.setPlanId(ownerLog.getPlanId());
entity.setOwnLogId(ownerLog.getOwnerLogId()); entity.setOwnLogId(ownerLog.getOwnerLogId());
entity.setWxEnterpriseId(wxEnterpriseId); entity.setWxEnterpriseId(wxEnterpriseId);
entity.setEnterpriseId(enterpriseId); entity.setEnterpriseId(enterpriseId);
entity.setStaffId(staffId); entity.setStaffId(staffId);
GroupChatBO chat = this.groupChatService.getByWxChatId(wxEnterpriseId, wxChatId);
if (null == chat || StringUtils.isBlank(chat.getEnterpriseId())) {
logger.info("群不存在,或未认领,wxChatId={}", wxChatId);
continue;
}
if (null != chat) {
entity.setGroupChatId(chat.getGroupChatId());
}
entity.setSendTime(sendTime); entity.setSendTime(sendTime);
this.groupChatPlanLogMapper.insert(entity); this.groupChatPlanLogMapper.insert(entity);
} }
...@@ -327,8 +348,8 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService { ...@@ -327,8 +348,8 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService {
@Override @Override
public void stop(String clerkId, String clerkName, Long planId) { public void stop(String clerkId, String clerkName, Long planId) {
logger.info("终止计划,并触发统计planId={}", planId);
this.groupChatPlanMapper.stopById(planId, clerkId, clerkName); this.groupChatPlanMapper.stopById(planId, clerkId, clerkName);
logger.info("触发统计");
this.putMQForData(planId); this.putMQForData(planId);
} }
......
...@@ -111,7 +111,7 @@ ...@@ -111,7 +111,7 @@
<update id="stopById"> <update id="stopById">
UPDATE UPDATE
tab_haoban_group_chat_plan SET status_flag = 0 , modifier_id = tab_haoban_group_chat_plan SET status_flag = 0 , modifier_id =
#{clerkId} , modifier_name = #{clerkName} , send_time = now() , update_time=now() WHERE plan_id = #{planId} #{clerkId} , modifier_name = #{clerkName} , end_time = now() , update_time=now() WHERE plan_id = #{planId}
</update> </update>
<update id="updateSendFlag"> <update id="updateSendFlag">
......
...@@ -104,7 +104,8 @@ ...@@ -104,7 +104,8 @@
<select id="listForTimer" resultType="long"> <select id="listForTimer" resultType="long">
SELECT a.owner_log_id FROM tab_haoban_group_chat_plan_owner_log a left join tab_haoban_group_chat_plan b on a.plan_id = b.plan_id SELECT a.owner_log_id FROM tab_haoban_group_chat_plan_owner_log a left join tab_haoban_group_chat_plan b on a.plan_id = b.plan_id
WHERE b.end_time >= DATE_ADD(NOW(),INTERVAL -12 hour) and a.done_flag = 0 and a.delete_flag = 0 and b.delete_flag = 0 and a.msgid is not null WHERE b.end_time >= DATE_ADD(NOW(),INTERVAL -6 hour) and a.done_flag = 0 and a.delete_flag = 0 and b.delete_flag = 0 and a.msgid is not null
and b.status_flag = 0
<if test="null != planId and -1 != planId"> <if test="null != planId and -1 != planId">
and a.plan_id = #{planId} and a.plan_id = #{planId}
</if> </if>
...@@ -127,7 +128,8 @@ ...@@ -127,7 +128,8 @@
a.msgid msgid a.msgid msgid
from tab_haoban_group_chat_plan_owner_log a left join tab_haoban_staff b on a.staff_id = b.staff_id from tab_haoban_group_chat_plan_owner_log a left join tab_haoban_staff b on a.staff_id = b.staff_id
where where
a.wx_enterprise_id = #{wxEnterpriseId} and a.plan_id = #{planId} a.wx_enterprise_id = #{wxEnterpriseId} and a.plan_id = #{planId} and a.delete_flag = 0
order by a.create_time , a.owner_log_id
</select> </select>
<select id="listOwnerLogPageForWxaTotal" parameterType="com.gic.haoban.manage.api.dto.qdto.chat.GroupChatPlanSearchQDTO" resultType="com.gic.haoban.manage.api.dto.chat.ChatOwnerTotalDTO"> <select id="listOwnerLogPageForWxaTotal" parameterType="com.gic.haoban.manage.api.dto.qdto.chat.GroupChatPlanSearchQDTO" resultType="com.gic.haoban.manage.api.dto.chat.ChatOwnerTotalDTO">
......
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