From 6b24ae48c664c25676672ece72d134474c6af817 Mon Sep 17 00:00:00 2001
From: liaoxujun@qq.com <liaoxujun@qq.com>
Date: 星期二, 12 九月 2023 15:00:23 +0800
Subject: [PATCH] 消息发送

---
 DocumentServiceAPI.Job/PermissionJob.cs                                |   70 ++++++++++++++
 DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj.user  |    2 
 .gitignore                                                             |    2 
 DocumentServiceApi.InitQMessage/DocumentServiceApi.InitQMessage.csproj |    1 
 DocumentServiceApi.InitQMessage/MessageReceive.cs                      |   23 ++++
 DocumentServiceAPI.Web.Core/Startup.cs                                 |    1 
 DocumentServiceAPI.Job/JobStartup.cs                                   |   27 +++++
 DocumentServiceApi.InitQMessage/INITQMessageDefine.cs                  |   13 ++
 DocumentServiceAPI.Job/DocumentServiceAPI.Job.csproj                   |   18 +++
 DocumentServiceAPI.Web.Core/DocumentServiceAPI.Web.Core.csproj         |    1 
 DocumentServiceAPI.sln                                                 |    8 +
 DocumentServiceApi.InitQMessage/PostMessageServices.cs                 |   75 +++++++++++++++
 12 files changed, 237 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 2237dec..28cca3e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,5 @@
 DocumentServiceAPI.Application/DocumentServiceAPI.Application.xml
 DocumentServiceApi.InitQMessage/bin/
 DocumentServiceAPI.Web.Entry/Log/DocSericeApistatupLog.txt
+DocumentServiceAPI.Job/bin/
+DocumentServiceAPI.Job/obj/
diff --git a/DocumentServiceAPI.Job/DocumentServiceAPI.Job.csproj b/DocumentServiceAPI.Job/DocumentServiceAPI.Job.csproj
new file mode 100644
index 0000000..5cbb12e
--- /dev/null
+++ b/DocumentServiceAPI.Job/DocumentServiceAPI.Job.csproj
@@ -0,0 +1,18 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net6.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\DocumentServiceAPI.Core\DocumentServiceAPI.Core.csproj" />
+    <ProjectReference Include="..\DocumentServiceAPI.Enum\DocumentServiceAPI.Enum.csproj" />
+    <ProjectReference Include="..\DocumentServiceApi.InitQMessage\DocumentServiceApi.InitQMessage.csproj" />
+    <ProjectReference Include="..\DocumentServiceAPI.Model\DocumentServiceAPI.Model.csproj" />
+    <ProjectReference Include="..\DocumentServiceAPI.Services\DocumentServiceAPI.Services.csproj" />
+    <ProjectReference Include="..\DocumentServiceAPI.Utility\DocumentServiceAPI.Utility.csproj" />
+  </ItemGroup>
+
+</Project>
diff --git a/DocumentServiceAPI.Job/JobStartup.cs b/DocumentServiceAPI.Job/JobStartup.cs
new file mode 100644
index 0000000..3ebc6e5
--- /dev/null
+++ b/DocumentServiceAPI.Job/JobStartup.cs
@@ -0,0 +1,27 @@
+锘縰sing Furion;
+using Furion.Schedule;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+
+
+namespace DocumentServiceAPI.Job
+{
+    public class JobStartup: AppStartup
+    {
+        public void ConfigureServices(IServiceCollection services)
+        {
+            services.AddSchedule((op) =>
+            {
+                //娉ㄥ叆perissionjob
+                op.AddJob<PermissionJob>("鏉冮檺瀹氭椂鏈嶅姟",concurrent:false,triggerBuilders: Triggers.Daily());
+            });
+        }
+
+        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+        {
+
+
+        }
+    }
+}
diff --git a/DocumentServiceAPI.Job/PermissionJob.cs b/DocumentServiceAPI.Job/PermissionJob.cs
new file mode 100644
index 0000000..495901e
--- /dev/null
+++ b/DocumentServiceAPI.Job/PermissionJob.cs
@@ -0,0 +1,70 @@
+锘縰sing DocumentServiceApi.InitQMessage;
+using DocumentServiceAPI.Model.Permissions;
+using DocumentServiceAPI.Model.UserInfoModel;
+using Furion.Schedule;
+using Microsoft.Extensions.Logging;
+using Npgsql.TypeHandlers;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DocumentServiceAPI.Job
+{
+    public class PermissionJob : IJob
+    {
+        private readonly ILogger<PermissionJob> _logger;
+        private readonly ISqlSugarClient _db;
+        private readonly PostMessageServices _InitQMessagePost;
+        public PermissionJob(ILogger<PermissionJob> logger , ISqlSugarClient db,PostMessageServices postMessageServices)
+        {
+            _logger = logger;
+            _db = db;
+            _InitQMessagePost = postMessageServices;
+        }
+
+        public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
+        {
+
+            _logger.LogInformation("鎵ц浜嗕换鍔xecuteAsync");
+        var TimeOutPList=  await  _db.Queryable<TenantPermissions>().Where(x => x.IsEn && x.OverTime < DateTime.Now).ToListAsync();
+            foreach (var item in TimeOutPList)
+            {
+                //璁剧疆鏉冮檺涓烘棤鏁�
+                item.IsEn = false;
+
+            }
+           await _db.Updateable(TimeOutPList).UpdateColumns(it => new { it.IsEn }).ExecuteCommandAsync();
+
+            var tPermissions=    await    _db.Queryable< TenantPermissions >().LeftJoin<TenantInfo>((tx,t)=>tx.TenantId==t.Id).Where((tx,t)=>tx.IsEn==true&&tx.OverTime<DateTime.Now.AddDays(15)).Select((tx,t)=>new {tx,t}).ToListAsync();
+            foreach (var t in tPermissions)
+            {
+                TimeSpan difference = t.tx.OverTime - DateTime.Now;
+               int data=    difference.Days;
+                if (data == 15|| data == 10 ||data==3)
+                {
+                    //绗�15澶╋紝10澶╋紝3澶╁彂閫佺煭淇�
+                    _InitQMessagePost.PostDelayMessage(new MessAgeOption
+                    {
+                       
+                        Title="鏍囦功绠$悊绯荤粺娑堟伅",                       
+                        isNeedSMS = true,
+                        PhoneCode = t.t.ItCode,
+                        UserID = t.t.ZcUserID,
+                        MsgContent = $"鎮ㄧ殑 鏍囦功绠$悊绯荤粺灏嗕簬{DateTime.Now.ToString("yyyy MM dd")}鏃ュ埌鏈燂紝璇峰敖蹇笌瀹㈡埛缁忕悊鑱旂郴銆愬洓宸濇斂閲囨嫑鎶曟爣鍜ㄨ鏈夐檺鍏徃銆�",
+                        SMSMsgContent = $"鎮ㄧ殑 鏍囦功绠$悊绯荤粺灏嗕簬{DateTime.Now.ToString("yyyy MM dd")}鏃ュ埌鏈燂紝璇峰敖蹇笌瀹㈡埛缁忕悊鑱旂郴銆愬洓宸濇斂閲囨嫑鎶曟爣鍜ㄨ鏈夐檺鍏徃銆�"
+                    }, DateTime.Now.AddHours(8));
+                }
+               
+            }
+
+            return ;
+
+           
+        }
+    }
+
+    
+}
diff --git a/DocumentServiceAPI.Web.Core/DocumentServiceAPI.Web.Core.csproj b/DocumentServiceAPI.Web.Core/DocumentServiceAPI.Web.Core.csproj
index ad97204..e5d62ee 100644
--- a/DocumentServiceAPI.Web.Core/DocumentServiceAPI.Web.Core.csproj
+++ b/DocumentServiceAPI.Web.Core/DocumentServiceAPI.Web.Core.csproj
@@ -15,6 +15,7 @@
 
 	<ItemGroup>
 		<ProjectReference Include="..\DocumentServiceAPI.Application\DocumentServiceAPI.Application.csproj" />
+		<ProjectReference Include="..\DocumentServiceAPI.Job\DocumentServiceAPI.Job.csproj" />
 		<ProjectReference Include="..\DocumentServiceAPI.Model\DocumentServiceAPI.Model.csproj" />
 	</ItemGroup>
 
diff --git a/DocumentServiceAPI.Web.Core/Startup.cs b/DocumentServiceAPI.Web.Core/Startup.cs
index f672793..adb37ab 100644
--- a/DocumentServiceAPI.Web.Core/Startup.cs
+++ b/DocumentServiceAPI.Web.Core/Startup.cs
@@ -9,6 +9,7 @@
 using System.Text.Json.Serialization;
 using System.Text.Unicode;
 
+
 namespace DocumentServiceAPI.Web.Core;
 
 public class Startup : AppStartup
diff --git a/DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj.user b/DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj.user
index 85e333f..d5c942b 100644
--- a/DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj.user
+++ b/DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj.user
@@ -4,7 +4,7 @@
     <DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
   </PropertyGroup>
   <PropertyGroup>
-    <ActiveDebugProfile>IIS Express</ActiveDebugProfile>
+    <ActiveDebugProfile>DocumentServiceAPI.Web.Entry</ActiveDebugProfile>
     <NameOfLastUsedPublishProfile>E:\workdir\鏍囦功杞欢\ApiService\DocumentServiceAPI\DocumentServiceAPI.Web.Entry\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
   </PropertyGroup>
 </Project>
\ No newline at end of file
diff --git a/DocumentServiceAPI.sln b/DocumentServiceAPI.sln
index cf65739..7a12f04 100644
--- a/DocumentServiceAPI.sln
+++ b/DocumentServiceAPI.sln
@@ -23,7 +23,9 @@
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZcPayCore", "ZcPayCore\ZcPayCore.csproj", "{76BFAB65-B7AC-4534-A595-363551111129}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentServiceApi.InitQMessage", "DocumentServiceApi.InitQMessage\DocumentServiceApi.InitQMessage.csproj", "{0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DocumentServiceApi.InitQMessage", "DocumentServiceApi.InitQMessage\DocumentServiceApi.InitQMessage.csproj", "{0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DocumentServiceAPI.Job", "DocumentServiceAPI.Job\DocumentServiceAPI.Job.csproj", "{8DF63C80-56C7-47B3-9D2B-B1C08601FCDF}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -74,6 +76,10 @@
 		{0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{0A75ECEE-91C9-4A87-8573-4298DF0B6CDE}.Release|Any CPU.Build.0 = Release|Any CPU
+		{8DF63C80-56C7-47B3-9D2B-B1C08601FCDF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{8DF63C80-56C7-47B3-9D2B-B1C08601FCDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{8DF63C80-56C7-47B3-9D2B-B1C08601FCDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{8DF63C80-56C7-47B3-9D2B-B1C08601FCDF}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
diff --git a/DocumentServiceApi.InitQMessage/DocumentServiceApi.InitQMessage.csproj b/DocumentServiceApi.InitQMessage/DocumentServiceApi.InitQMessage.csproj
index cd7176f..40d20a8 100644
--- a/DocumentServiceApi.InitQMessage/DocumentServiceApi.InitQMessage.csproj
+++ b/DocumentServiceApi.InitQMessage/DocumentServiceApi.InitQMessage.csproj
@@ -11,6 +11,7 @@
   </ItemGroup>
 
   <ItemGroup>
+    <ProjectReference Include="..\DocumentServiceAPI.Application\DocumentServiceAPI.Application.csproj" />
     <ProjectReference Include="..\DocumentServiceAPI.Core\DocumentServiceAPI.Core.csproj" />
     <ProjectReference Include="..\DocumentServiceAPI.Model\DocumentServiceAPI.Model.csproj" />
   </ItemGroup>
diff --git a/DocumentServiceApi.InitQMessage/INITQMessageDefine.cs b/DocumentServiceApi.InitQMessage/INITQMessageDefine.cs
index a95de16..b19b881 100644
--- a/DocumentServiceApi.InitQMessage/INITQMessageDefine.cs
+++ b/DocumentServiceApi.InitQMessage/INITQMessageDefine.cs
@@ -20,5 +20,18 @@
         /// 鎾ゅ崟
         /// </summary>
         public const string DecTenantOder = "DocumentServiceAPI_DecOderINIT";
+
+        /// <summary>
+        ///  瀹氭椂闃熷垪娑堟伅鍙戝簭鍒楋紝鍦ㄨ繖閲岃浆鍙�
+        /// </summary>
+        public const string DTSendMessageList = "DocumentServiceAPI_MessageList";
+
+        /// <summary>
+        ///  灏嗘秷鎭彂閫佸埌鐢ㄦ埛涓績鎵ц娑堟伅鍙戦�� 璺熺敤鎴蜂腑蹇冨畾涔変竴鑷�
+        /// </summary>
+        public const string DTSendMessage = "MSG_AND_SMSMSG";
+
+
+
     }
 }
diff --git a/DocumentServiceApi.InitQMessage/MessageReceive.cs b/DocumentServiceApi.InitQMessage/MessageReceive.cs
index c5d8895..272bf15 100644
--- a/DocumentServiceApi.InitQMessage/MessageReceive.cs
+++ b/DocumentServiceApi.InitQMessage/MessageReceive.cs
@@ -8,6 +8,7 @@
 using Furion.Schedule;
 using InitQ.Abstractions;
 using InitQ.Attributes;
+using InitQ.Cache;
 using Microsoft.Extensions.Options;
 using SqlSugar;
 using System;
@@ -23,8 +24,12 @@
     /// </summary>
     public class MessageReceive: IRedisSubscribe
     {
-
-         
+        private InitQ.Cache.ICacheService _cacheService;
+      public    MessageReceive(InitQ.Cache.ICacheService cacheService)
+        {
+            _cacheService = cacheService;
+        }
+       
         /// <summary>
         /// 鍒濆鍖栬鍗曞鐞�
         /// </summary>
@@ -239,5 +244,19 @@
 
         }
 
+        /// <summary>
+        /// 鍙戦�佹秷鎭粰鐢ㄦ埛涓紝鐢ㄦ埛涓績浼氬搷搴旇繖涓秷鎭�
+        /// </summary>
+        /// <param name="msg"></param>
+        /// <returns></returns>
+        [SubscribeDelay(INITQMessageDefine.DTSendMessage)]
+        private async Task  SendMessage(string msg)
+        {
+            
+          await  _cacheService.ListRightPushAsync(INITQMessageDefine.DTSendMessage, msg);
+        }
+
     }
+
+
 }
diff --git a/DocumentServiceApi.InitQMessage/PostMessageServices.cs b/DocumentServiceApi.InitQMessage/PostMessageServices.cs
new file mode 100644
index 0000000..ebde4ce
--- /dev/null
+++ b/DocumentServiceApi.InitQMessage/PostMessageServices.cs
@@ -0,0 +1,75 @@
+锘縰sing DocumentServiceAPI.Application.UserAndLogin.Services;
+using Furion.DependencyInjection;
+using InitQ.Cache;
+using Microsoft.AspNetCore.Identity;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DocumentServiceApi.InitQMessage
+{
+    /// <summary>
+    /// 鍙戦�佹秷鎭湇鍔�
+    /// </summary>
+    public class PostMessageServices: IScoped
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+       private ICacheService _InitQService;
+        public PostMessageServices( ICacheService initQService)
+        {
+            _InitQService = initQService;
+        }
+        /// <summary>
+        /// 鍙戦�佸欢鏃舵秷鎭�
+        /// </summary>
+        public async void  PostDelayMessage(MessAgeOption msg,DateTime time)
+        {
+          await  _InitQService.SortedSetAddAsync(INITQMessageDefine.DTSendMessageList, JsonConvert.SerializeObject( msg),time);
+        }
+
+    }
+
+
+    /// <summary>
+    /// 娑堟伅璁剧疆鍜屽唴瀹规帴鍙fā鍨�
+    /// </summary>
+    public class MessAgeOption
+    {
+        /// <summary>
+        /// 鏄惁闇�瑕佸彂閫佹墜鏈虹煭淇�
+        /// </summary>
+        public bool isNeedSMS { get; set; } = false;
+        /// <summary>
+        /// 娑堟伅鍐呭
+        /// </summary>
+        public string MsgContent { get; set; }
+
+        /// <summary>
+        /// 娑堟伅鍐呭  鍙互璇曞缁勭紪鍙�
+        /// </summary>
+        public string PhoneCode { get; set; }
+
+        /// <summary>
+        /// 鏍煎紡鍖栧悗鐨勬墜鏈烘秷鎭唴瀹�
+        /// </summary>
+        public string SMSMsgContent { get; set; }
+
+
+        /// <summary>
+        /// 鏍囬
+        /// </summary>
+        public string Title { get; set; }
+        /// <summary>
+        /// 鐢ㄦ埛ID
+        /// </summary>
+        public Guid? UserID { get; set; }
+
+
+
+    }
+}

--
Gitblit v1.9.1