|
|
|
|
using GDZZ.Core;
|
|
|
|
|
using Furion.DependencyInjection;
|
|
|
|
|
using Furion.DynamicApiController;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using GDZZ.Application.Entity;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using GDZZ.Core.Entity;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Furion.FriendlyException;
|
|
|
|
|
|
|
|
|
|
namespace GDZZ.Application
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 基础用户服务
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiDescriptionSettings("Application",Name = "BaseUser", Order = 1)]
|
|
|
|
|
public class BaseUserService : IBaseUserService, IDynamicApiController, ITransient
|
|
|
|
|
{
|
|
|
|
|
private readonly SqlSugarRepository<BaseUser> _rep;
|
|
|
|
|
private readonly SqlSugarRepository<SeIF> Self; //职业仓储
|
|
|
|
|
|
|
|
|
|
private readonly SqlSugarRepository<SysUser> _sysUserRep; // 用户表仓储
|
|
|
|
|
private readonly SqlSugarRepository<OnlineUser> _sysOnlineUerRep; // 在线用户表仓储
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BaseUserService(SqlSugarRepository<BaseUser> rep,
|
|
|
|
|
SqlSugarRepository<SeIF> Self,
|
|
|
|
|
|
|
|
|
|
SqlSugarRepository<OnlineUser> _sysOnlineUerRep,
|
|
|
|
|
SqlSugarRepository<SysUser> _sysUserRep)
|
|
|
|
|
{
|
|
|
|
|
_rep = rep;
|
|
|
|
|
|
|
|
|
|
this.Self= Self;
|
|
|
|
|
this._sysUserRep = _sysUserRep;
|
|
|
|
|
this._sysOnlineUerRep= _sysOnlineUerRep;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新基础用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/Mini/User/edit")]
|
|
|
|
|
public async Task Update(UpdateBaseUserInput input)
|
|
|
|
|
{
|
|
|
|
|
//后台系统用户
|
|
|
|
|
var sysuser = await this._sysUserRep.SingleAsync(x => x.Id == UserManager.UserId);
|
|
|
|
|
if (sysuser == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh("修改失败!", sysuser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var user = this._rep.AsQueryable()
|
|
|
|
|
.Filter("TenantId", true)
|
|
|
|
|
.First(x => x.CreatedUserId == UserManager.UserId);
|
|
|
|
|
|
|
|
|
|
var Self = await this.Self.FirstOrDefaultAsync(x => x.CreatedUserId == sysuser.Id);
|
|
|
|
|
if(Self.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
await this.Self.InsertAsync(new SeIF
|
|
|
|
|
{
|
|
|
|
|
Name = input.Self,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Self.Name = input.Self;
|
|
|
|
|
await this.Self.AsUpdateable(Self).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
user.AvatarUrl = input.AvatarUrl;
|
|
|
|
|
user.Describe = input.Describe;
|
|
|
|
|
sysuser.Avatar = input.AvatarUrl;
|
|
|
|
|
sysuser.Sex = input.Sex;
|
|
|
|
|
await this._sysUserRep.AsUpdateable(sysuser).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
await this._rep.AsUpdateable(user).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取教师列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/Mini/BaseUser/list")]
|
|
|
|
|
public async Task<dynamic> TeacherList()
|
|
|
|
|
{
|
|
|
|
|
var thls = await this._sysUserRep.AsQueryable()
|
|
|
|
|
.InnerJoin<OnlineUser>((u, r) => u.Id == r.UserId)
|
|
|
|
|
.Where(u => u.AdminType == AdminType.None)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
//var user = await _sysOnlineUerRep.AsQueryable()
|
|
|
|
|
// .Filter("TenantId", true)
|
|
|
|
|
// .Where(m => m.UserId == entity.OtherUserID).OrderByDescending(x => x.LastTime).FirstAsync();
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分页查询基础用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BaseUser/page")]
|
|
|
|
|
public async Task<dynamic> Page([FromQuery] BaseUserInput input)
|
|
|
|
|
{
|
|
|
|
|
var entities = await _rep.AsQueryable()
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.UserName), u => u.UserName.Contains(input.UserName.Trim()))
|
|
|
|
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
|
|
|
|
return entities.XnPagedResult();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 增加基础用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BaseUser/add")]
|
|
|
|
|
public async Task Add(AddBaseUserInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = input.Adapt<BaseUser>();
|
|
|
|
|
await _rep.InsertAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除基础用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/BaseUser/delete")]
|
|
|
|
|
public async Task Delete(DeleteBaseUserInput input)
|
|
|
|
|
{
|
|
|
|
|
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
|
|
|
await _rep.DeleteAsync(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取基础用户
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BaseUser/detail")]
|
|
|
|
|
public async Task<BaseUser> Get([FromQuery] QueryeBaseUserInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取基础用户列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="input"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BaseUser/list")]
|
|
|
|
|
public async Task<dynamic> List([FromQuery] BaseUserInput input)
|
|
|
|
|
{
|
|
|
|
|
return await _rep.ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|