QwGroupMsgMapper.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package com.fs.qw.mapper;
  2. import com.fs.qw.domain.QwGroupMsg;
  3. import com.fs.qw.param.QwGroupMsgDetailsParam;
  4. import com.fs.qw.vo.QwGroupMsgDetailsVO;
  5. import com.fs.qw.vo.QwGroupMsgVO;
  6. import org.apache.ibatis.annotations.Param;
  7. import org.apache.ibatis.annotations.Select;
  8. import org.springframework.stereotype.Repository;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. /**
  12. * 客户群发记录主Mapper接口
  13. *
  14. * @author fs
  15. * @date 2024-06-20
  16. */
  17. @Repository
  18. public interface QwGroupMsgMapper
  19. {
  20. /**
  21. * 查询客户群发记录主
  22. *
  23. * @param id 客户群发记录主主键
  24. * @return 客户群发记录主
  25. */
  26. public QwGroupMsg selectQwGroupMsgById(Long id);
  27. @Select("SELECT qgm.*,gmi.* FROM qw_group_msg qgm left join qw_group_msg_item gmi on qgm.id=gmi.group_msg_id " +
  28. "where qgm.id=#{id}")
  29. public QwGroupMsgVO selectQwGroupMsgByIdVO(@Param("id") Long id);
  30. /**
  31. * 查询客户群发记录主列表
  32. *
  33. * @param qwGroupMsg 客户群发记录主
  34. * @return 客户群发记录主集合
  35. */
  36. @Select("<script> " +
  37. "select gm.*, gmt.msg_type from qw_group_msg gm left join qw_group_msg_item gmt on gm.id=gmt.group_msg_id " +
  38. "<where>" +
  39. "<if test='map.msgid != null and map.msgid != \"\" '> and gm.msgid = #{map.msgid}</if> " +
  40. "<if test='map.chatType != null and map.chatType != \"\" '> and gm.chat_type = #{map.chatType}</if> " +
  41. "<if test='map.selectType != null and map.selectType != \"\" '> and gm.select_type = #{map.selectType}</if> " +
  42. "<if test='map.sender != null and map.sender != \"\" '> and gm.sender = #{map.sender}</if> " +
  43. "<if test='map.allowSelect != null and map.allowSelect !=\"\" '> and gm.allow_select = #{map.allowSelect}</if> " +
  44. "<if test='map.textContent != null and map.textContent != \"\" '> and gm.text_content like concat( #{map.textContent}, '%')</if> " +
  45. "<if test='map.corpId != null and map.corpId != \"\" '> and gm.corp_id = #{map.corpId}</if> " +
  46. "<if test='map.companyId != null '> and gm.company_id = #{map.companyId}</if> " +
  47. "<if test='map.tagNames != null and map.tagNames != \"\" '> and gm.tag_names like concat(#{map.tagNames}, '%')</if> " +
  48. "<if test='map.groupChatNames != null and map.groupChatNames != \"\" '> and gm.group_chat_names like concat( #{map.groupChatNames}, '%')</if> " +
  49. "<if test='map.fromUserCount != null '> and gm.from_user_count = #{map.fromUserCount}</if> " +
  50. "<if test='map.toUserCount != null '> and gm.to_user_count = #{map.toUserCount}</if> " +
  51. "<if test='map.fromUserNum != null '> and gm.from_user_num = #{map.fromUserNum}</if> " +
  52. "<if test='map.toUserNum != null '> and gm.to_user_num = #{map.toUserNum}</if> " +
  53. "<if test='map.createName != null and map.createName != \"\" '> and gm.create_name like concat( #{map.createName}, '%')</if> " +
  54. "<if test='map.isSend != null '> and gm.is_send = #{map.isSend}</if> " +
  55. "</where> " +
  56. "order by gm.create_time desc"+
  57. "</script>")
  58. public List<QwGroupMsgVO> selectQwGroupMsgListVO(@Param("map") QwGroupMsg qwGroupMsg);
  59. @Select("<script> " +
  60. "select gm.*, gmt.msg_type from qw_group_msg gm " +
  61. "left join qw_group_msg_item gmt on gm.id=gmt.group_msg_id " +
  62. "left join qw_user qu ON FIND_IN_SET(qu.qw_user_id,REPLACE(REPLACE(REPLACE(gm.sender, '[', ''), ']', ''), ' ', '')) > 0" +
  63. "<where>" +
  64. "<if test='map.msgid != null and map.msgid != \"\" '> and gm.msgid = #{map.msgid}</if> " +
  65. "<if test='map.chatType != null and map.chatType != \"\" '> and gm.chat_type = #{map.chatType}</if> " +
  66. "<if test='map.selectType != null and map.selectType != \"\" '> and gm.select_type = #{map.selectType}</if> " +
  67. "<if test='map.sender != null and map.sender != \"\" '> and gm.sender = #{map.sender}</if> " +
  68. "<if test='map.allowSelect != null and map.allowSelect !=\"\" '> and gm.allow_select = #{map.allowSelect}</if> " +
  69. "<if test='map.textContent != null and map.textContent != \"\" '> and gm.text_content like concat('%', #{map.textContent}, '%')</if> " +
  70. "<if test='map.corpId != null and map.corpId != \"\" '> and gm.corp_id = #{map.corpId}</if> " +
  71. "<if test='map.companyId != null '> and gm.company_id = #{map.companyId}</if> " +
  72. "<if test='map.tagNames != null and map.tagNames != \"\" '> and gm.tag_names like concat('%', #{map.tagNames}, '%')</if> " +
  73. "<if test='map.groupChatNames != null and map.groupChatNames != \"\" '> and gm.group_chat_names like concat('%', #{map.groupChatNames}, '%')</if> " +
  74. "<if test='map.fromUserCount != null '> and gm.from_user_count = #{map.fromUserCount}</if> " +
  75. "<if test='map.toUserCount != null '> and gm.to_user_count = #{map.toUserCount}</if> " +
  76. "<if test='map.fromUserNum != null '> and gm.from_user_num = #{map.fromUserNum}</if> " +
  77. "<if test='map.toUserNum != null '> and gm.to_user_num = #{map.toUserNum}</if> " +
  78. "<if test='map.createName != null and map.createName != \"\" '> and gm.create_name like concat('%', #{map.createName}, '%')</if> " +
  79. "<if test='map.isSend != null '> and gm.is_send = #{map.isSend}</if> " +
  80. "<if test='map.companyUserId != null '> and qu.company_user_id = #{map.companyUserId}</if> " +
  81. "</where> " +
  82. "order by gm.create_time desc"+
  83. "</script>")
  84. public List<QwGroupMsgVO> selectQwGroupMsgListMyVO(@Param("map") QwGroupMsg qwGroupMsg);
  85. @Select("<script> " +
  86. " SELECT " +
  87. " cu.nick_name, ec.NAME, ec.avatar, mu.* " +
  88. "<if test='map.chatType == \"group\" '> " +
  89. " , qgc.name as chatName " +
  90. "</if> " +
  91. "FROM " +
  92. " qw_group_msg_user mu " +
  93. " LEFT JOIN qw_user qu ON mu.user_id = qu.qw_user_id and mu.corp_id=qu.corp_id " +
  94. " LEFT JOIN company_user cu ON qu.company_user_id = cu.user_id " +
  95. " LEFT JOIN qw_external_contact ec ON mu.external_userid = ec.external_user_id and mu.corp_id=ec.corp_id " +
  96. " AND mu.user_id = ec.user_id " +
  97. "<if test='map.chatType == \"group\" '> " +
  98. " LEFT JOIN qw_group_chat qgc ON mu.chat_id = qgc.chat_id and mu.user_id=qgc.owner and mu.corp_id=qgc.corp_id " +
  99. "</if> " +
  100. "WHERE 1=1 and " +
  101. " mu.group_msg_id = #{map.msgId} " +
  102. "<if test='map.nickName != null and map.nickName != \"\" '> " +
  103. "and cu.nick_name like concat( #{map.nickName}, '%') " +
  104. "</if> " +
  105. " <if test='map.chatType == \"group\" and map.chatName != null and map.chatName != \"\" '> " +
  106. "and qgc.name like concat('%', #{map.chatName}, '%') " +
  107. "</if> " +
  108. " <if test='map.name != null and map.name != \"\" '> " +
  109. "and ec.name like concat('%', #{map.name}, '%') " +
  110. "</if> " +
  111. " <if test='map.status != null '> " +
  112. "and mu.status = #{map.status} " +
  113. "</if> " +
  114. " <if test='map.sendStatus != null '> " +
  115. "and mu.send_status = #{map.sendStatus} " +
  116. "</if> " +
  117. " <if test='map.chatType != null and map.chatType != \"\" '> " +
  118. "and mu.chat_type = #{map.chatType} " +
  119. "</if> " +
  120. "</script>")
  121. public List<QwGroupMsgDetailsVO> getCountGroupMsgUserDetails(@Param("map") QwGroupMsgDetailsParam qwGroupMsgDetailsParam);
  122. /** 统计数据详情,已发送,未发送,已接收,未接收等 */
  123. @Select("SELECT " +
  124. " COALESCE(SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END), 0) AS '未发送成员', " +
  125. " COALESCE(SUM(CASE WHEN send_status = '0' THEN 1 ELSE 0 END), 0) AS '未送达客户', " +
  126. " COALESCE(SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END), 0) AS '已发送成员', " +
  127. " COALESCE(SUM(CASE WHEN send_status = '1' THEN 1 ELSE 0 END), 0) AS '送达客户', " +
  128. " COALESCE(SUM(CASE WHEN send_status = '2' THEN 1 ELSE 0 END), 0) AS '不是好友发送失败', " +
  129. " COALESCE(SUM(CASE WHEN send_status = '3' THEN 1 ELSE 0 END), 0) AS '接收已达上限' " +
  130. "FROM qw_group_msg_user where group_msg_id=#{groupMsgId}")
  131. public HashMap<String,Integer> getCountGroupMsgUser(@Param("groupMsgId") Long groupMsgId);
  132. @Select("SELECT " +
  133. " COALESCE(SUM(CASE WHEN status = 0 THEN 1 ELSE 0 END), 0) AS '未发送群主', " +
  134. " COALESCE(SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END), 0) AS '已发送群主', " +
  135. " COALESCE(SUM(CASE WHEN send_status = '1' THEN 1 ELSE 0 END), 0) AS '送达群聊' " +
  136. "FROM qw_group_msg_user where group_msg_id=#{groupMsgId}")
  137. public HashMap<String,Integer> getCountGroupMsgBaseUser(@Param("groupMsgId") Long groupMsgId);
  138. /**
  139. * 新增客户群发记录主
  140. *
  141. * @param qwGroupMsg 客户群发记录主
  142. * @return 结果
  143. */
  144. public int insertQwGroupMsg(QwGroupMsg qwGroupMsg);
  145. /**
  146. * 修改客户群发记录主
  147. *
  148. * @param qwGroupMsg 客户群发记录主
  149. * @return 结果
  150. */
  151. public int updateQwGroupMsg(QwGroupMsg qwGroupMsg);
  152. /**
  153. * 删除客户群发记录主
  154. *
  155. * @param id 客户群发记录主主键
  156. * @return 结果
  157. */
  158. public int deleteQwGroupMsgById(Long id);
  159. /**
  160. * 批量删除客户群发记录主
  161. *
  162. * @param ids 需要删除的数据主键集合
  163. * @return 结果
  164. */
  165. public int deleteQwGroupMsgByIds(Long[] ids);
  166. @Select("SELECT qgm.*,gmi.id as itemId, gmi.group_msg_id, gmi.msg_id, gmi.msg_type, gmi.media_id, gmi.media_pic_url, gmi.title, " +
  167. "gmi.picurl, gmi.description, gmi.url, gmi.miniprogram_pic_media_id, gmi.miniprogram_pic_url, gmi.miniprogram_appid, " +
  168. "gmi.miniprogram_title, gmi.miniprogram_page, gmi.video_media_id, gmi.video_url, gmi.file_media_id, gmi.file_url " +
  169. "FROM qw_group_msg qgm " +
  170. "LEFT JOIN qw_group_msg_item gmi ON qgm.id = gmi.group_msg_id " +
  171. "WHERE " +
  172. "qgm.is_send = 3 " +
  173. "AND qgm.is_timer_send = 1 " +
  174. "AND timer_send <= NOW()")
  175. public List<QwGroupMsgVO> getQwGroupMsgTask();
  176. }