小程序接口调优

This commit is contained in:
夏菊 2025-03-06 17:51:11 +08:00
parent 3afe6eada7
commit 18819ad259
7 changed files with 343 additions and 27 deletions

View File

@ -75,6 +75,158 @@ namespace BLL
}
#endregion
public static string CreateTestRecordItem(Model.Training_CompanyTrainingItem getCompanyTraining, string testRecordId, Model.SitePerson_Person person, Model.Sys_User user)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var trainingIds = getCompanyTraining.TestTrainingIds.Split(',');
var testTrainings = db.Training_TestTraining.Where(x => trainingIds.Contains(x.TrainingId));
var getTestRecord = db.Training_TestRecord.FirstOrDefault(x => x.TestRecordId == testRecordId);
if (getTestRecord != null && !getTestRecord.TestStartTime.HasValue)
{
////考试时长
getTestRecord.Duration = 120;
getTestRecord.TestStartTime = DateTime.Now;
db.SubmitChanges();
}
////当前人考试记录 未加入考试计划的 当考试开始扫码时 不允许再参与考试
var item = db.Training_TestRecordItem.FirstOrDefault(x => x.TestRecordId == getTestRecord.TestRecordId);
if (item == null)
{
List<Model.Training_TestTrainingItem> getTestTrainingItemList = new List<Model.Training_TestTrainingItem>();
//var testPlanTrainings = from x in db.Training_TestPlanTraining
// where x.TestPlanId == getTestPlan.TestPlanId
// select x;
//// 计划考试中单选、多选、判断题总数
var sysTestRule = Funs.DB.Sys_TestRule.FirstOrDefault();
int sumTestType1Count = 0;// testPlanTrainings.Sum(x => x.TestType1Count) ?? 0;
int sumTestType2Count = 0;//testPlanTrainings.Sum(x => x.TestType2Count) ?? 0;
int sumTestType3Count = 0;//testPlanTrainings.Sum(x => x.TestType3Count) ?? 0;
if (sysTestRule != null)
{
sumTestType1Count = sysTestRule.SCount;
sumTestType2Count = sysTestRule.MCount;
sumTestType3Count = sysTestRule.JCount;
}
////获取类型下适合岗位试题集合
List<Model.Training_TestTrainingItem> getTestTrainingItemALLs;
string WorkPostId = "";
string DepartId = "";
if (person != null)
{
WorkPostId = person.WorkPostId;
}
if (user != null)
{
DepartId = user.DepartId;
}
getTestTrainingItemALLs = (from x in db.Training_TestTrainingItem
where x.TrainingId != null && (x.WorkPostIds == null || string.IsNullOrEmpty(WorkPostId) || x.WorkPostIds.Contains(WorkPostId)) || (x.DepartIds == null || string.IsNullOrEmpty(DepartId) || x.DepartIds.Contains(DepartId))
select x).ToList();
foreach (var itemT in testTrainings)
{
//// 获取类型下的题目
var getTestTrainingItems = getTestTrainingItemALLs.Where(x => x.TrainingId == itemT.TrainingId).ToList();
if (getTestTrainingItems.Count() > 0)
{
////单选题
var getSItem = getTestTrainingItems.Where(x => x.TestType == "1").OrderBy(x => Guid.NewGuid()).Take(sumTestType1Count);
if (getSItem.Count() > 0)
{
getTestTrainingItemList.AddRange(getSItem);
}
///多选题
var getMItem = getTestTrainingItems.Where(x => x.TestType == "2").OrderBy(x => Guid.NewGuid()).Take(sumTestType2Count);
if (getMItem.Count() > 0)
{
getTestTrainingItemList.AddRange(getMItem);
}
///判断题
var getJItem = getTestTrainingItems.Where(x => x.TestType == "3").OrderBy(x => Guid.NewGuid()).Take(sumTestType3Count);
if (getJItem.Count() > 0)
{
getTestTrainingItemList.AddRange(getJItem);
}
}
}
//// 获取得到的单选题、多选题、判断题 数量
int getDiffTestType1Count = sumTestType1Count - getTestTrainingItemList.Where(x => x.TestType == "1").Count();
int getDiffTestType2Count = sumTestType2Count - getTestTrainingItemList.Where(x => x.TestType == "2").Count();
int getDiffTestType3Count = sumTestType3Count - getTestTrainingItemList.Where(x => x.TestType == "3").Count();
if (getDiffTestType1Count > 0 || getDiffTestType2Count > 0 || getDiffTestType3Count > 0)
{
var getTestTrainingItemNulls = getTestTrainingItemALLs.Where(x => x.WorkPostIds == null).ToList();
if (getTestTrainingItemNulls.Count() > 0)
{
/// 通用且未选择的题目
var getTestTrainingItemDiffs = getTestTrainingItemNulls.Except(getTestTrainingItemList).ToList();
////单选题
if (getDiffTestType1Count > 0)
{
var getSItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "1").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType1Count);
if (getSItemD.Count() > 0)
{
getTestTrainingItemList.AddRange(getSItemD);
}
}
///多选题
if (getDiffTestType2Count > 0)
{
var getMItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "2").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType2Count);
if (getMItemD.Count() > 0)
{
getTestTrainingItemList.AddRange(getMItemD);
}
}
///判断题
if (getDiffTestType3Count > 0)
{
var getJItemD = getTestTrainingItemDiffs.Where(x => x.TestType == "3").OrderBy(x => Guid.NewGuid()).Take(getDiffTestType3Count);
if (getJItemD.Count() > 0)
{
getTestTrainingItemList.AddRange(getJItemD);
}
}
}
}
if (getTestTrainingItemList.Count() > 0)
{
var getItems = from x in getTestTrainingItemList
select new Model.Training_TestRecordItem
{
TestRecordItemId = SQLHelper.GetNewID(),
TestRecordId = getTestRecord.TestRecordId,
TrainingItemName = x.TrainingItemName,
TrainingItemCode = x.TrainingItemCode,
Abstracts = x.Abstracts,
AttachUrl = x.AttachUrl,
TestType = x.TestType,
AItem = x.AItem,
BItem = x.BItem,
CItem = x.CItem,
DItem = x.DItem,
EItem = x.EItem,
AnswerItems = x.AnswerItems,
Score = x.TestType == "1" ? sysTestRule.SValue : (x.TestType == "2" ? sysTestRule.MValue : sysTestRule.JValue),
};
db.Training_TestRecordItem.InsertAllOnSubmit(getItems);
db.SubmitChanges();
BLL.RedisHelper redis = new BLL.RedisHelper();
redis.SetObjString(testRecordId, getItems);
}
}
}
return testRecordId;
}
#region PersonIdTestPlanId生成试卷
/// <summary>
/// 根据PersonId、TestPlanId生成试卷 扫码生成试卷

View File

@ -37,6 +37,8 @@ namespace BLL
TrainTypeName = db.Base_TrainType.FirstOrDefault(b => b.TrainTypeId == y.TrainTypeId).TrainTypeName,
TrainLevelName = db.Base_TrainLevel.FirstOrDefault(b => b.TrainLevelId == y.TrainLevelId).TrainLevelName,
PlanStatesName = y.States == "3" ? "已完成" : "培训中",
TaskStatesName = x.States == "2" ? "已完成" : "培训中",
TrainingItemCode = getTrainingItemCode(y.PlanId),
IsRetakeCourse = y.IsRetakeCourse == 1 ? 1 : 0,
}).ToList();
if (!string.IsNullOrWhiteSpace(isRetakeCourse))
@ -46,6 +48,18 @@ namespace BLL
return getDataLists;
}
}
public static string getTrainingItemCode(string PlanId)
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
{
var ids = db.Training_PlanItem.Where(xx => xx.PlanId == PlanId).Select(x => x.CompanyTrainingItemId).ToList();
var codes = db.Training_CompanyTrainingItem.Where(x => ids.Contains(x.CompanyTrainingItemId)).Select(x => x.CompanyTrainingItemCode);
string res = string.Join(",", codes);
return res;
}
}
#endregion
#region TaskId获取培训任务教材列表
@ -62,6 +76,8 @@ namespace BLL
GetDataService.CreateTrainingTaskItemByTaskId(taskId);
var getDataLists = (from x in db.Training_TaskItem
join y in db.Training_CompanyTrainingItem on x.TrainingItemCode equals y.CompanyTrainingItemCode into temp
from y in temp.DefaultIfEmpty()
where x.TaskId == taskId
orderby x.TrainingItemCode
select new Model.TrainingTaskItemItem
@ -69,11 +85,12 @@ namespace BLL
TaskItemId = x.TaskItemId,
TaskId = x.TaskId,
PlanId = x.PlanId,
PersonId = x.PersonId,
StartTime = x.StartTime,
EndTime = x.EndTime,
LearnTime = x.LearnTime,
LearningTime = x.LearnTime,
AttachTime = y.LearningTime,
VideoProgress = x.VideoProgress,
PersonId = x.PersonId,
TrainingItemCode = x.TrainingItemCode,
TrainingItemName = x.TrainingItemName,
AttachUrl = x.AttachUrl.Replace('\\', '/'),

View File

@ -21,6 +21,8 @@
<SccProvider>
</SccProvider>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -66,8 +68,11 @@
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.3.11, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.2.1.1\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\lib\net461\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Office.Interop.Excel.15.0.4795.1001\lib\net20\Microsoft.Office.Interop.Excel.dll</HintPath>
@ -103,12 +108,18 @@
<HintPath>..\packages\MicrosoftOfficeCore.15.0.0\lib\net35\Office.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Pipelines.Sockets.Unofficial, Version=1.0.0.0, Culture=neutral, PublicKeyToken=42ea0a778e13fbe2, processorArchitecture=MSIL">
<HintPath>..\packages\Pipelines.Sockets.Unofficial.2.2.8\lib\net461\Pipelines.Sockets.Unofficial.dll</HintPath>
</Reference>
<Reference Include="Quartz, Version=3.7.0.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
<HintPath>..\packages\Quartz.3.7.0\lib\netstandard2.0\Quartz.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=106.15.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.15.0\lib\net452\RestSharp.dll</HintPath>
</Reference>
<Reference Include="StackExchange.Redis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46, processorArchitecture=MSIL">
<HintPath>..\packages\StackExchange.Redis.2.8.24\lib\net461\StackExchange.Redis.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
@ -125,7 +136,14 @@
</Reference>
<Reference Include="System.DirectoryServices" />
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL" />
<Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.IO.Pipelines, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Pipelines.5.0.1\lib\net461\System.IO.Pipelines.dll</HintPath>
</Reference>
<Reference Include="System.Management" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
@ -142,6 +160,11 @@
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.Security.AccessControl, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@ -155,6 +178,12 @@
</Reference>
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Threading.Channels, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Channels.5.0.0\lib\net461\System.Threading.Channels.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Transactions" />
<Reference Include="System.Web" />
<Reference Include="System.Web.DataVisualization" />
@ -274,6 +303,9 @@
<Compile Include="Common\NPOIHelper.cs" />
<Compile Include="Common\PrinterDocService.cs" />
<Compile Include="Common\ProjectDataFlowSetService.cs" />
<Compile Include="Common\Redis\ICache.cs" />
<Compile Include="Common\Redis\Redis.cs" />
<Compile Include="Common\Redis\RedisHelper.cs" />
<Compile Include="Common\UploadFileService.cs" />
<Compile Include="Common\UpLoadImageService.cs" />
<Compile Include="Common\UserShowColumnsService.cs" />
@ -1160,6 +1192,13 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\build\Microsoft.Extensions.Logging.Abstractions.targets" Condition="Exists('..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\build\Microsoft.Extensions.Logging.Abstractions.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\build\Microsoft.Extensions.Logging.Abstractions.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Extensions.Logging.Abstractions.6.0.0\build\Microsoft.Extensions.Logging.Abstractions.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -41,7 +41,9 @@ namespace BLL
PersonId = item.UserId,
TrainingItemCode = dataItem.TrainingItemCode,
TrainingItemName = dataItem.TrainingItemName,
AttachUrl = dataItem.AttachUrl,
// LearnTime = dataItem.LearningTime,//秒 注释原因2024-5-24存储过程LearningTime是教材时长培训任务教材明细表中的学习时间字段LearnTime不能复用
LearnTime = 0,
AttachUrl = dataItem.AttachUrl,
};
var getTaskItem = db.Training_TaskItem.FirstOrDefault(x => x.TaskId == item.TaskId && x.TrainingItemName == newTaskItem.TrainingItemName && x.AttachUrl == newTaskItem.AttachUrl);

View File

@ -48,6 +48,14 @@ namespace Model
set;
}
/// <summary>
/// 培训任务状态
/// </summary>
public string TaskStatesName
{
get;
set;
}
/// <summary>
/// 培训计划时间
/// </summary>
public string TrainStartDate
@ -111,6 +119,11 @@ namespace Model
get;
set;
}
public string TrainingItemCode
{
get;
set;
}
/// <summary>
/// 是否是重修任务
/// </summary>

View File

@ -87,28 +87,43 @@ namespace Model
get;
set;
}
/// <summary>
/// 开始时间
/// </summary>
public DateTime? StartTime
{
get;
set;
}
public int? LearnTime
{
get;
set;
}
public DateTime? EndTime
{
get;
set;
}
{
get;
set;
}
/// <summary>
/// 学习时长(秒)
/// </summary>
public int? LearningTime
{
get;
set;
}
/// <summary>
/// 教材时长(秒)
/// </summary>
public int? AttachTime
{
get;
set;
}
public DateTime? EndTime
{
get;
set;
}
/// <summary>
/// 视频进度(秒)
/// </summary>
public int? VideoProgress
{
get;
set;
}
{
get;
set;
}
}
}
}

View File

@ -5,6 +5,7 @@ using System.Net;
using System.Net.Http;
using System.Web.Http;
using BLL;
using Model;
namespace WebAPI.Controllers
{
@ -293,5 +294,82 @@ namespace WebAPI.Controllers
#endregion
public Model.ResponeData getTrainingPlanTestRecordItemByTestPlanIdPersonId(string companyTrainingItemCode, string personId, string projectId)
{
var responeData = new Model.ResponeData();
try
{
using (var db = new Model.SGGLDB(Funs.ConnString))
{
var getCompanyTraining = db.Training_CompanyTrainingItem.FirstOrDefault(e => e.CompanyTrainingItemCode == companyTrainingItemCode);
if (getCompanyTraining != null)
{
var user = db.Sys_User.FirstOrDefault(x => x.UserId == personId);
Model.SitePerson_Person person;
if (user != null)
{
person = db.SitePerson_Person.FirstOrDefault(e => (e.PersonId == personId || e.IdentityCard == user.IdentityCard) && e.ProjectId == projectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId);
}
else
{
person = db.SitePerson_Person.FirstOrDefault(e => e.PersonId == personId && e.ProjectId == projectId);// PersonService.GetPersonByUserId(personId, getTestPlan.ProjectId);
}
if (person != null || user != null)
{
var testRecord = db.Training_TestRecord.FirstOrDefault(x => x.CompanyTrainingItemId == getCompanyTraining.CompanyTrainingItemId && x.TestManId == personId && !x.TestEndTime.HasValue);
if (testRecord != null)
{
string testRecordId = APITestRecordService.CreateTestRecordItem(getCompanyTraining, testRecord.TestRecordId, person, user);
responeData.code = 2;
responeData.data = new { testRecordId };
}
else if (person != null)
{
var testRecord2 = db.Training_TestRecord.FirstOrDefault(x => x.CompanyTrainingItemId == getCompanyTraining.CompanyTrainingItemId && x.TestManId == person.PersonId && !x.TestEndTime.HasValue);
if (testRecord2 != null)
{
string testRecordId = APITestRecordService.CreateTestRecordItem(getCompanyTraining, testRecord2.TestRecordId, person, user);
responeData.code = 2;
responeData.data = new { testRecordId };
}
else
{
Training_TestRecord training_TestRecord = new Training_TestRecord();
training_TestRecord.TestRecordId = Guid.NewGuid().ToString();
training_TestRecord.ProjectId = projectId;
training_TestRecord.CompanyTrainingItemId = getCompanyTraining.CompanyTrainingItemId;
training_TestRecord.TestManId = person.PersonId;
db.Training_TestRecord.InsertOnSubmit(training_TestRecord);
db.SubmitChanges();
string testRecordId = APITestRecordService.CreateTestRecordItem(getCompanyTraining, training_TestRecord.TestRecordId, person, user);
responeData.code = 2;
responeData.data = new { testRecordId };
}
}
else
{
Training_TestRecord training_TestRecord = new Training_TestRecord();
training_TestRecord.TestRecordId = Guid.NewGuid().ToString();
training_TestRecord.ProjectId = projectId;
training_TestRecord.CompanyTrainingItemId = getCompanyTraining.CompanyTrainingItemId;
training_TestRecord.TestManId = user.UserId;
db.Training_TestRecord.InsertOnSubmit(training_TestRecord);
db.SubmitChanges();
string testRecordId = APITestRecordService.CreateTestRecordItem(getCompanyTraining, training_TestRecord.TestRecordId, person, user);
responeData.code = 2;
responeData.data = new { testRecordId };
}
}
}
}
}
catch (Exception ex)
{
responeData.code = 0;
responeData.message = ex.Message;
}
return responeData;
}
}
}