using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; /// /// 试卷详情 /// [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 stepList = new List(); } public class FractionManager : MonoBehaviour { public ExamRoot examData = new ExamRoot(); public List examStepItem = new List(); public static FractionManager Instance; [SerializeField] float Totalscore; public bool isok = true; public bool isYanDian = false; public int sum = 0;//工器具分数 public List errorTools = new List(); public List rightTools = new List(); public List examPaperDetails = new List(); public bool isDianBi = true; public string[] exceptionRecordKeywords = new string[6] { "A相", "B相", "C相", "电流", "短接", "窃电" }; public List testPen = new List(); /// /// 记录检查 /// public Dictionary> recordCheck = new Dictionary>(); 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>(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; } /// /// 检测工器具得分数 /// /// 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); } /// /// 填写工作单 /// /// /// public void CheckWriteOders(int score, List 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); } /// /// 联系客户-打开服务器 /// 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); } /// /// 联系客户-展示工作证 /// 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); } /// /// 柜门验电 /// 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; /// /// 检测钳形电流表 /// 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; /// /// 检测万用表 /// 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; } } /// /// 异常记录 /// 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 keywords = new List(); foreach (string keyword in exceptionRecordKeywords) { if (sentence.Contains(keyword)) { keywords.Add(keyword); } } if (keywords.Count == 0) return 1; else return 0; } /// /// 通过名称移除检测列表中得对象 /// /// 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; } } /// /// 分数上传 /// /// /// /// /// 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(); } } } } }