MacStatusController.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using Cksoft.Unity;
  4. using DllEapDal;
  5. using DllEapEntity;
  6. using DllEapEntity.Onsemi;
  7. using DllStatusShowDal;
  8. using log4net.Core;
  9. using log4net.Util;
  10. using Microsoft.AspNetCore.Mvc;
  11. using Microsoft.AspNetCore.SignalR;
  12. using Microsoft.Extensions.Logging;
  13. using Newtonsoft.Json;
  14. using Newtonsoft.Json.Linq;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Linq;
  20. using Cksoft.Unity.Log4NetConfig;
  21. namespace WebUpload.Controllers
  22. {
  23. [Route("eap/api/[controller]/[action]")]
  24. public class MacStatusController : ControllerBase
  25. {
  26. //public IActionResult Index()
  27. //{
  28. // return View();
  29. //}
  30. private ILogger<MacStatusController> myloger = null;
  31. public MacStatusController(ILogger<MacStatusController> ploger)
  32. {
  33. myloger = ploger;
  34. }
  35. /// <summary>
  36. /// lot 调程
  37. /// </summary>
  38. /// <param name="lotNum"></param>
  39. /// <returns></returns>
  40. [HttpPost]
  41. public EapResponse adjustmentLot([FromForm] string lotid, [FromForm] string macCode)
  42. {
  43. string errorinfo = string.Empty;
  44. var res = new EapResponse { Code = 1, Msg = string.Empty };
  45. #region 根据设备id和lot号,获取程序名称、程序版本
  46. string ip = AppConfigurtaionServices.Configuration["mesurl" + ":url"];
  47. string mesurl = ip + "ofilm/eap/findEquipmentProgramInfo";
  48. Dictionary<string, string> dic = new Dictionary<string, string>();
  49. dic.Add("equipmentID", macCode);
  50. dic.Add("lotId", lotid);
  51. myloger.LogError($"调程访问mesApiUrl:{mesurl}?equipmentID = {macCode}&lotId={lotid}");
  52. OfilmMesApiResponse mesResult = HttpRequestHelper<OfilmMesApiResponse>.Get(mesurl, dic, ref errorinfo);
  53. myloger.LogError($"调程访问返回结果,{ JsonConvert.SerializeObject(mesResult)}");
  54. #endregion
  55. if (mesResult.Success == true)
  56. {
  57. using (IDatabase db = DbFactory.Base("eap"))
  58. {
  59. db.BeginTrans();
  60. var dal = new ProgramDal(db);
  61. string recipe = mesResult.Result.RecipeName;
  62. int version = Convert.ToInt32(mesResult.Result.Version);
  63. myloger.LogError($"开始调程,机台编号={macCode},程序名称={recipe},版本={version}");
  64. var resultcount = dal.DownloadProgramForLot(macCode, recipe, version, ref errorinfo);
  65. if (resultcount <= 0)
  66. {
  67. myloger.LogError($"调程发生错误:{errorinfo}");
  68. }
  69. else
  70. {
  71. myloger.LogInformation($"调程成功......");
  72. }
  73. res.Code = resultcount;
  74. db.Commit();
  75. }
  76. }
  77. else
  78. {
  79. res.Code = -1;
  80. res.Msg = mesResult.Message;
  81. }
  82. return res;
  83. }
  84. /// <summary>
  85. /// 添加设备状态
  86. /// </summary>
  87. /// <param name="macStatus"></param>
  88. /// <returns></returns>
  89. [HttpPost]
  90. public EapResponse InsMacStatus([FromBody] MacStatus macStatus)
  91. {
  92. var errorinfo = string.Empty;
  93. var res = new EapResponse { Code = 1, Msg = string.Empty };
  94. using (IDatabase db = DbFactory.Base("eap"))
  95. {
  96. db.BeginTrans();
  97. var dal = new MacStatusDal(db);
  98. MacStatus mst = new MacStatus();
  99. //添加状态程序名称
  100. string condition = $" and a.fcode='{macStatus.MacCode}'";
  101. List<Machine> mac = db.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  102. if (mac.Count <= 0)
  103. {
  104. errorinfo = $"未找到机台【{macStatus.MacCode}】。";
  105. return null;
  106. }
  107. Ad830PlusProgramDal tempdal = new Ad830PlusProgramDal(db);
  108. string programname = tempdal.GetProgramName(mac[0], ref errorinfo);
  109. macStatus.Remark = programname;
  110. macStatus.ProgramName = string.IsNullOrEmpty(macStatus.ProgramName) ? "待机程序" : macStatus.ProgramName;
  111. macStatus.STime = DateTime.Now;
  112. var result = dal.PushStatusToMQ(mac[0].ID, macStatus, ref errorinfo);
  113. if (result < 0)
  114. {
  115. res.Code = -1;
  116. res.Msg = errorinfo;
  117. res.Data = null;
  118. return res;
  119. }
  120. res.Code = 1;
  121. res.Data = macStatus;
  122. db.Commit();
  123. LogHelper<MacStatus>.LogFatal("新增MacStatus-->" + Json.ToJson(macStatus), "用户操作", macStatus.RecCode);
  124. return res;
  125. }
  126. }
  127. /// <summary>
  128. /// 修改设备结束时间
  129. /// </summary>
  130. /// <param name="macStatus"></param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. public EapResponse UdpMacStatus([FromBody] MacStatus macStatus)
  134. {
  135. var errorinfo = string.Empty;
  136. var res = new EapResponse { Code = 1, Msg = string.Empty };
  137. using (IDatabase db = DbFactory.Base("eap"))
  138. {
  139. db.BeginTrans();
  140. var dal = new MacStatusDal(db);
  141. macStatus.STime = DateTime.Now;
  142. macStatus.ETime = DateTime.Now;
  143. int result = dal.UpdatePreStatus(macStatus, string.Empty, ref errorinfo);
  144. if (result == -1)
  145. {
  146. res.Code = -1;
  147. res.Msg = errorinfo;
  148. res.Data = null;
  149. return res;
  150. }
  151. macStatus.StatusID = 3;
  152. if (this.InsMacStatus(macStatus).Code < 0)
  153. {
  154. res.Code = -1;
  155. res.Msg = "新增闲置状态失败";
  156. db.Rollback();
  157. return res;
  158. }
  159. res.Data = result;
  160. db.Commit();
  161. LogHelper<MacStatus>.LogFatal("修改MacStatus-->" + Json.ToJson(macStatus), "用户操作", macStatus.RecCode);
  162. return res;
  163. }
  164. }
  165. [HttpGet]
  166. public EapResponse GetMacStatuses01(string macCode)
  167. {
  168. var errorinfo = string.Empty;
  169. var res = new EapResponse { Code = 1, Msg = string.Empty };
  170. using (IDatabase db = DbFactory.Base("eapslave"))
  171. {
  172. var dal = new MacStatusDal(db);
  173. var model = dal.GetMacStatus01ByMacode(macCode);
  174. if (model == null)
  175. {
  176. res.Code = -1;
  177. res.Msg = errorinfo;
  178. res.Data = null;
  179. return res;
  180. }
  181. res.Data = model;
  182. return res;
  183. }
  184. }
  185. /// <summary>
  186. /// Check
  187. /// </summary>
  188. /// <param name="macCode"></param>
  189. /// <returns></returns>
  190. [HttpGet]
  191. public OfilmMesApiResponse GetactiveCheck(string macCode)
  192. {
  193. var errorinfo = string.Empty;
  194. var res = new EapResponse { Code = 1, Msg = string.Empty };
  195. string ip = AppConfigurtaionServices.Configuration["mesurl" + ":url"];
  196. string mesurl = ip + "ofilm/eap/activeCheck";
  197. Dictionary<string, string> dic = new Dictionary<string, string>();
  198. dic.Add("equipmentID", macCode);
  199. OfilmMesApiResponse mesResult = HttpRequestHelper<OfilmMesApiResponse>.Get(mesurl, dic, ref errorinfo);
  200. //if (mesResult.Success == false)
  201. //{
  202. // res.Code = -1;
  203. // res.Msg = mesResult.Message + errorinfo;
  204. // res.Data = null;
  205. // return res;
  206. //}
  207. //res.Data = mesResult.Result;
  208. return mesResult;
  209. }
  210. }
  211. }