You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
Tiobon.Web.Core/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs

158 lines
6.4 KiB

using Tiobon.Core.IServices;
using Tiobon.Core.Model.Models;
using Tiobon.Core.Services.BASE;
using Tiobon.Core.IRepository.Base;
using Tiobon.Core.Common.Caches;
using Newtonsoft.Json.Linq;
using Tiobon.Core.Common;
using Tiobon.Core.Model;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
namespace Tiobon.Core.Services;
/// <summary>
/// 考试记录 (服务)
/// </summary>
public class Ghre_ExamRecordServices : BaseServices<Ghre_ExamRecord, Ghre_ExamRecordDto, InsertGhre_ExamRecordInput, EditGhre_ExamRecordInput>, IGhre_ExamRecordServices
{
private readonly IBaseRepository<Ghre_ExamRecord> _dal;
//private readonly IGhre_ExamPaperServices _ghre_ExamPaperServices;
public Ghre_ExamRecordServices(ICaching caching,
//IGhre_ExamPaperServices ghre_ExamPaperServices,
IBaseRepository<Ghre_ExamRecord> dal)
{
this._dal = dal;
base.BaseDal = dal;
base._caching = caching;
//_ghre_ExamPaperServices = ghre_ExamPaperServices;
}
public override async Task<ServicePageResult<Ghre_ExamRecordDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true)
{
if (string.IsNullOrWhiteSpace(filter.orderBy))
filter.orderBy = "CreateTime1 DESC";
if (filter.pageSize == 0)
filter.pageSize = 10000;
var countSql = @$" SELECT COUNT(1) FROM Ghre_ExamRecord_V";
var sql = @$" SELECT *
FROM Ghre_ExamRecord_V";
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 (name == "DueDate")
{
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(value);
conditions += $" AND FORMAT(DueDate, 'yyyy-MM-dd') = '{jsonParam.columnValue}'";
continue;
}
if (!string.IsNullOrWhiteSpace(value))
{
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(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;
}
}
}
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 += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize;
var entitys = await Db.Ado.SqlQueryAsync<Ghre_ExamRecordDto>(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 ? "合格" : "不合格";
//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");
});
return new ServicePageResult<Ghre_ExamRecordDto>(filter.pageNum, total, filter.pageSize, entitys);
}
public async Task<ServicePageResult<Ghre_ExamRecordDto>> Query(string examId, QueryBody body)
{
return await QueryFilterPage(body, $"ExamId='{examId}'");
}
public async Task<ServiceResult> ModifyAdjustScore(string examRecordId, EditGhre_ExamRecordInput edit)
{
var entity = await QuerySingle(examRecordId);
var paper = await Db.Queryable<Ghre_ExamPaper>().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}'");
}
}