136 lines
5.1 KiB
C#
136 lines
5.1 KiB
C#
using Competition.Common.Util;
|
|
using CompetitionAPI.api.unity;
|
|
using CompetitionAPI.Util;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Threading.Tasks.Dataflow;
|
|
|
|
namespace CompetitionAPI.Controllers.unity
|
|
{
|
|
[Route("unity/[controller]")]
|
|
[ApiController]
|
|
public class StopTicketProcController : Controller
|
|
{
|
|
Competition.Mysql.BLL.pow_exam exam_bll = new Competition.Mysql.BLL.pow_exam();
|
|
|
|
Competition.Mysql.BLL.pow_achievement bll_pow_achievement = new Competition.Mysql.BLL.pow_achievement();
|
|
|
|
Competition.Mysql.BLL.admin_user bll_admin_User = new Competition.Mysql.BLL.admin_user();
|
|
|
|
Competition.Mysql.BLL.pow_user_operation_proc_ticket bll_pow_user_operation_proc_ticket = new Competition.Mysql.BLL.pow_user_operation_proc_ticket();
|
|
|
|
public StopTicketProcController()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 停止操作票所有步骤接口
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpPost]
|
|
[APIFilter]
|
|
public JsonResult Index([FromForm] StopTicketProcRequest req)
|
|
{
|
|
try
|
|
{
|
|
//参数:
|
|
//UserId :用户id
|
|
//ExamId:考试id
|
|
//Type:送电、停电
|
|
|
|
if (string.IsNullOrEmpty(req.ExamId))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "ExamId参数不能为空"));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(req.Type))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "Type参数不能为空"));
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(req.UserId))
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "UserId参数不能为空"));
|
|
}
|
|
|
|
|
|
//UserId :用户id
|
|
//ExamId:考试id
|
|
//Type:送电、停电
|
|
|
|
var achievement = bll_pow_achievement.GetModelList(" ExamId='" + req.ExamId + "' and UserId='" + req.UserId + "' ").FirstOrDefault();
|
|
if (null == achievement)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "考生成绩数据不存在"));
|
|
}
|
|
|
|
var qry = string.Format(" UserId='{0}' and ExamId='{1}' and Type='{2}' and LENGTH(Content)>0 ", req.UserId, req.ExamId, req.Type);
|
|
var proc_ticket_list = bll_pow_user_operation_proc_ticket.GetModelList(qry).OrderBy(s => s.SerialNumber).ToList();
|
|
|
|
if (proc_ticket_list.Count <= 0)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "操作票步骤数据不存在"));
|
|
}
|
|
|
|
//获取操作票步骤得分
|
|
var total_score = get_ticket_proc_scrore(proc_ticket_list);
|
|
var user = bll_admin_User.GetModel(req.UserId);
|
|
var exam = exam_bll.GetModel(req.ExamId);
|
|
|
|
|
|
var details_model = new Competition.Mysql.Model.pow_achievement_details();
|
|
details_model.DetailsId = Guid.NewGuid().ToString("N");
|
|
details_model.AchievementId = achievement.AchievementId;
|
|
details_model.ItemName = req.Type + "操作票步骤";
|
|
details_model.ItemizedScore = total_score;
|
|
details_model.Type = req.Type + "操作票步骤";
|
|
details_model.CreateTime = DateTime.Now;
|
|
details_model.TotalScore = 5;
|
|
bll_pow_achievement.OperationAddUpdateData(new List<Competition.Mysql.Model.pow_achievement_details>() { details_model }, achievement.AchievementId, total_score);
|
|
return Json(Tool.GetJsonWithCode(APICode.Success, "操作票步骤总分:" + total_score));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取步骤得分
|
|
/// </summary>
|
|
/// <param name="list_proc"></param>
|
|
/// <returns></returns>
|
|
private int get_ticket_proc_scrore(List<Competition.Mysql.Model.pow_user_operation_proc_ticket> list_proc)
|
|
{
|
|
int total = 5;
|
|
foreach (var item in list_proc)
|
|
{
|
|
//未做步骤直接扣1分
|
|
if (item.State == 0)
|
|
{
|
|
total = total - 1;
|
|
if (total <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
//已做步骤按真实情况扣分或不扣分
|
|
else
|
|
{
|
|
total = total - item.Score;
|
|
if (total <= 0)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
return total;
|
|
}
|
|
}
|
|
}
|