CgscManager.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using QM.KJGH.CGGL.IRepository;
  2. using QM.KJGH.Gis.PyServer;
  3. using QM.KJGH.Model.KJGH;
  4. using QM.OrmSqlSugar;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using WS;
  10. using WS.Helper;
  11. using WS.Log;
  12. namespace QM.KJGH.CgglService.Managers
  13. {
  14. /// <summary>
  15. /// 成果机器审查
  16. /// </summary>
  17. public class CgscManager : SqlSugarRepository<CgzjZjrw>, ICgscManager
  18. {
  19. public string PyExe;
  20. public string RootPath;
  21. public string PythonFile;
  22. public CgscManager()
  23. {
  24. PyExe = ConfigHelper.Configuration["Path:PyExe"];
  25. PythonFile = ConfigHelper.Configuration["Path:PythonFile"];
  26. RootPath = ConfigHelper.Configuration["Path:Root"];
  27. }
  28. #region 任务
  29. /// <summary>
  30. /// 获取新任务
  31. /// </summary>
  32. /// <returns></returns>
  33. public CgzjZjrw NewTask()
  34. {
  35. try
  36. {
  37. Db.BeginTran();
  38. var model = First(t => t.RWZT == KJGH.Model.Enums.EnumRwzt.Create, new List<WS.Orm.OrderByModel<CgzjZjrw>>() {
  39. new WS.Orm.OrderByModel<CgzjZjrw> (){ order = t=>t.CJSJ , type = WS.Orm.DbOrderEnum.Asc}
  40. });
  41. if (model == null)
  42. return model;
  43. RunLog.Debug("任务:" + model.ToJson());
  44. CgglCg cgglCg = Db.Queryable<CgglCg>().Where(t => t.BSM == model.CG_BSM).First();
  45. RunLog.Debug($"成果:{cgglCg == null}");
  46. model.RWZT = KJGH.Model.Enums.EnumRwzt.Run;
  47. model.ZJSJ = DateTime.Now;
  48. Db.Updateable(model).ExecuteCommand();
  49. if(cgglCg != null)
  50. {
  51. RunLog.Debug($"成果111:{ cgglCg.ToJson() }");
  52. cgglCg.ZT_JQSC = KJGH.Model.Enums.EnumCgscZT.审查中;
  53. Db.Updateable(cgglCg).ExecuteCommand();
  54. }
  55. Db.CommitTran();
  56. return model;
  57. }
  58. catch (Exception ex)
  59. {
  60. WS.Log.RunLog.Error(ex);
  61. Db.RollbackTran();
  62. }
  63. return null;
  64. }
  65. /// <summary>
  66. /// 任务完成
  67. /// </summary>
  68. /// <returns></returns>
  69. public void TaskComplete(string bsm)
  70. {
  71. try
  72. {
  73. Db.BeginTran();
  74. var model = Get(t => t.BSM == bsm);
  75. CgglCg cgglCg = Db.Queryable<CgglCg>().Where(t => t.BSM == model.CG_BSM).First();
  76. model.RWZT = KJGH.Model.Enums.EnumRwzt.Complete;
  77. model.WCSJ = DateTime.Now;
  78. Db.Updateable(model).ExecuteCommand();
  79. if (cgglCg != null)
  80. {
  81. cgglCg.ZT_JQSC = KJGH.Model.Enums.EnumCgscZT.审查通过;
  82. Db.Updateable(cgglCg).ExecuteCommand();
  83. }
  84. Db.CommitTran();
  85. }
  86. catch (Exception ex)
  87. {
  88. WS.Log.RunLog.Error(ex);
  89. Db.RollbackTran();
  90. }
  91. }
  92. /// <summary>
  93. /// 任务错误
  94. /// </summary>
  95. /// <param name="msg">错误信息</param>
  96. /// <returns></returns>
  97. public void TaskError(string bsm, string msg)
  98. {
  99. try
  100. {
  101. Db.BeginTran();
  102. var model = Get(t => t.BSM == bsm);
  103. CgglCg cgglCg = Db.Queryable<CgglCg>().Where(t => t.BSM == model.CG_BSM).First();
  104. model.RWZT = KJGH.Model.Enums.EnumRwzt.Error;
  105. cgglCg.ZT_JQSC = KJGH.Model.Enums.EnumCgscZT.退回;
  106. model.WCSJ = DateTime.Now;
  107. Db.Updateable(model).ExecuteCommand();
  108. Db.Updateable(cgglCg).ExecuteCommand();
  109. Db.CommitTran();
  110. }
  111. catch (Exception ex)
  112. {
  113. WS.Log.RunLog.Error(ex);
  114. Db.RollbackTran();
  115. }
  116. }
  117. #endregion
  118. /// <summary>
  119. /// 任务解析
  120. /// </summary>
  121. public void Monitor() {
  122. var task = NewTask();
  123. if (task != null)
  124. {
  125. try
  126. {
  127. Thread.Sleep(1000 * 30);
  128. TaskComplete(task.BSM);
  129. //PyManager pyManager = new PyManager()
  130. //{
  131. // PyExe = PyExe,
  132. // PythonFile = PythonFile,
  133. //};
  134. //var res = pyManager.Run(EnumFunction.Cgsjzj, new { bsm = task.BSM, root = RootPath });
  135. //RunLog.Info("执行结果:" + res);
  136. //res = res.Replace("\r\n", "");
  137. //if (!res.Contains("####OK####"))
  138. // throw new Exception(res.Replace("####ERROR####", ""));
  139. //var file = res.Replace("####OK####", "");
  140. //TaskComplete(task.BSM);
  141. }
  142. catch (Exception ex)
  143. {
  144. RunLog.Error(ex, $"{ServiceConsts.ServiceName}执行任务异常!");
  145. TaskError(task.BSM, ex.Message);
  146. }
  147. }
  148. }
  149. }
  150. }