CommonSqlKataService.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using GxPress.Service.Interface.CommonSqlKata;
  2. namespace GxPress.Service.Implement.CommonSqlKataService
  3. {
  4. public class CommonSqlKataService : ICommonSqlKataService
  5. {
  6. /// <summary>
  7. /// 通用
  8. /// </summary>
  9. /// <param name="noticeTypeValue"></param>
  10. /// <param name="userId"></param>
  11. /// <param name="query"></param>
  12. /// <returns></returns>
  13. public SqlKata.Query GetCommonQueryAsync(int noticeTypeValue, int userId, SqlKata.Query query)
  14. {
  15. var PraiseCount = new SqlKata.Query("tede_analyze");
  16. PraiseCount.WhereColumns("tede_analyze.SourceId", "=", "tede_middle.MiddleId");
  17. PraiseCount.Where("tede_analyze.TypeValue", noticeTypeValue);
  18. PraiseCount.Where("tede_analyze.AnalyzeType", 1);
  19. PraiseCount.AsCount();
  20. query.Select(PraiseCount, "PraiseCount");
  21. var IsLaud = new SqlKata.Query("tede_analyze");
  22. IsLaud.WhereColumns("tede_analyze.SourceId", "=", "tede_middle.MiddleId");
  23. IsLaud.Where("tede_analyze.TypeValue", noticeTypeValue);
  24. IsLaud.Where("tede_analyze.UserId", userId);
  25. IsLaud.Where("tede_analyze.AnalyzeType", 1);
  26. IsLaud.Limit(1);
  27. IsLaud.AsCount();
  28. query.Select(IsLaud, "IsLaud");
  29. var CommentCount = new SqlKata.Query("tede_comment");
  30. CommentCount.WhereColumns("tede_comment.ArticleId", "=", "tede_middle.MiddleId");
  31. CommentCount.Where("tede_comment.pid", 0);
  32. CommentCount.Where("tede_comment.TypeValue", noticeTypeValue);
  33. CommentCount.AsCount();
  34. query.Select(CommentCount, "CommentCount");
  35. var RetransmissionCount = new SqlKata.Query("tede_analyze");
  36. RetransmissionCount.WhereColumns("tede_analyze.SourceId", "=", "tede_middle.MiddleId");
  37. RetransmissionCount.Where("tede_analyze.TypeValue", noticeTypeValue);
  38. RetransmissionCount.Where("tede_analyze.UserId", userId);
  39. RetransmissionCount.Where("tede_analyze.AnalyzeType", 4);
  40. RetransmissionCount.AsCount();
  41. query.Select(RetransmissionCount, "RetransmissionCount");
  42. var IsRetransmission = new SqlKata.Query("tede_analyze");
  43. IsRetransmission.WhereColumns("tede_analyze.SourceId", "=", "tede_middle.MiddleId");
  44. IsRetransmission.Where("tede_analyze.TypeValue", noticeTypeValue);
  45. IsRetransmission.Where("tede_analyze.UserId", userId);
  46. IsRetransmission.Where("tede_analyze.AnalyzeType", 4);
  47. IsRetransmission.Limit(1);
  48. IsRetransmission.AsCount();
  49. query.Select(IsRetransmission, "IsRetransmission");
  50. var IsCollect = new SqlKata.Query("tede_analyze");
  51. IsCollect.WhereColumns("tede_analyze.SourceId", "=", "tede_middle.MiddleId");
  52. IsCollect.Where("tede_analyze.TypeValue", noticeTypeValue);
  53. IsCollect.Where("tede_analyze.UserId", userId);
  54. IsCollect.Where("tede_analyze.AnalyzeType", 3);
  55. IsCollect.Limit(1);
  56. IsCollect.AsCount();
  57. query.Select(IsCollect, "IsCollect");
  58. var CollectCount = new SqlKata.Query("tede_analyze");
  59. CollectCount.WhereColumns("tede_analyze.SourceId", "=", "tede_middle.MiddleId");
  60. CollectCount.Where("tede_analyze.TypeValue", noticeTypeValue);
  61. CollectCount.Where("tede_analyze.UserId", userId);
  62. CollectCount.Where("tede_analyze.AnalyzeType", 3);
  63. CollectCount.AsCount();
  64. query.Select(CollectCount, "CollectCount");
  65. return query;
  66. }
  67. /// <summary>
  68. /// 收件箱
  69. /// </summary>
  70. /// <param name="query"></param>
  71. /// <returns></returns>
  72. public SqlKata.Query NoticeQueryAsync(SqlKata.Query query, int userId)
  73. {
  74. var enjoyUser = new SqlKata.Query("tede_user_middle");
  75. enjoyUser.Where("MiddleType", 10);
  76. enjoyUser.WhereColumns("DataSourceId", "=", "tede_middle.MiddleId");
  77. enjoyUser.SelectRaw("GROUP_CONCAT(SourceName Separator'、')");
  78. query.Select(enjoyUser, "EnjoyUser");
  79. var flowUserName = new SqlKata.Query("tede_user");
  80. flowUserName.SelectRaw("GROUP_CONCAT(Name Separator'、')");
  81. var flowTodo = new SqlKata.Query("tede_flow_todo");
  82. flowTodo.WhereColumns("tede_flow_todo.FlowId", "=", "tede_notice.SourceId");
  83. flowTodo.Where("tede_flow_todo.type", "ApproverCheck");
  84. flowTodo.Select("tede_flow_todo.UserId");
  85. flowUserName.WhereIn("tede_user.Id", flowTodo);
  86. query.Select(flowUserName, "FlowUserName");
  87. var uCheckedCount = new SqlKata.Query("tede_flow_todo");
  88. uCheckedCount.WhereColumns("tede_flow_todo.FlowId", "=", "tede_notice.SourceId");
  89. uCheckedCount.Where("tede_flow_todo.type", "ApproverCheck");
  90. uCheckedCount.AsCount();
  91. query.Select(uCheckedCount, "UCheckedCount");
  92. var checkedCount = new SqlKata.Query("tede_flow_todo");
  93. checkedCount.WhereColumns("tede_flow_todo.FlowId", "=", "tede_notice.SourceId");
  94. checkedCount.Where("tede_flow_todo.type", "ApproverCheck");
  95. checkedCount.Where("tede_flow_todo.IsRead", true);
  96. checkedCount.AsCount();
  97. query.Select(checkedCount, "CheckedCount");
  98. var isFlowRead = new SqlKata.Query("tede_flow_todo");
  99. isFlowRead.WhereColumns("tede_flow_todo.FlowId", "=", "tede_notice.SourceId");
  100. isFlowRead.WhereColumns("tede_flow_todo.UserId", "=", "tede_middle.UserId");
  101. isFlowRead.Where("tede_flow_todo.type", "CarbonCopy");
  102. isFlowRead.Limit(1);
  103. isFlowRead.Select("IsRead");
  104. query.Select(isFlowRead, "IsFlowRead");
  105. var isFlowChecked = new SqlKata.Query("tede_flow_todo");
  106. isFlowChecked.WhereColumns("tede_flow_todo.FlowId", "=", "tede_notice.SourceId");
  107. isFlowChecked.Where("tede_flow_todo.type", "ApproverCheck");
  108. isFlowChecked.Where("tede_flow_todo.IsRead", true);
  109. isFlowChecked.Limit(1);
  110. isFlowChecked.Select("IsRead");
  111. query.Select(isFlowChecked, "IsFlowChecked");
  112. var IsMyFlowRead = new SqlKata.Query("tede_flow");
  113. IsMyFlowRead.WhereColumns("tede_flow.Id", "=", "tede_notice.SourceId");
  114. IsMyFlowRead.WhereColumns("tede_flow.UserId", "=", "tede_notice.UserId");
  115. IsMyFlowRead.Select("IsRead");
  116. query.Select(IsMyFlowRead, "IsMyFlowRead");
  117. var IsDone = new SqlKata.Query("tede_flow_todo");
  118. IsDone.WhereColumns("tede_flow_todo.UserId", "=", "tede_middle.UserId");
  119. IsDone.Where("tede_flow_todo.type", "ApproverCheck");
  120. IsDone.Limit(1);
  121. IsDone.Select("IsDone");
  122. query.Select(IsDone, "IsDone");
  123. var IsChecked = new SqlKata.Query("tede_flow_todo");
  124. IsChecked.WhereColumns("tede_flow_todo.UserId", "=", "tede_middle.UserId");
  125. IsChecked.Where("tede_flow_todo.type", "ApproverCheck");
  126. IsChecked.Limit(1);
  127. IsChecked.Select("IsChecked");
  128. query.Select(IsChecked, "IsChecked");
  129. var DoneType = new SqlKata.Query("tede_flow_todo");
  130. DoneType.WhereColumns("tede_flow_todo.UserId", "=", "tede_middle.UserId");
  131. DoneType.Where("tede_flow_todo.type", "ApproverCheck");
  132. DoneType.Limit(1);
  133. DoneType.Select("DoneType");
  134. query.Select(DoneType, "DoneType");
  135. var userName = new SqlKata.Query("tede_user");
  136. var tedeFlow = new SqlKata.Query("tede_flow");
  137. tedeFlow.WhereColumns("tede_flow.Id", "=", "tede_notice.SourceId");
  138. tedeFlow.Select("tede_flow.UserId");
  139. userName.WhereIn("tede_user.Id", tedeFlow);
  140. userName.Limit(1);
  141. userName.Select("Name");
  142. query.Select(userName, "Name");
  143. var IsFlowAdmin = new SqlKata.Query("tede_flow");
  144. IsFlowAdmin.WhereColumns("tede_flow.Id", "=", "tede_notice.SourceId");
  145. IsFlowAdmin.Where("tede_flow.UserId", userId);
  146. IsFlowAdmin.AsCount();
  147. query.Select(IsFlowAdmin, "IsFlowAdmin");
  148. var FileCount = new SqlKata.Query("tede_middle");
  149. FileCount.WhereColumns("tede_middle.ParentId", "=", "tede_middle.Id");
  150. FileCount.Where("tede_middle.IsDelete", false);
  151. FileCount.WhereNot("tede_middle.NoticeAddresseeType", 2); ;
  152. FileCount.AsCount();
  153. query.Select(FileCount, "FileCount");
  154. var ReadCount = new SqlKata.Query("tede_addressee");
  155. ReadCount.WhereColumns("tede_addressee.SourceId", "=", "tede_middle.Id");
  156. ReadCount.Where("tede_addressee.IsRead", true);
  157. ReadCount.AsCount();
  158. query.Select(ReadCount, "ReadCount");
  159. var AllCount = new SqlKata.Query("tede_addressee");
  160. AllCount.WhereColumns("tede_addressee.SourceId", "=", "tede_middle.Id");
  161. AllCount.AsCount();
  162. query.Select(AllCount, "AllCount");
  163. var IsRead = new SqlKata.Query("tede_addressee");
  164. IsRead.WhereColumns("tede_addressee.SourceId", "=", "tede_middle.MiddleId");
  165. IsRead.Where("tede_addressee.IsRead", true);
  166. IsRead.Where("tede_addressee.UserId", userId);
  167. IsRead.Limit(1);
  168. IsRead.Select("IsRead");
  169. query.Select(IsRead, "IsRead");
  170. return query;
  171. }
  172. }
  173. }