Commit f3797a47 by 徐高华

parent 722b42bf
......@@ -9,6 +9,7 @@ public class ChatEventDTO implements Serializable {
*/
private static final long serialVersionUID = -155687993581919178L;
private String changeType;
private String chatId;
private String updateDetail;
private Integer joinScene;
......@@ -16,6 +17,14 @@ public class ChatEventDTO implements Serializable {
private Integer memChangeCnt;
private String corpid;
public String getChangeType() {
return changeType;
}
public void setChangeType(String changeType) {
this.changeType = changeType;
}
public String getChatId() {
return chatId;
}
......
package com.gic.haoban.manage.api.service.chat;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.chat.ChatEventDTO;
public interface GroupChatApiService {
......@@ -12,6 +13,6 @@ public interface GroupChatApiService {
* @param dto
* @throws
*/
public void qwEventNotice(ChatEventDTO dto);
public ServiceResponse<Void> qwEventNotice(ChatEventDTO dto);
}
package com.gic.haoban.manage.service.dao.mapper;
import com.gic.haoban.manage.api.dto.ExternalClerkRelatedDTO;
import com.gic.haoban.manage.service.entity.TabHaobanExternalClerkRelated;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.gic.haoban.manage.api.dto.ExternalClerkRelatedDTO;
import com.gic.haoban.manage.service.entity.TabHaobanExternalClerkRelated;
import com.github.pagehelper.Page;
public interface TabHaobanExternalClerkRelatedMapper {
int insertSelective(TabHaobanExternalClerkRelated record);
......@@ -384,5 +385,11 @@ public interface TabHaobanExternalClerkRelatedMapper {
void updateClerkInfo(@Param("staffId")String staffId, @Param("oldClerkId")String oldClerkId, @Param("newClerkId")String newClerkId, @Param("storeId")String storeId);
int updateExternalStatus(@Param("wxEnterpriseId")String wxEnterpriseId, @Param("externalUserid")String externalUserid, @Param("status")int status);
/**
* 通过第三方或者待开发查询是否好友
*/
TabHaobanExternalClerkRelated getMemberForExternalId(@Param("wxEnterpriseId") String wxEnterpriseId,
@Param("externalUserId") String externalUserId);
}
\ No newline at end of file
......@@ -21,13 +21,17 @@ public interface GroupChatMapper {
public int deleteByPrimaryKey(Long groupChatId);
public int updateByPrimaryKey(TabGroupChat tabHaobanGroupChat);
public int update(TabGroupChat tabHaobanGroupChat);
// 更新群状态
public int updateChatStatus(@Param("groupChatId")Long groupChatId , @Param("chatStatus")int chatStatus) ;
public TabGroupChat selectById(Long groupChatId);
public List<TabGroupChat> listByIdList(@Param("idList")List<String> idList) ;
public TabGroupChat selectByWxChatId(@Param("wxChatId") String wxChatId);
public List<TabGroupChat> listByIdList(@Param("idList") List<String> idList);
public TabGroupChat selectByWxChatId(@Param("wxEnterpriseId") String wxEnterpriseId,
@Param("wxChatId") String wxChatId);
public List<TabGroupChat> listAll(TabGroupChat tabHaobanGroupChat);
}
\ No newline at end of file
package com.gic.haoban.manage.service.dao.mapper.chat;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.gic.haoban.manage.service.entity.chat.TabGroupChatUser;
......@@ -21,10 +19,11 @@ public interface GroupChatUserMapper {
public int deleteByPrimaryKey(Long chatUserId);
public int updateByPrimaryKey(TabGroupChatUser tabHaobanGroupChatUser);
public int update(TabGroupChatUser tabHaobanGroupChatUser);
public TabGroupChatUser selectById(Long chatUserId);
public TabGroupChatUser selectByUserIdAndChatId(@Param("groupChatId")Long groupChatId , @Param("userId")String userId) ;
public TabGroupChatUser selectByUserIdAndChatId(@Param("groupChatId") Long groupChatId,
@Param("userId") String userId);
}
\ No newline at end of file
package com.gic.haoban.manage.service.service.chat;
public interface GroupChatService {
// 解散群
public void dismissChat(String corpid, String wxChatId);
// 创建群
public void createChat(String corpid, String wxChatId);
// 更新同步群信息
public void updateChat(String corpid, String wxChatId ,String updateDetail);
// 初始化企业群
public void initEnterpriseGroupChat(String wxEnterpriseId);
}
\ No newline at end of file
......@@ -19,13 +19,14 @@ import com.gic.haoban.manage.api.dto.SecretSettingDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.enums.SecretTypeEnum;
import com.gic.haoban.manage.service.dao.mapper.StaffMapper;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanExternalClerkRelatedMapper;
import com.gic.haoban.manage.service.dao.mapper.chat.GroupChatMapper;
import com.gic.haoban.manage.service.dao.mapper.chat.GroupChatUserMapper;
import com.gic.haoban.manage.service.entity.TabHaobanExternalClerkRelated;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabHaobanWxEnterprise;
import com.gic.haoban.manage.service.entity.chat.TabGroupChat;
import com.gic.haoban.manage.service.entity.chat.TabGroupChatUser;
import com.gic.haoban.manage.service.service.ExternalClerkRelatedService;
import com.gic.haoban.manage.service.service.SecretSettingService;
import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.service.chat.GroupChatService;
......@@ -37,7 +38,7 @@ import com.gic.wechat.api.dto.qywx.chat.GroupChatListDTO;
import com.gic.wechat.api.dto.qywx.chat.GroupChatListItemDTO;
import com.gic.wechat.api.service.qywx.QywxChatApiService;
@Service
@Service("groupChatService")
public class GroupChatServiceImpl implements GroupChatService {
private static final Logger logger = LoggerFactory.getLogger(GroupChatService.class);
......@@ -53,13 +54,64 @@ public class GroupChatServiceImpl implements GroupChatService {
@Autowired
private MemberService memberService;
@Autowired
private ExternalClerkRelatedService externalClerkRelatedService;
private TabHaobanExternalClerkRelatedMapper externalClerkRelatedMapper;
@Autowired
private StaffMapper staffMapper;
@Autowired
private SecretSettingService secretSettingService;
public void initGroupChat(String wxEnterpriseId) {
@Override
public void createChat(String corpid, String wxChatId) {
String wxEnterpriseId = this.getWxEnterpriesId(corpid);
if (null == wxEnterpriseId) {
return;
}
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
this.insertGroupChat(qwDTO, wxChatId, 0, false);
}
@Override
public void dismissChat(String corpid, String wxChatId) {
String wxEnterpriseId = this.getWxEnterpriesId(corpid);
if (null == wxEnterpriseId) {
return;
}
TabGroupChat groupChat = this.groupChatMapper.selectByWxChatId(wxEnterpriseId, wxChatId);
if (null == groupChat) {
logger.info("群查不到,wxChatid={}", wxChatId);
return;
}
this.groupChatMapper.updateChatStatus(groupChat.getGroupChatId(), 4);
}
@Override
public void updateChat(String corpid, String wxChatId, String updateDetail) {
String wxEnterpriseId = this.getWxEnterpriesId(corpid);
if (null == wxEnterpriseId) {
return;
}
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
if (null == qwDTO) {
logger.info("wxEnterpriseId不存在,id={}", wxEnterpriseId);
return;
}
TabGroupChat groupChat = this.groupChatMapper.selectByWxChatId(qwDTO.getWxEnterpriseId(), wxChatId);
// change_name=群名变更change_notice=群公告变更
if ("change_name".equals(updateDetail) || "change_notice".equals(updateDetail)) {
this.initGroupChatDetail(qwDTO, groupChat, false);
}
// change_owner=群主变更
if ("change_owner".equals(updateDetail)) {
}
// add_member=成员入群 del_member=成员退群
if ("add_member".equals(updateDetail) || "del_member".equals(updateDetail)) {
}
}
@Override
public void initEnterpriseGroupChat(String wxEnterpriseId) {
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
if (null == qwDTO) {
logger.info("wxEnterpriseId不存在,id={}", wxEnterpriseId);
......@@ -83,13 +135,14 @@ public class GroupChatServiceImpl implements GroupChatService {
.map(dto -> dto.getWxUserId()).collect(Collectors.toList());
}
if (CollectionUtils.isNotEmpty(userIdList)) {
this.saveGroupChat(qwDTO, userIdList, null);
this.syncGroupChat(qwDTO, userIdList, null);
}
pageNum++;
}
}
public void saveGroupChat(WxEnterpriseQwDTO qwDTO, List<String> userIdList, String cursor) {
// 同步成员的群
private void syncGroupChat(WxEnterpriseQwDTO qwDTO, List<String> userIdList, String cursor) {
logger.info("qwDTO={},idlist={},cursor={}", JSON.toJSONString(qwDTO), JSON.toJSONString(userIdList), cursor);
int limit = 1;
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(qwDTO.getWxEnterpriseId(),
......@@ -109,42 +162,49 @@ public class GroupChatServiceImpl implements GroupChatService {
List<GroupChatListItemDTO> list = dto.getGroup_chat_list();
for (GroupChatListItemDTO item : list) {
String wxChatId = item.getChat_id();
TabGroupChat groupChat = this.groupChatMapper.selectByWxChatId(wxChatId);
Long groupChatId = null;
if (null != groupChat) {
groupChatId = groupChat.getGroupChatId();
logger.info("群已存在,chatid={},groupChatId={}", wxChatId, groupChatId);
} else {
groupChatId = UniqueIdUtils.uniqueLong();
TabGroupChat chat = new TabGroupChat();
chat.setGroupChatId(groupChatId);
chat.setWxEnterpriseId(qwDTO.getWxEnterpriseId());
chat.setWxChatId(wxChatId);
chat.setChatStatus(item.getStatus());
chat.setCreateTime(new Date());
chat.setUpdateTime(new Date());
chat.setStatusFlag(0);
chat.setDeleteFlag(0);
chat.setTotalCount(0);
chat.setTotalMemberCount(0);
chat.setAddMemberCount(0);
chat.setAddCount(0);
chat.setQuitCount(0);
chat.setQuitMemberCount(0);
this.groupChatMapper.insert(chat);
}
this.groupChatDetailInit(groupChatId);
int chatStatus = item.getStatus();
this.insertGroupChat(qwDTO, wxChatId, chatStatus, true);
}
if (org.apache.commons.lang3.StringUtils.isNotBlank(cursor)) {
this.saveGroupChat(qwDTO, userIdList, cursor);
this.syncGroupChat(qwDTO, userIdList, cursor);
}
}
public void groupChatDetailInit(Long groupChatId) {
TabGroupChat chat = this.groupChatMapper.selectById(groupChatId);
// 新增群记录
private void insertGroupChat(WxEnterpriseQwDTO qwDTO, String wxChatId, int chatStatus, boolean syncDetailFlag) {
TabGroupChat groupChat = this.groupChatMapper.selectByWxChatId(qwDTO.getWxEnterpriseId(), wxChatId);
Long groupChatId = null;
if (null != groupChat) {
groupChatId = groupChat.getGroupChatId();
logger.info("群已存在,chatid={},groupChatId={}", wxChatId, groupChatId);
} else {
groupChatId = UniqueIdUtils.uniqueLong();
TabGroupChat chat = new TabGroupChat();
chat.setGroupChatId(groupChatId);
chat.setWxEnterpriseId(qwDTO.getWxEnterpriseId());
chat.setWxChatId(wxChatId);
chat.setChatStatus(chatStatus);
chat.setCreateTime(new Date());
chat.setUpdateTime(new Date());
chat.setStatusFlag(0);
chat.setDeleteFlag(0);
chat.setTotalCount(0);
chat.setTotalMemberCount(0);
chat.setAddMemberCount(0);
chat.setAddCount(0);
chat.setQuitCount(0);
chat.setQuitMemberCount(0);
this.groupChatMapper.insert(chat);
}
if (syncDetailFlag) {
this.initGroupChatDetail(qwDTO, groupChatId, true);
}
}
private void initGroupChatDetail(WxEnterpriseQwDTO qwDTO, TabGroupChat chat, boolean syncMember) {
Long groupChatId = chat.getGroupChatId();
String wxEnterpriseId = chat.getWxEnterpriseId();
String enterpriseId = chat.getEnterpriseId();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
SecretSettingDTO secretSetting = secretSettingService.getSecretSetting(qwDTO.getWxEnterpriseId(),
SecretTypeEnum.CUSTOMIZED_APP.getVal());
if (null == secretSetting) {
......@@ -167,8 +227,11 @@ public class GroupChatServiceImpl implements GroupChatService {
}
chat.setStaffId(staff.getStaffId());
logger.info("更新群信息={}", JSON.toJSONString(chat));
this.groupChatMapper.updateByPrimaryKey(chat);
this.groupChatMapper.update(chat);
if (!syncMember) {
logger.info("不同步群会员信息");
return;
}
List<GroupChatDetailMemberDTO> memberList = detail.getMember_list();
List<TabGroupChatUser> userList = new ArrayList<>();
for (GroupChatDetailMemberDTO member : memberList) {
......@@ -177,7 +240,7 @@ public class GroupChatServiceImpl implements GroupChatService {
if (null != user) {
logger.info("更新用户");
this.matchGicMember(wxEnterpriseId, enterpriseId, member.getUnionid(), userId, user);
this.groupChatUserMapper.updateByPrimaryKey(user);
this.groupChatUserMapper.update(user);
continue;
}
user = new TabGroupChatUser();
......@@ -207,6 +270,13 @@ public class GroupChatServiceImpl implements GroupChatService {
}
}
// 初始化群信息-不包括群状态
private void initGroupChatDetail(WxEnterpriseQwDTO qwDTO, Long groupChatId, boolean syncMember) {
TabGroupChat chat = this.groupChatMapper.selectById(groupChatId);
this.initGroupChatDetail(qwDTO, chat, syncMember);
}
// 匹配群成员-客户
private void matchGicMember(String wxEnterpriseId, String enterpriseId, String unionid, String externalUserId,
TabGroupChatUser user) {
if (StringUtils.isBlank(enterpriseId)) {
......@@ -219,14 +289,22 @@ public class GroupChatServiceImpl implements GroupChatService {
user.setUserType(3);
}
} else if (StringUtils.isNotBlank(externalUserId)) {
List<TabHaobanExternalClerkRelated> list = this.externalClerkRelatedService
.listExternalByExternalUserid(wxEnterpriseId, externalUserId);
list = list.stream().filter(dto -> StringUtils.isNotBlank(dto.getMemberId())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(list)) {
user.setMemberId(list.get(0).getMemberId());
TabHaobanExternalClerkRelated related = this.externalClerkRelatedMapper
.getMemberForExternalId(wxEnterpriseId, externalUserId);
if (null != related) {
user.setMemberId(related.getMemberId());
user.setUserType(3);
}
}
}
private String getWxEnterpriesId(String corpid) {
TabHaobanWxEnterprise wxEnterprise = this.wxEnterpriseService.getEnterpriseBycorpId(corpid);
if (wxEnterprise == null) {
logger.info("企业不存在,corpid={}", corpid);
return null;
}
return wxEnterprise.getWxEnterpriseId();
}
}
\ No newline at end of file
......@@ -2,20 +2,40 @@ package com.gic.haoban.manage.service.service.out.impl.chat;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.chat.ChatEventDTO;
import com.gic.haoban.manage.api.service.chat.GroupChatApiService;
import com.gic.haoban.manage.service.service.chat.GroupChatService;
@Service("groupChatApiService")
public class GroupChatApiServiceImpl implements GroupChatApiService {
private static final Logger logger = LogManager.getLogger(GroupChatApiService.class);
@Autowired
private GroupChatService groupChatService;
@Override
public void qwEventNotice(ChatEventDTO dto) {
logger.info("群事件,params={}", JSON.toJSONString(dto));
public ServiceResponse<Void> qwEventNotice(ChatEventDTO dto) {
logger.info("收到群事件,params={}", JSON.toJSONString(dto));
String changeType = dto.getChangeType();
String wxChatId = dto.getChatId();
String corpid = dto.getCorpid();
// 群解散事件
if ("dismiss".equals(changeType)) {
this.groupChatService.dismissChat(corpid, wxChatId);
} else if ("create".equals(changeType)) {
// 创建群
this.groupChatService.createChat(corpid, wxChatId);
} else {
String updateDetail = dto.getUpdateDetail();
this.groupChatService.updateChat(corpid, wxChatId, updateDetail);
}
return ServiceResponse.success();
}
}
......@@ -754,5 +754,16 @@
update tab_haoban_external_clerk_related set external_status = #{status} where
external_user_id = #{externalUserid} and wx_enterprise_id = #{wxEnterpriseId}
</update>
<select id="getMemberForExternalId" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from tab_haoban_external_clerk_related where wx_enterprise_id = #{wxEnterpriseId}
and self_external_userid = #{externalUserId} and status_flag = 1 and member_id <![CDATA[ <> '' ]]>
union
select <include refid="Base_Column_List"/>
from tab_haoban_external_clerk_related where wx_enterprise_id = #{wxEnterpriseId}
and external_user_id = #{externalUserId} and status_flag = 1 and member_id <![CDATA[ <> '' ]]>
limit 1
</select>
</mapper>
\ No newline at end of file
......@@ -105,24 +105,32 @@
<!-- ==================更新 ========== -->
<update id="updateByPrimaryKey"
<update id="update"
parameterType="com.gic.haoban.manage.service.entity.chat.TabGroupChat">
<![CDATA[
UPDATE tab_haoban_group_chat SET
group_chat_id=#{groupChatId,jdbcType=BIGINT},
wx_enterprise_id=#{wxEnterpriseId,jdbcType=CHAR},
name=#{name,jdbcType=VARCHAR},
staff_id=#{staffId,jdbcType=CHAR},
chat_add_time=#{chatAddTime,jdbcType=TIMESTAMP},
chat_dissolve_time=#{chatDissolveTime,jdbcType=TIMESTAMP},
chat_notice=#{chatNotice,jdbcType=VARCHAR},
chat_status=#{chatStatus,jdbcType=INTEGER},
update_time=now(),
enterprise_id=#{enterpriseId,jdbcType=CHAR},
status_flag=#{statusFlag,jdbcType=INTEGER}
where group_chat_id = #{groupChatId}
<![CDATA[
UPDATE tab_haoban_group_chat SET
group_chat_id=#{groupChatId,jdbcType=BIGINT},
name=#{name,jdbcType=VARCHAR},
staff_id=#{staffId,jdbcType=CHAR},
chat_add_time=#{chatAddTime,jdbcType=TIMESTAMP},
chat_dissolve_time=#{chatDissolveTime,jdbcType=TIMESTAMP},
chat_notice=#{chatNotice,jdbcType=VARCHAR},
chat_status=#{chatStatus,jdbcType=INTEGER},
update_time=now(),
status_flag=#{statusFlag,jdbcType=INTEGER}
where group_chat_id = #{groupChatId}
]]>
</update>
<update id="updateChatStatus">
update tab_haoban_group_chat set chat_status = #{chatStatus} ,
<if test="chatStatus==4">
and chat_dissolve_time = now()
</if>
update_time =now() where group_chat_id = #{groupChatId}
</update>
<!-- ============ 查询============= -->
<select id="selectById" parameterType="long"
......@@ -132,21 +140,23 @@
FROM tab_haoban_group_chat WHERE group_chat_id = #{groupChatId} and
delete_flag = 0
</select>
<select id="listByIdList" resultMap="result-map-tabHaobanGroupChat">
SELECT
<include refid="Base_Column_List" />
FROM tab_haoban_group_chat WHERE group_chat_id in
<foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
and delete_flag = 0
FROM tab_haoban_group_chat WHERE group_chat_id in
<foreach collection="idList" item="id" index="index" open="("
close=")" separator=",">
#{id}
</foreach>
and delete_flag = 0
</select>
<select id="selectByWxChatId" resultMap="result-map-tabHaobanGroupChat">
select
<include refid="Base_Column_List" />
FROM tab_haoban_group_chat WHERE wx_chat_id = #{wxChatId} and
wx_enterprise_id = #{wxEnterpriseId}
delete_flag = 0
</select>
......
......@@ -105,12 +105,9 @@
<!-- ==================更新 ========== -->
<update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.chat.TabGroupChatUser">
<update id="update" parameterType="com.gic.haoban.manage.service.entity.chat.TabGroupChatUser">
<![CDATA[
UPDATE tab_haoban_group_chat_user SET
chat_user_id=#{chatUserId,jdbcType=BIGINT},
wx_enterprise_id=#{wxEnterpriseId,jdbcType=CHAR},
enterprise_id=#{enterpriseId,jdbcType=CHAR},
user_type=#{userType,jdbcType=INTEGER},
join_time=#{joinTime,jdbcType=DATE},
user_name=#{userName,jdbcType=VARCHAR},
......@@ -119,7 +116,7 @@
unionid=#{unionid,jdbcType=VARCHAR},
member_id=#{memberId,jdbcType=VARCHAR},
invitor_user_id=#{invitorUserId,jdbcType=VARCHAR},
update_time=#{updateTime,jdbcType=TIMESTAMP},
update_time=now(),
group_chat_id=#{groupChatId,jdbcType=BIGINT},
status_flag=#{statusFlag,jdbcType=INTEGER},
user_quit_time=#{userQuitTime,jdbcType=TIMESTAMP},
......
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