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.
 
 
 
 
 
 

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