262 lines
15 KiB
C#
262 lines
15 KiB
C#
using Competition.Common.Util;
|
|
using CompetitionAPI.api.unity;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using CompetitionAPI.Util;
|
|
|
|
namespace CompetitionAPI.Controllers.unity
|
|
{
|
|
[Route("unity/[controller]")]
|
|
[ApiController]
|
|
public class EndFaultOperationController : Controller
|
|
{
|
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
|
|
|
Competition.Mysql.BLL.pow_user_exam user_exam_bll = new Competition.Mysql.BLL.pow_user_exam();
|
|
|
|
Competition.Mysql.BLL.pow_user_fault user_fault_bll = new Competition.Mysql.BLL.pow_user_fault();
|
|
|
|
Competition.Mysql.BLL.pow_exam_fault exam_fault_bll = new Competition.Mysql.BLL.pow_exam_fault();
|
|
|
|
Competition.Mysql.BLL.pow_achievement achievement_bll = new Competition.Mysql.BLL.pow_achievement();
|
|
|
|
Competition.Mysql.BLL.pow_achievement_details achievement_details_bll = new Competition.Mysql.BLL.pow_achievement_details();
|
|
|
|
Competition.Mysql.BLL.pow_config config_bll = new Competition.Mysql.BLL.pow_config();
|
|
|
|
public EndFaultOperationController(IWebHostEnvironment webHostEnvironment)
|
|
{
|
|
_webHostEnvironment = webHostEnvironment;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 结束故障排故处理接口
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
[Authorize]
|
|
[HttpPost]
|
|
[APIFilter]
|
|
public JsonResult Index([FromForm] EndFaultOperationRequest req)
|
|
{
|
|
try
|
|
{
|
|
var config_model = config_bll.GetModelList("").FirstOrDefault();
|
|
if (config_model == null)
|
|
{
|
|
return Json(Tool.GetJsonWithCode(APICode.Fail, "配置信息不存在"));
|
|
}
|
|
var details_list = new List<Competition.Mysql.Model.pow_achievement_details>();
|
|
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 exam_fault = exam_fault_bll.GetModelList(" ExamId='" + req.ExamId + "' and ChoiceQuestion!='0' order by CreateTime asc ");
|
|
var user_fault = user_fault_bll.GetModelList(" ExamId='" + req.ExamId + "' and UserId='" + req.UserId + "' ");
|
|
var select_total_score = exam_fault.Sum(a => decimal.Parse(a.SelectSocre));
|
|
var fault_total_score = exam_fault.Sum(a => decimal.Parse(a.FaultScore));
|
|
var handler_score = exam_fault.Sum(a => decimal.Parse(a.HandlerScore));
|
|
var total = select_total_score + fault_total_score + handler_score;//总分
|
|
var TotalDefectScore = decimal.Parse(config_model.TotalDefectScore);
|
|
//组织树
|
|
var tree_list = ReadTree();
|
|
var new_exam_fault = exam_fault.Where(a => a.SpecificSimulation == "现场处理").ToList();
|
|
foreach (var item in new_exam_fault)
|
|
{
|
|
var root_device_name = "";
|
|
var device_name = "";
|
|
var user_fault_model = user_fault.Where(a => a.FaultId == item.FaultId).FirstOrDefault();
|
|
if (user_fault_model != null)
|
|
{
|
|
var first_list = tree_list.Where(a => a.TowerId == item.RootDeviceId).FirstOrDefault();
|
|
if (first_list != null)
|
|
{
|
|
root_device_name = first_list.Tower;
|
|
if (first_list.TowerId != item.DeviceId)
|
|
{
|
|
if (first_list.Data != null)
|
|
{
|
|
var two_list = first_list.Data.Where(a => a.PowerDistributionBoxId == item.DeviceId).FirstOrDefault();
|
|
if (two_list != null)
|
|
{
|
|
device_name = two_list.PowerDistributionBox;
|
|
}
|
|
else
|
|
{
|
|
var three_list = first_list.Data.SelectMany(a => a.Data).Where(a => a.LineId == item.DeviceId).FirstOrDefault();
|
|
if (three_list != null)
|
|
{
|
|
device_name = three_list.Line;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (item.ChoiceQuestion == user_fault_model.ChoiceQuestion)
|
|
{
|
|
var value_list = new List<string>();
|
|
var select_value_list = new List<string>();
|
|
if (item.FaultDesc == "配电箱箱门未加锁" || item.FaultDesc == "柜门与箱体没有链接线")
|
|
{
|
|
if (!string.IsNullOrEmpty(item.Position))
|
|
{
|
|
value_list = item.Position.Split('|').ToList();
|
|
select_value_list = user_fault_model.Position.Split('|').ToList();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (item.FaultDesc == "配电箱孔洞未封堵"
|
|
|| item.FaultDesc == "熔断器下桩头发热"
|
|
|| item.FaultDesc == "熔芯不匹配"
|
|
|| item.FaultDesc == "熔芯损坏"
|
|
|| item.FaultDesc == "电缆头套管相色缺失"
|
|
|| item.FaultDesc == "电缆接头发热"
|
|
|| item.FaultDesc == "电缆绝缘层老化开裂"
|
|
|| item.FaultDesc == "拉线无警示套管"
|
|
|| item.FaultDesc == "拉线松动"
|
|
|| item.FaultDesc == "拉线断股锈蚀"
|
|
|| item.FaultDesc == "拉线UT线夹螺帽不齐全"
|
|
|| item.FaultDesc == "接头发热"
|
|
|| item.FaultDesc == "线路弧垂不一致")
|
|
{
|
|
if (!string.IsNullOrEmpty(item.MultipleQuestion))
|
|
{
|
|
if (item.FaultDesc != "相色标识错误")
|
|
{
|
|
value_list = item.MultipleQuestion.Split('|').ToList();
|
|
select_value_list = user_fault_model.MultipleQuestion.Split('|').ToList();
|
|
}
|
|
}
|
|
//if (!string.IsNullOrEmpty(item.MultipleQuestion))
|
|
//{
|
|
// value_list = item.MultipleQuestion.Split('|').ToList();
|
|
// select_value_list = user_fault_model.MultipleQuestion.Split('|').ToList();
|
|
//}
|
|
}
|
|
}
|
|
|
|
if (value_list.Count == 0)
|
|
{
|
|
decimal processing_score = 0;
|
|
|
|
processing_score = System.Decimal.Round((decimal.Parse(item.HandlerScore) / total) * TotalDefectScore, 3);
|
|
var item_name = user_fault_model.FaultDesc + "-" + "缺陷处理分值";
|
|
item_name = root_device_name + "-" + device_name + "-" + item_name;
|
|
var achievement_details_model = achievement_details_bll.GetModelList(" AchievementId='" + achievement_model.AchievementId + "' and ItemName='" + item_name + "' ").FirstOrDefault();
|
|
if (achievement_details_model == null)
|
|
{
|
|
var add_details_model = new Competition.Mysql.Model.pow_achievement_details();
|
|
add_details_model.DetailsId = Guid.NewGuid().ToString("N");
|
|
add_details_model.AchievementId = achievement_model.AchievementId;
|
|
add_details_model.ItemName = item_name;
|
|
add_details_model.ItemizedScore = 0;
|
|
add_details_model.Type = "故障排故处理";
|
|
add_details_model.CreateTime = DateTime.Now;
|
|
add_details_model.TotalScore = processing_score;
|
|
add_details_model.FaultDesc = item_name.Replace("-缺陷处理分值", "");
|
|
add_details_model.ScoreType = "缺陷处理分值";
|
|
details_list.Add(add_details_model);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var position_item in value_list)
|
|
{
|
|
if (select_value_list.Contains(position_item))
|
|
{
|
|
decimal processing_score = 0;
|
|
|
|
var processing_score_model = System.Decimal.Round((decimal.Parse(item.HandlerScore) / total) * TotalDefectScore, 3);
|
|
decimal otherQuestionScore = 0;
|
|
var firstQuestionScore = Tool.TransFormation(processing_score_model, value_list.Count, out otherQuestionScore);
|
|
|
|
var user_Index = value_list.IndexOf(position_item);
|
|
if (user_Index == 0)
|
|
{
|
|
processing_score = firstQuestionScore;
|
|
}
|
|
else
|
|
{
|
|
processing_score = otherQuestionScore;
|
|
}
|
|
|
|
var item_name = user_fault_model.FaultDesc + "-" + position_item + "-" + "缺陷处理分值";
|
|
item_name = root_device_name + "-" + device_name + "-" + item_name;
|
|
var achievement_details_model = achievement_details_bll.GetModelList(" AchievementId='" + achievement_model.AchievementId + "' and ItemName='" + item_name + "' ").FirstOrDefault();
|
|
if (achievement_details_model == null)
|
|
{
|
|
var add_details_model = new Competition.Mysql.Model.pow_achievement_details();
|
|
add_details_model.DetailsId = Guid.NewGuid().ToString("N");
|
|
add_details_model.AchievementId = achievement_model.AchievementId;
|
|
add_details_model.ItemName = item_name;
|
|
add_details_model.ItemizedScore = 0;
|
|
add_details_model.Type = "故障排故处理";
|
|
add_details_model.CreateTime = DateTime.Now;
|
|
add_details_model.TotalScore = processing_score;
|
|
add_details_model.FaultDesc = item_name.Replace("-缺陷处理分值", "");
|
|
add_details_model.ScoreType = "缺陷处理分值";
|
|
details_list.Add(add_details_model);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
var details = achievement_details_bll.GetModelList(" AchievementId='" + achievement_model.AchievementId + "' and Type='故障排故处理' ");
|
|
var total_score = details.Sum(a => a.ItemizedScore);
|
|
if (achievement_bll.OperationAddUpdateData(details_list, achievement_model.AchievementId, total_score.Value) > 0)
|
|
{
|
|
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, "发生错误,请联系管理员。"));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取树结构json
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private List<Competition.Mysql.Other.fault_tree> ReadTree()
|
|
{
|
|
var tree_list = new List<Competition.Mysql.Other.fault_tree>();
|
|
string fault_tree_file = _webHostEnvironment.WebRootPath + "/Json/FaultTree.json";
|
|
//读取json文件
|
|
using (StreamReader file = System.IO.File.OpenText(fault_tree_file))
|
|
{
|
|
using (JsonTextReader reader = new JsonTextReader(file))
|
|
{
|
|
tree_list = JsonConvert.DeserializeObject<List<Competition.Mysql.Other.fault_tree>>(JToken.ReadFrom(reader).ToString());
|
|
}
|
|
}
|
|
return tree_list;
|
|
}
|
|
}
|
|
}
|