134 lines
4.5 KiB
C#
134 lines
4.5 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;
|
|
|
|
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 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 Mission mission;
|
|
public string missionText;
|
|
|
|
public Dictionary<string, string> defaultTicketValues = new Dictionary<string, string>();
|
|
public Dictionary<string, string> selectedTicketValues = new Dictionary<string, string>();
|
|
|
|
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");
|
|
}
|
|
|
|
|
|
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)
|
|
{
|
|
|
|
string placeholder = $"${{{property.Name}}}";
|
|
content = content.Replace(placeholder, property.GetValue(mission.configurations, null).ToString());
|
|
}
|
|
}
|
|
return content;
|
|
}
|
|
|
|
public float CalculateCorrectRate()
|
|
{
|
|
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 = 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;
|
|
}
|
|
}
|