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.
 
 
 
 
 
 

472 lines
16 KiB

  1. using Dapper;
  2. using Learun.DataBase.Repository;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Text;
  8. namespace Learun.Application.WorkFlow
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架
  12. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  13. /// 创建人:力软-框架开发组
  14. /// 日 期:2018.12.06
  15. /// 描 述:工作流模板(新)
  16. /// </summary>
  17. public class NWFSchemeService: RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取流程分页列表
  22. /// </summary>
  23. /// <param name="pagination">分页参数</param>
  24. /// <param name="queryJson">查询条件</param>
  25. /// <returns></returns>
  26. public IEnumerable<NWFSchemeInfoEntity> GetInfoPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT t.* ");
  32. strSql.Append(",t1.F_Type,t1.F_CreateDate,t1.F_CreateUserId,t1.F_CreateUserName ");
  33. strSql.Append(" FROM LR_NWF_SchemeInfo t LEFT JOIN LR_NWF_Scheme t1 ON t.F_SchemeId = t1.F_Id WHERE 1=1 ");
  34. var dp = new DynamicParameters();
  35. if (!string.IsNullOrEmpty(queryJson)) {
  36. var queryParam = queryJson.ToJObject();
  37. if (!queryParam["keyword"].IsEmpty())
  38. {
  39. strSql.Append(" AND ( t.F_Name like @keyword OR t.F_Code like @keyword ) ");
  40. dp.Add("keyword", "%" + queryParam["keyword"].ToString() + "%", DbType.String);
  41. }
  42. if (!queryParam["category"].IsEmpty())
  43. {
  44. strSql.Append(" AND t.F_Category = @category ");
  45. dp.Add("category", queryParam["category"].ToString(), DbType.String);
  46. }
  47. }
  48. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString(), dp, pagination);
  49. }
  50. catch (Exception ex)
  51. {
  52. if (ex is ExceptionEx)
  53. {
  54. throw;
  55. }
  56. else
  57. {
  58. throw ExceptionEx.ThrowServiceException(ex);
  59. }
  60. }
  61. }
  62. /// <summary>
  63. /// 获取自定义流程列表
  64. /// </summary>
  65. /// <param name="userInfo">用户信息</param>
  66. /// <returns></returns>
  67. public IEnumerable<NWFSchemeInfoEntity> GetInfoList(UserInfo userInfo)
  68. {
  69. try
  70. {
  71. string userId = userInfo.userId;
  72. string postIds = userInfo.postIds;
  73. string roleIds = userInfo.roleIds;
  74. List<NWFSchemeAuthEntity> list = (List<NWFSchemeAuthEntity>)this.BaseRepository().FindList<NWFSchemeAuthEntity>(t => t.F_ObjId == null
  75. || userId.Contains(t.F_ObjId)
  76. || postIds.Contains(t.F_ObjId)
  77. || roleIds.Contains(t.F_ObjId)
  78. );
  79. string schemeinfoIds = "";
  80. foreach (var item in list)
  81. {
  82. schemeinfoIds += "'" + item.F_SchemeInfoId + "',";
  83. }
  84. schemeinfoIds = "(" + schemeinfoIds.Remove(schemeinfoIds.Length - 1, 1) + ")";
  85. var strSql = new StringBuilder();
  86. strSql.Append("SELECT * ");
  87. strSql.Append(" FROM LR_NWF_SchemeInfo t WHERE t.F_EnabledMark = 1 AND t.F_Mark = 1 AND t.F_Kind = 1 AND t.F_Id in " + schemeinfoIds);
  88. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString());
  89. }
  90. catch (Exception ex)
  91. {
  92. if (ex is ExceptionEx)
  93. {
  94. throw;
  95. }
  96. else
  97. {
  98. throw ExceptionEx.ThrowServiceException(ex);
  99. }
  100. }
  101. }
  102. /// <summary>
  103. /// 获取流程列表
  104. /// </summary>
  105. /// <returns></returns>
  106. public IEnumerable<NWFSchemeInfoEntity> GetInfoList()
  107. {
  108. try
  109. {
  110. var strSql = new StringBuilder();
  111. strSql.Append("SELECT * ");
  112. strSql.Append(" FROM LR_NWF_SchemeInfo t WHERE t.F_EnabledMark = 1 ");
  113. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString());
  114. }
  115. catch (Exception ex)
  116. {
  117. if (ex is ExceptionEx)
  118. {
  119. throw;
  120. }
  121. else
  122. {
  123. throw ExceptionEx.ThrowServiceException(ex);
  124. }
  125. }
  126. }
  127. /// <summary>
  128. /// 获取流程模板分页列表
  129. /// </summary>
  130. /// <param name="pagination">分页参数</param>
  131. /// <param name="userInfo">登录者信息</param>
  132. /// <param name="queryJson">查询参数</param>
  133. /// <returns></returns>
  134. public IEnumerable<NWFSchemeInfoEntity> GetAppInfoPageList(Pagination pagination, UserInfo userInfo, string queryJson)
  135. {
  136. try
  137. {
  138. string userId = userInfo.userId;
  139. string postIds = userInfo.postIds;
  140. string roleIds = userInfo.roleIds;
  141. List<NWFSchemeAuthEntity> list = (List<NWFSchemeAuthEntity>)this.BaseRepository().FindList<NWFSchemeAuthEntity>(t => t.F_ObjId == null
  142. || userId.Contains(t.F_ObjId)
  143. || postIds.Contains(t.F_ObjId)
  144. || roleIds.Contains(t.F_ObjId)
  145. );
  146. string schemeinfoIds = "";
  147. foreach (var item in list)
  148. {
  149. schemeinfoIds += "'" + item.F_SchemeInfoId + "',";
  150. }
  151. schemeinfoIds = "(" + schemeinfoIds.Remove(schemeinfoIds.Length - 1, 1) + ")";
  152. var strSql = new StringBuilder();
  153. strSql.Append("SELECT * ");
  154. strSql.Append(" FROM LR_NWF_SchemeInfo t WHERE t.F_EnabledMark = 1 AND t.F_Mark = 1 AND F_IsInApp = 1 AND t.F_Kind = 1 AND t.F_Id in " + schemeinfoIds);
  155. var queryParam = queryJson.ToJObject();
  156. string keyword = "";
  157. if (!queryParam["keyword"].IsEmpty())
  158. {
  159. strSql.Append(" AND ( t.F_Name like @keyword OR t.F_Code like @keyword ) ");
  160. keyword = "%" + queryParam["keyword"].ToString() + "%";
  161. }
  162. return this.BaseRepository().FindList<NWFSchemeInfoEntity>(strSql.ToString(), new { keyword }, pagination);
  163. }
  164. catch (Exception ex)
  165. {
  166. if (ex is ExceptionEx)
  167. {
  168. throw;
  169. }
  170. else
  171. {
  172. throw ExceptionEx.ThrowServiceException(ex);
  173. }
  174. }
  175. }
  176. /// <summary>
  177. /// 获取模板基础信息的实体
  178. /// </summary>
  179. /// <param name="keyValue">主键</param>
  180. /// <returns></returns>
  181. public NWFSchemeInfoEntity GetInfoEntity(string keyValue)
  182. {
  183. try
  184. {
  185. return this.BaseRepository().FindEntity<NWFSchemeInfoEntity>(keyValue);
  186. }
  187. catch (Exception ex)
  188. {
  189. if (ex is ExceptionEx)
  190. {
  191. throw;
  192. }
  193. else
  194. {
  195. throw ExceptionEx.ThrowServiceException(ex);
  196. }
  197. }
  198. }
  199. /// <summary>
  200. /// 获取模板基础信息的实体
  201. /// </summary>
  202. /// <param name="code">流程编号</param>
  203. /// <returns></returns>
  204. public NWFSchemeInfoEntity GetInfoEntityByCode(string code)
  205. {
  206. try
  207. {
  208. return this.BaseRepository().FindEntity<NWFSchemeInfoEntity>(t => t.F_Code == code);
  209. }
  210. catch (Exception ex)
  211. {
  212. if (ex is ExceptionEx)
  213. {
  214. throw;
  215. }
  216. else
  217. {
  218. throw ExceptionEx.ThrowServiceException(ex);
  219. }
  220. }
  221. }
  222. /// <summary>
  223. /// 获取流程模板权限列表
  224. /// </summary>
  225. /// <param name="schemeInfoId">模板信息主键</param>
  226. /// <returns></returns>
  227. public IEnumerable<NWFSchemeAuthEntity> GetAuthList(string schemeInfoId)
  228. {
  229. try
  230. {
  231. return this.BaseRepository().FindList<NWFSchemeAuthEntity>(t => t.F_SchemeInfoId == schemeInfoId);
  232. }
  233. catch (Exception ex)
  234. {
  235. if (ex is ExceptionEx)
  236. {
  237. throw;
  238. }
  239. else
  240. {
  241. throw ExceptionEx.ThrowServiceException(ex);
  242. }
  243. }
  244. }
  245. /// <summary>
  246. /// 获取模板列表
  247. /// </summary>
  248. /// <param name="pagination">分页参数</param>
  249. /// <param name="schemeInfoId">流程信息主键</param>
  250. /// <returns></returns>
  251. public IEnumerable<NWFSchemeEntity> GetSchemePageList(Pagination pagination, string schemeInfoId)
  252. {
  253. try
  254. {
  255. var strSql = new StringBuilder();
  256. strSql.Append("SELECT t.F_Id,t.F_SchemeInfoId,t.F_Type,t.F_CreateDate,t.F_CreateUserId,t.F_CreateUserName");
  257. strSql.Append(" FROM LR_NWF_Scheme t ");
  258. strSql.Append(" WHERE t.F_SchemeInfoId = @schemeInfoId ");
  259. return this.BaseRepository().FindList<NWFSchemeEntity>(strSql.ToString(), new { schemeInfoId }, pagination);
  260. }
  261. catch (Exception ex)
  262. {
  263. if (ex is ExceptionEx)
  264. {
  265. throw;
  266. }
  267. else
  268. {
  269. throw ExceptionEx.ThrowServiceException(ex);
  270. }
  271. }
  272. }
  273. /// <summary>
  274. /// 获取模板的实体
  275. /// </summary>
  276. /// <param name="keyValue">主键</param>
  277. /// <returns></returns>
  278. public NWFSchemeEntity GetSchemeEntity(string keyValue)
  279. {
  280. try
  281. {
  282. return this.BaseRepository().FindEntity<NWFSchemeEntity>(keyValue);
  283. }
  284. catch (Exception ex)
  285. {
  286. if (ex is ExceptionEx)
  287. {
  288. throw;
  289. }
  290. else
  291. {
  292. throw ExceptionEx.ThrowServiceException(ex);
  293. }
  294. }
  295. }
  296. #endregion
  297. #region 提交数据
  298. /// <summary>
  299. /// 虚拟删除模板信息
  300. /// </summary>
  301. /// <param name="keyValue">主键</param>
  302. public void DeleteEntity(string keyValue)
  303. {
  304. var db = this.BaseRepository().BeginTrans();
  305. try
  306. {
  307. db.Delete<NWFSchemeInfoEntity>(t => t.F_Id.Equals(keyValue));
  308. db.Delete<NWFSchemeAuthEntity>(t => t.F_SchemeInfoId.Equals(keyValue));
  309. db.Delete<NWFSchemeEntity>(t => t.F_SchemeInfoId.Equals(keyValue));
  310. db.Commit();
  311. }
  312. catch (Exception ex)
  313. {
  314. db.Rollback();
  315. if (ex is ExceptionEx)
  316. {
  317. throw;
  318. }
  319. else
  320. {
  321. throw ExceptionEx.ThrowServiceException(ex);
  322. }
  323. }
  324. }
  325. /// <summary>
  326. /// 保存模板信息
  327. /// </summary>
  328. /// <param name="keyValue">主键</param>
  329. /// <param name="infoEntity">模板基础信息</param>
  330. /// <param name="schemeEntity">模板信息</param>
  331. /// <param name="authList">模板权限信息</param>
  332. public void SaveEntity(string keyValue, NWFSchemeInfoEntity infoEntity, NWFSchemeEntity schemeEntity, List<NWFSchemeAuthEntity> authList)
  333. {
  334. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  335. try
  336. {
  337. if (string.IsNullOrEmpty(keyValue))
  338. {
  339. infoEntity.Create();
  340. }
  341. else
  342. {
  343. infoEntity.Modify(keyValue);
  344. }
  345. #region 模板信息
  346. if (schemeEntity != null)
  347. {
  348. schemeEntity.F_SchemeInfoId = infoEntity.F_Id;
  349. schemeEntity.Create();
  350. db.Insert(schemeEntity);
  351. infoEntity.F_SchemeId = schemeEntity.F_Id;
  352. }
  353. #endregion
  354. #region 模板基础信息
  355. if (!string.IsNullOrEmpty(keyValue))
  356. {
  357. db.Update(infoEntity);
  358. }
  359. else
  360. {
  361. db.Insert(infoEntity);
  362. }
  363. #endregion
  364. #region 流程模板权限信息
  365. string schemeInfoId = infoEntity.F_Id;
  366. db.Delete<NWFSchemeAuthEntity>(t => t.F_SchemeInfoId == schemeInfoId);
  367. foreach (var item in authList)
  368. {
  369. item.Create();
  370. item.F_SchemeInfoId = schemeInfoId;
  371. db.Insert(item);
  372. }
  373. #endregion
  374. db.Commit();
  375. }
  376. catch (Exception ex)
  377. {
  378. db.Rollback();
  379. if (ex is ExceptionEx)
  380. {
  381. throw;
  382. }
  383. else
  384. {
  385. throw ExceptionEx.ThrowServiceException(ex);
  386. }
  387. }
  388. }
  389. /// <summary>
  390. /// 更新流程模板
  391. /// </summary>
  392. /// <param name="schemeInfoId">模板信息主键</param>
  393. /// <param name="schemeId">模板主键</param>
  394. public void UpdateScheme(string schemeInfoId, string schemeId)
  395. {
  396. try
  397. {
  398. NWFSchemeEntity nWFSchemeEntity = GetSchemeEntity(schemeId);
  399. NWFSchemeInfoEntity entity = new NWFSchemeInfoEntity
  400. {
  401. F_Id = schemeInfoId,
  402. F_SchemeId = schemeId
  403. };
  404. if (nWFSchemeEntity.F_Type != 1)
  405. {
  406. entity.F_EnabledMark = 0;
  407. }
  408. this.BaseRepository().Update(entity);
  409. }
  410. catch (Exception ex)
  411. {
  412. if (ex is ExceptionEx)
  413. {
  414. throw;
  415. }
  416. else
  417. {
  418. throw ExceptionEx.ThrowServiceException(ex);
  419. }
  420. }
  421. }
  422. /// <summary>
  423. /// 更新自定义表单模板状态
  424. /// </summary>
  425. /// <param name="schemeInfoId">模板信息主键</param>
  426. /// <param name="state">状态1启用0禁用</param>
  427. public void UpdateState(string schemeInfoId, int state)
  428. {
  429. try
  430. {
  431. NWFSchemeInfoEntity entity = new NWFSchemeInfoEntity
  432. {
  433. F_Id = schemeInfoId,
  434. F_EnabledMark = state
  435. };
  436. this.BaseRepository().Update(entity);
  437. }
  438. catch (Exception ex)
  439. {
  440. if (ex is ExceptionEx)
  441. {
  442. throw;
  443. }
  444. else
  445. {
  446. throw ExceptionEx.ThrowServiceException(ex);
  447. }
  448. }
  449. }
  450. #endregion
  451. }
  452. }