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.
 
 
 
 
 
 

260 lines
8.8 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.LogisticsManagement;
  9. namespace Learun.Application.TwoDevelopment.EducationalAdministration
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
  13. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2022-03-03 10:15
  16. /// 描 述:教材入库
  17. /// </summary>
  18. public class TextBookInService : 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<TextBookInEntity> 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 TextBookIn t ");
  35. strSql.Append(" WHERE 1=1 ");
  36. var queryParam = queryJson.ToJObject();
  37. // 虚拟参数
  38. var dp = new DynamicParameters(new { });
  39. if (!queryParam["TextBookName"].IsEmpty())
  40. {
  41. dp.Add("TextBookName", queryParam["TextBookName"].ToString(), DbType.String);
  42. strSql.Append(" AND t.TextBookName = @TextBookName ");
  43. }
  44. return this.BaseRepository("CollegeMIS").FindList<TextBookInEntity>(strSql.ToString(), dp, pagination);
  45. }
  46. catch (Exception ex)
  47. {
  48. if (ex is ExceptionEx)
  49. {
  50. throw;
  51. }
  52. else
  53. {
  54. throw ExceptionEx.ThrowServiceException(ex);
  55. }
  56. }
  57. }
  58. /// <summary>
  59. /// 获取TextBookIn表实体数据
  60. /// </summary>
  61. /// <param name="keyValue">主键</param>
  62. /// <returns></returns>
  63. public TextBookInEntity GetTextBookInEntity(string keyValue)
  64. {
  65. try
  66. {
  67. return this.BaseRepository("CollegeMIS").FindEntity<TextBookInEntity>(keyValue);
  68. }
  69. catch (Exception ex)
  70. {
  71. if (ex is ExceptionEx)
  72. {
  73. throw;
  74. }
  75. else
  76. {
  77. throw ExceptionEx.ThrowServiceException(ex);
  78. }
  79. }
  80. }
  81. /// <summary>
  82. /// 获取TextBookIn表RK明细
  83. /// </summary>
  84. /// <param name="keyValue">主键</param>
  85. /// <returns></returns>
  86. public IEnumerable<TextBookInEntity> GetInEntity(string keyValue)
  87. {
  88. try
  89. {
  90. return this.BaseRepository("CollegeMIS").FindList<TextBookInEntity>(x => x.InOutCode == keyValue);
  91. }
  92. catch (Exception ex)
  93. {
  94. if (ex is ExceptionEx)
  95. {
  96. throw;
  97. }
  98. else
  99. {
  100. throw ExceptionEx.ThrowServiceException(ex);
  101. }
  102. }
  103. }
  104. #endregion
  105. #region 提交数据
  106. /// <summary>
  107. /// 删除实体数据
  108. /// </summary>
  109. /// <param name="keyValue">主键</param>
  110. public void DeleteEntity(string keyValue)
  111. {
  112. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  113. try
  114. {
  115. decimal? Num = 0;
  116. var keyValueArr = keyValue.Split(',');
  117. foreach (var item in keyValueArr)
  118. {
  119. var entity = BaseRepository("CollegeMIS").FindEntity<TextBookInEntity>(x => x.ID == item);
  120. if (entity != null)
  121. {
  122. Num += entity.variate;
  123. var InOutEntity = db.FindEntity<TextbookInOutEntity>(x => x.BookCode == entity.InOutCode);
  124. if (InOutEntity != null)
  125. {
  126. InOutEntity.FinallyNum = InOutEntity.FinallyNum - Num;
  127. if (InOutEntity.FinallyNum == 0 || InOutEntity.FinallyNum > 0)
  128. {
  129. db.Delete(entity);
  130. db.Update(InOutEntity);
  131. }
  132. else
  133. {
  134. db.Rollback();
  135. }
  136. }
  137. else
  138. {
  139. db.Rollback();
  140. }
  141. }
  142. }
  143. db.Commit();
  144. }
  145. catch (Exception ex)
  146. {
  147. db.Rollback();
  148. if (ex is ExceptionEx)
  149. {
  150. throw;
  151. }
  152. else
  153. {
  154. throw ExceptionEx.ThrowServiceException(ex);
  155. }
  156. }
  157. }
  158. /// <summary>
  159. /// 保存实体数据(新增、修改)
  160. /// </summary>
  161. /// <param name="keyValue">主键</param>
  162. /// <param name="entity">实体</param>
  163. public void SaveEntity(string keyValue, TextBookInEntity entity)
  164. {
  165. try
  166. {
  167. if (!string.IsNullOrEmpty(keyValue))
  168. {
  169. entity.Modify(keyValue);
  170. this.BaseRepository("CollegeMIS").Update(entity);
  171. }
  172. else
  173. {
  174. entity.Create();
  175. this.BaseRepository("CollegeMIS").Insert(entity);
  176. }
  177. }
  178. catch (Exception ex)
  179. {
  180. if (ex is ExceptionEx)
  181. {
  182. throw;
  183. }
  184. else
  185. {
  186. throw ExceptionEx.ThrowServiceException(ex);
  187. }
  188. }
  189. }
  190. /// <summary>
  191. /// 保存
  192. /// </summary>
  193. /// <param name="keyValue"></param>
  194. /// <param name="entity">库存</param>
  195. /// <param name="textbookIndentDateil"></param>
  196. public void SaveEntity(string keyValue, TextbookInOutEntity entity, List<TextBookInEntity> textbookInList)
  197. {
  198. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  199. try
  200. {
  201. decimal? variate = 0;
  202. if (textbookInList.Count > 0)
  203. {
  204. for (int i = 0; i < textbookInList.Count; i++)
  205. {
  206. textbookInList[i].InOutCode = entity.BookCode;
  207. textbookInList[i].LessonNo = entity.LessonNo;
  208. textbookInList[i].PublishNo = entity.PublishNo;
  209. textbookInList[i].TextBookNo = entity.TextBookNo;
  210. textbookInList[i].TextBookName = entity.TextBookName;
  211. textbookInList[i].FirstAuthor = entity.FirstAuthor;
  212. textbookInList[i].OtherAuthor = entity.OtherAuthor;
  213. textbookInList[i].Pubdate = entity.Pubdate;
  214. textbookInList[i].Publisher = entity.Publisher;
  215. textbookInList[i].Edition = entity.Edition;
  216. textbookInList[i].Impression = entity.Impression;
  217. textbookInList[i].Impression = entity.Impression;
  218. variate += textbookInList[i].variate;
  219. }
  220. db.Insert(textbookInList);
  221. if (variate != 0 && variate > 0)
  222. {
  223. var newtextInOutEntity = db.FindEntity<TextbookInOutEntity>(x => x.BookCode == entity.BookCode);
  224. if (newtextInOutEntity != null)
  225. {
  226. newtextInOutEntity.FinallyNum += variate;
  227. newtextInOutEntity.RKNum += variate;
  228. db.Update(newtextInOutEntity);
  229. }
  230. }
  231. }
  232. db.Commit();
  233. }
  234. catch (Exception ex)
  235. {
  236. db.Rollback();
  237. if (ex is ExceptionEx)
  238. {
  239. throw;
  240. }
  241. else
  242. {
  243. throw ExceptionEx.ThrowServiceException(ex);
  244. }
  245. }
  246. }
  247. #endregion
  248. }
  249. }