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.
 
 
 
 
 
 

1627 lines
63 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.Linq;
  7. using System.Text;
  8. using Learun.Application.TwoDevelopment.LR_LGManager;
  9. namespace Learun.Application.WorkFlow
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架
  13. /// Copyright (c) 2013-2018 上海力软信息技术有限公司
  14. /// 创建人:力软-框架开发组
  15. /// 日 期:2018.12.07
  16. /// 描 述:流程进程
  17. /// </summary>
  18. public class NWFProcessSericve : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取流程进程实体
  23. /// </summary>
  24. /// <param name="keyValue">主键</param>
  25. /// <returns></returns>
  26. public NWFProcessEntity GetEntity(string keyValue)
  27. {
  28. try
  29. {
  30. return this.BaseRepository().FindEntity<NWFProcessEntity>(keyValue);
  31. }
  32. catch (Exception ex)
  33. {
  34. if (ex is ExceptionEx)
  35. {
  36. throw;
  37. }
  38. else
  39. {
  40. throw ExceptionEx.ThrowServiceException(ex);
  41. }
  42. }
  43. }
  44. /// <summary>
  45. /// 获取流程进程实例
  46. /// </summary>
  47. /// <param name="processId">父流程进程主键</param>
  48. /// <param name="nodeId">节点主键</param>
  49. /// <returns></returns>
  50. public NWFProcessEntity GetEntityByProcessId(string processId, string nodeId)
  51. {
  52. try
  53. {
  54. return this.BaseRepository().FindEntity<NWFProcessEntity>(t => t.F_ParentProcessId == processId && t.F_ParentNodeId == nodeId);
  55. }
  56. catch (Exception ex)
  57. {
  58. if (ex is ExceptionEx)
  59. {
  60. throw;
  61. }
  62. else
  63. {
  64. throw ExceptionEx.ThrowServiceException(ex);
  65. }
  66. }
  67. }
  68. /// <summary>
  69. /// 获取子流程列表
  70. /// </summary>
  71. /// <param name="parentProcessId">父流程进程主键</param>
  72. /// <returns></returns>
  73. public IEnumerable<NWFProcessEntity> GetChildProcessList(string parentProcessId)
  74. {
  75. try
  76. {
  77. return this.BaseRepository().FindList<NWFProcessEntity>(t => t.F_ParentProcessId == parentProcessId);
  78. }
  79. catch (Exception ex)
  80. {
  81. if (ex is ExceptionEx)
  82. {
  83. throw;
  84. }
  85. else
  86. {
  87. throw ExceptionEx.ThrowServiceException(ex);
  88. }
  89. }
  90. }
  91. /// <summary>
  92. /// 获取流程信息列表
  93. /// </summary>
  94. /// <param name="pagination">分页参数</param>
  95. /// <param name="queryJson">查询条件</param>
  96. /// <returns></returns>
  97. public IEnumerable<NWFProcessEntity> GetPageList(Pagination pagination, string queryJson)
  98. {
  99. try
  100. {
  101. var expression = LinqExtensions.True<NWFProcessEntity>();
  102. var queryParam = queryJson.ToJObject();
  103. // 分类
  104. if (!queryParam["categoryId"].IsEmpty()) // 1:未完成 2:已完成
  105. {
  106. if (queryParam["categoryId"].ToString() == "1")
  107. {
  108. expression = expression.And(t => t.F_IsFinished == 0);
  109. // 是否作废
  110. if (!queryParam["F_EnabledMark"].IsEmpty()) // 是否作废
  111. {
  112. expression = expression.And(t => t.F_EnabledMark == 3);
  113. }
  114. else
  115. {
  116. expression = expression.And(t => t.F_EnabledMark != 3);
  117. }
  118. }
  119. else
  120. {
  121. expression = expression.And(t => t.F_IsFinished == 1);
  122. }
  123. }
  124. //流程类别
  125. if (!queryParam["F_Category"].IsEmpty()) // 1:未完成 2:已完成
  126. {
  127. var Categofy = queryParam["F_Category"].ToString();
  128. var codeList = this.BaseRepository().FindList<NWFSchemeInfoEntity>(a => a.F_Category == Categofy).Select(a => a.F_Code);
  129. if (codeList.Count() > 0)
  130. {
  131. expression = expression.And(a => codeList.Contains(a.F_SchemeCode));
  132. }
  133. }
  134. // 操作时间
  135. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  136. {
  137. DateTime startTime = queryParam["StartTime"].ToDate();
  138. DateTime endTime = queryParam["EndTime"].ToDate();
  139. expression = expression.And(t => t.F_CreateDate >= startTime && t.F_CreateDate <= endTime);
  140. }
  141. // 关键字
  142. if (!queryParam["keyword"].IsEmpty())
  143. {
  144. string keyword = queryParam["keyword"].ToString();
  145. expression = expression.And(t => t.F_Title.Contains(keyword) || t.F_SchemeName.Contains(keyword) || t.F_CreateUserName.Contains(keyword));
  146. }
  147. expression = expression.And(t => t.F_EnabledMark != 2);
  148. expression = expression.And(t => t.F_IsChild == 0);
  149. var result = this.BaseRepository().FindList<NWFProcessEntity>(expression, pagination);
  150. return result;
  151. }
  152. catch (Exception ex)
  153. {
  154. if (ex is ExceptionEx)
  155. {
  156. throw;
  157. }
  158. else
  159. {
  160. throw ExceptionEx.ThrowServiceException(ex);
  161. }
  162. }
  163. }
  164. /// <summary>
  165. /// 获取流程信息列表
  166. /// </summary>
  167. /// <param name="pagination">分页参数</param>
  168. /// <param name="queryJson">查询条件</param>
  169. /// <returns></returns>
  170. public IEnumerable<NWFProcessEntity> GetAllList()
  171. {
  172. try
  173. {
  174. return this.BaseRepository().FindList<NWFProcessEntity>();
  175. }
  176. catch (Exception ex)
  177. {
  178. if (ex is ExceptionEx)
  179. {
  180. throw;
  181. }
  182. else
  183. {
  184. throw ExceptionEx.ThrowServiceException(ex);
  185. }
  186. }
  187. }
  188. public LC_hetongEntity GetHTInfo(string keyValue)
  189. {
  190. try
  191. {
  192. return this.BaseRepository("CollegeMIS").FindEntity<LC_hetongEntity>(a => a.LC_ID == keyValue);
  193. }
  194. catch (Exception ex)
  195. {
  196. if (ex is ExceptionEx)
  197. {
  198. throw;
  199. }
  200. else
  201. {
  202. throw ExceptionEx.ThrowServiceException(ex);
  203. }
  204. }
  205. }
  206. /// <summary>
  207. /// 获取我的流程信息列表
  208. /// </summary>
  209. /// <param name="userId">用户主键</param>
  210. /// <param name="pagination">分页参数</param>
  211. /// <param name="queryJson">查询条件</param>
  212. /// <param name="schemeCode">流程模板编码</param>
  213. /// <returns></returns>
  214. public IEnumerable<NWFProcessEntity> GetMyPageList(string userId, Pagination pagination, string queryJson, string schemeCode)
  215. {
  216. try
  217. {
  218. var expression = LinqExtensions.True<NWFProcessEntity>();
  219. var queryParam = queryJson.ToJObject();
  220. expression = expression.And(t => t.F_CreateUserId == userId);
  221. // 操作时间
  222. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  223. {
  224. DateTime startTime = queryParam["StartTime"].ToDate();
  225. DateTime endTime = queryParam["EndTime"].ToDate();
  226. expression = expression.And(t => t.F_CreateDate >= startTime && t.F_CreateDate <= endTime);
  227. }
  228. // 关键字
  229. if (!queryParam["keyword"].IsEmpty())
  230. {
  231. string keyword = queryParam["keyword"].ToString();
  232. expression = expression.And(t => t.F_Title.Contains(keyword) || t.F_SchemeName.Contains(keyword));
  233. }
  234. if (!string.IsNullOrEmpty(schemeCode))
  235. {
  236. expression = expression.And(t => t.F_SchemeCode.Equals(schemeCode));
  237. }
  238. expression = expression.And(t => t.F_IsChild == 0);
  239. var aa = this.BaseRepository().FindList<NWFProcessEntity>(expression, pagination);
  240. foreach (var item in aa)
  241. {
  242. item.F_TaskId = this.BaseRepository().FindEntity<NWFTaskEntity>(x => x.F_ProcessId == item.F_Id)?.F_Id;
  243. item.F_TaskType = this.BaseRepository().FindEntity<NWFTaskEntity>(x => x.F_ProcessId == item.F_Id)?.F_Type;
  244. item.F_TaskName = this.BaseRepository().FindEntity<NWFTaskEntity>(x => x.F_ProcessId == item.F_Id)?.F_NodeName;
  245. //合同流程审批专用 如果第一步校长审批同意的话 可以打印授权委托书
  246. if (item.F_SchemeCode == "LC_Contract_")
  247. {
  248. var entity = this.BaseRepository().FindEntity<NWFTaskLogEntity>(a =>
  249. a.F_ProcessId == item.F_Id && a.F_TaskUserId == "29add015-3638-415d-9f91-5024bd746fb5" &&
  250. a.F_OperationCode == "agree");
  251. if (null != entity)
  252. {
  253. item.LeaderIsAgree = true;
  254. }
  255. }
  256. }
  257. return aa;
  258. }
  259. catch (Exception ex)
  260. {
  261. if (ex is ExceptionEx)
  262. {
  263. throw;
  264. }
  265. else
  266. {
  267. throw ExceptionEx.ThrowServiceException(ex);
  268. }
  269. }
  270. }
  271. /// <summary>
  272. /// 获取我的流程信息列表
  273. /// </summary>
  274. /// <param name="userId">用户主键</param>
  275. /// <param name="pagination">分页参数</param>
  276. /// <param name="schemeCode">流程模板编码</param>
  277. /// <returns></returns>
  278. public IEnumerable<NWFProcessEntity> GetMyPageList(string userId, string queryJson, string schemeCode)
  279. {
  280. try
  281. {
  282. var expression = LinqExtensions.True<NWFProcessEntity>();
  283. var queryParam = queryJson.ToJObject();
  284. expression = expression.And(t => t.F_CreateUserId == userId);
  285. // 操作时间
  286. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  287. {
  288. DateTime startTime = queryParam["StartTime"].ToDate();
  289. DateTime endTime = queryParam["EndTime"].ToDate();
  290. expression = expression.And(t => t.F_CreateDate >= startTime && t.F_CreateDate <= endTime);
  291. }
  292. // 关键字
  293. if (!queryParam["keyword"].IsEmpty())
  294. {
  295. string keyword = queryParam["keyword"].ToString();
  296. expression = expression.And(t => t.F_Title.Contains(keyword) || t.F_SchemeName.Contains(keyword));
  297. }
  298. if (!string.IsNullOrEmpty(schemeCode))
  299. {
  300. expression = expression.And(t => t.F_SchemeCode.Equals(schemeCode));
  301. }
  302. expression = expression.And(t => t.F_IsChild == 0);
  303. return this.BaseRepository().FindList<NWFProcessEntity>(expression);
  304. }
  305. catch (Exception ex)
  306. {
  307. if (ex is ExceptionEx)
  308. {
  309. throw;
  310. }
  311. else
  312. {
  313. throw ExceptionEx.ThrowServiceException(ex);
  314. }
  315. }
  316. }
  317. /// <summary>
  318. /// 获取我的代办任务列表
  319. /// </summary>
  320. /// <param name="userInfo">用户信息</param>
  321. /// <param name="pagination">翻页信息</param>
  322. /// <param name="queryJson">查询条件</param>
  323. /// <param name="schemeCode">流程模板编码</param>
  324. /// <param name="isBatchAudit">true获取批量审核任务</param>
  325. /// <returns></returns>
  326. public IEnumerable<NWFProcessEntity> GetMyTaskPageList(UserInfo userInfo, Pagination pagination, string queryJson, string schemeCode, bool isBatchAudit = false)
  327. {
  328. try
  329. {
  330. string userId = userInfo.userId;
  331. var strSql = new StringBuilder();
  332. strSql.Append(@"SELECT
  333. t.F_Id AS F_TaskId,
  334. t.F_Type AS F_TaskType,
  335. t.F_NodeName AS F_TaskName,
  336. t.F_IsUrge,
  337. t.F_ModifyDate as F_CreateDate,
  338. p.F_Id,
  339. p.F_SchemeId,
  340. p.F_SchemeCode,
  341. p.F_SchemeName,
  342. p.F_Title,
  343. p.F_Level,
  344. p.F_EnabledMark,
  345. p.F_IsAgain,
  346. p.F_IsFinished,
  347. p.F_IsChild,
  348. p.F_ParentTaskId,
  349. p.F_ParentProcessId,
  350. p.F_CreateUserId,
  351. p.F_CreateUserName,
  352. p.F_IsStart
  353. FROM
  354. (
  355. SELECT
  356. F_TaskId
  357. FROM
  358. LR_NWF_TaskRelation r1
  359. LEFT JOIN LR_NWF_Task t1 ON r1.F_TaskId = t1.F_Id
  360. WHERE r1.F_Mark = 0 AND r1.F_Result = 0 AND (r1.F_UserId = @userId
  361. ");
  362. // 添加委托信息
  363. List<UserInfo> delegateList = GetDelegateProcess(userId);
  364. foreach (var item in delegateList)
  365. {
  366. string processId = "'" + item.wfProcessId.Replace(",", "','") + "'";
  367. string userI2 = "'" + item.userId + "'";
  368. strSql.Append(" OR (r1.F_UserId =" + userI2 + " AND t1.F_ProcessId in (" + processId + ") AND t1.F_Type != 2 )");
  369. }
  370. strSql.Append(@") GROUP BY
  371. F_TaskId
  372. ) r
  373. LEFT JOIN LR_NWF_Task t ON t.F_Id = r.F_TaskId
  374. LEFT JOIN LR_NWF_Process p ON p.F_Id = t.F_ProcessId
  375. WHERE
  376. t.F_IsFinished = 0 AND (p.F_IsFinished = 0 OR t.F_Type = 2 OR t.F_Type = 4 OR t.F_Type = 6)");
  377. var queryParam = queryJson.ToJObject();
  378. DateTime startTime = DateTime.Now, endTime = DateTime.Now;
  379. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  380. {
  381. startTime = queryParam["StartTime"].ToDate();
  382. endTime = queryParam["EndTime"].ToDate();
  383. strSql.Append(" AND ( t.F_ModifyDate >= @startTime AND t.F_ModifyDate <= @endTime ) ");
  384. }
  385. string keyword = "";
  386. if (!queryParam["keyword"].IsEmpty())
  387. {
  388. keyword = "%" + queryParam["keyword"].ToString() + "%";
  389. strSql.Append(" AND ( p.F_Title like @keyword OR p.F_SchemeName like @keyword ) ");
  390. }
  391. if (!string.IsNullOrEmpty(schemeCode))
  392. {
  393. strSql.Append(" AND p.F_SchemeCode = @schemeCode ");
  394. }
  395. if (isBatchAudit)
  396. {
  397. strSql.Append(" AND t.F_IsBatchAudit = 1 ");
  398. }
  399. return this.BaseRepository().FindList<NWFProcessEntity>(strSql.ToString(), new { userId, startTime, endTime, keyword, schemeCode }, pagination);
  400. }
  401. catch (Exception ex)
  402. {
  403. if (ex is ExceptionEx)
  404. {
  405. throw;
  406. }
  407. else
  408. {
  409. throw ExceptionEx.ThrowServiceException(ex);
  410. }
  411. }
  412. }
  413. /// <summary>
  414. /// 获取我的代办任务列表
  415. /// </summary>
  416. /// <param name="userInfo">用户信息</param>
  417. /// <param name="queryJson">查询条件</param>
  418. /// <param name="schemeCode">流程模板编码</param>
  419. /// <param name="isBatchAudit">true获取批量审核任务</param>
  420. /// <returns></returns>
  421. public IEnumerable<NWFProcessEntity> GetMyTaskPageList(UserInfo userInfo, string queryJson, string schemeCode, bool isBatchAudit = false)
  422. {
  423. try
  424. {
  425. string userId = userInfo.userId;
  426. var strSql = new StringBuilder();
  427. strSql.Append(@"SELECT
  428. t.F_Id AS F_TaskId,
  429. t.F_Type AS F_TaskType,
  430. t.F_NodeName AS F_TaskName,
  431. t.F_IsUrge,
  432. t.F_ModifyDate as F_CreateDate,
  433. p.F_Id,
  434. p.F_SchemeId,
  435. p.F_SchemeCode,
  436. p.F_SchemeName,
  437. p.F_Title,
  438. p.F_Level,
  439. p.F_EnabledMark,
  440. p.F_IsAgain,
  441. p.F_IsFinished,
  442. p.F_IsChild,
  443. p.F_ParentTaskId,
  444. p.F_ParentProcessId,
  445. p.F_CreateUserId,
  446. p.F_CreateUserName,
  447. p.F_IsStart
  448. FROM
  449. (
  450. SELECT
  451. F_TaskId
  452. FROM
  453. LR_NWF_TaskRelation r1
  454. LEFT JOIN LR_NWF_Task t1 ON r1.F_TaskId = t1.F_Id
  455. WHERE r1.F_Mark = 0 AND r1.F_Result = 0 AND (r1.F_UserId = @userId
  456. ");
  457. // 添加委托信息
  458. List<UserInfo> delegateList = GetDelegateProcess(userId);
  459. foreach (var item in delegateList)
  460. {
  461. string processId = "'" + item.wfProcessId.Replace(",", "','") + "'";
  462. string userI2 = "'" + item.userId + "'";
  463. strSql.Append(" OR (r1.F_UserId =" + userI2 + " AND t1.F_ProcessId in (" + processId + ") AND t1.F_Type != 2 )");
  464. }
  465. strSql.Append(@") GROUP BY
  466. F_TaskId
  467. ) r
  468. LEFT JOIN LR_NWF_Task t ON t.F_Id = r.F_TaskId
  469. LEFT JOIN LR_NWF_Process p ON p.F_Id = t.F_ProcessId
  470. WHERE
  471. t.F_IsFinished = 0 AND (p.F_IsFinished = 0 OR t.F_Type = 2 OR t.F_Type = 4 OR t.F_Type = 6)");
  472. var queryParam = queryJson.ToJObject();
  473. DateTime startTime = DateTime.Now, endTime = DateTime.Now;
  474. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  475. {
  476. startTime = queryParam["StartTime"].ToDate();
  477. endTime = queryParam["EndTime"].ToDate();
  478. strSql.Append(" AND ( t.F_ModifyDate >= @startTime AND t.F_ModifyDate <= @endTime ) ");
  479. }
  480. string keyword = "";
  481. if (!queryParam["keyword"].IsEmpty())
  482. {
  483. keyword = "%" + queryParam["keyword"].ToString() + "%";
  484. strSql.Append(" AND ( p.F_Title like @keyword OR p.F_SchemeName like @keyword ) ");
  485. }
  486. if (!string.IsNullOrEmpty(schemeCode))
  487. {
  488. strSql.Append(" AND p.F_SchemeCode = @schemeCode ");
  489. }
  490. if (isBatchAudit)
  491. {
  492. strSql.Append(" AND t.F_IsBatchAudit = 1 ");
  493. }
  494. return this.BaseRepository().FindList<NWFProcessEntity>(strSql.ToString(), new { userId, startTime, endTime, keyword, schemeCode });
  495. }
  496. catch (Exception ex)
  497. {
  498. if (ex is ExceptionEx)
  499. {
  500. throw;
  501. }
  502. else
  503. {
  504. throw ExceptionEx.ThrowServiceException(ex);
  505. }
  506. }
  507. }
  508. /// <summary>
  509. /// 获取我的已办任务列表
  510. /// </summary>
  511. /// <param name="userId">用户主键</param>
  512. /// <param name="pagination">翻页信息</param>
  513. /// <param name="queryJson">查询条件</param>
  514. /// <param name="schemeCode">流程模板编码</param>
  515. /// <returns></returns>
  516. public IEnumerable<NWFProcessEntity> GetMyFinishTaskPageList(UserInfo userInfo, Pagination pagination, string queryJson, string schemeCode)
  517. {
  518. try
  519. {
  520. var strSql = new StringBuilder();
  521. strSql.Append(@"SELECT
  522. t.F_Id AS F_TaskId,
  523. t.F_Type AS F_TaskType,
  524. t.F_NodeName AS F_TaskName,
  525. r.F_Time as F_CreateDate,
  526. p.F_Id,
  527. p.F_SchemeId,
  528. p.F_SchemeCode,
  529. p.F_SchemeName,
  530. p.F_Title,
  531. p.F_Level,
  532. p.F_EnabledMark,
  533. p.F_IsAgain,
  534. p.F_IsFinished,
  535. p.F_IsChild,
  536. p.F_ParentTaskId,
  537. p.F_ParentProcessId,
  538. p.F_CreateUserId,
  539. p.F_CreateUserName,
  540. p.F_IsStart,
  541. t.F_NodeId
  542. FROM
  543. LR_NWF_Task t
  544. LEFT JOIN LR_NWF_TaskRelation r on r.F_TaskId = t.F_Id
  545. LEFT JOIN LR_NWF_Process p ON t.F_ProcessId = p.F_Id
  546. WHERE
  547. (r.F_Result = 1 OR r.F_Result = 2 OR r.F_Result = 4) AND r.F_UserId = @userId
  548. ");
  549. var queryParam = queryJson.ToJObject();
  550. DateTime startTime = DateTime.Now, endTime = DateTime.Now;
  551. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  552. {
  553. startTime = queryParam["StartTime"].ToDate();
  554. endTime = queryParam["EndTime"].ToDate();
  555. strSql.Append(" AND ( r.F_Time >= @startTime AND r.F_Time <= @endTime ) ");
  556. }
  557. string keyword = "";
  558. if (!queryParam["keyword"].IsEmpty())
  559. {
  560. keyword = "%" + queryParam["keyword"].ToString() + "%";
  561. strSql.Append(" AND ( p.F_ProcessName like @keyword OR p.F_SchemeName like @keyword ) ");
  562. }
  563. if (!string.IsNullOrEmpty(schemeCode))
  564. {
  565. strSql.Append(" AND p.F_SchemeCode = @schemeCode ");
  566. }
  567. var data = this.BaseRepository().FindList<NWFProcessEntity>(strSql.ToString(), new { userInfo.userId, startTime, endTime, keyword, schemeCode }, pagination);
  568. foreach (var item in data)
  569. {
  570. var nextNode = this.BaseRepository().FindEntity<NWFTaskLogEntity>(a =>
  571. a.F_ProcessId == item.F_Id && a.F_PrevNodeId == item.F_NodeId);
  572. if (null != nextNode)
  573. {
  574. item.NextNodeIsAudited = true;
  575. }
  576. }
  577. return data;
  578. }
  579. catch (Exception ex)
  580. {
  581. if (ex is ExceptionEx)
  582. {
  583. throw;
  584. }
  585. else
  586. {
  587. throw ExceptionEx.ThrowServiceException(ex);
  588. }
  589. }
  590. }
  591. /// <summary>
  592. /// 获取我的已办任务列表
  593. /// </summary>
  594. /// <param name="userId">用户主键</param>
  595. /// <param name="queryJson">查询条件</param>
  596. /// <param name="schemeCode">流程模板编码</param>
  597. /// <returns></returns>
  598. public IEnumerable<NWFProcessEntity> GetMyFinishTaskPageList(UserInfo userInfo, string queryJson, string schemeCode)
  599. {
  600. try
  601. {
  602. var strSql = new StringBuilder();
  603. strSql.Append(@"SELECT
  604. t.F_Id AS F_TaskId,
  605. t.F_Type AS F_TaskType,
  606. t.F_NodeName AS F_TaskName,
  607. r.F_Time as F_CreateDate,
  608. p.F_Id,
  609. p.F_SchemeId,
  610. p.F_SchemeCode,
  611. p.F_SchemeName,
  612. p.F_Title,
  613. p.F_Level,
  614. p.F_EnabledMark,
  615. p.F_IsAgain,
  616. p.F_IsFinished,
  617. p.F_IsChild,
  618. p.F_ParentTaskId,
  619. p.F_ParentProcessId,
  620. p.F_CreateUserId,
  621. p.F_CreateUserName,
  622. p.F_IsStart
  623. FROM
  624. LR_NWF_Task t
  625. LEFT JOIN LR_NWF_TaskRelation r on r.F_TaskId = t.F_Id
  626. LEFT JOIN LR_NWF_Process p ON t.F_ProcessId = p.F_Id
  627. WHERE
  628. (r.F_Result = 1 OR r.F_Result = 2 OR r.F_Result = 4) AND r.F_UserId = @userId
  629. ");
  630. var queryParam = queryJson.ToJObject();
  631. DateTime startTime = DateTime.Now, endTime = DateTime.Now;
  632. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  633. {
  634. startTime = queryParam["StartTime"].ToDate();
  635. endTime = queryParam["EndTime"].ToDate();
  636. strSql.Append(" AND ( r.F_Time >= @startTime AND r.F_Time <= @endTime ) ");
  637. }
  638. string keyword = "";
  639. if (!queryParam["keyword"].IsEmpty())
  640. {
  641. keyword = "%" + queryParam["keyword"].ToString() + "%";
  642. strSql.Append(" AND ( p.F_ProcessName like @keyword OR p.F_SchemeName like @keyword ) ");
  643. }
  644. if (!string.IsNullOrEmpty(schemeCode))
  645. {
  646. strSql.Append(" AND p.F_SchemeCode = @schemeCode ");
  647. }
  648. return this.BaseRepository().FindList<NWFProcessEntity>(strSql.ToString(), new { userInfo.userId, startTime, endTime, keyword, schemeCode });
  649. }
  650. catch (Exception ex)
  651. {
  652. if (ex is ExceptionEx)
  653. {
  654. throw;
  655. }
  656. else
  657. {
  658. throw ExceptionEx.ThrowServiceException(ex);
  659. }
  660. }
  661. }
  662. /// <summary>
  663. /// 获取委托人关联的流程进程列表
  664. /// </summary>
  665. /// <param name="userId">当前用户主键</param>
  666. /// <returns></returns>
  667. public List<UserInfo> GetDelegateProcess(string userId)
  668. {
  669. try
  670. {
  671. List<UserInfo> delegateUserlist = new List<UserInfo>();
  672. DateTime datatime = DateTime.Now;
  673. IEnumerable<NWFDelegateRuleEntity> wfDelegateRuleList = this.BaseRepository().FindList<NWFDelegateRuleEntity>(t => t.F_ToUserId == userId && t.F_BeginDate <= datatime && t.F_EndDate >= datatime);
  674. foreach (var item in wfDelegateRuleList)
  675. {
  676. UserInfo userinfo = new UserInfo();
  677. userinfo.userId = item.F_CreateUserId;
  678. var strSql = new StringBuilder();
  679. strSql.Append(@"SELECT
  680. p.F_Id
  681. FROM
  682. LR_NWF_DelegateRelation d
  683. LEFT JOIN LR_NWF_SchemeInfo s ON s.F_Id = d.F_SchemeInfoId
  684. LEFT JOIN LR_NWF_Process p ON p.F_SchemeCode = s.F_Code
  685. WHERE
  686. p.F_Id IS NOT NULL
  687. AND p.F_IsFinished = 0
  688. AND d.F_DelegateRuleId = @DelegateRuleId ");
  689. DataTable dt = this.BaseRepository().FindTable(strSql.ToString(), new { DelegateRuleId = item.F_Id });
  690. userinfo.wfProcessId = "";
  691. foreach (DataRow dr in dt.Rows)
  692. {
  693. if (!string.IsNullOrEmpty(dr[0].ToString()))
  694. {
  695. if (!string.IsNullOrEmpty(userinfo.wfProcessId))
  696. {
  697. userinfo.wfProcessId += ",";
  698. }
  699. userinfo.wfProcessId += dr[0].ToString();
  700. }
  701. }
  702. if (!string.IsNullOrEmpty(userinfo.wfProcessId))
  703. {
  704. delegateUserlist.Add(userinfo);
  705. }
  706. }
  707. return delegateUserlist;
  708. }
  709. catch (Exception ex)
  710. {
  711. if (ex is ExceptionEx)
  712. {
  713. throw;
  714. }
  715. else
  716. {
  717. throw ExceptionEx.ThrowServiceException(ex);
  718. }
  719. }
  720. }
  721. #region 获取sql语句
  722. /// <summary>
  723. /// 获取我的流程信息列表SQL语句
  724. /// </summary>
  725. /// <returns></returns>
  726. public string GetMySql()
  727. {
  728. try
  729. {
  730. var strSql = new StringBuilder();
  731. strSql.Append(@"SELECT
  732. p.F_CreateDate,
  733. p.F_Id,
  734. p.F_SchemeId,
  735. p.F_SchemeCode,
  736. p.F_SchemeName,
  737. p.F_Title,
  738. p.F_Level,
  739. p.F_EnabledMark,
  740. p.F_IsAgain,
  741. p.F_IsFinished,
  742. p.F_IsChild,
  743. p.F_ParentTaskId,
  744. p.F_ParentProcessId,
  745. p.F_CreateUserId,
  746. p.F_CreateUserName,
  747. p.F_IsStart
  748. FROM
  749. LR_NWF_Process p
  750. WHERE
  751. p.F_CreateUserId = @userId AND p.F_IsChild = 0
  752. ");
  753. return strSql.ToString();
  754. }
  755. catch (Exception ex)
  756. {
  757. if (ex is ExceptionEx)
  758. {
  759. throw;
  760. }
  761. else
  762. {
  763. throw ExceptionEx.ThrowServiceException(ex);
  764. }
  765. }
  766. }
  767. /// <summary>
  768. /// 获取我的代办任务列表SQL语句
  769. /// </summary>
  770. /// <param name="userInfo">用户信息</param>
  771. /// <param name="isBatchAudit">true获取批量审核任务</param>
  772. /// <returns></returns>
  773. public string GetMyTaskSql(UserInfo userInfo, bool isBatchAudit = false)
  774. {
  775. try
  776. {
  777. var strSql = new StringBuilder();
  778. strSql.Append(@"SELECT
  779. t.F_Id AS F_TaskId,
  780. t.F_Type AS F_TaskType,
  781. t.F_NodeName AS F_TaskName,
  782. t.F_IsUrge,
  783. t.F_ModifyDate as F_CreateDate,
  784. p.F_Id,
  785. p.F_SchemeId,
  786. p.F_SchemeCode,
  787. p.F_SchemeName,
  788. p.F_Title,
  789. p.F_Level,
  790. p.F_EnabledMark,
  791. p.F_IsAgain,
  792. p.F_IsFinished,
  793. p.F_IsChild,
  794. p.F_ParentTaskId,
  795. p.F_ParentProcessId,
  796. p.F_CreateUserId,
  797. p.F_CreateUserName,
  798. p.F_IsStart
  799. FROM
  800. (
  801. SELECT
  802. F_TaskId
  803. FROM
  804. LR_NWF_TaskRelation r1
  805. LEFT JOIN LR_NWF_Task t1 ON r1.F_TaskId = t1.F_Id
  806. WHERE r1.F_Mark = 0 AND r1.F_Result = 0 AND (r1.F_UserId = @userId
  807. ");
  808. // 添加委托信息
  809. List<UserInfo> delegateList = GetDelegateProcess(userInfo.userId);
  810. foreach (var item in delegateList)
  811. {
  812. string processId = "'" + item.wfProcessId.Replace(",", "','") + "'";
  813. string userI2 = "'" + item.userId + "'";
  814. strSql.Append(" OR (r1.F_UserId =" + userI2 + " AND t1.F_ProcessId in (" + processId + ") AND t1.F_Type != 2 )");
  815. }
  816. strSql.Append(@") GROUP BY
  817. F_TaskId
  818. ) r
  819. LEFT JOIN LR_NWF_Task t ON t.F_Id = r.F_TaskId
  820. LEFT JOIN LR_NWF_Process p ON p.F_Id = t.F_ProcessId
  821. WHERE
  822. t.F_IsFinished = 0 AND (p.F_IsFinished = 0 OR t.F_Type = 2)");
  823. if (isBatchAudit)
  824. {
  825. strSql.Append(" AND t.F_IsBatchAudit = 1 ");
  826. }
  827. return strSql.ToString();
  828. }
  829. catch (Exception ex)
  830. {
  831. if (ex is ExceptionEx)
  832. {
  833. throw;
  834. }
  835. else
  836. {
  837. throw ExceptionEx.ThrowServiceException(ex);
  838. }
  839. }
  840. }
  841. /// <summary>
  842. /// 获取我的已办任务列表SQL语句
  843. /// </summary>
  844. /// <returns></returns>
  845. public string GetMyFinishTaskSql()
  846. {
  847. try
  848. {
  849. var strSql = new StringBuilder();
  850. strSql.Append(@"SELECT
  851. t.F_Id AS F_TaskId,
  852. t.F_Type AS F_TaskType,
  853. t.F_NodeName AS F_TaskName,
  854. r.F_Time as F_CreateDate,
  855. p.F_Id,
  856. p.F_SchemeId,
  857. p.F_SchemeCode,
  858. p.F_SchemeName,
  859. p.F_Title,
  860. p.F_Level,
  861. p.F_EnabledMark,
  862. p.F_IsAgain,
  863. p.F_IsFinished,
  864. p.F_IsChild,
  865. p.F_ParentTaskId,
  866. p.F_ParentProcessId,
  867. p.F_CreateUserId,
  868. p.F_CreateUserName,
  869. p.F_IsStart
  870. FROM
  871. LR_NWF_Task t
  872. LEFT JOIN LR_NWF_TaskRelation r on r.F_TaskId = t.F_Id
  873. LEFT JOIN LR_NWF_Process p ON t.F_ProcessId = p.F_Id
  874. WHERE
  875. (r.F_Result = 1 OR r.F_Result = 2 OR r.F_Result = 4) AND r.F_UserId = @userId
  876. ");
  877. return strSql.ToString();
  878. }
  879. catch (Exception ex)
  880. {
  881. if (ex is ExceptionEx)
  882. {
  883. throw;
  884. }
  885. else
  886. {
  887. throw ExceptionEx.ThrowServiceException(ex);
  888. }
  889. }
  890. }
  891. #endregion
  892. #endregion
  893. #region 保存信息
  894. /// <summary>
  895. /// 保存流程进程数据
  896. /// </summary>
  897. /// <param name="nWFProcessEntity">流程进程</param>
  898. /// <param name="taskList">流程任务列表</param>
  899. /// <param name="taskMsgList">流程消息列表</param>
  900. /// <param name="taskLogEntity">任务日志</param>
  901. public void Save(NWFProcessEntity nWFProcessEntity, List<NWFTaskEntity> taskList, List<NWFTaskMsgEntity> taskMsgList, NWFTaskLogEntity taskLogEntity)
  902. {
  903. NWFProcessEntity nWFProcessEntityTmp = this.BaseRepository().FindEntity<NWFProcessEntity>(nWFProcessEntity.F_Id);
  904. var db = this.BaseRepository().BeginTrans();
  905. try
  906. {
  907. if (nWFProcessEntityTmp == null)
  908. {
  909. db.Insert(nWFProcessEntity);
  910. }
  911. else
  912. {
  913. db.Update(nWFProcessEntity);
  914. }
  915. foreach (var task in taskList)
  916. {
  917. task.F_ModifyDate = DateTime.Now;
  918. db.Insert(task);
  919. int num = 1;
  920. if (task.nWFUserInfoList != null)
  921. {
  922. foreach (var taskUser in task.nWFUserInfoList)
  923. {
  924. NWFTaskRelationEntity nWFTaskRelationEntity = new NWFTaskRelationEntity();
  925. nWFTaskRelationEntity.Create();
  926. nWFTaskRelationEntity.F_TaskId = task.F_Id;
  927. nWFTaskRelationEntity.F_UserId = taskUser.Id;
  928. nWFTaskRelationEntity.F_Mark = taskUser.Mark;
  929. nWFTaskRelationEntity.F_Result = 0;
  930. nWFTaskRelationEntity.F_Sort = num;
  931. db.Insert(nWFTaskRelationEntity);
  932. num++;
  933. }
  934. }
  935. }
  936. foreach (var taskMsg in taskMsgList)
  937. {
  938. db.Insert(taskMsg);
  939. }
  940. db.Insert(taskLogEntity);
  941. db.Commit();
  942. }
  943. catch (Exception ex)
  944. {
  945. db.Rollback();
  946. if (ex is ExceptionEx)
  947. {
  948. throw;
  949. }
  950. else
  951. {
  952. throw ExceptionEx.ThrowServiceException(ex);
  953. }
  954. }
  955. }
  956. /// <summary>
  957. /// 保存流程进程信息
  958. /// </summary>
  959. /// <param name="taskLogEntity">任务日志</param>
  960. /// <param name="taskRelationEntity">任务执行人状态更新</param>
  961. /// <param name="taskEntityUpdate">任务状态更新</param>
  962. /// <param name="processEntity">流程进程状态更新</param>
  963. /// <param name="confluenceList">会签信息</param>
  964. /// <param name="closeTaskList">会签需要关闭的任务</param>
  965. /// <param name="taskList">新的任务列表</param>
  966. /// <param name="taskMsgList">新的任务消息列表</param>
  967. public void Save(NWFTaskLogEntity taskLogEntity, NWFTaskRelationEntity taskRelationEntity, NWFTaskEntity taskEntityUpdate, NWFProcessEntity processEntity, List<NWFConfluenceEntity> confluenceList, List<NWFTaskEntity> closeTaskList, List<NWFTaskEntity> taskList, List<NWFTaskMsgEntity> taskMsgList, NWFProcessEntity pProcessEntity = null)
  968. {
  969. var db = this.BaseRepository().BeginTrans();
  970. try
  971. {
  972. db.Insert(taskLogEntity);
  973. if (taskRelationEntity != null)
  974. db.Update(taskRelationEntity);
  975. db.Update(taskEntityUpdate);
  976. if (processEntity != null)
  977. {
  978. db.Update(processEntity);
  979. }
  980. if (pProcessEntity != null)
  981. {
  982. db.Update(pProcessEntity);
  983. }
  984. if (confluenceList != null)
  985. {
  986. foreach (var item in confluenceList)
  987. {
  988. if (item.isClear)
  989. {
  990. string processId = item.F_ProcessId;
  991. string nodeId = item.F_NodeId;
  992. db.Delete<NWFConfluenceEntity>(t => t.F_ProcessId == processId && t.F_NodeId == nodeId);
  993. // 增加一条会签审核记录
  994. NWFTaskLogEntity nWFTaskLogEntity = new NWFTaskLogEntity()
  995. {
  996. F_ProcessId = processId,
  997. F_OperationCode = "confluence",
  998. F_OperationName = "会签" + (item.confluenceRes == 1 ? "通过" : "不通过"),
  999. F_NodeId = item.F_NodeId,
  1000. F_TaskType = 7
  1001. };
  1002. nWFTaskLogEntity.Create();
  1003. db.Insert(nWFTaskLogEntity);
  1004. }
  1005. else
  1006. {
  1007. db.Insert(item);
  1008. }
  1009. }
  1010. }
  1011. if (closeTaskList != null)
  1012. {
  1013. foreach (var item in closeTaskList)
  1014. {
  1015. db.Update(item);
  1016. }
  1017. }
  1018. foreach (var task in taskList)
  1019. {
  1020. task.F_ModifyDate = DateTime.Now;
  1021. db.Insert(task);
  1022. int num = 1;
  1023. if (task.nWFUserInfoList != null)
  1024. {
  1025. foreach (var taskUser in task.nWFUserInfoList)
  1026. {
  1027. NWFTaskRelationEntity nWFTaskRelationEntity = new NWFTaskRelationEntity();
  1028. nWFTaskRelationEntity.Create();
  1029. nWFTaskRelationEntity.F_TaskId = task.F_Id;
  1030. nWFTaskRelationEntity.F_UserId = taskUser.Id;
  1031. nWFTaskRelationEntity.F_Mark = taskUser.Mark;
  1032. nWFTaskRelationEntity.F_Result = 0;
  1033. nWFTaskRelationEntity.F_Sort = num;
  1034. db.Insert(nWFTaskRelationEntity);
  1035. num++;
  1036. }
  1037. }
  1038. }
  1039. foreach (var taskMsg in taskMsgList)
  1040. {
  1041. db.Insert(taskMsg);
  1042. }
  1043. db.Commit();
  1044. }
  1045. catch (Exception ex)
  1046. {
  1047. db.Rollback();
  1048. if (ex is ExceptionEx)
  1049. {
  1050. throw;
  1051. }
  1052. else
  1053. {
  1054. throw ExceptionEx.ThrowServiceException(ex);
  1055. }
  1056. }
  1057. }
  1058. /// <summary>
  1059. /// 保存流程进程数据
  1060. /// </summary>
  1061. /// <param name="nWFProcessEntity">流程进程</param>
  1062. public void Save(NWFProcessEntity nWFProcessEntity)
  1063. {
  1064. try
  1065. {
  1066. this.BaseRepository().Insert(nWFProcessEntity);
  1067. }
  1068. catch (Exception ex)
  1069. {
  1070. if (ex is ExceptionEx)
  1071. {
  1072. throw;
  1073. }
  1074. else
  1075. {
  1076. throw ExceptionEx.ThrowServiceException(ex);
  1077. }
  1078. }
  1079. }
  1080. /// <summary>
  1081. /// 保存流程进程数据
  1082. /// </summary>
  1083. /// <param name="nWFTaskLogEntity">任务日志数据</param>
  1084. /// <param name="taskUserUpdateList">任务执行人需要更新状态数据</param>
  1085. /// <param name="nWFTaskMsgEntity">任务消息</param>
  1086. public void Save(NWFTaskLogEntity nWFTaskLogEntity, List<NWFTaskRelationEntity> taskUserUpdateList, NWFTaskMsgEntity nWFTaskMsgEntity)
  1087. {
  1088. var db = this.BaseRepository().BeginTrans();
  1089. try
  1090. {
  1091. db.Insert(nWFTaskLogEntity);
  1092. foreach (var item in taskUserUpdateList)
  1093. {
  1094. db.Update(item);
  1095. }
  1096. db.Insert(nWFTaskMsgEntity);
  1097. db.Commit();
  1098. }
  1099. catch (Exception ex)
  1100. {
  1101. db.Rollback();
  1102. if (ex is ExceptionEx)
  1103. {
  1104. throw;
  1105. }
  1106. else
  1107. {
  1108. throw ExceptionEx.ThrowServiceException(ex);
  1109. }
  1110. }
  1111. }
  1112. /// <summary>
  1113. /// 保存流程进程数据
  1114. /// </summary>
  1115. /// <param name="nWFTaskLogEntity">任务日志数据</param>
  1116. /// <param name="nWFTaskRelationEntity">任务执行人需要更新状态数据</param>
  1117. /// <param name="taskEntity">任务</param>
  1118. public void Save(NWFTaskLogEntity nWFTaskLogEntity, NWFTaskRelationEntity nWFTaskRelationEntity, NWFTaskEntity taskEntity)
  1119. {
  1120. var db = this.BaseRepository().BeginTrans();
  1121. try
  1122. {
  1123. db.Insert(nWFTaskLogEntity);
  1124. db.Update(nWFTaskRelationEntity);
  1125. if (taskEntity != null)
  1126. {
  1127. taskEntity.F_ModifyDate = DateTime.Now;
  1128. db.Update(taskEntity);
  1129. }
  1130. db.Commit();
  1131. }
  1132. catch (Exception ex)
  1133. {
  1134. db.Rollback();
  1135. if (ex is ExceptionEx)
  1136. {
  1137. throw;
  1138. }
  1139. else
  1140. {
  1141. throw ExceptionEx.ThrowServiceException(ex);
  1142. }
  1143. }
  1144. }
  1145. /// <summary>
  1146. /// 保存流程进程数据
  1147. /// </summary>
  1148. /// <param name="nWFTaskLogEntity">任务日志数据</param>
  1149. /// <param name="taskList">需要更新的任务列表</param>
  1150. /// <param name="taskMsgList">任务消息列表</param>
  1151. public void Save(NWFTaskLogEntity nWFTaskLogEntity, List<NWFTaskEntity> taskList, List<NWFTaskMsgEntity> taskMsgList)
  1152. {
  1153. var db = this.BaseRepository().BeginTrans();
  1154. try
  1155. {
  1156. db.Insert(nWFTaskLogEntity);
  1157. foreach (var item in taskList)
  1158. {
  1159. item.F_ModifyDate = DateTime.Now;
  1160. db.Update(item);
  1161. }
  1162. foreach (var item in taskMsgList)
  1163. {
  1164. db.Insert(item);
  1165. }
  1166. db.Commit();
  1167. }
  1168. catch (Exception ex)
  1169. {
  1170. db.Rollback();
  1171. if (ex is ExceptionEx)
  1172. {
  1173. throw;
  1174. }
  1175. else
  1176. {
  1177. throw ExceptionEx.ThrowServiceException(ex);
  1178. }
  1179. }
  1180. }
  1181. /// <summary>
  1182. /// 保存流程进程数据
  1183. /// </summary>
  1184. /// <param name="nWFTaskLogEntity">任务日志数据</param>
  1185. /// <param name="taskList">需要更新的任务列表</param>
  1186. /// <param name="taskMsgList">任务消息列表</param>
  1187. public void Save(NWFTaskLogEntity nWFTaskLogEntity, NWFTaskEntity task, List<NWFTaskMsgEntity> taskMsgList)
  1188. {
  1189. var db = this.BaseRepository().BeginTrans();
  1190. try
  1191. {
  1192. db.Insert(nWFTaskLogEntity);
  1193. task.F_ModifyDate = DateTime.Now;
  1194. db.Update(task);
  1195. foreach (var item in taskMsgList)
  1196. {
  1197. db.Insert(item);
  1198. }
  1199. db.Commit();
  1200. }
  1201. catch (Exception ex)
  1202. {
  1203. db.Rollback();
  1204. if (ex is ExceptionEx)
  1205. {
  1206. throw;
  1207. }
  1208. else
  1209. {
  1210. throw ExceptionEx.ThrowServiceException(ex);
  1211. }
  1212. }
  1213. }
  1214. /// <summary>
  1215. /// 保存流程进程信息
  1216. /// </summary>
  1217. /// <param name="taskLogEntity">任务日志</param>
  1218. /// <param name="taskRelationEntity">任务执行人状态更新</param>
  1219. /// <param name="taskEntityUpdate">任务状态更新</param>
  1220. /// <param name="processEntity">流程进程状态更新</param>
  1221. /// <param name="taskList">新的任务列表</param>
  1222. /// <param name="taskMsgList">新的任务消息列表</param>
  1223. public void Save(NWFTaskLogEntity pTaskLogEntity, NWFTaskRelationEntity pTaskRelationEntity, NWFTaskEntity pTaskEntityUpdate, NWFProcessEntity pProcessEntity, List<NWFTaskEntity> pTaskList, List<NWFTaskMsgEntity> pTaskMsgList, NWFProcessEntity nWFProcessEntity, List<NWFTaskEntity> taskList, List<NWFTaskMsgEntity> taskMsgList, NWFTaskLogEntity taskLogEntity)
  1224. {
  1225. NWFProcessEntity nWFProcessEntityTmp = this.BaseRepository().FindEntity<NWFProcessEntity>(nWFProcessEntity.F_Id);
  1226. IEnumerable<NWFTaskEntity> uTaskList = this.BaseRepository().FindList<NWFTaskEntity>(t => t.F_ProcessId == nWFProcessEntity.F_Id && t.F_NodeId == taskLogEntity.F_NodeId && t.F_IsFinished == 0);
  1227. var db = this.BaseRepository().BeginTrans();
  1228. try
  1229. {
  1230. if (nWFProcessEntityTmp == null)
  1231. {
  1232. db.Insert(nWFProcessEntity);
  1233. }
  1234. else
  1235. {
  1236. db.Update(nWFProcessEntity);
  1237. }
  1238. foreach (var task in taskList)
  1239. {
  1240. task.F_ModifyDate = DateTime.Now;
  1241. db.Insert(task);
  1242. int num = 1;
  1243. if (task.nWFUserInfoList != null)
  1244. {
  1245. foreach (var taskUser in task.nWFUserInfoList)
  1246. {
  1247. NWFTaskRelationEntity nWFTaskRelationEntity = new NWFTaskRelationEntity();
  1248. nWFTaskRelationEntity.Create();
  1249. nWFTaskRelationEntity.F_TaskId = task.F_Id;
  1250. nWFTaskRelationEntity.F_UserId = taskUser.Id;
  1251. nWFTaskRelationEntity.F_Mark = taskUser.Mark;
  1252. nWFTaskRelationEntity.F_Result = 0;
  1253. nWFTaskRelationEntity.F_Sort = num;
  1254. db.Insert(nWFTaskRelationEntity);
  1255. num++;
  1256. }
  1257. }
  1258. }
  1259. foreach (var taskMsg in taskMsgList)
  1260. {
  1261. db.Insert(taskMsg);
  1262. }
  1263. db.Insert(taskLogEntity);
  1264. foreach (var item in uTaskList)
  1265. {
  1266. item.F_IsFinished = 1;
  1267. db.Update(item);
  1268. }
  1269. // 父流程
  1270. db.Insert(pTaskLogEntity);
  1271. db.Update(pTaskRelationEntity);
  1272. db.Update(pTaskEntityUpdate);
  1273. if (pProcessEntity != null)
  1274. {
  1275. db.Update(pProcessEntity);
  1276. }
  1277. foreach (var task in pTaskList)
  1278. {
  1279. task.F_ModifyDate = DateTime.Now;
  1280. db.Insert(task);
  1281. int num = 1;
  1282. if (task.nWFUserInfoList != null)
  1283. {
  1284. foreach (var taskUser in task.nWFUserInfoList)
  1285. {
  1286. NWFTaskRelationEntity nWFTaskRelationEntity = new NWFTaskRelationEntity();
  1287. nWFTaskRelationEntity.Create();
  1288. nWFTaskRelationEntity.F_TaskId = task.F_Id;
  1289. nWFTaskRelationEntity.F_UserId = taskUser.Id;
  1290. nWFTaskRelationEntity.F_Mark = taskUser.Mark;
  1291. nWFTaskRelationEntity.F_Result = 0;
  1292. nWFTaskRelationEntity.F_Sort = num;
  1293. db.Insert(nWFTaskRelationEntity);
  1294. num++;
  1295. }
  1296. }
  1297. }
  1298. foreach (var taskMsg in pTaskMsgList)
  1299. {
  1300. db.Insert(taskMsg);
  1301. }
  1302. db.Commit();
  1303. }
  1304. catch (Exception ex)
  1305. {
  1306. db.Rollback();
  1307. if (ex is ExceptionEx)
  1308. {
  1309. throw;
  1310. }
  1311. else
  1312. {
  1313. throw ExceptionEx.ThrowServiceException(ex);
  1314. }
  1315. }
  1316. }
  1317. /// <summary>
  1318. /// (流程撤销)
  1319. /// </summary>
  1320. /// <param name="processId">流程进程实例</param>
  1321. /// <param name="taskList">流程任务列表</param>
  1322. /// <param name="EnabledMark">2草稿3作废</param>
  1323. public void Save(string processId, IEnumerable<NWFTaskEntity> taskList, int EnabledMark, NWFTaskLogEntity nWFTaskLogEntity = null)
  1324. {
  1325. var db = this.BaseRepository().BeginTrans();
  1326. try
  1327. {
  1328. NWFProcessEntity nWFProcessEntity = new NWFProcessEntity();
  1329. nWFProcessEntity.F_Id = processId;
  1330. nWFProcessEntity.F_EnabledMark = EnabledMark;
  1331. db.Update(nWFProcessEntity);
  1332. if (EnabledMark == 2)
  1333. {
  1334. db.Delete<NWFTaskLogEntity>(t => t.F_ProcessId == processId);
  1335. }
  1336. foreach (var task in taskList)
  1337. {
  1338. db.Delete(task);
  1339. string taskId = task.F_Id;
  1340. db.Delete<NWFTaskMsgEntity>(t => t.F_TaskId == taskId);
  1341. db.Delete<NWFTaskRelationEntity>(t => t.F_TaskId == taskId);
  1342. }
  1343. if (nWFTaskLogEntity != null)
  1344. {
  1345. db.Insert(nWFTaskLogEntity);
  1346. }
  1347. db.Commit();
  1348. }
  1349. catch (Exception ex)
  1350. {
  1351. db.Rollback();
  1352. if (ex is ExceptionEx)
  1353. {
  1354. throw;
  1355. }
  1356. else
  1357. {
  1358. throw ExceptionEx.ThrowServiceException(ex);
  1359. }
  1360. }
  1361. }
  1362. /// <summary>
  1363. /// 删除流程进程实体
  1364. /// </summary>
  1365. /// <param name="processId">流程进程主键</param>
  1366. public void DeleteEntity(string processId)
  1367. {
  1368. try
  1369. {
  1370. this.BaseRepository().Delete<NWFProcessEntity>(t => t.F_Id == processId);
  1371. }
  1372. catch (Exception ex)
  1373. {
  1374. if (ex is ExceptionEx)
  1375. {
  1376. throw;
  1377. }
  1378. else
  1379. {
  1380. throw ExceptionEx.ThrowServiceException(ex);
  1381. }
  1382. }
  1383. }
  1384. /// <summary>
  1385. ///
  1386. /// </summary>
  1387. /// <param name="processId"></param>
  1388. /// <param name="EnabledMark"></param>
  1389. public void UpdateEnabledMark(string processId, string EnabledMark)
  1390. {
  1391. try
  1392. {
  1393. var entity= this.BaseRepository().FindEntity<NWFProcessEntity>(t => t.F_Id == processId);
  1394. entity.F_EnabledMark =Convert.ToInt32(EnabledMark) ;
  1395. this.BaseRepository().Update(entity);
  1396. }
  1397. catch (Exception ex)
  1398. {
  1399. if (ex is ExceptionEx)
  1400. {
  1401. throw;
  1402. }
  1403. else
  1404. {
  1405. throw ExceptionEx.ThrowServiceException(ex);
  1406. }
  1407. }
  1408. }
  1409. /// <summary>
  1410. /// 删除流程进程所有信息(流程撤销)
  1411. /// </summary>
  1412. /// <param name="processId">流程进程实例</param>
  1413. /// <param name="taskList">流程任务列表</param>
  1414. public void Delete(string processId, IEnumerable<NWFTaskEntity> taskList)
  1415. {
  1416. var db = this.BaseRepository().BeginTrans();
  1417. try
  1418. {
  1419. db.Delete<NWFProcessEntity>(t => t.F_Id == processId);
  1420. db.Delete<NWFTaskLogEntity>(t => t.F_ProcessId == processId);
  1421. foreach (var task in taskList)
  1422. {
  1423. db.Delete(task);
  1424. string taskId = task.F_Id;
  1425. db.Delete<NWFTaskMsgEntity>(t => t.F_TaskId == taskId);
  1426. db.Delete<NWFTaskRelationEntity>(t => t.F_TaskId == taskId);
  1427. }
  1428. db.Commit();
  1429. }
  1430. catch (Exception ex)
  1431. {
  1432. db.Rollback();
  1433. if (ex is ExceptionEx)
  1434. {
  1435. throw;
  1436. }
  1437. else
  1438. {
  1439. throw ExceptionEx.ThrowServiceException(ex);
  1440. }
  1441. }
  1442. }
  1443. /// <summary>
  1444. /// 撤销审核
  1445. /// </summary>
  1446. /// <param name="taskList">需要撤回的任务节点</param>
  1447. /// <param name="taskUser">当前处理人</param>
  1448. /// <param name="taskEntity">当前任务</param>
  1449. /// <param name="taskLogEntity">日志信息</param>
  1450. /// <param name="taskUserNew">当前任务节点的处理人(串行多人审核)</param>
  1451. public void RevokeAudit(List<string> taskList, NWFTaskRelationEntity taskUser, NWFTaskEntity taskEntity, NWFTaskLogEntity taskLogEntity, NWFTaskRelationEntity taskUserNew = null)
  1452. {
  1453. var db = this.BaseRepository().BeginTrans();
  1454. try
  1455. {
  1456. if (taskList != null)
  1457. {
  1458. foreach (var taskId in taskList)
  1459. {
  1460. db.Delete<NWFTaskEntity>(t => t.F_Id == taskId);
  1461. db.Delete<NWFTaskRelationEntity>(t => t.F_TaskId == taskId);
  1462. db.Delete<NWFTaskMsgEntity>(t => t.F_TaskId == taskId);
  1463. }
  1464. }
  1465. if (taskEntity != null)
  1466. {
  1467. db.Update(taskEntity);
  1468. }
  1469. taskUser.F_Mark = 0;
  1470. taskUser.F_Result = 0;
  1471. db.Update(taskUser);
  1472. db.Insert(taskLogEntity);
  1473. if (taskUserNew != null)
  1474. {
  1475. taskUserNew.F_Mark = 1;
  1476. taskUserNew.F_Result = 0;
  1477. db.Update(taskUserNew);
  1478. }
  1479. // 更新下流程实例(处理重新发起状态)
  1480. NWFProcessEntity nWFProcessEntity = new NWFProcessEntity();
  1481. nWFProcessEntity.F_Id = taskLogEntity.F_ProcessId;
  1482. nWFProcessEntity.F_IsAgain = 0;
  1483. db.Update(nWFProcessEntity);
  1484. db.Commit();
  1485. }
  1486. catch (Exception ex)
  1487. {
  1488. db.Rollback();
  1489. if (ex is ExceptionEx)
  1490. {
  1491. throw;
  1492. }
  1493. else
  1494. {
  1495. throw ExceptionEx.ThrowServiceException(ex);
  1496. }
  1497. }
  1498. }
  1499. /// <summary>
  1500. /// 保存任务
  1501. /// </summary>
  1502. /// <param name="taskList">任务列表</param>
  1503. public void SaveTask(List<NWFTaskEntity> taskList)
  1504. {
  1505. var db = this.BaseRepository().BeginTrans();
  1506. try
  1507. {
  1508. foreach (var task in taskList)
  1509. {
  1510. task.F_ModifyDate = DateTime.Now;
  1511. db.Insert(task);
  1512. int num = 1;
  1513. if (task.nWFUserInfoList != null)
  1514. {
  1515. foreach (var taskUser in task.nWFUserInfoList)
  1516. {
  1517. NWFTaskRelationEntity nWFTaskRelationEntity = new NWFTaskRelationEntity();
  1518. nWFTaskRelationEntity.Create();
  1519. nWFTaskRelationEntity.F_TaskId = task.F_Id;
  1520. nWFTaskRelationEntity.F_UserId = taskUser.Id;
  1521. nWFTaskRelationEntity.F_Mark = taskUser.Mark;
  1522. nWFTaskRelationEntity.F_Result = 0;
  1523. nWFTaskRelationEntity.F_Sort = num;
  1524. db.Insert(nWFTaskRelationEntity);
  1525. num++;
  1526. }
  1527. }
  1528. }
  1529. db.Commit();
  1530. }
  1531. catch (Exception)
  1532. {
  1533. db.Rollback();
  1534. throw;
  1535. }
  1536. }
  1537. #endregion
  1538. }
  1539. }