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.
 
 
 
 
 
 

341 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.Text;
  8. using Learun.Application.TwoDevelopment.AssetManagementSystem;
  9. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
  13. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2022-02-18 14:27
  16. /// 描 述:教材订单管理
  17. /// </summary>
  18. public class TextBookIndentService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取页面显示列表数据
  23. /// </summary>
  24. /// <param name="pagination">分页参数</param>
  25. /// <param name="queryJson">查询参数</param>
  26. /// <returns></returns>
  27. public IEnumerable<TextBookIndentEntity> GetPageList(Pagination pagination, string queryJson)
  28. {
  29. try
  30. {
  31. var strSql = new StringBuilder();
  32. strSql.Append("SELECT ");
  33. strSql.Append(@" * ");
  34. strSql.Append(" FROM TextBookIndent t ");
  35. strSql.Append(" WHERE 1=1 ");
  36. var queryParam = queryJson.ToJObject();
  37. // 虚拟参数
  38. var dp = new DynamicParameters(new { });
  39. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  40. {
  41. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  42. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  43. strSql.Append(" AND ( t.CreateTime >= @startTime AND t.CreateTime <= @endTime ) ");
  44. }
  45. if (!queryParam["DeptNo"].IsEmpty())
  46. {
  47. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  48. strSql.Append(" AND t.DeptNo = @DeptNo ");
  49. }
  50. if (!queryParam["MajorNo"].IsEmpty())
  51. {
  52. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  53. strSql.Append(" AND t.MajorNo = @MajorNo ");
  54. }
  55. if (!queryParam["LessonNo"].IsEmpty())
  56. {
  57. dp.Add("LessonNo", queryParam["LessonNo"].ToString(), DbType.String);
  58. strSql.Append(" AND t.LessonNo = @LessonNo ");
  59. }
  60. if (!queryParam["AcademicYearNo"].IsEmpty())
  61. {
  62. dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
  63. strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
  64. }
  65. if (!queryParam["Semester"].IsEmpty())
  66. {
  67. dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
  68. strSql.Append(" AND t.Semester = @Semester ");
  69. }
  70. if (!queryParam["PublishNo"].IsEmpty())
  71. {
  72. dp.Add("PublishNo", "%" + queryParam["PublishNo"].ToString() + "%", DbType.String);
  73. strSql.Append(" AND t.PublishNo Like @PublishNo ");
  74. }
  75. return this.BaseRepository("CollegeMIS").FindList<TextBookIndentEntity>(strSql.ToString(), dp, pagination);
  76. }
  77. catch (Exception ex)
  78. {
  79. if (ex is ExceptionEx)
  80. {
  81. throw;
  82. }
  83. else
  84. {
  85. throw ExceptionEx.ThrowServiceException(ex);
  86. }
  87. }
  88. }
  89. /// <summary>
  90. /// 获取TextBookIndent表实体数据
  91. /// </summary>
  92. /// <param name="keyValue">主键</param>
  93. /// <returns></returns>
  94. public TextBookIndentEntity GetTextBookIndentEntity(string keyValue)
  95. {
  96. try
  97. {
  98. return this.BaseRepository("CollegeMIS").FindEntity<TextBookIndentEntity>(keyValue);
  99. }
  100. catch (Exception ex)
  101. {
  102. if (ex is ExceptionEx)
  103. {
  104. throw;
  105. }
  106. else
  107. {
  108. throw ExceptionEx.ThrowServiceException(ex);
  109. }
  110. }
  111. }
  112. /// <summary>
  113. /// 获取主表实体数据
  114. /// </summary>
  115. /// <param name="processId">流程实例ID</param>
  116. /// <returns></returns>
  117. public TextBookIndentEntity GetEntityByProcessId(string processId)
  118. {
  119. try
  120. {
  121. return this.BaseRepository("CollegeMIS").FindEntity<TextBookIndentEntity>(t => t.processId == processId);
  122. }
  123. catch (Exception ex)
  124. {
  125. if (ex is ExceptionEx)
  126. {
  127. throw;
  128. }
  129. else
  130. {
  131. throw ExceptionEx.ThrowServiceException(ex);
  132. }
  133. }
  134. }
  135. /// <summary>
  136. /// 获取Ass_AssetsInfoApply表实体数据
  137. /// <param name="keyValue">主键</param>
  138. /// <summary>
  139. /// <returns></returns>
  140. public IEnumerable<TextBookIndentDetailEntity> TextBookIndentDetailList(string keyValue)
  141. {
  142. try
  143. {
  144. return this.BaseRepository("CollegeMIS").FindList<TextBookIndentDetailEntity>(t => t.IndentId == keyValue);
  145. }
  146. catch (Exception ex)
  147. {
  148. if (ex is ExceptionEx)
  149. {
  150. throw;
  151. }
  152. else
  153. {
  154. throw ExceptionEx.ThrowServiceException(ex);
  155. }
  156. }
  157. }
  158. #endregion
  159. #region 提交数据
  160. /// <summary>
  161. /// 删除实体数据
  162. /// </summary>
  163. /// <param name="keyValue">主键</param>
  164. public void DeleteEntity(string keyValue)
  165. {
  166. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  167. try
  168. {
  169. db.Delete<TextBookIndentDetailEntity>(t => t.IndentId == keyValue);
  170. db.Delete<TextBookIndentEntity>(t => t.ID == keyValue);
  171. db.Commit();
  172. }
  173. catch (Exception ex)
  174. {
  175. db.Rollback();
  176. if (ex is ExceptionEx)
  177. {
  178. throw;
  179. }
  180. else
  181. {
  182. throw ExceptionEx.ThrowServiceException(ex);
  183. }
  184. }
  185. }
  186. /// <summary>
  187. /// 保存实体数据(新增、修改)
  188. /// </summary>
  189. /// <param name="keyValue">主键</param>
  190. /// <param name="entity">实体</param>
  191. /// <returns></returns>
  192. public void SaveEntity(string keyValue, TextBookIndentEntity entity, List<TextBookIndentDetailEntity> textbookIndentDateil)
  193. {
  194. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  195. try
  196. {
  197. if (!string.IsNullOrEmpty(keyValue))
  198. {
  199. entity.Modify(keyValue);
  200. db.Update(entity);
  201. db.Delete<TextBookIndentDetailEntity>(t => t.IndentId == keyValue);
  202. foreach (TextBookIndentDetailEntity item in textbookIndentDateil)
  203. {
  204. item.Create();
  205. item.IndentId = keyValue;
  206. db.Insert(item);
  207. }
  208. }
  209. else
  210. {
  211. entity.Create();
  212. db.Insert(entity);
  213. foreach (TextBookIndentDetailEntity item in textbookIndentDateil)
  214. {
  215. item.Create();
  216. item.IndentId = entity.ID;
  217. db.Insert(item);
  218. }
  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. public void ModifyStatus(string keyValue, string processId)
  236. {
  237. try
  238. {
  239. var entity = this.BaseRepository("CollegeMIS").FindEntity<TextBookIndentEntity>(a => a.ID == keyValue);
  240. entity.processId = processId;
  241. entity.Status = 1;
  242. this.BaseRepository("CollegeMIS").Update(entity);
  243. }
  244. catch (Exception e)
  245. {
  246. if (e is ExceptionEx)
  247. {
  248. throw;
  249. }
  250. else
  251. {
  252. throw ExceptionEx.ThrowServiceException(e);
  253. }
  254. }
  255. }
  256. /// <summary>
  257. /// 审批后修改状态
  258. /// </summary>
  259. /// <param name="pastatus"></param>
  260. /// <param name="processId"></param>
  261. public void ChangeStatusByProcessId(int pastatus, string processId)
  262. {
  263. var db = this.BaseRepository("CollegeMIS");
  264. try
  265. {
  266. db.BeginTrans();
  267. var entity = this.BaseRepository("CollegeMIS").FindEntity<TextBookIndentEntity>(a => a.processId == processId);
  268. entity.Status = pastatus;
  269. db.Update(entity);
  270. if (pastatus == 2)
  271. {
  272. //教材订单明细
  273. var detailList = db.FindList<TextBookIndentDetailEntity>(x => x.IndentId == entity.ID);
  274. //审核通过,添加征订数据
  275. TextBookSolSubEntity textBookSolSub = new TextBookSolSubEntity();
  276. textBookSolSub.Create();
  277. textBookSolSub.TextBookIndentId = entity.ID;
  278. textBookSolSub.DeptNo = entity.DeptNo;
  279. textBookSolSub.MajorNo = entity.MajorNo;
  280. textBookSolSub.LessonNo = entity.LessonNo;
  281. textBookSolSub.AcademicYearNo = entity.AcademicYearNo;
  282. textBookSolSub.Semester = entity.Semester;
  283. textBookSolSub.PublishNo = entity.PublishNo;
  284. textBookSolSub.TextBookNo = entity.TextBookNo;
  285. textBookSolSub.TextBookName = entity.TextBookName;
  286. textBookSolSub.FirstAuthor = entity.FirstAuthor;
  287. textBookSolSub.OtherAuthor = entity.OtherAuthor;
  288. textBookSolSub.OrderNum = entity.OrderNum;
  289. textBookSolSub.Remark = entity.Remark;
  290. textBookSolSub.Publisher = entity.Publisher;
  291. textBookSolSub.Edition = entity.Edition;
  292. textBookSolSub.Price = entity.Price;
  293. textBookSolSub.ClassSum = entity.ClassSum;
  294. db.Insert(textBookSolSub);
  295. foreach (var detail in detailList)
  296. {
  297. TextBookSolSubDetailEntity textBookSolSubDetail = new TextBookSolSubDetailEntity();
  298. textBookSolSubDetail.Create();
  299. textBookSolSubDetail.SolSubId = textBookSolSub.ID;
  300. textBookSolSubDetail.ClassNo = detail.ClassNo;
  301. textBookSolSubDetail.TeachSum = detail.TeachSum;
  302. textBookSolSubDetail.StuSum = detail.StuSum;
  303. textBookSolSubDetail.Remark = detail.Remark;
  304. db.Insert(textBookSolSubDetail);
  305. }
  306. }
  307. db.Commit();
  308. }
  309. catch (Exception e)
  310. {
  311. db.Rollback();
  312. if (e is ExceptionEx)
  313. {
  314. throw;
  315. }
  316. else
  317. {
  318. throw ExceptionEx.ThrowServiceException(e);
  319. }
  320. }
  321. }
  322. #endregion
  323. }
  324. }