OfilmProgramDal.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllEapEntity;
  4. using DllEapEntity.Dtos;
  5. using DllEapEntity.Onsemi;
  6. using DllSocketFile;
  7. using Microsoft.Extensions.Configuration;
  8. using Microsoft.Extensions.Logging;
  9. using Newtonsoft.Json;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Configuration;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. namespace DllEapDal.OFILM
  17. {
  18. public class OfilmProgramDal
  19. {
  20. private IDatabase CurrDb;
  21. private IConfiguration Configuration;
  22. private string mesApiPrefix;
  23. private ILogger logger;
  24. public OfilmProgramDal(IDatabase db)
  25. {
  26. CurrDb = db;
  27. }
  28. public OfilmProgramDal(IDatabase db, IConfiguration configuration,
  29. ILogger logger)
  30. {
  31. CurrDb = db;
  32. this.Configuration = configuration;
  33. this.mesApiPrefix = Configuration["mesurl:url"];
  34. this.logger = logger;
  35. }
  36. /// <summary>
  37. /// 获取程序列表
  38. /// </summary>
  39. /// <param name="macId"></param>
  40. /// <param name="proName"></param>
  41. /// <param name="errorinfo"></param>
  42. /// <returns></returns>
  43. public IEnumerable<OnsemiProgramDto> GetProgramPaths(int macId, string proName, ref string errorinfo)
  44. {
  45. var machine = CurrDb.FindEntityFor<Machine>(macId);
  46. var uploadedPros = CurrDb.FindListForCondition<BusinessFileRelation>($" and c.UploadMacID={machine.ID}", ref errorinfo);
  47. if (machine.MModeCode == "ADT7900DUO")
  48. {
  49. string reError = "";
  50. var res = new MacOrderSendDal(this.CurrDb).SendOrder(machine, 7, 19, "S7F19", ref reError);
  51. if (proName != null && proName.Length > 0)
  52. {
  53. res = res.Where(v => v.FContent.Contains(proName)).ToList();
  54. }
  55. return res.Where(v => v.FContent.Trim().Length > 0).Select(v =>
  56. {
  57. var fileOrgName = Regex.Match(v.FContent, @"(?<=\\).*").Value;
  58. return new OnsemiProgramDto()
  59. {
  60. Name = fileOrgName,
  61. Path = v.FContent,
  62. State = uploadedPros.Any(t => t.FileOrgName == fileOrgName) ? "已上传" : "未上传"
  63. };
  64. });
  65. };
  66. IEnumerable<OnsemiProgramDto> pros = null;
  67. var socketFile = new SocketFile();
  68. IEnumerable<string> fileNames = null;
  69. var customer = AppConfigurtaionServices.Configuration["Client"];
  70. if (customer.ToUpper() == "OFILM")
  71. {
  72. fileNames = socketFile.GetMacFileList(machine, proName, ref errorinfo);
  73. if (fileNames != null && fileNames.Count() > 0)
  74. {
  75. pros = fileNames.Select(c => new OnsemiProgramDto
  76. {
  77. Path = c,
  78. Name = c,
  79. State = uploadedPros.Any(t => t.FileOrgName == c) ? "已上传" : "未上传"
  80. });
  81. }
  82. }
  83. else if (customer.ToUpper() == "TRS")
  84. {
  85. var dtos = socketFile.GetMacFileListForTRS(machine, proName, ref errorinfo);
  86. if (dtos != null && dtos.Count() > 0)
  87. {
  88. pros = dtos.Select(c => new OnsemiProgramDto
  89. {
  90. Path = c.Path,
  91. Name = c.Name,
  92. State = uploadedPros.Any(t => t.FileOrgName == c.Name) ? "已上传" : "未上传"
  93. });
  94. }
  95. }
  96. else
  97. {
  98. var dtos = socketFile.GetMacFileListForTRS(machine, proName, ref errorinfo);
  99. if (dtos != null && dtos.Count() > 0)
  100. {
  101. pros = dtos.Select(c => new OnsemiProgramDto
  102. {
  103. Path = c.Path,
  104. Name = c.Name,
  105. State = uploadedPros.Any(t => t.FileOrgName == c.Name) ? "已上传" : "未上传"
  106. });
  107. }
  108. }
  109. return pros;
  110. }
  111. public int Upload(int macId, string proPath, string proName, string userCode, ref string errorinfo)
  112. {
  113. var machine = CurrDb.FindEntityFor<Machine>(macId);
  114. //if (machine.MModeCode == "ADT7900DUO")
  115. //{
  116. // // ADT7900程序上传
  117. // return new Adt7900ProgramDal(this.CurrDb, this.logger).UploadProgram(machine, proName, proPath, userCode);
  118. //}
  119. var socketFile = new SocketFile();
  120. var customer = AppConfigurtaionServices.Configuration["Client"];
  121. if (customer.ToUpper() == "OFILM")
  122. {
  123. var flag = socketFile.UploadFile(machine, proName, ref errorinfo);
  124. if (flag == null)
  125. return -1;
  126. CallMesuploadRecipe(machine.FCode, proName, flag.Version, ref errorinfo);
  127. }
  128. else
  129. {
  130. var flag = socketFile.UploadForTRS(machine, proName, proPath, ref errorinfo);
  131. if (flag == null)
  132. return -1;
  133. }
  134. return 1;
  135. }
  136. private int CallMesuploadRecipe(string maccode, string programname, int version, ref string errorinfo)
  137. {
  138. try
  139. {
  140. //处理程序名称,传给MES的程序名称不能含.RCP扩展名称
  141. if (programname.Length > 4)
  142. {
  143. string extname = programname.Substring(programname.Length - 4, 4);
  144. if (extname == ".rcp")
  145. programname = programname.Substring(0, programname.Length - 4);
  146. }
  147. string actionName = "uploadRecipe";
  148. string fullUrl = mesApiPrefix + actionName;
  149. IDictionary<string, string> dic = new Dictionary<string, string>();
  150. dic.Add("equipmentID", maccode);
  151. dic.Add("recipeName", programname);
  152. dic.Add("version", version.ToString());
  153. var response = HttpRequestHelper<OfilmMesApiResponse>.Get(fullUrl, dic, ref errorinfo);
  154. string logText = $"调用MES上传程序接口:{fullUrl},传入的参数:{JsonConvert.SerializeObject(dic)}," +
  155. $"接收到的值为:{JsonConvert.SerializeObject(response)}";
  156. this.logger.LogError(logText);
  157. return 1;
  158. }
  159. catch (Exception ex)
  160. {
  161. errorinfo = ex.ToString();
  162. return -1;
  163. }
  164. }
  165. }
  166. }