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.
 
 
 
 
 
 

635 lines
22 KiB

  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. var expression = LinqExtensions.True<EpidemicSituationEntity>();
  142. var queryParam = queryJson.ToJObject();
  143. // 填表人员
  144. if (!queryParam["Creater"].IsEmpty())
  145. {
  146. string Creater = queryParam["Creater"].ToString();
  147. expression = expression.And(t => t.Creater.Equals(Creater));
  148. }
  149. // 类别
  150. if (!queryParam["Type"].IsEmpty())
  151. {
  152. int Type = 0;
  153. int.TryParse(queryParam["Type"].ToString(), out Type);
  154. expression = expression.And(t => t.Type.Equals(Type));
  155. }
  156. // 学生来源
  157. if (!queryParam["StudentSource"].IsEmpty())
  158. {
  159. string StudentSource = queryParam["StudentSource"].ToString();
  160. expression = expression.And(t => t.StudentSource.Contains(StudentSource));
  161. }
  162. list = this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>(list, expression, pagination).ToList();
  163. return list;
  164. }
  165. catch (Exception ex)
  166. {
  167. if (ex is ExceptionEx)
  168. {
  169. throw;
  170. }
  171. else
  172. {
  173. throw ExceptionEx.ThrowServiceException(ex);
  174. }
  175. }
  176. }
  177. /// <summary>
  178. /// 获取页面显示列表数据
  179. /// <summary>
  180. /// <param name="queryJson">查询参数</param>
  181. /// <returns></returns>
  182. public IEnumerable<EpidemicSituationEntity> GetList(string queryJson)
  183. {
  184. try
  185. {
  186. var strSql = new StringBuilder();
  187. strSql.Append("SELECT ");
  188. strSql.Append(@"
  189. t.ID,
  190. t.Creater,
  191. t.UnitName,
  192. t.BackUser,
  193. t.Type,
  194. t.Department,
  195. t.RelationShip,
  196. t.Gender,
  197. t.IDCard,
  198. t.HomeAddress,
  199. t.Mobile,
  200. t.Provice,
  201. t.Objective,
  202. t.OutReason,
  203. t.OutTime,
  204. t.BackHomeTime,
  205. t.Vehicle,
  206. t.VehicleNum,
  207. t.BackAddress,
  208. t.CreateTime,
  209. t.HealthSituation,
  210. t.OutArea,
  211. t.StudentSource,
  212. t.City,
  213. t.Contacts
  214. ");
  215. strSql.Append(" FROM EpidemicSituation t ");
  216. strSql.Append(" WHERE 1=1 ");
  217. var queryParam = queryJson.ToJObject();
  218. // 虚拟参数
  219. var dp = new DynamicParameters(new { });
  220. if (!queryParam["Creater"].IsEmpty())
  221. {
  222. dp.Add("Creater", "%" + queryParam["Creater"].ToString() + "%", DbType.String);
  223. strSql.Append(" AND t.Creater Like @Creater ");
  224. }
  225. if (!queryParam["Type"].IsEmpty())
  226. {
  227. dp.Add("Type", queryParam["Type"].ToString(), DbType.String);
  228. strSql.Append(" AND t.Type = @Type ");
  229. }
  230. if (!queryParam["IDCard"].IsEmpty())
  231. {
  232. dp.Add("IDCard", "%" + queryParam["IDCard"].ToString() + "%", DbType.String);
  233. strSql.Append(" AND t.IDCard Like @IDCard ");
  234. }
  235. if (!queryParam["UnitName"].IsEmpty())
  236. {
  237. dp.Add("UnitName", "%" + queryParam["UnitName"].ToString() + "%", DbType.String);
  238. strSql.Append(" AND t.UnitName Like @UnitName ");
  239. }
  240. return this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>(strSql.ToString(), dp);
  241. }
  242. catch (Exception ex)
  243. {
  244. if (ex is ExceptionEx)
  245. {
  246. throw;
  247. }
  248. else
  249. {
  250. throw ExceptionEx.ThrowServiceException(ex);
  251. }
  252. }
  253. }
  254. /// <summary>
  255. /// 获取ContactsDetails表数据
  256. /// <summary>
  257. /// <returns></returns>
  258. public IEnumerable<ContactsDetailsEntity> GetContactsDetailsList(string keyValue)
  259. {
  260. try
  261. {
  262. return this.BaseRepository("CollegeMIS").FindList<ContactsDetailsEntity>(t => t.EID == keyValue);
  263. }
  264. catch (Exception ex)
  265. {
  266. if (ex is ExceptionEx)
  267. {
  268. throw;
  269. }
  270. else
  271. {
  272. throw ExceptionEx.ThrowServiceException(ex);
  273. }
  274. }
  275. }
  276. /// <summary>
  277. /// 获取ContactsDetails表数据
  278. /// <summary>
  279. /// <returns></returns>
  280. public IEnumerable<PeopleDetailsEntity> GetPeopleDetailsList(string keyValue)
  281. {
  282. try
  283. {
  284. return this.BaseRepository("CollegeMIS").FindList<PeopleDetailsEntity>(t => t.EID == keyValue);
  285. }
  286. catch (Exception ex)
  287. {
  288. if (ex is ExceptionEx)
  289. {
  290. throw;
  291. }
  292. else
  293. {
  294. throw ExceptionEx.ThrowServiceException(ex);
  295. }
  296. }
  297. }
  298. /// <summary>
  299. /// 获取ContactsDetails表数据
  300. /// <summary>
  301. /// <returns></returns>
  302. public IEnumerable<PassPlaceEntity> GetPassPlaceList(string keyValue)
  303. {
  304. try
  305. {
  306. return this.BaseRepository("CollegeMIS").FindList<PassPlaceEntity>(t => t.EID == keyValue);
  307. }
  308. catch (Exception ex)
  309. {
  310. if (ex is ExceptionEx)
  311. {
  312. throw;
  313. }
  314. else
  315. {
  316. throw ExceptionEx.ThrowServiceException(ex);
  317. }
  318. }
  319. }
  320. /// <summary>
  321. /// 获取ContactsDetails表实体数据
  322. /// <param name="keyValue">主键</param>
  323. /// <summary>
  324. /// <returns></returns>
  325. public ContactsDetailsEntity GetContactsDetailsEntity(string keyValue)
  326. {
  327. try
  328. {
  329. return this.BaseRepository("CollegeMIS").FindEntity<ContactsDetailsEntity>(t => t.EID == keyValue);
  330. }
  331. catch (Exception ex)
  332. {
  333. if (ex is ExceptionEx)
  334. {
  335. throw;
  336. }
  337. else
  338. {
  339. throw ExceptionEx.ThrowServiceException(ex);
  340. }
  341. }
  342. }
  343. /// <summary>
  344. /// 获取ContactsDetails表实体数据
  345. /// <param name="keyValue">主键</param>
  346. /// <summary>
  347. /// <returns></returns>
  348. public PeopleDetailsEntity GetPeopleDetailsEntity(string keyValue)
  349. {
  350. try
  351. {
  352. return this.BaseRepository("CollegeMIS").FindEntity<PeopleDetailsEntity>(t => t.EID == keyValue);
  353. }
  354. catch (Exception ex)
  355. {
  356. if (ex is ExceptionEx)
  357. {
  358. throw;
  359. }
  360. else
  361. {
  362. throw ExceptionEx.ThrowServiceException(ex);
  363. }
  364. }
  365. }
  366. /// <summary>
  367. /// 获取ContactsDetails表实体数据
  368. /// <param name="keyValue">主键</param>
  369. /// <summary>
  370. /// <returns></returns>
  371. public PassPlaceEntity GetPassPlaceEntity(string keyValue)
  372. {
  373. try
  374. {
  375. return this.BaseRepository("CollegeMIS").FindEntity<PassPlaceEntity>(t => t.EID == keyValue);
  376. }
  377. catch (Exception ex)
  378. {
  379. if (ex is ExceptionEx)
  380. {
  381. throw;
  382. }
  383. else
  384. {
  385. throw ExceptionEx.ThrowServiceException(ex);
  386. }
  387. }
  388. }
  389. /// <summary>
  390. /// 获取EpidemicSituation表实体数据
  391. /// <param name="keyValue">主键</param>
  392. /// <summary>
  393. /// <returns></returns>
  394. public EpidemicSituationEntity GetEpidemicSituationEntity(string keyValue)
  395. {
  396. try
  397. {
  398. return this.BaseRepository("CollegeMIS").FindEntity<EpidemicSituationEntity>(keyValue);
  399. }
  400. catch (Exception ex)
  401. {
  402. if (ex is ExceptionEx)
  403. {
  404. throw;
  405. }
  406. else
  407. {
  408. throw ExceptionEx.ThrowServiceException(ex);
  409. }
  410. }
  411. }
  412. #endregion
  413. #region 提交数据
  414. /// <summary>
  415. /// 删除实体数据
  416. /// <param name="keyValue">主键</param>
  417. /// <summary>
  418. /// <returns></returns>
  419. public void DeleteEntity(string keyValue)
  420. {
  421. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  422. try
  423. {
  424. var epidemicSituationEntity = GetEpidemicSituationEntity(keyValue);
  425. db.Delete<EpidemicSituationEntity>(t => t.ID == keyValue);
  426. db.Delete<ContactsDetailsEntity>(t => t.EID == epidemicSituationEntity.ID);
  427. db.Delete<PeopleDetailsEntity>(t => t.EID == epidemicSituationEntity.ID);
  428. db.Delete<PassPlaceEntity>(t => t.EID == epidemicSituationEntity.ID);
  429. db.Commit();
  430. }
  431. catch (Exception ex)
  432. {
  433. db.Rollback();
  434. if (ex is ExceptionEx)
  435. {
  436. throw;
  437. }
  438. else
  439. {
  440. throw ExceptionEx.ThrowServiceException(ex);
  441. }
  442. }
  443. }
  444. /// <summary>
  445. /// 判断今天是否提交过
  446. /// <param name="keyValue">主键</param>
  447. /// <summary>
  448. /// <returns></returns>
  449. public bool HasTodayValue(string userId)
  450. {
  451. try
  452. {
  453. var dataNow = DateTime.Now.Date.ToString();
  454. var list = this.BaseRepository("CollegeMIS").FindList<EpidemicSituationEntity>(a => a.Creater == userId);
  455. var result = false;
  456. foreach (var item in list)
  457. {
  458. if (item.CreateTime.ToDate().Date.ToString() == dataNow)
  459. {
  460. result = true;
  461. }
  462. }
  463. return result;
  464. }
  465. catch (Exception ex)
  466. {
  467. if (ex is ExceptionEx)
  468. {
  469. throw;
  470. }
  471. else
  472. {
  473. throw ExceptionEx.ThrowServiceException(ex);
  474. }
  475. }
  476. }
  477. /// <summary>
  478. /// 保存实体数据(新增、修改)
  479. /// <param name="keyValue">主键</param>
  480. /// <summary>
  481. /// <returns></returns>
  482. public void SaveEntity(UserInfo userInfo, string keyValue, EpidemicSituationEntity entity, List<ContactsDetailsEntity> contactsDetailsList)
  483. {
  484. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  485. try
  486. {
  487. if (!string.IsNullOrEmpty(keyValue))
  488. {
  489. var epidemicSituationEntityTmp = GetEpidemicSituationEntity(keyValue);
  490. entity.Modify(keyValue, userInfo);
  491. db.Update(entity);
  492. db.Delete<ContactsDetailsEntity>(t => t.EID == epidemicSituationEntityTmp.ID);
  493. foreach (ContactsDetailsEntity item in contactsDetailsList)
  494. {
  495. item.Create(userInfo);
  496. item.EID = epidemicSituationEntityTmp.ID;
  497. db.Insert(item);
  498. }
  499. }
  500. else
  501. {
  502. entity.Create(userInfo);
  503. db.Insert(entity);
  504. foreach (ContactsDetailsEntity item in contactsDetailsList)
  505. {
  506. item.Create(userInfo);
  507. item.EID = entity.ID;
  508. db.Insert(item);
  509. }
  510. }
  511. db.Commit();
  512. }
  513. catch (Exception ex)
  514. {
  515. db.Rollback();
  516. if (ex is ExceptionEx)
  517. {
  518. throw;
  519. }
  520. else
  521. {
  522. throw ExceptionEx.ThrowServiceException(ex);
  523. }
  524. }
  525. }
  526. /// <summary>
  527. /// 保存实体数据(新增、修改)
  528. /// <param name="keyValue">主键</param>
  529. /// <summary>
  530. /// <returns></returns>
  531. public void SaveEntity(UserInfo userInfo, string keyValue, EpidemicSituationEntity entity, List<ContactsDetailsEntity> contactsDetailsList, List<PassPlaceEntity> passList, List<PeopleDetailsEntity> peopleDetailsList)
  532. {
  533. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  534. try
  535. {
  536. if (!string.IsNullOrEmpty(keyValue))
  537. {
  538. var epidemicSituationEntityTmp = GetEpidemicSituationEntity(keyValue);
  539. entity.Modify(keyValue, userInfo);
  540. db.Update(entity);
  541. db.Delete<ContactsDetailsEntity>(t => t.EID == epidemicSituationEntityTmp.ID);
  542. db.Delete<PassPlaceEntity>(t => t.EID == epidemicSituationEntityTmp.ID);
  543. db.Delete<PeopleDetailsEntity>(t => t.EID == epidemicSituationEntityTmp.ID);
  544. foreach (ContactsDetailsEntity item in contactsDetailsList)
  545. {
  546. item.Create(userInfo);
  547. item.EID = epidemicSituationEntityTmp.ID;
  548. db.Insert(item);
  549. }
  550. foreach (PeopleDetailsEntity item in peopleDetailsList)
  551. {
  552. item.Create();
  553. item.EID = entity.ID;
  554. db.Insert(item);
  555. }
  556. foreach (var item in passList)
  557. {
  558. item.Create();
  559. item.EID = epidemicSituationEntityTmp.ID;
  560. db.Insert(item);
  561. }
  562. }
  563. else
  564. {
  565. entity.Create(userInfo);
  566. db.Insert(entity);
  567. foreach (ContactsDetailsEntity item in contactsDetailsList)
  568. {
  569. item.Create(userInfo);
  570. item.EID = entity.ID;
  571. db.Insert(item);
  572. }
  573. foreach (PeopleDetailsEntity item in peopleDetailsList)
  574. {
  575. item.Create();
  576. item.EID = entity.ID;
  577. db.Insert(item);
  578. }
  579. foreach (var item in passList)
  580. {
  581. item.Create();
  582. item.EID = entity.ID;
  583. db.Insert(item);
  584. }
  585. }
  586. db.Commit();
  587. }
  588. catch (Exception ex)
  589. {
  590. db.Rollback();
  591. if (ex is ExceptionEx)
  592. {
  593. throw;
  594. }
  595. else
  596. {
  597. throw ExceptionEx.ThrowServiceException(ex);
  598. }
  599. }
  600. }
  601. #endregion
  602. }
  603. }