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 21 KiB

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