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.
 
 
 
 
 
 

709 line
30 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Learun.Application.Base.AuthorizeModule;
  11. using Learun.Application.Organization;
  12. using Learun.Application.TwoDevelopment.LR_Desktop;
  13. using Microsoft.AspNet.SignalR.Client;
  14. using Newtonsoft.Json;
  15. using Learun.Application.TwoDevelopment.EducationalAdministration;
  16. namespace Learun.Application.WorkFlow
  17. {
  18. /// <summary>
  19. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  20. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  21. /// 创建人:陈彬彬
  22. /// 日 期:2017.04.17
  23. /// 描 述:任务实例
  24. /// </summary>
  25. public class WfTaskService : RepositoryFactory
  26. {
  27. #region 获取数据
  28. /// <summary>
  29. /// 获取未完成的流程实例任务列表
  30. /// </summary>
  31. /// <param name="processId">流程实例主键</param>
  32. /// <returns></returns>
  33. public IEnumerable<WfTaskEntity> GetList(string processId)
  34. {
  35. try
  36. {
  37. return this.BaseRepository().FindList<WfTaskEntity>(t => t.F_ProcessId == processId && t.F_IsFinished == 0);
  38. }
  39. catch (Exception ex)
  40. {
  41. if (ex is ExceptionEx)
  42. {
  43. throw;
  44. }
  45. else
  46. {
  47. throw ExceptionEx.ThrowServiceException(ex);
  48. }
  49. }
  50. }
  51. /// <summary>
  52. /// 获取当前任务节点主键
  53. /// </summary>
  54. /// <param name="processId">流程实例主键</param>
  55. /// <returns></returns>
  56. public List<string> GetCurrentNodeIds(string processId)
  57. {
  58. try
  59. {
  60. var strSql = new StringBuilder();
  61. strSql.Append(@"SELECT
  62. t.F_NodeId
  63. FROM
  64. LR_WF_Task t
  65. WHERE
  66. t.F_IsFinished = 0 AND t.F_ProcessId = @processId
  67. GROUP BY
  68. t.F_ProcessId,
  69. t.F_NodeId
  70. ");
  71. var taskList = this.BaseRepository().FindList<WfTaskEntity>(strSql.ToString(), new { processId = processId });
  72. List<string> list = new List<string>();
  73. foreach (var item in taskList)
  74. {
  75. list.Add(item.F_NodeId);
  76. }
  77. return list;
  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="keyValue">主键</param>
  95. /// <returns></returns>
  96. public WfTaskEntity GetEntity(string keyValue)
  97. {
  98. try
  99. {
  100. return this.BaseRepository().FindEntity<WfTaskEntity>(t => t.F_Id == keyValue);
  101. }
  102. catch (Exception ex)
  103. {
  104. if (ex is ExceptionEx)
  105. {
  106. throw;
  107. }
  108. else
  109. {
  110. throw ExceptionEx.ThrowServiceException(ex);
  111. }
  112. }
  113. }
  114. /// <summary>
  115. /// 获取任务实体
  116. /// </summary>
  117. /// <param name="processId">流程实例主键</param>
  118. /// <param name="nodeId">节点主键</param>
  119. /// <returns></returns>
  120. public WfTaskEntity GetEntityUnFinish(string processId, string nodeId)
  121. {
  122. try
  123. {
  124. return this.BaseRepository().FindEntity<WfTaskEntity>(t => t.F_ProcessId == processId && t.F_NodeId == nodeId && t.F_IsFinished == 0);
  125. }
  126. catch (Exception ex)
  127. {
  128. if (ex is ExceptionEx)
  129. {
  130. throw;
  131. }
  132. else
  133. {
  134. throw ExceptionEx.ThrowServiceException(ex);
  135. }
  136. }
  137. }
  138. /// <summary>
  139. /// 获取任务实体
  140. /// </summary>
  141. /// <param name="processId">流程实例主键</param>
  142. /// <param name="nodeId">节点主键</param>
  143. /// <returns></returns>
  144. public WfTaskEntity GetEntity(string processId, string nodeId)
  145. {
  146. try
  147. {
  148. return this.BaseRepository().FindEntity<WfTaskEntity>(t => t.F_ProcessId == processId && t.F_NodeId == nodeId);
  149. }
  150. catch (Exception ex)
  151. {
  152. if (ex is ExceptionEx)
  153. {
  154. throw;
  155. }
  156. else
  157. {
  158. throw ExceptionEx.ThrowServiceException(ex);
  159. }
  160. }
  161. }
  162. /// <summary>
  163. /// 获取未处理任务列表
  164. /// </summary>
  165. /// <param name="userInfo">用户信息</param>
  166. /// <param name="pagination">翻页信息</param>
  167. /// <param name="queryJson">查询条件</param>
  168. /// <returns></returns>
  169. public IEnumerable<WfProcessInstanceEntity> GetActiveList(UserInfo userInfo, Pagination pagination, string queryJson, List<UserInfo> delegateList)
  170. {
  171. try
  172. {
  173. string userId = userInfo.userId;
  174. string postIds = "'" + userInfo.postIds?.Replace(",", "','") + "'";
  175. string roleIds = "'" + userInfo.roleIds?.Replace(",", "','") + "'";
  176. string companyId = userInfo.companyId;
  177. string departmentId = userInfo.departmentId;
  178. // 获取委托信息
  179. var strSql = new StringBuilder();
  180. strSql.Append(@"SELECT
  181. a.F_TaskId,
  182. a.F_TaskType,
  183. a.F_TaskName,
  184. p.F_Id,
  185. p.F_SchemeId,
  186. p.F_SchemeCode,
  187. p.F_SchemeName,
  188. p.F_ProcessName,
  189. p.F_ProcessLevel,
  190. p.F_EnabledMark,
  191. p.F_IsFinished,
  192. p.F_IsAgain,
  193. p.F_Description,
  194. p.F_CreateDate,
  195. p.F_CreateUserId,
  196. p.F_CreateUserName,
  197. p.F_CompanyId,
  198. p.F_DepartmentId,
  199. p.F_IsChildFlow,
  200. p.F_ProcessParentId
  201. FROM
  202. (
  203. SELECT
  204. MAX(t.F_Id) AS F_TaskId,
  205. MAX(t.F_TaskType) AS F_TaskType,
  206. t.F_ProcessId,
  207. t.F_NodeName AS F_TaskName
  208. FROM
  209. LR_WF_Task t WHERE t.F_IsFinished = 0 ");
  210. strSql.Append(" AND ( t.F_AuditorId = '1' OR ");
  211. strSql.Append(" t.F_AuditorId = @userId ");
  212. if (!string.IsNullOrEmpty(userInfo.postIds))
  213. {
  214. strSql.Append(" OR (t.F_AuditorId in (" + postIds + ") AND t.F_CompanyId = '1' AND t.F_DepartmentId = '1' ) ");
  215. strSql.Append(" OR (t.F_AuditorId in (" + postIds + ") AND t.F_CompanyId = @companyId ) ");
  216. strSql.Append(" OR (t.F_AuditorId in (" + postIds + ") AND t.F_DepartmentId = @departmentId ) ");
  217. }
  218. if (!string.IsNullOrEmpty(userInfo.roleIds))
  219. {
  220. strSql.Append(" OR (t.F_AuditorId in (" + roleIds + ") AND t.F_CompanyId = '1' AND t.F_DepartmentId = '1' ) ");
  221. strSql.Append(" OR (t.F_AuditorId in (" + roleIds + ") AND t.F_CompanyId = @companyId ) ");
  222. strSql.Append(" OR (t.F_AuditorId in (" + roleIds + ") AND t.F_DepartmentId = @departmentId) ");
  223. }
  224. // 添加委托信息
  225. foreach (var item in delegateList)
  226. {
  227. string processId = "'" + item.wfProcessId.Replace(",", "','") + "'";
  228. string postIds2 = "'" + item.postIds?.Replace(",", "','") + "'";
  229. string roleIds2 = "'" + item.roleIds?.Replace(",", "','") + "'";
  230. string userI2 = "'" + item.userId + "'";
  231. string companyId2 = "'" + item.companyId + "'";
  232. string departmentId2 = "'" + item.departmentId + "'";
  233. strSql.Append(" OR (t.F_AuditorId =" + userI2 + " AND t.F_ProcessId in (" + processId + ") )");
  234. if (!string.IsNullOrEmpty(item.postIds))
  235. {
  236. strSql.Append(" OR (t.F_AuditorId in (" + postIds2 + ") AND t.F_CompanyId = '1' AND t.F_DepartmentId = '1' AND t.F_ProcessId in (" + processId + ") ) ");
  237. strSql.Append(" OR (t.F_AuditorId in (" + postIds2 + ") AND t.F_CompanyId = " + companyId2 + " AND t.F_ProcessId in (" + processId + ") ) ");
  238. strSql.Append(" OR (t.F_AuditorId in (" + postIds2 + ") AND t.F_DepartmentId = " + departmentId2 + " AND t.F_ProcessId in (" + processId + ") ) ");
  239. }
  240. if (!string.IsNullOrEmpty(item.roleIds))
  241. {
  242. strSql.Append(" OR (t.F_AuditorId in (" + roleIds2 + ") AND t.F_CompanyId = '1' AND t.F_DepartmentId = '1' AND t.F_ProcessId in (" + processId + ") ) ");
  243. strSql.Append(" OR (t.F_AuditorId in (" + roleIds2 + ") AND t.F_CompanyId = " + companyId2 + " AND t.F_ProcessId in (" + processId + ") ) ");
  244. strSql.Append(" OR (t.F_AuditorId in (" + roleIds2 + ") AND t.F_DepartmentId = " + departmentId2 + " AND t.F_ProcessId in (" + processId + ") ) ");
  245. }
  246. }
  247. strSql.Append(@" ) GROUP BY
  248. t.F_ProcessId,
  249. t.F_NodeId,
  250. t.F_NodeName )a LEFT JOIN LR_WF_ProcessInstance p ON p.F_Id = a.F_ProcessId WHERE 1=1 AND (p.F_IsFinished = 0 OR a.F_TaskType = 3) AND p.F_EnabledMark = 1 ");
  251. var queryParam = queryJson.ToJObject();
  252. DateTime startTime = DateTime.Now, endTime = DateTime.Now;
  253. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  254. {
  255. startTime = queryParam["StartTime"].ToDate();
  256. endTime = queryParam["EndTime"].ToDate();
  257. strSql.Append(" AND ( p.F_CreateDate >= @startTime AND p.F_CreateDate <= @endTime ) ");
  258. }
  259. string keyword = "";
  260. if (!queryParam["keyword"].IsEmpty())
  261. {
  262. keyword = "%" + queryParam["keyword"].ToString() + "%";
  263. strSql.Append(" AND ( p.F_ProcessName like @keyword OR p.F_SchemeName like @keyword ) ");
  264. }
  265. return this.BaseRepository().FindList<WfProcessInstanceEntity>(strSql.ToString(), new { userId, companyId, departmentId, startTime, endTime, keyword }, pagination);
  266. }
  267. catch (Exception ex)
  268. {
  269. if (ex is ExceptionEx)
  270. {
  271. throw;
  272. }
  273. else
  274. {
  275. throw ExceptionEx.ThrowServiceException(ex);
  276. }
  277. }
  278. }
  279. /// <summary>
  280. /// 获取已处理任务列表
  281. /// </summary>
  282. /// <param name="userId">用户主键</param>
  283. /// <param name="pagination">翻页信息</param>
  284. /// <param name="queryJson">查询条件</param>
  285. /// <returns></returns>
  286. public IEnumerable<WfProcessInstanceEntity> GetHasList(string userId, Pagination pagination, string queryJson)
  287. {
  288. try
  289. {
  290. var strSql = new StringBuilder();
  291. strSql.Append(@"SELECT
  292. t.F_Id AS F_TaskId,
  293. t.F_TaskType,
  294. t.F_NodeName AS F_TaskName,
  295. p.F_Id,
  296. p.F_SchemeId,
  297. p.F_SchemeCode,
  298. p.F_SchemeName,
  299. p.F_ProcessName,
  300. p.F_ProcessLevel,
  301. p.F_EnabledMark,
  302. p.F_IsFinished,
  303. p.F_IsAgain,
  304. p.F_Description,
  305. p.F_CreateDate,
  306. p.F_CreateUserId,
  307. p.F_CreateUserName,
  308. p.F_CompanyId,
  309. p.F_DepartmentId,
  310. p.F_IsChildFlow,
  311. p.F_ProcessParentId
  312. FROM
  313. LR_WF_Task t
  314. LEFT JOIN LR_WF_ProcessInstance p ON t.F_ProcessId = p.F_Id
  315. WHERE
  316. t.F_IsFinished = 1 AND t.F_ModifyUserId = @userId
  317. ");
  318. var queryParam = queryJson.ToJObject();
  319. DateTime startTime = DateTime.Now, endTime = DateTime.Now;
  320. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  321. {
  322. startTime = queryParam["StartTime"].ToDate();
  323. endTime = queryParam["EndTime"].ToDate();
  324. strSql.Append(" AND ( p.F_CreateDate >= @startTime AND p.F_CreateDate <= @endTime ) ");
  325. }
  326. string keyword = "";
  327. if (!queryParam["keyword"].IsEmpty())
  328. {
  329. keyword = "%" + queryParam["keyword"].ToString() + "%";
  330. strSql.Append(" AND ( p.F_ProcessName like @keyword OR p.F_SchemeName like @keyword ) ");
  331. }
  332. return this.BaseRepository().FindList<WfProcessInstanceEntity>(strSql.ToString(), new { userId = userId, startTime = startTime, endTime = endTime, keyword = keyword }, pagination);
  333. }
  334. catch (Exception ex)
  335. {
  336. if (ex is ExceptionEx)
  337. {
  338. throw;
  339. }
  340. else
  341. {
  342. throw ExceptionEx.ThrowServiceException(ex);
  343. }
  344. }
  345. }
  346. /// <summary>
  347. /// 获取委托人信息列表
  348. /// </summary>
  349. /// <param name="userId">我的用户Id</param>
  350. /// <returns></returns>
  351. public List<UserInfo> GetDelegateTask(string userId)
  352. {
  353. try
  354. {
  355. List<UserInfo> delegateUserlist = new List<UserInfo>();
  356. DateTime datatime = DateTime.Now;
  357. IEnumerable<WfDelegateRuleEntity> wfDelegateRuleList = this.BaseRepository().FindList<WfDelegateRuleEntity>(t => t.F_ToUserId == userId && t.F_BeginDate >= datatime && t.F_EndDate <= datatime);
  358. foreach (var item in wfDelegateRuleList)
  359. {
  360. UserInfo userinfo = new UserInfo();
  361. userinfo.userId = item.F_CreateUserId;
  362. var strSql = new StringBuilder();
  363. strSql.Append(@"SELECT
  364. p.F_Id
  365. FROM
  366. LR_WF_DelegateRuleRelation d
  367. LEFT JOIN LR_WF_SchemeInfo s ON s.F_Id = d.F_SchemeInfoId
  368. LEFT JOIN LR_WF_ProcessInstance p ON p.F_SchemeCode = s.F_Code
  369. WHERE
  370. p.F_Id IS NOT NULL
  371. AND p.F_IsFinished = 0 AND d.F_DelegateRuleId = @DelegateRuleId ");
  372. DataTable dt = this.BaseRepository().FindTable(strSql.ToString(), new { DelegateRuleId = item.F_Id });
  373. userinfo.wfProcessId = "";
  374. foreach (DataRow dr in dt.Rows)
  375. {
  376. if (!string.IsNullOrEmpty(dr[0].ToString()))
  377. {
  378. if (!string.IsNullOrEmpty(userinfo.wfProcessId))
  379. {
  380. userinfo.wfProcessId += ",";
  381. }
  382. userinfo.wfProcessId += dr[0].ToString();
  383. }
  384. }
  385. if (!string.IsNullOrEmpty(userinfo.wfProcessId))
  386. {
  387. delegateUserlist.Add(userinfo);
  388. }
  389. }
  390. return delegateUserlist;
  391. }
  392. catch (Exception ex)
  393. {
  394. if (ex is ExceptionEx)
  395. {
  396. throw;
  397. }
  398. else
  399. {
  400. throw ExceptionEx.ThrowServiceException(ex);
  401. }
  402. }
  403. }
  404. #endregion
  405. #region 提交数据
  406. /// <summary>
  407. /// 保存或更新流程实例任务
  408. /// </summary>
  409. /// <param name="entity">实体</param>
  410. public void SaveEntity(WfTaskEntity entity)
  411. {
  412. try
  413. {
  414. entity.Create();
  415. this.BaseRepository().Insert(entity);
  416. }
  417. catch (Exception ex)
  418. {
  419. if (ex is ExceptionEx)
  420. {
  421. throw;
  422. }
  423. else
  424. {
  425. throw ExceptionEx.ThrowServiceException(ex);
  426. }
  427. }
  428. }
  429. /// <summary>
  430. /// 保存或更新流程实例任务
  431. /// </summary>
  432. /// <param name="entity">实体</param>
  433. /// <param name="companyId">公司主键</param>
  434. /// <param name="departmentId">部门主键</param>
  435. public void SaveEntitys(WfTaskEntity entity, string companyId, string departmentId)
  436. {
  437. try
  438. {
  439. if (entity.auditors.Count > 0)
  440. {
  441. foreach (var auditor in entity.auditors)
  442. {
  443. WfTaskEntity wfTaskEntity = new WfTaskEntity();
  444. wfTaskEntity.F_ProcessId = entity.F_ProcessId;
  445. wfTaskEntity.F_NodeId = entity.F_NodeId;
  446. wfTaskEntity.F_NodeName = entity.F_NodeName;
  447. wfTaskEntity.F_TaskType = entity.F_TaskType;
  448. wfTaskEntity.F_TimeoutAction = entity.F_TimeoutAction;
  449. wfTaskEntity.F_TimeoutNotice = entity.F_TimeoutNotice;
  450. wfTaskEntity.F_PreviousId = entity.F_PreviousId;
  451. wfTaskEntity.F_PreviousName = entity.F_PreviousName;
  452. wfTaskEntity.F_CreateUserId = entity.F_CreateUserId;
  453. wfTaskEntity.F_CreateUserName = entity.F_CreateUserName;
  454. wfTaskEntity.F_AuditorId = auditor.auditorId;
  455. wfTaskEntity.F_AuditorName = auditor.auditorName;
  456. wfTaskEntity.F_CompanyId = "1";
  457. wfTaskEntity.F_DepartmentId = "1";
  458. if (auditor.condition == 1)//1.同一个部门2.同一个公司
  459. {
  460. wfTaskEntity.F_DepartmentId = departmentId;
  461. }
  462. else if (auditor.condition == 2)
  463. {
  464. wfTaskEntity.F_CompanyId = companyId;
  465. }
  466. wfTaskEntity.Create();
  467. this.BaseRepository().Insert(wfTaskEntity);
  468. //读取信息推送管理-待办流程推送(04)的配置
  469. var informationPushEntity = this.BaseRepository().FindEntity<Sys_InformationPushEntity>(x => x.PushItem == "04");
  470. if (informationPushEntity != null && informationPushEntity.Status == true)
  471. {
  472. //微信推送
  473. try
  474. {
  475. PushWeixin(wfTaskEntity);
  476. }
  477. catch (Exception e)
  478. {
  479. }
  480. }
  481. }
  482. }
  483. else
  484. {
  485. entity.F_AuditorId = "1";
  486. entity.Create();
  487. this.BaseRepository().Insert(entity);
  488. }
  489. }
  490. catch (Exception ex)
  491. {
  492. if (ex is ExceptionEx)
  493. {
  494. throw;
  495. }
  496. else
  497. {
  498. throw ExceptionEx.ThrowServiceException(ex);
  499. }
  500. }
  501. }
  502. public void PushWeixin(WfTaskEntity wfTaskEntity)
  503. {
  504. try
  505. {
  506. var processinstance = BaseRepository()
  507. .FindEntity<WfProcessInstanceEntity>(m => m.F_Id == wfTaskEntity.F_ProcessId);
  508. var needpostuserlist = new List<UserEntity>();
  509. var userinfontp = this.BaseRepository()
  510. .FindEntity<UserEntity>(m => m.F_UserId == wfTaskEntity.F_AuditorId);
  511. if (userinfontp != null)
  512. {
  513. needpostuserlist.Add(userinfontp);
  514. }
  515. //增加角色、岗位判断
  516. var alluserlist = this.BaseRepository()
  517. .FindList<UserEntity>(m => !string.IsNullOrEmpty(m.OpenIdForWeixin));
  518. foreach (UserEntity user in alluserlist)
  519. {
  520. var rolelist = BaseRepository()
  521. .FindList<UserRelationEntity>(m => m.F_UserId == user.F_UserId && m.F_Category == 1)
  522. .Select(m => "'" + m.F_ObjectId + "'").ToList();
  523. if (rolelist.Count > 0)
  524. {
  525. string roleIds = string.Join(",", rolelist);
  526. if (roleIds.Contains(wfTaskEntity.F_AuditorId) &&
  527. wfTaskEntity.F_CompanyId == user.F_CompanyId && !needpostuserlist.Contains(user))
  528. {
  529. needpostuserlist.Add(user);
  530. }
  531. if (roleIds.Contains(wfTaskEntity.F_AuditorId) &&
  532. wfTaskEntity.F_DepartmentId == user.F_DepartmentId && !needpostuserlist.Contains(user))
  533. {
  534. needpostuserlist.Add(user);
  535. }
  536. }
  537. var postlist = BaseRepository()
  538. .FindList<UserRelationEntity>(m => m.F_UserId == user.F_UserId && m.F_Category == 2)
  539. .Select(m => "'" + m.F_ObjectId + "'").ToList();
  540. if (postlist.Count > 0)
  541. {
  542. string postids = string.Join(",", postlist);
  543. if (postids.Contains(wfTaskEntity.F_AuditorId) &&
  544. wfTaskEntity.F_CompanyId == user.F_CompanyId && !needpostuserlist.Contains(user))
  545. {
  546. needpostuserlist.Add(user);
  547. }
  548. if (postids.Contains(wfTaskEntity.F_AuditorId) &&
  549. wfTaskEntity.F_DepartmentId == user.F_DepartmentId && !needpostuserlist.Contains(user))
  550. {
  551. needpostuserlist.Add(user);
  552. }
  553. }
  554. }
  555. var WeChatConfigentity = BaseRepository().FindEntity<WeChatConfigEntity>(m => m.IsEnable == true);
  556. string appid = WeChatConfigentity.APPId;
  557. string secret = WeChatConfigentity.secret;
  558. var wechatemplete = BaseRepository()
  559. .FindEntity<WeChatTemplateEntity>(m => m.WeID == WeChatConfigentity.ID && m.TCode == "task");
  560. string weixintaskurl = wechatemplete.TUrl;
  561. string weixintasktempid = wechatemplete.TempId;
  562. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  563. foreach (UserEntity userinfo in needpostuserlist)
  564. {
  565. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin) && processinstance != null)
  566. {
  567. //执行推送任务
  568. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  569. {
  570. if (!string.IsNullOrEmpty(responsejson))
  571. {
  572. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  573. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  574. {
  575. string access_token = weixintokenobj.access_token;
  576. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  577. "\"template_id\":\"" + weixintasktempid + "\"," +
  578. "\"url\":\"" + weixintaskurl + "\"," +
  579. "\"data\":{" +
  580. "\"first\": {\"value\":\"" + processinstance.F_SchemeName + "\",\"color\":\"#173177\"}," +
  581. "\"keyword1\":{\"value\":\"" + processinstance.F_SchemeName + "\",\"color\":\"#173177\"}," +
  582. "\"keyword2\": {\"value\":\"" + processinstance.F_ProcessName + "\",\"color\":\"#173177\"}," +
  583. "\"keyword3\": {\"value\":\"" + wfTaskEntity.F_NodeName + "\",\"color\":\"#173177\"}," +
  584. "\"keyword4\": {\"value\":\"您有新的待办流程【" + processinstance.F_SchemeName + "】\",\"color\":\"#173177\"}" +
  585. //"\"remark\":{\"value\":\"欢迎再次购买!\",\"color\":\"#173177\"}" +
  586. "}" +
  587. "}";
  588. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  589. }
  590. }
  591. }
  592. }
  593. }
  594. //推送飞星
  595. Task.Run(async () =>
  596. {
  597. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  598. {
  599. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  600. await hubConnection.Start();
  601. await hubProxy.Invoke("PushAnnouncement", processinstance.F_Id, processinstance.F_SchemeName, processinstance.F_ProcessName, "task", string.Join(",", needpostuserlist.Select(m => m.F_UserId)), "");
  602. }
  603. });
  604. }
  605. catch (Exception e)
  606. {
  607. }
  608. }
  609. /// <summary>
  610. /// 更新任务状态
  611. /// </summary>
  612. /// <param name="keyValue">主键</param>
  613. /// <param name="state">状态 1 完成 2 关闭(会签 </param>
  614. public void UpdateState(string keyValue, int state)
  615. {
  616. try
  617. {
  618. WfTaskEntity wfTaskEntity = new WfTaskEntity();
  619. wfTaskEntity.Modify(keyValue);
  620. wfTaskEntity.F_IsFinished = state;
  621. this.BaseRepository().Update(wfTaskEntity);
  622. }
  623. catch (Exception ex)
  624. {
  625. if (ex is ExceptionEx)
  626. {
  627. throw;
  628. }
  629. else
  630. {
  631. throw ExceptionEx.ThrowServiceException(ex);
  632. }
  633. }
  634. }
  635. /// <summary>
  636. /// 更新任务完成状态
  637. /// </summary>
  638. /// <param name="processId">流程实例主键</param>
  639. /// <param name="nodeId">节点主键</param>
  640. /// <param name="taskId">任务节点Id</param>
  641. /// <param name="userId">用户主键</param>
  642. /// <param name="userName">用户名称</param>
  643. public void UpdateStateByNodeId(string processId, string nodeId, string taskId, string userId, string userName)
  644. {
  645. try
  646. {
  647. var list = this.BaseRepository().FindList<WfTaskEntity>(t => t.F_ProcessId == processId && t.F_IsFinished == 0 && t.F_NodeId == nodeId);
  648. foreach (var item in list)
  649. {
  650. WfTaskEntity wfTaskEntity = new WfTaskEntity();
  651. wfTaskEntity.Modify(item.F_Id);
  652. wfTaskEntity.F_IsFinished = 1;
  653. if (taskId == item.F_Id)
  654. {
  655. wfTaskEntity.F_ModifyUserId = userId;
  656. }
  657. wfTaskEntity.F_ModifyUserName = userName;
  658. this.BaseRepository().Update(wfTaskEntity);
  659. }
  660. }
  661. catch (Exception ex)
  662. {
  663. if (ex is ExceptionEx)
  664. {
  665. throw;
  666. }
  667. else
  668. {
  669. throw ExceptionEx.ThrowServiceException(ex);
  670. }
  671. }
  672. }
  673. #endregion
  674. }
  675. }