DeleReminderMessage.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using OASystem.API.OAMethodLib.ALiYun;
  2. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  3. using OASystem.API.OAMethodLib.QiYeWeChatAPI.AppNotice;
  4. using OASystem.Domain.Dtos.Business;
  5. using OASystem.Domain.Entities.Business;
  6. using OASystem.Domain.Entities.Customer;
  7. using OASystem.Domain.Entities.Groups;
  8. using OASystem.Domain.Entities.PersonnelModule;
  9. using OASystem.Domain.ViewModels.CRM;
  10. using OASystem.Domain.ViewModels.Groups;
  11. using OASystem.Infrastructure.Repositories.Groups;
  12. using OASystem.Infrastructure.Repositories.PersonnelModule;
  13. namespace OASystem.API.OAMethodLib.Quartz.Business
  14. {
  15. public static class DeleReminderMessage
  16. {
  17. private readonly static DelegationInfoRepository _grpDeleRep = AutofacIocManager.Instance.GetService<DelegationInfoRepository>();
  18. private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  19. /// <summary>
  20. /// 检查团组结束日期,将当天和2天后的团组整理并发送短信提醒
  21. /// </summary>
  22. public static async void PostMessage()
  23. {
  24. DeleReminderConfig _deleReminderConfig = AutofacIocManager.Instance.GetService<DeleReminderConfig>();
  25. List<string> list_PhoneNumbers = _deleReminderConfig.PhoneNumber.Split(',').ToList();
  26. //sqladd2day查询0A2014数据库,正式使用新OA后将两次查询合并
  27. DateTime dtNow = DateTime.Now;
  28. string add2day = dtNow.AddDays(2).ToString("yyyy-MM-dd");
  29. string add7day = dtNow.AddDays(7).ToString("yyyy-MM-dd");
  30. _grpDeleRep.ChangeDataBase(DBEnum.OA2014DB);
  31. string sql = string.Format(@" Select * From DelegationInfo With(Nolock) Where IsDel=0 And VisitEndDate ='{0}' Or VisitStartDate='{1}' ", add2day, add7day);
  32. List<OA2021_DelegationInfo> list_source = _grpDeleRep._sqlSugar.SqlQueryable<OA2021_DelegationInfo>(sql).ToList();
  33. _grpDeleRep.ChangeDataBase(DBEnum.OA2023DB);
  34. if (list_source.Count > 0)
  35. {
  36. List<OA2021_DelegationInfo> listAdd7day = list_source.Where(s => s.VisitStartDate.Equals(add7day)).ToList();
  37. List<OA2021_DelegationInfo> listAdd2day = list_source.Where(s => s.VisitEndDate.Equals(add2day)).ToList();
  38. if (listAdd7day.Count > 0)
  39. {
  40. string teamNames = "";
  41. listAdd7day.ForEach(s => teamNames += s.TeamName + "、");
  42. teamNames = teamNames.TrimEnd('、');
  43. //发送短信
  44. string add7dayZH = dtNow.AddDays(7).ToString("yyyy年MM月dd日");
  45. string templateParam = JsonConvert.SerializeObject(new { teams = teamNames, date = add7dayZH });
  46. foreach (string postPhoneNumber in list_PhoneNumbers)
  47. {
  48. string postResult = AliMessagePost.PostMessage(postPhoneNumber, "泛美国际团组", "SMS_461505530", templateParam);
  49. Bus_MsgPostInfo _entity = new Bus_MsgPostInfo();
  50. _entity.Source = "ALiYun";
  51. _entity.TeamNames = teamNames;
  52. _entity.PostType = "Dele2";
  53. _entity.PhoneNumber = postPhoneNumber;
  54. _entity.PostResult = postResult;
  55. _grpDeleRep._sqlSugar.Insertable<Bus_MsgPostInfo>(_entity);
  56. }
  57. }
  58. if (listAdd2day.Count > 0)
  59. {
  60. string teamNames = "";
  61. listAdd2day.ForEach(s => teamNames += s.TeamName + "、");
  62. teamNames = teamNames.TrimEnd('、');
  63. //发送短信
  64. string add2dayZH = dtNow.AddDays(2).ToString("yyyy年MM月dd日");
  65. string templateParam = JsonConvert.SerializeObject(new { teams = teamNames, date = add2dayZH });
  66. foreach (string postPhoneNumber in list_PhoneNumbers)
  67. {
  68. string postResult = AliMessagePost.PostMessage(postPhoneNumber, "泛美国际团组", "SMS_461575447", templateParam);
  69. Bus_MsgPostInfo _entity = new Bus_MsgPostInfo();
  70. _entity.Source = "ALiYun";
  71. _entity.TeamNames = teamNames;
  72. _entity.PostType = "Dele1";
  73. _entity.PhoneNumber = postPhoneNumber;
  74. _entity.PostResult = postResult;
  75. _grpDeleRep._sqlSugar.Insertable<Bus_MsgPostInfo>(_entity);
  76. }
  77. }
  78. }
  79. }
  80. /// <summary>
  81. /// 企业微信发送消息
  82. /// </summary>
  83. public static async void PostMessageByWebhook()
  84. {
  85. DateTime dtNow = DateTime.Now;
  86. string now = dtNow.ToString("yyyy-MM-dd");
  87. string add3day = dtNow.AddDays(2).ToString("yyyy-MM-dd"); //结束出访前3天(含今天)
  88. string add7day = dtNow.AddDays(6).ToString("yyyy-MM-dd"); //开始出访7天内(含今天)
  89. string minus1day = dtNow.AddDays(-1).ToString("yyyy-MM-dd"); //于昨日结束
  90. //string sql = string.Format(@" Select * From Grp_DelegationInfo With(Nolock) Where IsDel=0 And VisitEndDate ='{0}' Or VisitStartDate='{1}' ", add3day, add7day);
  91. //List<Grp_DelegationInfo> list_source = _grpDeleRep._sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  92. string sql7day = string.Format(@" Select * From Grp_DelegationInfo With(Nolock) where IsDel = 0 And VisitStartDate Between '{0} 00:00:00' And '{1} 23:59:59' Order By VisitStartDate Asc ", now, add7day);
  93. string sql3day = string.Format(@" Select * From Grp_DelegationInfo With(Nolock) where IsDel = 0 And VisitEndDate Between '{0} 00:00:00' And '{1} 23:59:59' Order By VisitEndDate Asc ", now, add3day);
  94. string sqlm1day = string.Format(@" Select * From Grp_DelegationInfo With(Nolock) where IsDel = 0 And VisitEndDate Between '{0} 00:00:00' And '{1} 23:59:59' Order By VisitEndDate Asc ", minus1day, minus1day);
  95. List<Grp_DelegationInfo> listAdd7day = _grpDeleRep._sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql7day).ToList();
  96. List<Grp_DelegationInfo> listAdd3day = _grpDeleRep._sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql3day).ToList();
  97. List<Grp_DelegationInfo> listMinus1day = _grpDeleRep._sqlSugar.SqlQueryable<Grp_DelegationInfo>(sqlm1day).ToList();
  98. await AppNoticeLibrary.SendChatMsg_GroupRemindersToCaiwu(listAdd7day, listAdd3day, listMinus1day, QiyeWeChatEnum.CaiWuChat02);
  99. await AppNoticeLibrary.SendChatMsg_GroupRemindersToGuojiao(listAdd3day, QiyeWeChatEnum.GuoJiaoChat01);
  100. }
  101. public static async void PostMessageByWebhook_CRMStatistics()
  102. {
  103. DateTime dtNow = DateTime.Now;
  104. if (dtNow.DayOfWeek == DayOfWeek.Monday)
  105. {
  106. string dt_1day = dtNow.AddDays(-1).ToString("yyyy-MM-dd");
  107. string dt_7day = dtNow.AddDays(-7).ToString("yyyy-MM-dd");
  108. string sql_users = string.Format(@" Select * From Sys_Users with(Nolock) where IsDel = 0 And DepId = 6 And Id Not In (321) ");
  109. List<Sys_Users> userList = _grpDeleRep._sqlSugar.SqlQueryable<Sys_Users>(sql_users).ToList();
  110. List<CRMWeekStatisticsView> source = new List<CRMWeekStatisticsView>();
  111. int total_insert = 0;
  112. int total_delete = 0;
  113. foreach (var u in userList)
  114. {
  115. string sql_temp1 = string.Format(@" Select * From Crm_NewClientData With(Nolock) where CreateUserId = {0} And CreateTime Between '{1} 00:00:00' And '{2} 23:59:59' ", u.Id, dt_7day, dt_1day);
  116. List<Crm_NewClientData> crmList = _grpDeleRep._sqlSugar.SqlQueryable<Crm_NewClientData>(sql_temp1).ToList();
  117. int iNum = crmList.Where(s => s.IsDel == 0).Count();
  118. int dNum = crmList.Where(s => s.IsDel == 1).Count();
  119. string userName = u.CnName;
  120. total_insert += iNum;
  121. total_delete += dNum;
  122. CRMWeekStatisticsView sourceItem = new CRMWeekStatisticsView()
  123. {
  124. DeleteNum = dNum,
  125. InsertNum = iNum,
  126. UserName = userName
  127. };
  128. source.Add(sourceItem);
  129. }
  130. List<string> temp = new List<string>() { "234", "309" };
  131. await AppNoticeLibrary.SendUserMsg_CRMStatistics_ToHR(source, temp, dt_7day, dt_1day);
  132. }
  133. if (dtNow.Day == 1)
  134. {
  135. string dt_last = dtNow.AddDays(-1).ToString("yyyy-MM-dd");
  136. string dt_first = dtNow.AddDays(-1).ToString("yyyy-MM-01");
  137. string sql_users = string.Format(@" Select * From Sys_Users with(Nolock) where IsDel = 0 And DepId = 6 And Id Not In (321) ");
  138. List<Sys_Users> userList = _grpDeleRep._sqlSugar.SqlQueryable<Sys_Users>(sql_users).ToList();
  139. List<CRMWeekStatisticsView> source = new List<CRMWeekStatisticsView>();
  140. int total_insert = 0;
  141. int total_delete = 0;
  142. foreach (var u in userList)
  143. {
  144. string sql_temp1 = string.Format(@" Select * From Crm_NewClientData With(Nolock) where CreateUserId = {0} And CreateTime Between '{1} 00:00:00' And '{2} 23:59:59' ", u.Id, dt_first, dt_last);
  145. List<Crm_NewClientData> crmList = _grpDeleRep._sqlSugar.SqlQueryable<Crm_NewClientData>(sql_temp1).ToList();
  146. int iNum = crmList.Where(s => s.IsDel == 0).Count();
  147. int dNum = crmList.Where(s => s.IsDel == 1).Count();
  148. string userName = u.CnName;
  149. total_insert += iNum;
  150. total_delete += dNum;
  151. CRMWeekStatisticsView sourceItem = new CRMWeekStatisticsView()
  152. {
  153. DeleteNum = dNum,
  154. InsertNum = iNum,
  155. UserName = userName
  156. };
  157. source.Add(sourceItem);
  158. }
  159. List<string> temp = new List<string>() { "234", "309" };
  160. await AppNoticeLibrary.SendUserMsg_CRMStatistics_Month_ToHR(source, temp, dt_first, dt_last, total_insert, total_delete);
  161. }
  162. }
  163. }
  164. }