177 lines
6.2 KiB
C#
177 lines
6.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using static MQTT;
|
|
using WI;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEngine;
|
|
|
|
namespace CHN
|
|
{
|
|
public class DataManager : MonoBehaviour, ISingle
|
|
{
|
|
public Action<Machine, SimpleField> onCompleteInfo;
|
|
public Action<Machine, SimpleField> onSimpleInfo;
|
|
private Dictionary<string, DashBoardData> machineTable = new();
|
|
private Dictionary<string, SimpleField> includeFields = new();
|
|
private HashSet<string> samples = new();
|
|
private List<SimpleField> simpleField;
|
|
private string simplePath;
|
|
public override void AfterAwake()
|
|
{
|
|
var machines = FindObjectsByType<Machine>(FindObjectsSortMode.None);
|
|
foreach (var machine in machines)
|
|
{
|
|
if (string.IsNullOrEmpty(machine.code))
|
|
continue;
|
|
|
|
if (machineTable.ContainsKey(GapRemove(machine.code)))
|
|
continue;
|
|
|
|
machineTable.Add(GapRemove(machine.code), new());
|
|
}
|
|
var fileds = typeof(DashBoardData).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
|
//simpleField= JsonConvert.DeserializeObject<List<SimpleField>>(simplePath);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
samples.Add(fileds[i].Name);
|
|
}
|
|
}
|
|
|
|
public void MachineMatching(List<CompleteInfo> machineInfos)
|
|
{
|
|
foreach (CompleteInfo info in machineInfos)
|
|
{
|
|
var id = info.workcd;
|
|
var name = GapRemove(id);
|
|
if (machineTable.ContainsKey(name))
|
|
{
|
|
machineTable[name] = SetDashboardMQTTData(info);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void GetSimpleCompleteData(Machine machine)
|
|
{
|
|
if (string.IsNullOrEmpty(machine.code))
|
|
return;
|
|
var machineName = GapRemove(machine.code);
|
|
if (includeFields.ContainsKey(machineName))
|
|
{
|
|
includeFields[machineName].machineInfo = machineTable[machineName];
|
|
}
|
|
else
|
|
{
|
|
var simpleTest = new SimpleField();
|
|
simpleTest.machineName = machineName;
|
|
simpleTest.machineInfo = machineTable[machineName];
|
|
simpleTest.simpleField = samples;
|
|
includeFields.Add(machineName, simpleTest);
|
|
}
|
|
|
|
//foreach(var simple in simpleField)
|
|
//{
|
|
// var machineName = GapRemove(machine.name);
|
|
// if (simple.machineName.Equals(machineName))
|
|
// {
|
|
// simple.machineInfo = machineTable[machineName];
|
|
// onSimpleInfo?.Invoke(simple);
|
|
// break;
|
|
// }
|
|
//}
|
|
onSimpleInfo?.Invoke(machine, includeFields[machineName]);
|
|
}
|
|
|
|
public void SimpleFiledChange(Machine machine, HashSet<string> fields)
|
|
{
|
|
if (string.IsNullOrEmpty(machine.code))
|
|
return;
|
|
var machineName = GapRemove(machine.code);
|
|
var simpleField = includeFields[machineName];
|
|
simpleField.simpleField = fields;
|
|
includeFields[machineName] = simpleField;
|
|
}
|
|
|
|
public void GetCompleteInfo(Machine machine)
|
|
{
|
|
if (string.IsNullOrEmpty(machine.code))
|
|
return;
|
|
var machineName = GapRemove(machine.code);
|
|
var simpleField = includeFields[machineName];
|
|
onCompleteInfo?.Invoke(machine, simpleField);
|
|
}
|
|
|
|
string GapRemove(string name)
|
|
{
|
|
return Regex.Replace(name, @"\s", "");
|
|
}
|
|
private DashBoardData SetDashboardMQTTData(CompleteInfo completeInfos)
|
|
{
|
|
var dashboardData = new DashBoardData();
|
|
|
|
dashboardData.wordno = completeInfos.wordno;
|
|
dashboardData.workdt = completeInfos.workdt;
|
|
dashboardData.daynight = completeInfos.daynight;
|
|
dashboardData.workcd = completeInfos.workcd;
|
|
dashboardData.worknm = completeInfos.worknm;
|
|
dashboardData.workseq = completeInfos.workseq;
|
|
dashboardData.statusnm = completeInfos.statusnm;
|
|
dashboardData.itemcd = completeInfos.itemcd;
|
|
dashboardData.itemdesc = completeInfos.itemdesc;
|
|
dashboardData.pjtcd = completeInfos.pjtcd;
|
|
dashboardData.matcd = completeInfos.matcd;
|
|
dashboardData.cycletime = completeInfos.cycletime;
|
|
dashboardData.cavity = completeInfos.cavity;
|
|
dashboardData.planqty = completeInfos.planqty;
|
|
dashboardData.goalqty = completeInfos.goalqty;
|
|
dashboardData.workqty = completeInfos.workqty;
|
|
dashboardData.goodqty = completeInfos.goodqty;
|
|
dashboardData.badqty = completeInfos.badqty;
|
|
dashboardData.badrate = completeInfos.badrate;
|
|
dashboardData.efficiency = completeInfos.efficiency;
|
|
dashboardData.progressrate = completeInfos.progressrate;
|
|
dashboardData.sttm = completeInfos.sttm;
|
|
dashboardData.totm = completeInfos.totm;
|
|
|
|
return dashboardData;
|
|
}
|
|
}
|
|
[Serializable]
|
|
public class SimpleField
|
|
{
|
|
public string machineName;
|
|
public DashBoardData machineInfo;
|
|
public HashSet<string> simpleField;
|
|
}
|
|
|
|
[Serializable]
|
|
public class DashBoardData
|
|
{
|
|
public string wordno;
|
|
public string workdt;
|
|
public string daynight;
|
|
public string workcd;
|
|
public string worknm;
|
|
public string workseq;
|
|
public string statusnm;
|
|
public string itemcd;
|
|
public string itemdesc;
|
|
public string pjtcd;
|
|
public string matcd;
|
|
public string cycletime;
|
|
public string cavity;
|
|
public string planqty;
|
|
public string goalqty;
|
|
public string workqty;
|
|
public string goodqty;
|
|
public string badqty;
|
|
public string badrate;
|
|
public string efficiency;
|
|
public string progressrate;
|
|
public string sttm;
|
|
public string totm;
|
|
public string MOLDSEQ;
|
|
public string MOLDCD;
|
|
}
|
|
}
|