From a2349c8e9b49f246ea11fefe487dae64e1851095 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Fri, 5 Jul 2024 16:20:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=B0=83=E6=95=B4=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ghre/Ghre_ExamRecordController.cs | 6 + Tiobon.Core.IServices/BASE/IBaseServices.cs | 3 +- .../Ghre/IGhre_ExamRecordServices.cs | 2 + Tiobon.Core.Services/BASE/BaseServices.cs | 15 +- Tiobon.Core.Services/CommonServices.cs | 2 + .../Ghre/Ghre_ExamRecordServices.cs | 209 ++++++++++-------- 6 files changed, 142 insertions(+), 95 deletions(-) diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamRecordController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamRecordController.cs index 08c0f547..b780cd8e 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamRecordController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_ExamRecordController.cs @@ -27,4 +27,10 @@ public class Ghre_ExamRecordController : BaseController ModifyAdjustScore(string examRecordId, [FromBody] EditGhre_ExamRecordInput edit) + { + return await _service.ModifyAdjustScore(examRecordId, edit); + } } \ No newline at end of file diff --git a/Tiobon.Core.IServices/BASE/IBaseServices.cs b/Tiobon.Core.IServices/BASE/IBaseServices.cs index 35a4aeb9..a804e022 100644 --- a/Tiobon.Core.IServices/BASE/IBaseServices.cs +++ b/Tiobon.Core.IServices/BASE/IBaseServices.cs @@ -130,7 +130,8 @@ namespace Tiobon.Core.IServices.BASE Task> Query(Expression> whereExpression); Task> QueryDto(Expression> whereExpression); - + Task QuerySingle(object objId); + Task QuerySingle(Expression> whereExpression); Task QuerySingleDto(Expression> whereExpression); Task> Query(Expression> whereExpression, string orderByFields); Task> Query(Expression> expression); diff --git a/Tiobon.Core.IServices/Ghre/IGhre_ExamRecordServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_ExamRecordServices.cs index 997de2ef..270a5a44 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_ExamRecordServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_ExamRecordServices.cs @@ -11,5 +11,7 @@ namespace Tiobon.Core.IServices public interface IGhre_ExamRecordServices :IBaseServices { Task> Query(string examId, QueryBody body); + + Task ModifyAdjustScore(string examRecordId, EditGhre_ExamRecordInput edit); } } \ No newline at end of file diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 1d52dfb6..fb636a58 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -573,11 +573,22 @@ public class BaseServices : IBaseServ var data = await BaseDal.Query(whereExpression); return Mapper.Map(data).ToANew>(); } - - public async Task QuerySingleDto(Expression> whereExpression) + public virtual async Task QuerySingle(object objId) + { + var entity = await BaseDal.QueryById(objId); + return entity; + } + public async Task QuerySingle(Expression> whereExpression) { var entitys = await BaseDal.Query(whereExpression); var entity = entitys.FirstOrDefault(); + if (entity == null) + return default; + else return entity; + } + public async Task QuerySingleDto(Expression> whereExpression) + { + var entity = await QuerySingle(whereExpression); if (entity == null) return default; else return Mapper.Map(entity).ToANew(); diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index e3aa1378..afbe5cc9 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -1062,6 +1062,8 @@ public partial class CommonServices : BaseServices>, ICommon case "F_OnlineExamScores": result.DT_Procedure.QueryProcedure = dt.Rows[0]["QueryProcedure"].ToString(); result.DT_Procedure.QueryProcedure += "/" + param.jsonParam.MasterId; + toolbar = result.JM_PageControlT1.Toolbar.Where(x => x.fnKey == "DetailYN").FirstOrDefault(); + if (toolbar != null) { toolbar.fnKey = "TBD3YN"; } sql = $@"SELECT A.RoleId, B.RoleNo, B.RoleName FROM Ghrs_UserRole A LEFT JOIN Ghrs_Role B ON A.RoleId = B.RoleId diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs index 61080c9e..b26af797 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs @@ -8,126 +8,151 @@ using Newtonsoft.Json.Linq; using Tiobon.Core.Common; using Tiobon.Core.Model; using Newtonsoft.Json; -using Microsoft.AspNetCore.Mvc; +using System.Text.RegularExpressions; -namespace Tiobon.Core.Services +namespace Tiobon.Core.Services; + +/// +/// 考试记录 (服务) +/// +public class Ghre_ExamRecordServices : BaseServices, IGhre_ExamRecordServices { - /// - /// 考试记录 (服务) - /// - public class Ghre_ExamRecordServices : BaseServices, IGhre_ExamRecordServices + private readonly IBaseRepository _dal; + //private readonly IGhre_ExamPaperServices _ghre_ExamPaperServices; + public Ghre_ExamRecordServices(ICaching caching, + //IGhre_ExamPaperServices ghre_ExamPaperServices, + IBaseRepository dal) { - private readonly IBaseRepository _dal; - public Ghre_ExamRecordServices(ICaching caching, IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - base._caching = caching; - } + this._dal = dal; + base.BaseDal = dal; + base._caching = caching; + //_ghre_ExamPaperServices = ghre_ExamPaperServices; + } - public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) - { - if (string.IsNullOrWhiteSpace(filter.orderBy)) - filter.orderBy = "CreateTime1 DESC"; + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + { + if (string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "CreateTime1 DESC"; - if (filter.pageSize == 0) - filter.pageSize = 10000; + if (filter.pageSize == 0) + filter.pageSize = 10000; - var countSql = @$" SELECT COUNT(1) FROM Ghre_ExamRecord_V"; - var sql = @$" SELECT * + var countSql = @$" SELECT COUNT(1) FROM Ghre_ExamRecord_V"; + var sql = @$" SELECT * FROM Ghre_ExamRecord_V"; - string conditions = " WHERE IsEnable = 1"; + string conditions = " WHERE IsEnable = 1"; + + if (!string.IsNullOrEmpty(condition)) conditions += " AND " + condition; + if (filter.jsonParam != null) + foreach (JProperty jProperty in filter.jsonParam.Properties()) + { + var name = jProperty.Name; + var value = jProperty.Value.ToString(); + if (name == "page" || name == "pageSize") + continue; - if (!string.IsNullOrEmpty(condition)) conditions += " AND " + condition; - if (filter.jsonParam != null) - foreach (JProperty jProperty in filter.jsonParam.Properties()) + if (name == "DueDate") { - var name = jProperty.Name; - var value = jProperty.Value.ToString(); - if (name == "page" || name == "pageSize") - continue; + var jsonParam = JsonConvert.DeserializeObject(value); + conditions += $" AND FORMAT(DueDate, 'yyyy-MM-dd') = '{jsonParam.columnValue}'"; + continue; - if (name == "DueDate") - { - var jsonParam = JsonConvert.DeserializeObject(value); - conditions += $" AND FORMAT(DueDate, 'yyyy-MM-dd') = '{jsonParam.columnValue}'"; - continue; + } + if (!string.IsNullOrWhiteSpace(value)) + { + var jsonParam = JsonConvert.DeserializeObject(value); - } - if (!string.IsNullOrWhiteSpace(value)) + switch (jsonParam.operationKey) { - var jsonParam = JsonConvert.DeserializeObject(value); - - switch (jsonParam.operationKey) - { - case "Include": - conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; - break; - case "NotInclude": - conditions += $" AND {name} NOT LIKE '%{jsonParam.columnValue}%'"; - break; - case "IsNull": - conditions += $" AND {name} IS NULL"; - break; - case "NotNull": - conditions += $" AND {name} IS NOT NULL"; - break; - case "Equal": - conditions += $" AND {name} ='{jsonParam.columnValue}'"; - break; - case "NotEqual": - conditions += $" AND {name} !='{jsonParam.columnValue}'"; - break; - default: - break; - } + case "Include": + conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; + break; + case "NotInclude": + conditions += $" AND {name} NOT LIKE '%{jsonParam.columnValue}%'"; + break; + case "IsNull": + conditions += $" AND {name} IS NULL"; + break; + case "NotNull": + conditions += $" AND {name} IS NOT NULL"; + break; + case "Equal": + conditions += $" AND {name} ='{jsonParam.columnValue}'"; + break; + case "NotEqual": + conditions += $" AND {name} !='{jsonParam.columnValue}'"; + break; + default: + break; } } + } - sql += conditions; - countSql += conditions; - int total = await Db.Ado.GetIntAsync(countSql); + sql += conditions; + countSql += conditions; + int total = await Db.Ado.GetIntAsync(countSql); - sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; - sql += ") A ) B ) C"; + sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; + sql += ") A ) B ) C"; - sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; + sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; - var entitys = await Db.Ado.SqlQueryAsync(sql); + var entitys = await Db.Ado.SqlQueryAsync(sql); - entitys.ForEach(async x => - { - x.ScoreStatus = await GetParaLabel("TrainingExamScoreStatus", x.ScoreStatus); - //x.CourseStatusLabel = await GetParaLabel("TrainingCourseStatus", x.CourseStatus); - //x.StudyStatusLabel = await GetParaLabel("TrainingStudyStatus", x.StudyStatus); - x.IsPassLabel = x.IsPass == true ? "合格" : "不合格"; + entitys.ForEach(async x => + { + x.ScoreStatus = await GetParaLabel("TrainingExamScoreStatus", x.ScoreStatus); + //x.CourseStatusLabel = await GetParaLabel("TrainingCourseStatus", x.CourseStatus); + //x.StudyStatusLabel = await GetParaLabel("TrainingStudyStatus", x.StudyStatus); + x.IsPassLabel = x.IsPass == true ? "合格" : "不合格"; - //x.InStatusLabel = x.InStatus == "1" ? "在职" : null; - //x.InStatusLabel = x.InStatus == "2" ? "离职" : null; - //x.InStatusLabel = x.InStatus == "0" ? "未入职" : null; - if (x.BeginTime != null) - x.ExamDate = x.BeginTime.Value.ToString("yyyy-MM-dd"); + //x.InStatusLabel = x.InStatus == "1" ? "在职" : null; + //x.InStatusLabel = x.InStatus == "2" ? "离职" : null; + //x.InStatusLabel = x.InStatus == "0" ? "未入职" : null; + if (x.BeginTime != null) + x.ExamDate = x.BeginTime.Value.ToString("yyyy-MM-dd"); - x.TotalScore += x.Score ?? 0; - x.TotalScore += x.AdjustScore ?? 0; - //if (x.DueDate != null) - // x.DueDate1 = x.DueDate.Value.ToString("yyyy-MM-dd"); - //if (x.ExamDate != null) - // x.ExamDate1 = x.ExamDate.Value.ToString("yyyy-MM-dd"); + x.TotalScore += x.Score ?? 0; + x.TotalScore += x.AdjustScore ?? 0; + //if (x.DueDate != null) + // x.DueDate1 = x.DueDate.Value.ToString("yyyy-MM-dd"); + //if (x.ExamDate != null) + // x.ExamDate1 = x.ExamDate.Value.ToString("yyyy-MM-dd"); - }); + }); - return new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); + return new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); - } + } + public async Task> Query(string examId, QueryBody body) + { + return await QueryFilterPage(body, $"ExamId='{examId}'"); + } + public async Task ModifyAdjustScore(string examRecordId, EditGhre_ExamRecordInput edit) + { + var entity = await QuerySingle(examRecordId); - public async Task> Query(string examId, [FromBody] QueryBody body) - { - return await QueryFilterPage(body, $"ExamId='{examId}'"); - } + var paper = await Db.Queryable().FirstAsync(x => x.Id == entity.ExamPaperId); + if (paper == null) + return ServiceResult.OprateFailed("该考试管理的试卷已被删除,暂不可变更调整分!"); + + entity.AdjustScore = edit.AdjustScore; + entity.Score += entity.AdjustScore; + + string score1 = Regex.Replace(entity.Score.ToString(), @"\.(0+)$", "") + "/" + Regex.Replace(entity.Score.ToString(), @"\.(0+)$", ""); + if (entity.Score < 0) + return ServiceResult.OprateFailed($"调整后得分为【{score1}】,得分不可小于0!"); + if (entity.Score > paper.TotalScore) + return ServiceResult.OprateFailed($"调整后得分为【{score1}】,不可大于卷面总分【{Regex.Replace(paper.TotalScore.ToString(), @"\.(0+)$", "") + "/" + Regex.Replace(paper.TotalScore.ToString(), @"\.(0+)$", "")}】!"); + + await Update(entity); + + return ServiceResult.OprateSuccess("修改成功!"); + + //return await QueryFilterPage(body, $"ExamId='{examId}'"); } } \ No newline at end of file