Commit cd470723 by 徐高华

群统计

parent 42380389
...@@ -16,8 +16,8 @@ import com.gic.haoban.manage.service.entity.chat.TabGroupChatData; ...@@ -16,8 +16,8 @@ import com.gic.haoban.manage.service.entity.chat.TabGroupChatData;
* @CopyRight * @CopyRight
*/ */
public interface GroupChatDataMapper { public interface GroupChatDataMapper {
public int insert(TabGroupChatData entity); public int batchInsert(List<TabGroupChatData> list) ;
public GroupChatDataDTO listTotalData(ChatDataSearchQDTO qdto); public GroupChatDataDTO listTotalData(ChatDataSearchQDTO qdto);
......
...@@ -26,6 +26,9 @@ public interface GroupChatOwnerMapper { ...@@ -26,6 +26,9 @@ public interface GroupChatOwnerMapper {
public int updateChatCount(@Param("staffId") String staffId, @Param("chatCount") int chatCount); public int updateChatCount(@Param("staffId") String staffId, @Param("chatCount") int chatCount);
public List<GroupChatOwnerDTO> listOwner(OwnerSearchQDTO qdto); public List<GroupChatOwnerDTO> listOwner(OwnerSearchQDTO qdto);
public List<GroupChatOwnerDTO> listOwnerForStatistic(@Param("wxEnterpriseId")String wxEnterpriseId , @Param("startItem") int startItem,
@Param("pageSize") int pageSize);
/** /**
* *
......
package com.gic.haoban.manage.service.service.chat.impl; package com.gic.haoban.manage.service.service.chat.impl;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -43,6 +44,9 @@ public class GroupChatDataServiceImpl implements GroupChatDataService { ...@@ -43,6 +44,9 @@ public class GroupChatDataServiceImpl implements GroupChatDataService {
private static final Logger logger = LoggerFactory.getLogger(GroupChatDataService.class); private static final Logger logger = LoggerFactory.getLogger(GroupChatDataService.class);
// 每次成员数
private int pageSize = 100;
@Autowired @Autowired
private QywxChatApiService qywxChatApiService; private QywxChatApiService qywxChatApiService;
@Autowired @Autowired
...@@ -76,78 +80,93 @@ public class GroupChatDataServiceImpl implements GroupChatDataService { ...@@ -76,78 +80,93 @@ public class GroupChatDataServiceImpl implements GroupChatDataService {
@Override @Override
public void chatDataTimer(String params) { public void chatDataTimer(String params) {
logger.info("群统计定时开始"); logger.info("群统计定时开始,params={}", params);
List<TabHaobanWxEnterprise> wxEnterpriseList = this.wxEnterpriseMapper.listByIds(null); if (StringUtils.isEmpty(params) || "-1".equals(params)) {
for (TabHaobanWxEnterprise item : wxEnterpriseList) { List<TabHaobanWxEnterprise> wxEnterpriseList = this.wxEnterpriseMapper.listByIds(null);
try { for (TabHaobanWxEnterprise item : wxEnterpriseList) {
this.getDataFormQw(item.getWxEnterpriseId()); try {
} catch (Exception e) { this.getDataFormQw(item.getWxEnterpriseId());
logger.info("统计异常,wxeid={}", item.getWxEnterpriseId()); } catch (Exception e) {
e.printStackTrace(); logger.info("统计异常,wxeid={}", item.getWxEnterpriseId());
e.printStackTrace();
}
} }
} else {
this.getDataFormQw(params);
} }
} }
private void getDataFormQw(String wxEnterpriseId) { private void getDataFormQw(String wxEnterpriseId) {
logger.info("开始处理wxEnterpriseId={}", wxEnterpriseId); logger.info("群统计开始wxEnterpriseId={}", wxEnterpriseId);
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId); WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
if (null == qwDTO) { if (null == qwDTO) {
logger.info("wxEnterpriseId不存在,id={}", wxEnterpriseId); logger.info("企业不存在,id={}", wxEnterpriseId);
return; return;
} }
if (qwDTO.getWxSecurityType() == 0) { if (qwDTO.getWxSecurityType() == 0) {
logger.info("wxSecurityType=0,不处理,id={}", wxEnterpriseId); logger.info("wxSecurityType=0,不处理,id={}", wxEnterpriseId);
return; return;
} }
OwnerSearchQDTO qdto = new OwnerSearchQDTO(); int pageNum = 0;
qdto.setWxEnterpriseId(wxEnterpriseId); List<GroupChatOwnerDTO> list = null;
List<GroupChatOwnerDTO> list = this.groupChatOwnerMapper.listOwner(qdto); while (true) {
if (CollectionUtils.isEmpty(list)) { list = this.groupChatOwnerMapper.listOwnerForStatistic(wxEnterpriseId, pageNum * pageSize, pageSize);
logger.info("无群主记录,不处理"); if (CollectionUtils.isEmpty(list)) {
return; logger.info("无群主记录,不处理,wxeid={}", wxEnterpriseId);
} break;
List<String> userIdList = null; }
Map<String, String> staffIdMap = new HashMap<>(); pageNum++;
if (qwDTO.needOpenUserId3th()) { List<String> userIdList = null;
userIdList = list.stream().map(dto -> dto.getWxOpenUserId()).collect(Collectors.toList()); Map<String, String> staffIdMap = new HashMap<>();
staffIdMap = list.stream().collect(Collectors.toMap(GroupChatOwnerDTO::getWxOpenUserId, if (qwDTO.needOpenUserId3th()) {
GroupChatOwnerDTO::getStaffId, (k1, k2) -> k1)); userIdList = list.stream().map(dto -> dto.getWxOpenUserId()).collect(Collectors.toList());
} else { staffIdMap = list.stream().collect(Collectors.toMap(GroupChatOwnerDTO::getWxOpenUserId,
userIdList = list.stream().map(dto -> dto.getWxUserId()).collect(Collectors.toList()); GroupChatOwnerDTO::getStaffId, (k1, k2) -> k1));
staffIdMap = list.stream().collect( } else {
Collectors.toMap(GroupChatOwnerDTO::getWxUserId, GroupChatOwnerDTO::getStaffId, (k1, k2) -> k1)); userIdList = list.stream().map(dto -> dto.getWxUserId()).collect(Collectors.toList());
} staffIdMap = list.stream().collect(Collectors.toMap(GroupChatOwnerDTO::getWxUserId,
GroupChatOwnerDTO::getStaffId, (k1, k2) -> k1));
Date date = DateUtil.addDay(DateUtil.getStartTimeOfDay(), -1); }
Long time = date.getTime() / 1000;
ServiceResponse<List<GroupChatQwDataDTO>> resp = this.qywxChatApiService.statistic(qwDTO.getThirdCorpid(),
config.getWxSuiteid(), userIdList, time, time);
logger.info(JSON.toJSONString(resp));
List<GroupChatQwDataDTO> dataList = resp.getResult(); Date date = DateUtil.addDay(DateUtil.getStartTimeOfDay(), -1);
if (CollectionUtils.isEmpty(dataList)) { Long time = date.getTime() / 1000;
return; ServiceResponse<List<GroupChatQwDataDTO>> resp = this.qywxChatApiService.statistic(qwDTO.getThirdCorpid(),
} config.getWxSuiteid(), userIdList, time, time);
for (GroupChatQwDataDTO dto : dataList) { List<GroupChatQwDataDTO> dataList = resp.getResult();
String userId = dto.getOwner(); if (CollectionUtils.isEmpty(dataList)) {
if (StringUtils.isEmpty(staffIdMap.get(userId))) { if (list.size() < pageSize) {
break;
}
continue; continue;
} }
GroupChatQwDataItemDTO item = dto.getData(); List<TabGroupChatData> addList = new ArrayList<>();
TabGroupChatData entity = new TabGroupChatData(); for (GroupChatQwDataDTO dto : dataList) {
entity.setDataId(UniqueIdUtils.uniqueLong()); String userId = dto.getOwner();
entity.setDate(date); if (StringUtils.isEmpty(staffIdMap.get(userId))) {
entity.setWxEnterpriseId(wxEnterpriseId); continue;
entity.setStaffId(staffIdMap.get(userId)); }
entity.setMsgTotal(item.getMsg_total()); GroupChatQwDataItemDTO item = dto.getData();
entity.setChatHasMsg(item.getChat_has_msg()); TabGroupChatData entity = new TabGroupChatData();
entity.setChatTotal(item.getChat_total()); entity.setDataId(UniqueIdUtils.uniqueLong());
entity.setNewChatCnt(item.getNew_chat_cnt()); entity.setDate(date);
entity.setMigrateTraineeChatCnt(item.getMigrate_trainee_chat_cnt()); entity.setWxEnterpriseId(wxEnterpriseId);
entity.setMemberHasMsg(item.getMember_has_msg()); entity.setStaffId(staffIdMap.get(userId));
entity.setMemberTotal(item.getMember_total()); entity.setMsgTotal(item.getMsg_total());
entity.setNewMemberCnt(item.getNew_member_cnt()); entity.setChatHasMsg(item.getChat_has_msg());
this.groupChatDataMapper.insert(entity); entity.setChatTotal(item.getChat_total());
entity.setNewChatCnt(item.getNew_chat_cnt());
entity.setMigrateTraineeChatCnt(item.getMigrate_trainee_chat_cnt());
entity.setMemberHasMsg(item.getMember_has_msg());
entity.setMemberTotal(item.getMember_total());
entity.setNewMemberCnt(item.getNew_member_cnt());
addList.add(entity);
}
if (CollectionUtils.isNotEmpty(addList)) {
this.groupChatDataMapper.batchInsert(addList);
}
if (list.size() < pageSize) {
break;
}
} }
} }
} }
\ No newline at end of file
...@@ -99,7 +99,7 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService { ...@@ -99,7 +99,7 @@ public class GroupChatPlanServiceImpl implements GroupChatPlanService {
private static GicMQClient mqClient = GICMQClientUtil.getClientInstance(); private static GicMQClient mqClient = GICMQClientUtil.getClientInstance();
// 每次成员数 // 每次成员数
private int pageSize = 1; private int pageSize = 1000;
// 发送队列 // 发送队列
private void putMQForSend(Long id) { private void putMQForSend(Long id) {
......
...@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service; ...@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.minlog.Log;
import com.gic.api.base.commons.BasePageInfo; import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse; import com.gic.api.base.commons.ServiceResponse;
...@@ -941,6 +942,10 @@ public class GroupChatServiceImpl implements GroupChatService { ...@@ -941,6 +942,10 @@ public class GroupChatServiceImpl implements GroupChatService {
} }
String secret = secretSetting.getSecretVal(); String secret = secretSetting.getSecretVal();
TabHaobanStaff stff = this.staffMapper.selectByPrimaryKey(staffId); TabHaobanStaff stff = this.staffMapper.selectByPrimaryKey(staffId);
if(null == stff) {
Log.info("staff不存在,stffid={}",staffId);
return ;
}
String userid = stff.getWxUserId(); String userid = stff.getWxUserId();
if (qwDTO.needOpenUserIdDk()) { if (qwDTO.needOpenUserIdDk()) {
userid = stff.getWxOpenUseId(); userid = stff.getWxOpenUseId();
......
...@@ -33,40 +33,39 @@ ...@@ -33,40 +33,39 @@
migrate_trainee_chat_cnt, migrate_trainee_chat_cnt,
create_time create_time
</sql> </sql>
<!-- ===================== 新增 ======================== -->
<insert id="insert" <insert id="batchInsert">
parameterType="com.gic.haoban.manage.service.entity.chat.TabGroupChatData"> INSERT INTO tab_haoban_group_chat_data(
<![CDATA[ data_id,
INSERT INTO tab_haoban_group_chat_data( wx_enterprise_id,
data_id, staff_id,
wx_enterprise_id, date,
staff_id, new_chat_cnt,
date, chat_total,
new_chat_cnt, chat_has_msg,
chat_total, new_member_cnt,
chat_has_msg, member_total,
new_member_cnt, member_has_msg,
member_total, msg_total,
member_has_msg, migrate_trainee_chat_cnt,
msg_total, create_time
migrate_trainee_chat_cnt, )VALUES
create_time <foreach collection="list" item="item" separator="," >
)VALUES( ( #{item.dataId},
#{dataId}, #{item.wxEnterpriseId},
#{wxEnterpriseId}, #{item.staffId},
#{staffId}, #{item.date},
#{date}, #{item.newChatCnt},
#{newChatCnt}, #{item.chatTotal},
#{chatTotal}, #{item.chatHasMsg},
#{chatHasMsg}, #{item.newMemberCnt},
#{newMemberCnt}, #{item.memberTotal},
#{memberTotal}, #{item.memberHasMsg},
#{memberHasMsg}, #{item.msgTotal},
#{msgTotal}, #{item.migrateTraineeChatCnt},
#{migrateTraineeChatCnt}, now()
now() )
) </foreach>
]]>
</insert> </insert>
<select id="listTotalData" parameterType="com.gic.haoban.manage.api.dto.qdto.chat.ChatDataSearchQDTO" <select id="listTotalData" parameterType="com.gic.haoban.manage.api.dto.qdto.chat.ChatDataSearchQDTO"
......
...@@ -225,12 +225,13 @@ ...@@ -225,12 +225,13 @@
</select> </select>
<select id="listAllNeedInit" resultMap="result-map-tabHaobanGroupChat"> <select id="listAllNeedInit" resultMap="result-map-tabHaobanGroupChat">
select <include refid="Base_Column_List" /> from tab_haoban_group_chat where create_time > DATE_ADD(NOW(),INTERVAL -1 day) and init_flag = 0 select <include refid="Base_Column_List" /> from tab_haoban_group_chat where update_time > DATE_ADD(NOW(),INTERVAL -1 day) and init_flag = 0
</select> </select>
<select id="listAllNeedInitWxChatIdDk" resultMap="result-map-tabHaobanGroupChat"> <select id="listAllNeedInitWxChatIdDk" resultMap="result-map-tabHaobanGroupChat">
select wx_enterprise_id wxEnterpriseId , staff_id staffId from tab_haoban_group_chat where update_time > DATE_ADD(NOW(),INTERVAL -30 day) and wx_chat_id_dk is null and init_flag = 1 and name is not null SELECT a.wx_enterprise_id wxEnterpriseId , a.staff_id staffId FROM tab_haoban_group_chat a LEFT JOIN tab_haoban_wx_enterprise b ON a.wx_enterprise_id=b.wx_enterprise_id
group by wx_enterprise_id , staff_id WHERE a.update_time > DATE_ADD(NOW(),INTERVAL -7 DAY) AND a.wx_chat_id_dk IS NULL AND a.init_flag = 1 AND a.chat_status != 4 AND a.name <![CDATA[ <> ]]>'' AND b.wx_security_type > 0
GROUP BY a.wx_enterprise_id , a.staff_id
</select> </select>
<select id="list" resultType="com.gic.haoban.manage.api.dto.chat.GroupChatDTO" parameterType="com.gic.haoban.manage.api.dto.qdto.chat.GroupChatSearchQDTO"> <select id="list" resultType="com.gic.haoban.manage.api.dto.chat.GroupChatDTO" parameterType="com.gic.haoban.manage.api.dto.qdto.chat.GroupChatSearchQDTO">
......
...@@ -78,6 +78,14 @@ ...@@ -78,6 +78,14 @@
</if> </if>
</select> </select>
<select id="listOwnerForStatistic" resultType="com.gic.haoban.manage.api.dto.chat.GroupChatOwnerDTO">
SELECT a.staff_id staffId , a.wx_enterprise_id wxEnterpriseId ,
b.wx_user_id wxUserId , b.wx_open_user_id wxOpenUserId
FROM tab_haoban_group_chat_owner a LEFT JOIN tab_haoban_staff b ON a.`staff_id` = b.`staff_id`
where a.wx_enterprise_id=#{wxEnterpriseId} and b.status_flag = 1 limit ${startItem},${pageSize}
</select>
<select id="dimissionOwnerList" resultType="com.gic.haoban.manage.api.dto.chat.GroupChatOwnerDTO"> <select id="dimissionOwnerList" resultType="com.gic.haoban.manage.api.dto.chat.GroupChatOwnerDTO">
SELECT a.staff_id staffId , b.`staff_name` staffName , a.wx_enterprise_id wxEnterpriseId , SELECT a.staff_id staffId , b.`staff_name` staffName , a.wx_enterprise_id wxEnterpriseId ,
b.wx_user_id wxUserId , b.wx_open_user_id wxOpenUserId b.wx_user_id wxUserId , b.wx_open_user_id wxOpenUserId
......
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