diff --git a/SafeCampus.API/SafeCampus.Application/Manager/SMS/ISMSUtilService.cs b/SafeCampus.API/SafeCampus.Application/Manager/SMS/ISMSUtilService.cs new file mode 100644 index 0000000..0622f4b --- /dev/null +++ b/SafeCampus.API/SafeCampus.Application/Manager/SMS/ISMSUtilService.cs @@ -0,0 +1,7 @@ +namespace SafeCampus.Core.Utils.TXYSMS; + +public interface ISMSUtilService +{ + Task SendSms(string[] phone, string[] content); + Task CreateSMSLog(string phone, bool sendState, string content); +} \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.Core/Utils/TXYSMS/TxySmsUtil.cs b/SafeCampus.API/SafeCampus.Application/Manager/SMS/TxySmsUtil.cs similarity index 52% rename from SafeCampus.API/SafeCampus.Core/Utils/TXYSMS/TxySmsUtil.cs rename to SafeCampus.API/SafeCampus.Application/Manager/SMS/TxySmsUtil.cs index b2ab24c..ab56477 100644 --- a/SafeCampus.API/SafeCampus.Core/Utils/TXYSMS/TxySmsUtil.cs +++ b/SafeCampus.API/SafeCampus.Application/Manager/SMS/TxySmsUtil.cs @@ -6,15 +6,22 @@ using TencentCloud.Sms.V20210111.Models; namespace SafeCampus.Core.Utils.TXYSMS; -public static class TxySmsUtil +public class TxySmsUtil: ISMSUtilService, IScoped { + private readonly SqlSugarScope _db; + + public TxySmsUtil() + { + _db = DbContext.DB; + } + /// /// 发送短信 /// /// new[] { $"+86{phone}" } 手机号码 /// new[] { code.ToString(), "5" } 内容参数 /// - public static bool SendSms(string[] phone, string[] content) + public async Task SendSms(string[] phone, string[] content) { var setting = App.GetOptionsMonitor(); Credential cred = new() @@ -37,12 +44,33 @@ public static class TxySmsUtil TemplateId = setting.VerificationCodeId, TemplateParamSet = content, }; - SendSmsResponse resp = client.SendSmsSync(req); + SendSmsResponse resp = await client.SendSms(req); if (resp.SendStatusSet[0].Code == "Ok") { - // 缓存验证码 + await CreateSMSLog(string.Join(",", phone), true, string.Join(",", content)); return true; } + await CreateSMSLog(string.Join(",",phone), false, string.Join(",", content)); return false; } + public async Task CreateSMSLog(string phone, bool sendState,string content) + { + string name = phone;//用户姓名 + string opAccount = "系统通知";//用户账号 + //日志表实体 + var devLogVisit = new SysLogVisit + { + Name = "短信通知", + Category = CateGoryConst.CONFIG_SYS_ALARM_SMS, + ExeStatus = sendState ? SysLogConst.SUCCESS : SysLogConst.FAIL, + OpAddress = content, + OpIp = "", + OpBrowser = "", + OpOs = "", + OpTime = DateTime.Now, + OpUser = name, + OpAccount = opAccount + }; + await _db.CopyNew().InsertableWithAttr(devLogVisit).IgnoreColumns(true).SplitTable().ExecuteCommandAsync();//入库 + } } \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.Application/SafeCampus.Application.xml b/SafeCampus.API/SafeCampus.Application/SafeCampus.Application.xml index 33e2ebf..7f99a12 100644 --- a/SafeCampus.API/SafeCampus.Application/SafeCampus.Application.xml +++ b/SafeCampus.API/SafeCampus.Application/SafeCampus.Application.xml @@ -626,6 +626,13 @@ + + + 根据摄像头编码获取摄像头信息 + + + + 租户id @@ -2655,5 +2662,13 @@ + + + 发送短信 + + new[] { $"+86{phone}" } 手机号码 + new[] { code.ToString(), "5" } 内容参数 + + diff --git a/SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/CameraInfoService.cs b/SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/CameraInfoService.cs index e16cd2e..f095037 100644 --- a/SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/CameraInfoService.cs +++ b/SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/CameraInfoService.cs @@ -224,4 +224,10 @@ public class CameraInfoService : DbRepository, ICameraInfoService var list = await query.CountAsync(); return list; } + + public async Task GetInfoByCode(string sensorId) + { + var model = await Context.Queryable().Where(x => x.SensorId==sensorId).FirstAsync(); + return model?.Adapt(); + } } \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/ICameraInfoService.cs b/SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/ICameraInfoService.cs index 8bed2f4..f187198 100644 --- a/SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/ICameraInfoService.cs +++ b/SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/ICameraInfoService.cs @@ -48,4 +48,10 @@ public interface ICameraInfoService:ITransient /// /// Task GetCameraCount(CameraSearch search); + /// + /// 根据摄像头编码获取摄像头信息 + /// + /// + /// + Task GetInfoByCode(string sensorId); } \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.Application/Services/Business/Warn/Service/WarnInfoService.cs b/SafeCampus.API/SafeCampus.Application/Services/Business/Warn/Service/WarnInfoService.cs index 52e9e10..39735bb 100644 --- a/SafeCampus.API/SafeCampus.Application/Services/Business/Warn/Service/WarnInfoService.cs +++ b/SafeCampus.API/SafeCampus.Application/Services/Business/Warn/Service/WarnInfoService.cs @@ -1,36 +1,91 @@ using Mapster; using MoYu.DependencyInjection; using MoYu.FriendlyException; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json; using SafeCampus.Application.Services.Business; +using SafeCampus.Application.Services.Business.CameraInfoService; +using SafeCampus.Application.Services.Business.PersonInfoService; using SafeCampus.Application.Services.Business.Warn.Dto; using SafeCampus.Application.Services.Business.Warn.Service; using SafeCampus.Core.Utils.TXYSMS; namespace SafeCampus.Web.Core.Controllers.Application.Business.Warn.Service; -public class WarnInfoService:DbRepository, IWarnInfoService,ITransient +public class WarnInfoService : DbRepository, IWarnInfoService, ITransient { private readonly ISimpleCacheService _simpleCacheService; + private readonly IConfigService _configService; + private readonly ISMSUtilService _smsUtilService; + private readonly ICameraInfoService _cameraInfoService; + private readonly IPersonInfoService _personInfoService; - public WarnInfoService(ISimpleCacheService simpleCacheService) + public WarnInfoService(ISimpleCacheService simpleCacheService, IConfigService configService, ISMSUtilService smsUtilService, ICameraInfoService cameraInfoService, IPersonInfoService personInfoService) { _simpleCacheService = simpleCacheService; + _configService = configService; + _smsUtilService = smsUtilService; + _cameraInfoService = cameraInfoService; + _personInfoService = personInfoService; } public async Task Add(WarnInfoDto vm) { - var model = vm.Adapt(); await InsertAsync(model); - //TODO 发送短信 - TxySmsUtil.SendSms(new[] { "" }, new[] { "" }); + var time = DateTime.Now; + var count = 1; + var pushState = + (await _configService.GetByConfigKey(CateGoryConst.CONFIG_BIZ_DEFINE, BizConfigConst.BIZ_SMS_STATES)) + .ConfigValue.ToBoolean(); + var daySum = + (await _configService.GetByConfigKey(CateGoryConst.CONFIG_BIZ_DEFINE, BizConfigConst.BIZ_SMS_STATES_DAY)) + .ConfigValue.ToInt(); + if (daySum > 1) + { + count = await Context.Queryable().CountAsync(x => + x.Tick.Year == time.Year && x.Tick.Month == time.Month && x.Tick.Day == time.Day); + } + + if (!pushState || count < daySum) return true; + { + var phone = await _cameraInfoService.GetInfoByCode(model.CameraId); + if (phone == null) return true; + var config = _simpleCacheService.Get>(SafeCampusConst.WarnGroup); + //场景名称 + var sceneName = config.FirstOrDefault(x => x.Subset.Any(xx => xx.Code == model.AlarmType) && x.CameraId.Contains(model.CameraId))?.Name; + //TODO 发送短信 + var kzxx = ""; + if (!string.IsNullOrEmpty(model.Extend)) + { + if (string.IsNullOrEmpty(model.PersonId)) + { + var extend = JsonConvert.DeserializeObject(model.Extend); + kzxx = extend["age"] != null ? $",年龄:{extend["age"]};年龄置信度:{Convert.ToInt32(Convert.ToDecimal(extend["ageProb"]) * 100)}%;" : ""; + } + else + { + var pre = await _personInfoService.GetInfo(model.PersonId); + if (pre!=null) + { + kzxx = $",姓名:{pre.Name},班级:{pre.PersonSetName}"; + } + } + } + if (model.AlarmType == "crowd") + { + kzxx = $",人群聚集数量:{model.Count}"; + } + var content = $"{model.Tick:yyyy-MM-dd HH:mm:ss}【{phone.SensorName}】触发【{model.AlarmTypeDesc}】预警,场景【{sceneName}】{kzxx}"; + await _smsUtilService.SendSms(new[] { phone.SysUserItem.Phone }, new[] { content }); + } return true; } public async Task Delete(long Id) { - var model = await GetFirstAsync(x=>x.Id==Id); + var model = await GetFirstAsync(x => x.Id == Id); if (model == null) { throw Oops.Oh("信息不存在"); @@ -58,7 +113,7 @@ public class WarnInfoService:DbRepository, IWarnInfoService,ITransient public async Task GetInfo(long Id) { var model = await Context.Queryable() - .Includes(x=>x.CameraInfoItem) + .Includes(x => x.CameraInfoItem) .Includes(x => x.PersonInfoItem) .Includes(x => x.PersonSetInfoItem) .FirstAsync(x => x.Id == Id); @@ -73,10 +128,10 @@ public class WarnInfoService:DbRepository, IWarnInfoService,ITransient { var config = _simpleCacheService.Get>(SafeCampusConst.WarnGroup); var guolvIds = new List(); - - if (config!=null) + + if (config != null) { - var guolv = await Context.Queryable().Select(x=>new{x.CameraId,x.AlarmType,x.Id}).ToListAsync(); + var guolv = await Context.Queryable().Select(x => new { x.CameraId, x.AlarmType, x.Id }).ToListAsync(); foreach (var warnGroupInfo in config) { if (warnGroupInfo.State) @@ -98,22 +153,22 @@ public class WarnInfoService:DbRepository, IWarnInfoService,ITransient } } } - + var query = Context.Queryable() - .Includes(x=>x.CameraInfoItem) - .Includes(x=>x.PersonInfoItem) - .Includes(x=>x.PersonSetInfoItem,x=>x.MajorInfoItem,x=>x.DepartmentInfoItem) + .Includes(x => x.CameraInfoItem) + .Includes(x => x.PersonInfoItem) + .Includes(x => x.PersonSetInfoItem, x => x.MajorInfoItem, x => x.DepartmentInfoItem) .WhereIF(search.WarnHand.HasValue, x => x.WarnHand == search.WarnHand) - .WhereIF(!string.IsNullOrEmpty(search.AlarmType),x => x.AlarmType == search.AlarmType) + .WhereIF(!string.IsNullOrEmpty(search.AlarmType), x => x.AlarmType == search.AlarmType) .WhereIF(!string.IsNullOrEmpty(search.CameraId), x => x.CameraId == search.CameraId) - .WhereIF(search.StartTick.HasValue,x => x.Tick >= search.StartTick) + .WhereIF(search.StartTick.HasValue, x => x.Tick >= search.StartTick) .WhereIF(search.EndTick.HasValue, x => x.Tick <= search.EndTick) - .WhereIF(!string.IsNullOrEmpty(search.PersonId),x=>x.PersonId==search.PersonId) - .WhereIF(guolvIds.Any(),x=>!guolvIds.Contains(x.Id)); - - var list=await query.OrderByDescending(x=>x.Tick) - .ToPagedListAsyncMapster(search.PageNum, search.PageSize); - return list; + .WhereIF(!string.IsNullOrEmpty(search.PersonId), x => x.PersonId == search.PersonId) + .WhereIF(guolvIds.Any(), x => !guolvIds.Contains(x.Id)); + + var list = await query.OrderByDescending(x => x.Tick) + .ToPagedListAsyncMapster(search.PageNum, search.PageSize); + return list; } @@ -162,14 +217,14 @@ public class WarnInfoService:DbRepository, IWarnInfoService,ITransient } } var query = Context.Queryable() - .Includes(x => x.CameraInfoItem,x=>x.CameraGroupItem) + .Includes(x => x.CameraInfoItem, x => x.CameraGroupItem) .Includes(x => x.PersonInfoItem) .Includes(x => x.PersonSetInfoItem) .WhereIF(search.WarnHand.HasValue, x => x.WarnHand == search.WarnHand) .WhereIF(!string.IsNullOrEmpty(search.AlarmType), x => x.AlarmType == search.AlarmType) - .WhereIF(search.AlarmTypes!=null&&search.AlarmTypes.Any(),x=>search.AlarmTypes.Contains(x.AlarmType)) - .WhereIF(search.PersonSetIds != null&&search.PersonSetIds.Any(),x=>search.PersonSetIds.Contains(x.PersonSetId)) - .WhereIF(search.CameraIds != null&&search.CameraIds.Any(),x=>search.CameraIds.Contains(x.CameraId)) + .WhereIF(search.AlarmTypes != null && search.AlarmTypes.Any(), x => search.AlarmTypes.Contains(x.AlarmType)) + .WhereIF(search.PersonSetIds != null && search.PersonSetIds.Any(), x => search.PersonSetIds.Contains(x.PersonSetId)) + .WhereIF(search.CameraIds != null && search.CameraIds.Any(), x => search.CameraIds.Contains(x.CameraId)) .WhereIF(!string.IsNullOrEmpty(search.CameraId), x => x.CameraId == search.CameraId) .WhereIF(!string.IsNullOrEmpty(search.PersonId), x => x.PersonId == search.PersonId) .WhereIF(search.StartTick.HasValue, x => x.Tick >= search.StartTick) @@ -180,7 +235,7 @@ public class WarnInfoService:DbRepository, IWarnInfoService,ITransient .ToListAsync(); return list.Adapt>(); } - public async Task>GetWarnType() + public async Task> GetWarnType() { var config = _simpleCacheService.Get>(SafeCampusConst.WarnGroup); var guolvIds = new List(); diff --git a/SafeCampus.API/SafeCampus.Core/SafeCampus.Core.xml b/SafeCampus.API/SafeCampus.Core/SafeCampus.Core.xml index f25d334..2ac8256 100644 --- a/SafeCampus.API/SafeCampus.Core/SafeCampus.Core.xml +++ b/SafeCampus.API/SafeCampus.Core/SafeCampus.Core.xml @@ -1750,14 +1750,6 @@ - - - 发送短信 - - new[] { $"+86{phone}" } 手机号码 - new[] { code.ToString(), "5" } 内容参数 - - 压缩单个文件 diff --git a/SafeCampus.API/SafeCampus.System/Const/CateGoryConst.cs b/SafeCampus.API/SafeCampus.System/Const/CateGoryConst.cs index 7c067a2..478aa25 100644 --- a/SafeCampus.API/SafeCampus.System/Const/CateGoryConst.cs +++ b/SafeCampus.API/SafeCampus.System/Const/CateGoryConst.cs @@ -21,6 +21,10 @@ public class CateGoryConst /// 系统基础 /// public const string CONFIG_SYS_BASE = "SYS_BASE"; + /// + /// 系统预警短信通知 + /// + public const string CONFIG_SYS_ALARM_SMS = "SYS_ALARM_SMS"; /// /// 登录策略 diff --git a/SafeCampus.API/SafeCampus.System/EventSubscriber/Const/EventSubscriberConst.cs b/SafeCampus.API/SafeCampus.System/EventSubscriber/Const/EventSubscriberConst.cs index 2ae17c8..0b4a088 100644 --- a/SafeCampus.API/SafeCampus.System/EventSubscriber/Const/EventSubscriberConst.cs +++ b/SafeCampus.API/SafeCampus.System/EventSubscriber/Const/EventSubscriberConst.cs @@ -26,6 +26,14 @@ public class EventSubscriberConst /// B端登录 /// public const string LOGIN_OUT_B = "B端登出"; + /// + /// 短信发送成功 + /// + public const string SMS_SUCCESS = "发送成功"; + /// + /// 短信发送失败 + /// + public const string SMS_FAIL = "发送失败"; #endregion AuthEventSubscriber diff --git a/SafeCampus.API/SafeCampus.System/SafeCampus.System.csproj b/SafeCampus.API/SafeCampus.System/SafeCampus.System.csproj index 3b629bb..196c465 100644 --- a/SafeCampus.API/SafeCampus.System/SafeCampus.System.csproj +++ b/SafeCampus.API/SafeCampus.System/SafeCampus.System.csproj @@ -48,9 +48,4 @@ - - - - - diff --git a/SafeCampus.API/SafeCampus.System/SafeCampus.System.xml b/SafeCampus.API/SafeCampus.System/SafeCampus.System.xml index 14f6fe6..7672aee 100644 --- a/SafeCampus.API/SafeCampus.System/SafeCampus.System.xml +++ b/SafeCampus.API/SafeCampus.System/SafeCampus.System.xml @@ -81,6 +81,11 @@ 系统基础 + + + 系统预警短信通知 + + 登录策略 @@ -2723,6 +2728,16 @@ B端登录 + + + 短信发送成功 + + + + + 短信发送失败 + + 清除用户缓存 @@ -3190,6 +3205,50 @@ 用户ID Token列表 + + + 根据分类删除 + + 分类名称 + + + + + 访问日志分页查询 + + 查询参数 + 日志列表 + + + + 根统计N天来登录和登出数量 + + 天使 + 统计信息 + + + + 统计登录登出总览 + + 登录和登出的数量 + + + + 分表最多查近多少年的数据 + + + + + + + + + + + + + + 权限认证输入 @@ -5335,6 +5394,36 @@ + + + 短信日志分页输入 + + + + + 短信日志周统计输出 + + + + + 日期 + + + + + 成功次数 + + + + + 失败次数 + + + + + 短信日志统计 + + 访问日志分页输入 diff --git a/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogInput.cs b/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogInput.cs new file mode 100644 index 0000000..62d6315 --- /dev/null +++ b/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogInput.cs @@ -0,0 +1,9 @@ +namespace SafeCampus.System; + +/// +/// 短信日志分页输入 +/// +public class SmsLogPageInput :BasePageInput +{ +} + diff --git a/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogOutput.cs b/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogOutput.cs new file mode 100644 index 0000000..a81f4fb --- /dev/null +++ b/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogOutput.cs @@ -0,0 +1,28 @@ +namespace SafeCampus.System; + +/// +/// 短信日志周统计输出 +/// +public class SmsLogDayStatisticsOutput +{ + /// + /// 日期 + /// + public string Date { get; set; } + /// + /// 成功次数 + /// + public int SuccessCount { get; set; } + + /// + /// 失败次数 + /// + public int FailCount { get; set; } +} + +/// +/// 短信日志统计 +/// +public class SmsLogTotalCountOutput : VisitLogTotalCountOutput +{ +} diff --git a/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/ISmsLogService.cs b/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/ISmsLogService.cs new file mode 100644 index 0000000..9321aa2 --- /dev/null +++ b/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/ISmsLogService.cs @@ -0,0 +1,31 @@ +namespace SafeCampus.System.Services.LogAudit.SmsLog; + +public interface ISmsLogService:ITransient +{ + /// + /// 根据分类删除 + /// + /// 分类名称 + /// + Task Delete(); + + /// + /// 访问日志分页查询 + /// + /// 查询参数 + /// 日志列表 + Task> Page(SmsLogPageInput input); + + /// + /// 根统计N天来登录和登出数量 + /// + /// 天使 + /// 统计信息 + Task> StatisticsByDay(int day); + + /// + /// 统计登录登出总览 + /// + /// 登录和登出的数量 + Task> TotalCount(); +} \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/SmsLogService.cs b/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/SmsLogService.cs new file mode 100644 index 0000000..06c43f1 --- /dev/null +++ b/SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/SmsLogService.cs @@ -0,0 +1,84 @@ +namespace SafeCampus.System.Services.LogAudit.SmsLog; + +public class SmsLogService : DbRepository, ISmsLogService +{ + /// + /// 分表最多查近多少年的数据 + /// + private readonly int _maxTabs = 100; + + /// + public async Task> Page(SmsLogPageInput input) + { + var query = Context.Queryable() + .Where(x=>x.Category== CateGoryConst.CONFIG_SYS_ALARM_SMS) + //.WhereIF(!string.IsNullOrEmpty(input.Account), it => it.OpAccount == input.Account)//根据账号查询 + //.WhereIF(!string.IsNullOrEmpty(input.Category), it => it.Category == input.Category)//根据分类查询 + .WhereIF(!string.IsNullOrEmpty(input.SearchKey), it => it.OpAccount.Contains(input.SearchKey) || it.OpUser.Contains(input.SearchKey)||it.OpAddress.Contains(input.SearchKey))//根据关键字查询 + .SplitTable(tabs => tabs.Take(_maxTabs)) + .OrderByIF(!string.IsNullOrEmpty(input.SortField), $"{input.SortField} {input.SortOrder}")//排序 + .OrderBy(it => it.CreateTime, OrderByType.Desc); + var pageInfo = await query.ToPagedListAsync(input.PageNum, input.PageSize);//分页 + return pageInfo; + } + + /// + public async Task> StatisticsByDay(int day) + { + //取最近七天 + var dayArray = Enumerable.Range(0, day).Select(it => DateTime.Now.Date.AddDays(it * -1)).ToList(); + //生成时间表 + var queryableLeft = Context.Reportable(dayArray).ToQueryable(); + //ReportableDateType.MonthsInLast1yea 表式近一年月份 并且queryable之后还能在where过滤 + var queryableRight = Context.Queryable().SplitTable(tabs => tabs.Take(_maxTabs));//声名表 + //报表查询 + var list = await Context + .Queryable(queryableLeft, queryableRight, JoinType.Left, + (x1, x2) => x2.CreateTime.Value.ToString("yyyy-MM-dd") == x1.ColumnName.ToString("yyyy-MM-dd")) + .GroupBy((x1, x2) => x1.ColumnName)//根据时间分组 + .OrderBy((x1, x2) => x1.ColumnName)//根据时间升序排序 + .Select((x1, x2) => new SmsLogDayStatisticsOutput + { + SuccessCount = SqlFunc.AggregateSum(SqlFunc.IIF(x2.Category == CateGoryConst.CONFIG_SYS_ALARM_SMS&&x2.ExeStatus== SysLogConst.SUCCESS, 1, 0)),//null的数据要为0所以不能用count + FailCount = SqlFunc.AggregateSum(SqlFunc.IIF(x2.Category == CateGoryConst.CONFIG_SYS_ALARM_SMS&&x2.ExeStatus==SysLogConst.FAIL, 1, 0)),//null的数据要为0所以不能用count + Date = x1.ColumnName.ToString("yyyy-MM-dd") + }).ToListAsync(); + return list; + } + + /// + public async Task> TotalCount() + { + var data = await Context.Queryable().SplitTable(tabs => tabs.Take(_maxTabs)).GroupBy(it => new{ it.Category ,it.ExeStatus})//根据分类分组 + .Select(it => new + { + it.Category,//分类 + it.ExeStatus, + Count = SqlFunc.AggregateCount(it.Category)//数量 + }).ToListAsync(); + //定义结果数组 + var SmsLogTotalCounts = new List + { + //添加登录数据 + new SmsLogTotalCountOutput + { + Type = EventSubscriberConst.SMS_SUCCESS, + Value = data.Where(it => it.Category == CateGoryConst.CONFIG_SYS_ALARM_SMS&&it.ExeStatus==SysLogConst.SUCCESS).Select(it => it.Count).FirstOrDefault() + }, + //添加登出数据 + new SmsLogTotalCountOutput + { + Type = EventSubscriberConst.SMS_FAIL, + Value = data.Where(it => it.Category == CateGoryConst.CONFIG_SYS_ALARM_SMS&&it.ExeStatus==SysLogConst.FAIL).Select(it => it.Count).FirstOrDefault() + } + }; + return SmsLogTotalCounts; + } + + /// + public async Task Delete() + { + await Context.Deleteable().Where(it => it.Category == CateGoryConst.CONFIG_SYS_ALARM_SMS).SplitTable(tabs => tabs.Take(_maxTabs)) + .ExecuteCommandAsync();//删除对应分类日志 + } +} \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.System/Services/LogAudit/VisitLog/VisitLogService.cs b/SafeCampus.API/SafeCampus.System/Services/LogAudit/VisitLog/VisitLogService.cs index 032a497..f0de9a4 100644 --- a/SafeCampus.API/SafeCampus.System/Services/LogAudit/VisitLog/VisitLogService.cs +++ b/SafeCampus.API/SafeCampus.System/Services/LogAudit/VisitLog/VisitLogService.cs @@ -1,14 +1,4 @@ - -// - - - - - - - - -namespace SafeCampus.System; +namespace SafeCampus.System; /// /// diff --git a/SafeCampus.API/SafeCampus.Web.Core/Controllers/Application/LargeScreen/LargeScreenController.cs b/SafeCampus.API/SafeCampus.Web.Core/Controllers/Application/LargeScreen/LargeScreenController.cs index 0798e1f..666b106 100644 --- a/SafeCampus.API/SafeCampus.Web.Core/Controllers/Application/LargeScreen/LargeScreenController.cs +++ b/SafeCampus.API/SafeCampus.Web.Core/Controllers/Application/LargeScreen/LargeScreenController.cs @@ -16,6 +16,7 @@ using SafeCampus.Application.Manager.DeepelephManager; using SafeCampus.Application.Services.Business.DepartmentService; using SafeCampus.Application.Services.Business.MajorService; using SafeCampus.Application.Services.Business.PersonSetInfoService; +using SafeCampus.Core.Utils.TXYSMS; namespace SafeCampus.Web.Core.Controllers.Application.LargeScreen; @@ -41,9 +42,10 @@ public class LargeScreenController private readonly IPersonSetInfoService _personSetInfoService; private readonly IMajorService _majorService; private readonly IDepartmentService _departmentService; + private readonly ISMSUtilService _msUtilService; - public LargeScreenController(IPersonInfoService personInfoService, ICameraGroupService cameraGroupService, IWarnInfoService warnInfoService, ISimpleCacheService simpleCacheService, IAttendanceService attendanceService, IBuildingService buildingService, IDormitoryService dormitoryService, IConfigService configService, IClassRoomCallTaskService classRoomCallTaskService, IClassRoomCallService classRoomCallService, IDeepelephManager deepelephManager, IPersonSetInfoService personSetInfoService, IMajorService majorService, IDepartmentService departmentService) + public LargeScreenController(IPersonInfoService personInfoService, ICameraGroupService cameraGroupService, IWarnInfoService warnInfoService, ISimpleCacheService simpleCacheService, IAttendanceService attendanceService, IBuildingService buildingService, IDormitoryService dormitoryService, IConfigService configService, IClassRoomCallTaskService classRoomCallTaskService, IClassRoomCallService classRoomCallService, IDeepelephManager deepelephManager, IPersonSetInfoService personSetInfoService, IMajorService majorService, IDepartmentService departmentService, ISMSUtilService msUtilService) { _personInfoService = personInfoService; _cameraGroupService = cameraGroupService; @@ -59,6 +61,7 @@ public class LargeScreenController _personSetInfoService = personSetInfoService; _majorService = majorService; _departmentService = departmentService; + _msUtilService = msUtilService; } /// @@ -335,4 +338,10 @@ public class LargeScreenController { return await _departmentService.GetNoPageList(new DepartmentSearch()); } + + public async Task SmsTest(string phone,bool issucc,string content) + { + await _msUtilService.CreateSMSLog(phone, issucc, content); + return true; + } } \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.Web.Core/Controllers/System/LogAudit/SmsLogController.cs b/SafeCampus.API/SafeCampus.Web.Core/Controllers/System/LogAudit/SmsLogController.cs new file mode 100644 index 0000000..21abff1 --- /dev/null +++ b/SafeCampus.API/SafeCampus.Web.Core/Controllers/System/LogAudit/SmsLogController.cs @@ -0,0 +1,61 @@ +using SafeCampus.System.Services.LogAudit.SmsLog; + +namespace SafeCampus.Web.Core; +/// +/// 短信日志控制器 +/// +[ApiDescriptionSettings(Tag = "短信日志")] +[Route("sys/audit/[controller]")] +[SuperAdmin] +public class SmsLogController : BaseController +{ + private readonly ISmsLogService _smsLogService; + + public SmsLogController(ISmsLogService smsLogService) + { + _smsLogService = smsLogService; + } + + + /// + /// 短信日志分页查询 + /// + /// + /// + [HttpGet("page")] + public async Task Page([FromQuery] SmsLogPageInput input) + { + return await _smsLogService.Page(input); + } + + /// + /// 短信日志周统计折线图 + /// + /// + [HttpGet("lineChartData")] + public async Task LineChartData() + { + return await _smsLogService.StatisticsByDay(7); + } + + /// + /// 短信日志总览饼图 + /// + /// + [HttpGet("pieChartData")] + public async Task PieChartData() + { + return await _smsLogService.TotalCount(); + } + + /// + /// 清空日志 + /// + /// + /// + [HttpPost("delete")] + public async Task Delete() + { + await _smsLogService.Delete(); + } +} \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.Web.Core/Logging/DatabaseLoggingWriter.cs b/SafeCampus.API/SafeCampus.Web.Core/Logging/DatabaseLoggingWriter.cs index 0b49530..5d5cdbd 100644 --- a/SafeCampus.API/SafeCampus.Web.Core/Logging/DatabaseLoggingWriter.cs +++ b/SafeCampus.API/SafeCampus.Web.Core/Logging/DatabaseLoggingWriter.cs @@ -1,14 +1,4 @@ - -// - - - - - - - - -using Masuit.Tools; +using Masuit.Tools; using Microsoft.Extensions.Logging; using NewLife.Serialization; using SqlSugar; diff --git a/SafeCampus.API/SafeCampus.Web.Core/SafeCampus.Web.Core.xml b/SafeCampus.API/SafeCampus.Web.Core/SafeCampus.Web.Core.xml index 6fdbbbd..40f9fa4 100644 --- a/SafeCampus.API/SafeCampus.Web.Core/SafeCampus.Web.Core.xml +++ b/SafeCampus.API/SafeCampus.Web.Core/SafeCampus.Web.Core.xml @@ -2448,6 +2448,37 @@ + + + 短信日志控制器 + + + + + 短信日志分页查询 + + + + + + + 短信日志周统计折线图 + + + + + + 短信日志总览饼图 + + + + + + 清空日志 + + + + 系统配置控制器 diff --git a/SafeCampus.API/SafeCampus.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user b/SafeCampus.API/SafeCampus.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user index 9c4744e..31c1707 100644 --- a/SafeCampus.API/SafeCampus.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user +++ b/SafeCampus.API/SafeCampus.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user @@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. <_PublishTargetUrl>F:\Project\QJKJ\SafeCampus\SafeCampus.API\SafeCampus.Web.Entry\bin\Release\net6.0\publish\ - True|2024-10-24T01:50:55.5191427Z;True|2024-10-24T09:34:12.7696084+08:00;True|2024-10-23T10:41:37.0558539+08:00;True|2024-10-23T09:28:31.4313071+08:00;True|2024-10-23T09:26:31.5501719+08:00;True|2024-10-23T09:23:51.0582343+08:00;True|2024-10-23T09:06:44.5849207+08:00;True|2024-10-22T13:08:17.1569031+08:00;True|2024-10-22T09:42:47.5945039+08:00;True|2024-10-21T17:29:20.3317104+08:00;True|2024-10-21T16:46:26.6984879+08:00;True|2024-10-21T10:12:44.0443975+08:00;True|2024-10-10T10:57:40.0075220+08:00;True|2024-10-10T10:02:41.0397715+08:00;True|2024-10-09T17:39:11.0140701+08:00;True|2024-10-09T17:18:07.5988076+08:00;True|2024-10-09T17:10:57.0818759+08:00;True|2024-10-09T17:08:07.1773134+08:00;True|2024-10-09T16:38:21.4832776+08:00;True|2024-10-09T16:31:58.3589164+08:00;True|2024-10-09T16:10:50.3337773+08:00;True|2024-10-09T10:39:55.8405182+08:00;True|2024-10-08T17:55:12.0035540+08:00;True|2024-10-08T16:48:00.5056466+08:00;True|2024-10-08T16:27:40.5071980+08:00;True|2024-10-08T16:24:26.2664694+08:00;True|2024-10-08T15:41:46.6016263+08:00;True|2024-09-30T17:07:19.0903067+08:00;True|2024-09-30T10:34:23.6203647+08:00;True|2024-09-29T14:44:27.0928205+08:00;True|2024-09-24T17:04:13.1154955+08:00;True|2024-09-23T14:58:29.0998917+08:00;True|2024-09-23T14:34:42.4664825+08:00;True|2024-09-23T14:34:14.9788969+08:00;True|2024-09-23T14:21:01.8969413+08:00;True|2024-09-23T14:17:25.6978104+08:00;True|2024-09-23T13:44:21.2948521+08:00;True|2024-09-23T13:42:29.2647186+08:00;True|2024-09-19T17:53:09.3428873+08:00;True|2024-09-19T17:47:47.8015573+08:00;True|2024-09-19T17:33:18.0038814+08:00;True|2024-09-19T17:13:16.6885326+08:00;True|2024-09-19T16:40:10.4911580+08:00;True|2024-09-19T15:32:43.5092007+08:00;True|2024-09-19T14:13:40.1278496+08:00;True|2024-09-19T11:00:03.7642790+08:00;True|2024-09-04T16:01:07.1761640+08:00;True|2024-09-04T15:47:33.3094448+08:00;True|2024-09-04T13:33:22.9396193+08:00;True|2024-08-30T13:27:03.2003529+08:00;True|2024-08-27T15:31:21.7026102+08:00;True|2024-08-20T11:12:26.7141701+08:00;True|2024-08-19T17:23:34.5703879+08:00;True|2024-08-19T15:55:28.3484786+08:00;True|2024-08-19T15:45:49.5623372+08:00;True|2024-08-19T14:56:17.7733738+08:00;True|2024-08-19T14:52:03.2782392+08:00;True|2024-08-19T14:10:57.7043528+08:00;True|2024-08-19T13:38:29.9236695+08:00;False|2024-08-19T13:29:18.8873264+08:00;True|2024-08-19T12:31:57.9280692+08:00;True|2024-08-19T11:50:36.7241244+08:00;True|2024-08-19T10:24:05.0018377+08:00;True|2024-08-19T10:23:30.0445364+08:00;True|2024-08-19T10:12:33.8316906+08:00;True|2024-08-19T10:10:48.0967630+08:00;True|2024-08-16T12:17:51.5743944+08:00;True|2024-08-16T11:36:15.1880346+08:00;True|2024-08-12T11:27:42.2864171+08:00;True|2024-08-09T14:54:42.9062124+08:00;True|2024-08-09T11:49:01.0339449+08:00;True|2024-08-09T11:43:21.9947939+08:00;True|2024-08-09T10:43:25.7641675+08:00;True|2024-08-08T15:23:17.0510180+08:00;True|2024-08-08T15:20:50.3450876+08:00;True|2024-08-08T11:06:43.0783261+08:00;True|2024-08-07T17:24:03.0780935+08:00;True|2024-08-07T17:20:50.6266614+08:00;True|2024-08-07T17:18:15.6367265+08:00;True|2024-08-06T17:31:40.3452266+08:00;True|2024-07-31T16:54:03.1890463+08:00;True|2024-07-30T17:11:33.2514194+08:00;True|2024-07-30T17:08:14.5888060+08:00;True|2024-07-30T09:56:08.6349163+08:00;True|2024-07-30T09:50:02.2368269+08:00;True|2024-07-29T16:20:12.3202393+08:00;True|2024-07-29T16:16:29.9634841+08:00;True|2024-07-29T16:09:51.7696392+08:00;True|2024-07-29T16:06:49.4145658+08:00;True|2024-07-29T15:58:50.6654249+08:00;True|2024-07-29T11:32:11.6206514+08:00;True|2024-07-29T11:26:26.1574563+08:00;True|2024-07-29T11:04:41.1896705+08:00;True|2024-07-29T10:38:38.4560275+08:00;True|2024-07-29T10:33:38.5288332+08:00;False|2024-07-29T10:33:21.0642261+08:00;False|2024-07-29T10:33:00.1005216+08:00;True|2024-07-29T09:54:59.2794860+08:00;True|2024-07-29T09:08:54.4899269+08:00;True|2024-07-26T18:02:13.5407348+08:00; + True|2024-11-19T08:11:53.2744549Z;True|2024-10-24T09:50:55.5191427+08:00;True|2024-10-24T09:34:12.7696084+08:00;True|2024-10-23T10:41:37.0558539+08:00;True|2024-10-23T09:28:31.4313071+08:00;True|2024-10-23T09:26:31.5501719+08:00;True|2024-10-23T09:23:51.0582343+08:00;True|2024-10-23T09:06:44.5849207+08:00;True|2024-10-22T13:08:17.1569031+08:00;True|2024-10-22T09:42:47.5945039+08:00;True|2024-10-21T17:29:20.3317104+08:00;True|2024-10-21T16:46:26.6984879+08:00;True|2024-10-21T10:12:44.0443975+08:00;True|2024-10-10T10:57:40.0075220+08:00;True|2024-10-10T10:02:41.0397715+08:00;True|2024-10-09T17:39:11.0140701+08:00;True|2024-10-09T17:18:07.5988076+08:00;True|2024-10-09T17:10:57.0818759+08:00;True|2024-10-09T17:08:07.1773134+08:00;True|2024-10-09T16:38:21.4832776+08:00;True|2024-10-09T16:31:58.3589164+08:00;True|2024-10-09T16:10:50.3337773+08:00;True|2024-10-09T10:39:55.8405182+08:00;True|2024-10-08T17:55:12.0035540+08:00;True|2024-10-08T16:48:00.5056466+08:00;True|2024-10-08T16:27:40.5071980+08:00;True|2024-10-08T16:24:26.2664694+08:00;True|2024-10-08T15:41:46.6016263+08:00;True|2024-09-30T17:07:19.0903067+08:00;True|2024-09-30T10:34:23.6203647+08:00;True|2024-09-29T14:44:27.0928205+08:00;True|2024-09-24T17:04:13.1154955+08:00;True|2024-09-23T14:58:29.0998917+08:00;True|2024-09-23T14:34:42.4664825+08:00;True|2024-09-23T14:34:14.9788969+08:00;True|2024-09-23T14:21:01.8969413+08:00;True|2024-09-23T14:17:25.6978104+08:00;True|2024-09-23T13:44:21.2948521+08:00;True|2024-09-23T13:42:29.2647186+08:00;True|2024-09-19T17:53:09.3428873+08:00;True|2024-09-19T17:47:47.8015573+08:00;True|2024-09-19T17:33:18.0038814+08:00;True|2024-09-19T17:13:16.6885326+08:00;True|2024-09-19T16:40:10.4911580+08:00;True|2024-09-19T15:32:43.5092007+08:00;True|2024-09-19T14:13:40.1278496+08:00;True|2024-09-19T11:00:03.7642790+08:00;True|2024-09-04T16:01:07.1761640+08:00;True|2024-09-04T15:47:33.3094448+08:00;True|2024-09-04T13:33:22.9396193+08:00;True|2024-08-30T13:27:03.2003529+08:00;True|2024-08-27T15:31:21.7026102+08:00;True|2024-08-20T11:12:26.7141701+08:00;True|2024-08-19T17:23:34.5703879+08:00;True|2024-08-19T15:55:28.3484786+08:00;True|2024-08-19T15:45:49.5623372+08:00;True|2024-08-19T14:56:17.7733738+08:00;True|2024-08-19T14:52:03.2782392+08:00;True|2024-08-19T14:10:57.7043528+08:00;True|2024-08-19T13:38:29.9236695+08:00;False|2024-08-19T13:29:18.8873264+08:00;True|2024-08-19T12:31:57.9280692+08:00;True|2024-08-19T11:50:36.7241244+08:00;True|2024-08-19T10:24:05.0018377+08:00;True|2024-08-19T10:23:30.0445364+08:00;True|2024-08-19T10:12:33.8316906+08:00;True|2024-08-19T10:10:48.0967630+08:00;True|2024-08-16T12:17:51.5743944+08:00;True|2024-08-16T11:36:15.1880346+08:00;True|2024-08-12T11:27:42.2864171+08:00;True|2024-08-09T14:54:42.9062124+08:00;True|2024-08-09T11:49:01.0339449+08:00;True|2024-08-09T11:43:21.9947939+08:00;True|2024-08-09T10:43:25.7641675+08:00;True|2024-08-08T15:23:17.0510180+08:00;True|2024-08-08T15:20:50.3450876+08:00;True|2024-08-08T11:06:43.0783261+08:00;True|2024-08-07T17:24:03.0780935+08:00;True|2024-08-07T17:20:50.6266614+08:00;True|2024-08-07T17:18:15.6367265+08:00;True|2024-08-06T17:31:40.3452266+08:00;True|2024-07-31T16:54:03.1890463+08:00;True|2024-07-30T17:11:33.2514194+08:00;True|2024-07-30T17:08:14.5888060+08:00;True|2024-07-30T09:56:08.6349163+08:00;True|2024-07-30T09:50:02.2368269+08:00;True|2024-07-29T16:20:12.3202393+08:00;True|2024-07-29T16:16:29.9634841+08:00;True|2024-07-29T16:09:51.7696392+08:00;True|2024-07-29T16:06:49.4145658+08:00;True|2024-07-29T15:58:50.6654249+08:00;True|2024-07-29T11:32:11.6206514+08:00;True|2024-07-29T11:26:26.1574563+08:00;True|2024-07-29T11:04:41.1896705+08:00;True|2024-07-29T10:38:38.4560275+08:00;True|2024-07-29T10:33:38.5288332+08:00;False|2024-07-29T10:33:21.0642261+08:00;False|2024-07-29T10:33:00.1005216+08:00;True|2024-07-29T09:54:59.2794860+08:00;True|2024-07-29T09:08:54.4899269+08:00; \ No newline at end of file diff --git a/SafeCampus.API/SafeCampus.Web.Entry/appsettings.json b/SafeCampus.API/SafeCampus.Web.Entry/appsettings.json index ac14443..a40e2f5 100644 --- a/SafeCampus.API/SafeCampus.Web.Entry/appsettings.json +++ b/SafeCampus.API/SafeCampus.Web.Entry/appsettings.json @@ -54,9 +54,9 @@ }, //腾讯云短信配置 "TXSms": { - "SecretId": "AKIDe7LJ2UfZDafT0OWNxHK7dutb2D7k6B0X", - "SecretKey": "II2WjgOpzsUqvjGXXGiupUgdNr40g5D4", - "SmsAppId": "1400681981", + "SecretId": "AKIDxg9LHvJQGp79uPedLmwpRntiGXXGlzzj", + "SecretKey": "VjgMp1wax3sRjlVyB7l82mHXhfMmxsXw", + "SmsAppId": "1400949814", "SmsSn": "北京泉江科技", "VerificationCodeId": "1408635" }