This commit is contained in:
parent
520aaac302
commit
23856bf617
|
|
@ -92,6 +92,8 @@ namespace WGShare.API.Controllers
|
|||
btnAutn.Add(new Claim("account", user.Account));
|
||||
btnAutn.Add(new Claim("uname", user.UserName));
|
||||
btnAutn.Add(new Claim("ssid", user.ScreenShareId));
|
||||
btnAutn.Add(new Claim("year", user.Year.ToString()));
|
||||
btnAutn.Add(new Claim("subject", ((int)user.Subject).ToString()));
|
||||
|
||||
// 获取已登录的token
|
||||
var tokens = RedisHelper.Instance.Get<AccessAndRefreshToken>(RedisKeyConstant.Data.GetAccessTokenKey(user.Id));
|
||||
|
|
@ -165,6 +167,8 @@ namespace WGShare.API.Controllers
|
|||
btnAutn.Add(new Claim("account", user.Account));
|
||||
btnAutn.Add(new Claim("uname", user.UserName));
|
||||
btnAutn.Add(new Claim("ssid", user.ScreenShareId));
|
||||
btnAutn.Add(new Claim("year", user.Year.ToString()));
|
||||
btnAutn.Add(new Claim("subject", ((int)user.Subject).ToString()));
|
||||
|
||||
var accessToken = _jwtHelper.CreateToken(user.Id, btnAutn);
|
||||
var refreshTokenNew = Guid.NewGuid().ToString();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ using WGShare.API.Controllers.Basic;
|
|||
using WGShare.API.Helpers;
|
||||
using WGShare.Domain.DTOs.User;
|
||||
using WGShare.Domain.Entities;
|
||||
using WGShare.Domain.Enums;
|
||||
using WGShare.Domain.FriendlyException;
|
||||
using WGShare.Domain.GeneralModel;
|
||||
using Yitter.IdGenerator;
|
||||
|
|
@ -193,7 +194,14 @@ namespace WGShare.API.Controllers.Backend
|
|||
x.Pwd = x.Pwd.MDString();
|
||||
x.ScreenShareId = UserShareIdHelper.GenerateUnique8DigitNumber();
|
||||
x.TenantId = tenantId;
|
||||
x.RoleId = x.RoleId == "管理员" ? "1" : "2";
|
||||
|
||||
var roleId = "2";
|
||||
if (x.RoleId == "管理员")
|
||||
roleId = "1";
|
||||
else if (x.RoleId == "房间管理员")
|
||||
roleId = "3";
|
||||
x.RoleId = roleId;
|
||||
x.Subject = x.SubjectName.GetEnumValueFromDescription<SubjectType>();
|
||||
});
|
||||
|
||||
await _sqlSugar.Insertable(users).ExecuteCommandAsync();
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace WGShare.API.Controllers.Basic
|
|||
{
|
||||
throw Oops.Oh("用户信息有误,请重新登录");
|
||||
}
|
||||
|
||||
|
||||
return (RoleEnums)role;
|
||||
}
|
||||
}
|
||||
|
|
@ -111,6 +111,43 @@ namespace WGShare.API.Controllers.Basic
|
|||
}
|
||||
}
|
||||
|
||||
private int year = -1;
|
||||
public int Year
|
||||
{
|
||||
get
|
||||
{
|
||||
if (year >= 0)
|
||||
{
|
||||
return year;
|
||||
}
|
||||
|
||||
var year_str = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "year").Value;
|
||||
if (string.IsNullOrWhiteSpace(year_str) || !int.TryParse(year_str, out year))
|
||||
{
|
||||
throw Oops.Oh("用户信息有误,请重新登录");
|
||||
}
|
||||
return year;
|
||||
}
|
||||
}
|
||||
|
||||
private int subject = -1;
|
||||
public SubjectType Subject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (subject >= 0)
|
||||
{
|
||||
return (SubjectType)subject;
|
||||
}
|
||||
|
||||
var subject_str = HttpContext.User.Claims.FirstOrDefault(x => x.Type == "subject").Value;
|
||||
if (string.IsNullOrWhiteSpace(subject_str) || !int.TryParse(subject_str, out subject))
|
||||
{
|
||||
throw Oops.Oh("用户信息有误,请重新登录");
|
||||
}
|
||||
return (SubjectType)subject;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ namespace WGShare.API.Controllers.Frontend
|
|||
|
||||
var list = await _sqlSugar.Queryable<Room>()
|
||||
.Where(x => x.TenantId == TenantId && x.IsDelete == false)
|
||||
.WhereIF(Year > 0, x => x.Year == Year)
|
||||
.WhereIF(Subject > 0, x => x.Subject == Subject)
|
||||
.OrderBy(x => x.Id, OrderByType.Desc)
|
||||
.ToPageListAsync(dto.PageIndex, dto.PageSize, total);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ using WGShare.Domain.Entities;
|
|||
using WGShare.Domain.FriendlyException;
|
||||
using WGShare.Domain.GeneralModel;
|
||||
using Yitter.IdGenerator;
|
||||
using WGShare.Domain.Enums;
|
||||
|
||||
namespace WGShare.API.Controllers.Frontend
|
||||
{
|
||||
|
|
@ -61,7 +62,9 @@ namespace WGShare.API.Controllers.Frontend
|
|||
Account = u.Account,
|
||||
RoleId = r.Id,
|
||||
RoleName = r.RoleName,
|
||||
ScreenShareId = u.ScreenShareId
|
||||
ScreenShareId = u.ScreenShareId,
|
||||
Subject = u.Subject,
|
||||
Year = u.Year,
|
||||
})
|
||||
.ToPageListAsync(pagedBaseDto.PageIndex, pagedBaseDto.PageSize, total);
|
||||
|
||||
|
|
@ -109,7 +112,7 @@ namespace WGShare.API.Controllers.Frontend
|
|||
}
|
||||
|
||||
return await _sqlSugar.Updateable(entity)
|
||||
.UpdateColumns(x => new { x.Account, x.UserName, x.RoleId }).ExecuteCommandAsync() > 0;
|
||||
.UpdateColumns(x => new { x.Account, x.UserName, x.RoleId, x.Year, x.Subject }).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -126,6 +129,21 @@ namespace WGShare.API.Controllers.Frontend
|
|||
.UpdateColumns(x => new { x.Pwd }).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量修改用户信息
|
||||
/// </summary>
|
||||
/// <param name="inputDTO"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("bth")]
|
||||
public async Task<bool> BatchModifyUsers([FromBody] List<UserBatchUpdateDTO> updateDTOs)
|
||||
{
|
||||
var entity = updateDTOs.Adapt<List<User>>();
|
||||
|
||||
return await _sqlSugar.Updateable(entity)
|
||||
.UpdateColumns(x => new { x.RoleId, x.Subject, x.Year }).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
|
|
@ -213,7 +231,7 @@ namespace WGShare.API.Controllers.Frontend
|
|||
else if (x.RoleId == "房间管理员")
|
||||
roleId = "3";
|
||||
x.RoleId = roleId;
|
||||
|
||||
x.Subject = x.SubjectName.GetEnumValueFromDescription<SubjectType>();
|
||||
});
|
||||
|
||||
await _sqlSugar.Insertable(users).ExecuteCommandAsync();
|
||||
|
|
@ -221,5 +239,7 @@ namespace WGShare.API.Controllers.Frontend
|
|||
return Ok((isSuccess: true, url: "", msg: "导入成功"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using MiniExcelLibs;
|
||||
using SqlSugar;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using System.Text.RegularExpressions;
|
||||
using WGShare.API.Controllers.Basic;
|
||||
|
|
@ -11,6 +13,7 @@ using WGShare.API.Helpers;
|
|||
using WGShare.Domain.DTOs.Login;
|
||||
using WGShare.Domain.DTOs.User;
|
||||
using WGShare.Domain.Entities;
|
||||
using WGShare.Domain.Enums;
|
||||
using WGShare.Domain.FriendlyException;
|
||||
|
||||
namespace WGShare.API.Controllers
|
||||
|
|
@ -38,5 +41,33 @@ namespace WGShare.API.Controllers
|
|||
{
|
||||
return await _sqlSugar.Queryable<Role>().Where(x => x.IsDelete == false).ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 科目列表下拉框
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("sub-dp-list"), AllowAnonymous]
|
||||
public async Task<List<SubjectInfo>> GetSubjectDropDownList()
|
||||
{
|
||||
var list = new List<SubjectInfo>();
|
||||
foreach (SubjectType subject in Enum.GetValues(typeof(SubjectType)))
|
||||
{
|
||||
var description = GetEnumDescription(subject);
|
||||
list.Add(new SubjectInfo { Value = (int)subject, Name = description });
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
private string GetEnumDescription(Enum value)
|
||||
{
|
||||
FieldInfo fi = value.GetType().GetField(value.ToString());
|
||||
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
|
||||
if (attributes != null && attributes.Length > 0)
|
||||
return attributes[0].Description;
|
||||
else
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using WGShare.Domain.DTOs.User;
|
||||
using WGShare.Domain.Enums;
|
||||
|
||||
namespace WGShare.API.Helpers
|
||||
{
|
||||
|
|
@ -10,5 +13,38 @@ namespace WGShare.API.Helpers
|
|||
var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
|
||||
return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据描述获取枚举
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="description"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public static T GetEnumValueFromDescription<T>(this string description) where T : Enum
|
||||
{
|
||||
description = description.Trim();
|
||||
foreach (var field in typeof(T).GetFields())
|
||||
{
|
||||
if (Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) is DescriptionAttribute attribute)
|
||||
{
|
||||
if (attribute.Description == description)
|
||||
{
|
||||
return (T)field.GetValue(null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (field.Name == description)
|
||||
{
|
||||
return (T)field.GetValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new ArgumentException($"No matching enum value found for description: {description}", nameof(description));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -315,6 +315,13 @@
|
|||
<param name="inputDTO"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WGShare.API.Controllers.Frontend.UserController.BatchModifyUsers(System.Collections.Generic.List{WGShare.Domain.DTOs.User.UserBatchUpdateDTO})">
|
||||
<summary>
|
||||
批量修改用户信息
|
||||
</summary>
|
||||
<param name="inputDTO"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WGShare.API.Controllers.Frontend.UserController.Delete(System.String[])">
|
||||
<summary>
|
||||
删除用户
|
||||
|
|
@ -340,6 +347,12 @@
|
|||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:WGShare.API.Controllers.PublicController.GetSubjectDropDownList">
|
||||
<summary>
|
||||
科目列表下拉框
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="F:WGShare.API.Helpers.AgoraHelper.Constant.REDIS_CHANNEL_USERCOUNT">
|
||||
<summary>
|
||||
Redis 键,hash ,每个频道用户数量
|
||||
|
|
@ -394,6 +407,15 @@
|
|||
<param name="jsTimestamp">JavaScript 时间戳(以秒为单位)。</param>
|
||||
<returns>对应的本地时间的 DateTime 对象。</returns>
|
||||
</member>
|
||||
<member name="M:WGShare.API.Helpers.EnumExtensions.GetEnumValueFromDescription``1(System.String)">
|
||||
<summary>
|
||||
根据描述获取枚举
|
||||
</summary>
|
||||
<typeparam name="T"></typeparam>
|
||||
<param name="description"></param>
|
||||
<returns></returns>
|
||||
<exception cref="T:System.ArgumentException"></exception>
|
||||
</member>
|
||||
<member name="M:WGShare.API.Helpers.OssHelper.GetUploadUrl(System.String,System.String,System.UInt32)">
|
||||
<summary>
|
||||
获取上传url
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGShare.Domain.DTOs.User
|
||||
{
|
||||
public class SubjectInfo
|
||||
{
|
||||
public int Value { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WGShare.Domain.Entities;
|
||||
using WGShare.Domain.Enums;
|
||||
|
||||
namespace WGShare.Domain.DTOs.User
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户批量修改信息
|
||||
/// </summary>
|
||||
public class UserBatchUpdateDTO
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public int Year { get; set; }
|
||||
public SubjectType Subject { get; set; }
|
||||
public string RoleId { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,16 @@ namespace WGShare.Domain.DTOs.User
|
|||
///</summary>
|
||||
[ExcelColumnName("角色")]
|
||||
public string RoleId{ get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[ExcelColumnName("届")]
|
||||
public int Year { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
///</summary>
|
||||
[ExcelColumnName("科目")]
|
||||
public string SubjectName { get; set; }
|
||||
|
||||
|
||||
[ExcelColumnName("导入结果")]
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WGShare.Domain.Enums;
|
||||
|
||||
namespace WGShare.Domain.DTOs.User
|
||||
{
|
||||
|
|
@ -31,5 +32,15 @@ namespace WGShare.Domain.DTOs.User
|
|||
/// 租户id
|
||||
///</summary>
|
||||
public string? TenantId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 届
|
||||
/// </summary>
|
||||
public int Year { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 科目
|
||||
/// </summary>
|
||||
public SubjectType Subject { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WGShare.Domain.Enums;
|
||||
|
||||
namespace WGShare.Domain.DTOs.User
|
||||
{
|
||||
|
|
@ -29,5 +30,15 @@ namespace WGShare.Domain.DTOs.User
|
|||
/// 共享屏幕ID
|
||||
/// </summary>
|
||||
public string ScreenShareId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 届
|
||||
/// </summary>
|
||||
public int Year { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 科目
|
||||
/// </summary>
|
||||
public SubjectType Subject { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
using WGShare.Domain.Enums;
|
||||
using Yitter.IdGenerator;
|
||||
namespace WGShare.Domain.Entities
|
||||
{
|
||||
|
|
@ -49,5 +50,17 @@ namespace WGShare.Domain.Entities
|
|||
///</summary>
|
||||
[SugarColumn(ColumnName = "room_num")]
|
||||
public string RoomNum { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 届
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "year")]
|
||||
public int Year { get; set; }
|
||||
/// <summary>
|
||||
/// 科目
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "subject")]
|
||||
public SubjectType Subject { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SqlSugar;
|
||||
using WGShare.Domain.Enums;
|
||||
using Yitter.IdGenerator;
|
||||
namespace WGShare.Domain.Entities
|
||||
{
|
||||
|
|
@ -69,6 +70,22 @@ namespace WGShare.Domain.Entities
|
|||
[SugarColumn(ColumnName = "screen_share_id", IsOnlyIgnoreUpdate = true)]
|
||||
public string ScreenShareId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 届
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "year")]
|
||||
public int Year { get; set; }
|
||||
/// <summary>
|
||||
/// 科目
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "subject")]
|
||||
public SubjectType Subject { get; set; }
|
||||
/// <summary>
|
||||
/// 科目名称
|
||||
///</summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string SubjectName { get; set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public string RoleName { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WGShare.Domain.Enums
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public enum SubjectType
|
||||
{
|
||||
/// <summary>
|
||||
/// 全部科目
|
||||
/// </summary>
|
||||
[Description("全部科目")]
|
||||
All = 0,
|
||||
/// <summary>
|
||||
/// 语文
|
||||
/// </summary>
|
||||
[Description("语文")]
|
||||
Chinese = 1,
|
||||
/// <summary>
|
||||
/// 数学
|
||||
/// </summary>
|
||||
[Description("数学")]
|
||||
Math = 2,
|
||||
/// <summary>
|
||||
/// 英语
|
||||
/// </summary>
|
||||
[Description("英语")]
|
||||
English = 3,
|
||||
/// <summary>
|
||||
/// 物理
|
||||
/// </summary>
|
||||
[Description("物理")]
|
||||
Physical = 4,
|
||||
/// <summary>
|
||||
/// 化学
|
||||
/// </summary>
|
||||
[Description("化学")]
|
||||
Chemical = 5,
|
||||
/// <summary>
|
||||
/// 生物
|
||||
/// </summary>
|
||||
[Description("生物")]
|
||||
Biological = 6,
|
||||
/// <summary>
|
||||
/// 政治
|
||||
/// </summary>
|
||||
[Description("政治")]
|
||||
Political = 7,
|
||||
/// <summary>
|
||||
/// 历史
|
||||
/// </summary>
|
||||
[Description("历史")]
|
||||
History = 8,
|
||||
/// <summary>
|
||||
/// 地理
|
||||
/// </summary>
|
||||
[Description("地理")]
|
||||
Geographic = 9
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue