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.
 
 
 
 
 
 

379 lines
13 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Learun.Application.Extention.TaskScheduling
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架
  10. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  11. /// 创 建:超级管理员
  12. /// 日 期:2019-01-09 16:07
  13. /// 描 述:任务计划模板信息
  14. /// </summary>
  15. public class TSSchemeService : RepositoryFactory
  16. {
  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 strSql = new StringBuilder();
  29. strSql.Append(@"
  30. SELECT
  31. t.F_Id,
  32. t.F_Name,
  33. t.F_Description,
  34. p.F_State,
  35. p.F_BeginTime,
  36. p.F_EndTime,
  37. p.F_Id as F_PorcessId
  38. FROM
  39. LR_TS_SchemeInfo t
  40. LEFT JOIN LR_TS_Process p ON p.F_SchemeInfoId = t.F_Id
  41. AND p.F_State != 10
  42. ");
  43. strSql.Append(" WHERE 1=1 AND F_DeleteMark = 0 ");
  44. var queryParam = queryJson.ToJObject();
  45. string keyWord = "";
  46. if (!queryParam["keyWord"].IsEmpty()) {
  47. keyWord ="%" + queryParam["keyWord"].ToString()+ "%";
  48. strSql.Append(" AND t.F_Name like @keyWord ");
  49. }
  50. return this.BaseRepository().FindList<TSSchemeInfoEntity>(strSql.ToString(), new { keyWord }, pagination);
  51. }
  52. catch (Exception ex)
  53. {
  54. if (ex is ExceptionEx)
  55. {
  56. throw;
  57. }
  58. else
  59. {
  60. throw ExceptionEx.ThrowServiceException(ex);
  61. }
  62. }
  63. }
  64. /// <summary>
  65. /// 获取模板的历史数据
  66. /// </summary>
  67. /// <param name="pagination">分页参数</param>
  68. /// <param name="queryJson">查询参数</param>
  69. /// <returns></returns>
  70. public IEnumerable<TSSchemeEntity> GetSchemePageList(Pagination pagination, string queryJson)
  71. {
  72. try
  73. {
  74. var strSql = new StringBuilder();
  75. strSql.Append("SELECT ");
  76. strSql.Append(@"
  77. t.F_Id,
  78. t.F_SchemeInfoId,
  79. t.F_IsActive,
  80. t.F_CreateDate,
  81. t.F_CreateUserId,
  82. t.F_CreateUserName
  83. ");
  84. strSql.Append(" FROM LR_TS_Scheme t ");
  85. strSql.Append(" WHERE 1=1 ");
  86. var queryParam = queryJson.ToJObject();
  87. return this.BaseRepository().FindList<TSSchemeEntity>(strSql.ToString(), pagination);
  88. }
  89. catch (Exception ex)
  90. {
  91. if (ex is ExceptionEx)
  92. {
  93. throw;
  94. }
  95. else
  96. {
  97. throw ExceptionEx.ThrowServiceException(ex);
  98. }
  99. }
  100. }
  101. /// <summary>
  102. /// 获取表实体数据
  103. /// <param name="keyValue">主键</param>
  104. /// <summary>
  105. /// <returns></returns>
  106. public TSSchemeInfoEntity GetSchemeInfoEntity(string keyValue)
  107. {
  108. try
  109. {
  110. return this.BaseRepository().FindEntity<TSSchemeInfoEntity>(keyValue);
  111. }
  112. catch (Exception ex)
  113. {
  114. if (ex is ExceptionEx)
  115. {
  116. throw;
  117. }
  118. else
  119. {
  120. throw ExceptionEx.ThrowServiceException(ex);
  121. }
  122. }
  123. }
  124. /// <summary>
  125. /// 获取表实体数据
  126. /// <param name="keyValue">主键</param>
  127. /// <summary>
  128. /// <returns></returns>
  129. public TSSchemeEntity GetSchemeEntity(string keyValue)
  130. {
  131. try
  132. {
  133. return this.BaseRepository().FindEntity<TSSchemeEntity>(keyValue);
  134. }
  135. catch (Exception ex)
  136. {
  137. if (ex is ExceptionEx)
  138. {
  139. throw;
  140. }
  141. else
  142. {
  143. throw ExceptionEx.ThrowServiceException(ex);
  144. }
  145. }
  146. }
  147. /// <summary>
  148. /// 获取表实体数据
  149. /// <param name="keyValue">模板信息主键</param>
  150. /// <summary>
  151. /// <returns></returns>
  152. public TSSchemeEntity GetSchemeEntityByInfo(string keyValue)
  153. {
  154. try
  155. {
  156. return this.BaseRepository().FindEntity<TSSchemeEntity>(t=>t.F_IsActive == 1 && t.F_SchemeInfoId == keyValue);
  157. }
  158. catch (Exception ex)
  159. {
  160. if (ex is ExceptionEx)
  161. {
  162. throw;
  163. }
  164. else
  165. {
  166. throw ExceptionEx.ThrowServiceException(ex);
  167. }
  168. }
  169. }
  170. #endregion
  171. #region 提交数据
  172. /// <summary>
  173. /// 删除实体数据
  174. /// <param name="keyValue">主键</param>
  175. /// <summary>
  176. /// <returns></returns>
  177. public void DeleteEntity(string keyValue)
  178. {
  179. TSProcessEntity entity = this.BaseRepository().FindEntity<TSProcessEntity>(t=>t.F_SchemeInfoId == keyValue && (t.F_State == 1 || t.F_State == 2) );
  180. var db = this.BaseRepository().BeginTrans();
  181. try
  182. {
  183. if (entity != null) {
  184. entity.F_State = 10;
  185. db.Update(entity);
  186. }
  187. TSSchemeInfoEntity tSSchemeInfoEntity = new TSSchemeInfoEntity() {
  188. F_Id = keyValue,
  189. F_DeleteMark = 1
  190. };
  191. db.Update(tSSchemeInfoEntity);
  192. db.Commit();
  193. }
  194. catch (Exception ex)
  195. {
  196. db.Rollback();
  197. if (ex is ExceptionEx)
  198. {
  199. throw;
  200. }
  201. else
  202. {
  203. throw ExceptionEx.ThrowServiceException(ex);
  204. }
  205. }
  206. }
  207. /// <summary>
  208. /// 保存实体数据(新增、修改)
  209. /// <param name="keyValue">主键</param>
  210. /// <summary>
  211. /// <returns></returns>
  212. public TSProcessEntity SaveEntity(string keyValue, TSSchemeInfoEntity schemeInfoEntity, TSSchemeEntity schemeEntity)
  213. {
  214. TSSchemeModel tSSchemeModel = schemeEntity.F_Scheme.ToObject<TSSchemeModel>();
  215. TSProcessEntity tSProcessEntity = null;
  216. TSSchemeEntity schemeEntity2 = null;
  217. if (!string.IsNullOrEmpty(keyValue))
  218. {
  219. schemeEntity2 = this.BaseRepository().FindEntity<TSSchemeEntity>(t=>t.F_IsActive == 1 && t.F_SchemeInfoId == keyValue);
  220. }
  221. var db = this.BaseRepository().BeginTrans();
  222. try
  223. {
  224. if (!string.IsNullOrEmpty(keyValue))
  225. {
  226. schemeInfoEntity.Modify(keyValue);
  227. db.Update(schemeInfoEntity);
  228. if (schemeEntity2 == null || schemeEntity2.F_Scheme != schemeEntity.F_Scheme) {
  229. schemeEntity.Create();
  230. schemeEntity.F_SchemeInfoId = schemeInfoEntity.F_Id;
  231. schemeEntity.F_IsActive = 1;
  232. db.Insert(schemeEntity);
  233. if (schemeEntity2 != null) {
  234. schemeEntity2.F_IsActive = 2;
  235. db.Update(schemeEntity2);
  236. }
  237. // 关闭老的任务进程
  238. TSProcessEntity tSProcessOldEntity = this.BaseRepository().FindEntity<TSProcessEntity>(t => t.F_SchemeInfoId == keyValue && t.F_State != 10);
  239. if (tSProcessOldEntity.F_State != 3) {
  240. if (tSProcessOldEntity.F_State == 1 || tSProcessOldEntity.F_State == 2)
  241. {
  242. tSProcessOldEntity.F_State = 10;
  243. db.Update(tSProcessOldEntity);
  244. }
  245. // 新增一个任务进程
  246. tSProcessEntity = new TSProcessEntity()
  247. {
  248. F_State = 1,
  249. F_SchemeId = schemeEntity.F_Id,
  250. F_SchemeInfoId = schemeInfoEntity.F_Id,
  251. F_EndType = tSSchemeModel.endType,
  252. F_EndTime = tSSchemeModel.endTime
  253. };
  254. tSProcessEntity.Create();
  255. if (tSSchemeModel.startType == 1)
  256. {
  257. tSProcessEntity.F_BeginTime = DateTime.Now;
  258. }
  259. else
  260. {
  261. tSProcessEntity.F_BeginTime = tSSchemeModel.startTime;
  262. }
  263. if (tSSchemeModel.endType == 1)
  264. {
  265. tSProcessEntity.F_EndTime = DateTime.MaxValue;
  266. }
  267. db.Insert(tSProcessEntity);
  268. }
  269. }
  270. }
  271. else
  272. {
  273. schemeInfoEntity.Create();
  274. db.Insert(schemeInfoEntity);
  275. schemeEntity.Create();
  276. schemeEntity.F_SchemeInfoId = schemeInfoEntity.F_Id;
  277. schemeEntity.F_IsActive = 1;
  278. db.Insert(schemeEntity);
  279. // 新增一个任务进程
  280. tSProcessEntity = new TSProcessEntity() {
  281. F_State = 1,
  282. F_SchemeId = schemeEntity.F_Id,
  283. F_SchemeInfoId = schemeInfoEntity.F_Id,
  284. F_EndType = tSSchemeModel.endType,
  285. F_EndTime = tSSchemeModel.endTime
  286. };
  287. tSProcessEntity.Create();
  288. if (tSSchemeModel.startType == 1)
  289. {
  290. tSProcessEntity.F_BeginTime = DateTime.Now;
  291. }
  292. else {
  293. tSProcessEntity.F_BeginTime = tSSchemeModel.startTime;
  294. }
  295. if (tSSchemeModel.endType == 1) {
  296. tSProcessEntity.F_EndTime = DateTime.MaxValue;
  297. }
  298. db.Insert(tSProcessEntity);
  299. }
  300. db.Commit();
  301. return tSProcessEntity;
  302. }
  303. catch (Exception ex)
  304. {
  305. db.Rollback();
  306. if (ex is ExceptionEx)
  307. {
  308. throw;
  309. }
  310. else
  311. {
  312. throw ExceptionEx.ThrowServiceException(ex);
  313. }
  314. }
  315. }
  316. /// <summary>
  317. /// 保存实体数据(新增、修改)
  318. /// <param name="keyValue">主键</param>
  319. /// <summary>
  320. /// <returns></returns>
  321. public void SaveEntity(string keyValue, TSSchemeInfoEntity entity)
  322. {
  323. try
  324. {
  325. if (!string.IsNullOrEmpty(keyValue))
  326. {
  327. entity.Modify(keyValue);
  328. this.BaseRepository().Update(entity);
  329. }
  330. else
  331. {
  332. entity.Create();
  333. this.BaseRepository().Insert(entity);
  334. }
  335. }
  336. catch (Exception ex)
  337. {
  338. if (ex is ExceptionEx)
  339. {
  340. throw;
  341. }
  342. else
  343. {
  344. throw ExceptionEx.ThrowServiceException(ex);
  345. }
  346. }
  347. }
  348. #endregion
  349. }
  350. }