2022-03-15 17:36:38 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-04-28 14:56:47 +08:00
|
|
|
|
using System.Configuration;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
2022-03-15 17:36:38 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Web.Http;
|
|
|
|
|
using BLL;
|
|
|
|
|
namespace WebAPI.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 考试-考生记录信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TestRecordController : ApiController
|
|
|
|
|
{
|
|
|
|
|
#region 根据TestPlanId获取考生及试卷列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据TestPlanId获取考生及试卷列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="testPlanId"></param>
|
|
|
|
|
/// <returns>考试人员</returns>
|
|
|
|
|
public Model.ResponeData getTestRecordListByTestPlanId(string testPlanId)
|
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
responeData.data = APITestRecordService.getTestRecordListByTestPlanId(testPlanId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据试卷ID获取试卷记录详细
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据试卷ID获取试卷记录详细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="testRecordId"></param>
|
|
|
|
|
/// <returns>试卷详细</returns>
|
|
|
|
|
public Model.ResponeData getTestRecordByTestRecordId(string testRecordId)
|
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
responeData.data = APITestRecordService.getTestRecordByTestRecordId(testRecordId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据TestRecordId获取试卷题目列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据TestRecordId获取试卷题目列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="testRecordId"></param>
|
|
|
|
|
/// <param name="pageIndex">页码</param>
|
|
|
|
|
/// <returns>试卷题目列表</returns>
|
|
|
|
|
public Model.ResponeData getTestRecordItemListByTestRecordId(string testRecordId, int pageIndex)
|
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var getDataLists = APITestRecordService.geTestRecordItemListByTestRecordId(testRecordId);
|
|
|
|
|
int pageCount = getDataLists.Count;
|
|
|
|
|
if (pageCount > 0 && pageIndex > 0)
|
|
|
|
|
{
|
|
|
|
|
getDataLists = getDataLists.OrderBy(x => x.TestType).ThenBy(x => x.TrainingItemCode).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
|
|
|
|
|
}
|
|
|
|
|
responeData.data = new { pageCount, getDataLists };
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取当前试卷的答题倒计时
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取当前试卷的答题倒计时
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="testRecordId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Model.ResponeData getTestTimesByTestRecordId(string testRecordId)
|
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int mTime = 0;
|
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
{
|
|
|
|
|
var getTestRecord = db.Training_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecordId);
|
|
|
|
|
if (getTestRecord != null)
|
|
|
|
|
{
|
|
|
|
|
DateTime startTime = DateTime.Now;
|
|
|
|
|
if (getTestRecord.TestStartTime.HasValue)
|
|
|
|
|
{
|
|
|
|
|
startTime = getTestRecord.TestStartTime.Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
getTestRecord.TestStartTime = startTime;
|
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
}
|
|
|
|
|
mTime = Convert.ToInt32((getTestRecord.TestStartTime.Value.AddMinutes(getTestRecord.Duration) - DateTime.Now).TotalSeconds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
responeData.data = new { mTime };
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据TestRecordItemId获取试卷题目详细
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据TestRecordItemId获取试卷题目详细
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="testRecordItemId"></param>
|
|
|
|
|
/// <returns>考试人员</returns>
|
|
|
|
|
public Model.ResponeData getTestRecordItemByTestRecordItemId(string testRecordItemId)
|
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
responeData.data = APITestRecordService.geTestRecordItemByTestRecordItemId(testRecordItemId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据ProjectId、PersonId获取当前人试卷列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据ProjectId、PersonId获取当前人试卷列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="projectId">项目ID</param>
|
|
|
|
|
/// <param name="personId">人员ID(null查全部)</param>
|
|
|
|
|
/// <param name="pageIndex">页码</param>
|
|
|
|
|
/// <returns>考试记录列表</returns>
|
|
|
|
|
public Model.ResponeData getTrainingTestRecordListByProjectIdPersonId(string projectId, string personId, int pageIndex)
|
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
personId = PersonService.GetPersonIdByUserId(personId);
|
|
|
|
|
var getDataLists = APITestRecordService.getTrainingTestRecordListByProjectIdPersonId(projectId, personId);
|
|
|
|
|
int pageCount = getDataLists.Count;
|
|
|
|
|
if (pageCount > 0 && pageIndex > 0)
|
|
|
|
|
{
|
|
|
|
|
getDataLists = getDataLists.OrderByDescending(x => x.TestStartTime).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
|
|
|
|
|
}
|
|
|
|
|
responeData.data = new { pageCount, getDataLists };
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据ProjectId获取所有考试记录列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据ProjectId获取所有考试记录列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="projectId">项目ID</param>
|
|
|
|
|
/// <param name="pageIndex">页码</param>
|
|
|
|
|
/// <returns>考试记录列表</returns>
|
|
|
|
|
public Model.ResponeData getTrainingTestRecordListByProjectId(string projectId, int pageIndex)
|
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var getDataLists = APITestRecordService.getTrainingTestRecordListByProjectId(projectId, null, null, null, null);
|
|
|
|
|
int pageCount = getDataLists.Count;
|
|
|
|
|
if (pageCount > 0 && pageIndex > 0)
|
|
|
|
|
{
|
|
|
|
|
getDataLists = getDataLists.OrderByDescending(x => x.TestStartTime).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
|
|
|
|
|
}
|
|
|
|
|
responeData.data = new { pageCount, getDataLists };
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据ProjectId获取所有考试记录列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据ProjectId获取所有考试记录列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="projectId">项目ID</param>
|
|
|
|
|
/// <param name="unitId">单位ID</param>
|
|
|
|
|
/// <param name="workPostId">岗位ID</param>
|
|
|
|
|
/// <param name="strPass">0-未通过;1通过;空所有</param>
|
|
|
|
|
/// <param name="pageIndex">页码</param>
|
|
|
|
|
/// <returns>考试记录列表</returns>
|
2022-12-20 09:32:32 +08:00
|
|
|
|
public Model.ResponeData getTrainingTestRecordListQuery(string projectId, string unitId, string workPostId, string departId, string strPass, int pageIndex)
|
2022-03-15 17:36:38 +08:00
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(departId))
|
2022-03-15 17:36:38 +08:00
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
var getDataLists = APITestRecordService.getTrainingTestRecordListByDepartId(unitId,departId,strPass,string.Empty);
|
|
|
|
|
int pageCount = getDataLists.Count;
|
|
|
|
|
if (pageCount > 0 && pageIndex > 0)
|
|
|
|
|
{
|
|
|
|
|
getDataLists = getDataLists.OrderByDescending(x => x.TestStartTime).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
|
|
|
|
|
}
|
|
|
|
|
responeData.data = new { pageCount, getDataLists };
|
2022-03-15 17:36:38 +08:00
|
|
|
|
}
|
2022-12-20 09:32:32 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var getDataLists = APITestRecordService.getTrainingTestRecordListByProjectId(projectId, unitId, workPostId, strPass, string.Empty);
|
|
|
|
|
int pageCount = getDataLists.Count;
|
|
|
|
|
if (pageCount > 0 && pageIndex > 0)
|
|
|
|
|
{
|
|
|
|
|
getDataLists = getDataLists.OrderByDescending(x => x.TestStartTime).Skip(Funs.PageSize * (pageIndex - 1)).Take(Funs.PageSize).ToList();
|
|
|
|
|
}
|
|
|
|
|
responeData.data = new { pageCount, getDataLists };
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 17:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据ProjectId获取所有考试记录列表
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据ProjectId获取所有考试记录列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="projectId">项目ID</param>
|
|
|
|
|
/// <param name="unitId">单位ID</param>
|
|
|
|
|
/// <param name="workPostId">岗位ID</param>
|
|
|
|
|
/// <param name="strPass">0-未通过;1通过;空所有</param>
|
|
|
|
|
/// <param name="strParam">参数</param>
|
|
|
|
|
/// <param name="pageIndex">页码</param>
|
|
|
|
|
/// <returns>考试记录列表</returns>
|
2022-12-20 09:32:32 +08:00
|
|
|
|
|
2022-03-15 17:36:38 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 根据TestRecordItemId、selectedItem 考生答题
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据TestRecordItemId、selectedItem 考生答题
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="testRecordItemId">题目ID</param>
|
|
|
|
|
/// <param name="selectedItem">选项</param>
|
|
|
|
|
public Model.ResponeData getTestRecordItemAnswerBySelectedItem(string testRecordItemId, string selectedItem)
|
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(testRecordItemId) && !string.IsNullOrEmpty(selectedItem))
|
2022-03-15 17:36:38 +08:00
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
2022-03-15 17:36:38 +08:00
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
var getTItem = db.Training_TestRecordItem.FirstOrDefault(x => x.TestRecordItemId == testRecordItemId);
|
|
|
|
|
if (getTItem != null)
|
|
|
|
|
{
|
|
|
|
|
getTItem.SubjectScore = 0;
|
|
|
|
|
getTItem.SelectedItem = selectedItem;
|
|
|
|
|
if (!string.IsNullOrEmpty(selectedItem))
|
|
|
|
|
{
|
|
|
|
|
if (getTItem.AnswerItems == selectedItem)
|
|
|
|
|
{
|
|
|
|
|
getTItem.SubjectScore = getTItem.Score ?? 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var listA = Funs.GetStrListByStr(getTItem.AnswerItems.ToUpper(), ',');
|
|
|
|
|
var listS = Funs.GetStrListByStr(selectedItem.ToUpper(), ',');
|
|
|
|
|
if (getTItem.TestType == "2" && listA.Count >= listS.Count)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
foreach (var item in listS)
|
|
|
|
|
{
|
|
|
|
|
if (!listA.Contains(item))
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i == 0)
|
|
|
|
|
{
|
|
|
|
|
if (listA.Count == listS.Count)
|
|
|
|
|
{
|
|
|
|
|
getTItem.SubjectScore = getTItem.Score ?? 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
getTItem.SubjectScore = Convert.ToDecimal((getTItem.Score ?? 0) * 1.0 / 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
}
|
2022-03-15 17:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
2022-12-20 09:32:32 +08:00
|
|
|
|
responeData.message = "答题为空选项!";
|
2022-03-15 17:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 交卷
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 交卷
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="testRecordId">试卷ID</param>
|
2023-04-28 14:56:47 +08:00
|
|
|
|
public Model.ResponeData getSubmitTestRecordByTestRecordId(string testRecordId,string Signature)
|
2022-03-15 17:36:38 +08:00
|
|
|
|
{
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
2022-03-15 17:36:38 +08:00
|
|
|
|
{
|
|
|
|
|
string returnTestRecordId = string.Empty;
|
2022-12-20 09:32:32 +08:00
|
|
|
|
decimal getTestScores = 0;
|
|
|
|
|
var getTestRecord = db.Training_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecordId);
|
|
|
|
|
if (getTestRecord != null)
|
2022-03-15 17:36:38 +08:00
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
if (getTestRecord.TestStartTime.HasValue)
|
|
|
|
|
{
|
2023-04-28 14:56:47 +08:00
|
|
|
|
getTestRecord.Signature = Signature;
|
2022-12-20 09:32:32 +08:00
|
|
|
|
getTestRecord.TestEndTime = DateTime.Now;
|
2023-07-13 10:09:46 +08:00
|
|
|
|
// var getRItem = db.Training_TestRecordItem.Where(x => x.TestRecordId == testRecordId);
|
|
|
|
|
// if (getRItem.Count() > 0)
|
|
|
|
|
// {
|
|
|
|
|
getTestRecord.TestScores = db.Training_TestRecordItem.Where(x => x.TestRecordId == testRecordId).Sum(x => x.SubjectScore ?? 0);
|
|
|
|
|
// }
|
2022-12-20 09:32:32 +08:00
|
|
|
|
db.SubmitChanges();
|
|
|
|
|
getTestScores = getTestRecord.TestScores ?? 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////考试分数
|
2023-07-13 10:09:46 +08:00
|
|
|
|
int getPassScores = SysConstSetService.getPassScoreForApi();
|
2022-12-20 09:32:32 +08:00
|
|
|
|
if (getTestScores <= getPassScores)
|
2022-03-15 17:36:38 +08:00
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
int testCount = db.Training_TestRecord.Where(x => x.TestPlanId == getTestRecord.TestPlanId && x.TestManId == getTestRecord.TestManId).Count();
|
|
|
|
|
if (testCount < 2)
|
|
|
|
|
{
|
|
|
|
|
////重新生成一条考试记录 以及考试试卷
|
|
|
|
|
returnTestRecordId = APITestRecordService.getResitTestRecord(getTestRecord);
|
|
|
|
|
responeData.message = "考试不合格!您的成绩为:【" + getTestScores.ToString() + "】,您将进入补考。";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// APITestRecordService.updateAll(getTestRecord.TestPlanId);
|
|
|
|
|
responeData.message = "考试不合格!您的成绩为:【" + getTestScores.ToString() + "】,请再次参加培训后补考。";
|
|
|
|
|
}
|
2022-03-15 17:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-12-20 09:32:32 +08:00
|
|
|
|
// APITestRecordService.updateAll(getTestRecord.TestPlanId);
|
|
|
|
|
responeData.message = "恭喜考试通过!您的成绩为:【" + getTestScores.ToString() + "】。";
|
2022-03-15 17:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-20 09:32:32 +08:00
|
|
|
|
responeData.data = new { getTestScores, getPassScores, returnTestRecordId };
|
|
|
|
|
}
|
2022-03-15 17:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2023-04-28 14:56:47 +08:00
|
|
|
|
|
|
|
|
|
#region 交卷
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 交卷
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Model.ResponeData SaveSubmitTestRecordByTestRecordId(Model.TestRecordItem testRecordItem)
|
|
|
|
|
{
|
|
|
|
|
string testRecordId = testRecordItem.TestRecordId;
|
|
|
|
|
string Signature = testRecordItem.Signature;
|
|
|
|
|
string Fingerprint = testRecordItem.Fingerprint;
|
|
|
|
|
var responeData = new Model.ResponeData();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
|
|
|
|
{
|
|
|
|
|
var getTestRecord = db.Training_TestRecord.FirstOrDefault(e => e.TestRecordId == testRecordId);
|
|
|
|
|
if (getTestRecord != null)
|
|
|
|
|
{
|
|
|
|
|
string rootUrl = ConfigurationManager.AppSettings["localRoot"];
|
|
|
|
|
string SignatureUrl = @"FileUpload\TestRecord\" + getTestRecord.TestRecordId + "~签名" + ".png";
|
|
|
|
|
string FingerprintUrl = @"FileUpload\TestRecord\" + getTestRecord.TestRecordId + "~指纹" + ".png";
|
|
|
|
|
string Signaturefilename = rootUrl + SignatureUrl;
|
|
|
|
|
string Fingerprintfilename = rootUrl + FingerprintUrl;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Signature))
|
|
|
|
|
{
|
|
|
|
|
Signature = Signature.Replace("data:image/svg+xml;base64,", "").Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//将base64头部信息替换
|
|
|
|
|
byte[] bytes = Convert.FromBase64String(Signature);
|
|
|
|
|
|
|
|
|
|
MemoryStream memStream = new MemoryStream(bytes);
|
|
|
|
|
Image mImage = Image.FromStream(memStream);
|
|
|
|
|
Bitmap bp = new Bitmap(mImage);
|
|
|
|
|
MemoryStream ms = new MemoryStream();
|
|
|
|
|
bp.Save(Signaturefilename, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
|
|
// System.IO.File.WriteAllBytes(Signaturefilename, Convert.FromBase64String(Signature));
|
|
|
|
|
|
|
|
|
|
getTestRecord.Signature = Signaturefilename.Replace(rootUrl, "");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(Fingerprint))
|
|
|
|
|
{
|
|
|
|
|
Fingerprint = Fingerprint.Replace("data:image/svg+xml;base64,", "").Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//将base64头部信息替换
|
|
|
|
|
|
|
|
|
|
byte[] bytes = Convert.FromBase64String(Fingerprint);
|
|
|
|
|
|
|
|
|
|
MemoryStream memStream = new MemoryStream(bytes);
|
|
|
|
|
Image mImage = Image.FromStream(memStream);
|
|
|
|
|
Bitmap bp = new Bitmap(mImage);
|
|
|
|
|
MemoryStream ms = new MemoryStream();
|
|
|
|
|
bp.Save(Fingerprintfilename, System.Drawing.Imaging.ImageFormat.Png);
|
|
|
|
|
|
|
|
|
|
getTestRecord.Fingerprint = Fingerprintfilename.Replace(rootUrl, "");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
APITestRecordService.updateTestRecord(getTestRecord);
|
|
|
|
|
string returnTestRecordId = string.Empty;
|
|
|
|
|
////考试分数
|
|
|
|
|
decimal getTestScores = APITestRecordService.getSubmitTestRecord(getTestRecord);
|
|
|
|
|
////及格分数
|
|
|
|
|
int getPassScores = 80;
|
|
|
|
|
var testRule = db.Sys_TestRule.FirstOrDefault();
|
|
|
|
|
if (testRule != null)
|
|
|
|
|
{
|
|
|
|
|
getPassScores = testRule.PassingScore;
|
|
|
|
|
}
|
|
|
|
|
if (getTestScores <= getPassScores)
|
|
|
|
|
{
|
|
|
|
|
int testCount = db.Training_TestRecord.Where(x => x.TestPlanId == getTestRecord.TestPlanId && x.TestManId == getTestRecord.TestManId).Count();
|
|
|
|
|
if (testCount < 2)
|
|
|
|
|
{
|
|
|
|
|
////重新生成一条考试记录 以及考试试卷
|
|
|
|
|
returnTestRecordId = APITestRecordService.getResitTestRecord(getTestRecord);
|
|
|
|
|
responeData.message = "考试不合格!您的成绩为:【" + getTestScores.ToString() + "】,您将进入补考。";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
APITestRecordService.updateAll(getTestRecord.TestPlanId);
|
|
|
|
|
responeData.message = "考试不合格!您的成绩为:【" + getTestScores.ToString() + "】,请再次参加培训后补考。";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
APITestRecordService.updateAll(getTestRecord.TestPlanId);
|
|
|
|
|
responeData.message = "恭喜考试通过!您的成绩为:【" + getTestScores.ToString() + "】。";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
responeData.data = new { getTestScores, getPassScores, returnTestRecordId };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
responeData.code = 0;
|
|
|
|
|
responeData.message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return responeData;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2022-03-15 17:36:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|