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.
 
 
 
 
 
 

287 lines
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-02 10:37
  16. /// 描 述:教材库存表
  17. /// </summary>
  18. public class TextbookInOutService : RepositoryFactory
  19. {
  20. #region 获取数据
  21. /// <summary>
  22. /// 获取列表数据
  23. /// </summary>
  24. /// <param name="queryJson">条件参数</param>
  25. /// <returns></returns>
  26. public IEnumerable<TextbookInOutEntity> GetList(string queryJson)
  27. {
  28. try
  29. {
  30. //参考写法
  31. var queryParam = queryJson.ToJObject();
  32. //虚拟参数
  33. var dp = new DynamicParameters(new { });
  34. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  35. var strSql = new StringBuilder();
  36. strSql.Append("SELECT *");
  37. strSql.Append(" FROM TextbookInOut t where 1=1 and ISDEl = 0 ");
  38. return this.BaseRepository("CollegeMIS").FindList<TextbookInOutEntity>(strSql.ToString());
  39. }
  40. catch (Exception ex)
  41. {
  42. if (ex is ExceptionEx)
  43. {
  44. throw;
  45. }
  46. else
  47. {
  48. throw ExceptionEx.ThrowServiceException(ex);
  49. }
  50. }
  51. }
  52. /// <summary>
  53. /// 获取列表分页数据
  54. /// </summary>
  55. /// <param name="pagination">分页参数</param>
  56. /// <param name="queryJson">条件参数</param>
  57. /// <returns></returns>
  58. public IEnumerable<TextbookInOutEntity> GetPageList(Pagination pagination, string queryJson)
  59. {
  60. try
  61. {
  62. var strSql = new StringBuilder();
  63. strSql.Append("SELECT *");
  64. strSql.Append(" FROM TextbookInOut t where 1=1 ");
  65. var queryParam = queryJson.ToJObject();
  66. var dp = new DynamicParameters(new { });
  67. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  68. {
  69. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  70. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  71. strSql.Append(" AND ( t.CreateTime >= @startTime AND t.CreateTime <= @endTime ) ");
  72. }
  73. if (!queryParam["SqlParameter"].IsEmpty())
  74. {
  75. string SqlParameter = queryParam["SqlParameter"].ToString();
  76. strSql.Append(SqlParameter);
  77. }
  78. if (!queryParam["keyword"].IsEmpty())
  79. {
  80. strSql.Append(" and ( t.TextBookNo like @keyword or t.TextBookName like @keyword or t.FirstAuthor like @keyword )");
  81. dp.Add("keyword", "%" + queryParam["keyword"].ToString() + "%", DbType.String);
  82. }
  83. if (!queryParam["TextBookName"].IsEmpty())
  84. {
  85. strSql.Append(" and TextBookName like @TextBookName ");
  86. dp.Add("TextBookName", "%" + queryParam["TextBookName"].ToString() + "%", DbType.String);
  87. }
  88. return this.BaseRepository("CollegeMIS").FindList<TextbookInOutEntity>(strSql.ToString(), dp, pagination);
  89. }
  90. catch (Exception ex)
  91. {
  92. if (ex is ExceptionEx)
  93. {
  94. throw;
  95. }
  96. else
  97. {
  98. throw ExceptionEx.ThrowServiceException(ex);
  99. }
  100. }
  101. }
  102. /// <summary>
  103. /// 获取实体数据
  104. /// </summary>
  105. /// <param name="keyValue">主键</param>
  106. /// <returns></returns>
  107. public TextbookInOutEntity GetEntity(string keyValue)
  108. {
  109. try
  110. {
  111. return this.BaseRepository("CollegeMIS").FindEntity<TextbookInOutEntity>(x => x.ID == keyValue && x.IsDel == 0);
  112. }
  113. catch (Exception ex)
  114. {
  115. if (ex is ExceptionEx)
  116. {
  117. throw;
  118. }
  119. else
  120. {
  121. throw ExceptionEx.ThrowServiceException(ex);
  122. }
  123. }
  124. }
  125. /// <summary>
  126. /// 获取实体数据
  127. /// </summary>
  128. /// <param name="keyValue">主键</param>
  129. /// <returns></returns>
  130. public IEnumerable<TextbookInOutEntity> GetInOrOutEntity(string keyValue)
  131. {
  132. try
  133. {
  134. List<TextbookInOutEntity> returnList = new List<TextbookInOutEntity>();
  135. //TextbookInOutEntity InOutList = new TextbookInOutEntity();
  136. List<TextBookInEntity> InEntity = this.BaseRepository("CollegeMIS").FindList<TextBookInEntity>(x => x.InOutCode == keyValue).ToList();
  137. List<TextBookOutEntity> OutEntity = this.BaseRepository("CollegeMIS").FindList<TextBookOutEntity>(x => x.InOutCode == keyValue).ToList();
  138. if (InEntity.Count() > 0 || OutEntity.Count() > 0)
  139. {
  140. for (int i = 0; i < InEntity.Count(); i++)
  141. {
  142. TextbookInOutEntity InOutList = new TextbookInOutEntity();
  143. InOutList.CKORRK = "入库";
  144. InOutList.InorOut = InEntity[i].InOutCode;
  145. InOutList.BookCode = InEntity[i].BookCode;
  146. InOutList.variate = InEntity[i].variate;
  147. InOutList.CreateTime = InEntity[i].CreateTime;
  148. InOutList.CrateUserID = InEntity[i].CrateUserID;
  149. InOutList.Remark = InEntity[i].Remark;
  150. returnList.Add(InOutList);
  151. }
  152. for (int j = 0; j < OutEntity.Count(); j++)
  153. {
  154. TextbookInOutEntity InOutList = new TextbookInOutEntity();
  155. InOutList.CKORRK = "出库";
  156. InOutList.InorOut = OutEntity[j].InOutCode;
  157. InOutList.BookCode = OutEntity[j].BookCode;
  158. InOutList.variate = OutEntity[j].Variate;
  159. InOutList.CreateTime = InEntity[j].CreateTime;
  160. InOutList.CrateUserID = InEntity[j].CrateUserID;
  161. InOutList.Remark = OutEntity[j].Remark;
  162. returnList.Add(InOutList);
  163. }
  164. }
  165. return returnList;
  166. }
  167. catch (Exception ex)
  168. {
  169. if (ex is ExceptionEx)
  170. {
  171. throw;
  172. }
  173. else
  174. {
  175. throw ExceptionEx.ThrowServiceException(ex);
  176. }
  177. }
  178. }
  179. #endregion
  180. #region 提交数据
  181. /// <summary>
  182. /// 删除实体数据
  183. /// </summary>
  184. /// <param name="keyValue">主键</param>
  185. public void DeleteEntity(string keyValue)
  186. {
  187. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  188. try
  189. {
  190. var keyValueArr = keyValue.Split(',');
  191. foreach (var item in keyValueArr)
  192. {
  193. var entity = BaseRepository("CollegeMIS").FindEntity<TextbookInOutEntity>(x => x.ID == item);
  194. entity.IsDel = 1;
  195. db.Update(entity);
  196. }
  197. db.Commit();
  198. }
  199. catch (Exception ex)
  200. {
  201. db.Rollback();
  202. if (ex is ExceptionEx)
  203. {
  204. throw;
  205. }
  206. else
  207. {
  208. throw ExceptionEx.ThrowServiceException(ex);
  209. }
  210. }
  211. }
  212. /// <summary>
  213. /// 保存实体数据(新增、修改)
  214. /// <param name="keyValue">主键</param>
  215. /// <param name="entity">实体</param>
  216. /// </summary>
  217. public void SaveEntity(string keyValue, TextbookInOutEntity entity)
  218. {
  219. try
  220. {
  221. if (!string.IsNullOrEmpty(keyValue))
  222. {
  223. entity.Modify(keyValue);
  224. this.BaseRepository("CollegeMIS").Update(entity);
  225. }
  226. else
  227. {
  228. entity.Create();
  229. this.BaseRepository("CollegeMIS").Insert(entity);
  230. }
  231. }
  232. catch (Exception ex)
  233. {
  234. if (ex is ExceptionEx)
  235. {
  236. throw;
  237. }
  238. else
  239. {
  240. throw ExceptionEx.ThrowServiceException(ex);
  241. }
  242. }
  243. }
  244. /// <summary>
  245. /// 提交
  246. /// </summary>
  247. /// <param name="keyValue"></param>
  248. public void SubmitEntity(string keyValue)
  249. {
  250. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  251. try
  252. {
  253. var keyValueArr = keyValue.Split(',');
  254. foreach (var item in keyValueArr)
  255. {
  256. var entity = BaseRepository("CollegeMIS").FindEntity<TextbookInOutEntity>(x => x.ID == item);
  257. entity.IsSubmit = 1;
  258. db.Update(entity);
  259. }
  260. db.Commit();
  261. }
  262. catch (Exception ex)
  263. {
  264. db.Rollback();
  265. if (ex is ExceptionEx)
  266. {
  267. throw;
  268. }
  269. else
  270. {
  271. throw ExceptionEx.ThrowServiceException(ex);
  272. }
  273. }
  274. }
  275. #endregion
  276. }
  277. }