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.
 
 
 
 
 
 

380 lines
12 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-01-29 11:08
  16. /// 描 述:班级信息管理
  17. /// </summary>
  18. public class ClassInfoService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// <summary>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<ClassInfoEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT ");
  32. strSql.Append(@"
  33. t.ClassId,
  34. t.ClassName,
  35. t.ClassNo,
  36. t.DeptNo,
  37. t.MajorNo,
  38. t.SerialNum,
  39. t.Grade,
  40. t.StuNum,
  41. t.ClassDiredctorNo,
  42. t.ClassTutorNo,
  43. t.ClassType,
  44. t.CheckMark,t.IsSeparate
  45. ");
  46. strSql.Append(" FROM ClassInfo t ");
  47. strSql.Append(" WHERE 1=1 ");
  48. var queryParam = queryJson.ToJObject();
  49. // 虚拟参数
  50. var dp = new DynamicParameters(new { });
  51. if (!queryParam["ClassName"].IsEmpty())
  52. {
  53. dp.Add("ClassName", "%" + queryParam["ClassName"].ToString() + "%", DbType.String);
  54. strSql.Append(" AND t.ClassName Like @ClassName ");
  55. }
  56. if (!queryParam["ClassNo"].IsEmpty())
  57. {
  58. dp.Add("ClassNo", "%" + queryParam["ClassNo"].ToString() + "%", DbType.String);
  59. strSql.Append(" AND t.ClassNo Like @ClassNo ");
  60. }
  61. if (!queryParam["DeptNo"].IsEmpty())
  62. {
  63. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  64. strSql.Append(" AND t.DeptNo = @DeptNo ");
  65. }
  66. if (!queryParam["MajorNo"].IsEmpty())
  67. {
  68. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  69. strSql.Append(" AND t.MajorNo = @MajorNo ");
  70. }
  71. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(strSql.ToString(), dp, pagination);
  72. }
  73. catch (Exception ex)
  74. {
  75. if (ex is ExceptionEx)
  76. {
  77. throw;
  78. }
  79. else
  80. {
  81. throw ExceptionEx.ThrowServiceException(ex);
  82. }
  83. }
  84. }
  85. internal bool GetAny()
  86. {
  87. try
  88. {
  89. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>().ToList().Count > 0 ? true : false;
  90. }
  91. catch (Exception ex)
  92. {
  93. if (ex is ExceptionEx)
  94. {
  95. throw;
  96. }
  97. else
  98. {
  99. throw ExceptionEx.ThrowServiceException(ex);
  100. }
  101. }
  102. }
  103. /// <summary>
  104. /// 获取ClassInfo表实体数据
  105. /// <param name="keyValue">主键</param>
  106. /// <summary>
  107. /// <returns></returns>
  108. public ClassInfoEntity GetClassInfoEntity(string keyValue)
  109. {
  110. try
  111. {
  112. return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(keyValue);
  113. }
  114. catch (Exception ex)
  115. {
  116. if (ex is ExceptionEx)
  117. {
  118. throw;
  119. }
  120. else
  121. {
  122. throw ExceptionEx.ThrowServiceException(ex);
  123. }
  124. }
  125. }
  126. /// <summary>
  127. /// 获取ClassInfo表实体数据
  128. /// <param name="classNo">班级编号</param>
  129. /// <summary>
  130. /// <returns></returns>
  131. public ClassInfoEntity GetClassInfoEntityByClassNo(string classNo)
  132. {
  133. try
  134. {
  135. return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(x => x.ClassNo == classNo);
  136. }
  137. catch (Exception ex)
  138. {
  139. if (ex is ExceptionEx)
  140. {
  141. throw;
  142. }
  143. else
  144. {
  145. throw ExceptionEx.ThrowServiceException(ex);
  146. }
  147. }
  148. }
  149. /// <summary>
  150. /// 获取ClassInfo表实体数据
  151. /// <param name="classNo">班级编号</param>
  152. /// <summary>
  153. /// <returns></returns>
  154. public string GetSchoolIdByClassNo(string classNo)
  155. {
  156. try
  157. {
  158. var sql = $@"select F_SchoolId from CdDept where DeptNo=
  159. (select DeptNo from ClassInfo where ClassNo = '{classNo}')
  160. ";
  161. var obj= this.BaseRepository("CollegeMIS").FindObject(sql);//.FindList<ClassInfoEntity>(sql);
  162. if (obj != null)
  163. return obj.ToString();
  164. else
  165. return "";
  166. }
  167. catch (Exception ex)
  168. {
  169. if (ex is ExceptionEx)
  170. {
  171. throw;
  172. }
  173. else
  174. {
  175. throw ExceptionEx.ThrowServiceException(ex);
  176. }
  177. }
  178. }
  179. /// <summary>
  180. /// 获取ClassInfo表实体数据
  181. /// <param name="className">班级名称</param>
  182. /// <summary>
  183. /// <returns></returns>
  184. public ClassInfoEntity GetClassInfoEntityByClassName(string className)
  185. {
  186. try
  187. {
  188. return this.BaseRepository("CollegeMIS").FindEntity<ClassInfoEntity>(x => x.ClassName == className);
  189. }
  190. catch (Exception ex)
  191. {
  192. if (ex is ExceptionEx)
  193. {
  194. throw;
  195. }
  196. else
  197. {
  198. throw ExceptionEx.ThrowServiceException(ex);
  199. }
  200. }
  201. }
  202. #endregion
  203. #region 提交数据
  204. public void Lock(string keyValue)
  205. {
  206. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  207. try
  208. {
  209. //单个启用
  210. //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + keyValue + "'");
  211. //多个启用
  212. var keyValueArr = keyValue.Split(',');
  213. foreach (var item in keyValueArr)
  214. {
  215. db.ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + item + "'");
  216. }
  217. db.Commit();
  218. }
  219. catch (Exception ex)
  220. {
  221. db.Rollback();
  222. if (ex is ExceptionEx)
  223. {
  224. throw;
  225. }
  226. else
  227. {
  228. throw ExceptionEx.ThrowServiceException(ex);
  229. }
  230. }
  231. }
  232. public void UnLock(string keyValue)
  233. {
  234. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  235. try
  236. {
  237. //单个停用
  238. //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + keyValue + "'");
  239. //多个停用
  240. var keyValueArr = keyValue.Split(',');
  241. foreach (var item in keyValueArr)
  242. {
  243. db.ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + item + "'");
  244. }
  245. db.Commit();
  246. }
  247. catch (Exception ex)
  248. {
  249. db.Rollback();
  250. if (ex is ExceptionEx)
  251. {
  252. throw;
  253. }
  254. else
  255. {
  256. throw ExceptionEx.ThrowServiceException(ex);
  257. }
  258. }
  259. }
  260. /// <summary>
  261. /// 删除实体数据
  262. /// <param name="keyValue">主键</param>
  263. /// <summary>
  264. /// <returns></returns>
  265. public void DeleteEntity(string keyValue)
  266. {
  267. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  268. try
  269. {
  270. //单个删除
  271. //this.BaseRepository("CollegeMIS").Delete<ClassInfoEntity>(t => t.ClassId == keyValue);
  272. //多个删除
  273. var keyValueArr = keyValue.Split(',');
  274. foreach (var item in keyValueArr)
  275. {
  276. db.Delete<ClassInfoEntity>(t => t.ClassId == item);
  277. }
  278. db.Commit();
  279. }
  280. catch (Exception ex)
  281. {
  282. db.Rollback();
  283. if (ex is ExceptionEx)
  284. {
  285. throw;
  286. }
  287. else
  288. {
  289. throw ExceptionEx.ThrowServiceException(ex);
  290. }
  291. }
  292. }
  293. /// <summary>
  294. /// 保存实体数据(新增、修改)
  295. /// <param name="keyValue">主键</param>
  296. /// <summary>
  297. /// <returns></returns>
  298. public void SaveEntity(string keyValue, ClassInfoEntity entity)
  299. {
  300. try
  301. {
  302. if (!string.IsNullOrEmpty(keyValue))
  303. {
  304. entity.Modify(keyValue);
  305. this.BaseRepository("CollegeMIS").Update(entity);
  306. }
  307. else
  308. {
  309. entity.Create();
  310. this.BaseRepository("CollegeMIS").Insert(entity);
  311. }
  312. }
  313. catch (Exception ex)
  314. {
  315. if (ex is ExceptionEx)
  316. {
  317. throw;
  318. }
  319. else
  320. {
  321. throw ExceptionEx.ThrowServiceException(ex);
  322. }
  323. }
  324. }
  325. #endregion
  326. public IEnumerable<ClassInfoEntity> GetAllClass()
  327. {
  328. try
  329. {
  330. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true);
  331. }
  332. catch (Exception ex)
  333. {
  334. if (ex is ExceptionEx)
  335. {
  336. throw;
  337. }
  338. else
  339. {
  340. throw ExceptionEx.ThrowServiceException(ex);
  341. }
  342. }
  343. }
  344. public IEnumerable<ClassInfoEntity> GetClassByMajorNo(string MajorNo)
  345. {
  346. try
  347. {
  348. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true && m.MajorNo == MajorNo);
  349. }
  350. catch (Exception ex)
  351. {
  352. if (ex is ExceptionEx)
  353. {
  354. throw;
  355. }
  356. else
  357. {
  358. throw ExceptionEx.ThrowServiceException(ex);
  359. }
  360. }
  361. }
  362. }
  363. }