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.
 
 
 
 
 
 

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