|
- using Dapper;
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Linq;
- using System.Text;
-
- namespace Learun.Application.TwoDevelopment.EducationalAdministration
- {
- /// <summary>
- /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
- /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- /// 创 建:超级管理员
- /// 日 期:2022-06-17 11:00
- /// 描 述:体温上报
- /// </summary>
- public class HealthPunchStuService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">查询参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<HealthPunchStuEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT ");
- strSql.Append(@"* ");
- strSql.Append(" FROM HealthPunchStu t ");
- strSql.Append(" WHERE 1=1 ");
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- var dp = new DynamicParameters(new { });
- return this.BaseRepository("CollegeMIS").FindList<HealthPunchStuEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取HealthPunchStu表实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public HealthPunchStuEntity GetHealthPunchStuEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<HealthPunchStuEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">查询参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<HealthPunchStuEntity> GetStatistics(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- string sql1 = " ";
- string sql2 = " ";
- if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
- {
- sql1 = " and DkDate >= '" + queryParam["StartTime"].ToDate()
- + "' and DkDate <= '" + queryParam["EndTime"].ToDate() + "' ";
- }
- if (!queryParam["F_School"].IsEmpty())
- {
- sql2 = " and F_School ='" + queryParam["F_School"].ToString() + "' ";
- }
- if (!queryParam["MajorNo"].IsEmpty())
- {
- sql2 += " and MajorNo ='" + queryParam["MajorNo"].ToString() + "'";
- }
- if (!queryParam["ClassNo"].IsEmpty())
- {
- sql2 += " and ClassNo ='" + queryParam["ClassNo"].ToString() + "'";
- }
-
- if (!queryParam["StuNo"].IsEmpty())
- {
- sql2 += " and StuNo like '%" + queryParam["StuNo"].ToString() + "%'";
- }
- if (!queryParam["StuName"].IsEmpty())
- {
- sql2 += " and StuName like '%" + queryParam["StuName"].ToString() + "%'";
- }
- if (!queryParam["IsStatus"].IsEmpty())
- {
- string Num = queryParam["IsStatus"].ToString();
- if (Num == "0")
- {
- sql2 += " and t.num = '" + Num + "' ";
- }
- else if (Num == "1")
- {
- sql2 += " and t.num < '3' and t.num <> '0' ";
- }
- else if (Num == "2")
- {
- sql2 += " and t.num = '3' ";
- }
- }
-
- strSql.Append(@" select * from (
- select zb.F_SchoolId as F_School,zb.MajorNo,zb.ClassNo,zb.StuNo,zb.StuName,zb.mobile,isnull(fb.DkDate,Getdate()) as DkDate,
- fb.Address1,fb.Address2,fb.Address3,fb.Temperature1,fb.Temperature2,fb.Temperature3,isnull(fb.Num,0) as Num from StuInfoBasic zb
- left join (
- select hps.*,aa.address as Address1,aa.Temperature as Temperature1 ,bb.address as Address2,bb.Temperature as Temperature2,cc.address as Address3 ,cc.Temperature
- as Temperature3,dd.Num from (
- select StuNo,StuName,DkDate from HealthPunchStu hps where 1=1 " + sql1 + "");
- strSql.Append(@" group by StuNo,StuName,DkDate) hps
- left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
- strSql.Append(@" ) AA on AA.StuNo=hps.StuNo and AA.StuName=hps.StuName and AA.dkType=1
- left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
- strSql.Append(@" ) BB on BB.StuNo=hps.Stuno and BB.StuName=hps.StuName and BB.dkType=2
- left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
- strSql.Append(@" ) CC on CC.StuNo=hps.Stuno and CC.StuName=hps.StuName and CC.dkType=3
- left join (select Stuno,Count(*) as num from HealthPunchStu hps where 1=1 " + sql1 + " ");
- strSql.Append(@" group by Stuno ) dd on dd.StuNo=hps.Stuno
- ) fb on fb.Stuno = zb.stuno and fb.StuName = zb.StuName
- )t where 1= 1 " + sql1 + sql2 + " ");
- return this.BaseRepository("CollegeMIS").FindList<HealthPunchStuEntity>(strSql.ToString(), pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">查询参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<HealthPunchStuEntity> GetStatisticsTeach(Pagination pagination, string queryJson)
- {
- try
- {
- var account = LoginUserInfo.Get().account;
- var classinfo = this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(x => x.ClassDiredctorNo == account).ToList();
- var strSql = new StringBuilder();
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- string sql1 = " ";
- string sql2 = " ";
- if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
- {
- sql1 = " and DkDate >= '" + queryParam["StartTime"].ToDate()
- + "' and DkDate <= '" + queryParam["EndTime"].ToDate() + "' ";
- }
- if (classinfo.Count > 0)
- {
- var classno = classinfo.FirstOrDefault();
- if (classinfo.Count == 1)
- {
- sql2 += " and ClassNo ='" + classno.ClassNo + "'";
- }
- else
- {
- sql2 += " and (";
- for (int i = 0; i < classinfo.Count; i++)
- {
- if (i == 0)
- {
- sql2 += " classno ='" + classinfo[i].ClassNo + "' ";
- }
- else
- {
- sql2 += " or classno ='" + classinfo[i].ClassNo + "' ";
- }
- }
- sql2 += ")";
- }
- }
- else
- {
- sql2 += " and t.num = '-1' ";
- }
- if (!queryParam["ClassNo"].IsEmpty())
- {
- sql2 += " and ClassNo ='" + queryParam["ClassNo"].ToString() + "'";
- }
- if (!queryParam["StuNo"].IsEmpty())
- {
- sql2 += " and StuNo like '%" + queryParam["StuNo"].ToString() + "%'";
- }
- if (!queryParam["StuName"].IsEmpty())
- {
- sql2 += " and StuName like '%" + queryParam["StuName"].ToString() + "%'";
- }
- if (!queryParam["IsStatus"].IsEmpty())
- {
- string Num = queryParam["IsStatus"].ToString();
- if (Num == "0")
- {
- sql2 += " and t.num = '" + Num + "' ";
- }
- else if (Num == "1")
- {
- sql2 += " and t.num < '3' and t.num <> '0' ";
- }
- else if (Num == "2")
- {
- sql2 += " and t.num = '3' ";
- }
- }
-
- strSql.Append(@" select * from (
- select zb.F_SchoolId as F_School,zb.MajorNo,zb.ClassNo,zb.StuNo,zb.StuName,zb.mobile,isnull(fb.DkDate,Getdate()) as DkDate,
- fb.Address1,fb.Address2,fb.Address3,fb.Temperature1,fb.Temperature2,fb.Temperature3,isnull(fb.Num,0) as Num from StuInfoBasic zb
- left join (
- select hps.*,aa.address as Address1,aa.Temperature as Temperature1 ,bb.address as Address2,bb.Temperature as Temperature2,cc.address as Address3 ,cc.Temperature
- as Temperature3,dd.Num from (
- select StuNo,StuName,DkDate from HealthPunchStu hps where 1=1 " + sql1 + "");
- strSql.Append(@" group by StuNo,StuName,DkDate) hps
- left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
- strSql.Append(@" ) AA on AA.StuNo=hps.StuNo and AA.StuName=hps.StuName and AA.dkType=1
- left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
- strSql.Append(@" ) BB on BB.StuNo=hps.Stuno and BB.StuName=hps.StuName and BB.dkType=2
- left join (select * from HealthPunchStu where 1=1 " + sql1 + "");
- strSql.Append(@" ) CC on CC.StuNo=hps.Stuno and CC.StuName=hps.StuName and CC.dkType=3
- left join (select Stuno,Count(*) as num from HealthPunchStu hps where 1=1 " + sql1 + " ");
- strSql.Append(@" group by Stuno ) dd on dd.StuNo=hps.Stuno
- ) fb on fb.Stuno = zb.stuno and fb.StuName = zb.StuName
- )t where 1= 1 " + sql1 + sql2 + " ");
- return this.BaseRepository("CollegeMIS").FindList<HealthPunchStuEntity>(strSql.ToString(), pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
- #endregion
-
- #region 提交数据
-
- /// <summary>
- /// 删除实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void DeleteEntity(string keyValue)
- {
- try
- {
- this.BaseRepository("CollegeMIS").Delete<HealthPunchStuEntity>(t => t.ID == keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- public void SaveEntity(string keyValue, HealthPunchStuEntity entity)
- {
- try
- {
- var userInfo = LoginUserInfo.Get();
- var stuInfo = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(x => x.StuNo == userInfo.account);
- if (stuInfo != null)
- {
- entity.StuNo = stuInfo.StuNo;
- entity.StuName = userInfo.realName;
- entity.Phone = stuInfo.mobile;
- entity.F_School = stuInfo.F_SchoolId;
- entity.DeptNo = stuInfo.DeptNo;
- entity.MajorNo = stuInfo.MajorNo;
- entity.ClassNo = stuInfo.ClassNo;
- entity.Grade = stuInfo.Grade;
- entity.Sex = Convert.ToInt32(stuInfo.GenderNo);
- entity.CreateTime = DateTime.Now;
- entity.DKDate = DateTime.Now;
- entity.Year = DateTime.Now.Year.ToString();
- entity.Moth = DateTime.Now.Month.ToString();
- entity.Day = DateTime.Now.Day.ToString();
- }
- entity.Create();
- this.BaseRepository("CollegeMIS").Insert(entity);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- public string PunchCard(string keyValue, HealthPunchStuEntity entity)
- {
- try
- {
- //获取打卡规则
- var dktime1 = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchTimeEntity>(x => x.CheckMark == 0 && x.Description == "1");
- var dktime2 = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchTimeEntity>(x => x.CheckMark == 0 && x.Description == "2");
- var dktime3 = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchTimeEntity>(x => x.CheckMark == 0 && x.Description == "3");
-
- var datenow = DateTime.Now.ToString("yyyy-MM-dd");
- DateTime Nowdate = DateTime.Now;
- DateTime todyTime = DateTime.Now.Date;
- var userInfo = LoginUserInfo.Get();
-
- if (dktime1 != null && dktime2 != null && dktime3 != null)
- {
- DateTime Startime1 = Convert.ToDateTime(datenow + " " + dktime1.StarTime);
- DateTime Startime2 = Convert.ToDateTime(datenow + " " + dktime1.EndTime);
- DateTime Startime3 = Convert.ToDateTime(datenow + " " + dktime2.StarTime);
- DateTime Startime4 = Convert.ToDateTime(datenow + " " + dktime2.EndTime);
- DateTime Startime5 = Convert.ToDateTime(datenow + " " + dktime3.StarTime);
- DateTime Startime6 = Convert.ToDateTime(datenow + " " + dktime3.EndTime);
-
- #region 学生数据
- var stuInfo = this.BaseRepository("CollegeMIS").FindEntity<StuInfoBasicEntity>(x => x.StuNo == userInfo.account);
- if (stuInfo != null)
- {
- entity.StuNo = stuInfo.StuNo;
- entity.StuName = userInfo.realName;
- entity.Phone = stuInfo.mobile;
- entity.F_School = stuInfo.F_SchoolId;
- entity.DeptNo = stuInfo.DeptNo;
- entity.MajorNo = stuInfo.MajorNo;
- entity.ClassNo = stuInfo.ClassNo;
- entity.Grade = stuInfo.Grade;
- entity.Sex = Convert.ToInt32(stuInfo.GenderNo);
- entity.CreateTime = DateTime.Now;
- entity.DKDate = DateTime.Now;
- entity.Year = DateTime.Now.Year.ToString();
- entity.Moth = DateTime.Now.Month.ToString();
- entity.Day = DateTime.Now.Day.ToString();
- }
- else
- {
- return "学生数据不存在!";
- }
- #endregion
-
- if (Startime1 <= Nowdate && Startime2 >= Nowdate) //早上打卡
- {
- var HealthPunchStu = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchStuEntity>(x => x.DKDate == todyTime && x.DKType == "1" && x.StuNo == userInfo.account);
- if (HealthPunchStu == null)
- {
- entity.DKType = "1";
- }
- else
- {
- return "请勿重复打卡!";
- }
- }
- else if (Startime3 <= Nowdate && Startime4 >= Nowdate)
- {
- var HealthPunchStu = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchStuEntity>(x => x.DKDate == todyTime && x.DKType == "2" && x.StuNo == userInfo.account);
- if (HealthPunchStu == null)
- {
- entity.DKType = "2";
- }
- else
- {
- return "请勿重复打卡!";
- }
- }
- else if (Startime5 <= Nowdate && Startime6 >= Nowdate)
- {
- var HealthPunchStu = this.BaseRepository("CollegeMIS").FindEntity<HealthPunchStuEntity>(x => x.DKDate == todyTime && x.DKType == "3" && x.StuNo == userInfo.account);
- if (HealthPunchStu == null)
- {
- entity.DKType = "3";
- }
- else
- {
- return "请勿重复打卡";
- }
- }
- else
- {
- return "请在规定的时间段内打卡!";
- }
- }
- else
- {
- return "请先设置打卡时间";
- }
- entity.Create();
- this.BaseRepository("CollegeMIS").Insert(entity);
- return "保存成功";
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- }
- }
|