172 lines
6.2 KiB
C#
172 lines
6.2 KiB
C#
using LitJson;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using System.Reflection;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
public class Configurations
|
|
{
|
|
public string title { get; set; }
|
|
public string startdate { get; set; }
|
|
public string enddate { get; set; }
|
|
public string line { get; set; }//线路名称
|
|
public string station { get; set; }//台区名称
|
|
public string company { get; set; }//公司名称
|
|
public string leader { get; set; }//工作负责人
|
|
public string licensor { get; set; }//工作许可人
|
|
public string issuer { get; set; }//工作签发人
|
|
public string contects { get; set; }//联系人
|
|
public string team { get; set; }//班组名称
|
|
public string member { get; set; }//班组成员
|
|
public string mission { get; set; }//工作任务
|
|
//public string targetDevice { get; set; }//目标设备
|
|
public string tel { get; set; }//联系电话
|
|
public string hasElectric { get; set; }//5.1安全措施
|
|
public string electricPart { get; set; }//带电部分
|
|
|
|
public string userName { get; set; }//用户名称
|
|
public string userContects { get; set; }//用户联系人
|
|
public string userTel { get; set; }//用户联系电话
|
|
}
|
|
|
|
public class Mission
|
|
{
|
|
public Configurations configurations;
|
|
public string content;
|
|
public List<string> workTicketLabelsSelect;//工作票需要选定的标签
|
|
}
|
|
|
|
public class MissionMgr : BaseManager<MissionMgr>
|
|
{
|
|
public WorkTicketType defaultWorkTicketType = WorkTicketType.无;//工作票类型
|
|
public WorkTicketType selectedWorkTicketType = WorkTicketType.无;//工作票类型
|
|
public Mission mission;//从missiondata读取的任务内容
|
|
public string missionText;//显示在工作票上的任务内容
|
|
|
|
public Dictionary<string, string> defaultTicketValues = new Dictionary<string, string>();//stream下面的WorkOrderAndWorkTicket
|
|
public Dictionary<string, string> selectedTicketValues = new Dictionary<string, string>();
|
|
|
|
public void Reset()
|
|
{
|
|
selectedWorkTicketType = WorkTicketType.无;
|
|
selectedTicketValues.Clear();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
defaultTicketValues.Clear();
|
|
string path = $"MissionData/{GameManager.RunModelMgr.schemeID.ToString()}";
|
|
mission = GameManager.JsonMgr.LoadData<Mission>(path);
|
|
missionText = File.ReadAllText(Application.streamingAssetsPath + "/" + path + ".json");
|
|
string xmlContent = "";
|
|
Directory.GetFiles(Application.streamingAssetsPath + $"/Setting/科目/{GameManager.Instance.systemId}").ToList().ForEach(a =>
|
|
{
|
|
if (Path.GetExtension(a) == ".xml" && a.Contains(GameManager.RunModelMgr.schemeID.ToString()))
|
|
{
|
|
xmlContent = File.ReadAllText(a);
|
|
foreach (var item in Enum.GetValues(typeof(WorkTicketType)))
|
|
{
|
|
if (xmlContent.Contains(item.ToString()))
|
|
{
|
|
defaultWorkTicketType = (WorkTicketType)Enum.Parse(typeof(WorkTicketType), item.ToString());
|
|
Debug.Log("工作票类型:" + defaultWorkTicketType);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
});
|
|
if (defaultWorkTicketType == WorkTicketType.无)
|
|
{
|
|
defaultWorkTicketType = WorkTicketType.低压工作票;
|
|
}
|
|
}
|
|
|
|
|
|
public void SaveMissionData()
|
|
{
|
|
string path = $"MissionData/{GameManager.RunModelMgr.schemeID.ToString()}";
|
|
try
|
|
{
|
|
GameManager.JsonMgr.SaveData(mission, path);
|
|
missionText = File.ReadAllText(Application.streamingAssetsPath + "/" + path + ".json");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError("任务内容本地更新失败:" + e);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将工作票内容中的配置项替换
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string ToMissionText()
|
|
{
|
|
string content = "";
|
|
JObject jsonObj = JObject.Parse(missionText);
|
|
content = (string)jsonObj["content"];
|
|
if (mission.configurations == null)
|
|
{
|
|
JObject configurations = (JObject)jsonObj["configurations"];
|
|
foreach (var config in configurations.Properties())
|
|
{
|
|
string placeholder = $"${{{config.Name}}}";
|
|
content = content.Replace(placeholder, (string)config.Value);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Type typeOfconfig = mission.configurations.GetType();
|
|
PropertyInfo[] properties = typeOfconfig.GetProperties();
|
|
foreach (PropertyInfo property in properties)
|
|
{
|
|
//Debug.Log("===>" + property.Name);
|
|
if (property.GetValue(mission.configurations, null) != null)
|
|
{
|
|
string placeholder = $"${{{property.Name}}}";
|
|
content = content.Replace(placeholder, property.GetValue(mission.configurations, null).ToString());
|
|
}
|
|
}
|
|
}
|
|
return content;
|
|
}
|
|
|
|
public float CalculateCorrectRate()
|
|
{
|
|
if (defaultWorkTicketType != selectedWorkTicketType)return 0;
|
|
|
|
float rate = 0;
|
|
int total = defaultTicketValues.Count - 1;
|
|
int count = 0;
|
|
foreach (var item in defaultTicketValues)
|
|
{
|
|
if(selectedTicketValues.ContainsKey(item.Key) && item.Value == selectedTicketValues[item.Key])
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
string def_Labels = "";
|
|
if (defaultTicketValues.ContainsKey("workTicketLabelsSelect"))
|
|
def_Labels = defaultTicketValues["workTicketLabelsSelect"];
|
|
List<string> def_LabelsList = new List<string>(def_Labels.Split('&'));
|
|
total += def_LabelsList.Count;
|
|
if (def_LabelsList.Count > 0) total--;
|
|
if (selectedTicketValues.ContainsKey("workTicketLabelsSelect"))
|
|
{
|
|
string sel_Labels = selectedTicketValues["workTicketLabelsSelect"];
|
|
List<string> sel_LabelsList = new List<string>(sel_Labels.Split('&'));
|
|
count += ToolFuncManager.CountMatches(def_LabelsList, sel_LabelsList);
|
|
if (sel_LabelsList.Count > 0) count--;
|
|
}
|
|
rate = count * 1.0f / total;
|
|
return rate;
|
|
}
|
|
}
|