627 lines
20 KiB
C#
627 lines
20 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using static HTTP;
|
|
|
|
namespace Samkwang
|
|
{
|
|
public class DataManager : MonoBehaviour
|
|
{
|
|
public string sceneName;
|
|
private Dictionary<string, int> orderMap = new();
|
|
private Machine[] machines;
|
|
|
|
private List<CompleteInfo> matchedMachineInfos = new List<CompleteInfo>();
|
|
private Dictionary<string, List<EquipmentInfo>> equipmentInfos = new();
|
|
private Dictionary<string, List<AlarmInfo>> alarmInfos = new();
|
|
private Dictionary<string, OneHourInfo> oneHourInfoDict = new Dictionary<string, OneHourInfo>();
|
|
private Dictionary<string, RealtimeInfo_A> realtimeInfoADict = new Dictionary<string, RealtimeInfo_A>();
|
|
private Dictionary<string, RealtimeInfo_B> realtimeInfoBDict = new Dictionary<string, RealtimeInfo_B>();
|
|
|
|
public Machine currentMachine;
|
|
public Action<List<CompleteInfo>> onSetMachineDatas;
|
|
public Action<List<OneHourInfo>> onSetOneHourDatas;
|
|
public Action<Machine, CompleteInfo> onSetMachineData;
|
|
public Action<string, List<EquipmentInfo>> onSetEquipmentDatas;
|
|
public Action<List<AlarmInfo>> onSetAlarmInfos;
|
|
public Action<Dictionary<string, List<AlarmInfo>>> onSetMatchAlarmInfos;
|
|
public Action<List<RealtimeInfo_A>> onSetRealtimeInfoAs;
|
|
public Action<List<RealtimeInfo_B>> onSetRealtimeInfoBs;
|
|
// 특정 머신의 실시간 데이터가 갱신되었을 때 (필요시 사용)
|
|
public Action<string, RealtimeInfo_A> onSetRealtimeInfoA;
|
|
public Action<string, RealtimeInfo_B> onSetRealtimeInfoB;
|
|
|
|
private void Awake()
|
|
{
|
|
var dataOrder = Resources.Load<TextAsset>("DataOrder").text;
|
|
var workcdOrder = JsonConvert.DeserializeObject<List<string>>(dataOrder);
|
|
orderMap = workcdOrder.Select((workcd, index) => new { workcd, index }).ToDictionary(x => x.workcd, x => x.index);
|
|
}
|
|
private void Start()
|
|
{
|
|
machines = FindObjectsByType<Machine>(FindObjectsSortMode.None);
|
|
}
|
|
public List<CompleteInfo> SortListByWorknm(List<CompleteInfo> machineInfos)
|
|
{
|
|
return machineInfos.Where(field => orderMap.ContainsKey(field.worknm)).OrderBy(field => orderMap[field.worknm]).ToList();
|
|
}
|
|
|
|
public void SortMachineInfoData(List<CompleteInfo> infos)
|
|
{
|
|
// infos를 worknm 기준으로 Dictionary로 변환하면서 갱신
|
|
var infoDict = new Dictionary<string, CompleteInfo>();
|
|
var H1_infoDict = new Dictionary<string, OneHourInfo>();
|
|
foreach (var info in infos)
|
|
{
|
|
infoDict[info.worknm] = info; // 동일 키면 최신 데이터로 덮어쓰기
|
|
}
|
|
|
|
matchedMachineInfos.Clear();
|
|
|
|
foreach (var machine in machines)
|
|
{
|
|
if (string.IsNullOrEmpty(machine.machineName))
|
|
continue;
|
|
|
|
if (infoDict.TryGetValue(machine.machineName, out var info))
|
|
{
|
|
machine.SetAnimation(info.statusnm);
|
|
machine.SetWaringLight(info.statusnm);
|
|
matchedMachineInfos.Add(info);
|
|
|
|
if (oneHourInfoDict.TryGetValue(machine.machineName, out var oneHourInfo))
|
|
{
|
|
machine.GetComponent<UI_MachineStatusItem>()?.SetStatusData(oneHourInfo);
|
|
}
|
|
}
|
|
}
|
|
var sortInfos = SortListByWorknm(matchedMachineInfos);
|
|
onSetMachineDatas(sortInfos);
|
|
UpdateShowMachineData(sortInfos);
|
|
}
|
|
public void SetSelectedMachineData(Machine machine)
|
|
{
|
|
currentMachine = machine;
|
|
UpdateShowEquipmentData();
|
|
}
|
|
public void SetSelectedMachine(Machine machine, CompleteInfo info)
|
|
{
|
|
currentMachine = machine;
|
|
onSetMachineData(currentMachine, info);
|
|
}
|
|
public void UpdateShowMachineData(List<CompleteInfo> infos)
|
|
{
|
|
if (currentMachine == null || currentMachine.machineName == null)
|
|
return;
|
|
|
|
foreach(var info in infos)
|
|
{
|
|
if(info.worknm == currentMachine.machineName)
|
|
{
|
|
onSetMachineData(currentMachine,info);
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateOneHourData(List<OneHourInfo> infos)
|
|
{
|
|
if (infos == null) return;
|
|
|
|
foreach (var info in infos)
|
|
{
|
|
if (!string.IsNullOrEmpty(info.worknm))
|
|
{
|
|
oneHourInfoDict[info.worknm] = info;
|
|
}
|
|
}
|
|
|
|
|
|
foreach (var machine in machines)
|
|
{
|
|
if (string.IsNullOrEmpty(machine.machineName)) continue;
|
|
|
|
if (oneHourInfoDict.TryGetValue(machine.machineName, out var h1Info))
|
|
{
|
|
var uiItem = machine.GetComponent<UI_MachineStatusItem>();
|
|
if (uiItem != null)
|
|
{
|
|
uiItem.SetStatusData(h1Info);
|
|
}
|
|
}
|
|
}
|
|
|
|
onSetOneHourDatas?.Invoke(infos);
|
|
}
|
|
|
|
public void SetEquipementDataListArrangement(List<EquipmentInfo> infos)
|
|
{
|
|
if (infos == null || infos.Count == 0)
|
|
return;
|
|
|
|
var cleaned = infos.Where(i => i != null).ToList();
|
|
|
|
var grouped = cleaned.GroupBy(i => string.IsNullOrWhiteSpace(i.worknm) ? "<UNKNOWN>" : i.worknm.Trim());
|
|
|
|
foreach (var g in grouped)
|
|
{
|
|
var groupList = g.ToList();
|
|
equipmentInfos[g.Key] = groupList;
|
|
}
|
|
UpdateShowEquipmentData();
|
|
}
|
|
public void SetSelectedEquipmentData(Machine machine)
|
|
{
|
|
currentMachine = machine;
|
|
//UpdateShowEquipmentData();
|
|
UpdateShowRealtimeData();
|
|
}
|
|
public void UpdateShowEquipmentData()
|
|
{
|
|
if (currentMachine == null || currentMachine.machineName == null)
|
|
return;
|
|
|
|
var dataClearList = new List<EquipmentInfo>();
|
|
|
|
if (equipmentInfos.Count() <= 0)
|
|
{
|
|
onSetEquipmentDatas?.Invoke(currentMachine.machineName, dataClearList);
|
|
}
|
|
else
|
|
{
|
|
if (equipmentInfos.ContainsKey(currentMachine.machineName))
|
|
{
|
|
onSetEquipmentDatas?.Invoke(currentMachine.machineName, equipmentInfos[currentMachine.machineName]);
|
|
}
|
|
else
|
|
{
|
|
onSetEquipmentDatas?.Invoke(currentMachine.machineName, dataClearList);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void SetAlarmDataList(List<AlarmInfo> infos)
|
|
{
|
|
var alarmDataList = new List<AlarmInfo>();
|
|
|
|
foreach (var info in infos)
|
|
{
|
|
var matchedData = matchedMachineInfos.Find(x => x.worknm == info.worknm);
|
|
if (matchedData == null || matchedData.statusnm == "비가동중")
|
|
continue;
|
|
|
|
alarmDataList.Add(info);
|
|
machines.FirstOrDefault(x => x.machineName == info.worknm).SetAlarm(info.state);
|
|
}
|
|
onSetAlarmInfos?.Invoke(alarmDataList);
|
|
SetAlarmDataListArrangement(alarmDataList);
|
|
}
|
|
public void SetAlarmDataListArrangement(List<AlarmInfo> infos)
|
|
{
|
|
if (infos == null) return;
|
|
|
|
foreach (var info in infos)
|
|
{
|
|
if (info == null || string.IsNullOrEmpty(info.worknm))
|
|
continue;
|
|
|
|
if (!alarmInfos.TryGetValue(info.worknm, out var list))
|
|
{
|
|
list = new List<AlarmInfo>();
|
|
alarmInfos[info.worknm] = list;
|
|
}
|
|
|
|
int index = list.FindIndex(x => !string.IsNullOrEmpty(x.id) && x.id == info.id);
|
|
|
|
if (index >= 0)
|
|
{
|
|
list[index] = info;
|
|
}
|
|
else
|
|
{
|
|
list.Add(info);
|
|
}
|
|
}
|
|
onSetMatchAlarmInfos?.Invoke(alarmInfos);
|
|
}
|
|
|
|
public void SetEquipmentItem(ItemDatum itemDatum)
|
|
{
|
|
foreach(var machine in machines)
|
|
{
|
|
if (machine.machineStatusIcon == null)
|
|
continue;
|
|
|
|
if (machine.machineStatusIcon.data.itemcd != null)
|
|
{
|
|
var itemcd = machine.machineStatusIcon.data.itemcd;
|
|
var itemdata = itemDatum.rows.Where(x => x.itemCode == itemcd).FirstOrDefault();
|
|
|
|
if (itemdata == null)
|
|
{
|
|
machine.SetItemModel("Default");
|
|
}
|
|
else
|
|
{
|
|
machine.SetItemModel(itemdata.Model.fileName);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
machine.SetItemModel("Default");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetRealtimeInfoAList(List<RealtimeInfo_A> infos)
|
|
{
|
|
if (infos == null) return;
|
|
|
|
foreach (var info in infos)
|
|
{
|
|
if (!string.IsNullOrEmpty(info.worknm))
|
|
{
|
|
realtimeInfoADict[info.worknm] = info;
|
|
|
|
// 만약 현재 선택된 머신이 이 데이터의 주인이라면 개별 갱신 이벤트 발생
|
|
if (currentMachine != null && currentMachine.machineName == info.worknm &&
|
|
info.worknm.Contains("SUMITOMO"))
|
|
{
|
|
onSetRealtimeInfoA?.Invoke(info.worknm, info);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 전체 리스트 갱신 알림
|
|
onSetRealtimeInfoAs?.Invoke(infos);
|
|
}
|
|
|
|
public void SetRealtimeInfoBList(List<RealtimeInfo_B> infos)
|
|
{
|
|
if (infos == null) return;
|
|
|
|
foreach (var info in infos)
|
|
{
|
|
if (!string.IsNullOrEmpty(info.worknm))
|
|
{
|
|
realtimeInfoBDict[info.worknm] = info;
|
|
|
|
// 만약 현재 선택된 머신이 이 데이터의 주인이라면 개별 갱신 이벤트 발생
|
|
if (currentMachine != null && currentMachine.machineName == info.worknm &&
|
|
info.worknm.Contains("SODICK"))
|
|
{
|
|
onSetRealtimeInfoB?.Invoke(info.worknm, info);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 전체 리스트 갱신 알림
|
|
onSetRealtimeInfoBs?.Invoke(infos);
|
|
}
|
|
public void UpdateShowRealtimeData()
|
|
{
|
|
if (currentMachine == null || string.IsNullOrEmpty(currentMachine.machineName)) return;
|
|
|
|
string machineName = currentMachine.machineName;
|
|
|
|
// 베트남 설비인 경우
|
|
if (machineName.Contains("WC"))
|
|
{
|
|
if (equipmentInfos.TryGetValue(machineName, out var list))
|
|
{
|
|
onSetEquipmentDatas?.Invoke(machineName, list);
|
|
}
|
|
else
|
|
{
|
|
onSetEquipmentDatas?.Invoke(machineName, new List<EquipmentInfo>());
|
|
}
|
|
}
|
|
// SUMITOMO 설비인 경우 -> RealtimeInfo_A 사용
|
|
else if (machineName.Contains("SUMITOMO"))
|
|
{
|
|
if (realtimeInfoADict.TryGetValue(machineName, out var infoA))
|
|
{
|
|
onSetRealtimeInfoA?.Invoke(machineName, infoA);
|
|
}
|
|
else
|
|
{
|
|
// 데이터가 없으면 null을 보내 UI 초기화
|
|
onSetRealtimeInfoA?.Invoke(machineName, null);
|
|
}
|
|
|
|
// B 데이터 UI는 닫거나 초기화할 필요가 있다면 여기서 처리
|
|
// onSetRealtimeDataB?.Invoke(machineName, null);
|
|
}
|
|
// SODICK 설비인 경우 -> RealtimeInfo_B 사용
|
|
else if (machineName.Contains("SODICK"))
|
|
{
|
|
if (realtimeInfoBDict.TryGetValue(machineName, out var infoB))
|
|
{
|
|
onSetRealtimeInfoB?.Invoke(machineName, infoB);
|
|
}
|
|
else
|
|
{
|
|
onSetRealtimeInfoB?.Invoke(machineName, null);
|
|
}
|
|
|
|
// A 데이터 UI 초기화
|
|
// onSetRealtimeDataA?.Invoke(machineName, null);
|
|
}
|
|
else
|
|
{
|
|
// 그 외 설비 (데이터 없음)
|
|
onSetRealtimeInfoA?.Invoke(machineName, null);
|
|
onSetRealtimeInfoB?.Invoke(machineName, null);
|
|
}
|
|
}
|
|
|
|
}
|
|
[Serializable]
|
|
public class BranchInfos
|
|
{
|
|
public long SEND_TIME;
|
|
public double SERVER_RUNNING_TIME;
|
|
public List<BranchInfo> SAMKWANG_TOTAL_WORK;//_MEMORY;
|
|
}
|
|
|
|
[Serializable]
|
|
public class BranchInfo
|
|
{
|
|
public string planqty;
|
|
public string workqty;
|
|
public string goodqty;
|
|
public string badqty;
|
|
public string badrate;
|
|
public string progressrate;
|
|
}
|
|
|
|
[Serializable]
|
|
public class WorkShopInfos
|
|
{
|
|
public long SEND_TIME;
|
|
public double SERVER_RUNNING_TIME;
|
|
public List<WorkShopInfo> SAMKWANG_GROUP_WORK;//_MEMORY;
|
|
}
|
|
[Serializable]
|
|
public class WorkShopInfo
|
|
{
|
|
public string groupcd;
|
|
public string groupnm;
|
|
public string mchcnt;
|
|
public string planqty;
|
|
public string workqty;
|
|
public string goodqty;
|
|
public string badqty;
|
|
public string badrate;
|
|
public string progressrate;
|
|
}
|
|
|
|
[Serializable]
|
|
public class CompleteInfos
|
|
{
|
|
public long SEND_TIME;
|
|
public double SERVER_RUNNING_TIME;
|
|
public List<CompleteInfo> SAMKWANG_EQUIPMENT;//_MEMORY;
|
|
}
|
|
[Serializable]
|
|
public class CompleteInfo
|
|
{
|
|
public string datagbn;
|
|
public string wordno;
|
|
public string workdt;
|
|
public string pvp;
|
|
public string sitecd;
|
|
public string wccd;
|
|
public string workcd;
|
|
public string worknm;
|
|
public string workseq;
|
|
public string status;
|
|
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 goaltime;
|
|
public string ptotm;
|
|
public string psttm;
|
|
public string moldcd;
|
|
public string moldseq;
|
|
public string porate;
|
|
public string goodqtyrate;
|
|
public string eorate;
|
|
public string lct;
|
|
public string wct;
|
|
}
|
|
[Serializable]
|
|
public class EquipmentInfos
|
|
{
|
|
public long SEND_TIME;
|
|
public double SERVER_RUNNING_TIME;
|
|
public List<EquipmentInfo> SAMKWANG_EQUIPMENT_DATA;//_MEMORY;
|
|
}
|
|
[Serializable]
|
|
public class EquipmentInfo
|
|
{
|
|
public string workcd;
|
|
public string worknm;
|
|
public string inputdt;
|
|
public string total_shot;
|
|
public string item_cd;
|
|
public string item_nm;
|
|
public string item_val;
|
|
}
|
|
|
|
[Serializable]
|
|
public class RealtimeInfos_A
|
|
{
|
|
public long SEND_TIME;
|
|
public double SERVER_RUNNING_TIME;
|
|
public List<RealtimeInfo_A> SAMKWANG_KOREA_REALTIME_A;
|
|
}
|
|
[Serializable]
|
|
public class RealtimeInfo_A
|
|
{
|
|
public string worknm;
|
|
public string workcd;
|
|
public string input_dt;
|
|
public string S001;
|
|
public string S002;
|
|
public string S003;
|
|
public string S004;
|
|
public string S005;
|
|
public string S006;
|
|
public string S007;
|
|
public string S008;
|
|
public string S009;
|
|
public string S010;
|
|
public string S011;
|
|
public string S012;
|
|
public string S013;
|
|
public string S014;
|
|
public string S015;
|
|
public string S016;
|
|
public string S017;
|
|
public string S018;
|
|
public string S019;
|
|
public string S020;
|
|
public string S021;
|
|
public string S022;
|
|
public string S023;
|
|
public string S024;
|
|
public string S025;
|
|
public string S026;
|
|
public string S027;
|
|
public string S028;
|
|
public string S029;
|
|
public string S030;
|
|
public string S031;
|
|
public string S032;
|
|
public string S033;
|
|
public string S034;
|
|
public string S035;
|
|
}
|
|
|
|
[Serializable]
|
|
public class RealtimeInfos_B
|
|
{
|
|
public long SEND_TIME;
|
|
public double SERVER_RUNNING_TIME;
|
|
public List<RealtimeInfo_B> SAMKWANG_KOREA_REALTIME_B;
|
|
}
|
|
[Serializable]
|
|
public class RealtimeInfo_B
|
|
{
|
|
public string worknm;
|
|
public string workcd;
|
|
public string input_dt;
|
|
public string back_pressure;
|
|
public string back_pressure_1;
|
|
public string back_pressure_2;
|
|
public string back_pressure_3;
|
|
public string back_pressure_vp;
|
|
public string cavity_cnt;
|
|
public string clamp_pressure;
|
|
public string cushion_last;
|
|
public string cushion_min;
|
|
public string cycle_time;
|
|
public string data_date;
|
|
public string data_time;
|
|
public string fill_time;
|
|
public string inj_pressure_max;
|
|
public string inj_pressure_t1;
|
|
public string inj_pressure_t2;
|
|
public string inj_pressure_t3;
|
|
public string inj_pressure_v1_2;
|
|
public string inj_pressure_v2_3;
|
|
public string inj_pressure_v3_4;
|
|
public string inj_speed_t1;
|
|
public string inj_speed_t2;
|
|
public string inj_speed_t3;
|
|
public string inj_speed_v1_2;
|
|
public string inj_speed_v2_3;
|
|
public string inj_speed_v3_4;
|
|
public string inj_speed_vp;
|
|
public string ng_qty;
|
|
public string oil_temp;
|
|
public string ok_qty;
|
|
public string open_pos;
|
|
public string plan_qty;
|
|
public string quality_eval;
|
|
public string remain_qty;
|
|
public string run_time;
|
|
public string shot_cnt;
|
|
public string temp_d1;
|
|
public string temp_d2;
|
|
public string temp_d3;
|
|
public string temp_d4;
|
|
public string temp_z0;
|
|
public string temp_z1;
|
|
public string temp_z2;
|
|
public string temp_z3;
|
|
public string temp_z4;
|
|
public string temp_z5;
|
|
public string temp_z6;
|
|
public string temp_zh;
|
|
public string temp_zj;
|
|
public string total_shot_cnt;
|
|
public string vp_position;
|
|
public string vp_pressure;
|
|
public string weigh_time;
|
|
public string weigh_val;
|
|
}
|
|
|
|
[Serializable]
|
|
public class AlarmInfos
|
|
{
|
|
public long SEND_TIME;
|
|
public double SERVER_RUNNING_TIME;
|
|
public List<AlarmInfo> SAMKWANG_ALARM;//_MEMORY;
|
|
}
|
|
[Serializable]
|
|
public class AlarmInfo
|
|
{
|
|
public string id;
|
|
public string state;
|
|
public string message;
|
|
public string code;
|
|
public string set_time;
|
|
public string clear_time;
|
|
public string created_at;
|
|
public string updated_at;
|
|
public string workcd;
|
|
public string worknm;
|
|
}
|
|
|
|
[Serializable]
|
|
public class OneHourInfos
|
|
{
|
|
public long SEND_TIME;
|
|
public double SERVER_RUNNING_TIME;
|
|
public List<OneHourInfo> SAMKWANG_HOUR_WORK;//_MEMORY;
|
|
}
|
|
[Serializable]
|
|
public class OneHourInfo
|
|
{
|
|
public string wordno;
|
|
public string workqty;
|
|
public string badqty;
|
|
public string worknm;
|
|
}
|
|
}
|