feat: 新增期刊二维码批量生成功能及相关配套
1. 新增UserJournalQrCodeGenerateConsumer消费者处理二维码生成队列任务 2. 新增用户期刊状态枚举的生成中、失败状态 3. 新增批量生成二维码服务方法和相关DTO 4. 优化SqlSugar自动填充创建/更新人字段逻辑 5. 调整接口参数从操作人ID改为操作人名称 6. 新增获取未绑定二维码的API接口和服务方法
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Context;
|
||||
using SqlSugar;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
|
||||
@ -117,14 +120,18 @@ namespace QYZH.InteractiveMagazine.Repository.Core
|
||||
db.Aop.DataExecuting = (oldValue, entityInfo) =>
|
||||
{
|
||||
var entityValue = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue)?.ToString();
|
||||
var currnetUserName = "";
|
||||
var currentUserName = GetCurrentUserName();
|
||||
/*** inset生效 ***/
|
||||
if (entityInfo.OperationType == DataFilterType.InsertByObject)
|
||||
{
|
||||
if (entityInfo.PropertyName == "CreatedAt" && (string.IsNullOrWhiteSpace(entityValue) || entityValue == DateTime.MinValue.ToString()))
|
||||
entityInfo.SetValue(DateTime.Now);//修改CreateTime字段
|
||||
else if (entityInfo.PropertyName == "CreatedBy" && (string.IsNullOrWhiteSpace(entityValue)))
|
||||
entityInfo.SetValue(currnetUserName);//修改创建人字段
|
||||
else if (entityInfo.PropertyName == "CreatedBy" && ShouldSetOperatorName(entityValue, currentUserName))
|
||||
entityInfo.SetValue(currentUserName);//修改创建人字段
|
||||
else if (entityInfo.PropertyName == "UpdatedAt" && (string.IsNullOrWhiteSpace(entityValue) || entityValue == DateTime.MinValue.ToString()))
|
||||
entityInfo.SetValue(DateTime.Now);//修改UpdatedTime字段
|
||||
else if (entityInfo.PropertyName == "UpdatedBy" && ShouldSetOperatorName(entityValue, currentUserName))
|
||||
entityInfo.SetValue(currentUserName);//修改更新人字段
|
||||
else if (entityInfo.PropertyName == "IsDeleted" && string.IsNullOrWhiteSpace(entityValue))
|
||||
entityInfo.SetValue("0");//修改CreateTime字段
|
||||
}
|
||||
@ -134,8 +141,8 @@ namespace QYZH.InteractiveMagazine.Repository.Core
|
||||
{
|
||||
if (entityInfo.PropertyName == "UpdatedAt" && (string.IsNullOrWhiteSpace(entityValue) || entityValue == DateTime.MinValue.ToString()))
|
||||
entityInfo.SetValue(DateTime.Now);//修改UpdatedTime字段
|
||||
else if (entityInfo.PropertyName == "UpdatedBy" && (string.IsNullOrWhiteSpace(entityValue) || entityValue == "0"))
|
||||
entityInfo.SetValue(currnetUserName);//修改更新人字段
|
||||
else if (entityInfo.PropertyName == "UpdatedBy" && ShouldSetOperatorName(entityValue, currentUserName))
|
||||
entityInfo.SetValue(currentUserName);//修改更新人字段
|
||||
}
|
||||
};
|
||||
return db;
|
||||
@ -143,6 +150,39 @@ namespace QYZH.InteractiveMagazine.Repository.Core
|
||||
}
|
||||
|
||||
|
||||
private static string GetCurrentUserName()
|
||||
{
|
||||
try
|
||||
{
|
||||
var httpContextAccessor = ServiceContext.ServiceProvider?.GetService(typeof(IHttpContextAccessor)) as IHttpContextAccessor;
|
||||
var user = httpContextAccessor?.HttpContext?.User;
|
||||
var userName = user?.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value
|
||||
?? user?.Identity?.Name;
|
||||
|
||||
return string.IsNullOrWhiteSpace(userName) ? "System" : userName;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "System";
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ShouldSetOperatorName(string? entityValue, string currentUserName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(entityValue) || entityValue == "0")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (currentUserName != "System" && long.TryParse(entityValue, out _))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 把一个字符串转成驼峰规则的字符串
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user