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.
 
 
 
 
 
 

353 lines
16 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-Ultimate V7.0.0 数字化智慧校园
  13. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2019-06-14 10:24
  16. /// 描 述:教师考勤
  17. /// </summary>
  18. public class TeachAttendanceService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<Teach_attendanceEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT t.* ");
  32. strSql.Append(" FROM Teach_attendance t ");
  33. strSql.Append(" WHERE 1=1 ");
  34. var queryParam = queryJson.ToJObject();
  35. // 虚拟参数
  36. var dp = new DynamicParameters(new { });
  37. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  38. {
  39. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  40. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  41. strSql.Append(" AND ( t.ClockTime >= @startTime AND t.ClockTime <= @endTime ) ");
  42. }
  43. return this.BaseRepository("CollegeMIS").FindList<Teach_attendanceEntity>(strSql.ToString(), dp, pagination);
  44. }
  45. catch (Exception ex)
  46. {
  47. if (ex is ExceptionEx)
  48. {
  49. throw;
  50. }
  51. else
  52. {
  53. throw ExceptionEx.ThrowServiceException(ex);
  54. }
  55. }
  56. }
  57. internal object GetAttendanceByEmpNo(string empNo)
  58. {
  59. try
  60. {
  61. var entityList = this.BaseRepository("CollegeMIS").FindList<Teach_attendanceEntity>(a => a.EmpNo == empNo).ToList();
  62. var dataK = entityList.GroupBy(a => a.ClockTime?.ToString("yyyyMMdd"))
  63. .Select(a => new
  64. {
  65. key = a.Key,
  66. y = a.Key.Substring(0, 4),
  67. m = a.Key.Substring(4, 2),
  68. d = a.Key.Substring(6),
  69. day = $"{entityList.FirstOrDefault(b => b.ClockTime?.ToString("yyyyMMdd") == a.Key)?.ClockTime?.ToString("yyyy年MM月dd日")} {System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(Convert.ToDateTime(entityList.FirstOrDefault(b => b.ClockTime?.ToString("yyyyMMdd") == a.Key)?.ClockTime).DayOfWeek)}",
  70. list = entityList.Where(b => b.ClockTime?.ToString("yyyyMMdd") == a.Key).OrderBy(b => b.ClockTime).Select(b => new { time = b.ClockTime?.ToString("HH:mm"), location = b.ClockPlace, status = "1" }),
  71. state = "1"
  72. });
  73. return dataK;
  74. }
  75. catch (Exception ex)
  76. {
  77. if (ex is ExceptionEx)
  78. {
  79. throw;
  80. }
  81. else
  82. {
  83. throw ExceptionEx.ThrowServiceException(ex);
  84. }
  85. }
  86. }
  87. /// <summary>
  88. /// 获取Teach_attendance表实体数据
  89. /// <param name="keyValue">主键</param>
  90. /// <summary>
  91. /// <returns></returns>
  92. public Teach_attendanceEntity GetTeach_attendanceEntity(string keyValue)
  93. {
  94. try
  95. {
  96. return this.BaseRepository("CollegeMIS").FindEntity<Teach_attendanceEntity>(keyValue);
  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="queryJson">查询参数</param>
  114. /// <returns></returns>
  115. public IEnumerable<Teach_attendanceEntity> GetStatisticDetailList(Pagination pagination, string queryJson)
  116. {
  117. try
  118. {
  119. var queryParam = queryJson.ToJObject();
  120. var datest = DateTime.Now.ToDateString();
  121. var dateet = datest;
  122. if (!queryParam["startTime"].IsEmpty())
  123. {
  124. datest = queryParam["startTime"].ToDate().ToDateString();
  125. }
  126. if (!queryParam["endTime"].IsEmpty())
  127. {
  128. dateet = queryParam["endTime"].ToDate().ToDateString();
  129. }
  130. var strSql1 = $@"select a.ALTId as ALTIdInArrange,a.LessonDate,a.AcademicYearNo,a.Semester, a.LessonNo, a.LessonName, a.EmpNo as EmpNoInArrange, a.EmpName as EmpNameInArrange,a.ClassroomNo,a.LessonTime,
  131. a.StartTime, a.EndTime,a.LessonSortNo as LessonSortNoInArrange,e.F_DepartmentId,t.ID,t.EmpNo,t.EmpName,t.ALTId,t.ALTOEId,t.LessonSortNo,t.ADType,t.ADTime,t.ClockTime,t.ClockStatus,t.ClockPlace,t.ADPhoto,t.ALon,t.ALat,t.AIsOut,t.ARemark,e.photo,t.IsFit,t.Img
  132. from ArrangeLessonTerm a
  133. left join Teach_Attendance t on a.ALTId=t.ALTId and t.LessonSortNo='1'
  134. left join EmpInfo e on a.EmpNo=e.EmpNo
  135. where a.LessonDate >='{datest}' and a.LessonDate <= '{dateet}'";
  136. var strSql2 = $@"select a.Id as ALTIdInArrange,a.LessonDate,a.AcademicYearNo, a.Semester, a.LessonNo, a.LessonName,a.EmpNo as EmpNoInArrange, a.EmpName as EmpNameInArrange,a.ClassRoomNo as ClassroomNo,a.LessonSection as LessonTime,
  137. case when LEN(a.LessonTime)>0 then SUBSTRING(a.LessonTime,1,CHARINDEX('-',a.LessonTime)-1) else '' end as StartTime,
  138. case when LEN(a.LessonTime)>0 then SUBSTRING(a.LessonTime,CHARINDEX('-',a.LessonTime)+1,LEN(a.LessonTime)-CHARINDEX('-',a.LessonTime)) else '' end as EndTime,
  139. a.LessonSortNo as LessonSortNoInArrange,e.F_DepartmentId,t.ID,t.EmpNo,t.EmpName,t.ALTId,t.ALTOEId,t.LessonSortNo,t.ADType,t.ADTime,t.ClockTime,t.ClockStatus,t.ClockPlace,t.ADPhoto,t.ALon,t.ALat,t.AIsOut,t.ARemark,e.photo,t.IsFit,t.Img from ArrangeLessonTermOfElective a
  140. left join Teach_Attendance t on a.Id=t.ALTId and t.LessonSortNo='2'
  141. left join EmpInfo e on a.EmpNo=e.EmpNo
  142. where a.LessonDate >='{datest}' and a.LessonDate <= '{dateet}'";
  143. // 虚拟参数
  144. var dp = new DynamicParameters(new { });
  145. if (!queryParam["EmpNo"].IsEmpty())
  146. {
  147. dp.Add("EmpNo", queryParam["EmpNo"].ToString(), DbType.String);
  148. strSql1 += " AND a.EmpNo = @EmpNo";
  149. strSql2 += " AND a.EmpNo = @EmpNo";
  150. }
  151. if (!queryParam["EmpName"].IsEmpty())
  152. {
  153. dp.Add("EmpName", "%" + queryParam["EmpName"].ToString() + "%", DbType.String);
  154. strSql1 += " AND a.EmpName Like @EmpName";
  155. strSql2 += " AND a.EmpName Like @EmpName";
  156. }
  157. if (!queryParam["F_DepartmentId"].IsEmpty())
  158. {
  159. dp.Add("F_DepartmentId", queryParam["F_DepartmentId"].ToString(), DbType.String);
  160. strSql1 += " AND e.F_DepartmentId = @F_DepartmentId";
  161. strSql2 += " AND e.F_DepartmentId = @F_DepartmentId";
  162. }
  163. var strSql = new StringBuilder();
  164. strSql.Append(strSql1);
  165. strSql.Append(" union ");
  166. strSql.Append(strSql2);
  167. //某天记录列表
  168. var data = this.BaseRepository("CollegeMIS").FindList<Teach_attendanceEntity>(strSql.ToString(), dp)
  169. .GroupBy(a => new
  170. {
  171. a.ALTIdInArrange,
  172. a.LessonDate,
  173. a.AcademicYearNo,
  174. a.Semester,
  175. a.LessonNo,
  176. a.LessonName,
  177. a.EmpNoInArrange,
  178. a.EmpNameInArrange,
  179. a.ClassroomNo,
  180. a.LessonTime,
  181. a.StartTime,
  182. a.EndTime,
  183. a.LessonSortNoInArrange,
  184. a.F_DepartmentId,a.Photo
  185. }).Select(x => new Teach_attendanceEntity
  186. {
  187. ALTIdInArrange = x.Key.ALTIdInArrange,
  188. LessonDate = x.Key.LessonDate.ToDate().ToDateString(),
  189. AcademicYearNo = x.Key.AcademicYearNo,
  190. Semester = x.Key.Semester,
  191. LessonNo = x.Key.LessonNo,
  192. LessonName = x.Key.LessonName,
  193. EmpNoInArrange = x.Key.EmpNoInArrange,
  194. EmpNameInArrange = x.Key.EmpNameInArrange,
  195. ClassroomNo = x.Key.ClassroomNo,
  196. LessonTime = x.Key.LessonTime,
  197. StartTime = x.Key.StartTime,
  198. EndTime = x.Key.EndTime,
  199. LessonSortNoInArrange = x.Key.LessonSortNoInArrange,
  200. F_DepartmentId = x.Key.F_DepartmentId,
  201. Photo=x.Key.Photo,
  202. Group = x.Select(y => new Teach_attendanceEntity()
  203. {
  204. Photo=y.Photo,
  205. ADType = y.ADType,
  206. ClockTime = y.ClockTime,
  207. ClockStatus = y.ClockStatus,
  208. IsFit = y.IsFit,
  209. Img=y.Img
  210. }).ToList()
  211. }).OrderBy(x => x.LessonDate).ThenBy(x => Convert.ToInt32(x.LessonTime.Substring(1)));
  212. //结果列表
  213. var result = new List<Teach_attendanceEntity>();
  214. foreach (var item in data)
  215. {
  216. string photo = item.Photo;
  217. //上课时间
  218. var WorkTimeTemp = string.Format("{0} {1}", item.LessonDate, item.StartTime).ToDate();
  219. //下课时间
  220. var CloseTimeTemp = string.Format("{0} {1}", item.LessonDate, item.EndTime).ToDate();
  221. //课程应工作分钟数
  222. var WholeMinutes = (CloseTimeTemp - WorkTimeTemp).TotalMinutes.ToInt();
  223. //上课
  224. var adtype1 = item.Group.FirstOrDefault(x => x.ADType == "1");
  225. //下课
  226. var adtype2 = item.Group.FirstOrDefault(x => x.ADType == "2");
  227. //补充结果集
  228. item.TimePeriod = string.Format("{0}-{1}", item.StartTime, item.EndTime);
  229. item.ADStatusWork = adtype1 != null ? adtype1.ClockStatus : "6";
  230. item.ADStatusClose = adtype2 != null ? adtype2.ClockStatus : "6";
  231. item.ClockTimeWork = adtype1 != null ? adtype1.ClockTime.ToTimeString() : "-";
  232. item.ClockTimeClose = adtype2 != null ? adtype2.ClockTime.ToTimeString() : "-";
  233. item.ChidaoMinutes = adtype1 != null ? adtype1.ClockStatus == "2" ? (adtype1.ClockTime.Value - WorkTimeTemp).TotalMinutes.ToInt() : 0 : 0;
  234. item.ZaoTuiMinutes = adtype2 != null ? adtype2.ClockStatus == "3" ? (CloseTimeTemp - adtype2.ClockTime.Value).TotalMinutes.ToInt() : 0 : 0;
  235. item.ChuQinMinutes = adtype1 != null && adtype2 != null ? (adtype2.ClockTime.Value - adtype1.ClockTime.Value).TotalMinutes.ToInt() : 0;
  236. item.QueQinMinutes = adtype1 != null && adtype2 != null ? 0 : WholeMinutes;
  237. item.RestMinutes = 0;
  238. item.WorkMinutes = WholeMinutes == item.QueQinMinutes ? 0 : WholeMinutes - item.ChidaoMinutes - item.ZaoTuiMinutes - item.QueQinMinutes;
  239. item.Photo = photo;
  240. item.IsFitstr = (adtype1 != null ? adtype1.IsFit.ToString() : "") + "," + (adtype2 != null ? adtype2.IsFit.ToString() : "");
  241. item.Img = (adtype1 != null ? adtype1.Img : "") + "," + (adtype2 != null ? adtype2.Img : "");
  242. result.Add(item);
  243. }
  244. if (!queryParam["ClockStatus"].IsEmpty())
  245. {
  246. if (queryParam["ClockStatus"].ToString() == "0")//旷工
  247. {
  248. result = result.Where(x => x.ADStatusWork == "6" || x.ADStatusClose == "6").ToList();
  249. }
  250. else
  251. {
  252. result = result.Where(x => x.ADStatusWork == queryParam["ClockStatus"].ToString() || x.ADStatusClose == queryParam["ClockStatus"].ToString()).ToList();
  253. }
  254. }
  255. return result;
  256. }
  257. catch (Exception ex)
  258. {
  259. if (ex is ExceptionEx)
  260. {
  261. throw;
  262. }
  263. else
  264. {
  265. throw ExceptionEx.ThrowBusinessException(ex);
  266. }
  267. }
  268. }
  269. public string GetStatisticDetailimg(string teachno)
  270. {
  271. var strSql = new StringBuilder();
  272. strSql.Append("SELECT t.img ");
  273. strSql.Append(" FROM Teach_attendance t ");
  274. strSql.Append(" WHERE 1=1 and empno='"+teachno+"' and isfit=1 and img is not null");
  275. return this.BaseRepository("CollegeMIS").FindObject(strSql.ToString())?.ToString();
  276. }
  277. #endregion
  278. #region 提交数据
  279. /// <summary>
  280. /// 删除实体数据
  281. /// <param name="keyValue">主键</param>
  282. /// <summary>
  283. /// <returns></returns>
  284. public void DeleteEntity(string keyValue)
  285. {
  286. try
  287. {
  288. this.BaseRepository("CollegeMIS").Delete<Teach_attendanceEntity>(t => t.ID == keyValue);
  289. }
  290. catch (Exception ex)
  291. {
  292. if (ex is ExceptionEx)
  293. {
  294. throw;
  295. }
  296. else
  297. {
  298. throw ExceptionEx.ThrowServiceException(ex);
  299. }
  300. }
  301. }
  302. /// <summary>
  303. /// 保存实体数据(新增、修改)
  304. /// <param name="keyValue">主键</param>
  305. /// <summary>
  306. /// <returns></returns>
  307. public void SaveEntity(string keyValue, Teach_attendanceEntity entity)
  308. {
  309. try
  310. {
  311. if (!string.IsNullOrEmpty(keyValue))
  312. {
  313. entity.Modify(keyValue);
  314. this.BaseRepository("CollegeMIS").Update(entity);
  315. }
  316. else
  317. {
  318. entity.Create();
  319. this.BaseRepository("CollegeMIS").Insert(entity);
  320. }
  321. }
  322. catch (Exception ex)
  323. {
  324. if (ex is ExceptionEx)
  325. {
  326. throw;
  327. }
  328. else
  329. {
  330. throw ExceptionEx.ThrowServiceException(ex);
  331. }
  332. }
  333. }
  334. #endregion
  335. }
  336. }