|
- using Dapper;
- using Learun.DataBase.Repository;
- using Learun.Util;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
-
- namespace Learun.Application.TwoDevelopment.AssetManagementSystem
- {
- /// <summary>
- /// 版 本 Learun-ADMS V7.0.6 力软敏捷开发框架
- /// Copyright (c) 2013-2020 力软信息技术(苏州)有限公司
- /// 创 建:超级管理员
- /// 日 期:2022-11-07 14:25
- /// 描 述:经费开支申报
- /// </summary>
- public class FundsApplyService : RepositoryFactory
- {
- #region 获取数据
-
- /// <summary>
- /// 获取页面显示列表数据
- /// </summary>
- /// <param name="pagination">分页参数</param>
- /// <param name="queryJson">查询参数</param>
- /// <returns></returns>
- public IEnumerable<FundsApplyEntity> GetPageList(Pagination pagination, string queryJson)
- {
- try
- {
- var strSql = new StringBuilder();
- strSql.Append("SELECT ");
- strSql.Append(@"
- t.*
- ");
- strSql.Append(" FROM FundsApply t ");
- strSql.Append(" WHERE 1=1 ");
- var queryParam = queryJson.ToJObject();
- // 虚拟参数
- var dp = new DynamicParameters(new { });
- if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
- {
- dp.Add("startTime", queryParam["StartTime"].ToDate(), DbType.DateTime);
- dp.Add("endTime", queryParam["EndTime"].ToDate(), DbType.DateTime);
- strSql.Append(" AND ( t.ApplyTime >= @startTime AND t.ApplyTime <= @endTime ) ");
- }
- if (!queryParam["ApplyUser"].IsEmpty())
- {
- dp.Add("ApplyUser", queryParam["ApplyUser"].ToString(), DbType.String);
- strSql.Append(" AND t.ApplyUser = @ApplyUser ");
- }
- return this.BaseRepository("CollegeMIS").FindList<FundsApplyEntity>(strSql.ToString(), dp, pagination);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取FundsApply表实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <returns></returns>
- public FundsApplyEntity GetFundsApplyEntity(string keyValue)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<FundsApplyEntity>(keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 获取主表实体数据
- /// </summary>
- /// <param name="processId">流程实例ID</param>
- /// <returns></returns>
- public FundsApplyEntity GetEntityByProcessId(string processId)
- {
- try
- {
- return this.BaseRepository("CollegeMIS").FindEntity<FundsApplyEntity>(t => t.ProcessId == processId);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- #region 提交数据
-
- /// <summary>
- /// 删除实体数据
- /// </summary>
- /// <param name="keyValue">主键</param>
- public void DeleteEntity(string keyValue)
- {
- try
- {
- this.BaseRepository("CollegeMIS").Delete<FundsApplyEntity>(t => t.Id == keyValue);
- this.BaseRepository("CollegeMIS").Delete<FundsApplyDetailEntity>(t => t.ApplyId == keyValue);
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- /// 保存实体数据(新增、修改)
- /// </summary>
- /// <param name="keyValue">主键</param>
- /// <param name="entity">实体</param>
- /// <returns></returns>
- public void SaveEntity(string keyValue, FundsApplyEntity entity, List<FundsApplyDetailEntity> detailList)
- {
- var db = this.BaseRepository("CollegeMIS");
- try
- {
- db.BeginTrans();
- if (!string.IsNullOrEmpty(keyValue))
- {
- entity.Modify(keyValue);
- db.Update(entity);
- }
- else
- {
- entity.Create();
- db.Insert(entity);
- }
- //子表
- db.ExecuteBySql($"delete FundsApplyDetail where ApplyId='{entity.Id}'");
- foreach (var detail in detailList)
- {
- detail.Create();
- detail.ApplyId = entity.Id;
- db.Insert(detail);
- }
- db.Commit();
- }
- catch (Exception ex)
- {
- db.Rollback();
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- /// <summary>
- ///
- /// </summary>
- /// <param name="keyValue"></param>
- /// <param name="status"></param>
- /// <param name="processId"></param>
- public void ChangeStatusById(string keyValue, int status, string processId)
- {
- try
- {
- this.BaseRepository("CollegeMIS").ExecuteBySql($"update FundsApply set ProcessId='{processId}',status='{status}' where Id='{keyValue}'");
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- public void ChangeStatusByProcessId(string processId, int status)
- {
- try
- {
- this.BaseRepository("CollegeMIS").ExecuteBySql($"update FundsApply set status='{status}' where ProcessId='{processId}'");
- }
- catch (Exception ex)
- {
- if (ex is ExceptionEx)
- {
- throw;
- }
- else
- {
- throw ExceptionEx.ThrowServiceException(ex);
- }
- }
- }
-
- #endregion
-
- }
- }
|