小程序接口调优

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
@@ -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;
}
}
}