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.
 
 
 
 
 
 

644 lines
23 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Text;
  7. namespace Learun.Application.WorkFlow
  8. {
  9. /// <summary>
  10. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  11. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  12. /// 创建人:陈彬彬
  13. /// 日 期:2017.04.17
  14. /// 描 述:工作流模板处理
  15. /// </summary>
  16. public class WfSchemeService : RepositoryFactory
  17. {
  18. #region 属性 构造函数
  19. private string schemeInfoFieldSql;
  20. private string schemeFieldSql;
  21. public WfSchemeService()
  22. {
  23. schemeInfoFieldSql = @"
  24. t.F_Id,
  25. t.F_Code,
  26. t.F_Name,
  27. t.F_Category,
  28. t.F_Kind,
  29. t.F_SchemeId,
  30. t.F_DeleteMark,
  31. t.F_EnabledMark,
  32. t.F_Description
  33. ";
  34. schemeFieldSql = @"
  35. t.F_Id,
  36. t.F_SchemeInfoId,
  37. t.F_Type,
  38. t.F_CreateDate,
  39. t.F_CreateUserId,
  40. t.F_CreateUserName
  41. ";
  42. }
  43. #endregion
  44. #region 获取数据
  45. /// <summary>
  46. /// 获取流程分页列表
  47. /// </summary>
  48. /// <param name="pagination">分页参数</param>
  49. /// <param name="keyword">关键字</param>
  50. /// <param name="category">分类</param>
  51. /// <returns></returns>
  52. public IEnumerable<WfSchemeInfoEntity> GetSchemeInfoPageList(Pagination pagination, string keyword, string category)
  53. {
  54. try
  55. {
  56. var strSql = new StringBuilder();
  57. strSql.Append("SELECT ");
  58. strSql.Append(schemeInfoFieldSql);
  59. strSql.Append(",t1.F_Type,t1.F_CreateDate,t1.F_CreateUserId,t1.F_CreateUserName ");
  60. strSql.Append(" FROM LR_WF_SchemeInfo t LEFT JOIN LR_WF_Scheme t1 ON t.F_SchemeId = t1.F_Id WHERE 1=1 AND t.F_DeleteMark = 0 ");
  61. if (!string.IsNullOrEmpty(keyword))
  62. {
  63. strSql.Append(" AND ( t.F_Name like @keyword OR t.F_Code like @keyword ) ");
  64. keyword = "%" + keyword + "%";
  65. }
  66. if (!string.IsNullOrEmpty(category))
  67. {
  68. strSql.Append(" AND t.F_Category = @category ");
  69. }
  70. return this.BaseRepository().FindList<WfSchemeInfoEntity>(strSql.ToString(), new { keyword = keyword, category = category }, pagination);
  71. }
  72. catch (Exception ex)
  73. {
  74. if (ex is ExceptionEx)
  75. {
  76. throw;
  77. }
  78. else
  79. {
  80. throw ExceptionEx.ThrowServiceException(ex);
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// 获取流程模板分页列表
  86. /// </summary>
  87. /// <param name="pagination">分页参数</param>
  88. /// <param name="userInfo">登录者信息</param>
  89. /// <param name="queryJson">查询参数</param>
  90. /// <returns></returns>
  91. public IEnumerable<WfSchemeInfoEntity> GetAppSchemeInfoPageList(Pagination pagination, UserInfo userInfo, string queryJson)
  92. {
  93. try
  94. {
  95. string userId = userInfo.userId;
  96. string postIds = userInfo.postIds;
  97. string roleIds = userInfo.roleIds;
  98. List<WfSchemeAuthorizeEntity> list = (List<WfSchemeAuthorizeEntity>)this.BaseRepository().FindList<WfSchemeAuthorizeEntity>(t => t.F_ObjectId == null
  99. || userId.Contains(t.F_ObjectId)
  100. || postIds.Contains(t.F_ObjectId)
  101. || roleIds.Contains(t.F_ObjectId)
  102. );
  103. string schemeinfoIds = "";
  104. foreach (var item in list)
  105. {
  106. schemeinfoIds += "'" + item.F_SchemeInfoId + "',";
  107. }
  108. schemeinfoIds = "(" + schemeinfoIds.Remove(schemeinfoIds.Length - 1, 1) + ")";
  109. var strSql = new StringBuilder();
  110. strSql.Append("SELECT ");
  111. strSql.Append(schemeInfoFieldSql);
  112. strSql.Append(" FROM LR_WF_SchemeInfo t WHERE 1=1 AND t.F_DeleteMark = 0 AND t.F_EnabledMark = 1 AND t.F_Kind = 1 AND F_IsApp = 1 AND t.F_Id in " + schemeinfoIds);
  113. var queryParam = queryJson.ToJObject();
  114. string keyword = "";
  115. if (!queryParam["keyword"].IsEmpty())
  116. {
  117. strSql.Append(" AND ( t.F_Name like @keyword OR t.F_Code like @keyword ) ");
  118. keyword = "%" + queryParam["keyword"].ToString() + "%";
  119. }
  120. return this.BaseRepository().FindList<WfSchemeInfoEntity>(strSql.ToString(), new { keyword }, pagination);
  121. }
  122. catch (Exception ex)
  123. {
  124. if (ex is ExceptionEx)
  125. {
  126. throw;
  127. }
  128. else
  129. {
  130. throw ExceptionEx.ThrowServiceException(ex);
  131. }
  132. }
  133. }
  134. /// <summary>
  135. /// 获取自定义流程列表
  136. /// </summary>
  137. /// <param name="userInfo">用户信息</param>
  138. /// <returns></returns>
  139. public IEnumerable<WfSchemeInfoEntity> GetCustmerSchemeInfoList(UserInfo userInfo)
  140. {
  141. try
  142. {
  143. string userId = userInfo.userId;
  144. string postIds = userInfo.postIds;
  145. string roleIds = userInfo.roleIds;
  146. List<WfSchemeAuthorizeEntity> list = (List<WfSchemeAuthorizeEntity>)this.BaseRepository().FindList<WfSchemeAuthorizeEntity>(t => t.F_ObjectId == null
  147. || userId.Contains(t.F_ObjectId)
  148. || postIds.Contains(t.F_ObjectId)
  149. || roleIds.Contains(t.F_ObjectId)
  150. );
  151. string schemeinfoIds = "";
  152. foreach (var item in list)
  153. {
  154. schemeinfoIds += "'" + item.F_SchemeInfoId + "',";
  155. }
  156. schemeinfoIds = "(" + schemeinfoIds.Remove(schemeinfoIds.Length - 1, 1) + ")";
  157. var strSql = new StringBuilder();
  158. strSql.Append("SELECT ");
  159. strSql.Append(schemeInfoFieldSql);
  160. strSql.Append(" FROM LR_WF_SchemeInfo t WHERE 1=1 AND t.F_DeleteMark = 0 AND t.F_EnabledMark = 1 AND t.F_Kind = 1 AND t.F_Id in " + schemeinfoIds);
  161. return this.BaseRepository().FindList<WfSchemeInfoEntity>(strSql.ToString());
  162. }
  163. catch (Exception ex)
  164. {
  165. if (ex is ExceptionEx)
  166. {
  167. throw;
  168. }
  169. else
  170. {
  171. throw ExceptionEx.ThrowServiceException(ex);
  172. }
  173. }
  174. }
  175. /// <summary>
  176. /// 获取自定义流程列表
  177. /// </summary>
  178. /// <param name="userInfo">用户信息</param>
  179. /// <returns></returns>
  180. public IEnumerable<WfSchemeInfoEntity> GetAppCustmerSchemeInfoList(UserInfo userInfo)
  181. {
  182. try
  183. {
  184. string userId = userInfo.userId;
  185. string postIds = userInfo.postIds;
  186. string roleIds = userInfo.roleIds;
  187. List<WfSchemeAuthorizeEntity> list = (List<WfSchemeAuthorizeEntity>)this.BaseRepository().FindList<WfSchemeAuthorizeEntity>(t => t.F_ObjectId == null
  188. || userId.Contains(t.F_ObjectId)
  189. || postIds.Contains(t.F_ObjectId)
  190. || roleIds.Contains(t.F_ObjectId)
  191. );
  192. string schemeinfoIds = "";
  193. foreach (var item in list)
  194. {
  195. schemeinfoIds += "'" + item.F_SchemeInfoId + "',";
  196. }
  197. schemeinfoIds = "(" + schemeinfoIds.Remove(schemeinfoIds.Length - 1, 1) + ")";
  198. var strSql = new StringBuilder();
  199. strSql.Append("SELECT ");
  200. strSql.Append(schemeInfoFieldSql);
  201. strSql.Append(" FROM LR_WF_SchemeInfo t WHERE 1=1 AND t.F_DeleteMark = 0 AND t.F_EnabledMark = 1 AND t.F_Kind = 1 AND F_IsApp = 1 AND t.F_Id in " + schemeinfoIds);
  202. return this.BaseRepository().FindList<WfSchemeInfoEntity>(strSql.ToString());
  203. }
  204. catch (Exception ex)
  205. {
  206. if (ex is ExceptionEx)
  207. {
  208. throw;
  209. }
  210. else
  211. {
  212. throw ExceptionEx.ThrowServiceException(ex);
  213. }
  214. }
  215. }
  216. /// <summary>
  217. /// 获取模板列表
  218. /// </summary>
  219. /// <param name="schemeInfoId">模板信息主键</param>
  220. /// <returns></returns>
  221. public IEnumerable<WfSchemeEntity> GetWfSchemeList(string schemeInfoId)
  222. {
  223. try
  224. {
  225. var strSql = new StringBuilder();
  226. strSql.Append("SELECT ");
  227. strSql.Append(schemeFieldSql);
  228. strSql.Append(" FROM LR_WF_Scheme t WHERE 1=1 ");
  229. strSql.Append(" AND t.F_SchemeInfoId = @schemeInfoId ");
  230. return this.BaseRepository().FindList<WfSchemeEntity>(strSql.ToString(), new { schemeInfoId = schemeInfoId });
  231. }
  232. catch (Exception ex)
  233. {
  234. if (ex is ExceptionEx)
  235. {
  236. throw;
  237. }
  238. else
  239. {
  240. throw ExceptionEx.ThrowServiceException(ex);
  241. }
  242. }
  243. }
  244. /// <summary>
  245. /// 获取模板列表
  246. /// </summary>
  247. /// <param name="pagination">分页参数</param>
  248. /// <param name="schemeInfoId">模板信息主键</param>
  249. /// <returns></returns>
  250. public IEnumerable<WfSchemeEntity> GetSchemePageList(Pagination pagination, string schemeInfoId)
  251. {
  252. try
  253. {
  254. var strSql = new StringBuilder();
  255. strSql.Append("SELECT ");
  256. strSql.Append(schemeFieldSql);
  257. strSql.Append(" FROM LR_WF_Scheme t WHERE 1=1 ");
  258. strSql.Append(" AND t.F_SchemeInfoId = @schemeInfoId ");
  259. return this.BaseRepository().FindList<WfSchemeEntity>(strSql.ToString(), new { schemeInfoId = 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 WfSchemeInfoEntity GetWfSchemeInfoEntity(string keyValue)
  279. {
  280. try
  281. {
  282. return this.BaseRepository().FindEntity<WfSchemeInfoEntity>(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. /// <summary>
  297. /// 获取模板基础信息的实体
  298. /// </summary>
  299. /// <param name="code">流程编号</param>
  300. /// <returns></returns>
  301. public WfSchemeInfoEntity GetWfSchemeInfoEntityByCode(string code)
  302. {
  303. try
  304. {
  305. return this.BaseRepository().FindEntity<WfSchemeInfoEntity>(t => t.F_Code == code && t.F_DeleteMark == 0);
  306. }
  307. catch (Exception ex)
  308. {
  309. if (ex is ExceptionEx)
  310. {
  311. throw;
  312. }
  313. else
  314. {
  315. throw ExceptionEx.ThrowServiceException(ex);
  316. }
  317. }
  318. }
  319. /// <summary>
  320. /// 获取模板的实体
  321. /// </summary>
  322. /// <param name="keyValue">主键</param>
  323. /// <returns></returns>
  324. public WfSchemeEntity GetWfSchemeEntity(string keyValue)
  325. {
  326. try
  327. {
  328. return this.BaseRepository().FindEntity<WfSchemeEntity>(keyValue);
  329. }
  330. catch (Exception ex)
  331. {
  332. if (ex is ExceptionEx)
  333. {
  334. throw;
  335. }
  336. else
  337. {
  338. throw ExceptionEx.ThrowServiceException(ex);
  339. }
  340. }
  341. }
  342. /// <summary>
  343. /// 获取流程模板权限列表
  344. /// </summary>
  345. /// <param name="schemeInfoId">模板信息主键</param>
  346. /// <returns></returns>
  347. public IEnumerable<WfSchemeAuthorizeEntity> GetWfSchemeAuthorizeList(string schemeInfoId)
  348. {
  349. try
  350. {
  351. return this.BaseRepository().FindList<WfSchemeAuthorizeEntity>(t => t.F_SchemeInfoId == schemeInfoId);
  352. }
  353. catch (Exception ex)
  354. {
  355. if (ex is ExceptionEx)
  356. {
  357. throw;
  358. }
  359. else
  360. {
  361. throw ExceptionEx.ThrowServiceException(ex);
  362. }
  363. }
  364. }
  365. #endregion
  366. #region 提交数据
  367. /// <summary>
  368. /// 虚拟删除模板信息
  369. /// </summary>
  370. /// <param name="keyValue">主键</param>
  371. public void VirtualDelete(string keyValue)
  372. {
  373. try
  374. {
  375. WfSchemeInfoEntity entity = new WfSchemeInfoEntity()
  376. {
  377. F_Id = keyValue,
  378. F_DeleteMark = 1
  379. };
  380. this.BaseRepository().Update(entity);
  381. }
  382. catch (Exception ex)
  383. {
  384. if (ex is ExceptionEx)
  385. {
  386. throw;
  387. }
  388. else
  389. {
  390. throw ExceptionEx.ThrowServiceException(ex);
  391. }
  392. }
  393. }
  394. /// <summary>
  395. /// 保存模板信息
  396. /// </summary>
  397. /// <param name="keyValue">主键</param>
  398. /// <param name="wfSchemeInfoEntity">模板基础信息</param>
  399. /// <param name="wfSchemeEntity">模板信息</param>
  400. public void SaveEntity(string keyValue, WfSchemeInfoEntity wfSchemeInfoEntity, WfSchemeEntity wfSchemeEntity, List<WfSchemeAuthorizeEntity> wfSchemeAuthorizeList)
  401. {
  402. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  403. try
  404. {
  405. if (string.IsNullOrEmpty(keyValue))
  406. {
  407. wfSchemeInfoEntity.Create();
  408. }
  409. else
  410. {
  411. wfSchemeInfoEntity.Modify(keyValue);
  412. }
  413. #region 模板信息
  414. if (wfSchemeEntity != null)
  415. {
  416. wfSchemeEntity.F_SchemeInfoId = wfSchemeInfoEntity.F_Id;
  417. wfSchemeEntity.Create();
  418. db.Insert(wfSchemeEntity);
  419. wfSchemeInfoEntity.F_SchemeId = wfSchemeEntity.F_Id;
  420. }
  421. #endregion
  422. #region 模板基础信息
  423. if (!string.IsNullOrEmpty(keyValue))
  424. {
  425. db.Update(wfSchemeInfoEntity);
  426. }
  427. else
  428. {
  429. db.Insert(wfSchemeInfoEntity);
  430. }
  431. #endregion
  432. #region 流程模板权限信息
  433. string schemeInfoId = wfSchemeInfoEntity.F_Id;
  434. db.Delete<WfSchemeAuthorizeEntity>(t => t.F_SchemeInfoId == schemeInfoId);
  435. foreach (var wfSchemeAuthorize in wfSchemeAuthorizeList)
  436. {
  437. wfSchemeAuthorize.F_SchemeInfoId = schemeInfoId;
  438. db.Insert(wfSchemeAuthorize);
  439. }
  440. #endregion
  441. db.Commit();
  442. }
  443. catch (Exception ex)
  444. {
  445. db.Rollback();
  446. if (ex is ExceptionEx)
  447. {
  448. throw;
  449. }
  450. else
  451. {
  452. throw ExceptionEx.ThrowServiceException(ex);
  453. }
  454. }
  455. }
  456. /// <summary>
  457. /// 更新流程模板
  458. /// </summary>
  459. /// <param name="schemeInfoId">模板信息主键</param>
  460. /// <param name="schemeId">模板主键</param>
  461. public void UpdateScheme(string schemeInfoId, string schemeId)
  462. {
  463. try
  464. {
  465. WfSchemeEntity wfSchemeEntity = GetWfSchemeEntity(schemeId);
  466. WfSchemeInfoEntity entity = new WfSchemeInfoEntity
  467. {
  468. F_Id = schemeInfoId,
  469. F_SchemeId = schemeId
  470. };
  471. if (wfSchemeEntity.F_Type != 1)
  472. {
  473. entity.F_EnabledMark = 0;
  474. }
  475. this.BaseRepository().Update(entity);
  476. }
  477. catch (Exception ex)
  478. {
  479. if (ex is ExceptionEx)
  480. {
  481. throw;
  482. }
  483. else
  484. {
  485. throw ExceptionEx.ThrowServiceException(ex);
  486. }
  487. }
  488. }
  489. /// <summary>
  490. /// 保存模板基础信息
  491. /// </summary>
  492. /// <param name="keyValue">主键</param>
  493. /// <param name="schemeInfoEntity">模板基础信息</param>
  494. public void SaveSchemeInfoEntity(string keyValue, WfSchemeInfoEntity schemeInfoEntity)
  495. {
  496. try
  497. {
  498. if (!string.IsNullOrEmpty(keyValue))
  499. {
  500. schemeInfoEntity.Modify(keyValue);
  501. this.BaseRepository().Update(schemeInfoEntity);
  502. }
  503. else
  504. {
  505. schemeInfoEntity.Create();
  506. this.BaseRepository().Insert(schemeInfoEntity);
  507. }
  508. }
  509. catch (Exception ex)
  510. {
  511. if (ex is ExceptionEx)
  512. {
  513. throw;
  514. }
  515. else
  516. {
  517. throw ExceptionEx.ThrowServiceException(ex);
  518. }
  519. }
  520. }
  521. /// <summary>
  522. /// 更新自定义表单模板状态
  523. /// </summary>
  524. /// <param name="schemeInfoId">模板信息主键</param>
  525. /// <param name="state">状态1启用0禁用</param>
  526. public void UpdateState(string schemeInfoId, int state)
  527. {
  528. try
  529. {
  530. WfSchemeInfoEntity entity = new WfSchemeInfoEntity
  531. {
  532. F_Id = schemeInfoId,
  533. F_EnabledMark = state
  534. };
  535. this.BaseRepository().Update(entity);
  536. }
  537. catch (Exception ex)
  538. {
  539. if (ex is ExceptionEx)
  540. {
  541. throw;
  542. }
  543. else
  544. {
  545. throw ExceptionEx.ThrowServiceException(ex);
  546. }
  547. }
  548. }
  549. #endregion
  550. #region 扩展数据
  551. /// <summary>
  552. /// 获取流程模板使用次数列表
  553. /// </summary>
  554. /// <param name="queryJson">查询参数</param>
  555. /// <returns></returns>
  556. public IEnumerable<WfProcessInstanceEntity> GetWfSchemeUseList(string queryJson)
  557. {
  558. try
  559. {
  560. //var dp = new DynamicParameters(new { });
  561. var dp = new object();
  562. var strSql = new StringBuilder();
  563. strSql.Append("select si.F_Category,si.F_Name,si.F_Code,si.F_Kind,p.F_Id,p.F_CreateDate from");
  564. strSql.Append(" [dbo].[LR_WF_SchemeInfo] si left join [dbo].[LR_WF_Scheme] s on si.F_Id=s.F_SchemeInfoId left join [dbo].[LR_WF_ProcessInstance] p on s.F_Id=p.F_SchemeId ");
  565. strSql.Append(" where si.F_DeleteMark=0 and si.F_EnabledMark=1 and s.F_Type=1");
  566. var queryParam = queryJson.ToJObject();
  567. if (!queryParam["year"].IsEmpty())
  568. {
  569. //dp.Add("year", queryParam["year"].ToInt(), DbType.Int32);
  570. dp = new { year = queryParam["year"].ToInt() };
  571. strSql.Append(" and DATEPART(yyyy,p.F_CreateDate) = @year ");
  572. }
  573. return this.BaseRepository().FindList<WfProcessInstanceEntity>(strSql.ToString(), dp);
  574. }
  575. catch (Exception ex)
  576. {
  577. if (ex is ExceptionEx)
  578. {
  579. throw;
  580. }
  581. else
  582. {
  583. throw ExceptionEx.ThrowServiceException(ex);
  584. }
  585. }
  586. }
  587. public IEnumerable<WfProcessInstanceEntity> GetWfSchemeStart()
  588. {
  589. try
  590. {
  591. var strSql = new StringBuilder();
  592. // strSql.Append(@"select si.F_Category,si.F_Name,si.F_Code,si.F_Id,count(p.F_Id) from
  593. //[dbo].[LR_WF_SchemeInfo] si left join [dbo].[LR_WF_Scheme] s on si.F_Id=s.F_SchemeInfoId left join [dbo].[LR_WF_ProcessInstance] p on s.F_Id=p.F_SchemeId
  594. // where si.F_DeleteMark=0 and si.F_EnabledMark=1 and s.F_Type=1 and si.F_Kind=1
  595. // group by si.F_Category,si.F_Name,si.F_Code,si.F_Id order by count(p.F_Id) desc");
  596. strSql.Append(@"SELECT t.F_Category,t.F_Name,t.F_Code,t.F_Id,COUNT(t.F_Id)
  597. FROM LR_NWF_SchemeInfo t LEFT JOIN LR_NWF_Scheme t1 ON t.F_SchemeId = t1.F_Id WHERE t.F_EnabledMark=1 AND t1.F_Type=1
  598. GROUP BY t.F_Category,t.F_Name,t.F_Code,t.F_Id ORDER BY COUNT(t.F_Id) DESC");
  599. return this.BaseRepository().FindList<WfProcessInstanceEntity>(strSql.ToString());
  600. }
  601. catch (Exception ex)
  602. {
  603. if (ex is ExceptionEx)
  604. {
  605. throw;
  606. }
  607. else
  608. {
  609. throw ExceptionEx.ThrowServiceException(ex);
  610. }
  611. }
  612. }
  613. #endregion
  614. }
  615. }