diff --git a/WGShare.API/Controllers/AuthController.cs b/WGShare.API/Controllers/AuthController.cs index f0b40ac..c6532c6 100644 --- a/WGShare.API/Controllers/AuthController.cs +++ b/WGShare.API/Controllers/AuthController.cs @@ -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(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(); diff --git a/WGShare.API/Controllers/Backend/UserController.cs b/WGShare.API/Controllers/Backend/UserController.cs index 8f3ce7c..c3b9ea1 100644 --- a/WGShare.API/Controllers/Backend/UserController.cs +++ b/WGShare.API/Controllers/Backend/UserController.cs @@ -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(); }); await _sqlSugar.Insertable(users).ExecuteCommandAsync(); diff --git a/WGShare.API/Controllers/Basic/BasicController.cs b/WGShare.API/Controllers/Basic/BasicController.cs index 83160b1..6614270 100644 --- a/WGShare.API/Controllers/Basic/BasicController.cs +++ b/WGShare.API/Controllers/Basic/BasicController.cs @@ -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; + } + } } } diff --git a/WGShare.API/Controllers/Frontend/HomeController.cs b/WGShare.API/Controllers/Frontend/HomeController.cs index 9f62e2f..3f56a75 100644 --- a/WGShare.API/Controllers/Frontend/HomeController.cs +++ b/WGShare.API/Controllers/Frontend/HomeController.cs @@ -63,6 +63,8 @@ namespace WGShare.API.Controllers.Frontend var list = await _sqlSugar.Queryable() .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); diff --git a/WGShare.API/Controllers/Frontend/UserController.cs b/WGShare.API/Controllers/Frontend/UserController.cs index acf3e7e..2e01ebc 100644 --- a/WGShare.API/Controllers/Frontend/UserController.cs +++ b/WGShare.API/Controllers/Frontend/UserController.cs @@ -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; } /// @@ -126,6 +129,21 @@ namespace WGShare.API.Controllers.Frontend .UpdateColumns(x => new { x.Pwd }).ExecuteCommandAsync() > 0; } + /// + /// 批量修改用户信息 + /// + /// + /// + [HttpPut("bth")] + public async Task BatchModifyUsers([FromBody] List updateDTOs) + { + var entity = updateDTOs.Adapt>(); + + return await _sqlSugar.Updateable(entity) + .UpdateColumns(x => new { x.RoleId, x.Subject, x.Year }).ExecuteCommandAsync() > 0; + } + + /// /// 删除用户 /// @@ -213,7 +231,7 @@ namespace WGShare.API.Controllers.Frontend else if (x.RoleId == "房间管理员") roleId = "3"; x.RoleId = roleId; - + x.Subject = x.SubjectName.GetEnumValueFromDescription(); }); await _sqlSugar.Insertable(users).ExecuteCommandAsync(); @@ -221,5 +239,7 @@ namespace WGShare.API.Controllers.Frontend return Ok((isSuccess: true, url: "", msg: "导入成功")); } + + } } diff --git a/WGShare.API/Controllers/PublicController.cs b/WGShare.API/Controllers/PublicController.cs index 2cbcdd4..78fff28 100644 --- a/WGShare.API/Controllers/PublicController.cs +++ b/WGShare.API/Controllers/PublicController.cs @@ -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().Where(x => x.IsDelete == false).ToListAsync(); } + + /// + /// 科目列表下拉框 + /// + /// + [HttpGet("sub-dp-list"), AllowAnonymous] + public async Task> GetSubjectDropDownList() + { + var list = new List(); + 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(); + } } } diff --git a/WGShare.API/Helpers/EnumExtensions.cs b/WGShare.API/Helpers/EnumExtensions.cs index 5e2dbd8..0b75b89 100644 --- a/WGShare.API/Helpers/EnumExtensions.cs +++ b/WGShare.API/Helpers/EnumExtensions.cs @@ -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; } + + /// + /// 根据描述获取枚举 + /// + /// + /// + /// + /// + public static T GetEnumValueFromDescription(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)); + } + + } } diff --git a/WGShare.API/WGShare.API.xml b/WGShare.API/WGShare.API.xml index 6cbbd4f..2ebda6e 100644 --- a/WGShare.API/WGShare.API.xml +++ b/WGShare.API/WGShare.API.xml @@ -315,6 +315,13 @@ + + + 批量修改用户信息 + + + + 删除用户 @@ -340,6 +347,12 @@ + + + 科目列表下拉框 + + + Redis 键,hash ,每个频道用户数量 @@ -394,6 +407,15 @@ JavaScript 时间戳(以秒为单位)。 对应的本地时间的 DateTime 对象。 + + + 根据描述获取枚举 + + + + + + 获取上传url diff --git a/WGShare.Domain/DTOs/User/SubjectInfo.cs b/WGShare.Domain/DTOs/User/SubjectInfo.cs new file mode 100644 index 0000000..43919fa --- /dev/null +++ b/WGShare.Domain/DTOs/User/SubjectInfo.cs @@ -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; } + } +} diff --git a/WGShare.Domain/DTOs/User/UserBatchUpdateDTO.cs b/WGShare.Domain/DTOs/User/UserBatchUpdateDTO.cs new file mode 100644 index 0000000..405b24b --- /dev/null +++ b/WGShare.Domain/DTOs/User/UserBatchUpdateDTO.cs @@ -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 +{ + /// + /// 用户批量修改信息 + /// + public class UserBatchUpdateDTO + { + public string Id { get; set; } + + public int Year { get; set; } + public SubjectType Subject { get; set; } + public string RoleId { get; set; } + } +} diff --git a/WGShare.Domain/DTOs/User/UserExcelInputDto.cs b/WGShare.Domain/DTOs/User/UserExcelInputDto.cs index a57ac60..62bf339 100644 --- a/WGShare.Domain/DTOs/User/UserExcelInputDto.cs +++ b/WGShare.Domain/DTOs/User/UserExcelInputDto.cs @@ -29,6 +29,16 @@ namespace WGShare.Domain.DTOs.User /// [ExcelColumnName("角色")] public string RoleId{ get; set; } + /// + /// + /// + [ExcelColumnName("届")] + public int Year { get; set; } + /// + /// + /// + [ExcelColumnName("科目")] + public string SubjectName { get; set; } [ExcelColumnName("导入结果")] diff --git a/WGShare.Domain/DTOs/User/UserInputDTO.cs b/WGShare.Domain/DTOs/User/UserInputDTO.cs index b003ca3..6d55bfc 100644 --- a/WGShare.Domain/DTOs/User/UserInputDTO.cs +++ b/WGShare.Domain/DTOs/User/UserInputDTO.cs @@ -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 /// public string? TenantId { get; set; } + + /// + /// 届 + /// + public int Year { get; set; } + + /// + /// 科目 + /// + public SubjectType Subject { get; set; } } } diff --git a/WGShare.Domain/DTOs/User/UserOutputDTO.cs b/WGShare.Domain/DTOs/User/UserOutputDTO.cs index 3a2dc2e..b7258ce 100644 --- a/WGShare.Domain/DTOs/User/UserOutputDTO.cs +++ b/WGShare.Domain/DTOs/User/UserOutputDTO.cs @@ -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 /// public string ScreenShareId { get; set; } + + /// + /// 届 + /// + public int Year { get; set; } + + /// + /// 科目 + /// + public SubjectType Subject { get; set; } } } diff --git a/WGShare.Domain/Entities/Room.cs b/WGShare.Domain/Entities/Room.cs index 0afb85e..70de651 100644 --- a/WGShare.Domain/Entities/Room.cs +++ b/WGShare.Domain/Entities/Room.cs @@ -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 /// [SugarColumn(ColumnName = "room_num")] public string RoomNum { get; set; } + + + /// + /// 届 + /// + [SugarColumn(ColumnName = "year")] + public int Year { get; set; } + /// + /// 科目 + /// + [SugarColumn(ColumnName = "subject")] + public SubjectType Subject { get; set; } } } diff --git a/WGShare.Domain/Entities/User.cs b/WGShare.Domain/Entities/User.cs index 6baff77..71a45b2 100644 --- a/WGShare.Domain/Entities/User.cs +++ b/WGShare.Domain/Entities/User.cs @@ -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; } + /// + /// 届 + /// + [SugarColumn(ColumnName = "year")] + public int Year { get; set; } + /// + /// 科目 + /// + [SugarColumn(ColumnName = "subject")] + public SubjectType Subject { get; set; } + /// + /// 科目名称 + /// + [SugarColumn(IsIgnore = true)] + public string SubjectName { get; set; } + [SugarColumn(IsIgnore = true)] public string RoleName { get; set; } diff --git a/WGShare.Domain/Enums/SubjectType.cs b/WGShare.Domain/Enums/SubjectType.cs new file mode 100644 index 0000000..174dbf7 --- /dev/null +++ b/WGShare.Domain/Enums/SubjectType.cs @@ -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 +{ + /// + /// + /// + public enum SubjectType + { + /// + /// 全部科目 + /// + [Description("全部科目")] + All = 0, + /// + /// 语文 + /// + [Description("语文")] + Chinese = 1, + /// + /// 数学 + /// + [Description("数学")] + Math = 2, + /// + /// 英语 + /// + [Description("英语")] + English = 3, + /// + /// 物理 + /// + [Description("物理")] + Physical = 4, + /// + /// 化学 + /// + [Description("化学")] + Chemical = 5, + /// + /// 生物 + /// + [Description("生物")] + Biological = 6, + /// + /// 政治 + /// + [Description("政治")] + Political = 7, + /// + /// 历史 + /// + [Description("历史")] + History = 8, + /// + /// 地理 + /// + [Description("地理")] + Geographic = 9 + } + +}