From a414aecac36213fd57c867a4ff16a349c68b6886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Thu, 21 Aug 2025 18:16:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E8=B5=B4=E6=A0=A1?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E8=A7=92=E8=89=B2=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AdminController.cs | 8 +-- .../Controllers/Dto/SchoolBusinessDto.cs | 56 +++++++++------- .../Controllers/ExamClassInfoController.cs | 3 + .../Controllers/MenuController.cs | 5 +- .../Controllers/MenuRelationController.cs | 66 +++++++++++++++++++ .../Controllers/SchoolBusinessController.cs | 33 +++++++--- Learn.Archives.API/Expand/HttpFilter.cs | 11 ++-- Learn.Archives.Core/Common/ClaimEnum.cs | 3 +- Learn.Archives.Core/Common/LiveUserInfo.cs | 8 ++- Learn.Archives.Core/Model/Admin.cs | 2 +- .../Model/Dto/SchoolBusinessDto.cs | 11 +++- Learn.Archives.Core/Model/ExamClassInfo.cs | 12 ++++ Learn.Archives.Core/Model/SchoolBusiness.cs | 2 +- 13 files changed, 167 insertions(+), 53 deletions(-) create mode 100644 Learn.Archives.API/Controllers/MenuRelationController.cs diff --git a/Learn.Archives.API/Controllers/AdminController.cs b/Learn.Archives.API/Controllers/AdminController.cs index b3d5740..08a15a1 100644 --- a/Learn.Archives.API/Controllers/AdminController.cs +++ b/Learn.Archives.API/Controllers/AdminController.cs @@ -48,10 +48,8 @@ namespace Learn.Archives.API.Controllers ? ["*:*:*"] : await menuRelationDB.AsQueryable() .LeftJoin((mr, m) => mr.MenuId == m.Id) - .Where((mr, m) => mr.RoleId == admin.RoleId) - .Select((mr, m) => m) - .Where(m =>m.IsButton) - .Select(m=>m.Auths) + .Where((mr, m) => mr.RoleId == admin.RoleId && m.IsButton) + .Select((mr, m) => m.Auths) .ToArrayAsync(); @@ -65,6 +63,7 @@ namespace Learn.Archives.API.Controllers NickName = admin.Name, AccessToken = JwtHelper.GetToken(AppCommon.Config.AuthKey, [ + new Claim(ClaimEnum.UserCenterRole,"1"),//让所有用户都有用户中心操作权限 new Claim(ClaimEnum.Role,admin.RoleId.ToString()), new Claim(ClaimEnum.UserId,admin.RoleId.ToString()), new Claim(ClaimEnum.Id, admin.Id.ToString()), @@ -73,6 +72,7 @@ namespace Learn.Archives.API.Controllers }; } + public override Task Edit([FromBody] Admin model) { //创建用户时 密码加密 diff --git a/Learn.Archives.API/Controllers/Dto/SchoolBusinessDto.cs b/Learn.Archives.API/Controllers/Dto/SchoolBusinessDto.cs index d23e1da..5adac2d 100644 --- a/Learn.Archives.API/Controllers/Dto/SchoolBusinessDto.cs +++ b/Learn.Archives.API/Controllers/Dto/SchoolBusinessDto.cs @@ -1,77 +1,83 @@ -using MiniExcelLibs.Attributes; +using Learn.Archives.Core.Model; +using MiniExcelLibs.Attributes; namespace Learn.Archives.API.Controllers.Dto { - public class SchoolBusinessDto + public class SchoolBusinessDto: SchoolBusiness { + public string? StartTimeStr => StartTime.ToString("yyyy-MM-dd"); + /// + /// 可以操作数据? + /// + public bool CanOperate { get; set; } } public class SchoolBusinessImportError : SchoolBusinessImport { - [ExcelColumnName("错误信息")] + [ExcelColumn(Name = "错误信息", Width = 50)] public string Error { get; set; } } public class SchoolBusinessImport { - [ExcelColumnName("学校")] + [ExcelColumn(Name = "学校", Width = 15)] public string School { get; set; } - [ExcelColumnName("年级")] + [ExcelColumn(Name = "年级", Width = 15)] public string Grade { get; set; } /// /// 赴校人员 /// 多个,分割 /// - [ExcelColumnName("赴校人员")] + [ExcelColumn(Name = "赴校人员", Width = 27)] public string Users { get; set; } - [ExcelColumnName("赴校时间")] + [ExcelColumn(Name = "赴校时间", Width = 15)] public DateTime StartTime { get; set; } [ExcelColumnName("开展会谈")] - public bool IsDiscussion { get; set; } + public string IsDiscussion { get; set; } - [ExcelColumnName("开展会谈情况")] + [ExcelColumn(Name = "开展会谈情况",Width =27)] public string Discussion { get; set; } [ExcelColumnName("开展班会")] - public bool IsClassMeeting { get; set; } - [ExcelColumnName("开展班会情况")] + public string IsClassMeeting { get; set; } + [ExcelColumn(Name = "开展班会情况", Width = 27)] public string ClassMeeting { get; set; } //----------------------------问题列表 - [ExcelColumnName("[问题]学校领导班子")] + [ExcelColumn(Name = "[问题]学校领导班子", Width = 30)] public string Q学校领导班子 { get; set; } - [ExcelColumnName("[问题]双师课堂")] + [ExcelColumn(Name = "[问题]双师课堂", Width = 30)] public string Q双师课堂 { get; set; } - [ExcelColumnName("[问题]设备")] + [ExcelColumn(Name = "[问题]设备", Width = 30)] public string Q设备 { get; set; } - [ExcelColumnName("[问题]学生")] + [ExcelColumn(Name = "[问题]学生", Width = 30)] public string Q学生 { get; set; } - [ExcelColumnName("[问题]其他")] + [ExcelColumn(Name = "[问题]其他", Width = 30)] public string Q其他 { get; set; } //----------------------------解决办法 - [ExcelColumnName("[解决]学校领导班子")] + [ExcelColumn(Name = "[解决]学校领导班子", Width = 30)] public string P学校领导班子 { get; set; } - [ExcelColumnName("[解决]双师课堂")] + [ExcelColumn(Name = "[解决]双师课堂", Width = 30)] public string P双师课堂 { get; set; } - [ExcelColumnName("[解决]设备")] + [ExcelColumn(Name = "[解决]设备", Width = 30)] public string P设备 { get; set; } - [ExcelColumnName("[解决]学生")] + [ExcelColumn(Name = "[解决]学生", Width = 30)] public string P学生 { get; set; } - [ExcelColumnName("[解决]其他")] + [ExcelColumn(Name = "[解决]其他", Width = 30)] public string P其他 { get; set; } //----------------------------额外需求 - [ExcelColumnName("需求/方案")] + [ExcelColumn(Name = "需求/方案", Width = 30)] public string Solution { get; set; } - [ExcelColumnName("沟通时间/执行记录")] + [ExcelColumn(Name = "沟通时间/执行记录", Width = 30)] public string Record { get; set; } - [ExcelColumnName("完结记录")] + [ExcelColumn(Name = "完结记录", Width = 30)] public string EndRecord { get; set; } - [ExcelColumnName("备注")] + [ExcelColumn(Name = "备注", Width = 40)] public string Remark { get; set; } diff --git a/Learn.Archives.API/Controllers/ExamClassInfoController.cs b/Learn.Archives.API/Controllers/ExamClassInfoController.cs index 30ae640..40e86f3 100644 --- a/Learn.Archives.API/Controllers/ExamClassInfoController.cs +++ b/Learn.Archives.API/Controllers/ExamClassInfoController.cs @@ -169,6 +169,9 @@ namespace Learn.Archives.API.Controllers EntryPersonId = userInfo.Id, BaseSchoolScore = exam.BaseSchoolScore, EntryPerson = userInfo.Name, + TestPaperType = exam.TestPaperType, + Type = exam.Type, + Average1 = exam.BaseSchoolScore, }; insertClassInfo.Add(eCInfo); var avgTotal = 0m; diff --git a/Learn.Archives.API/Controllers/MenuController.cs b/Learn.Archives.API/Controllers/MenuController.cs index dc4624e..cc813fd 100644 --- a/Learn.Archives.API/Controllers/MenuController.cs +++ b/Learn.Archives.API/Controllers/MenuController.cs @@ -49,15 +49,14 @@ namespace Learn.Archives.API.Controllers var rId = userInfo.RoleId; if (rId == 0) Oh.Error("登录了无效的用户"); Menu[] menuArr ; - if (userInfo.RoleId == 1) + if (userInfo.IsSa) menuArr = await baseService.AsQueryable() .Where(m => !m.IsButton).ToArrayAsync(); else menuArr = await menuRelationDB.AsQueryable() .LeftJoin((mr, m) => mr.MenuId == m.Id) - .Where((mr, m) => mr.RoleId == userInfo.RoleId) + .Where((mr, m) => mr.RoleId == userInfo.RoleId && !m.IsButton) .Select((mr, m) => m) - .Where(m=>!m.IsButton) .ToArrayAsync(); return GetChildren(menuArr, 0); } diff --git a/Learn.Archives.API/Controllers/MenuRelationController.cs b/Learn.Archives.API/Controllers/MenuRelationController.cs new file mode 100644 index 0000000..7ac0d44 --- /dev/null +++ b/Learn.Archives.API/Controllers/MenuRelationController.cs @@ -0,0 +1,66 @@ +using Learn.Archives.API.Controllers.Dto; +using Learn.Archives.API.Expand; +using Learn.Archives.Core.Common; +using Learn.Archives.Core.Model; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.Diagnostics; +using System.Security.Claims; +using UserCenter.Model; + +namespace Learn.Archives.API.Controllers +{ + /// + /// 管理员角色控制器 + /// + public class MenuRelationController : BackController + { + readonly Repository roleService; + readonly Repository mrService; + readonly LiveUserInfo userInfo; + public MenuRelationController(Repository baseService, LiveUserInfo userInfo, Repository mrService) : base(mrService) + { + this.roleService = baseService; + this.userInfo = userInfo; + this.mrService = mrService; + } + public class SetMenuInput + { + public long RoleId { get; set; } + public long[] MenuId { get; set; } + } + /// + /// 获取角色菜单ids + /// + /// + [HttpGet] + public async Task RoleMenu(long roleId) + { + if (roleId == 0) Oh.Error("无效的角色"); + if (!userInfo.IsSa) Oh.Error("无权访问"); + var role = roleService.GetByIdAsync(roleId); + if (role == null) Oh.Error("无效的角色"); + return await mrService.AsQueryable() + .Where(s=>s.RoleId==roleId) + .Select(s=>s.MenuId) + .ToArrayAsync(); + } + /// + /// 设置角色菜单 + /// + /// + [HttpPost] + public async Task SetMenu(SetMenuInput input) + { + if (input.MenuId == null || input.MenuId.Length==0) Oh.Error("选择了无可用的菜单"); + if (!userInfo.IsSa) Oh.Error("登录了无效的用户"); + var role = await roleService.GetByIdAsync(input.RoleId); + if (role == null) Oh.Error("无效的角色"); + var insertData= input.MenuId! + .Select(s=>new MenuRelation() {RoleId = role!.Id,MenuId = s }) + .ToArray(); + await mrService.AsDeleteable().Where(s=>s.RoleId == role!.Id).ExecuteCommandAsync(); + return await mrService.InsertRangeAsync(insertData); + } + } +} diff --git a/Learn.Archives.API/Controllers/SchoolBusinessController.cs b/Learn.Archives.API/Controllers/SchoolBusinessController.cs index 16dab34..192bdb8 100644 --- a/Learn.Archives.API/Controllers/SchoolBusinessController.cs +++ b/Learn.Archives.API/Controllers/SchoolBusinessController.cs @@ -4,6 +4,7 @@ using Learn.Archives.Core.Common; using Learn.Archives.Core.Model; using Learn.Archives.Core.Model.Dto; using Learn.Archives.Core.Model.Enum; +using Mapster; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; @@ -24,12 +25,14 @@ namespace Learn.Archives.API.Controllers readonly Repository schoolService; readonly Repository adminService; readonly IHttpContextAccessor accessor; - public SchoolBusinessController(Repository baseService, Repository schoolService, IHttpContextAccessor accessor, Repository adminService) : base(baseService) + readonly LiveUserInfo userInfo; + public SchoolBusinessController(Repository baseService, Repository schoolService, IHttpContextAccessor accessor, Repository adminService, LiveUserInfo userInfo) : base(baseService) { this.baseService = baseService; this.schoolService = schoolService; this.accessor = accessor; this.adminService = adminService; + this.userInfo = userInfo; } public class QueryPageDto @@ -45,7 +48,7 @@ namespace Learn.Archives.API.Controllers /// /// 赴校人员ID /// - public long? UserId { get; set; } + public string? UserName{ get; set; } /// /// 是否查询完结 /// @@ -77,15 +80,18 @@ namespace Learn.Archives.API.Controllers return base.Edit(model); } + public override async Task Info(long id) + { + return (await base.Info(id) as object).Adapt(); + } /// /// 查询 赴校列表 /// /// [HttpPost] - public async Task> QueryPageList(QueryPageDto dto) + public async Task> QueryPageList(QueryPageDto dto) { - var uid = dto.UserId.ToString(); var gInfo = GradeHelper.GetStudentGradeBaseByGrade(dto.Grade); RefAsync total = 0; var resData = await baseService.AsQueryable() @@ -94,13 +100,16 @@ namespace Learn.Archives.API.Controllers .WhereIF(dto.SolutionEnd != null, s => s.SolutionEnd == dto.SolutionEnd) .WhereIF(dto.StartTime != null, s => s.StartTime >= dto.StartTime) .WhereIF(dto.EndTime != null, s => s.StartTime <= dto.EndTime) - .WhereIF(uid != null, s => s.SchoolBusinessUser != null && SqlFunc.JsonLike(s.SchoolBusinessUser, uid)) + .WhereIF(!string.IsNullOrEmpty(dto.UserName), s => s.SchoolBusinessUser != null && SqlFunc.JsonLike(s.SchoolBusinessUser, dto.UserName)) .OrderByDescending(s => s.Id) + .Select() .ToPageListAsync(dto.PageIndex, dto.PageSize, total); - return new PageResult() { Data = resData, Total = total }; + foreach (var item in resData) + item.CanOperate =userInfo.IsSa || (item.SchoolBusinessUser?.Contains(userInfo.Name) ?? false); + return new PageResult() { Data = resData, Total = total }; } - + /// /// 导入考试信息 @@ -157,7 +166,7 @@ namespace Learn.Archives.API.Controllers } var adminArr = await adminService.AsQueryable() .Where(s => adminNameArr.Contains(s.Name)) - .Select(s => s.Id).ToArrayAsync(); + .Select(s => s.Name).ToArrayAsync(); var qStr = new Dictionary() { {FeedbackQuestionTypeEnum.学校领导班子,(imp.Q学校领导班子,imp.P学校领导班子) }, @@ -173,6 +182,8 @@ namespace Learn.Archives.API.Controllers var questionType = kvp.Key; var questions = kvp.Value.Questions; var solutions = kvp.Value.Solutions; + if (string.IsNullOrEmpty(questions) || string.IsNullOrEmpty(solutions)) + continue; // 解析问题 var questionMatches = regex.Matches(questions); var solutionMatches = regex.Matches(solutions); @@ -236,6 +247,8 @@ namespace Learn.Archives.API.Controllers Record = record, } }; + business.SolutionEnd = business.SolutionRecord.EndRecordTime != null; + insertInfo.Add(business); }; @@ -243,7 +256,7 @@ namespace Learn.Archives.API.Controllers return File(errorExcelInfo.ExportExcel(), "application/ms-excel"); //写入数据库 - + await baseService.InsertRangeAsync(insertInfo); return Ok(); } @@ -255,7 +268,7 @@ namespace Learn.Archives.API.Controllers public IActionResult DwImportTemplate() { var resultList = new List() { new SchoolBusinessImport() { } }; - return File(resultList.ExportExcel(), "application/ms-excel"); + return File(resultList.ExportExcel(), "application/ms-excel", "导入赴校信息模板.xlsx"); } diff --git a/Learn.Archives.API/Expand/HttpFilter.cs b/Learn.Archives.API/Expand/HttpFilter.cs index 0b97dc2..f45bb28 100644 --- a/Learn.Archives.API/Expand/HttpFilter.cs +++ b/Learn.Archives.API/Expand/HttpFilter.cs @@ -20,6 +20,7 @@ using Microsoft.AspNetCore.Hosting; using Learn.Archives.Core.Common; using Learn.Archives.Core.Model.Dto; using Learn.Archives.Core.Model; +using SqlSugar.IOC; namespace Learn.Archives.API.Expand { @@ -40,13 +41,11 @@ namespace Learn.Archives.API.Expand /// public class HttpLogAttribute : ActionFilterAttribute, IAsyncExceptionFilter { - readonly Repository logService; readonly LiveUserInfo userInfo; readonly Stopwatch _stopwatch;//统计程序耗时 - public HttpLogAttribute(Repository logService, LiveUserInfo userInfo) + public HttpLogAttribute( LiveUserInfo userInfo) { - this.logService = logService; _stopwatch = Stopwatch.StartNew(); this.userInfo = userInfo; } @@ -174,7 +173,7 @@ namespace Learn.Archives.API.Expand } } //写入队列 - await logService.InsertAsync(new HttpLog + await DbScoped.Sugar.Insertable(new HttpLog { Id = logId, Url = context.Request.Path + context.Request.QueryString, @@ -188,9 +187,9 @@ namespace Learn.Archives.API.Expand : string.Empty, Exception = e?.ToString(), ExceptionMessage = e?.Message, - AdminId = userInfo.Id , + AdminId = userInfo.Id, TotalMilliseconds = (double)_stopwatch.Elapsed.TotalMilliseconds - }); + }).ExecuteCommandAsync(); } diff --git a/Learn.Archives.Core/Common/ClaimEnum.cs b/Learn.Archives.Core/Common/ClaimEnum.cs index e456ae0..01ee0b8 100644 --- a/Learn.Archives.Core/Common/ClaimEnum.cs +++ b/Learn.Archives.Core/Common/ClaimEnum.cs @@ -6,7 +6,8 @@ public static string PositionId => "position"; public static string UserId => "user"; public static string Id => "id"; - public static string Role => "role"; + public static string UserCenterRole => "role"; + public static string Role => "role1"; public static string Scope => "scope"; public static string Name => "name"; } diff --git a/Learn.Archives.Core/Common/LiveUserInfo.cs b/Learn.Archives.Core/Common/LiveUserInfo.cs index 67eefd9..e8428e2 100644 --- a/Learn.Archives.Core/Common/LiveUserInfo.cs +++ b/Learn.Archives.Core/Common/LiveUserInfo.cs @@ -36,7 +36,13 @@ namespace Learn.Archives.Core.Common { get => long.Parse(_httpContextAccessor.HttpContext?.User.FindFirst(ClaimEnum.Role)?.Value ?? "0"); } - + /// + /// 是超管? + /// + public bool IsSa + { + get => RoleId == 1; + } /// /// 管理员id /// diff --git a/Learn.Archives.Core/Model/Admin.cs b/Learn.Archives.Core/Model/Admin.cs index 7af3047..442e21f 100644 --- a/Learn.Archives.Core/Model/Admin.cs +++ b/Learn.Archives.Core/Model/Admin.cs @@ -16,7 +16,7 @@ namespace Learn.Archives.Core.Model public class Admin : EntityBaseId, IDB { /// - /// 账号 + /// 名称 /// [SugarColumn(Length = 12)] public string Name { get; set; } diff --git a/Learn.Archives.Core/Model/Dto/SchoolBusinessDto.cs b/Learn.Archives.Core/Model/Dto/SchoolBusinessDto.cs index 764c0c6..aecc8d9 100644 --- a/Learn.Archives.Core/Model/Dto/SchoolBusinessDto.cs +++ b/Learn.Archives.Core/Model/Dto/SchoolBusinessDto.cs @@ -28,6 +28,8 @@ namespace Learn.Archives.Core.Model.Dto /// 添加完结时间 /// public DateTime? EndRecordTime { get; set; } + public string? ExecutionTimeStr => EndRecordTime?.ToString("yyyy-MM-dd"); + /// /// 执行记录 @@ -48,8 +50,10 @@ namespace Learn.Archives.Core.Model.Dto /// 执行时间 /// public DateTime? ExecutionTime { get; set; } + public string? ExecutionTimeStr => ExecutionTime?.ToString("yyyy-MM-dd"); - } + + } /// @@ -78,6 +82,9 @@ namespace Learn.Archives.Core.Model.Dto /// 解决时间 /// public DateTime? EndTime { get; set; } + public string? EndTimeStr=> EndTime?.ToString("yyyy-MM-dd"); + + } /// @@ -97,5 +104,7 @@ namespace Learn.Archives.Core.Model.Dto /// 解决时间 /// public DateTime? EndTime { get; set; } + public string? EndTimeStr => EndTime?.ToString("yyyy-MM-dd"); + } } diff --git a/Learn.Archives.Core/Model/ExamClassInfo.cs b/Learn.Archives.Core/Model/ExamClassInfo.cs index d687b31..1f2a9bf 100644 --- a/Learn.Archives.Core/Model/ExamClassInfo.cs +++ b/Learn.Archives.Core/Model/ExamClassInfo.cs @@ -31,12 +31,24 @@ namespace Learn.Archives.Core.Model /// 考试班级id /// public long ClassId { get; set; } + /// /// 考试班级名称 /// [SugarColumn(Length = 20)] public string ClassName { get; set; } + + /// + /// 试卷类型 + /// + public TestPaperTypeEnum TestPaperType { get; set; } + + /// + /// 考试类型 + /// + public ExamTypeEnum Type { get; set; } + /// /// 考试班级所属学校ID /// diff --git a/Learn.Archives.Core/Model/SchoolBusiness.cs b/Learn.Archives.Core/Model/SchoolBusiness.cs index e4f3d05..a181514 100644 --- a/Learn.Archives.Core/Model/SchoolBusiness.cs +++ b/Learn.Archives.Core/Model/SchoolBusiness.cs @@ -48,7 +48,7 @@ namespace Learn.Archives.Core.Model /// 赴校人员 逗号分隔 /// [SugarColumn(IsNullable = true, IsJson = true)] - public long[]? SchoolBusinessUser { get; set; } + public string[]? SchoolBusinessUser { get; set; } /// /// 赴校时间 ///