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.

TextbookInOutService.cs 13 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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 = OutEntity[j].CreateTime;
  160. InOutList.CrateUserID = OutEntity[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. entity.CKNum = 0;
  230. entity.RKNum = 0;
  231. this.BaseRepository("CollegeMIS").Insert(entity);
  232. }
  233. }
  234. catch (Exception ex)
  235. {
  236. if (ex is ExceptionEx)
  237. {
  238. throw;
  239. }
  240. else
  241. {
  242. throw ExceptionEx.ThrowServiceException(ex);
  243. }
  244. }
  245. }
  246. /// <summary>
  247. /// 提交
  248. /// </summary>
  249. /// <param name="keyValue"></param>
  250. public void SubmitEntity(string keyValue)
  251. {
  252. var db = this.BaseRepository("CollegeMIS").BeginTrans();
  253. try
  254. {
  255. var keyValueArr = keyValue.Split(',');
  256. foreach (var item in keyValueArr)
  257. {
  258. var entity = BaseRepository("CollegeMIS").FindEntity<TextbookInOutEntity>(x => x.ID == item);
  259. entity.IsSubmit = 1;
  260. //添加入库总数
  261. entity.RKNum += entity.FinallyNum;
  262. db.Update(entity);
  263. #region 将本次记录保存出库单
  264. TextBookInEntity InEntity = new TextBookInEntity
  265. {
  266. ID = Guid.NewGuid().ToString(),
  267. BookCode = "RK" + DateTime.Now.ToString("yyyyMMddHHmmss"),
  268. InOutCode = entity.BookCode,
  269. LessonNo = entity.LessonNo,
  270. PublishNo = entity.PublishNo,
  271. TextBookNo = entity.TextBookNo,
  272. TextBookName = entity.TextBookName,
  273. FirstAuthor = entity.FirstAuthor,
  274. OtherAuthor = entity.OtherAuthor,
  275. Pubdate = entity.Pubdate,
  276. Publisher = entity.Publisher,
  277. Edition = entity.Edition,
  278. Impression = entity.Impression,
  279. variate = entity.FinallyNum,
  280. CreateTime = DateTime.Now,
  281. CrateUserID = "system",
  282. Remark = "初始数据删除需谨慎"
  283. };
  284. #endregion
  285. db.Insert(InEntity);
  286. }
  287. db.Commit();
  288. }
  289. catch (Exception ex)
  290. {
  291. db.Rollback();
  292. if (ex is ExceptionEx)
  293. {
  294. throw;
  295. }
  296. else
  297. {
  298. throw ExceptionEx.ThrowServiceException(ex);
  299. }
  300. }
  301. }
  302. #endregion
  303. /// <summary>
  304. /// 去重
  305. /// </summary>
  306. /// <param name="keyValue"></param>
  307. /// <param name="TextBookNo"></param>
  308. /// <param name="TextBookName"></param>
  309. /// <param name="PublishNo"></param>
  310. /// <param name="Publisher"></param>
  311. /// <param name="Edition"></param>
  312. /// <param name="Impression"></param>
  313. /// <returns></returns>
  314. public int GetRepetitions(string keyValue, string LessonNo, string TextBookNo, string TextBookName, string PublishNo, string Publisher, string Edition, string Impression)
  315. {
  316. try
  317. {
  318. var HistoryList = new List<TextbookInOutEntity>();
  319. if (!string.IsNullOrEmpty(keyValue))
  320. {
  321. HistoryList = BaseRepository("CollegeMIS").FindList<TextbookInOutEntity>(
  322. x => x.ID == keyValue && x.LessonNo == LessonNo && x.TextBookNo == TextBookNo && x.TextBookName == TextBookName && x.PublishNo == PublishNo &&
  323. x.Publisher == Publisher && x.Edition == Edition && x.Impression == Impression && x.IsDel == 0).ToList();
  324. }
  325. else
  326. {
  327. HistoryList = BaseRepository("CollegeMIS").FindList<TextbookInOutEntity>(
  328. x => x.LessonNo == LessonNo && x.TextBookNo == TextBookNo && x.TextBookName == TextBookName && x.PublishNo == PublishNo &&
  329. x.Publisher == Publisher && x.Edition == Edition && x.Impression == Impression && x.IsDel == 0).ToList();
  330. }
  331. return HistoryList.Count;
  332. }
  333. catch (Exception ex)
  334. {
  335. if (ex is ExceptionEx)
  336. {
  337. throw;
  338. }
  339. else
  340. {
  341. throw ExceptionEx.ThrowServiceException(ex);
  342. }
  343. }
  344. }
  345. }
  346. }