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.
 
 
 
 
 
 

398 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. public DataTable GetSqlTree()
  203. {
  204. try
  205. {
  206. return this.BaseRepository("CollegeMIS").FindTable("select * from ClassInfo where CheckMark=1 ");
  207. }
  208. catch (Exception ex)
  209. {
  210. if (ex is ExceptionEx)
  211. {
  212. throw;
  213. }
  214. else
  215. {
  216. throw ExceptionEx.ThrowServiceException(ex);
  217. }
  218. }
  219. }
  220. #endregion
  221. #region 提交数据
  222. public void Lock(string keyValue)
  223. {
  224. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  225. try
  226. {
  227. //单个启用
  228. //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + keyValue + "'");
  229. //多个启用
  230. var keyValueArr = keyValue.Split(',');
  231. foreach (var item in keyValueArr)
  232. {
  233. db.ExecuteBySql("update ClassInfo set CheckMark=1 where ClassId='" + item + "'");
  234. }
  235. db.Commit();
  236. }
  237. catch (Exception ex)
  238. {
  239. db.Rollback();
  240. if (ex is ExceptionEx)
  241. {
  242. throw;
  243. }
  244. else
  245. {
  246. throw ExceptionEx.ThrowServiceException(ex);
  247. }
  248. }
  249. }
  250. public void UnLock(string keyValue)
  251. {
  252. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  253. try
  254. {
  255. //单个停用
  256. //this.BaseRepository("CollegeMIS").ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + keyValue + "'");
  257. //多个停用
  258. var keyValueArr = keyValue.Split(',');
  259. foreach (var item in keyValueArr)
  260. {
  261. db.ExecuteBySql("update ClassInfo set CheckMark=0 where ClassId='" + item + "'");
  262. }
  263. db.Commit();
  264. }
  265. catch (Exception ex)
  266. {
  267. db.Rollback();
  268. if (ex is ExceptionEx)
  269. {
  270. throw;
  271. }
  272. else
  273. {
  274. throw ExceptionEx.ThrowServiceException(ex);
  275. }
  276. }
  277. }
  278. /// <summary>
  279. /// 删除实体数据
  280. /// <param name="keyValue">主键</param>
  281. /// <summary>
  282. /// <returns></returns>
  283. public void DeleteEntity(string keyValue)
  284. {
  285. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  286. try
  287. {
  288. //单个删除
  289. //this.BaseRepository("CollegeMIS").Delete<ClassInfoEntity>(t => t.ClassId == keyValue);
  290. //多个删除
  291. var keyValueArr = keyValue.Split(',');
  292. foreach (var item in keyValueArr)
  293. {
  294. db.Delete<ClassInfoEntity>(t => t.ClassId == item);
  295. }
  296. db.Commit();
  297. }
  298. catch (Exception ex)
  299. {
  300. db.Rollback();
  301. if (ex is ExceptionEx)
  302. {
  303. throw;
  304. }
  305. else
  306. {
  307. throw ExceptionEx.ThrowServiceException(ex);
  308. }
  309. }
  310. }
  311. /// <summary>
  312. /// 保存实体数据(新增、修改)
  313. /// <param name="keyValue">主键</param>
  314. /// <summary>
  315. /// <returns></returns>
  316. public void SaveEntity(string keyValue, ClassInfoEntity entity)
  317. {
  318. try
  319. {
  320. if (!string.IsNullOrEmpty(keyValue))
  321. {
  322. entity.Modify(keyValue);
  323. this.BaseRepository("CollegeMIS").Update(entity);
  324. }
  325. else
  326. {
  327. entity.Create();
  328. this.BaseRepository("CollegeMIS").Insert(entity);
  329. }
  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. #endregion
  344. public IEnumerable<ClassInfoEntity> GetAllClass()
  345. {
  346. try
  347. {
  348. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true);
  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. public IEnumerable<ClassInfoEntity> GetClassByMajorNo(string MajorNo)
  363. {
  364. try
  365. {
  366. return this.BaseRepository("CollegeMIS").FindList<ClassInfoEntity>(m => m.CheckMark == true && m.MajorNo == MajorNo);
  367. }
  368. catch (Exception ex)
  369. {
  370. if (ex is ExceptionEx)
  371. {
  372. throw;
  373. }
  374. else
  375. {
  376. throw ExceptionEx.ThrowServiceException(ex);
  377. }
  378. }
  379. }
  380. }
  381. }