|
|
@ -14,6 +14,7 @@ using SqlSugar; |
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Tiobon.Core.Common.UserManager; |
|
|
|
using Tiobon.Core.Common.UserManager; |
|
|
|
|
|
|
|
using MathNet.Numerics.Distributions; |
|
|
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
|
|
@ -287,17 +288,32 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(status)) |
|
|
|
|
|
|
|
conditions += $" AND Status ='{status}'"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sql += " WHERE " + conditions; |
|
|
|
if (filter.pageSize == 0) |
|
|
|
if (filter.pageSize == 0) |
|
|
|
filter.pageSize = 10000; |
|
|
|
filter.pageSize = 10000; |
|
|
|
var data = await Db.SqlQueryable<Ghre_ExamDto>(sql) |
|
|
|
var data = await Db.SqlQueryable<Ghre_ExamDto>(sql) |
|
|
|
.OrderBy(filter.orderBy) |
|
|
|
.OrderBy(filter.orderBy) |
|
|
|
.ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); |
|
|
|
.ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); |
|
|
|
|
|
|
|
|
|
|
|
//data.ForEach(async x => |
|
|
|
data.ForEach(x => |
|
|
|
//{ |
|
|
|
{ |
|
|
|
// x.DifficultyLevelLabel = await GetParaLabel("DifficultyLevel", x.DifficultyLevel); |
|
|
|
x.ExamName = x.ExamName + "(" + x.ExamNo + ")"; |
|
|
|
// x.QuestionTypeLabel = await GetParaLabel("QuestionType", x.QuestionType); |
|
|
|
|
|
|
|
//}); |
|
|
|
if (x.Status == "Released" || x.Status == "Disabled") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
x.canEdit = 0; |
|
|
|
|
|
|
|
x.canDelete = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (x.Status == "Disabled") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
x.canClose = 0; |
|
|
|
|
|
|
|
x.canPreview = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return new ServicePageResult<Ghre_ExamDto>(filter.pageNum, totalCount, filter.pageSize, data); |
|
|
|
return new ServicePageResult<Ghre_ExamDto>(filter.pageNum, totalCount, filter.pageSize, data); |
|
|
|
} |
|
|
|
} |
|
|
@ -554,6 +570,15 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
if (pageData.AfterHowLong == 0) |
|
|
|
if (pageData.AfterHowLong == 0) |
|
|
|
pageData.AfterHowLong = pageData.AfterHowLong1; |
|
|
|
pageData.AfterHowLong = pageData.AfterHowLong1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(pageData.CoverUrl)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var course = await Db.Queryable<Ghre_ExamPaper>().Where(it => it.Id == pageData.ExamPaperId).FirstAsync(); |
|
|
|
|
|
|
|
pageData.CoverUrl = course?.CoverUrl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(pageData.ExamNo)) |
|
|
|
|
|
|
|
pageData.ExamNo = await GenerateContinuousSequence(); |
|
|
|
|
|
|
|
|
|
|
|
if (id == 0) |
|
|
|
if (id == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (string.IsNullOrEmpty(pageData.Status)) |
|
|
|
if (string.IsNullOrEmpty(pageData.Status)) |
|
|
@ -561,6 +586,7 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
var insert = Mapper.Map(pageData).ToANew<InsertGhre_ExamInput>(); |
|
|
|
var insert = Mapper.Map(pageData).ToANew<InsertGhre_ExamInput>(); |
|
|
|
id = await base.Add(insert); |
|
|
|
id = await base.Add(insert); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var insertStaffs = pageData.staffTableData.Select(x => new InsertGhre_ExamStaffInput() |
|
|
|
var insertStaffs = pageData.staffTableData.Select(x => new InsertGhre_ExamStaffInput() |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExamId = id, |
|
|
|
ExamId = id, |
|
|
@ -570,10 +596,18 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
|
|
|
|
|
|
|
await _ghre_ExamStaffServices.Add(insertStaffs); |
|
|
|
await _ghre_ExamStaffServices.Add(insertStaffs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Db.Updateable<Ghre_ExamPaper>().SetColumns(it => it.LinkTimes == it.LinkTimes + 1).Where(it => it.Id == insert.ExamPaperId).ExecuteCommand(); |
|
|
|
|
|
|
|
|
|
|
|
return ServiceResult<long>.OprateSuccess("添加成功!", id); |
|
|
|
return ServiceResult<long>.OprateSuccess("添加成功!", id); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
var exam = await base.QueryById(id); |
|
|
|
|
|
|
|
if (exam.ExamPaperId != pageData.ExamPaperId) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Db.Updateable<Ghre_ExamPaper>().SetColumns(it => it.LinkTimes == it.LinkTimes - 1).Where(it => it.Id == exam.ExamPaperId && it.LinkTimes > 0).ExecuteCommand(); |
|
|
|
|
|
|
|
Db.Updateable<Ghre_ExamPaper>().SetColumns(it => it.LinkTimes == it.LinkTimes + 1).Where(it => it.Id == pageData.ExamPaperId).ExecuteCommand(); |
|
|
|
|
|
|
|
} |
|
|
|
var insert = Mapper.Map(pageData).ToANew<EditGhre_ExamInput>(); |
|
|
|
var insert = Mapper.Map(pageData).ToANew<EditGhre_ExamInput>(); |
|
|
|
await base.Update(id, insert); |
|
|
|
await base.Update(id, insert); |
|
|
|
await _ghre_ExamStaffServices.Delete(x => x.ExamId == id); |
|
|
|
await _ghre_ExamStaffServices.Delete(x => x.ExamId == id); |
|
|
@ -645,12 +679,23 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
|
|
|
|
|
|
|
if (!await _ghre_ExamRecordServices.AnyAsync(x => x.ExamId == id)) |
|
|
|
if (!await _ghre_ExamRecordServices.AnyAsync(x => x.ExamId == id)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
var dt = DateTime.Now; |
|
|
|
var exam = await base.QueryById(id); |
|
|
|
var exam = await base.QueryById(id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (exam.DateType == "ExamDate") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (exam.BeginTime > dt) |
|
|
|
|
|
|
|
return ServiceResult.OprateFailed("考试尚未开始!"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (exam.EndTime < dt) |
|
|
|
|
|
|
|
return ServiceResult.OprateFailed("考试已结束!"); |
|
|
|
|
|
|
|
} |
|
|
|
var insrt = new InsertGhre_ExamRecordInput() |
|
|
|
var insrt = new InsertGhre_ExamRecordInput() |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExamId = id, |
|
|
|
ExamId = id, |
|
|
|
UserId = UserContext.Current.User_Id, |
|
|
|
UserId = UserContext.Current.User_Id, |
|
|
|
ActualBeginTime = DateTime.Now, |
|
|
|
ActualBeginTime = dt, |
|
|
|
ExamPaperId = exam.ExamPaperId |
|
|
|
ExamPaperId = exam.ExamPaperId |
|
|
|
}; |
|
|
|
}; |
|
|
|
await _ghre_ExamRecordServices.Add(insrt); |
|
|
|
await _ghre_ExamRecordServices.Add(insrt); |
|
|
@ -659,4 +704,68 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
return ServiceResult.OprateSuccess("操作成功!"); |
|
|
|
return ServiceResult.OprateSuccess("操作成功!"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<string> GenerateContinuousSequence() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string prefixTemp = "E"; |
|
|
|
|
|
|
|
string result = string.Empty; |
|
|
|
|
|
|
|
string tableCode = "Ghre_Exam"; |
|
|
|
|
|
|
|
string columnCode = "ExamNo"; |
|
|
|
|
|
|
|
int length = 6; |
|
|
|
|
|
|
|
int tempLength = 5; |
|
|
|
|
|
|
|
int sequence; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 查询 |
|
|
|
|
|
|
|
DbSelect dbSelect = new DbSelect(tableCode + " A", "A", null); |
|
|
|
|
|
|
|
dbSelect.IsInitDefaultValue = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(prefixTemp)) |
|
|
|
|
|
|
|
dbSelect.Select("MAX(SUBSTRING(A." + columnCode + "," + (prefixTemp.Length + 1).ToString() + "," + tempLength.ToString() + "))"); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
dbSelect.Select("MAX(A." + columnCode + ")"); |
|
|
|
|
|
|
|
//} |
|
|
|
|
|
|
|
//dbSelect.Select("MAX(CONVERT(DECIMAL,SUBSTRING(A.ISSUE_NO," + (prefix.Length + dateString.Length + 1).ToString() + "," + tempLength.ToString() + ")))"); |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(prefixTemp)) |
|
|
|
|
|
|
|
dbSelect.Where("SUBSTRING(A." + columnCode + ",1," + (prefixTemp.Length).ToString() + ")", " = ", prefixTemp); |
|
|
|
|
|
|
|
dbSelect.Where("LEN(A." + columnCode + ")", "=", length); |
|
|
|
|
|
|
|
string sql = dbSelect.GetSql(); |
|
|
|
|
|
|
|
//await Db.Ado.GetScalarAsync(sql) |
|
|
|
|
|
|
|
string maxSequence = Convert.ToString(await Db.Ado.GetScalarAsync(sql)); |
|
|
|
|
|
|
|
#endregion |
|
|
|
|
|
|
|
//tempLength = tempLength - dateString.Length; |
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(maxSequence)) |
|
|
|
|
|
|
|
result = prefixTemp + Convert.ToString(1).PadLeft(tempLength, '0'); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(prefixTemp)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (int.TryParse(maxSequence, out sequence)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sequence += 1; |
|
|
|
|
|
|
|
if (sequence.ToString().Length > tempLength) |
|
|
|
|
|
|
|
throw new Exception("自动生成字串长度已经超过设定长度!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
throw new Exception("表中的数据无法进行自动编号,请联系软件开发商!"); |
|
|
|
|
|
|
|
result = prefixTemp + sequence.ToString().PadLeft(tempLength, '0'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (int.TryParse(maxSequence, out sequence)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
sequence += 1; |
|
|
|
|
|
|
|
if (sequence.ToString().Length > length) |
|
|
|
|
|
|
|
throw new Exception("自动生成字串长度已经超过设定长度!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
throw new Exception("表中的数据无法进行自动编号,请联系软件开发商!"); |
|
|
|
|
|
|
|
result = sequence.ToString().PadLeft(length, '0'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception) { throw; } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |