DeleReminderMessage.cs 12 KB

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