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.

EpidemicSituationService.cs 22 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. using Dapper;
  2. using Learun.DataBase.Repository;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using Learun.Application.Organization;
  10. using Learun.Application.TwoDevelopment.EducationalAdministration;
  11. namespace Learun.Application.TwoDevelopment.PersonnelManagement
  12. {
  13. /// <summary>
  14. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  15. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  16. /// 创 建:超级管理员
  17. /// 日 期:2020-02-03 14:37
  18. /// 描 述:疫情记录
  19. /// </summary>
  20. public class EpidemicSituationService : RepositoryFactory
  21. {
  22. #region 获取数据
  23. /// <summary>
  24. /// 获取页面显示列表分页数据
  25. /// <summary>
  26. /// <param name="pagination">分页参数</param>
  27. /// <param name="queryJson">查询参数</param>
  28. /// <returns></returns>
  29. public IEnumerable<EpidemicSituationEntity> GetPageList(Pagination pagination, string queryJson)
  30. {
  31. try
  32. {
  33. var strSql = new StringBuilder();
  34. strSql.Append("SELECT ");
  35. strSql.Append(@"
  36. t.ID,
  37. t.Creater,
  38. t.UnitName,
  39. t.BackUser,
  40. t.Type,
  41. t.Department,
  42. t.RelationShip,
  43. t.Gender,
  44. t.IDCard,
  45. t.HomeAddress,
  46. t.Mobile,
  47. t.Provice,
  48. t.Objective,
  49. t.OutReason,
  50. t.OutTime,
  51. t.BackHomeTime,
  52. t.Vehicle,
  53. t.VehicleNum,
  54. t.BackAddress,
  55. t.CreateTime,
  56. t.HealthSituation,
  57. t.OutArea,
  58. t.City,
  59. t.IsOut,
  60. t.HasFamily,
  61. t.HasPeople,
  62. t.StudentSource,
  63. t.Contacts,d.ClassDiredctorNo
  64. ");
  65. strSql.Append(" FROM EpidemicSituation t left join "+ BaseRepository().getDbConnection().Database+ ".dbo.LR_Base_User b on t.Creater=b.F_UserId left join stuinfobasic c on b.F_EnCode=c.stuno left join classinfo d on c.classno=d.classno ");
  66. strSql.Append(" WHERE 1=1 ");
  67. var queryParam = queryJson.ToJObject();
  68. // 虚拟参数
  69. var dp = new DynamicParameters(new { });
  70. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  71. {
  72. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  73. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  74. strSql.Append(" AND ( t.CreateTime >= @startTime AND t.CreateTime <= @endTime ) ");
  75. }
  76. if (!queryParam["Creater"].IsEmpty())
  77. {
  78. dp.Add("Creater", "%"+queryParam["Creater"].ToString()+"%", DbType.String);
  79. strSql.Append(" AND c.StuName like @Creater ");
  80. }
  81. if (!queryParam["Type"].IsEmpty())
  82. {
  83. dp.Add("Type", queryParam["Type"].ToString(), DbType.String);
  84. strSql.Append(" AND t.Type = @Type ");
  85. }
  86. if (!queryParam["IDCard"].IsEmpty())
  87. {
  88. dp.Add("IDCard", "%" + queryParam["IDCard"].ToString() + "%", DbType.String);
  89. strSql.Append(" AND t.IDCard Like @IDCard ");
  90. }
  91. if (!queryParam["UnitName"].IsEmpty())
  92. {
  93. dp.Add("UnitName", "%" + queryParam["UnitName"].ToString() + "%", DbType.String);
  94. strSql.Append(" AND t.UnitName Like @UnitName ");
  95. }
  96. return this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>(strSql.ToString(), dp, pagination);
  97. }
  98. catch (Exception ex)
  99. {
  100. if (ex is ExceptionEx)
  101. {
  102. throw;
  103. }
  104. else
  105. {
  106. throw ExceptionEx.ThrowServiceException(ex);
  107. }
  108. }
  109. }
  110. /// <summary>
  111. /// 获取页面显示列表分页数据
  112. /// <summary>
  113. /// <param name="pagination">分页参数</param>
  114. /// <param name="queryJson">查询参数</param>
  115. /// <returns></returns>
  116. public List<EpidemicSituationEntity> GetReportPageList(Pagination pagination, string queryJson)
  117. {
  118. try
  119. {
  120. var dangerPlace = "330000,440000,500000,310000,420100,510100,513423,513435".Split(',').ToList();
  121. var dangerEID = this.BaseRepository("CollegeMIS").FindList<PassPlaceEntity>(a =>
  122. dangerPlace.Contains(a.Province) || dangerPlace.Contains(a.City) || dangerPlace.Contains(a.Area))
  123. .Select(a => a.EID).Distinct().ToList();
  124. var allEpiList = this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>();
  125. var allUserID = allEpiList.GroupBy(a => a.Creater).Select(a => a.Key);
  126. var dangerUserID = this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>(a => dangerEID.Contains(a.ID)).GroupBy(a => a.Creater).Select(a => a.Key).ToList();
  127. var list = new List<EpidemicSituationEntity>();
  128. foreach (var item in allUserID)
  129. {
  130. var entity = allEpiList.FirstOrDefault(a => a.Creater == item);
  131. if (dangerUserID.Contains(entity.Creater))
  132. {
  133. entity.IsGoDangerPlace = true;
  134. }
  135. if (allEpiList.Any(a => a.Creater == item && a.IsOut == 1))
  136. {
  137. entity.IsOut = 1;
  138. }
  139. if (allEpiList.Any(a => a.Creater == item && a.HasFamily == 1))
  140. {
  141. entity.HasFamily = 1;
  142. }
  143. if (allEpiList.Any(a => a.Creater == item && a.HasPeople == 1))
  144. {
  145. entity.HasPeople = 1;
  146. }
  147. list.Add(entity);
  148. }
  149. var expression = LinqExtensions.True<EpidemicSituationEntity>();
  150. var queryParam = queryJson.ToJObject();
  151. // 填表人员
  152. if (!queryParam["Creater"].IsEmpty())
  153. {
  154. string Creater = queryParam["Creater"].ToString();
  155. var studentlist = BaseRepository().FindList<UserEntity>(m=>m.F_RealName.Contains(Creater));
  156. expression = expression.And(t => studentlist.Any(m=>m.F_UserId== t.Creater));
  157. }
  158. // 类别
  159. if (!queryParam["Type"].IsEmpty())
  160. {
  161. int Type = 0;
  162. int.TryParse(queryParam["Type"].ToString(), out Type);
  163. expression = expression.And(t => t.Type.Equals(Type));
  164. }
  165. // 学生来源
  166. if (!queryParam["StudentSource"].IsEmpty())
  167. {
  168. string StudentSource = queryParam["StudentSource"].ToString();
  169. expression = expression.And(t => t.StudentSource.Contains(StudentSource));
  170. }
  171. list = this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>(list, expression, pagination).ToList();
  172. return list;
  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. /// 获取页面显示列表数据
  188. /// <summary>
  189. /// <param name="queryJson">查询参数</param>
  190. /// <returns></returns>
  191. public IEnumerable<EpidemicSituationEntity> GetList(string queryJson)
  192. {
  193. try
  194. {
  195. var strSql = new StringBuilder();
  196. strSql.Append("SELECT ");
  197. strSql.Append(@"
  198. t.ID,
  199. t.Creater,
  200. t.UnitName,
  201. t.BackUser,
  202. t.Type,
  203. t.Department,
  204. t.RelationShip,
  205. t.Gender,
  206. t.IDCard,
  207. t.HomeAddress,
  208. t.Mobile,
  209. t.Provice,
  210. t.Objective,
  211. t.OutReason,
  212. t.OutTime,
  213. t.BackHomeTime,
  214. t.Vehicle,
  215. t.VehicleNum,
  216. t.BackAddress,
  217. t.CreateTime,
  218. t.HealthSituation,
  219. t.OutArea,
  220. t.StudentSource,
  221. t.City,
  222. t.Contacts
  223. ");
  224. strSql.Append(" FROM EpidemicSituation t ");
  225. strSql.Append(" WHERE 1=1 ");
  226. var queryParam = queryJson.ToJObject();
  227. // 虚拟参数
  228. var dp = new DynamicParameters(new { });
  229. if (!queryParam["Creater"].IsEmpty())
  230. {
  231. dp.Add("Creater", "%" + queryParam["Creater"].ToString() + "%", DbType.String);
  232. strSql.Append(" AND t.Creater Like @Creater ");
  233. }
  234. if (!queryParam["Type"].IsEmpty())
  235. {
  236. dp.Add("Type", queryParam["Type"].ToString(), DbType.String);
  237. strSql.Append(" AND t.Type = @Type ");
  238. }
  239. if (!queryParam["IDCard"].IsEmpty())
  240. {
  241. dp.Add("IDCard", "%" + queryParam["IDCard"].ToString() + "%", DbType.String);
  242. strSql.Append(" AND t.IDCard Like @IDCard ");
  243. }
  244. if (!queryParam["UnitName"].IsEmpty())
  245. {
  246. dp.Add("UnitName", "%" + queryParam["UnitName"].ToString() + "%", DbType.String);
  247. strSql.Append(" AND t.UnitName Like @UnitName ");
  248. }
  249. return this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>(strSql.ToString(), dp);
  250. }
  251. catch (Exception ex)
  252. {
  253. if (ex is ExceptionEx)
  254. {
  255. throw;
  256. }
  257. else
  258. {
  259. throw ExceptionEx.ThrowServiceException(ex);
  260. }
  261. }
  262. }
  263. /// <summary>
  264. /// 获取ContactsDetails表数据
  265. /// <summary>
  266. /// <returns></returns>
  267. public IEnumerable<ContactsDetailsEntity> GetContactsDetailsList(string keyValue)
  268. {
  269. try
  270. {
  271. return this.BaseRepository("CollegeMIS").FindList<ContactsDetailsEntity>(t => t.EID == keyValue);
  272. }
  273. catch (Exception ex)
  274. {
  275. if (ex is ExceptionEx)
  276. {
  277. throw;
  278. }
  279. else
  280. {
  281. throw ExceptionEx.ThrowServiceException(ex);
  282. }
  283. }
  284. }
  285. /// <summary>
  286. /// 获取ContactsDetails表数据
  287. /// <summary>
  288. /// <returns></returns>
  289. public IEnumerable<PeopleDetailsEntity> GetPeopleDetailsList(string keyValue)
  290. {
  291. try
  292. {
  293. return this.BaseRepository("CollegeMIS").FindList<PeopleDetailsEntity>(t => t.EID == keyValue);
  294. }
  295. catch (Exception ex)
  296. {
  297. if (ex is ExceptionEx)
  298. {
  299. throw;
  300. }
  301. else
  302. {
  303. throw ExceptionEx.ThrowServiceException(ex);
  304. }
  305. }
  306. }
  307. /// <summary>
  308. /// 获取ContactsDetails表数据
  309. /// <summary>
  310. /// <returns></returns>
  311. public IEnumerable<PassPlaceEntity> GetPassPlaceList(string keyValue)
  312. {
  313. try
  314. {
  315. return this.BaseRepository("CollegeMIS").FindList<PassPlaceEntity>(t => t.EID == keyValue);
  316. }
  317. catch (Exception ex)
  318. {
  319. if (ex is ExceptionEx)
  320. {
  321. throw;
  322. }
  323. else
  324. {
  325. throw ExceptionEx.ThrowServiceException(ex);
  326. }
  327. }
  328. }
  329. /// <summary>
  330. /// 获取ContactsDetails表实体数据
  331. /// <param name="keyValue">主键</param>
  332. /// <summary>
  333. /// <returns></returns>
  334. public ContactsDetailsEntity GetContactsDetailsEntity(string keyValue)
  335. {
  336. try
  337. {
  338. return this.BaseRepository("CollegeMIS").FindEntity<ContactsDetailsEntity>(t => t.EID == keyValue);
  339. }
  340. catch (Exception ex)
  341. {
  342. if (ex is ExceptionEx)
  343. {
  344. throw;
  345. }
  346. else
  347. {
  348. throw ExceptionEx.ThrowServiceException(ex);
  349. }
  350. }
  351. }
  352. /// <summary>
  353. /// 获取ContactsDetails表实体数据
  354. /// <param name="keyValue">主键</param>
  355. /// <summary>
  356. /// <returns></returns>
  357. public PeopleDetailsEntity GetPeopleDetailsEntity(string keyValue)
  358. {
  359. try
  360. {
  361. return this.BaseRepository("CollegeMIS").FindEntity<PeopleDetailsEntity>(t => t.EID == keyValue);
  362. }
  363. catch (Exception ex)
  364. {
  365. if (ex is ExceptionEx)
  366. {
  367. throw;
  368. }
  369. else
  370. {
  371. throw ExceptionEx.ThrowServiceException(ex);
  372. }
  373. }
  374. }
  375. /// <summary>
  376. /// 获取ContactsDetails表实体数据
  377. /// <param name="keyValue">主键</param>
  378. /// <summary>
  379. /// <returns></returns>
  380. public PassPlaceEntity GetPassPlaceEntity(string keyValue)
  381. {
  382. try
  383. {
  384. return this.BaseRepository("CollegeMIS").FindEntity<PassPlaceEntity>(t => t.EID == keyValue);
  385. }
  386. catch (Exception ex)
  387. {
  388. if (ex is ExceptionEx)
  389. {
  390. throw;
  391. }
  392. else
  393. {
  394. throw ExceptionEx.ThrowServiceException(ex);
  395. }
  396. }
  397. }
  398. /// <summary>
  399. /// 获取EpidemicSituation表实体数据
  400. /// <param name="keyValue">主键</param>
  401. /// <summary>
  402. /// <returns></returns>
  403. public EpidemicSituationEntity GetEpidemicSituationEntity(string keyValue)
  404. {
  405. try
  406. {
  407. return this.BaseRepository("CollegeMIS").FindEntity<EpidemicSituationEntity>(keyValue);
  408. }
  409. catch (Exception ex)
  410. {
  411. if (ex is ExceptionEx)
  412. {
  413. throw;
  414. }
  415. else
  416. {
  417. throw ExceptionEx.ThrowServiceException(ex);
  418. }
  419. }
  420. }
  421. #endregion
  422. #region 提交数据
  423. /// <summary>
  424. /// 删除实体数据
  425. /// <param name="keyValue">主键</param>
  426. /// <summary>
  427. /// <returns></returns>
  428. public void DeleteEntity(string keyValue)
  429. {
  430. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  431. try
  432. {
  433. var epidemicSituationEntity = GetEpidemicSituationEntity(keyValue);
  434. db.Delete<EpidemicSituationEntity>(t => t.ID == keyValue);
  435. db.Delete<ContactsDetailsEntity>(t => t.EID == epidemicSituationEntity.ID);
  436. db.Delete<PeopleDetailsEntity>(t => t.EID == epidemicSituationEntity.ID);
  437. db.Delete<PassPlaceEntity>(t => t.EID == epidemicSituationEntity.ID);
  438. db.Commit();
  439. }
  440. catch (Exception ex)
  441. {
  442. db.Rollback();
  443. if (ex is ExceptionEx)
  444. {
  445. throw;
  446. }
  447. else
  448. {
  449. throw ExceptionEx.ThrowServiceException(ex);
  450. }
  451. }
  452. }
  453. /// <summary>
  454. /// 判断今天是否提交过
  455. /// <param name="keyValue">主键</param>
  456. /// <summary>
  457. /// <returns></returns>
  458. public bool HasTodayValue(string userId)
  459. {
  460. try
  461. {
  462. var dataNow = DateTime.Now.Date.ToString();
  463. var list = this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>(a => a.Creater == userId);
  464. var result = false;
  465. foreach (var item in list)
  466. {
  467. if (item.CreateTime.ToDate().Date.ToString() == dataNow)
  468. {
  469. result = true;
  470. }
  471. }
  472. return result;
  473. }
  474. catch (Exception ex)
  475. {
  476. if (ex is ExceptionEx)
  477. {
  478. throw;
  479. }
  480. else
  481. {
  482. throw ExceptionEx.ThrowServiceException(ex);
  483. }
  484. }
  485. }
  486. /// <summary>
  487. /// 保存实体数据(新增、修改)
  488. /// <param name="keyValue">主键</param>
  489. /// <summary>
  490. /// <returns></returns>
  491. public void SaveEntity(UserInfo userInfo, string keyValue, EpidemicSituationEntity entity, List<ContactsDetailsEntity> contactsDetailsList)
  492. {
  493. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  494. try
  495. {
  496. if (!string.IsNullOrEmpty(keyValue))
  497. {
  498. var epidemicSituationEntityTmp = GetEpidemicSituationEntity(keyValue);
  499. entity.Modify(keyValue, userInfo);
  500. db.Update(entity);
  501. db.Delete<ContactsDetailsEntity>(t => t.EID == epidemicSituationEntityTmp.ID);
  502. foreach (ContactsDetailsEntity item in contactsDetailsList)
  503. {
  504. item.Create(userInfo);
  505. item.EID = epidemicSituationEntityTmp.ID;
  506. db.Insert(item);
  507. }
  508. }
  509. else
  510. {
  511. entity.Create(userInfo);
  512. db.Insert(entity);
  513. foreach (ContactsDetailsEntity item in contactsDetailsList)
  514. {
  515. item.Create(userInfo);
  516. item.EID = entity.ID;
  517. db.Insert(item);
  518. }
  519. }
  520. db.Commit();
  521. }
  522. catch (Exception ex)
  523. {
  524. db.Rollback();
  525. if (ex is ExceptionEx)
  526. {
  527. throw;
  528. }
  529. else
  530. {
  531. throw ExceptionEx.ThrowServiceException(ex);
  532. }
  533. }
  534. }
  535. /// <summary>
  536. /// 保存实体数据(新增、修改)
  537. /// <param name="keyValue">主键</param>
  538. /// <summary>
  539. /// <returns></returns>
  540. public void SaveEntity(UserInfo userInfo, string keyValue, EpidemicSituationEntity entity, List<ContactsDetailsEntity> contactsDetailsList, List<PassPlaceEntity> passList, List<PeopleDetailsEntity> peopleDetailsList)
  541. {
  542. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  543. try
  544. {
  545. if (!string.IsNullOrEmpty(keyValue))
  546. {
  547. var epidemicSituationEntityTmp = GetEpidemicSituationEntity(keyValue);
  548. entity.Modify(keyValue, userInfo);
  549. db.Update(entity);
  550. db.Delete<ContactsDetailsEntity>(t => t.EID == epidemicSituationEntityTmp.ID);
  551. db.Delete<PassPlaceEntity>(t => t.EID == epidemicSituationEntityTmp.ID);
  552. db.Delete<PeopleDetailsEntity>(t => t.EID == epidemicSituationEntityTmp.ID);
  553. foreach (ContactsDetailsEntity item in contactsDetailsList)
  554. {
  555. item.Create(userInfo);
  556. item.EID = epidemicSituationEntityTmp.ID;
  557. db.Insert(item);
  558. }
  559. foreach (PeopleDetailsEntity item in peopleDetailsList)
  560. {
  561. item.Create();
  562. item.EID = entity.ID;
  563. db.Insert(item);
  564. }
  565. foreach (var item in passList)
  566. {
  567. item.Create();
  568. item.EID = epidemicSituationEntityTmp.ID;
  569. db.Insert(item);
  570. }
  571. }
  572. else
  573. {
  574. entity.Create(userInfo);
  575. db.Insert(entity);
  576. foreach (ContactsDetailsEntity item in contactsDetailsList)
  577. {
  578. item.Create(userInfo);
  579. item.EID = entity.ID;
  580. db.Insert(item);
  581. }
  582. foreach (PeopleDetailsEntity item in peopleDetailsList)
  583. {
  584. item.Create();
  585. item.EID = entity.ID;
  586. db.Insert(item);
  587. }
  588. foreach (var item in passList)
  589. {
  590. item.Create();
  591. item.EID = entity.ID;
  592. db.Insert(item);
  593. }
  594. }
  595. db.Commit();
  596. }
  597. catch (Exception ex)
  598. {
  599. db.Rollback();
  600. if (ex is ExceptionEx)
  601. {
  602. throw;
  603. }
  604. else
  605. {
  606. throw ExceptionEx.ThrowServiceException(ex);
  607. }
  608. }
  609. }
  610. #endregion
  611. }
  612. }