You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

333 lines
10 KiB

  1. using Learun.Util;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace Learun.Application.Extention.TaskScheduling
  5. {
  6. /// <summary>
  7. /// 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架
  8. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  9. /// 创 建:超级管理员
  10. /// 日 期:2019-01-09 16:07
  11. /// 描 述:任务计划模板信息
  12. /// </summary>
  13. public class TSSchemeBLL : TSSchemeIBLL
  14. {
  15. private TSSchemeService schemeService = new TSSchemeService();
  16. private TSProcessIBLL tSProcessIBLL = new TSProcessBLL();
  17. #region 获取数据
  18. /// <summary>
  19. /// 获取页面显示列表数据
  20. /// <summary>
  21. /// <param name="pagination">分页参数</param>
  22. /// <param name="queryJson">查询参数</param>
  23. /// <returns></returns>
  24. public IEnumerable<TSSchemeInfoEntity> GetPageList(Pagination pagination, string queryJson)
  25. {
  26. try
  27. {
  28. var list = (List<TSSchemeInfoEntity>)schemeService.GetPageList(pagination, queryJson);
  29. var list2 = list.FindAll(t=>(t.F_State == 1 || t.F_State == 2) && t.F_EndTime < DateTime.Now);
  30. foreach (var item in list2) {
  31. item.F_State = 4;
  32. TSProcessEntity tSProcessEntity = new TSProcessEntity()
  33. {
  34. F_Id = item.F_PorcessId,
  35. F_State = 4
  36. };
  37. tSProcessIBLL.SaveEntity(item.F_PorcessId, tSProcessEntity);
  38. }
  39. return list;
  40. }
  41. catch (Exception ex)
  42. {
  43. if (ex is ExceptionEx)
  44. {
  45. throw;
  46. }
  47. else
  48. {
  49. throw ExceptionEx.ThrowBusinessException(ex);
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 获取模板的历史数据
  55. /// </summary>
  56. /// <param name="pagination">分页参数</param>
  57. /// <param name="queryJson">查询参数</param>
  58. /// <returns></returns>
  59. public IEnumerable<TSSchemeEntity> GetSchemePageList(Pagination pagination, string queryJson)
  60. {
  61. try
  62. {
  63. return schemeService.GetSchemePageList(pagination, queryJson);
  64. }
  65. catch (Exception ex)
  66. {
  67. if (ex is ExceptionEx)
  68. {
  69. throw;
  70. }
  71. else
  72. {
  73. throw ExceptionEx.ThrowBusinessException(ex);
  74. }
  75. }
  76. }
  77. /// <summary>
  78. /// 获取表实体数据
  79. /// <param name="keyValue">主键</param>
  80. /// <summary>
  81. /// <returns></returns>
  82. public TSSchemeInfoEntity GetSchemeInfoEntity(string keyValue)
  83. {
  84. try
  85. {
  86. return schemeService.GetSchemeInfoEntity(keyValue);
  87. }
  88. catch (Exception ex)
  89. {
  90. if (ex is ExceptionEx)
  91. {
  92. throw;
  93. }
  94. else
  95. {
  96. throw ExceptionEx.ThrowBusinessException(ex);
  97. }
  98. }
  99. }
  100. /// <summary>
  101. /// 获取表实体数据
  102. /// <param name="keyValue">主键</param>
  103. /// <summary>
  104. /// <returns></returns>
  105. public TSSchemeEntity GetSchemeEntity(string keyValue)
  106. {
  107. try
  108. {
  109. return schemeService.GetSchemeEntity(keyValue);
  110. }
  111. catch (Exception ex)
  112. {
  113. if (ex is ExceptionEx)
  114. {
  115. throw;
  116. }
  117. else
  118. {
  119. throw ExceptionEx.ThrowBusinessException(ex);
  120. }
  121. }
  122. }
  123. /// <summary>
  124. /// 获取表实体数据
  125. /// <param name="keyValue">模板信息主键</param>
  126. /// <summary>
  127. /// <returns></returns>
  128. public TSSchemeEntity GetSchemeEntityByInfo(string keyValue)
  129. {
  130. try
  131. {
  132. return schemeService.GetSchemeEntityByInfo(keyValue);
  133. }
  134. catch (Exception ex)
  135. {
  136. if (ex is ExceptionEx)
  137. {
  138. throw;
  139. }
  140. else
  141. {
  142. throw ExceptionEx.ThrowBusinessException(ex);
  143. }
  144. }
  145. }
  146. #endregion
  147. #region 提交数据
  148. /// <summary>
  149. /// 删除实体数据
  150. /// <param name="keyValue">主键</param>
  151. /// <summary>
  152. /// <returns></returns>
  153. public void DeleteEntity(string keyValue)
  154. {
  155. try
  156. {
  157. schemeService.DeleteEntity(keyValue);
  158. QuartzHelper.DeleteJob(keyValue);
  159. }
  160. catch (Exception ex)
  161. {
  162. if (ex is ExceptionEx)
  163. {
  164. throw;
  165. }
  166. else
  167. {
  168. throw ExceptionEx.ThrowBusinessException(ex);
  169. }
  170. }
  171. }
  172. /// <summary>
  173. /// 保存实体数据(新增、修改)
  174. /// <param name="keyValue">主键</param>
  175. /// <summary>
  176. /// <returns></returns>
  177. public void SaveEntity(string keyValue, TSSchemeInfoEntity schemeInfoEntity, TSSchemeEntity schemeEntity)
  178. {
  179. try
  180. {
  181. TSProcessEntity tSProcessEntity = schemeService.SaveEntity(keyValue,schemeInfoEntity, schemeEntity);
  182. if (tSProcessEntity != null) {
  183. QuartzHelper.DeleteJob(keyValue);
  184. QuartzHelper.AddJob(schemeInfoEntity.F_Id, tSProcessEntity.F_Id, schemeEntity.F_Scheme.ToObject<TSSchemeModel>());
  185. }
  186. }
  187. catch (Exception ex)
  188. {
  189. if (ex is ExceptionEx)
  190. {
  191. throw;
  192. }
  193. else
  194. {
  195. throw ExceptionEx.ThrowBusinessException(ex);
  196. }
  197. }
  198. }
  199. /// <summary>
  200. /// 保存实体数据(新增、修改)
  201. /// <param name="keyValue">主键</param>
  202. /// <summary>
  203. /// <returns></returns>
  204. public void SaveEntity(string keyValue, TSSchemeInfoEntity entity)
  205. {
  206. try
  207. {
  208. schemeService.SaveEntity(keyValue, entity);
  209. }
  210. catch (Exception ex)
  211. {
  212. if (ex is ExceptionEx)
  213. {
  214. throw;
  215. }
  216. else
  217. {
  218. throw ExceptionEx.ThrowBusinessException(ex);
  219. }
  220. }
  221. }
  222. #endregion
  223. #region 扩展应用
  224. /// <summary>
  225. /// 暂停任务
  226. /// </summary>
  227. /// <param name="processId">任务进程主键</param>
  228. public void PauseJob(string processId) {
  229. try
  230. {
  231. TSProcessEntity tSProcessEntity = tSProcessIBLL.GetProcessEntity(processId);
  232. if (tSProcessEntity.F_State == 1 || tSProcessEntity.F_State == 2)
  233. {
  234. tSProcessEntity.F_State = 3;
  235. tSProcessIBLL.SaveEntity(processId, tSProcessEntity);
  236. QuartzHelper.DeleteJob(tSProcessEntity.F_SchemeInfoId);
  237. }
  238. }
  239. catch (Exception ex)
  240. {
  241. if (ex is ExceptionEx)
  242. {
  243. throw;
  244. }
  245. else
  246. {
  247. throw ExceptionEx.ThrowBusinessException(ex);
  248. }
  249. }
  250. }
  251. /// <summary>
  252. /// 启动任务
  253. /// </summary>
  254. /// <param name="processId">任务进程主键</param>
  255. public void EnAbleJob(string processId)
  256. {
  257. try
  258. {
  259. TSProcessEntity tSProcessEntity = tSProcessIBLL.GetProcessEntity(processId);
  260. TSSchemeEntity tSSchemeEntity = GetSchemeEntityByInfo(tSProcessEntity.F_SchemeInfoId);
  261. TSSchemeModel tSSchemeModel = tSSchemeEntity.F_Scheme.ToObject<TSSchemeModel>();
  262. if (tSProcessEntity.F_SchemeId != tSSchemeEntity.F_Id)
  263. {
  264. tSProcessEntity.F_State = 10;
  265. tSProcessIBLL.SaveEntity(tSProcessEntity.F_Id, tSProcessEntity);
  266. // 如果模板更改需要重新创建一个任务进程
  267. tSProcessEntity = new TSProcessEntity()
  268. {
  269. F_SchemeId = tSSchemeEntity.F_Id,
  270. F_SchemeInfoId = tSProcessEntity.F_SchemeInfoId,
  271. F_State = 2,
  272. F_EndType = tSSchemeModel.endType,
  273. F_EndTime = tSSchemeModel.endTime
  274. };
  275. if (tSSchemeModel.startType == 1)
  276. {
  277. tSProcessEntity.F_BeginTime = DateTime.Now;
  278. }
  279. else
  280. {
  281. tSProcessEntity.F_BeginTime = tSSchemeModel.startTime;
  282. }
  283. if (tSSchemeModel.endType == 1)
  284. {
  285. tSProcessEntity.F_EndTime = DateTime.MaxValue;
  286. }
  287. tSProcessIBLL.SaveEntity("", tSProcessEntity);
  288. }
  289. else
  290. {
  291. tSProcessEntity.F_State = 2;
  292. tSProcessIBLL.SaveEntity(tSProcessEntity.F_Id, tSProcessEntity);
  293. }
  294. QuartzHelper.AddJob(tSProcessEntity.F_SchemeInfoId, tSProcessEntity.F_Id, tSSchemeModel);
  295. }
  296. catch (Exception ex)
  297. {
  298. if (ex is ExceptionEx)
  299. {
  300. throw;
  301. }
  302. else
  303. {
  304. throw ExceptionEx.ThrowBusinessException(ex);
  305. }
  306. }
  307. }
  308. #endregion
  309. }
  310. }