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.
 
 
 
 
 
 

466 lines
20 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.EducationalAdministration
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
  13. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2022-06-17 11:00
  16. /// 描 述:体温上报
  17. /// </summary>
  18. public class HealthPunchStuService : 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<HealthPunchStuEntity> GetPageList(Pagination pagination, string queryJson)
  28. {
  29. try
  30. {
  31. var strSql = new StringBuilder();
  32. strSql.Append("SELECT ");
  33. strSql.Append(@"* ");
  34. strSql.Append(" FROM HealthPunchStu t ");
  35. strSql.Append(" WHERE 1=1 ");
  36. var queryParam = queryJson.ToJObject();
  37. // 虚拟参数
  38. var dp = new DynamicParameters(new { });
  39. return this.BaseRepository("CollegeMIS").FindList<HealthPunchStuEntity>(strSql.ToString(), dp, pagination);
  40. }
  41. catch (Exception ex)
  42. {
  43. if (ex is ExceptionEx)
  44. {
  45. throw;
  46. }
  47. else
  48. {
  49. throw ExceptionEx.ThrowServiceException(ex);
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 获取HealthPunchStu表实体数据
  55. /// </summary>
  56. /// <param name="keyValue">主键</param>
  57. /// <returns></returns>
  58. public HealthPunchStuEntity GetHealthPunchStuEntity(string keyValue)
  59. {
  60. try
  61. {
  62. return this.BaseRepository("CollegeMIS").FindEntity<HealthPunchStuEntity>(keyValue);
  63. }
  64. catch (Exception ex)
  65. {
  66. if (ex is ExceptionEx)
  67. {
  68. throw;
  69. }
  70. else
  71. {
  72. throw ExceptionEx.ThrowServiceException(ex);
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 获取页面显示列表数据
  78. /// </summary>
  79. /// <param name="pagination">查询参数</param>
  80. /// <param name="queryJson">查询参数</param>
  81. /// <returns></returns>
  82. public IEnumerable<HealthPunchStuEntity> GetStatistics(Pagination pagination, string queryJson)
  83. {
  84. try
  85. {
  86. var strSql = new StringBuilder();
  87. var queryParam = queryJson.ToJObject();
  88. // 虚拟参数
  89. string sql1 = " ";
  90. string sql2 = " ";
  91. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  92. {
  93. sql1 = " and DkDate >= '" + queryParam["StartTime"].ToDate()
  94. + "' and DkDate <= '" + queryParam["EndTime"].ToDate() + "' ";
  95. }
  96. if (!queryParam["F_School"].IsEmpty())
  97. {
  98. sql2 = " and F_School ='" + queryParam["F_School"].ToString() + "' ";
  99. }
  100. if (!queryParam["MajorNo"].IsEmpty())
  101. {
  102. sql2 += " and MajorNo ='" + queryParam["MajorNo"].ToString() + "'";
  103. }
  104. if (!queryParam["ClassNo"].IsEmpty())
  105. {
  106. sql2 += " and ClassNo ='" + queryParam["ClassNo"].ToString() + "'";
  107. }
  108. if (!queryParam["StuNo"].IsEmpty())
  109. {
  110. sql2 += " and StuNo like '%" + queryParam["StuNo"].ToString() + "%'";
  111. }
  112. if (!queryParam["StuName"].IsEmpty())
  113. {
  114. sql2 += " and StuName like '%" + queryParam["StuName"].ToString() + "%'";
  115. }
  116. if (!queryParam["IsStatus"].IsEmpty())
  117. {
  118. string Num = queryParam["IsStatus"].ToString();
  119. if (Num == "0")
  120. {
  121. sql2 += " and t.num = '" + Num + "' ";
  122. }
  123. else if (Num == "1")
  124. {
  125. sql2 += " and t.num < '3' and t.num <> '0' ";
  126. }
  127. else if (Num == "2")
  128. {
  129. sql2 += " and t.num = '3' ";
  130. }
  131. }
  132. strSql.Append(@" select * from (
  133. select zb.F_SchoolId as F_School,zb.MajorNo,zb.ClassNo,zb.StuNo,zb.StuName,zb.mobile,isnull(fb.DkDate,Getdate()) as DkDate,
  134. fb.Address1,fb.Address2,fb.Address3,fb.Temperature1,fb.Temperature2,fb.Temperature3,isnull(fb.Num,0) as Num from StuInfoBasic zb
  135. left join (
  136. select hps.*,aa.address as Address1,aa.Temperature as Temperature1 ,bb.address as Address2,bb.Temperature as Temperature2,cc.address as Address3 ,cc.Temperature
  137. as Temperature3,dd.Num from (
  138. select StuNo,StuName,DkDate from HealthPunchStu hps where 1=1 " + sql1 + "");
  139. strSql.Append(@" group by StuNo,StuName,DkDate) hps
  140. left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
  141. strSql.Append(@" ) AA on AA.StuNo=hps.StuNo and AA.StuName=hps.StuName and AA.dkType=1
  142. left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
  143. strSql.Append(@" ) BB on BB.StuNo=hps.Stuno and BB.StuName=hps.StuName and BB.dkType=2
  144. left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
  145. strSql.Append(@" ) CC on CC.StuNo=hps.Stuno and CC.StuName=hps.StuName and CC.dkType=3
  146. left join (select Stuno,Count(*) as num from HealthPunchStu hps where 1=1 " + sql1 + " ");
  147. strSql.Append(@" group by Stuno ) dd on dd.StuNo=hps.Stuno
  148. ) fb on fb.Stuno = zb.stuno and fb.StuName = zb.StuName
  149. )t where 1= 1 " + sql1 + sql2 + " ");
  150. return this.BaseRepository("CollegeMIS").FindList<HealthPunchStuEntity>(strSql.ToString(), pagination);
  151. }
  152. catch (Exception ex)
  153. {
  154. if (ex is ExceptionEx)
  155. {
  156. throw;
  157. }
  158. else
  159. {
  160. throw ExceptionEx.ThrowServiceException(ex);
  161. }
  162. }
  163. }
  164. /// <summary>
  165. /// 获取页面显示列表数据
  166. /// </summary>
  167. /// <param name="pagination">查询参数</param>
  168. /// <param name="queryJson">查询参数</param>
  169. /// <returns></returns>
  170. public IEnumerable<HealthPunchStuEntity> GetStatisticsTeach(Pagination pagination, string queryJson)
  171. {
  172. try
  173. {
  174. var account = LoginUserInfo.Get().account;
  175. var classinfo = this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(x => x.ClassDiredctorNo == account).ToList();
  176. var strSql = new StringBuilder();
  177. var queryParam = queryJson.ToJObject();
  178. // 虚拟参数
  179. string sql1 = " ";
  180. string sql2 = " ";
  181. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  182. {
  183. sql1 = " and DkDate >= '" + queryParam["StartTime"].ToDate()
  184. + "' and DkDate <= '" + queryParam["EndTime"].ToDate() + "' ";
  185. }
  186. if (classinfo.Count > 0)
  187. {
  188. var classno = classinfo.FirstOrDefault();
  189. if (classinfo.Count == 1)
  190. {
  191. sql2 += " and ClassNo ='" + classno.ClassNo + "'";
  192. }
  193. else
  194. {
  195. sql2 += " and (";
  196. for (int i = 0; i < classinfo.Count; i++)
  197. {
  198. if (i == 0)
  199. {
  200. sql2 += " classno ='" + classinfo[i].ClassNo + "' ";
  201. }
  202. else
  203. {
  204. sql2 += " or classno ='" + classinfo[i].ClassNo + "' ";
  205. }
  206. }
  207. sql2 += ")";
  208. }
  209. }
  210. else
  211. {
  212. sql2 += " and t.num = '-1' ";
  213. }
  214. if (!queryParam["ClassNo"].IsEmpty())
  215. {
  216. sql2 += " and ClassNo ='" + queryParam["ClassNo"].ToString() + "'";
  217. }
  218. if (!queryParam["StuNo"].IsEmpty())
  219. {
  220. sql2 += " and StuNo like '%" + queryParam["StuNo"].ToString() + "%'";
  221. }
  222. if (!queryParam["StuName"].IsEmpty())
  223. {
  224. sql2 += " and StuName like '%" + queryParam["StuName"].ToString() + "%'";
  225. }
  226. if (!queryParam["IsStatus"].IsEmpty())
  227. {
  228. string Num = queryParam["IsStatus"].ToString();
  229. if (Num == "0")
  230. {
  231. sql2 += " and t.num = '" + Num + "' ";
  232. }
  233. else if (Num == "1")
  234. {
  235. sql2 += " and t.num < '3' and t.num <> '0' ";
  236. }
  237. else if (Num == "2")
  238. {
  239. sql2 += " and t.num = '3' ";
  240. }
  241. }
  242. strSql.Append(@" select * from (
  243. select zb.F_SchoolId as F_School,zb.MajorNo,zb.ClassNo,zb.StuNo,zb.StuName,zb.mobile,isnull(fb.DkDate,Getdate()) as DkDate,
  244. fb.Address1,fb.Address2,fb.Address3,fb.Temperature1,fb.Temperature2,fb.Temperature3,isnull(fb.Num,0) as Num from StuInfoBasic zb
  245. left join (
  246. select hps.*,aa.address as Address1,aa.Temperature as Temperature1 ,bb.address as Address2,bb.Temperature as Temperature2,cc.address as Address3 ,cc.Temperature
  247. as Temperature3,dd.Num from (
  248. select StuNo,StuName,DkDate from HealthPunchStu hps where 1=1 " + sql1 + "");
  249. strSql.Append(@" group by StuNo,StuName,DkDate) hps
  250. left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
  251. strSql.Append(@" ) AA on AA.StuNo=hps.StuNo and AA.StuName=hps.StuName and AA.dkType=1
  252. left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
  253. strSql.Append(@" ) BB on BB.StuNo=hps.Stuno and BB.StuName=hps.StuName and BB.dkType=2
  254. left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
  255. strSql.Append(@" ) CC on CC.StuNo=hps.Stuno and CC.StuName=hps.StuName and CC.dkType=3
  256. left join (select Stuno,Count(*) as num from HealthPunchStu hps where 1=1 " + sql1 + " ");
  257. strSql.Append(@" group by Stuno ) dd on dd.StuNo=hps.Stuno
  258. ) fb on fb.Stuno = zb.stuno and fb.StuName = zb.StuName
  259. )t where 1= 1 " + sql1 + sql2 + " ");
  260. return this.BaseRepository("CollegeMIS").FindList<HealthPunchStuEntity>(strSql.ToString(), pagination);
  261. }
  262. catch (Exception ex)
  263. {
  264. if (ex is ExceptionEx)
  265. {
  266. throw;
  267. }
  268. else
  269. {
  270. throw ExceptionEx.ThrowServiceException(ex);
  271. }
  272. }
  273. }
  274. #endregion
  275. #region 提交数据
  276. /// <summary>
  277. /// 删除实体数据
  278. /// </summary>
  279. /// <param name="keyValue">主键</param>
  280. public void DeleteEntity(string keyValue)
  281. {
  282. try
  283. {
  284. this.BaseRepository("CollegeMIS").Delete<HealthPunchStuEntity>(t => t.ID == 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. /// 保存实体数据(新增、修改)
  300. /// </summary>
  301. /// <param name="keyValue">主键</param>
  302. /// <param name="entity">实体</param>
  303. public void SaveEntity(string keyValue, HealthPunchStuEntity entity)
  304. {
  305. try
  306. {
  307. var userInfo = LoginUserInfo.Get();
  308. var stuInfo = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(x => x.StuNo == userInfo.account);
  309. if (stuInfo != null)
  310. {
  311. entity.StuNo = stuInfo.StuNo;
  312. entity.StuName = userInfo.realName;
  313. entity.Phone = stuInfo.mobile;
  314. entity.F_School = stuInfo.F_SchoolId;
  315. entity.DeptNo = stuInfo.DeptNo;
  316. entity.MajorNo = stuInfo.MajorNo;
  317. entity.ClassNo = stuInfo.ClassNo;
  318. entity.Grade = stuInfo.Grade;
  319. entity.Sex = Convert.ToInt32(stuInfo.GenderNo);
  320. entity.CreateTime = DateTime.Now;
  321. entity.DKDate = DateTime.Now;
  322. entity.Year = DateTime.Now.Year.ToString();
  323. entity.Moth = DateTime.Now.Month.ToString();
  324. entity.Day = DateTime.Now.Day.ToString();
  325. }
  326. entity.Create();
  327. this.BaseRepository("CollegeMIS").Insert(entity);
  328. }
  329. catch (Exception ex)
  330. {
  331. if (ex is ExceptionEx)
  332. {
  333. throw;
  334. }
  335. else
  336. {
  337. throw ExceptionEx.ThrowServiceException(ex);
  338. }
  339. }
  340. }
  341. public string PunchCard(string keyValue, HealthPunchStuEntity entity)
  342. {
  343. try
  344. {
  345. //获取打卡规则
  346. var dktime1 = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchTimeEntity>(x => x.CheckMark == 0 && x.Description == "1");
  347. var dktime2 = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchTimeEntity>(x => x.CheckMark == 0 && x.Description == "2");
  348. var dktime3 = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchTimeEntity>(x => x.CheckMark == 0 && x.Description == "3");
  349. var datenow = DateTime.Now.ToString("yyyy-MM-dd");
  350. DateTime Nowdate = DateTime.Now;
  351. DateTime todyTime = DateTime.Now.Date;
  352. var userInfo = LoginUserInfo.Get();
  353. if (dktime1 != null && dktime2 != null && dktime3 != null)
  354. {
  355. DateTime Startime1 = Convert.ToDateTime(datenow + " " + dktime1.StarTime);
  356. DateTime Startime2 = Convert.ToDateTime(datenow + " " + dktime1.EndTime);
  357. DateTime Startime3 = Convert.ToDateTime(datenow + " " + dktime2.StarTime);
  358. DateTime Startime4 = Convert.ToDateTime(datenow + " " + dktime2.EndTime);
  359. DateTime Startime5 = Convert.ToDateTime(datenow + " " + dktime3.StarTime);
  360. DateTime Startime6 = Convert.ToDateTime(datenow + " " + dktime3.EndTime);
  361. #region 学生数据
  362. var stuInfo = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(x => x.StuNo == userInfo.account);
  363. if (stuInfo != null)
  364. {
  365. entity.StuNo = stuInfo.StuNo;
  366. entity.StuName = userInfo.realName;
  367. entity.Phone = stuInfo.mobile;
  368. entity.F_School = stuInfo.F_SchoolId;
  369. entity.DeptNo = stuInfo.DeptNo;
  370. entity.MajorNo = stuInfo.MajorNo;
  371. entity.ClassNo = stuInfo.ClassNo;
  372. entity.Grade = stuInfo.Grade;
  373. entity.Sex = Convert.ToInt32(stuInfo.GenderNo);
  374. entity.CreateTime = DateTime.Now;
  375. entity.DKDate = DateTime.Now;
  376. entity.Year = DateTime.Now.Year.ToString();
  377. entity.Moth = DateTime.Now.Month.ToString();
  378. entity.Day = DateTime.Now.Day.ToString();
  379. }
  380. else
  381. {
  382. return "学生数据不存在!";
  383. }
  384. #endregion
  385. if (Startime1 <= Nowdate && Startime2 >= Nowdate) //早上打卡
  386. {
  387. var HealthPunchStu = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchStuEntity>(x => x.DKDate == todyTime && x.DKType == "1" && x.StuNo == userInfo.account);
  388. if (HealthPunchStu == null)
  389. {
  390. entity.DKType = "1";
  391. }
  392. else
  393. {
  394. return "请勿重复打卡!";
  395. }
  396. }
  397. else if (Startime3 <= Nowdate && Startime4 >= Nowdate)
  398. {
  399. var HealthPunchStu = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchStuEntity>(x => x.DKDate == todyTime && x.DKType == "2" && x.StuNo == userInfo.account);
  400. if (HealthPunchStu == null)
  401. {
  402. entity.DKType = "2";
  403. }
  404. else
  405. {
  406. return "请勿重复打卡!";
  407. }
  408. }
  409. else if (Startime5 <= Nowdate && Startime6 >= Nowdate)
  410. {
  411. var HealthPunchStu = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchStuEntity>(x => x.DKDate == todyTime && x.DKType == "3" && x.StuNo == userInfo.account);
  412. if (HealthPunchStu == null)
  413. {
  414. entity.DKType = "3";
  415. }
  416. else
  417. {
  418. return "请勿重复打卡";
  419. }
  420. }
  421. else
  422. {
  423. return "请在规定的时间段内打卡!";
  424. }
  425. }
  426. else
  427. {
  428. return "请先设置打卡时间";
  429. }
  430. entity.Create();
  431. this.BaseRepository("CollegeMIS").Insert(entity);
  432. return "保存成功";
  433. }
  434. catch (Exception ex)
  435. {
  436. if (ex is ExceptionEx)
  437. {
  438. throw;
  439. }
  440. else
  441. {
  442. throw ExceptionEx.ThrowServiceException(ex);
  443. }
  444. }
  445. }
  446. #endregion
  447. }
  448. }