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.
 
 
 
 
 
 

593 lines
25 KiB

  1. using Dapper;
  2. using Learun.Application.Organization;
  3. using Learun.Application.TwoDevelopment.EducationalAdministration;
  4. using Learun.Application.TwoDevelopment.LR_Desktop;
  5. using Learun.DataBase.Repository;
  6. using Learun.Util;
  7. using Microsoft.AspNet.SignalR.Client;
  8. using Newtonsoft.Json;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Configuration;
  12. using System.Data;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Web;
  17. namespace Learun.Application.TwoDevelopment.PersonnelManagement
  18. {
  19. /// <summary>
  20. /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
  21. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  22. /// 创 建:超级管理员
  23. /// 日 期:2021-02-21 10:07
  24. /// 描 述:会议管理
  25. /// </summary>
  26. public class MeetingManagementService : RepositoryFactory
  27. {
  28. #region 获取数据
  29. /// <summary>
  30. /// 获取页面显示列表分页数据
  31. /// <summary>
  32. /// <param name="pagination">分页参数</param>
  33. /// <param name="queryJson">查询参数</param>
  34. /// <returns></returns>
  35. public IEnumerable<MeetingManagementEntity> GetPageList(Pagination pagination, string queryJson)
  36. {
  37. try
  38. {
  39. var strSql = new StringBuilder();
  40. strSql.Append("SELECT t.*,r.Name as ConferenceRoomName ");
  41. strSql.Append(" FROM MeetingManagement t left join ConferenceRoom r on t.MeetingPlace=r.ID ");
  42. strSql.Append(" WHERE 1=1 ");
  43. var queryParam = queryJson.ToJObject();
  44. // 虚拟参数
  45. var dp = new DynamicParameters(new { });
  46. if (!queryParam["MeetingTitle"].IsEmpty())
  47. {
  48. dp.Add("MeetingTitle", "%" + queryParam["MeetingTitle"].ToString() + "%", DbType.String);
  49. strSql.Append(" AND t.MeetingTitle Like @MeetingTitle ");
  50. }
  51. if (!queryParam["MeetingPlace"].IsEmpty())
  52. {
  53. dp.Add("MeetingPlace", queryParam["MeetingPlace"].ToString(), DbType.String);
  54. strSql.Append(" AND t.MeetingPlace = @MeetingPlace ");
  55. }
  56. if (!queryParam["CreateUser"].IsEmpty())
  57. {
  58. dp.Add("CreateUser", queryParam["CreateUser"].ToString(), DbType.String);
  59. strSql.Append(" AND t.CreateUser = @CreateUser ");
  60. }
  61. if (!queryParam["InternalParticipants"].IsEmpty())
  62. {
  63. dp.Add("InternalParticipants", "%" + queryParam["InternalParticipants"].ToString() + "%", DbType.String);
  64. strSql.Append(" AND t.InternalParticipants Like @InternalParticipants ");
  65. }
  66. return this.BaseRepository("CollegeMIS").FindList<MeetingManagementEntity>(strSql.ToString(), dp, pagination);
  67. }
  68. catch (Exception ex)
  69. {
  70. if (ex is ExceptionEx)
  71. {
  72. throw;
  73. }
  74. else
  75. {
  76. throw ExceptionEx.ThrowServiceException(ex);
  77. }
  78. }
  79. }
  80. /// <summary>
  81. /// 获取页面显示列表数据
  82. /// <summary>
  83. /// <param name="queryJson">查询参数</param>
  84. /// <returns></returns>
  85. public IEnumerable<MeetingManagementEntity> GetList(string queryJson)
  86. {
  87. try
  88. {
  89. var strSql = new StringBuilder();
  90. strSql.Append("SELECT t.*");
  91. strSql.Append(" FROM MeetingManagement t ");
  92. strSql.Append(" WHERE 1=1 ");
  93. var queryParam = queryJson.ToJObject();
  94. // 虚拟参数
  95. var dp = new DynamicParameters(new { });
  96. if (!queryParam["MeetingTitle"].IsEmpty())
  97. {
  98. dp.Add("MeetingTitle", "%" + queryParam["MeetingTitle"].ToString() + "%", DbType.String);
  99. strSql.Append(" AND t.MeetingTitle Like @MeetingTitle ");
  100. }
  101. if (!queryParam["MeetingPlace"].IsEmpty())
  102. {
  103. dp.Add("MeetingPlace", queryParam["MeetingPlace"].ToString(), DbType.String);
  104. strSql.Append(" AND t.MeetingPlace = @MeetingPlace ");
  105. }
  106. if (!queryParam["CreateUser"].IsEmpty())
  107. {
  108. dp.Add("CreateUser", queryParam["CreateUser"].ToString(), DbType.String);
  109. strSql.Append(" AND t.CreateUser = @CreateUser ");
  110. }
  111. return this.BaseRepository("CollegeMIS").FindList<MeetingManagementEntity>(strSql.ToString(), dp);
  112. }
  113. catch (Exception ex)
  114. {
  115. if (ex is ExceptionEx)
  116. {
  117. throw;
  118. }
  119. else
  120. {
  121. throw ExceptionEx.ThrowServiceException(ex);
  122. }
  123. }
  124. }
  125. /// <summary>
  126. /// 获取MeetingManagement表实体数据
  127. /// <param name="keyValue">主键</param>
  128. /// <summary>
  129. /// <returns></returns>
  130. public MeetingManagementEntity GetMeetingManagementEntity(string keyValue)
  131. {
  132. try
  133. {
  134. var data = this.BaseRepository("CollegeMIS").FindEntity<MeetingManagementEntity>(keyValue);
  135. if (data != null)
  136. {
  137. data.ConferenceRoomName = this.BaseRepository("CollegeMIS").FindEntity<ConferenceRoomEntity>(data.MeetingPlace).Name;
  138. }
  139. return data;
  140. }
  141. catch (Exception ex)
  142. {
  143. if (ex is ExceptionEx)
  144. {
  145. throw;
  146. }
  147. else
  148. {
  149. throw ExceptionEx.ThrowServiceException(ex);
  150. }
  151. }
  152. }
  153. /// <summary>
  154. /// 获取MeetingManagement表实体数据
  155. /// <param name="keyValue">主键</param>
  156. /// <summary>
  157. /// <returns></returns>
  158. public MeetingManagementEntity GetMeetingManagementEntityByProcessId(string processId)
  159. {
  160. try
  161. {
  162. return this.BaseRepository("CollegeMIS").FindEntity<MeetingManagementEntity>(x => x.ProcessId == processId);
  163. }
  164. catch (Exception ex)
  165. {
  166. if (ex is ExceptionEx)
  167. {
  168. throw;
  169. }
  170. else
  171. {
  172. throw ExceptionEx.ThrowServiceException(ex);
  173. }
  174. }
  175. }
  176. #endregion
  177. #region 提交数据
  178. /// <summary>
  179. /// 删除实体数据
  180. /// <param name="keyValue">主键</param>
  181. /// <summary>
  182. /// <returns></returns>
  183. public void DeleteEntity(string keyValue)
  184. {
  185. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  186. try
  187. {
  188. //会议签到记录表中删除参会人员记录
  189. db.Delete<MeetingSignInRecordEntity>(x => x.MeetID == keyValue);
  190. //会议工作管理表删除会议
  191. db.Delete<MeetingManagementEntity>(t => t.Id == keyValue);
  192. db.Commit();
  193. }
  194. catch (Exception ex)
  195. {
  196. db.Rollback();
  197. if (ex is ExceptionEx)
  198. {
  199. throw;
  200. }
  201. else
  202. {
  203. throw ExceptionEx.ThrowServiceException(ex);
  204. }
  205. }
  206. }
  207. /// <summary>
  208. /// 保存实体数据(新增、修改)
  209. /// <param name="keyValue">主键</param>
  210. /// <summary>
  211. /// <returns></returns>
  212. public void SaveEntity(UserInfo userInfo, string keyValue, MeetingManagementEntity entity)
  213. {
  214. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  215. try
  216. {
  217. if (!string.IsNullOrEmpty(keyValue))
  218. {
  219. entity.Modify(keyValue, userInfo);
  220. db.Update(entity);
  221. }
  222. else
  223. {
  224. entity.Create(userInfo);
  225. db.Insert(entity);
  226. }
  227. db.Commit();
  228. }
  229. catch (Exception ex)
  230. {
  231. db.Rollback();
  232. if (ex is ExceptionEx)
  233. {
  234. throw;
  235. }
  236. else
  237. {
  238. throw ExceptionEx.ThrowServiceException(ex);
  239. }
  240. }
  241. }
  242. /// <summary>
  243. /// 审核实体数据
  244. /// <param name="keyValue">主键</param>
  245. /// <summary>
  246. /// <returns></returns>
  247. public void DoCheck(UserInfo userInfo, string keyValue, string status)
  248. {
  249. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  250. try
  251. {
  252. //修改会议工作管理表的审核字段;
  253. db.ExecuteBySql("update MeetingManagement set CheckStatus='" + status + "',CheckUser='" + userInfo.userId + "',CheckTime='" + DateTime.Now + "' where Id='" + keyValue + "' ");
  254. if (status == "1")//审核通过:会议签到记录表中增加参会人员;
  255. {
  256. var entity = db.FindEntity<MeetingManagementEntity>(x => x.Id == keyValue);
  257. if (entity != null)
  258. {
  259. //增加校内参入人员:
  260. if (!string.IsNullOrEmpty(entity.InternalParticipants))
  261. {
  262. if (entity.InternalParticipants.IndexOf(',') == -1)
  263. {
  264. var model = new MeetingSignInRecordEntity()
  265. {
  266. MeetID = entity.Id,
  267. ParticipantID = entity.InternalParticipants,
  268. ParticipantName = this.BaseRepository().FindEntity<UserEntity>(x => x.F_UserId == entity.InternalParticipants)?.F_RealName,
  269. IsSignIn = false
  270. };
  271. model.Create(userInfo);
  272. db.Insert(model);
  273. }
  274. else
  275. {
  276. foreach (var item in entity.InternalParticipants.Split(','))
  277. {
  278. var model = new MeetingSignInRecordEntity()
  279. {
  280. MeetID = entity.Id,
  281. ParticipantID = item,
  282. ParticipantName = this.BaseRepository().FindEntity<UserEntity>(x => x.F_UserId == item)?.F_RealName,
  283. IsSignIn = false
  284. };
  285. model.Create(userInfo);
  286. db.Insert(model);
  287. }
  288. }
  289. }
  290. //增加校外参入人员:
  291. if (!string.IsNullOrEmpty(entity.ExternalParticipants))
  292. {
  293. if (entity.ExternalParticipants.IndexOf(',') == -1)
  294. {
  295. var model = new MeetingSignInRecordEntity()
  296. {
  297. MeetID = entity.Id,
  298. ParticipantName = entity.ExternalParticipants,
  299. IsSignIn = false
  300. };
  301. model.Create(userInfo);
  302. db.Insert(model);
  303. }
  304. else
  305. {
  306. foreach (var item in entity.ExternalParticipants.Split(','))
  307. {
  308. var model = new MeetingSignInRecordEntity()
  309. {
  310. MeetID = entity.Id,
  311. ParticipantName = item,
  312. IsSignIn = false
  313. };
  314. model.Create(userInfo);
  315. db.Insert(model);
  316. }
  317. }
  318. }
  319. }
  320. }
  321. else if (status == "2") //审核不通过:会议签到记录表中删除参会人员记录;
  322. {
  323. db.Delete<MeetingSignInRecordEntity>(x => x.MeetID == keyValue);
  324. }
  325. db.Commit();
  326. }
  327. catch (Exception ex)
  328. {
  329. db.Rollback();
  330. if (ex is ExceptionEx)
  331. {
  332. throw;
  333. }
  334. else
  335. {
  336. throw ExceptionEx.ThrowServiceException(ex);
  337. }
  338. }
  339. }
  340. /// <summary>
  341. /// 提交实体数据
  342. /// <param name="keyValue">主键</param>
  343. /// <summary>
  344. /// <returns></returns>
  345. public void DoSubmit(string keyValue, string status, string processId)
  346. {
  347. try
  348. {
  349. this.BaseRepository("CollegeMIS").ExecuteBySql("update MeetingManagement set CheckStatus='" + status + "',ProcessId='" + processId + "' where Id='" + keyValue + "' ");
  350. }
  351. catch (Exception ex)
  352. {
  353. if (ex is ExceptionEx)
  354. {
  355. throw;
  356. }
  357. else
  358. {
  359. throw ExceptionEx.ThrowServiceException(ex);
  360. }
  361. }
  362. }
  363. /// <summary>
  364. /// 审核实体数据
  365. /// <param name="keyValue">主键</param>
  366. /// <summary>
  367. /// <returns></returns>
  368. public void ChangeStatusByProcessId(string processId, string status, string userId)
  369. {
  370. UserInfo userInfo = LoginUserInfo.Get();
  371. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  372. try
  373. {
  374. //修改会议工作管理表的审核字段;
  375. db.ExecuteBySql("update MeetingManagement set CheckStatus='" + status + "',CheckUser='" + userId + "',CheckTime='" + DateTime.Now + "' where ProcessId='" + processId + "' ");
  376. var entity = db.FindEntity<MeetingManagementEntity>(x => x.ProcessId == processId);
  377. if (entity != null)
  378. {
  379. if (status == "1")//审核通过:会议签到记录表中增加参会人员;
  380. {
  381. //增加校内参入人员:
  382. if (!string.IsNullOrEmpty(entity.InternalParticipants))
  383. {
  384. if (entity.InternalParticipants.IndexOf(',') == -1)
  385. {
  386. var model = new MeetingSignInRecordEntity()
  387. {
  388. MeetID = entity.Id,
  389. ParticipantID = entity.InternalParticipants,
  390. ParticipantName = this.BaseRepository().FindEntity<UserEntity>(x => x.F_UserId == entity.InternalParticipants)?.F_RealName,
  391. IsSignIn = false
  392. };
  393. model.Create(userInfo);
  394. db.Insert(model);
  395. }
  396. else
  397. {
  398. foreach (var item in entity.InternalParticipants.Split(','))
  399. {
  400. var model = new MeetingSignInRecordEntity()
  401. {
  402. MeetID = entity.Id,
  403. ParticipantID = item,
  404. ParticipantName = this.BaseRepository().FindEntity<UserEntity>(x => x.F_UserId == item)?.F_RealName,
  405. IsSignIn = false
  406. };
  407. model.Create(userInfo);
  408. db.Insert(model);
  409. }
  410. }
  411. }
  412. //增加校外参入人员:
  413. if (!string.IsNullOrEmpty(entity.ExternalParticipants))
  414. {
  415. if (entity.ExternalParticipants.IndexOf(',') == -1)
  416. {
  417. var model = new MeetingSignInRecordEntity()
  418. {
  419. MeetID = entity.Id,
  420. ParticipantName = entity.ExternalParticipants,
  421. IsSignIn = false
  422. };
  423. model.Create(userInfo);
  424. db.Insert(model);
  425. }
  426. else
  427. {
  428. foreach (var item in entity.ExternalParticipants.Split(','))
  429. {
  430. var model = new MeetingSignInRecordEntity()
  431. {
  432. MeetID = entity.Id,
  433. ParticipantName = item,
  434. IsSignIn = false
  435. };
  436. model.Create(userInfo);
  437. db.Insert(model);
  438. }
  439. }
  440. }
  441. }
  442. else if (status == "2") //审核不通过:会议签到记录表中删除参会人员记录;
  443. {
  444. db.Delete<MeetingSignInRecordEntity>(x => x.MeetID == entity.Id);
  445. }
  446. }
  447. db.Commit();
  448. }
  449. catch (Exception ex)
  450. {
  451. db.Rollback();
  452. if (ex is ExceptionEx)
  453. {
  454. throw;
  455. }
  456. else
  457. {
  458. throw ExceptionEx.ThrowServiceException(ex);
  459. }
  460. }
  461. }
  462. public void ReceivedList(string processId)
  463. {
  464. var Received = GetMeetingManagementEntityByProcessId(processId);
  465. List<UserEntity> userInfos = new List<UserEntity>();
  466. foreach (var rid in Received.InternalParticipants.Split(','))
  467. {
  468. var user = this.BaseRepository().FindEntity<UserEntity>(m => m.F_UserId == rid);
  469. if (!userInfos.Contains(user))
  470. {
  471. userInfos.Add(user);
  472. }
  473. }
  474. if (!string.IsNullOrEmpty(Received.RecordPerson))
  475. {
  476. foreach (var rid in Received.RecordPerson.Split(','))
  477. {
  478. var user = this.BaseRepository().FindEntity<UserEntity>(m => m.F_UserId == rid);
  479. if (!userInfos.Contains(user))
  480. {
  481. userInfos.Add(user);
  482. }
  483. }
  484. }
  485. //foreach (var uitem in userInfos)
  486. //{
  487. // SYS_ReceiveMessageEntity receiveMessageEntity = new SYS_ReceiveMessageEntity();
  488. // receiveMessageEntity.Create();
  489. // receiveMessageEntity.SENDERID = Received.SENDERID;
  490. // receiveMessageEntity.SENDER = messageentity.SENDER;
  491. // receiveMessageEntity.RECEIVERID = uitem.F_UserId;
  492. // receiveMessageEntity.RECEIVER = uitem.F_RealName;
  493. // receiveMessageEntity.TITLE = messageentity.TITLE;
  494. // receiveMessageEntity.CONTENTS = messageentity.CONTENTS;
  495. // receiveMessageEntity.URL = messageentity.URL;
  496. // receiveMessageEntity.READFLAG = 0;
  497. // receiveMessageEntity.SENDTIME = DateTime.Now;
  498. // receiveMessageEntity.DelFlag = false;
  499. // this.BaseRepository().Insert(receiveMessageEntity);
  500. //}
  501. //读取信息推送管理-会议申请推送(03)的配置
  502. var informationPushEntity = this.BaseRepository().FindEntity<Sys_InformationPushEntity>(x => x.PushItem == "03");
  503. if (informationPushEntity != null && informationPushEntity.Status == true)
  504. {
  505. //微信推送
  506. try
  507. {
  508. PushWeixin(userInfos, Received.MeetingTitle);
  509. }
  510. catch (Exception e)
  511. {
  512. }
  513. //飞星推送
  514. Task.Run(async () =>
  515. {
  516. using (var hubConnection = new HubConnection(ConfigurationManager.AppSettings["CommunicationServeraddress"]))
  517. {
  518. var hubProxy = hubConnection.CreateHubProxy("SignalRHub");
  519. await hubConnection.Start();
  520. await hubProxy.Invoke("PushAnnouncement", Received.InternalParticipants, Received.MeetingTitle, Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(Received.Content)).Length < 20 ? Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(Received.Content)) : Util.Str.ReplaceHtml(HttpUtility.HtmlDecode(Received.Content)).Substring(0, 20), "mail", string.Join(",", userInfos.Select(m => m.F_UserId)), "");
  521. }
  522. });
  523. }
  524. }
  525. public void PushWeixin(List<UserEntity> needpostuserlist, string title)
  526. {
  527. var WeChatConfigentity = BaseRepository().FindEntity<WeChatConfigEntity>(m => m.IsEnable == true);
  528. string appid = WeChatConfigentity.APPId;
  529. string secret = WeChatConfigentity.secret;
  530. var wechatemplete = BaseRepository()
  531. .FindEntity<WeChatTemplateEntity>(m => m.WeID == WeChatConfigentity.ID && m.TCode == "task");
  532. string weixintaskurl = wechatemplete.TUrl;
  533. string weixintasktempid = wechatemplete.TempId;
  534. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  535. foreach (UserEntity userinfo in needpostuserlist)
  536. {
  537. if (userinfo != null && !string.IsNullOrEmpty(userinfo.OpenIdForWeixin))
  538. {
  539. //执行推送任务
  540. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  541. {
  542. if (!string.IsNullOrEmpty(responsejson))
  543. {
  544. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  545. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  546. {
  547. string access_token = weixintokenobj.access_token;
  548. string jsondata = "{\"touser\":\"" + userinfo.OpenIdForWeixin + "\"," +
  549. "\"template_id\":\"" + weixintasktempid + "\"," +
  550. "\"url\":\"" + weixintaskurl + "\"," +
  551. "\"data\":{" +
  552. "\"first\": {\"value\":\"您有新的会议消息\",\"color\":\"#173177\"}," +
  553. "\"keyword1\":{\"value\":\"未读邮件\",\"color\":\"#173177\"}," +
  554. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  555. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  556. "\"keyword4\": {\"value\":\"您有新的未读会议【" + title + "】\",\"color\":\"#173177\"}" +
  557. "}" +
  558. "}";
  559. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  560. }
  561. }
  562. }
  563. }
  564. }
  565. }
  566. #endregion
  567. }
  568. }