| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- /*-------------------------------------------------------------------------
- * 功能描述:EquipmentCodeMap
- * 作者:xulisong
- * 创建时间: 2019/3/22 9:11:56
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Serialization;
- using SAGA.DotNetUtils.Serializer;
- namespace SAGA.MBI.Common
- {
- public class EquipmentCodeMap
- {
- private const string FileName = "GroupEquipmentCodes.xml";
- public static void Init()
- {
- var groups = new List<GroupCodes>();
- groups.Add(new GroupCodes(new List<string>() {"CAD1", "CAD2"}));
- groups.Add(new GroupCodes(new List<string>() { "BAD1", "BAD2" }));
- string path = MBIConst.MBIDataDictionaryPath;
- string fileName = FileName;
- SerializerByXml.SerializeAndSave(path, fileName, groups);
- }
- // [CacheAspect]
- private static Dictionary<string, string> m_CacheData;
- public static Dictionary<string,string> Read()
- {
- if (m_CacheData != null)
- return m_CacheData;
- Dictionary<string, string> result = new Dictionary<string, string>();
- string path = MBIConst.MBIDataDictionaryPath;
- string fileName = FileName;
- List<GroupCodes> groupCodes = SerializerByXml.DeserializeList<GroupCodes>(path, fileName);
- for (int i = 0; i < groupCodes.Count; i++)
- {
- foreach (var groupCode in groupCodes[i])
- {
- result[groupCode] = (i+1).ToString();
- }
- }
- return m_CacheData=result;
- }
- /// <summary>
- /// 获取设备族编号,如果有分组信息的话获取分组信息,没有分组信息的话,返回输入值
- /// </summary>
- /// <param name="equipmentCode"></param>
- /// <returns></returns>
- public static string GetOriginCode(string equipmentCode)
- {
- if (equipmentCode == null)
- return equipmentCode;
- var dic = Read();
- if (dic != null && dic.TryGetValue(equipmentCode, out string originCode))
- {
- return originCode;
- }
- return equipmentCode;
- }
- }
- /// <summary>
- /// 数据分组信息
- /// </summary>
- [XmlType(TypeName = "GroupCodes")]
- public class GroupCodes : List<string>
- {
- public GroupCodes()
- { }
- public GroupCodes(IEnumerable<string> source):base(source)
- {
- }
- }
- }
|