CompetitionAPI_dotnet/CompetitionAPI/Controllers/unity/WriteTicketProcController.cs

126 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Competition.Common.Util;
using CompetitionAPI.api.unity;
using CompetitionAPI.Util;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace CompetitionAPI.Controllers.unity
{
[Route("unity/[controller]")]
[ApiController]
public class WriteTicketProcController : Controller
{
Competition.Mysql.BLL.pow_user_exam user_exam_bll = new Competition.Mysql.BLL.pow_user_exam();
Competition.Mysql.BLL.pow_user_operation_proc_ticket bll_pow_user_operation_proc_ticket = new Competition.Mysql.BLL.pow_user_operation_proc_ticket();
public WriteTicketProcController()
{
}
/// <summary>
/// 写入操作票步骤单步结果接口
/// </summary>
/// <param name="req"></param>
/// <returns></returns>
[Authorize]
[HttpPost]
[APIFilter]
public JsonResult Index([FromForm] WriteTicketProcRequest req)
{
try
{
if (string.IsNullOrEmpty(req.OperationTicketId))
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "OperationTicketId参数不能为空"));
}
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参数不能为空"));
}
if (string.IsNullOrEmpty(req.Score))
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "Score参数不能为空"));
}
if (string.IsNullOrEmpty(req.ScoreReason))
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "ScoreReason参数不能为空"));
}
var user_exam_model = user_exam_bll.GetModelList(" ExamId='" + req.ExamId + "' and UserId='" + req.UserId + "' ").FirstOrDefault();
if (user_exam_model != null)
{
if (user_exam_model.Status == "已结束")
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "考生考试已结束"));
}
}
else
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "考生考试信息不存在"));
}
//OperationTicketId: 步骤id
//UserId :用户id
//ExamId:考试id
//Type:送电、停电
//Score 扣分值:0不扣分
//ScoreReason扣分原因
var qry = string.Format(" OperationTicketId='{0}' and UserId='{1}' and ExamId='{2}' and Type='{3}' ", req.OperationTicketId, req.UserId, req.ExamId, req.Type);
var proc_ticket = bll_pow_user_operation_proc_ticket.GetModelList(qry).FirstOrDefault();
if (proc_ticket != null)
{
proc_ticket.State = 1; //已开始
proc_ticket.UpdateTime = DateTime.Now;
int i_score = 0;
int.TryParse(req.Score, out i_score);
proc_ticket.Score = i_score;
proc_ticket.ScoreReason = req.ScoreReason;
//是否扣分 01
if (i_score > 0)
{
proc_ticket.IsScore = "1";
}
else
{
proc_ticket.IsScore = "0";
}
var flag = bll_pow_user_operation_proc_ticket.Update(proc_ticket);
if (flag)
{
return Json(Tool.GetJsonWithCode(APICode.Success, ""));
}
else
{
return Json(Tool.GetJsonWithCode(APICode.Fail, ""));
}
}
else
{
return Json(Tool.GetJsonWithCode(APICode.Fail, "操作票步骤信息不存在"));
}
}
catch (Exception ex)
{
LogHelper.WriteLog(ex.Message + ",行号:" + ex.StackTrace);
return Json(Tool.GetJsonWithCode(APICode.Fail, "发生错误,请联系管理员。"));
}
}
}
}