Commit d754da9c by 徐高华

Merge branch 'feature/社群' into 'master'

Feature/社群

See merge request !847
parents 8de2644d 4c415a97
......@@ -16,8 +16,8 @@ import com.gic.haoban.manage.service.entity.chat.TabGroupChatData;
* @CopyRight
*/
public interface GroupChatDataMapper {
public int insert(TabGroupChatData entity);
public int batchInsert(List<TabGroupChatData> list) ;
public GroupChatDataDTO listTotalData(ChatDataSearchQDTO qdto);
......
......@@ -26,6 +26,9 @@ public interface GroupChatOwnerMapper {
public int updateChatCount(@Param("staffId") String staffId, @Param("chatCount") int chatCount);
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;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -13,7 +14,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
......@@ -24,7 +24,6 @@ import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.dto.chat.GroupChatDataDTO;
import com.gic.haoban.manage.api.dto.chat.GroupChatOwnerDTO;
import com.gic.haoban.manage.api.dto.qdto.chat.ChatDataSearchQDTO;
import com.gic.haoban.manage.api.dto.qdto.chat.OwnerSearchQDTO;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.dao.mapper.WxEnterpriseMapper;
import com.gic.haoban.manage.service.dao.mapper.chat.GroupChatDataMapper;
......@@ -43,6 +42,9 @@ public class GroupChatDataServiceImpl implements GroupChatDataService {
private static final Logger logger = LoggerFactory.getLogger(GroupChatDataService.class);
// 每次成员数
private int pageSize = 100;
@Autowired
private QywxChatApiService qywxChatApiService;
@Autowired
......@@ -76,78 +78,93 @@ public class GroupChatDataServiceImpl implements GroupChatDataService {
@Override
public void chatDataTimer(String params) {
logger.info("群统计定时开始");
List<TabHaobanWxEnterprise> wxEnterpriseList = this.wxEnterpriseMapper.listByIds(null);
for (TabHaobanWxEnterprise item : wxEnterpriseList) {
try {
this.getDataFormQw(item.getWxEnterpriseId());
} catch (Exception e) {
logger.info("统计异常,wxeid={}", item.getWxEnterpriseId());
e.printStackTrace();
logger.info("群统计定时开始,params={}", params);
if (StringUtils.isEmpty(params) || "-1".equals(params)) {
List<TabHaobanWxEnterprise> wxEnterpriseList = this.wxEnterpriseMapper.listByIds(null);
for (TabHaobanWxEnterprise item : wxEnterpriseList) {
try {
this.getDataFormQw(item.getWxEnterpriseId());
} catch (Exception e) {
logger.info("统计异常,wxeid={}", item.getWxEnterpriseId());
e.printStackTrace();
}
}
} else {
this.getDataFormQw(params);
}
}
private void getDataFormQw(String wxEnterpriseId) {
logger.info("开始处理wxEnterpriseId={}", wxEnterpriseId);
logger.info("群统计开始wxEnterpriseId={}", wxEnterpriseId);
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
if (null == qwDTO) {
logger.info("wxEnterpriseId不存在,id={}", wxEnterpriseId);
logger.info("企业不存在,id={}", wxEnterpriseId);
return;
}
if (qwDTO.getWxSecurityType() == 0) {
logger.info("wxSecurityType=0,不处理,id={}", wxEnterpriseId);
return;
}
OwnerSearchQDTO qdto = new OwnerSearchQDTO();
qdto.setWxEnterpriseId(wxEnterpriseId);
List<GroupChatOwnerDTO> list = this.groupChatOwnerMapper.listOwner(qdto);
if (CollectionUtils.isEmpty(list)) {
logger.info("无群主记录,不处理");
return;
}
List<String> userIdList = null;
Map<String, String> staffIdMap = new HashMap<>();
if (qwDTO.needOpenUserId3th()) {
userIdList = list.stream().map(dto -> dto.getWxOpenUserId()).collect(Collectors.toList());
staffIdMap = list.stream().collect(Collectors.toMap(GroupChatOwnerDTO::getWxOpenUserId,
GroupChatOwnerDTO::getStaffId, (k1, k2) -> k1));
} else {
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));
int pageNum = 0;
List<GroupChatOwnerDTO> list = null;
while (true) {
list = this.groupChatOwnerMapper.listOwnerForStatistic(wxEnterpriseId, pageNum * pageSize, pageSize);
if (CollectionUtils.isEmpty(list)) {
logger.info("无群主记录,不处理,wxeid={}", wxEnterpriseId);
break;
}
pageNum++;
List<String> userIdList = null;
Map<String, String> staffIdMap = new HashMap<>();
if (qwDTO.needOpenUserId3th()) {
userIdList = list.stream().map(dto -> dto.getWxOpenUserId()).collect(Collectors.toList());
staffIdMap = list.stream().collect(Collectors.toMap(GroupChatOwnerDTO::getWxOpenUserId,
GroupChatOwnerDTO::getStaffId, (k1, k2) -> k1));
} else {
userIdList = list.stream().map(dto -> dto.getWxUserId()).collect(Collectors.toList());
staffIdMap = list.stream().collect(Collectors.toMap(GroupChatOwnerDTO::getWxUserId,
GroupChatOwnerDTO::getStaffId, (k1, k2) -> k1));
}
List<GroupChatQwDataDTO> dataList = resp.getResult();
if (CollectionUtils.isEmpty(dataList)) {
return;
}
for (GroupChatQwDataDTO dto : dataList) {
String userId = dto.getOwner();
if (StringUtils.isEmpty(staffIdMap.get(userId))) {
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);
List<GroupChatQwDataDTO> dataList = resp.getResult();
if (CollectionUtils.isEmpty(dataList)) {
if (list.size() < pageSize) {
break;
}
continue;
}
GroupChatQwDataItemDTO item = dto.getData();
TabGroupChatData entity = new TabGroupChatData();
entity.setDataId(UniqueIdUtils.uniqueLong());
entity.setDate(date);
entity.setWxEnterpriseId(wxEnterpriseId);
entity.setStaffId(staffIdMap.get(userId));
entity.setMsgTotal(item.getMsg_total());
entity.setChatHasMsg(item.getChat_has_msg());
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());
this.groupChatDataMapper.insert(entity);
List<TabGroupChatData> addList = new ArrayList<>();
for (GroupChatQwDataDTO dto : dataList) {
String userId = dto.getOwner();
if (StringUtils.isEmpty(staffIdMap.get(userId))) {
continue;
}
GroupChatQwDataItemDTO item = dto.getData();
TabGroupChatData entity = new TabGroupChatData();
entity.setDataId(UniqueIdUtils.uniqueLong());
entity.setDate(date);
entity.setWxEnterpriseId(wxEnterpriseId);
entity.setStaffId(staffIdMap.get(userId));
entity.setMsgTotal(item.getMsg_total());
entity.setChatHasMsg(item.getChat_has_msg());
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 {
private static GicMQClient mqClient = GICMQClientUtil.getClientInstance();
// 每次成员数
private int pageSize = 1;
private int pageSize = 1000;
// 发送队列
private void putMQForSend(Long id) {
......
......@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.minlog.Log;
import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
......@@ -936,11 +937,15 @@ public class GroupChatServiceImpl implements GroupChatService {
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(qwDTO.getWxEnterpriseId(),
SecretTypeEnum.CUSTOMIZED_APP.getVal());
if (null == secretSetting) {
logger.info("未配置代开应用");
logger.info("未配置代开应用,wxEnterpriseId={}",wxEnterpriseId);
return;
}
String secret = secretSetting.getSecretVal();
TabHaobanStaff stff = this.staffMapper.selectByPrimaryKey(staffId);
if(null == stff) {
Log.info("staff不存在,stffid={}",staffId);
return ;
}
String userid = stff.getWxUserId();
if (qwDTO.needOpenUserIdDk()) {
userid = stff.getWxOpenUseId();
......
......@@ -33,40 +33,39 @@
migrate_trainee_chat_cnt,
create_time
</sql>
<!-- ===================== 新增 ======================== -->
<insert id="insert"
parameterType="com.gic.haoban.manage.service.entity.chat.TabGroupChatData">
<![CDATA[
INSERT INTO tab_haoban_group_chat_data(
data_id,
wx_enterprise_id,
staff_id,
date,
new_chat_cnt,
chat_total,
chat_has_msg,
new_member_cnt,
member_total,
member_has_msg,
msg_total,
migrate_trainee_chat_cnt,
create_time
)VALUES(
#{dataId},
#{wxEnterpriseId},
#{staffId},
#{date},
#{newChatCnt},
#{chatTotal},
#{chatHasMsg},
#{newMemberCnt},
#{memberTotal},
#{memberHasMsg},
#{msgTotal},
#{migrateTraineeChatCnt},
now()
)
]]>
<insert id="batchInsert">
INSERT INTO tab_haoban_group_chat_data(
data_id,
wx_enterprise_id,
staff_id,
date,
new_chat_cnt,
chat_total,
chat_has_msg,
new_member_cnt,
member_total,
member_has_msg,
msg_total,
migrate_trainee_chat_cnt,
create_time
)VALUES
<foreach collection="list" item="item" separator="," >
( #{item.dataId},
#{item.wxEnterpriseId},
#{item.staffId},
#{item.date},
#{item.newChatCnt},
#{item.chatTotal},
#{item.chatHasMsg},
#{item.newMemberCnt},
#{item.memberTotal},
#{item.memberHasMsg},
#{item.msgTotal},
#{item.migrateTraineeChatCnt},
now()
)
</foreach>
</insert>
<select id="listTotalData" parameterType="com.gic.haoban.manage.api.dto.qdto.chat.ChatDataSearchQDTO"
......
......@@ -225,12 +225,13 @@
</select>
<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 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
group by wx_enterprise_id , staff_id
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
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 id="list" resultType="com.gic.haoban.manage.api.dto.chat.GroupChatDTO" parameterType="com.gic.haoban.manage.api.dto.qdto.chat.GroupChatSearchQDTO">
......@@ -282,7 +283,7 @@
</if>
<if test="null != searchPage and '' != searchPage ">
<if test="searchPage == 'chatWidget' ">
and a.init_flag = 1
and a.init_flag = 1 and a.wx_chat_id_dk is not null
</if>
</if>
<if test="null != status and 1==status">
......
......@@ -78,6 +78,14 @@
</if>
</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 a.staff_id staffId , b.`staff_name` staffName , a.wx_enterprise_id wxEnterpriseId ,
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