MacStatusController.cs 10 KB

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