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.

ThermographyService.cs 29 KiB

4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
4 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. using Dapper;
  2. using Learun.Application.Base.AuthorizeModule;
  3. using Learun.Application.Organization;
  4. using Learun.Application.TwoDevelopment.LR_Desktop;
  5. using Learun.DataBase.Repository;
  6. using Learun.Util;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.Linq;
  12. using System.Text;
  13. using Learun.Application.Base.SystemModule;
  14. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  15. {
  16. /// <summary>
  17. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  18. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  19. /// 创 建:超级管理员
  20. /// 日 期:2020-04-16 15:52
  21. /// 描 述:班级自诊打卡
  22. /// </summary>
  23. public class ThermographyService : RepositoryFactory
  24. {
  25. #region 获取数据
  26. /// <summary>
  27. /// 获取页面显示列表分页数据
  28. /// <summary>
  29. /// <param name="pagination">分页参数</param>
  30. /// <param name="queryJson">查询参数</param>
  31. /// <returns></returns>
  32. public IEnumerable<ThermographyEntity> GetPageList(Pagination pagination, string queryJson)
  33. {
  34. try
  35. {
  36. var strSql = new StringBuilder();
  37. strSql.Append("SELECT t.* ");
  38. strSql.Append(" FROM Thermography t ");
  39. strSql.Append(" WHERE 1=1 ");
  40. var queryParam = queryJson.ToJObject();
  41. // 虚拟参数
  42. var dp = new DynamicParameters(new { });
  43. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  44. {
  45. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  46. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  47. strSql.Append(" AND ( t.MeasureDate >= @startTime AND t.MeasureDate <= @endTime ) ");
  48. }
  49. if (!queryParam["DeptNo"].IsEmpty())
  50. {
  51. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  52. strSql.Append(" AND t.DeptNo = @DeptNo ");
  53. }
  54. if (!queryParam["MajorNo"].IsEmpty())
  55. {
  56. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  57. strSql.Append(" AND t.MajorNo = @MajorNo ");
  58. }
  59. if (!queryParam["ClassNo"].IsEmpty())
  60. {
  61. dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
  62. strSql.Append(" AND t.ClassNo = @ClassNo ");
  63. }
  64. if (!queryParam["MeasureTime"].IsEmpty())
  65. {
  66. dp.Add("MeasureTime", queryParam["MeasureTime"].ToString(), DbType.String);
  67. strSql.Append(" AND t.MeasureTime = @MeasureTime ");
  68. }
  69. if (!queryParam["PersonBeingMeasured"].IsEmpty())
  70. {
  71. dp.Add("PersonBeingMeasured", queryParam["PersonBeingMeasured"].ToString(), DbType.String);
  72. strSql.Append(" AND t.PersonBeingMeasured = @PersonBeingMeasured ");
  73. }
  74. if (!queryParam["Status"].IsEmpty())
  75. {
  76. dp.Add("Status", queryParam["Status"].ToString(), DbType.String);
  77. strSql.Append(" AND t.Status = @Status ");
  78. }
  79. if (!queryParam["MeasurerID"].IsEmpty())
  80. {
  81. dp.Add("MeasurerID", queryParam["MeasurerID"].ToString(), DbType.String);
  82. strSql.Append(" AND t.MeasurerID = @MeasurerID ");
  83. }
  84. return this.BaseRepository("CollegeMIS").FindList<ThermographyEntity>(strSql.ToString(), dp, pagination);
  85. }
  86. catch (Exception ex)
  87. {
  88. if (ex is ExceptionEx)
  89. {
  90. throw;
  91. }
  92. else
  93. {
  94. throw ExceptionEx.ThrowServiceException(ex);
  95. }
  96. }
  97. }
  98. /// <summary>
  99. /// 获取页面显示列表数据
  100. /// <summary>
  101. /// <param name="queryJson">查询参数</param>
  102. /// <returns></returns>
  103. public IEnumerable<ThermographyEntity> GetList(string queryJson)
  104. {
  105. try
  106. {
  107. var strSql = new StringBuilder();
  108. strSql.Append("SELECT ");
  109. strSql.Append(@"
  110. t.ID,
  111. t.ClassNo,
  112. t.MeasurerID,
  113. t.PersonBeingMeasured,
  114. t.Status,
  115. t.Temperature,
  116. t.ProcessingResult,
  117. t.Remark,
  118. t.MeasureTime,
  119. t.DeptNo,
  120. t.MajorNo,
  121. t.MeasureDate
  122. ");
  123. strSql.Append(" FROM Thermography t ");
  124. strSql.Append(" WHERE 1=1 ");
  125. var queryParam = queryJson.ToJObject();
  126. // 虚拟参数
  127. var dp = new DynamicParameters(new { });
  128. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  129. {
  130. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  131. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  132. strSql.Append(" AND ( t.MeasureDate >= @startTime AND t.MeasureDate <= @endTime ) ");
  133. }
  134. if (!queryParam["ClassNo"].IsEmpty())
  135. {
  136. dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
  137. strSql.Append(" AND t.ClassNo = @ClassNo ");
  138. }
  139. if (!queryParam["PersonBeingMeasured"].IsEmpty())
  140. {
  141. dp.Add("PersonBeingMeasured", queryParam["PersonBeingMeasured"].ToString(), DbType.String);
  142. strSql.Append(" AND t.PersonBeingMeasured = @PersonBeingMeasured ");
  143. }
  144. if (!queryParam["Status"].IsEmpty())
  145. {
  146. dp.Add("Status", queryParam["Status"].ToString(), DbType.String);
  147. strSql.Append(" AND t.Status = @Status ");
  148. }
  149. return this.BaseRepository("CollegeMIS").FindList<ThermographyEntity>(strSql.ToString(), dp);
  150. }
  151. catch (Exception ex)
  152. {
  153. if (ex is ExceptionEx)
  154. {
  155. throw;
  156. }
  157. else
  158. {
  159. throw ExceptionEx.ThrowServiceException(ex);
  160. }
  161. }
  162. }
  163. /// <summary>
  164. /// 获取Thermography表实体数据
  165. /// <param name="keyValue">主键</param>
  166. /// <summary>
  167. /// <returns></returns>
  168. public ThermographyEntity GetThermographyEntity(string keyValue)
  169. {
  170. try
  171. {
  172. return this.BaseRepository("CollegeMIS").FindEntity<ThermographyEntity>(keyValue);
  173. }
  174. catch (Exception ex)
  175. {
  176. if (ex is ExceptionEx)
  177. {
  178. throw;
  179. }
  180. else
  181. {
  182. throw ExceptionEx.ThrowServiceException(ex);
  183. }
  184. }
  185. }
  186. /// <summary>
  187. /// 获取Thermography表实体数据
  188. /// <param name="keyValue">主键</param>
  189. /// <summary>
  190. /// <returns></returns>
  191. public ThermographyEntity GetThermographyEntitiesByClass(string classNo, DateTime measureDate, string measureTime)
  192. {
  193. try
  194. {
  195. var nextday = measureDate.AddDays(1).Date;
  196. return this.BaseRepository("CollegeMIS").FindEntity<ThermographyEntity>(x => x.ClassNo == classNo && x.MeasureDate >= measureDate && x.MeasureDate < nextday && x.MeasureTime == measureTime);
  197. }
  198. catch (Exception ex)
  199. {
  200. if (ex is ExceptionEx)
  201. {
  202. throw;
  203. }
  204. else
  205. {
  206. throw ExceptionEx.ThrowServiceException(ex);
  207. }
  208. }
  209. }
  210. /// <summary>
  211. /// 开始测温的学生列表
  212. /// <summary>
  213. /// <param name="pagination">分页参数</param>
  214. /// <param name="queryJson">查询参数</param>
  215. /// <returns></returns>
  216. public IEnumerable<ThermographyEntity> GetPageListOfStudent(string queryJson)
  217. {
  218. try
  219. {
  220. var userInfo = LoginUserInfo.Get();
  221. var strSql = new StringBuilder();
  222. strSql.Append("SELECT t.ClassNo,t.DeptNo,t.MajorNo,t.StuNo as PersonBeingMeasured,t.StuName as PersonBeingMeasuredName,'" + userInfo.account + "' as MeasurerID,'1' as Status,c.ClassName ");
  223. strSql.Append(" FROM StuInfoBasic t left join StuInfoBasic tt on t.ClassNo=tt.ClassNo left join ClassInfo c on t.ClassNo=c.ClassNo ");
  224. strSql.Append(" WHERE 1=1 ");
  225. var queryParam = queryJson.ToJObject();
  226. // 虚拟参数
  227. var dp = new DynamicParameters(new { });
  228. if (!queryParam["MeasurerID"].IsEmpty())
  229. {
  230. dp.Add("MeasurerID", queryParam["MeasurerID"].ToString(), DbType.String);
  231. strSql.Append(" AND tt.StuNo = @MeasurerID ");
  232. }
  233. return this.BaseRepository("CollegeMIS").FindList<ThermographyEntity>(strSql.ToString(), dp);
  234. }
  235. catch (Exception ex)
  236. {
  237. if (ex is ExceptionEx)
  238. {
  239. throw;
  240. }
  241. else
  242. {
  243. throw ExceptionEx.ThrowServiceException(ex);
  244. }
  245. }
  246. }
  247. /// <summary>
  248. /// APP中开始测温的学生列表
  249. /// <summary>
  250. /// <param name="pagination">分页参数</param>
  251. /// <param name="queryJson">查询参数</param>
  252. /// <returns></returns>
  253. public IEnumerable<ThermographyEntity> GetPageListOfStudentInApp(string queryJson)
  254. {
  255. try
  256. {
  257. var userInfo = LoginUserInfo.Get();
  258. var strSql = new StringBuilder();
  259. var queryParam = queryJson.ToJObject();
  260. // 虚拟参数
  261. var dp = new DynamicParameters(new { });
  262. var nowDate = DateTime.Now.Date;
  263. var nextDate = DateTime.Now.AddDays(1).Date;
  264. strSql.Append("SELECT t.ClassNo,t.DeptNo,t.MajorNo,t.StuNo as PersonBeingMeasured,t.StuName as PersonBeingMeasuredName,'" + userInfo.account + "' as MeasurerID,'1' as Status,c.ClassName ");
  265. if (!queryParam["MeasureTime"].IsEmpty() && queryParam["MeasureTime"].ToString() != "-1")
  266. {
  267. strSql.Append(" ,g.ID,case when g.Status is null then '1' else g.Status end as Status,g.Temperature,g.ProcessingResult,g.Remark,g.MeasureTime ");
  268. }
  269. strSql.Append(" FROM StuInfoBasic t left join StuInfoBasic tt on t.ClassNo=tt.ClassNo left join ClassInfo c on t.ClassNo=c.ClassNo ");
  270. if (!queryParam["MeasureTime"].IsEmpty() && queryParam["MeasureTime"].ToString() != "-1")
  271. {
  272. strSql.Append(" left join Thermography g on t.StuNo=g.PersonBeingMeasured and t.ClassNo=g.ClassNo and t.DeptNo=g.DeptNo and t.MajorNo=g.DeptNo ");
  273. strSql.Append(" and g.MeasureDate >='" + nowDate + "' and g.MeasureDate<'" + nextDate + "' ");
  274. dp.Add("MeasureTime", queryParam["MeasureTime"].ToString(), DbType.String);
  275. strSql.Append(" and g.MeasureTime=@MeasureTime ");
  276. }
  277. strSql.Append(" WHERE 1=1 ");
  278. if (!queryParam["MeasurerID"].IsEmpty())
  279. {
  280. dp.Add("MeasurerID", queryParam["MeasurerID"].ToString(), DbType.String);
  281. strSql.Append(" AND tt.StuNo = @MeasurerID ");
  282. }
  283. return this.BaseRepository("CollegeMIS").FindList<ThermographyEntity>(strSql.ToString(), dp);
  284. }
  285. catch (Exception ex)
  286. {
  287. if (ex is ExceptionEx)
  288. {
  289. throw;
  290. }
  291. else
  292. {
  293. throw ExceptionEx.ThrowServiceException(ex);
  294. }
  295. }
  296. }
  297. /// <summary>
  298. /// 班级自诊打卡统计
  299. /// <summary>
  300. /// <param name="queryJson">查询参数</param>
  301. /// <returns></returns>
  302. public IEnumerable<ThermographyEntity> GetListOfStatistic(string queryJson)
  303. {
  304. try
  305. {
  306. var queryParam = queryJson.ToJObject();
  307. // 虚拟参数
  308. var dp = new DynamicParameters(new { });
  309. var strSql = new StringBuilder();
  310. strSql.Append("select t.DeptNo,CONVERT(varchar(100), t.MeasureDate, 23) as MeasureDate,t.MeasureTime,sum(case when t.Status='0' then 1 else 0 end) as statusNum0,sum(case when t.Status='1' then 1 else 0 end) as statusNum1,sum(case when t.Status='2' then 1 else 0 end) as statusNum2,sum(case when t.Status!='0' then 1 else 0 end) as statusNum12,(select count(s.StuId) from StuInfoBasic s where s.DeptNo=t.DeptNo and s.CheckMark='1') as totalNum ");
  311. strSql.Append(" FROM Thermography t ");
  312. strSql.Append(" WHERE 1=1 ");
  313. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  314. {
  315. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  316. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  317. strSql.Append(" AND ( t.MeasureDate >= @startTime AND t.MeasureDate <= @endTime ) ");
  318. }
  319. if (!queryParam["DeptNo"].IsEmpty())
  320. {
  321. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  322. strSql.Append(" AND t.DeptNo = @DeptNo ");
  323. }
  324. if (!queryParam["MajorNo"].IsEmpty())
  325. {
  326. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  327. strSql.Append(" AND t.MajorNo = @MajorNo ");
  328. }
  329. if (!queryParam["ClassNo"].IsEmpty())
  330. {
  331. dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
  332. strSql.Append(" AND t.ClassNo = @ClassNo ");
  333. }
  334. strSql.Append(" group by t.DeptNo,CONVERT(varchar(100), t.MeasureDate, 23),t.MeasureTime ");
  335. return this.BaseRepository("CollegeMIS").FindList<ThermographyEntity>(strSql.ToString(), dp);
  336. }
  337. catch (Exception ex)
  338. {
  339. if (ex is ExceptionEx)
  340. {
  341. throw;
  342. }
  343. else
  344. {
  345. throw ExceptionEx.ThrowServiceException(ex);
  346. }
  347. }
  348. }
  349. #endregion
  350. #region 提交数据
  351. /// <summary>
  352. /// 删除实体数据
  353. /// <param name="keyValue">主键</param>
  354. /// <summary>
  355. /// <returns></returns>
  356. public void DeleteEntity(string keyValue)
  357. {
  358. try
  359. {
  360. this.BaseRepository("CollegeMIS").Delete<ThermographyEntity>(t => t.ID == keyValue);
  361. }
  362. catch (Exception ex)
  363. {
  364. if (ex is ExceptionEx)
  365. {
  366. throw;
  367. }
  368. else
  369. {
  370. throw ExceptionEx.ThrowServiceException(ex);
  371. }
  372. }
  373. }
  374. /// <summary>
  375. /// 保存实体数据(新增、修改)
  376. /// <param name="keyValue">主键</param>
  377. /// <summary>
  378. /// <returns></returns>
  379. public void SaveEntity(UserInfo userInfo, string keyValue, ThermographyEntity entity)
  380. {
  381. try
  382. {
  383. //限制测温时间(上午、中午、晚上)时:判断学生是否已测温,是则更新,否则新增;不限制测温时间时:新增;
  384. if (entity.MeasureTime == "-1")
  385. {
  386. entity.Create(userInfo);
  387. this.BaseRepository("CollegeMIS").Insert(entity);
  388. }
  389. else
  390. {
  391. if (!string.IsNullOrEmpty(keyValue))
  392. {
  393. entity.Modify(keyValue, userInfo);
  394. this.BaseRepository("CollegeMIS").Update(entity);
  395. }
  396. else
  397. {
  398. entity.Create(userInfo);
  399. this.BaseRepository("CollegeMIS").Insert(entity);
  400. }
  401. }
  402. LogEntity logEntity = new LogEntity();
  403. logEntity.F_LogId = Guid.NewGuid().ToString();
  404. logEntity.F_Module = "Thermography";
  405. logEntity.F_ExecuteResultJson = "Thermography Status=" + entity.Status;
  406. logEntity.WriteLog();
  407. //体温异常
  408. if (entity.Status == "2")
  409. {
  410. try
  411. {
  412. var stuModel = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(x => x.StuNo == entity.PersonBeingMeasured);
  413. if (stuModel != null)
  414. {
  415. logEntity = new LogEntity();
  416. logEntity.F_LogId = Guid.NewGuid().ToString();
  417. logEntity.F_Module = "Thermography";
  418. logEntity.F_ExecuteResultJson = "Thermography stuModelStuNo=" + stuModel.StuNo;
  419. logEntity.WriteLog();
  420. var title = string.Format("{0}({1})", stuModel.StuName, stuModel.StuNo);
  421. //读取信息推送管理-班级自诊打卡体温异常学生推送(05)的配置
  422. var informationPushEntity = this.BaseRepository().FindEntity<Sys_InformationPushEntity>(x => x.PushItem == "05");
  423. if (informationPushEntity != null && informationPushEntity.Status == true)
  424. {
  425. //微信推送
  426. PushWeixin(title);
  427. }
  428. }
  429. }
  430. catch (Exception e)
  431. {
  432. }
  433. }
  434. }
  435. catch (Exception ex)
  436. {
  437. if (ex is ExceptionEx)
  438. {
  439. throw;
  440. }
  441. else
  442. {
  443. throw ExceptionEx.ThrowServiceException(ex);
  444. }
  445. }
  446. }
  447. /// <summary>
  448. /// 生成对应时间段的测量体温的学生数据
  449. /// <param name="timeType">时间段类型</param>
  450. /// <summary>
  451. /// <returns></returns>
  452. public void CreateMorningStudents(string timeType)
  453. {
  454. try
  455. {
  456. //获取当前登录人
  457. var loginUser = LoginUserInfo.Get();
  458. //根据当前登录人获取所属班级
  459. //var classNo = this.BaseRepository("CollegeMIS")
  460. // .FindEntity<StuInfoBasicEntity>(a => a.StuNo == loginUser.account)?.ClassNo;
  461. var classNo = "201801301";
  462. if (classNo != null)
  463. {
  464. var latestTheEntity = this.BaseRepository("CollegeMIS")
  465. .FindList<ThermographyEntity>(a => a.CreateTime > DateTime.Today && a.MeasureTime == timeType).ToList();
  466. if (latestTheEntity.Count == 0)
  467. {
  468. //根据班号获取所有学生
  469. var students = this.BaseRepository("CollegeMIS")
  470. .FindList<StuInfoBasicEntity>(a => a.ClassNo == classNo);
  471. foreach (var student in students)
  472. {
  473. var thermographyEntity = new ThermographyEntity()
  474. {
  475. ClassNo = student.ClassNo,
  476. MeasureTime = timeType,
  477. PersonBeingMeasured = student.StuNo,
  478. CreateTime = DateTime.Now,
  479. MeasurerID = loginUser.account,
  480. MeasureDate = DateTime.Now,
  481. DeptNo = student.DeptNo,
  482. MajorNo = student.MajorNo,
  483. Status = "0"
  484. };
  485. thermographyEntity.Create(loginUser);
  486. this.BaseRepository("CollegeMIS").Insert(thermographyEntity);
  487. }
  488. }
  489. }
  490. }
  491. catch (Exception ex)
  492. {
  493. if (ex is ExceptionEx)
  494. {
  495. throw;
  496. }
  497. else
  498. {
  499. throw ExceptionEx.ThrowServiceException(ex);
  500. }
  501. }
  502. }
  503. /// <summary>
  504. /// 保存实体数据(新增、修改)
  505. /// <param name="keyValue">主键</param>
  506. /// <summary>
  507. /// <returns></returns>
  508. public void SaveEntityList(string measureTime, List<ThermographyEntity> entities)
  509. {
  510. var db = this.BaseRepository("CollegeMIS");
  511. db.BeginTrans();
  512. try
  513. {
  514. var userInfo = LoginUserInfo.Get();
  515. var now = DateTime.Now;
  516. var nowDate = DateTime.Now.Date;
  517. var nextDate = DateTime.Now.AddDays(1).Date;
  518. var pushTitle = string.Empty;//微信推送标题
  519. foreach (var entity in entities)
  520. {
  521. entity.MeasurerID = userInfo.account;
  522. entity.MeasureDate = now;
  523. entity.MeasureTime = measureTime;
  524. entity.CreateTime = now;
  525. //限制测温时间(上午、中午、晚上)时:判断学生是否已测温,是则更新,否则新增;不限制测温时间时:新增;
  526. if (measureTime != "-1")
  527. {
  528. var model = db.FindEntity<ThermographyEntity>(x => x.PersonBeingMeasured == entity.PersonBeingMeasured && x.MeasureTime == measureTime && x.MeasureDate >= nowDate && x.MeasureDate < nextDate);
  529. if (model != null)
  530. {
  531. db.Delete(model);
  532. }
  533. }
  534. entity.Create(userInfo);
  535. db.Insert(entity);
  536. //体温异常
  537. if (entity.Status == "2")
  538. {
  539. if (string.IsNullOrEmpty(pushTitle))
  540. {
  541. var classModel = db.FindEntity<ClassInfoEntity>(x => x.ClassNo == entity.ClassNo);
  542. pushTitle = string.Format("{0}班级({1})发现异常学生:{2}({3})", classModel?.ClassName, entity.ClassNo, entity.PersonBeingMeasuredName, entity.PersonBeingMeasured);
  543. }
  544. else
  545. {
  546. pushTitle += string.Format(",{0}({1})", entity.PersonBeingMeasuredName, entity.PersonBeingMeasured);
  547. }
  548. }
  549. }
  550. db.Commit();
  551. if (entities.Any(x => x.Status == "2"))
  552. {
  553. //读取信息推送管理-班级自诊打卡体温异常学生推送(05)的配置
  554. var informationPushEntity = this.BaseRepository().FindEntity<Sys_InformationPushEntity>(x => x.PushItem == "05");
  555. if (informationPushEntity != null && informationPushEntity.Status == true)
  556. {
  557. try
  558. {
  559. //微信推送
  560. PushWeixin(pushTitle);
  561. }
  562. catch (Exception)
  563. {
  564. throw;
  565. }
  566. }
  567. }
  568. }
  569. catch (Exception ex)
  570. {
  571. db.Rollback();
  572. if (ex is ExceptionEx)
  573. {
  574. throw;
  575. }
  576. else
  577. {
  578. throw ExceptionEx.ThrowServiceException(ex);
  579. }
  580. }
  581. }
  582. /// <summary>
  583. /// 微信推送
  584. /// </summary>
  585. /// <param name="title"></param>
  586. public void PushWeixin(string title)
  587. {
  588. var EpidemicControlTeamRoleId = Config.GetValue("EpidemicControlTeamRoleId");
  589. if (!string.IsNullOrEmpty(EpidemicControlTeamRoleId))
  590. {
  591. //疫情防控组成员
  592. var userRelationList = this.BaseRepository().FindList<UserRelationEntity>(x => x.F_ObjectId == EpidemicControlTeamRoleId);
  593. //微信配置
  594. var WeChatConfigentity = BaseRepository().FindEntity<WeChatConfigEntity>(m => m.IsEnable == true);
  595. string appid = WeChatConfigentity.APPId;
  596. string secret = WeChatConfigentity.secret;
  597. var wechatemplete = BaseRepository().FindEntity<WeChatTemplateEntity>(m => m.WeID == WeChatConfigentity.ID && m.TCode == "task");
  598. string weixintaskurl = wechatemplete.TUrl;
  599. string weixintasktempid = wechatemplete.TempId;
  600. var responsejson = Util.HttpMethods.HttpGet("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + secret);
  601. LogEntity logEntity = new LogEntity();
  602. logEntity.F_LogId = Guid.NewGuid().ToString();
  603. logEntity.F_Module = "Thermography";
  604. logEntity.F_ExecuteResultJson = "Thermography responsejson=" + responsejson;
  605. logEntity.WriteLog();
  606. foreach (var userRelationItem in userRelationList)
  607. {
  608. var userEntity = this.BaseRepository().FindEntity<UserEntity>(userRelationItem.F_UserId);
  609. if (userEntity != null && !string.IsNullOrEmpty(userEntity.OpenIdForWeixin))
  610. {
  611. //执行推送任务
  612. if (!string.IsNullOrEmpty(appid) && !string.IsNullOrEmpty(secret) && !string.IsNullOrEmpty(weixintaskurl) && !string.IsNullOrEmpty(weixintasktempid))
  613. {
  614. if (!string.IsNullOrEmpty(responsejson))
  615. {
  616. var weixintokenobj = JsonConvert.DeserializeObject<dynamic>(responsejson);
  617. if (string.IsNullOrEmpty(weixintokenobj.errcode))
  618. {
  619. string access_token = weixintokenobj.access_token;
  620. string jsondata = "{\"touser\":\"" + userEntity.OpenIdForWeixin + "\"," +
  621. "\"template_id\":\"" + weixintasktempid + "\"," +
  622. "\"url\":\"" + weixintaskurl + "\"," +
  623. "\"data\":{" +
  624. "\"first\": {\"value\":\"发现体温异常学生\",\"color\":\"#173177\"}," +
  625. "\"keyword1\":{\"value\":\"体温异常学生\",\"color\":\"#173177\"}," +
  626. "\"keyword2\": {\"value\":\"" + title + "\",\"color\":\"#173177\"}," +
  627. "\"keyword3\": {\"value\":\"待查看\",\"color\":\"#173177\"}," +
  628. "\"keyword4\": {\"value\":\"发现体温异常学生【" + title + "】\",\"color\":\"#173177\"}" +
  629. "}" +
  630. "}";
  631. string pushresult = Util.HttpMethods.HttpPost("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token, jsondata);
  632. logEntity = new LogEntity();
  633. logEntity.F_LogId = Guid.NewGuid().ToString();
  634. logEntity.F_Module = "Thermography";
  635. logEntity.F_ExecuteResultJson = "Thermography pushresult=" + pushresult;
  636. logEntity.WriteLog();
  637. }
  638. }
  639. }
  640. }
  641. }
  642. }
  643. }
  644. #endregion
  645. }
  646. }