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.
 
 
 
 
 
 

324 regels
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.Linq;
  8. using System.Text;
  9. namespace Learun.Application.TwoDevelopment.AssetManagementSystem
  10. {
  11. /// <summary>
  12. /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
  13. /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
  14. /// 创 建:超级管理员
  15. /// 日 期:2022-11-07 14:25
  16. /// 描 述:经费开支申报
  17. /// </summary>
  18. public class FundsApplyService : 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<FundsApplyEntity> GetPageList(Pagination pagination, string queryJson)
  28. {
  29. try
  30. {
  31. var strSql = new StringBuilder();
  32. strSql.Append("SELECT ");
  33. strSql.Append(@"
  34. t.*
  35. ");
  36. strSql.Append(" FROM FundsApply t ");
  37. strSql.Append(" WHERE 1=1 ");
  38. var queryParam = queryJson.ToJObject();
  39. // 虚拟参数
  40. var dp = new DynamicParameters(new { });
  41. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  42. {
  43. dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
  44. dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
  45. strSql.Append(" AND ( t.ApplyTime >= @startTime AND t.ApplyTime <= @endTime ) ");
  46. }
  47. var userLogin = LoginUserInfo.Get();
  48. //校长
  49. var PrincipalRole = Config.GetValue("PrincipalRoleId");
  50. //按角色查询是否有查看的权限
  51. var FundsApplyRole = Config.GetValue("FundsApplyRoleId");
  52. var loginInfoRoleIds = LoginUserInfo.Get().roleIds;
  53. if (!userLogin.Description.Contains("管理员") && !loginInfoRoleIds.Split(',').Contains(PrincipalRole)&& !loginInfoRoleIds.Split(',').Contains(FundsApplyRole))
  54. {
  55. strSql.Append(" AND t.ApplyUser = '" + userLogin.userId + "' ");
  56. }
  57. else
  58. {
  59. if (!queryParam["ApplyUser"].IsEmpty())
  60. {
  61. dp.Add("ApplyUser", queryParam["ApplyUser"].ToString(), DbType.String);
  62. strSql.Append(" AND t.ApplyUser = @ApplyUser ");
  63. }
  64. }
  65. return this.BaseRepository("CollegeMIS").FindList<FundsApplyEntity>(strSql.ToString(), dp, pagination);
  66. }
  67. catch (Exception ex)
  68. {
  69. if (ex is ExceptionEx)
  70. {
  71. throw;
  72. }
  73. else
  74. {
  75. throw ExceptionEx.ThrowServiceException(ex);
  76. }
  77. }
  78. }
  79. /// <summary>
  80. /// 获取FundsApply表实体数据
  81. /// </summary>
  82. /// <param name="keyValue">主键</param>
  83. /// <returns></returns>
  84. public FundsApplyEntity GetFundsApplyEntity(string keyValue)
  85. {
  86. try
  87. {
  88. return this.BaseRepository("CollegeMIS").FindEntity<FundsApplyEntity>(keyValue);
  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="processId">流程实例ID</param>
  106. /// <returns></returns>
  107. public FundsApplyEntity GetEntityByProcessId(string processId)
  108. {
  109. try
  110. {
  111. return this.BaseRepository("CollegeMIS").FindEntity<FundsApplyEntity>(t => t.ProcessId == processId);
  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. /// 获取FundsApply表实体数据
  127. /// </summary>
  128. /// <param name="keyValue">主键</param>
  129. /// <returns></returns>
  130. public string GetCode()
  131. {
  132. try
  133. {
  134. var strSql = new StringBuilder();
  135. strSql.Append(@"select * from FundsApply where 1= 1 and ApplyTime >= '" + DateTime.Now.Date + "' ");
  136. var data = this.BaseRepository("CollegeMIS").FindList<FundsApplyEntity>(strSql.ToString()).OrderByDescending(x => x.EnCode).FirstOrDefault();
  137. var Code = "JFKZ_" + CommonHelper.StringTime();
  138. if (data != null && !string.IsNullOrEmpty(data.EnCode))
  139. {
  140. var NCode = data.EnCode.Substring(data.EnCode.Length - 2, 2);
  141. Code = Code + (Convert.ToInt32(NCode) + 1).ToString().PadLeft(2, '0');
  142. }
  143. else
  144. {
  145. Code = Code + "01";
  146. }
  147. return Code;
  148. }
  149. catch (Exception ex)
  150. {
  151. if (ex is ExceptionEx)
  152. {
  153. throw;
  154. }
  155. else
  156. {
  157. throw ExceptionEx.ThrowServiceException(ex);
  158. }
  159. }
  160. }
  161. public string SaveCode(string Code, string keyValue)
  162. {
  163. var result = Code;
  164. var strSql = new StringBuilder();
  165. strSql.Append(@"select * from FundsApply where 1= 1 and ApplyTime >= '" + DateTime.Now.Date + "' and Encode = '" + Code + "'");
  166. var data = this.BaseRepository("CollegeMIS").FindList<FundsApplyEntity>(strSql.ToString()).FirstOrDefault();
  167. var Codes = "JFKZ_" + CommonHelper.StringTime();
  168. if (data != null && !string.IsNullOrEmpty(data.EnCode))
  169. {
  170. if (!string.IsNullOrEmpty(keyValue))
  171. {
  172. if (data.Id == keyValue)
  173. {
  174. return result;
  175. }
  176. else if (data.Id != keyValue && Code != data.EnCode)
  177. {
  178. var NCode = data.EnCode.Substring(data.EnCode.Length - 2, 2);
  179. result = Codes + (Convert.ToInt32(NCode) + 1).ToString().PadLeft(2, '0');
  180. }
  181. }
  182. else
  183. {
  184. if (Code == data.EnCode)
  185. {
  186. var NCode = data.EnCode.Substring(data.EnCode.Length - 2, 2);
  187. result = Codes + (Convert.ToInt32(NCode) + 1).ToString().PadLeft(2, '0');
  188. }
  189. else if (Code != data.EnCode)
  190. {
  191. result = Code;
  192. }
  193. }
  194. }
  195. return result;
  196. }
  197. #endregion
  198. #region 提交数据
  199. /// <summary>
  200. /// 删除实体数据
  201. /// </summary>
  202. /// <param name="keyValue">主键</param>
  203. public void DeleteEntity(string keyValue)
  204. {
  205. try
  206. {
  207. this.BaseRepository("CollegeMIS").Delete<FundsApplyEntity>(t => t.Id == keyValue);
  208. this.BaseRepository("CollegeMIS").Delete<FundsApplyDetailEntity>(t => t.ApplyId == keyValue);
  209. }
  210. catch (Exception ex)
  211. {
  212. if (ex is ExceptionEx)
  213. {
  214. throw;
  215. }
  216. else
  217. {
  218. throw ExceptionEx.ThrowServiceException(ex);
  219. }
  220. }
  221. }
  222. /// <summary>
  223. /// 保存实体数据(新增、修改)
  224. /// </summary>
  225. /// <param name="keyValue">主键</param>
  226. /// <param name="entity">实体</param>
  227. /// <returns></returns>
  228. public void SaveEntity(string keyValue, FundsApplyEntity entity, List<FundsApplyDetailEntity> detailList)
  229. {
  230. var db = this.BaseRepository("CollegeMIS");
  231. try
  232. {
  233. db.BeginTrans();
  234. if (!string.IsNullOrEmpty(keyValue))
  235. {
  236. entity.Modify(keyValue);
  237. db.Update(entity);
  238. }
  239. else
  240. {
  241. entity.Create();
  242. db.Insert(entity);
  243. }
  244. //子表
  245. db.ExecuteBySql($"delete FundsApplyDetail where ApplyId='{entity.Id}'");
  246. foreach (var detail in detailList)
  247. {
  248. detail.Create();
  249. detail.ApplyId = entity.Id;
  250. db.Insert(detail);
  251. }
  252. db.Commit();
  253. }
  254. catch (Exception ex)
  255. {
  256. db.Rollback();
  257. if (ex is ExceptionEx)
  258. {
  259. throw;
  260. }
  261. else
  262. {
  263. throw ExceptionEx.ThrowServiceException(ex);
  264. }
  265. }
  266. }
  267. /// <summary>
  268. ///
  269. /// </summary>
  270. /// <param name="keyValue"></param>
  271. /// <param name="status"></param>
  272. /// <param name="processId"></param>
  273. public void ChangeStatusById(string keyValue, int status, string processId)
  274. {
  275. try
  276. {
  277. this.BaseRepository("CollegeMIS").ExecuteBySql($"update FundsApply set ProcessId='{processId}',status='{status}' where Id='{keyValue}'");
  278. }
  279. catch (Exception ex)
  280. {
  281. if (ex is ExceptionEx)
  282. {
  283. throw;
  284. }
  285. else
  286. {
  287. throw ExceptionEx.ThrowServiceException(ex);
  288. }
  289. }
  290. }
  291. public void ChangeStatusByProcessId(string processId, int status)
  292. {
  293. try
  294. {
  295. this.BaseRepository("CollegeMIS").ExecuteBySql($"update FundsApply set status='{status}' where ProcessId='{processId}'");
  296. }
  297. catch (Exception ex)
  298. {
  299. if (ex is ExceptionEx)
  300. {
  301. throw;
  302. }
  303. else
  304. {
  305. throw ExceptionEx.ThrowServiceException(ex);
  306. }
  307. }
  308. }
  309. #endregion
  310. }
  311. }