Ver código fonte

增加预警短信推送

增加短信推送记录
master
王晓寒 6 dias atrás
pai
commit
c8de6b7b3b
22 arquivos alterados com 509 adições e 71 exclusões
  1. +7
    -0
      SafeCampus.API/SafeCampus.Application/Manager/SMS/ISMSUtilService.cs
  2. +32
    -4
      SafeCampus.API/SafeCampus.Application/Manager/SMS/TxySmsUtil.cs
  3. +15
    -0
      SafeCampus.API/SafeCampus.Application/SafeCampus.Application.xml
  4. +6
    -0
      SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/CameraInfoService.cs
  5. +6
    -0
      SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/ICameraInfoService.cs
  6. +82
    -27
      SafeCampus.API/SafeCampus.Application/Services/Business/Warn/Service/WarnInfoService.cs
  7. +0
    -8
      SafeCampus.API/SafeCampus.Core/SafeCampus.Core.xml
  8. +4
    -0
      SafeCampus.API/SafeCampus.System/Const/CateGoryConst.cs
  9. +8
    -0
      SafeCampus.API/SafeCampus.System/EventSubscriber/Const/EventSubscriberConst.cs
  10. +0
    -5
      SafeCampus.API/SafeCampus.System/SafeCampus.System.csproj
  11. +89
    -0
      SafeCampus.API/SafeCampus.System/SafeCampus.System.xml
  12. +9
    -0
      SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogInput.cs
  13. +28
    -0
      SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogOutput.cs
  14. +31
    -0
      SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/ISmsLogService.cs
  15. +84
    -0
      SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/SmsLogService.cs
  16. +1
    -11
      SafeCampus.API/SafeCampus.System/Services/LogAudit/VisitLog/VisitLogService.cs
  17. +10
    -1
      SafeCampus.API/SafeCampus.Web.Core/Controllers/Application/LargeScreen/LargeScreenController.cs
  18. +61
    -0
      SafeCampus.API/SafeCampus.Web.Core/Controllers/System/LogAudit/SmsLogController.cs
  19. +1
    -11
      SafeCampus.API/SafeCampus.Web.Core/Logging/DatabaseLoggingWriter.cs
  20. +31
    -0
      SafeCampus.API/SafeCampus.Web.Core/SafeCampus.Web.Core.xml
  21. +1
    -1
      SafeCampus.API/SafeCampus.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user
  22. +3
    -3
      SafeCampus.API/SafeCampus.Web.Entry/appsettings.json

+ 7
- 0
SafeCampus.API/SafeCampus.Application/Manager/SMS/ISMSUtilService.cs Ver arquivo

@@ -0,0 +1,7 @@
namespace SafeCampus.Core.Utils.TXYSMS;

public interface ISMSUtilService
{
Task<bool> SendSms(string[] phone, string[] content);
Task CreateSMSLog(string phone, bool sendState, string content);
}

SafeCampus.API/SafeCampus.Core/Utils/TXYSMS/TxySmsUtil.cs → SafeCampus.API/SafeCampus.Application/Manager/SMS/TxySmsUtil.cs Ver arquivo

@@ -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;
}

/// <summary>
/// 发送短信
/// </summary>
/// <param name="phone">new[] { $"+86{phone}" } 手机号码</param>
/// <param name="content">new[] { code.ToString(), "5" } 内容参数</param>
/// <returns></returns>
public static bool SendSms(string[] phone, string[] content)
public async Task<bool> SendSms(string[] phone, string[] content)
{
var setting = App.GetOptionsMonitor<TXSmsOptions>();
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();//入库
}
}

+ 15
- 0
SafeCampus.API/SafeCampus.Application/SafeCampus.Application.xml Ver arquivo

@@ -626,6 +626,13 @@
<param name="search"></param>
<returns></returns>
</member>
<member name="M:SafeCampus.Application.Services.Business.CameraInfoService.ICameraInfoService.GetInfoByCode(System.String)">
<summary>
根据摄像头编码获取摄像头信息
</summary>
<param name="sensorId"></param>
<returns></returns>
</member>
<member name="P:SafeCampus.Application.Services.Business.ClassRoomCallService.ClassRoomCallDto.TenantCode">
<summary>
租户id
@@ -2655,5 +2662,13 @@
</summary>
<param name="services"></param>
</member>
<member name="M:SafeCampus.Core.Utils.TXYSMS.TxySmsUtil.SendSms(System.String[],System.String[])">
<summary>
发送短信
</summary>
<param name="phone">new[] { $"+86{phone}" } 手机号码</param>
<param name="content">new[] { code.ToString(), "5" } 内容参数</param>
<returns></returns>
</member>
</members>
</doc>

+ 6
- 0
SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/CameraInfoService.cs Ver arquivo

@@ -224,4 +224,10 @@ public class CameraInfoService : DbRepository<CameraInfo>, ICameraInfoService
var list = await query.CountAsync();
return list;
}

public async Task<CameraInfoDto> GetInfoByCode(string sensorId)
{
var model = await Context.Queryable<CameraInfo>().Where(x => x.SensorId==sensorId).FirstAsync();
return model?.Adapt<CameraInfoDto>();
}
}

+ 6
- 0
SafeCampus.API/SafeCampus.Application/Services/Business/CameraInfoService/ICameraInfoService.cs Ver arquivo

@@ -48,4 +48,10 @@ public interface ICameraInfoService:ITransient
/// <param name="search"></param>
/// <returns></returns>
Task<int> GetCameraCount(CameraSearch search);
/// <summary>
/// 根据摄像头编码获取摄像头信息
/// </summary>
/// <param name="sensorId"></param>
/// <returns></returns>
Task<CameraInfoDto> GetInfoByCode(string sensorId);
}

+ 82
- 27
SafeCampus.API/SafeCampus.Application/Services/Business/Warn/Service/WarnInfoService.cs Ver arquivo

@@ -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<WarnInfo>, IWarnInfoService,ITransient
public class WarnInfoService : DbRepository<WarnInfo>, 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<bool> Add(WarnInfoDto vm)
{

var model = vm.Adapt<WarnInfo>();
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<WarnInfo>().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<List<WarnGroupInfo>>(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<JObject>(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<bool> 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<WarnInfo>, IWarnInfoService,ITransient
public async Task<WarnInfoDto> GetInfo(long Id)
{
var model = await Context.Queryable<WarnInfo>()
.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<WarnInfo>, IWarnInfoService,ITransient
{
var config = _simpleCacheService.Get<List<WarnGroupInfo>>(SafeCampusConst.WarnGroup);
var guolvIds = new List<long>();
if (config!=null)
if (config != null)
{
var guolv = await Context.Queryable<WarnInfo>().Select(x=>new{x.CameraId,x.AlarmType,x.Id}).ToListAsync();
var guolv = await Context.Queryable<WarnInfo>().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<WarnInfo>, IWarnInfoService,ITransient
}
}
}
var query = Context.Queryable<WarnInfo>()
.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<WarnInfo,WarnInfoList>(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<WarnInfo, WarnInfoList>(search.PageNum, search.PageSize);
return list;


}
@@ -162,14 +217,14 @@ public class WarnInfoService:DbRepository<WarnInfo>, IWarnInfoService,ITransient
}
}
var query = Context.Queryable<WarnInfo>()
.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<WarnInfo>, IWarnInfoService,ITransient
.ToListAsync();
return list.Adapt<List<WarnInfoList>>();
}
public async Task<List<WarnType>>GetWarnType()
public async Task<List<WarnType>> GetWarnType()
{
var config = _simpleCacheService.Get<List<WarnGroupInfo>>(SafeCampusConst.WarnGroup);
var guolvIds = new List<long>();


+ 0
- 8
SafeCampus.API/SafeCampus.Core/SafeCampus.Core.xml Ver arquivo

@@ -1750,14 +1750,6 @@
<param name="s2"></param>
<returns></returns>
</member>
<member name="M:SafeCampus.Core.Utils.TXYSMS.TxySmsUtil.SendSms(System.String[],System.String[])">
<summary>
发送短信
</summary>
<param name="phone">new[] { $"+86{phone}" } 手机号码</param>
<param name="content">new[] { code.ToString(), "5" } 内容参数</param>
<returns></returns>
</member>
<member name="M:SafeCampus.Core.Utils.ZipUtils.ZipFile(System.String,System.String,System.Int32,System.Int32)">
<summary>
压缩单个文件


+ 4
- 0
SafeCampus.API/SafeCampus.System/Const/CateGoryConst.cs Ver arquivo

@@ -21,6 +21,10 @@ public class CateGoryConst
/// 系统基础
/// </summary>
public const string CONFIG_SYS_BASE = "SYS_BASE";
/// <summary>
/// 系统预警短信通知
/// </summary>
public const string CONFIG_SYS_ALARM_SMS = "SYS_ALARM_SMS";

/// <summary>
/// 登录策略


+ 8
- 0
SafeCampus.API/SafeCampus.System/EventSubscriber/Const/EventSubscriberConst.cs Ver arquivo

@@ -26,6 +26,14 @@ public class EventSubscriberConst
/// B端登录
/// </summary>
public const string LOGIN_OUT_B = "B端登出";
/// <summary>
/// 短信发送成功
/// </summary>
public const string SMS_SUCCESS = "发送成功";
/// <summary>
/// 短信发送失败
/// </summary>
public const string SMS_FAIL = "发送失败";

#endregion AuthEventSubscriber



+ 0
- 5
SafeCampus.API/SafeCampus.System/SafeCampus.System.csproj Ver arquivo

@@ -48,9 +48,4 @@
</None>
</ItemGroup>


<ItemGroup>
<Folder Include="Services\LogAudit\" />
</ItemGroup>

</Project>

+ 89
- 0
SafeCampus.API/SafeCampus.System/SafeCampus.System.xml Ver arquivo

@@ -81,6 +81,11 @@
系统基础
</summary>
</member>
<member name="F:SafeCampus.System.CateGoryConst.CONFIG_SYS_ALARM_SMS">
<summary>
系统预警短信通知
</summary>
</member>
<member name="F:SafeCampus.System.CateGoryConst.CONFIG_LOGIN_POLICY">
<summary>
登录策略
@@ -2723,6 +2728,16 @@
B端登录
</summary>
</member>
<member name="F:SafeCampus.System.EventSubscriberConst.SMS_SUCCESS">
<summary>
短信发送成功
</summary>
</member>
<member name="F:SafeCampus.System.EventSubscriberConst.SMS_FAIL">
<summary>
短信发送失败
</summary>
</member>
<member name="F:SafeCampus.System.EventSubscriberConst.CLEAR_USER_CACHE">
<summary>
清除用户缓存
@@ -3190,6 +3205,50 @@
<param name="userId">用户ID</param>
<param name="tokenInfos">Token列表</param>
</member>
<member name="M:SafeCampus.System.Services.LogAudit.SmsLog.ISmsLogService.Delete">
<summary>
根据分类删除
</summary>
<param name="category">分类名称</param>
<returns></returns>
</member>
<member name="M:SafeCampus.System.Services.LogAudit.SmsLog.ISmsLogService.Page(SafeCampus.System.SmsLogPageInput)">
<summary>
访问日志分页查询
</summary>
<param name="input">查询参数</param>
<returns>日志列表</returns>
</member>
<member name="M:SafeCampus.System.Services.LogAudit.SmsLog.ISmsLogService.StatisticsByDay(System.Int32)">
<summary>
根统计N天来登录和登出数量
</summary>
<param name="day">天使</param>
<returns>统计信息</returns>
</member>
<member name="M:SafeCampus.System.Services.LogAudit.SmsLog.ISmsLogService.TotalCount">
<summary>
统计登录登出总览
</summary>
<returns>登录和登出的数量</returns>
</member>
<member name="F:SafeCampus.System.Services.LogAudit.SmsLog.SmsLogService._maxTabs">
<summary>
分表最多查近多少年的数据
</summary>
</member>
<member name="M:SafeCampus.System.Services.LogAudit.SmsLog.SmsLogService.Page(SafeCampus.System.SmsLogPageInput)">
<inheritdoc />
</member>
<member name="M:SafeCampus.System.Services.LogAudit.SmsLog.SmsLogService.StatisticsByDay(System.Int32)">
<inheritdoc />
</member>
<member name="M:SafeCampus.System.Services.LogAudit.SmsLog.SmsLogService.TotalCount">
<inheritdoc />
</member>
<member name="M:SafeCampus.System.Services.LogAudit.SmsLog.SmsLogService.Delete">
<inheritdoc />
</member>
<member name="T:SafeCampus.System.AuthInput">
<summary>
权限认证输入
@@ -5335,6 +5394,36 @@
<member name="M:SafeCampus.System.OperateLogService.Detail(SafeCampus.Core.BaseIdInput)">
<inheritdoc />
</member>
<member name="T:SafeCampus.System.SmsLogPageInput">
<summary>
短信日志分页输入
</summary>
</member>
<member name="T:SafeCampus.System.SmsLogDayStatisticsOutput">
<summary>
短信日志周统计输出
</summary>
</member>
<member name="P:SafeCampus.System.SmsLogDayStatisticsOutput.Date">
<summary>
日期
</summary>
</member>
<member name="P:SafeCampus.System.SmsLogDayStatisticsOutput.SuccessCount">
<summary>
成功次数
</summary>
</member>
<member name="P:SafeCampus.System.SmsLogDayStatisticsOutput.FailCount">
<summary>
失败次数
</summary>
</member>
<member name="T:SafeCampus.System.SmsLogTotalCountOutput">
<summary>
短信日志统计
</summary>
</member>
<member name="T:SafeCampus.System.VisitLogPageInput">
<summary>
访问日志分页输入


+ 9
- 0
SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogInput.cs Ver arquivo

@@ -0,0 +1,9 @@
namespace SafeCampus.System;

/// <summary>
/// 短信日志分页输入
/// </summary>
public class SmsLogPageInput :BasePageInput
{
}


+ 28
- 0
SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/Dto/SmsLogOutput.cs Ver arquivo

@@ -0,0 +1,28 @@
namespace SafeCampus.System;

/// <summary>
/// 短信日志周统计输出
/// </summary>
public class SmsLogDayStatisticsOutput
{
/// <summary>
/// 日期
/// </summary>
public string Date { get; set; }
/// <summary>
/// 成功次数
/// </summary>
public int SuccessCount { get; set; }

/// <summary>
/// 失败次数
/// </summary>
public int FailCount { get; set; }
}

/// <summary>
/// 短信日志统计
/// </summary>
public class SmsLogTotalCountOutput : VisitLogTotalCountOutput
{
}

+ 31
- 0
SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/ISmsLogService.cs Ver arquivo

@@ -0,0 +1,31 @@
namespace SafeCampus.System.Services.LogAudit.SmsLog;

public interface ISmsLogService:ITransient
{
/// <summary>
/// 根据分类删除
/// </summary>
/// <param name="category">分类名称</param>
/// <returns></returns>
Task Delete();

/// <summary>
/// 访问日志分页查询
/// </summary>
/// <param name="input">查询参数</param>
/// <returns>日志列表</returns>
Task<SqlSugarPagedList<SysLogVisit>> Page(SmsLogPageInput input);

/// <summary>
/// 根统计N天来登录和登出数量
/// </summary>
/// <param name="day">天使</param>
/// <returns>统计信息</returns>
Task<List<SmsLogDayStatisticsOutput>> StatisticsByDay(int day);

/// <summary>
/// 统计登录登出总览
/// </summary>
/// <returns>登录和登出的数量</returns>
Task<List<SmsLogTotalCountOutput>> TotalCount();
}

+ 84
- 0
SafeCampus.API/SafeCampus.System/Services/LogAudit/SmsLog/SmsLogService.cs Ver arquivo

@@ -0,0 +1,84 @@
namespace SafeCampus.System.Services.LogAudit.SmsLog;

public class SmsLogService : DbRepository<SysLogVisit>, ISmsLogService
{
/// <summary>
/// 分表最多查近多少年的数据
/// </summary>
private readonly int _maxTabs = 100;

/// <inheritdoc />
public async Task<SqlSugarPagedList<SysLogVisit>> Page(SmsLogPageInput input)
{
var query = Context.Queryable<SysLogVisit>()
.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;
}

/// <inheritdoc />
public async Task<List<SmsLogDayStatisticsOutput>> StatisticsByDay(int day)
{
//取最近七天
var dayArray = Enumerable.Range(0, day).Select(it => DateTime.Now.Date.AddDays(it * -1)).ToList();
//生成时间表
var queryableLeft = Context.Reportable(dayArray).ToQueryable<DateTime>();
//ReportableDateType.MonthsInLast1yea 表式近一年月份 并且queryable之后还能在where过滤
var queryableRight = Context.Queryable<SysLogVisit>().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;
}

/// <inheritdoc />
public async Task<List<SmsLogTotalCountOutput>> TotalCount()
{
var data = await Context.Queryable<SysLogVisit>().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<SmsLogTotalCountOutput>
{
//添加登录数据
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;
}

/// <inheritdoc />
public async Task Delete()
{
await Context.Deleteable<SysLogVisit>().Where(it => it.Category == CateGoryConst.CONFIG_SYS_ALARM_SMS).SplitTable(tabs => tabs.Take(_maxTabs))
.ExecuteCommandAsync();//删除对应分类日志
}
}

+ 1
- 11
SafeCampus.API/SafeCampus.System/Services/LogAudit/VisitLog/VisitLogService.cs Ver arquivo

@@ -1,14 +1,4 @@

//








namespace SafeCampus.System;
namespace SafeCampus.System;

/// <summary>
/// <inheritdoc cref="IVisitLogService"/>


+ 10
- 1
SafeCampus.API/SafeCampus.Web.Core/Controllers/Application/LargeScreen/LargeScreenController.cs Ver arquivo

@@ -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;
}

/// <summary>
@@ -335,4 +338,10 @@ public class LargeScreenController
{
return await _departmentService.GetNoPageList(new DepartmentSearch());
}

public async Task<bool> SmsTest(string phone,bool issucc,string content)
{
await _msUtilService.CreateSMSLog(phone, issucc, content);
return true;
}
}

+ 61
- 0
SafeCampus.API/SafeCampus.Web.Core/Controllers/System/LogAudit/SmsLogController.cs Ver arquivo

@@ -0,0 +1,61 @@
using SafeCampus.System.Services.LogAudit.SmsLog;

namespace SafeCampus.Web.Core;
/// <summary>
/// 短信日志控制器
/// </summary>
[ApiDescriptionSettings(Tag = "短信日志")]
[Route("sys/audit/[controller]")]
[SuperAdmin]
public class SmsLogController : BaseController
{
private readonly ISmsLogService _smsLogService;

public SmsLogController(ISmsLogService smsLogService)
{
_smsLogService = smsLogService;
}


/// <summary>
/// 短信日志分页查询
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("page")]
public async Task<dynamic> Page([FromQuery] SmsLogPageInput input)
{
return await _smsLogService.Page(input);
}

/// <summary>
/// 短信日志周统计折线图
/// </summary>
/// <returns></returns>
[HttpGet("lineChartData")]
public async Task<dynamic> LineChartData()
{
return await _smsLogService.StatisticsByDay(7);
}

/// <summary>
/// 短信日志总览饼图
/// </summary>
/// <returns></returns>
[HttpGet("pieChartData")]
public async Task<dynamic> PieChartData()
{
return await _smsLogService.TotalCount();
}

/// <summary>
/// 清空日志
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("delete")]
public async Task Delete()
{
await _smsLogService.Delete();
}
}

+ 1
- 11
SafeCampus.API/SafeCampus.Web.Core/Logging/DatabaseLoggingWriter.cs Ver arquivo

@@ -1,14 +1,4 @@

//








using Masuit.Tools;
using Masuit.Tools;
using Microsoft.Extensions.Logging;
using NewLife.Serialization;
using SqlSugar;


+ 31
- 0
SafeCampus.API/SafeCampus.Web.Core/SafeCampus.Web.Core.xml Ver arquivo

@@ -2448,6 +2448,37 @@
<param name="input"></param>
<returns></returns>
</member>
<member name="T:SafeCampus.Web.Core.SmsLogController">
<summary>
短信日志控制器
</summary>
</member>
<member name="M:SafeCampus.Web.Core.SmsLogController.Page(SafeCampus.System.SmsLogPageInput)">
<summary>
短信日志分页查询
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="M:SafeCampus.Web.Core.SmsLogController.LineChartData">
<summary>
短信日志周统计折线图
</summary>
<returns></returns>
</member>
<member name="M:SafeCampus.Web.Core.SmsLogController.PieChartData">
<summary>
短信日志总览饼图
</summary>
<returns></returns>
</member>
<member name="M:SafeCampus.Web.Core.SmsLogController.Delete">
<summary>
清空日志
</summary>
<param name="input"></param>
<returns></returns>
</member>
<member name="T:SafeCampus.Web.Core.ConfigController">
<summary>
系统配置控制器


+ 1
- 1
SafeCampus.API/SafeCampus.Web.Entry/Properties/PublishProfiles/FolderProfile.pubxml.user Ver arquivo

@@ -5,7 +5,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<Project>
<PropertyGroup>
<_PublishTargetUrl>F:\Project\QJKJ\SafeCampus\SafeCampus.API\SafeCampus.Web.Entry\bin\Release\net6.0\publish\</_PublishTargetUrl>
<History>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;</History>
<History>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;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

+ 3
- 3
SafeCampus.API/SafeCampus.Web.Entry/appsettings.json Ver arquivo

@@ -54,9 +54,9 @@
},
//腾讯云短信配置
"TXSms": {
"SecretId": "AKIDe7LJ2UfZDafT0OWNxHK7dutb2D7k6B0X",
"SecretKey": "II2WjgOpzsUqvjGXXGiupUgdNr40g5D4",
"SmsAppId": "1400681981",
"SecretId": "AKIDxg9LHvJQGp79uPedLmwpRntiGXXGlzzj",
"SecretKey": "VjgMp1wax3sRjlVyB7l82mHXhfMmxsXw",
"SmsAppId": "1400949814",
"SmsSn": "北京泉江科技",
"VerificationCodeId": "1408635"
}

Carregando…
Cancelar
Salvar