ProcessBusiness.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllDiodesMesDal;
  4. using DllDiodesMesEntity;
  5. using DllEapDal;
  6. using DllEapEntity;
  7. using Microsoft.Extensions.Logging;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using XiangQi.Mes.Entity;
  13. namespace DllParamCheckServer
  14. {
  15. public class ProcessBusiness
  16. {
  17. private IDatabase CurrDb = null;
  18. //private IDatabase EapDb = null;
  19. private ILogger loger = null;
  20. private int CheckTime = 0;
  21. public ProcessBusiness(IDatabase eapdb,ILogger loger,int checktime)
  22. {
  23. this.loger = loger;
  24. CurrDb = eapdb;
  25. CheckTime = checktime;
  26. }
  27. public int ParamCheck(ref string errorinfo)
  28. {
  29. try
  30. {
  31. //读取机台
  32. string condition = " and a.id in(SELECT macid FROM eapappservermac group by macid)";
  33. List<Machine> steps = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  34. foreach(var item in steps)
  35. {
  36. //单个机台盘点
  37. CurrDb.BeginTrans();
  38. errorinfo = "";
  39. int result = SingleParamCheck(item, ref errorinfo);
  40. if(result<=0)
  41. {
  42. CurrDb.Rollback();
  43. loger.LogError($"机台编号={item.FCode}参数点检失败:{errorinfo}");
  44. }
  45. else
  46. {
  47. CurrDb.Commit();
  48. }
  49. }
  50. return 1;
  51. }
  52. catch(Exception ex)
  53. {
  54. errorinfo = ex.Message.ToString();
  55. return -1;
  56. }
  57. }
  58. private int SingleParamCheck(Machine mac,ref string errorinfo)
  59. {
  60. try
  61. {
  62. //判断盘点时间是否已到
  63. string sqlstr = $"SELECT ifnull(max(a.id),0) FROM maccheckmst a where a.MacCode='{mac.FCode}' and a.CheckMode=1";
  64. int maxid = int.Parse(CurrDb.FindObject(sqlstr).ToString());
  65. if(maxid>0)
  66. {
  67. MacCheckMst checkmst = CurrDb.FindEntityFor<MacCheckMst>(maxid);
  68. long difftime = DateTime.Now.Ticks - checkmst.RecTime.Ticks;
  69. int mint = (int)(difftime / (10000000 * 60));
  70. if (mint < CheckTime)//还没到点检时间
  71. return 1;
  72. }
  73. //读取机台点检参数
  74. string condition = $" and b.MModelCode='{mac.MModeCode}' and a.CheckMode=1";
  75. List<ModelCheckDetail> details = CurrDb.FindListForCondition<ModelCheckDetail>(condition, ref errorinfo).ToList();
  76. if (details.Count <= 0)
  77. return 1;
  78. List<MacParam> macparams = new List<MacParam>();
  79. foreach(var item in details)
  80. {
  81. MacParam entity = new MacParam();
  82. entity.FCode = item.ParamCode;
  83. entity.FNum = item.FNum;
  84. macparams.Add(entity);
  85. }
  86. MacOrderSendDal dal = new MacOrderSendDal(CurrDb);
  87. macparams = dal.GetParamValue(mac.FCode, macparams, ref errorinfo);
  88. if (macparams == null)
  89. {
  90. return -1;
  91. }
  92. //添加点检记录
  93. List<MacCheckDetail> checkdetails = new List<MacCheckDetail>();
  94. foreach(var item in macparams)
  95. {
  96. MacCheckDetail check = new MacCheckDetail();
  97. check.FNum = item.FNum;
  98. check.ParamCode = item.FCode;
  99. check.ParamVal = item.FValue;
  100. checkdetails.Add(check);
  101. }
  102. MacCheckMstDal checkdal = new MacCheckMstDal(CurrDb);
  103. return checkdal.AddCheck(mac.FCode, checkdetails, "eap", ref errorinfo);
  104. }
  105. catch (Exception ex)
  106. {
  107. errorinfo = ex.Message.ToString();
  108. return -1;
  109. }
  110. }
  111. }
  112. }