IMGroupService.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using LeaRun.Application.Entity.MessageManage;
  2. using LeaRun.Application.IService.MessageManage;
  3. using LeaRun.Data;
  4. using LeaRun.Data.Repository;
  5. using LeaRun.Util.Extension;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Data.Common;
  10. using System.Text;
  11. namespace LeaRun.Application.Service.MessageManage
  12. {
  13. /// <summary>
  14. /// 版 本 V6.1
  15. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  16. /// 创建人:陈彬彬
  17. /// 日 期:2015.11.26 19:39
  18. /// 描 述:即时通信群组管理
  19. /// </summary>
  20. public class IMGroupService : RepositoryFactory, IMsgGroupService
  21. {
  22. /// <summary>
  23. /// 获取群组列表(即时通信)
  24. /// </summary>
  25. /// <returns></returns>
  26. public IEnumerable<IMGroupModel> GetList(string userId)
  27. {
  28. var strSql = new StringBuilder();
  29. strSql.Append(@"SELECT g.GroupId ,
  30. g.FullName AS GroupName ,
  31. u.UserId ,
  32. u.UserGroupId
  33. FROM IM_UserGroup u
  34. LEFT JOIN IM_Group g ON u.GroupId = g.GroupId
  35. WHERE 1 = 1");
  36. var parameter = new List<DbParameter>();
  37. //公司主键
  38. if (!userId.IsEmpty())
  39. {
  40. strSql.Append(" AND u.UserId = @UserId");
  41. parameter.Add(DbParameters.CreateDbParameter("@UserId", userId));
  42. }
  43. return this.BaseRepository().FindList<IMGroupModel>(strSql.ToString(), parameter.ToArray());
  44. }
  45. /// <summary>
  46. /// 获取群组里面的用户Id
  47. /// </summary>
  48. /// <param name="groupId"></param>
  49. /// <returns></returns>
  50. public DataTable GetUserIdList(string groupId)
  51. {
  52. var strSql = new StringBuilder();
  53. strSql.Append(@"SELECT t.GroupId ,
  54. t.UserId
  55. FROM IM_UserGroup t
  56. WHERE 1 = 1");
  57. var parameter = new List<DbParameter>();
  58. //群组Id
  59. if (!groupId.IsEmpty())
  60. {
  61. strSql.Append(" AND u.GroupId = @GroupId");
  62. parameter.Add(DbParameters.CreateDbParameter("@GroupId", groupId));
  63. }
  64. return this.BaseRepository().FindTable(strSql.ToString(), parameter.ToArray());
  65. }
  66. #region 提交数据
  67. /// <summary>
  68. /// 保存群组信息
  69. /// </summary>
  70. /// <param name="keyValue"></param>
  71. /// <param name="entity"></param>
  72. public void Save(string keyValue, IMGroupEntity entity,List<string> userIdList)
  73. {
  74. if (!string.IsNullOrEmpty(keyValue))
  75. {
  76. entity.Modify(keyValue);
  77. this.BaseRepository().Update<IMGroupEntity>(entity);
  78. }
  79. else
  80. {
  81. IDatabase db = DbFactory.Base().BeginTrans();
  82. try
  83. {
  84. entity.Create();
  85. db.Insert<IMGroupEntity>(entity);
  86. foreach (string userOne in userIdList)
  87. {
  88. IMUserGroupEntity msgusergroupentity = new IMUserGroupEntity();
  89. msgusergroupentity.GroupId = entity.GroupId;
  90. msgusergroupentity.UserId = userOne;
  91. msgusergroupentity.CreateUserId = entity.CreateUserId;
  92. msgusergroupentity.CreateUserName = entity.CreateUserName;
  93. db.Insert<IMUserGroupEntity>(msgusergroupentity);
  94. }
  95. db.Commit();
  96. }
  97. catch (Exception)
  98. {
  99. db.Rollback();
  100. throw;
  101. }
  102. }
  103. }
  104. /// <summary>
  105. /// 删除群组里的一个联系人
  106. /// </summary>
  107. /// <param name="UserGroupId"></param>
  108. public void RemoveUserId(string UserGroupId)
  109. {
  110. string keyValue = UserGroupId;
  111. this.BaseRepository().Delete<IMUserGroupEntity>(keyValue);
  112. }
  113. /// <summary>
  114. /// 群里增加一个用户
  115. /// </summary>
  116. /// <param name="entity"></param>
  117. public void AddUserId(IMUserGroupEntity entity)
  118. {
  119. entity.Create();
  120. this.BaseRepository().Insert<IMUserGroupEntity>(entity);
  121. }
  122. #endregion
  123. }
  124. }