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.
 
 
 
 
 
 

307 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.Text;
  8. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  9. {
  10. /// <summary>
  11. /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
  12. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  13. /// 创 建:超级管理员
  14. /// 日 期:2022-03-05 11:17
  15. /// 描 述:TextBookOut
  16. /// </summary>
  17. public class TextBookOutService : RepositoryFactory
  18. {
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取页面显示列表数据
  22. /// </summary>
  23. /// <param name="pagination">查询参数</param>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<TextBookOutEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var strSql = new StringBuilder();
  31. strSql.Append("SELECT ");
  32. strSql.Append(@"
  33. t.Id,
  34. t.AcademicYearNo,
  35. t.Semester,
  36. t.DeptNo,
  37. t.MajorNo,
  38. t.ClassNo,
  39. t.LessonNo,
  40. t.Variate,
  41. t.Recipient,
  42. t.CreateTime,
  43. t.CrateUserID
  44. ");
  45. strSql.Append(" FROM TextBookOut t ");
  46. strSql.Append(" WHERE 1=1 ");
  47. var queryParam = queryJson.ToJObject();
  48. // 虚拟参数
  49. var dp = new DynamicParameters(new { });
  50. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  51. {
  52. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  53. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  54. strSql.Append(" AND ( t.CreateTime >= @startTime AND t.CreateTime <= @endTime ) ");
  55. }
  56. if (!queryParam["AcademicYearNo"].IsEmpty())
  57. {
  58. dp.Add("AcademicYearNo", queryParam["AcademicYearNo"].ToString(), DbType.String);
  59. strSql.Append(" AND t.AcademicYearNo = @AcademicYearNo ");
  60. }
  61. if (!queryParam["Semester"].IsEmpty())
  62. {
  63. dp.Add("Semester", queryParam["Semester"].ToString(), DbType.String);
  64. strSql.Append(" AND t.Semester = @Semester ");
  65. }
  66. if (!queryParam["DeptNo"].IsEmpty())
  67. {
  68. dp.Add("DeptNo", queryParam["DeptNo"].ToString(), DbType.String);
  69. strSql.Append(" AND t.DeptNo = @DeptNo ");
  70. }
  71. if (!queryParam["MajorNo"].IsEmpty())
  72. {
  73. dp.Add("MajorNo", queryParam["MajorNo"].ToString(), DbType.String);
  74. strSql.Append(" AND t.MajorNo = @MajorNo ");
  75. }
  76. if (!queryParam["ClassNo"].IsEmpty())
  77. {
  78. dp.Add("ClassNo", queryParam["ClassNo"].ToString(), DbType.String);
  79. strSql.Append(" AND t.ClassNo = @ClassNo ");
  80. }
  81. if (!queryParam["LessonNo"].IsEmpty())
  82. {
  83. dp.Add("LessonNo", queryParam["LessonNo"].ToString(), DbType.String);
  84. strSql.Append(" AND t.LessonNo = @LessonNo ");
  85. }
  86. if (!queryParam["Recipient"].IsEmpty())
  87. {
  88. dp.Add("Recipient", "%" + queryParam["Recipient"].ToString() + "%", DbType.String);
  89. strSql.Append(" AND t.Recipient Like @Recipient ");
  90. }
  91. return this.BaseRepository("CollegeMIS").FindList<TextBookOutEntity>(strSql.ToString(), dp, pagination);
  92. }
  93. catch (Exception ex)
  94. {
  95. if (ex is ExceptionEx)
  96. {
  97. throw;
  98. }
  99. else
  100. {
  101. throw ExceptionEx.ThrowServiceException(ex);
  102. }
  103. }
  104. }
  105. public IEnumerable<TextBookOutEntity> GetListByCode(string code)
  106. {
  107. try
  108. {
  109. return this.BaseRepository("CollegeMIS").FindList<TextBookOutEntity>(x => x.InOutCode == code);
  110. }
  111. catch (Exception ex)
  112. {
  113. if (ex is ExceptionEx)
  114. {
  115. throw;
  116. }
  117. else
  118. {
  119. throw ExceptionEx.ThrowServiceException(ex);
  120. }
  121. }
  122. }
  123. /// <summary>
  124. /// 获取TextBookOut表实体数据
  125. /// </summary>
  126. /// <param name="keyValue">主键</param>
  127. /// <returns></returns>
  128. public TextBookOutEntity GetTextBookOutEntity(string keyValue)
  129. {
  130. try
  131. {
  132. return this.BaseRepository("CollegeMIS").FindEntity<TextBookOutEntity>(x => x.InOutCode == keyValue);
  133. }
  134. catch (Exception ex)
  135. {
  136. if (ex is ExceptionEx)
  137. {
  138. throw;
  139. }
  140. else
  141. {
  142. throw ExceptionEx.ThrowServiceException(ex);
  143. }
  144. }
  145. }
  146. #endregion
  147. #region 提交数据
  148. /// <summary>
  149. /// 删除实体数据
  150. /// </summary>
  151. /// <param name="keyValue">主键</param>
  152. public void DeleteEntity(string keyValue)
  153. {
  154. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  155. try
  156. {
  157. decimal? Num = 0;
  158. var keyValueArr = keyValue.Split(',');
  159. foreach (var item in keyValueArr)
  160. {
  161. var entity = BaseRepository("CollegeMIS").FindEntity<TextBookOutEntity>(x => x.ID == item);
  162. if (entity != null)
  163. {
  164. Num += entity.Variate;
  165. var InOutEntity = db.FindEntity<TextbookInOutEntity>(x => x.BookCode == entity.InOutCode);
  166. if (InOutEntity != null)
  167. {
  168. InOutEntity.FinallyNum += Num;
  169. db.Delete(entity);
  170. db.Update(InOutEntity);
  171. }
  172. else
  173. {
  174. db.Rollback();
  175. }
  176. }
  177. }
  178. db.Commit();
  179. }
  180. catch (Exception ex)
  181. {
  182. db.Rollback();
  183. if (ex is ExceptionEx)
  184. {
  185. throw;
  186. }
  187. else
  188. {
  189. throw ExceptionEx.ThrowServiceException(ex);
  190. }
  191. }
  192. }
  193. /// <summary>
  194. /// 保存实体数据(新增、修改)
  195. /// </summary>
  196. /// <param name="keyValue">主键</param>
  197. /// <param name="entity">实体</param>
  198. public void SaveEntity(string keyValue, TextBookOutEntity entity)
  199. {
  200. try
  201. {
  202. if (keyValue != null)
  203. {
  204. entity.Modify(keyValue);
  205. this.BaseRepository("CollegeMIS").Update(entity);
  206. }
  207. else
  208. {
  209. entity.Create();
  210. this.BaseRepository("CollegeMIS").Insert(entity);
  211. }
  212. }
  213. catch (Exception ex)
  214. {
  215. if (ex is ExceptionEx)
  216. {
  217. throw;
  218. }
  219. else
  220. {
  221. throw ExceptionEx.ThrowServiceException(ex);
  222. }
  223. }
  224. }
  225. /// <summary>
  226. /// 保存
  227. /// </summary>
  228. /// <param name="keyValue"></param>
  229. /// <param name="entity">库存</param>
  230. /// <param name="textbookIndentDateil"></param>
  231. public void SaveEntity(string keyValue, TextbookInOutEntity entity, List<TextBookOutEntity> textbookOutList)
  232. {
  233. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  234. try
  235. {
  236. decimal? variate = 0;
  237. if (textbookOutList.Count > 0)
  238. {
  239. for (int i = 0; i < textbookOutList.Count; i++)
  240. {
  241. textbookOutList[i].InOutCode = entity.BookCode;
  242. textbookOutList[i].LessonNo = entity.LessonNo;
  243. textbookOutList[i].PublishNo = entity.PublishNo;
  244. textbookOutList[i].TextBookNo = entity.TextBookNo;
  245. textbookOutList[i].TextBookName = entity.TextBookName;
  246. textbookOutList[i].FirstAuthor = entity.FirstAuthor;
  247. textbookOutList[i].OtherAuthor = entity.OtherAuthor;
  248. textbookOutList[i].Publisher = entity.Publisher;
  249. textbookOutList[i].Edition = entity.Edition;
  250. textbookOutList[i].Impression = entity.Impression;
  251. textbookOutList[i].Impression = entity.Impression;
  252. variate += textbookOutList[i].Variate;
  253. }
  254. db.Insert(textbookOutList);
  255. if (variate != 0 && variate > 0)
  256. {
  257. var newtextInOutEntity = db.FindEntity<TextbookInOutEntity>(x => x.BookCode == entity.BookCode);
  258. if (newtextInOutEntity != null)
  259. {
  260. newtextInOutEntity.FinallyNum -= variate;
  261. newtextInOutEntity.CKNum += variate;
  262. if (newtextInOutEntity.FinallyNum > 0 || newtextInOutEntity.FinallyNum == 0)
  263. {
  264. db.Update(newtextInOutEntity);
  265. }
  266. else
  267. {
  268. db.Rollback();
  269. }
  270. }
  271. else
  272. {
  273. db.Rollback();
  274. }
  275. }
  276. }
  277. db.Commit();
  278. }
  279. catch (Exception ex)
  280. {
  281. db.Rollback();
  282. if (ex is ExceptionEx)
  283. {
  284. throw;
  285. }
  286. else
  287. {
  288. throw ExceptionEx.ThrowServiceException(ex);
  289. }
  290. }
  291. }
  292. #endregion
  293. }
  294. }