123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using YiSha.Util;
- using YiSha.Util.Extension;
- using YiSha.Util.Model;
- using YiSha.Data.Repository;
- using YiSha.Entity.SystemManage;
- using YiSha.Model.Param.SystemManage;
- using System.Text;
- using System.Data.Common;
- using YiSha.Data;
- using YiSha.Enum;
- namespace YiSha.Service.SystemManage
- {
- public partial class LogApiService
- {
- private IRepositoryFactory _baseRepository;
- public LogApiService(IRepositoryFactory baseRepository)
- {
- _baseRepository = baseRepository;
- }
- #region 获取数据
- public async Task<List<LogApiEntity>> GetListPartial(LogApiListParam param)
- {
- var strSql = new StringBuilder();
- List<DbParameter> filter = ListFilterPartial(param, strSql);
- var list = await _baseRepository.BaseRepository(dbConnectType).FindList<LogApiEntity>(strSql.ToString(), filter.ToArray());
- return list.ToList();
- }
- public async Task<List<LogApiEntity>> GetPageListPartial(LogApiListParam param, Pagination pagination)
- {
- var strSql = new StringBuilder();
- List<DbParameter> filter = ListFilterPartial(param, strSql);
- var list = await _baseRepository.BaseRepository(dbConnectType).FindList<LogApiEntity>(strSql.ToString(), filter.ToArray(), pagination);
- return list.ToList();
- }
- public async Task<LogApiEntity> GetEntityPartial(int id)
- {
- return await _baseRepository.BaseRepository(dbConnectType).FindEntity<LogApiEntity>(id);
- }
- #endregion
- #region 提交数据
- public async Task SaveFormPartial(LogApiEntity entity)
- {
- if (entity.Id.IsNullOrZero())
- {
- await entity.Create();
- await _baseRepository.BaseRepository(dbConnectType).Insert<LogApiEntity>(entity);
- }
- else
- {
- await _baseRepository.BaseRepository(dbConnectType).Update<LogApiEntity>(entity);
- }
- }
- public async Task RemoveAllFormPartial()
- {
- await _baseRepository.BaseRepository(dbConnectType).ExecuteBySql("truncate table SysLogApi");
- }
- #endregion
- #region 私有方法
- private List<DbParameter> ListFilterPartial(LogApiListParam param, StringBuilder strSql)
- {
- strSql.Append(@"SELECT a.Id,
- a.BaseCreateTime,
- a.BaseCreatorId,
- a.LogStatus,
- a.Remark,
- a.ExecuteUrl,
- a.ExecuteParam,
- a.ExecuteResult,
- a.ExecuteTime,
- b.UserName,
- c.DepartmentName
- FROM SysLogApi a
- LEFT JOIN SysUser b ON a.BaseCreatorId = b.Id
- LEFT JOIN SysDepartment c ON b.DepartmentId = c.Id
- WHERE 1 = 1 and a.BaseIsDelete = @BaseIsDelete ");
- var parameter = new List<DbParameter>();
- parameter.Add(DbParameterExtension.CreateDbParameter("@BaseIsDelete", (int)IsDeleteEnum.No, dbConnectType));
- if (param != null)
- {
- if (!string.IsNullOrEmpty(param.UserName))
- {
- strSql.Append(" AND b.UserName like @UserName");
- parameter.Add(DbParameterExtension.CreateDbParameter("@UserName", '%' + param.UserName + '%', dbConnectType));
- }
- if (param.LogStatus > -1)
- {
- strSql.Append(" AND a.LogStatus = @LogStatus");
- parameter.Add(DbParameterExtension.CreateDbParameter("@LogStatus", param.LogStatus, dbConnectType));
- }
- if (!string.IsNullOrEmpty(param.ExecuteUrl))
- {
- strSql.Append(" AND a.ExecuteUrl like @ExecuteUrl");
- parameter.Add(DbParameterExtension.CreateDbParameter("@ExecuteUrl", '%' + param.ExecuteUrl + '%', dbConnectType));
- }
- if (!string.IsNullOrEmpty(param.StartTime.ParseToString()))
- {
- strSql.Append(" AND a.BaseCreateTime >= @StartTime");
- parameter.Add(DbParameterExtension.CreateDbParameter("@StartTime", param.StartTime, dbConnectType));
- }
- if (!string.IsNullOrEmpty(param.EndTime.ParseToString()))
- {
- param.EndTime = param.EndTime.Value.Date.Add(new TimeSpan(23, 59, 59));
- strSql.Append(" AND a.BaseCreateTime <= @EndTime");
- parameter.Add(DbParameterExtension.CreateDbParameter("@EndTime", param.EndTime, dbConnectType));
- }
- }
- return parameter;
- }
- /// <summary>
- /// 列表条件过滤
- /// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释)
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private Expression<Func<LogApiEntity, bool>> ListFilterPartial(LogApiListParam param)
- {
- var expression = LinqExtensions.True<LogApiEntity>();
- expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);
- if (param != null)
- {
- }
- return expression;
- }
- #endregion
- }
- }
|