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.
 
 
 
 
 
 

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