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.
 
 
 
 
 
 

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