更新项目配置,新增设备同步模块,优化WebSocket和Swagger配置,增强SCADA系统的免登录接口,支持数据字典项和登录日志的免登录查询与记录。调整Java编译设置,确保更好的开发体验。
This commit is contained in:
239
yy-admin-master/YY.Admin.Services/Service/User/SysUserService.cs
Normal file
239
yy-admin-master/YY.Admin.Services/Service/User/SysUserService.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
|
||||
using Dm.util;
|
||||
using SqlSugar;
|
||||
using System.Globalization;
|
||||
using YY.Admin.Core;
|
||||
using YY.Admin.Core.SeedData;
|
||||
using YY.Admin.Core.Session;
|
||||
using YY.Admin.Core.Util;
|
||||
|
||||
namespace YY.Admin.Services.Service.User
|
||||
{
|
||||
public class SysUserService : ISysUserService, ISingletonDependency
|
||||
{
|
||||
private readonly ISysOrgService _sysOrgService;
|
||||
private readonly ISqlSugarClient _dbContext;
|
||||
public SysUserService(ISysOrgService orgService, ISqlSugarClient dbContext)
|
||||
{
|
||||
_sysOrgService = orgService;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<List<SysUser>> GetUsersAsync()
|
||||
{
|
||||
await Task.Delay(200);
|
||||
return new List<SysUser>();
|
||||
}
|
||||
|
||||
public async Task<SqlSugarPagedList<UserOutput>> PageAsync(PageUserInput input)
|
||||
{
|
||||
var sexFilter = input.Sex.HasValue ? (int?)input.Sex.Value : null;
|
||||
var statusFilter = input.Status.HasValue ? (int?)input.Status.Value : null;
|
||||
|
||||
// 账号管理查询改为从 Jeecg 同构账号表读取
|
||||
var query = _dbContext.Queryable<JeecgSysUser>().ClearFilter()
|
||||
.WhereIF(input.TenantId > 0, u => u.LoginTenantId == input.TenantId)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Account), u => u.Username != null && u.Username.Contains(input.Account))
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.RealName), u => u.Realname != null && u.Realname.Contains(input.RealName))
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Phone), u => u.Phone != null && u.Phone.Contains(input.Phone))
|
||||
.WhereIF(input.BeginTime.HasValue, u => u.CreateTime >= input.BeginTime)
|
||||
.WhereIF(input.EndTime.HasValue, u => u.CreateTime <= input.EndTime)
|
||||
.OrderBy(u => SqlFunc.Desc(u.CreateTime));
|
||||
if (sexFilter.HasValue)
|
||||
{
|
||||
var sexValue = sexFilter.Value;
|
||||
query = query.Where(u => u.Sex == sexValue);
|
||||
}
|
||||
if (statusFilter.HasValue)
|
||||
{
|
||||
var statusValue = statusFilter.Value;
|
||||
query = query.Where(u => u.Status == statusValue);
|
||||
}
|
||||
|
||||
var pageData = await query.ToPagedListAsync(input.Page, input.PageSize);
|
||||
var mapped = pageData.Items.Select(u =>
|
||||
{
|
||||
long id = 0;
|
||||
long.TryParse(u.Id, NumberStyles.Integer, CultureInfo.InvariantCulture, out id);
|
||||
var sex = GenderEnum.Unknown;
|
||||
if (u.Sex == 1) sex = GenderEnum.Male;
|
||||
if (u.Sex == 2) sex = GenderEnum.Female;
|
||||
var status = u.Status == 1 ? StatusEnum.Enable : StatusEnum.Disable;
|
||||
return new UserOutput
|
||||
{
|
||||
Id = id,
|
||||
Account = u.Username ?? string.Empty,
|
||||
RealName = u.Realname ?? string.Empty,
|
||||
// Jeecg 同构表无 nickname 字段,昵称回退为真实姓名,避免页面显示被“清空”
|
||||
NickName = string.IsNullOrWhiteSpace(u.Realname) ? (u.Username ?? string.Empty) : u.Realname,
|
||||
Avatar = u.Avatar,
|
||||
Sex = sex,
|
||||
Birthday = u.Birthday,
|
||||
Phone = u.Phone,
|
||||
Email = u.Email,
|
||||
OfficePhone = u.Telephone,
|
||||
Status = status,
|
||||
CreateTime = u.CreateTime,
|
||||
OrgName = u.OrgCode ?? string.Empty,
|
||||
PosName = u.PositionType ?? string.Empty,
|
||||
RoleName = string.Empty,
|
||||
AccountType = AccountTypeEnum.NormalUser
|
||||
};
|
||||
}).ToList();
|
||||
|
||||
return new SqlSugarPagedList<UserOutput>
|
||||
{
|
||||
Page = pageData.Page,
|
||||
PageSize = pageData.PageSize,
|
||||
Items = mapped,
|
||||
Total = pageData.Total,
|
||||
TotalPages = pageData.TotalPages,
|
||||
HasNextPage = pageData.HasNextPage,
|
||||
HasPrevPage = pageData.HasPrevPage
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<int> BatchDeleteAsync(List<long> ids)
|
||||
{
|
||||
int count = 0;
|
||||
if (ids == null || ids.isEmpty())
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await _dbContext.AsTenant().BeginTranAsync();
|
||||
|
||||
count = await _dbContext.Deleteable<SysUser>().In(ids).ExecuteCommandAsync();
|
||||
|
||||
await _dbContext.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await _dbContext.AsTenant().RollbackTranAsync();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteAsync(long id)
|
||||
{
|
||||
int count = 0;
|
||||
try
|
||||
{
|
||||
await _dbContext.AsTenant().BeginTranAsync();
|
||||
|
||||
count = await _dbContext.Deleteable<SysUser>().In(id).ExecuteCommandAsync();
|
||||
|
||||
await _dbContext.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await _dbContext.AsTenant().RollbackTranAsync();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public async Task<int> CreateAsync(SysUser sysUser)
|
||||
{
|
||||
long maxId = await ReadMaxIdAsync();
|
||||
|
||||
sysUser.Id = ++maxId;
|
||||
sysUser.Password = CryptogramUtil.Encrypt(sysUser.Password);
|
||||
sysUser.CardType = CardTypeEnum.IdCard;
|
||||
sysUser.CultureLevel = CultureLevelEnum.Level0;
|
||||
sysUser.PosId = new SysPosSeedData().HasData().ToList()[0].Id;
|
||||
sysUser.TenantId = SqlSugarConst.DefaultTenantId;
|
||||
sysUser.CreateTime = DateTime.Now;
|
||||
sysUser.CreateUserId = AppSession.UserId;
|
||||
sysUser.CreateUserName = AppSession.CurrentUser!.Account;
|
||||
|
||||
int count = 0;
|
||||
try
|
||||
{
|
||||
await _dbContext.AsTenant().BeginTranAsync();
|
||||
|
||||
count = await _dbContext.Insertable(sysUser).ExecuteCommandAsync();
|
||||
|
||||
await _dbContext.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await _dbContext.AsTenant().RollbackTranAsync();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public async Task<int> UpdateAsync(SysUser sysUser)
|
||||
{
|
||||
sysUser.UpdateUserId = AppSession.UserId; ;
|
||||
sysUser.UpdateUserName = AppSession.CurrentUser!.Account;
|
||||
sysUser.UpdateTime = DateTime.Now;
|
||||
|
||||
int count = 0;
|
||||
try
|
||||
{
|
||||
await _dbContext.AsTenant().BeginTranAsync();
|
||||
|
||||
count = await _dbContext.Updateable(sysUser)
|
||||
.UpdateColumns(it => new { it.RealName, it.NickName, it.Sex, it.Birthday, it.Age, it.Status, it.UpdateUserId, it.UpdateUserName, it.UpdateTime })
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
await _dbContext.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await _dbContext.AsTenant().RollbackTranAsync();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public async Task<long> ReadMaxIdAsync()
|
||||
{
|
||||
return await _dbContext.Queryable<SysUser>().MaxAsync<long>("Id");
|
||||
}
|
||||
|
||||
public async Task<bool> AccountExistsAsync(string account, long? excludeUserId)
|
||||
{
|
||||
var query = _dbContext.Queryable<SysUser>()
|
||||
. Where(u => u.Account == account);
|
||||
|
||||
// excludeUserId不等于null && 不等于 0
|
||||
if (excludeUserId.HasValue && excludeUserId != 0)
|
||||
{
|
||||
query = query.Where(u => u.Id != excludeUserId.Value);
|
||||
}
|
||||
|
||||
return await query.AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<int> ToggleStatus(SysUser sysUser)
|
||||
{
|
||||
sysUser.UpdateUserId = AppSession.UserId; ;
|
||||
sysUser.UpdateUserName = AppSession.CurrentUser!.Account;
|
||||
sysUser.UpdateTime = DateTime.Now;
|
||||
|
||||
int count = 0;
|
||||
try
|
||||
{
|
||||
await _dbContext.AsTenant().BeginTranAsync();
|
||||
|
||||
count = await _dbContext.Updateable(sysUser)
|
||||
.UpdateColumns(it => new { it.Status, it.UpdateUserId, it.UpdateUserName, it.UpdateTime })
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
await _dbContext.AsTenant().CommitTranAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await _dbContext.AsTenant().RollbackTranAsync();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user