liaoxujun@qq.com
2023-09-12 6b24ae48c664c25676672ece72d134474c6af817
消息发送
8个文件已修改
4个文件已添加
241 ■■■■■ 已修改文件
.gitignore 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Job/DocumentServiceAPI.Job.csproj 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Job/JobStartup.cs 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Job/PermissionJob.cs 70 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Web.Core/DocumentServiceAPI.Web.Core.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Web.Core/Startup.cs 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.Web.Entry/DocumentServiceAPI.Web.Entry.csproj.user 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceAPI.sln 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/DocumentServiceApi.InitQMessage.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/INITQMessageDefine.cs 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/MessageReceive.cs 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DocumentServiceApi.InitQMessage/PostMessageServices.cs 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.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/
DocumentServiceAPI.Job/DocumentServiceAPI.Job.csproj
New file
@@ -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>
DocumentServiceAPI.Job/JobStartup.cs
New file
@@ -0,0 +1,27 @@
using 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)
        {
        }
    }
}
DocumentServiceAPI.Job/PermissionJob.cs
New file
@@ -0,0 +1,70 @@
using 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("执行了任务ExecuteAsync");
        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 ;
        }
    }
}
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>
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
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>
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
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>
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";
    }
}
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);
        }
    }
}
DocumentServiceApi.InitQMessage/PostMessageServices.cs
New file
@@ -0,0 +1,75 @@
using 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>
    /// 消息设置和内容接口模型
    /// </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; }
    }
}