165 lines
8.3 KiB
C#
165 lines
8.3 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;
|
|
|
|
namespace CompetitionAPI.Controllers.unity
|
|
{
|
|
[Route("unity/[controller]")]
|
|
[ApiController]
|
|
public class AddUserToolController : Controller
|
|
{
|
|
Competition.Mysql.BLL.pow_user_tool user_tool_bll = new Competition.Mysql.BLL.pow_user_tool();
|
|
|
|
Competition.Mysql.BLL.pow_achievement achievement_bll = new Competition.Mysql.BLL.pow_achievement();
|
|
|
|
Competition.Mysql.BLL.pow_user_exam user_exam_bll = new Competition.Mysql.BLL.pow_user_exam();
|
|
|
|
Competition.Mysql.BLL.pow_config config_bll = new Competition.Mysql.BLL.pow_config();
|
|
|
|
public AddUserToolController()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 巡线、排故工器具接口
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpPost]
|
|
[APIFilter]
|
|
public JsonResult Index([FromBody] AddUserToolRequest req)
|
|
{
|
|
try
|
|
{
|
|
if (req != null)
|
|
{
|
|
var config_model = config_bll.GetModelList("").FirstOrDefault();
|
|
if (config_model == null)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "配置信息不存在"));
|
|
}
|
|
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, "考生考试已结束"));
|
|
}
|
|
var achievement_model = achievement_bll.GetModelList(" ExamId='" + req.ExamId + "' and UserId='" + req.UserId + "' ").FirstOrDefault();
|
|
if (achievement_model == null)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "考生成绩数据不存在"));
|
|
}
|
|
var user_tool_list = user_tool_bll.GetModelList(" UserId='" + req.UserId + "' and ExamId='" + req.ExamId + "' and Purpose='" + req.Purpose + "' ");
|
|
var tool_list = req.Tool.Select(a => a.ToolName).ToList();
|
|
//var local_tool_list = model.Tool.Select(a => a.ToolName).ToList();
|
|
|
|
//用户有、正确有,修改是否选择
|
|
//用户有、正确没有,新增数据
|
|
//用户没有、正确有,
|
|
//巡检总分
|
|
var LineTotalScore = double.Parse(config_model.LineTotalScore);
|
|
//多选扣分值
|
|
var LineMultipleScore = double.Parse(config_model.LineMultipleScore);
|
|
//少选扣分值
|
|
var LineMomentScore = double.Parse(config_model.LineMomentScore);
|
|
var total_score = decimal.Parse(LineTotalScore.ToString());
|
|
////相同的数据
|
|
//var IdenticalData = user_tool_list.Where(s => tool_list.Contains(s.ToolName)).Select(s => s.ToolName).ToArray();
|
|
////不同
|
|
//var DifferentData = user_tool_list.Where(s => !tool_list.Contains(s.ToolName)).ToList();
|
|
////不同 用户选择数据里有,本地数据库里没有
|
|
//var FieldCaseData = model.Tool.Where(s => !local_tool_list.Contains(s.ToolName)).ToList();
|
|
|
|
var add_tool_list = new List<Competition.Mysql.Model.pow_user_tool>();
|
|
var update_tool_list = new List<Competition.Mysql.Model.pow_user_tool>();
|
|
foreach (var item in req.Tool)
|
|
{
|
|
var tool_model = user_tool_list.Where(a => a.ToolName == item.ToolName).FirstOrDefault();
|
|
if (tool_model != null)
|
|
{
|
|
tool_model.Quantity = item.Quantity;
|
|
tool_model.IsSelect = "1";
|
|
tool_model.IsScore = "0";
|
|
update_tool_list.Add(tool_model);
|
|
}
|
|
else
|
|
{
|
|
if (LineTotalScore != 0)
|
|
{
|
|
LineTotalScore = LineTotalScore - LineMultipleScore;
|
|
if (LineTotalScore < 0)
|
|
{
|
|
LineTotalScore = 0;
|
|
}
|
|
}
|
|
var add_tool_model = new Competition.Mysql.Model.pow_user_tool();
|
|
add_tool_model.UserToolId = Guid.NewGuid().ToString("N");
|
|
add_tool_model.UserId = req.UserId;
|
|
add_tool_model.ExamId = req.ExamId;
|
|
add_tool_model.Purpose = req.Purpose;
|
|
add_tool_model.ToolName = item.ToolName;
|
|
add_tool_model.IsSelect = "1";
|
|
add_tool_model.Quantity = item.Quantity;
|
|
add_tool_model.IsScore = "1";
|
|
add_tool_list.Add(add_tool_model);
|
|
}
|
|
}
|
|
|
|
//本地数据库正确数据里有,用户选择数据里没有,少选
|
|
var correct_data = user_tool_list.Where(s => !tool_list.Contains(s.ToolName)).ToList();
|
|
foreach (var item in correct_data)
|
|
{
|
|
if (LineTotalScore != 0)
|
|
{
|
|
LineTotalScore = LineTotalScore - LineMomentScore;
|
|
if (LineTotalScore < 0)
|
|
{
|
|
LineTotalScore = 0;
|
|
}
|
|
}
|
|
item.IsScore = "1";
|
|
update_tool_list.Add(item);
|
|
}
|
|
|
|
var details_model = new Competition.Mysql.Model.pow_achievement_details();
|
|
details_model.DetailsId = Guid.NewGuid().ToString("N");
|
|
details_model.AchievementId = achievement_model.AchievementId;
|
|
details_model.ItemName = req.Purpose + "工器具选择";
|
|
details_model.ItemizedScore = decimal.Parse(LineTotalScore.ToString());
|
|
details_model.Type = req.Purpose + "工器具";
|
|
details_model.CreateTime = DateTime.Now;
|
|
details_model.TotalScore = total_score;
|
|
if (user_tool_bll.OperationAddUpdateData(add_tool_list, update_tool_list, details_model, achievement_model.AchievementId, details_model.ItemizedScore.Value) > 0)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Success, "成功"));
|
|
}
|
|
else
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "失败"));
|
|
}
|
|
}
|
|
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, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
}
|
|
}
|