EquipmentCodeMap.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:EquipmentCodeMap
  3. * 作者:xulisong
  4. * 创建时间: 2019/3/22 9:11:56
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Xml.Serialization;
  13. using SAGA.DotNetUtils.Serializer;
  14. namespace SAGA.MBI.Common
  15. {
  16. public class EquipmentCodeMap
  17. {
  18. private const string FileName = "GroupEquipmentCodes.xml";
  19. public static void Init()
  20. {
  21. var groups = new List<GroupCodes>();
  22. groups.Add(new GroupCodes(new List<string>() {"CAD1", "CAD2"}));
  23. groups.Add(new GroupCodes(new List<string>() { "BAD1", "BAD2" }));
  24. string path = MBIConst.MBIDataDictionaryPath;
  25. string fileName = FileName;
  26. SerializerByXml.SerializeAndSave(path, fileName, groups);
  27. }
  28. // [CacheAspect]
  29. private static Dictionary<string, string> m_CacheData;
  30. public static Dictionary<string,string> Read()
  31. {
  32. if (m_CacheData != null)
  33. return m_CacheData;
  34. Dictionary<string, string> result = new Dictionary<string, string>();
  35. string path = MBIConst.MBIDataDictionaryPath;
  36. string fileName = FileName;
  37. List<GroupCodes> groupCodes = SerializerByXml.DeserializeList<GroupCodes>(path, fileName);
  38. for (int i = 0; i < groupCodes.Count; i++)
  39. {
  40. foreach (var groupCode in groupCodes[i])
  41. {
  42. result[groupCode] = (i+1).ToString();
  43. }
  44. }
  45. return m_CacheData=result;
  46. }
  47. /// <summary>
  48. /// 获取设备族编号,如果有分组信息的话获取分组信息,没有分组信息的话,返回输入值
  49. /// </summary>
  50. /// <param name="equipmentCode"></param>
  51. /// <returns></returns>
  52. public static string GetOriginCode(string equipmentCode)
  53. {
  54. if (equipmentCode == null)
  55. return equipmentCode;
  56. var dic = Read();
  57. if (dic != null && dic.TryGetValue(equipmentCode, out string originCode))
  58. {
  59. return originCode;
  60. }
  61. return equipmentCode;
  62. }
  63. }
  64. /// <summary>
  65. /// 数据分组信息
  66. /// </summary>
  67. [XmlType(TypeName = "GroupCodes")]
  68. public class GroupCodes : List<string>
  69. {
  70. public GroupCodes()
  71. { }
  72. public GroupCodes(IEnumerable<string> source):base(source)
  73. {
  74. }
  75. }
  76. }