398 lines
11 KiB
C#
398 lines
11 KiB
C#
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
/// <summary>
|
||
/// 试卷详情
|
||
/// </summary>
|
||
[Serializable]
|
||
public class ExamPaperDetails
|
||
{
|
||
public string stepName;
|
||
public string testPoint;
|
||
public float setScore;
|
||
public float score;
|
||
}
|
||
[Serializable]
|
||
public class CurrentExamPaperDetails
|
||
{
|
||
public string userName;
|
||
public string userId;
|
||
public int examId;
|
||
public int classId;
|
||
public string useTime;
|
||
public int examClassId;
|
||
public List<ExamPaperDetails> stepList = new List<ExamPaperDetails>();
|
||
}
|
||
|
||
public class FractionManager : MonoBehaviour
|
||
{
|
||
public ExamRoot examData = new ExamRoot();
|
||
public List<ExamStepItem> examStepItem = new List<ExamStepItem>();
|
||
public static FractionManager Instance;
|
||
[SerializeField] float Totalscore;
|
||
public bool isok = true;
|
||
public bool isYanDian = false;
|
||
public int sum = 0;//工器具分数
|
||
|
||
public List<string> errorTools = new List<string>();
|
||
public List<string> rightTools = new List<string>();
|
||
public List<ExamPaperDetails> examPaperDetails = new List<ExamPaperDetails>();
|
||
public bool isDianBi = true;
|
||
public string[] exceptionRecordKeywords = new string[6] { "A相", "B相", "C相", "电流", "短接", "窃电" };
|
||
|
||
public List<Fraction> testPen = new List<Fraction>();
|
||
/// <summary>
|
||
/// 记录检查
|
||
/// </summary>
|
||
public Dictionary<string, List<string>> recordCheck = new Dictionary<string, List<string>>();
|
||
|
||
private void Awake()
|
||
{
|
||
if (Instance != null)
|
||
{
|
||
Destroy(Instance);
|
||
return;
|
||
}
|
||
Instance = this;
|
||
isDianBi = true;
|
||
DontDestroyOnLoad(Instance);
|
||
}
|
||
public void OnInit()
|
||
{
|
||
CheckCabinetDoor(false);
|
||
CheckWanYong(false);
|
||
CheckQianXing(false);
|
||
CheckCallCustomShowWorkCard(false);
|
||
CheckToolsSum();
|
||
CheckCallCustomOpenServer(false);
|
||
isWanYongOnce = true;
|
||
isQianXing = true;
|
||
|
||
}
|
||
public void GetExamData()
|
||
{
|
||
examStepItem = JsonConvert.DeserializeObject<List<ExamStepItem>>(examData.data.examContent);
|
||
}
|
||
|
||
public void UpdateEPDByStep(string testPoint)
|
||
{
|
||
for (int i = 0; i < examPaperDetails.Count; i++)
|
||
{
|
||
if (examPaperDetails[i].testPoint == testPoint)
|
||
{
|
||
examPaperDetails.Remove(examPaperDetails[i]);
|
||
}
|
||
}
|
||
}
|
||
|
||
public float GetDefaultScore(string testPoint)
|
||
{
|
||
for (int i = 0; i < examStepItem.Count; i++)
|
||
{
|
||
if (examStepItem[i].point.Equals(testPoint))
|
||
return float.Parse(examStepItem[i].score);
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检测工器具得分数
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public void CheckToolsSum()
|
||
{
|
||
string tempTestPoint = "在工具间选择需要带到现场的工器具(验电笔、安全帽、绝缘鞋(设置日期)、钳形表、万用表、螺丝刀(绝缘包裹)、钢丝钳、服务记录仪、绝缘手套、钳形电流表_大、工作卡(背包默认存在工作证、移动作业终端)迷惑项:金属梯子、螺丝刀金属部分未绝缘包裹,日期超期)";
|
||
UpdateEPDByStep(tempTestPoint);
|
||
ExamPaperDetails e = new ExamPaperDetails();
|
||
e.stepName = "检查工器具";
|
||
e.testPoint = tempTestPoint;
|
||
e.setScore = GetDefaultScore(tempTestPoint);
|
||
float rightScore = e.setScore / 12;
|
||
if (rightTools.Count - errorTools.Count > 0)
|
||
{
|
||
e.score = (float)Math.Round((rightTools.Count - errorTools.Count) * rightScore, 2);
|
||
}
|
||
else
|
||
{
|
||
e.score = 0;
|
||
}
|
||
|
||
examPaperDetails.Add(e);
|
||
}
|
||
/// <summary>
|
||
/// 填写工作单
|
||
/// </summary>
|
||
/// <param name="score"></param>
|
||
/// <param name="stepPoints"></param>
|
||
public void CheckWriteOders(int score, List<string> stepPoints)
|
||
{
|
||
string tempTestPoint = "填写现场工作卡(通过下拉菜单来填写)";
|
||
UpdateEPDByStep(tempTestPoint);
|
||
ExamPaperDetails e = new ExamPaperDetails();
|
||
e.stepName = "填写工作单";
|
||
e.testPoint = tempTestPoint;
|
||
e.setScore = GetDefaultScore(tempTestPoint);
|
||
float rightScore = e.setScore / 8;
|
||
e.score = (float)Math.Round(score * rightScore, 2);
|
||
examPaperDetails.Add(e);
|
||
}
|
||
/// <summary>
|
||
/// 联系客户-打开服务器
|
||
/// </summary>
|
||
public void CheckCallCustomOpenServer(bool isOpen)
|
||
{
|
||
string tempTestPoint = "打开服务记录仪、全程记录";
|
||
UpdateEPDByStep(tempTestPoint);
|
||
ExamPaperDetails e = new ExamPaperDetails();
|
||
e.stepName = "联系客户";
|
||
e.testPoint = tempTestPoint;
|
||
e.setScore = GetDefaultScore(tempTestPoint);
|
||
if (isOpen)
|
||
{
|
||
e.score = e.setScore;
|
||
}
|
||
else
|
||
{
|
||
e.score = 0;
|
||
}
|
||
examPaperDetails.Add(e);
|
||
}
|
||
/// <summary>
|
||
/// 联系客户-展示工作证
|
||
/// </summary>
|
||
public void CheckCallCustomShowWorkCard(bool isOpen)
|
||
{
|
||
string tempTestPoint = "出示工作证、告知用户来进行用电检查";
|
||
UpdateEPDByStep(tempTestPoint);
|
||
ExamPaperDetails e = new ExamPaperDetails();
|
||
e.stepName = "联系客户";
|
||
e.testPoint = tempTestPoint;
|
||
e.setScore = GetDefaultScore(tempTestPoint);
|
||
if (isOpen)
|
||
{
|
||
e.score = e.setScore;
|
||
}
|
||
else
|
||
{
|
||
e.score = 0;
|
||
}
|
||
examPaperDetails.Add(e);
|
||
}
|
||
/// <summary>
|
||
/// 柜门验电
|
||
/// </summary>
|
||
public void CheckCabinetDoor(bool isRightStep)
|
||
{
|
||
string tempTestPoint = "拿出验电笔在有电的地方测试验电笔是否好坏。如果验电笔是好的验过并网柜门之后再次在有电的地方测试验电笔好坏。确保并网柜外壳确无电压。验电流程经过第一个三步之后,后续开门只需要一步";
|
||
UpdateEPDByStep(tempTestPoint);
|
||
ExamPaperDetails e = new ExamPaperDetails();
|
||
e.stepName = "柜门验电";
|
||
e.testPoint = tempTestPoint;
|
||
e.setScore = GetDefaultScore(tempTestPoint);
|
||
if (isRightStep)
|
||
{
|
||
e.score = e.setScore;
|
||
}
|
||
else
|
||
{
|
||
e.score = 0;
|
||
}
|
||
examPaperDetails.Add(e);
|
||
}
|
||
public bool isQianXing = true;
|
||
/// <summary>
|
||
/// 检测钳形电流表
|
||
/// </summary>
|
||
public void CheckQianXing(bool isOK)
|
||
{
|
||
if (isQianXing)
|
||
{
|
||
string tempTestPoint = "选择钳形电流表合适的量程对一次回路及二次回路电流进行检查。(在配电箱测出的数值无法与计量箱测出数值对应,则为异常,需打开电缆沟寻找窃电位置)";
|
||
UpdateEPDByStep(tempTestPoint);
|
||
ExamPaperDetails e = new ExamPaperDetails();
|
||
e.stepName = "现场检查";
|
||
e.testPoint = tempTestPoint;
|
||
e.setScore = GetDefaultScore(tempTestPoint);
|
||
if (isOK)
|
||
{
|
||
e.score = e.setScore;
|
||
}
|
||
else
|
||
{
|
||
e.score = 0;
|
||
}
|
||
examPaperDetails.Add(e);
|
||
isQianXing = false;
|
||
}
|
||
}
|
||
public bool isWanYongOnce = true;
|
||
/// <summary>
|
||
/// 检测万用表
|
||
/// </summary>
|
||
public void CheckWanYong(bool isOK)
|
||
{
|
||
if (isWanYongOnce)
|
||
{
|
||
string tempTestPoint = "使用万用表对表计电压进行检查是否正常,无断相现象。(电压检测出0V,为异常)";
|
||
UpdateEPDByStep(tempTestPoint);
|
||
ExamPaperDetails e = new ExamPaperDetails();
|
||
e.stepName = "现场检查";
|
||
e.testPoint = tempTestPoint;
|
||
e.setScore = GetDefaultScore(tempTestPoint);
|
||
if (isOK)
|
||
{
|
||
e.score = e.setScore;
|
||
}
|
||
else
|
||
{
|
||
e.score = 0;
|
||
}
|
||
examPaperDetails.Add(e);
|
||
isWanYongOnce = false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 异常记录
|
||
/// </summary>
|
||
public void CheckAbnormalRecords(string info)
|
||
{
|
||
string tempTestPoint = "随时可填写相关现场检查出的问题";
|
||
UpdateEPDByStep(tempTestPoint);
|
||
ExamPaperDetails e = new ExamPaperDetails();
|
||
e.stepName = "填写异常记录";
|
||
e.testPoint = tempTestPoint;
|
||
e.setScore = GetDefaultScore(tempTestPoint);
|
||
if (!string.IsNullOrEmpty(info) || info != "")
|
||
{
|
||
if (CheckForKeywords(info) == 1)
|
||
{
|
||
e.score = 0;
|
||
}
|
||
else
|
||
{
|
||
e.score = e.setScore;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
e.score = 0;
|
||
}
|
||
examPaperDetails.Add(e);
|
||
}
|
||
public int CheckForKeywords(string sentence)
|
||
{
|
||
List<string> keywords = new List<string>();
|
||
foreach (string keyword in exceptionRecordKeywords)
|
||
{
|
||
if (sentence.Contains(keyword))
|
||
{
|
||
keywords.Add(keyword);
|
||
}
|
||
}
|
||
|
||
if (keywords.Count == 0)
|
||
return 1;
|
||
else
|
||
return 0;
|
||
}
|
||
/// <summary>
|
||
/// 通过名称移除检测列表中得对象
|
||
/// </summary>
|
||
/// <param name="tool"></param>
|
||
public void RemoveToolByName(GameObject tool)
|
||
{
|
||
for (int i = 0; i < errorTools.Count; i++)
|
||
{
|
||
if (tool.name.Equals(errorTools[i]))
|
||
{
|
||
errorTools.Remove(errorTools[i]);
|
||
}
|
||
}
|
||
for (int i = 0; i < rightTools.Count; i++)
|
||
{
|
||
if (tool.name.Equals(rightTools[i]))
|
||
{
|
||
rightTools.Remove(rightTools[i]);
|
||
}
|
||
}
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
try
|
||
{
|
||
if (isYanDian)
|
||
{
|
||
//await overAsync(6, 10, "测量窃电点");
|
||
isok = false;
|
||
}
|
||
}
|
||
catch (System.Exception ex)
|
||
{
|
||
Debug.LogError(ex.Message);
|
||
throw;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 分数上传
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <param name="score"></param>
|
||
/// <param name="tips"></param>
|
||
/// <returns></returns>
|
||
public async Task overAsync(int id, int score, string tips)
|
||
{
|
||
if (isok)
|
||
{
|
||
isok = false;
|
||
await load(id, score, tips);
|
||
}
|
||
}
|
||
async Task load(int id, int score, string tips)
|
||
{
|
||
ExaminationLoad examinationLoad = new ExaminationLoad();
|
||
ExaminationData data = new ExaminationData
|
||
{
|
||
tip = tips,
|
||
id_card = UIManager.Instance.loginController.PassWord,
|
||
real_name = UIManager.Instance.loginController.userName,
|
||
score = score,
|
||
step = id
|
||
};
|
||
await examinationLoad.LoadAsync(data);
|
||
isok = true;
|
||
}
|
||
|
||
public void SwitchTestPenStep(Fraction f, ref bool isOnce)
|
||
{
|
||
if (isDianBi)
|
||
{
|
||
if (f.orderName == "验电")
|
||
{
|
||
if (!testPen.Contains(f))
|
||
testPen.Add(f);
|
||
}
|
||
|
||
if (testPen.Count == 3)
|
||
{
|
||
if (testPen[0].stepName.Equals("插座One") && testPen[1].stepName.Equals("柜门") && testPen[2].stepName.Equals("插座Two"))
|
||
{
|
||
CheckCabinetDoor(true);
|
||
//overAsync(4, 5, "验电");
|
||
Debug.Log("验电结束");
|
||
testPen[1].isOnce = false;
|
||
testPen[2].isOnce = false;
|
||
isOnce = false;
|
||
isDianBi = false;
|
||
testPen.Clear();
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|