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