CallFunction.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using DllEapEntity;
  4. using DllStatusShowDal;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. using System.Linq;
  9. using DllEapDal;
  10. using DllHsms;
  11. using Cksoft.Unity;
  12. using DllEapEntity.Rms;
  13. using DllDiodesMesDal;
  14. using DllDiodesMesEntity;
  15. using DllDiodesMesEntity.Dto;
  16. namespace DllLotServer
  17. {
  18. public class CallFunction
  19. {
  20. public static string CurrDbCode = "eap";
  21. public static string MesDbCode = "mes";
  22. private static string CurrStaffCode = "S00001";
  23. public static int LotStart(string maccode, List<McaSecVDetail> mcadetails, string usercode, ref string errorinfo)
  24. {
  25. IDatabase CurrDb = null;
  26. IDatabase MesDb = null;
  27. try
  28. {
  29. CurrDb = DbFactory.Base(CurrDbCode);
  30. MesDb = DbFactory.Base(MesDbCode);
  31. CurrentLoginUserDal userdal = new CurrentLoginUserDal(MesDb);
  32. CurrStaffCode = userdal.GetCurrUserCode();
  33. //CurrDb.BeginTrans();
  34. List<McaSecVDetail> ttlist = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotNo).ToList();
  35. if(ttlist.Count<=0)
  36. {
  37. errorinfo = $"未读取到机台【{maccode}】上的LOT编号。";
  38. return -1;
  39. }
  40. string lotno = ttlist[0].FVal;
  41. MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
  42. //调用lot查询接口
  43. int result = QueryLot(MesDb, lotno, ref errorinfo);
  44. if(result<=0)
  45. {
  46. //查询lot失败,给机台发送消息
  47. string temperrorinfo = "";
  48. senddal.SendS10F3(maccode, "Read LotInfo Failed from Mes.", ref temperrorinfo);
  49. return -1;
  50. }
  51. //调用lot trackin接口
  52. result = TrackIn(MesDb, lotno, maccode, ref errorinfo);
  53. if (result <= 0)
  54. {
  55. //查询lot失败,给机台发送消息
  56. string temperrorinfo = "";
  57. senddal.SendS10F3(maccode, $"Mes Track In Failed {errorinfo}", ref temperrorinfo);
  58. return -1;
  59. }
  60. else
  61. {
  62. string temperrorinfo = "";
  63. senddal.SendS10F3(maccode, "Mes Track In Success", ref temperrorinfo);
  64. }
  65. //CurrDb.Commit();
  66. return 1;
  67. }
  68. catch(Exception ex)
  69. {
  70. errorinfo = ex.Message.ToString();
  71. return -1;
  72. }
  73. finally
  74. {
  75. if (CurrDb != null)
  76. CurrDb.Close();
  77. if (MesDb != null)
  78. MesDb.Close();
  79. }
  80. }
  81. public static int QueryLot(IDatabase mesdb,string lot,ref string errorinfo)
  82. {
  83. try
  84. {
  85. mesdb.BeginTrans();
  86. LotDal dal = new LotDal(mesdb);
  87. LotMst mst= dal.ImportLotFromMes(lot, "", ref errorinfo);
  88. if (mst == null)
  89. {
  90. mesdb.Rollback();
  91. return -1;
  92. }
  93. mesdb.Commit();
  94. return 1;
  95. }
  96. catch(Exception ex)
  97. {
  98. errorinfo = ex.Message.ToString();
  99. return -1;
  100. }
  101. }
  102. public static int TrackIn(IDatabase mesdb, string lot,string maccode, ref string errorinfo)
  103. {
  104. try
  105. {
  106. LotDal dal = new LotDal(mesdb);
  107. int result = dal.TrackIn(lot,maccode, "", CurrStaffCode, ref errorinfo);
  108. if (result<=0)
  109. return -1;
  110. return 1;
  111. }
  112. catch (Exception ex)
  113. {
  114. errorinfo = ex.Message.ToString();
  115. return -1;
  116. }
  117. }
  118. public static int QtyColle(IDatabase mesdb,string lot,string maccode, List<McaSecVDetail> mcadetails, ref string errorinfo)
  119. {
  120. try
  121. {
  122. QtyColllectDto inparam = new QtyColllectDto();
  123. inparam.Lot = lot;
  124. inparam.MacCode = maccode;
  125. List<McaSecVDetail> ttlists = mcadetails.Where(t => t.FCode == StandardCode.SVID_StaffCode).ToList();
  126. if(ttlists.Count<=0)
  127. {
  128. errorinfo = $"未抓取到操作员工号。";
  129. return -1;
  130. }
  131. inparam.StaffCode = ttlists[0].FVal;
  132. ttlists = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotFinishUnit).ToList();
  133. if (ttlists.Count <= 0)
  134. {
  135. errorinfo = $"未抓取到Lot完成量。";
  136. return -1;
  137. }
  138. inparam.ProQty = int.Parse(ttlists[0].FVal);
  139. inparam.Yield = 1;
  140. mesdb.BeginTrans();
  141. LotDal dal = new LotDal(mesdb);
  142. int result = dal.QtyCollect(inparam, ref errorinfo);
  143. if (result <= 0)
  144. {
  145. mesdb.Rollback();
  146. return -1;
  147. }
  148. mesdb.Commit();
  149. return 1;
  150. }
  151. catch (Exception ex)
  152. {
  153. errorinfo = ex.Message.ToString();
  154. return -1;
  155. }
  156. }
  157. public static int DataColle(IDatabase mesdb,string lot, ref string errorinfo)
  158. {
  159. try
  160. {
  161. mesdb.BeginTrans();
  162. LotDal dal = new LotDal(mesdb);
  163. int result = dal.MaterialCheck(lot, ref errorinfo);
  164. if (result <= 0)
  165. {
  166. mesdb.Rollback();
  167. return -1;
  168. }
  169. mesdb.Commit();
  170. return 1;
  171. }
  172. catch (Exception ex)
  173. {
  174. errorinfo = ex.Message.ToString();
  175. return -1;
  176. }
  177. }
  178. private static int AddLoss(IDatabase mesdb,int loss,int mstid,ref string errorinfo)
  179. {
  180. LotExceptionDal lossdal = new LotExceptionDal(mesdb);
  181. LotException exc = new LotException();
  182. exc.ExceptionCode = "DPEP";
  183. exc.FCount = loss;
  184. exc.LotProcessReportID = mstid;
  185. int tempresult = lossdal.Add(exc, "", ref errorinfo);
  186. //if (tempresult <= 0)
  187. //{
  188. // mesdb.Rollback();
  189. // return -1;
  190. //}
  191. return 1;
  192. }
  193. public static int TrackOut(IDatabase mesdb, string lot, List<McaSecVDetail> mcadetails, ref string errorinfo)
  194. {
  195. try
  196. {
  197. //计算不良数量
  198. int goods = 0;
  199. List<McaSecVDetail> ttlists = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotFinishUnit).ToList();
  200. if (ttlists.Count > 0&& ttlists[0].FVal!="")
  201. {
  202. //errorinfo = $"未抓取到Lot完成量。";
  203. //return -1;
  204. goods = int.Parse(ttlists[0].FVal);
  205. }
  206. int intotal = 0;
  207. //int goods = int.Parse(ttlists[0].FVal);
  208. //读取lot的投入量
  209. List <LotProcess> lps = mesdb.FindListForCondition<LotProcess>($" and d.lotno='{lot}'", ref errorinfo).ToList();
  210. if(lps.Count>0&&lps[0].InTotal.ToString()!="")
  211. {
  212. //errorinfo = $"未找到【{lot}】的lot";
  213. //return -1;
  214. intotal = lps[0].InTotal;
  215. }
  216. //int intotal = lps[0].InTotal;
  217. //if(intotal<=0)
  218. //{
  219. // errorinfo = $"lot【{lot}】的投入量小于等于0,这样的数据不合理。";
  220. // return -1;
  221. //}
  222. int loss = intotal - goods;
  223. //if (loss < 0)
  224. //{
  225. // errorinfo = $"当前报废数量={loss}小于0,报废数量不能小于0";
  226. // return -1;
  227. //}
  228. if(loss>0)
  229. {
  230. mesdb.BeginTrans();
  231. //添加报废
  232. AddLoss(mesdb, loss, lps[0].ID, ref errorinfo);
  233. mesdb.Commit();
  234. }
  235. mesdb.BeginTrans();
  236. LotDal dal = new LotDal(mesdb);
  237. int result = dal.TrackOut(lot,goods,"", CurrStaffCode, ref errorinfo);
  238. //if (result <= 0)
  239. //{
  240. // mesdb.Rollback();
  241. // return -1;
  242. //}
  243. mesdb.Commit();
  244. return 1;
  245. }
  246. catch (Exception ex)
  247. {
  248. errorinfo = ex.Message.ToString();
  249. return -1;
  250. }
  251. }
  252. public static int LotEnd(string maccode, List<McaSecVDetail> mcadetails, string usercode, ref string errorinfo)
  253. {
  254. IDatabase CurrDb = null;
  255. IDatabase MesDb = null;
  256. try
  257. {
  258. CurrDb = DbFactory.Base(CurrDbCode);
  259. MesDb = DbFactory.Base(MesDbCode);
  260. CurrentLoginUserDal userdal = new CurrentLoginUserDal(MesDb);
  261. CurrStaffCode = userdal.GetCurrUserCode();
  262. //CurrDb.BeginTrans();
  263. List<McaSecVDetail> ttlist = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotNo).ToList();
  264. if (ttlist.Count <= 0)
  265. {
  266. errorinfo = $"未读取到机台【{maccode}】上的LOT编号。";
  267. return -1;
  268. }
  269. string lotno = ttlist[0].FVal;
  270. MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
  271. //调用产量收集
  272. int result = QtyColle(MesDb, lotno, maccode, mcadetails, ref errorinfo);
  273. if (result <= 0)
  274. {
  275. //查询lot失败,给机台发送消息
  276. string temperrorinfo = "";
  277. senddal.SendS10F3(maccode, "Mes QtyCollect Failed.", ref temperrorinfo);
  278. //return -1;
  279. }
  280. //调用数据接口
  281. result = DataColle(MesDb, lotno, ref errorinfo);
  282. if (result <= 0)
  283. {
  284. //查询lot失败,给机台发送消息
  285. string temperrorinfo = "";
  286. senddal.SendS10F3(maccode, "Mes DataCollect Failed", ref temperrorinfo);
  287. //return -1;
  288. }
  289. //调用lot trackOut接口
  290. result = TrackOut(MesDb,lotno, mcadetails, ref errorinfo);
  291. if (result <= 0)
  292. {
  293. //查询lot失败,给机台发送消息
  294. string temperrorinfo = "";
  295. senddal.SendS10F3(maccode, "Mes Track Out Failed", ref temperrorinfo);
  296. //return -1;
  297. }
  298. else
  299. {
  300. string temperrorinfo = "";
  301. senddal.SendS10F3(maccode, "Mes Track Out Success", ref temperrorinfo);
  302. }
  303. //CurrDb.Commit();
  304. return 1;
  305. }
  306. catch (Exception ex)
  307. {
  308. errorinfo = ex.Message.ToString();
  309. return -1;
  310. }
  311. finally
  312. {
  313. if (CurrDb != null)
  314. CurrDb.Close();
  315. if (MesDb != null)
  316. MesDb.Close();
  317. }
  318. }
  319. /// <summary>
  320. /// 清洗吸嘴
  321. /// </summary>
  322. /// <param name="maccode"></param>
  323. /// <param name="usercode"></param>
  324. /// <param name="errorinfo"></param>
  325. /// <returns></returns>
  326. public static int CollectLife(string maccode, List<McaSecVDetail> mcadetails, string usercode, ref string errorinfo)
  327. {
  328. IDatabase CurrDb = null;
  329. IDatabase MesDb = null;
  330. try
  331. {
  332. CurrDb = DbFactory.Base(CurrDbCode);
  333. MesDb = DbFactory.Base(MesDbCode);
  334. //CurrDb.BeginTrans();
  335. List<McaSecVDetail> ttlist = mcadetails.Where(t => t.FCode == StandardCode.SVID_LotNo).ToList();
  336. if (ttlist.Count <= 0)
  337. {
  338. errorinfo = $"未读取到机台【{maccode}】上的LOT编号。";
  339. return -1;
  340. }
  341. string lotno = ttlist[0].FVal;
  342. MesDb.BeginTrans();
  343. string sqlstr = $@"update lotprocess set CollectLife=CollectLife+1
  344. where LotMstID = (select id from lotmst where lotno = '{lotno}')";
  345. MesDb.ExecuteBySql(sqlstr);
  346. MesDb.BeginTrans();
  347. //CurrDb.Commit();
  348. return 1;
  349. }
  350. catch (Exception ex)
  351. {
  352. errorinfo = ex.Message.ToString();
  353. return -1;
  354. }
  355. finally
  356. {
  357. if (CurrDb != null)
  358. CurrDb.Close();
  359. if (MesDb != null)
  360. MesDb.Close();
  361. }
  362. }
  363. }
  364. }