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.
214 lines
9.8 KiB
214 lines
9.8 KiB
2 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Security.Claims;
|
||
|
using Yitter.IdGenerator;
|
||
|
using Znyc.Cloudcar.Admin.Commons.Cache;
|
||
|
using Znyc.Cloudcar.Admin.Commons.Helpers;
|
||
|
using Znyc.Cloudcar.Admin.Commons.Json;
|
||
|
using Znyc.Cloudcar.Admin.Commons.Log;
|
||
|
using Znyc.Cloudcar.Admin.Commons.Services;
|
||
|
using Znyc.Cloudcar.Admin.Security.Dtos;
|
||
|
using Znyc.Cloudcar.Admin.Security.Entitys;
|
||
|
using Znyc.Cloudcar.Admin.Security.IRepositories;
|
||
|
using Znyc.Cloudcar.Admin.Security.IServices;
|
||
|
|
||
|
namespace Znyc.Cloudcar.Admin.Security.Services
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// </summary>
|
||
|
public class ExceptionsLogsService : BaseService<ExceptionsLogsEntity, ExceptionsLogsOutputDto, long>,
|
||
|
IExceptionsLogsService
|
||
|
{
|
||
|
private readonly IExceptionsLogsRepository _iLogRepository;
|
||
|
private readonly IUserRepository _iuserRepository;
|
||
|
|
||
|
/// <summary>
|
||
|
/// </summary>
|
||
|
/// <param name="repository"></param>
|
||
|
/// <param name="userRepository"></param>
|
||
|
public ExceptionsLogsService(IExceptionsLogsRepository repository, IUserRepository userRepository) :
|
||
|
base(repository)
|
||
|
{
|
||
|
_iLogRepository = repository;
|
||
|
_iuserRepository = userRepository;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����������ѯ���ݿ�,�����ض���(���ڷ�ҳ������ʾ)
|
||
|
/// </summary>
|
||
|
/// <param name="search">��ѯ������</param>
|
||
|
/// <returns>ָ�������ļ���</returns>
|
||
|
//public async Task<PageResult<ExceptionsLogsOutputDto>> FindWithPagerSearchAsync(SearchExceptionsLogsModel search)
|
||
|
//{
|
||
|
// bool order = search.Order == "asc" ? false : true;
|
||
|
// string where = GetDataPrivilege(false);
|
||
|
// if (!string.IsNullOrEmpty(search.CreatedTime1))
|
||
|
// {
|
||
|
// @where += " and CreatedTime >='" + search.CreatedTime1.ToDateTime() + "'";
|
||
|
// }
|
||
|
|
||
|
// if (!string.IsNullOrEmpty(search.CreatedTime2))
|
||
|
// {
|
||
|
// @where += " and CreatedTime <='" + search.CreatedTime2.ToDateTime() + "'";
|
||
|
// }
|
||
|
|
||
|
// if (!string.IsNullOrEmpty(search.Filter.IPAddress))
|
||
|
// {
|
||
|
// @where += string.Format(" and IPAddress = '{0}'", search.Filter.IPAddress);
|
||
|
// };
|
||
|
// if (!string.IsNullOrEmpty(search.Filter.Account))
|
||
|
// {
|
||
|
// @where += string.Format(" and Account = '{0}'", search.Filter.Account);
|
||
|
// };
|
||
|
// PagerInfo pagerInfo = new PagerInfo
|
||
|
// {
|
||
|
// CurrenetPageIndex = search.CurrenetPageIndex,
|
||
|
// PageSize = search.PageSize
|
||
|
// };
|
||
|
|
||
|
// //Expression<Func<Log, bool>> filter = log => true;
|
||
|
// //if (!string.IsNullOrEmpty(search.Keywords))
|
||
|
// //{
|
||
|
// // filter = filter.And(log => log.Account.StartsWith(search.Keywords) || log.ModuleName.StartsWith(search.Keywords) || log.IPAddress.StartsWith(search.Keywords)
|
||
|
// // || log.IPAddressName.StartsWith(search.Keywords) || log.Description.StartsWith(search.Keywords));
|
||
|
// //}
|
||
|
// //if (!string.IsNullOrEmpty(search.EnCode))
|
||
|
// //{
|
||
|
// // filter = filter.And(log=>search.EnCode.Contains(log.Type));
|
||
|
// //}
|
||
|
// List<ExceptionsLogsEntity> list = await _iLogRepository.FindWithPagerAsync(where, pagerInfo, search.Sort, order);
|
||
|
// PageResult<ExceptionsLogsOutputDto> pageResult = new PageResult<ExceptionsLogsOutputDto>
|
||
|
// {
|
||
|
// CurrentPage = pagerInfo.CurrenetPageIndex,
|
||
|
// Items = list.MapTo<ExceptionsLogsOutputDto>(),
|
||
|
// ItemsPerPage = pagerInfo.PageSize,
|
||
|
// TotalItems = pagerInfo.RecordCount
|
||
|
// };
|
||
|
// return pageResult;
|
||
|
//}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����������Ϣ��д���û��IJ�����־��¼
|
||
|
/// </summary>
|
||
|
/// <param name="tableName">����������</param>
|
||
|
/// <param name="operationType">��������</param>
|
||
|
/// <param name="note">������ϸ����</param>
|
||
|
/// <returns></returns>
|
||
|
public bool OnOperationLog(string tableName, string operationType, string note)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
//��Ȼʵ���������¼����������ǻ���Ҫ�жϸñ��Ƿ������ñ����棬�������ڣ���¼������־��
|
||
|
//var identities = _httpContextAccessor.HttpContext.User.Identities;
|
||
|
if (HttpContextHelper.HttpContext == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
IEnumerable<ClaimsIdentity> identities = HttpContextHelper.HttpContext.User.Identities;
|
||
|
ClaimsIdentity claimsIdentity = identities.First();
|
||
|
List<Claim> claimlist = claimsIdentity.Claims as List<Claim>;
|
||
|
string userId = claimlist[0].Value;
|
||
|
CacheHelper cacheHelper = new CacheHelper();
|
||
|
AdminCurrentUser AdminCurrentUser = new AdminCurrentUser();
|
||
|
AdminCurrentUser user = cacheHelper.Get("login_user_" + userId).ToJson().ToObject<AdminCurrentUser>();
|
||
|
if (user != null)
|
||
|
{
|
||
|
AdminCurrentUser = user;
|
||
|
bool insert = operationType == DbLogType.Create.ToString();
|
||
|
; //&& settingInfo.InsertLog;
|
||
|
bool update = operationType == DbLogType.Update.ToString(); // && settingInfo.UpdateLog;
|
||
|
bool delete = operationType == DbLogType.Delete.ToString(); // && settingInfo.DeleteLog;
|
||
|
bool deletesoft = operationType == DbLogType.DeleteSoft.ToString(); // && settingInfo.DeleteLog;
|
||
|
bool exception = operationType == DbLogType.Exception.ToString(); // && settingInfo.DeleteLog;
|
||
|
bool sql = operationType == DbLogType.SQL.ToString(); // && settingInfo.DeleteLog;
|
||
|
|
||
|
if (insert || update || delete || deletesoft || exception || sql)
|
||
|
{
|
||
|
ExceptionsLogsEntity info = new ExceptionsLogsEntity
|
||
|
{
|
||
|
Id = YitIdHelper.NextId()
|
||
|
};
|
||
|
//info.ModuleName = tableName;
|
||
|
//info.Type = operationType;
|
||
|
//info.Description = note;
|
||
|
//info.Date = info.CreatedTime = DateTime.Now;
|
||
|
//info.CreatedUserId = CurrentUser.UserId;
|
||
|
//info.Account = AdminCurrentUser.Account;
|
||
|
//info.UserName = AdminCurrentUser.UserName;
|
||
|
//info.OrganizeId = AdminCurrentUser.OrganizeId;
|
||
|
//info.IPAddress = AdminCurrentUser.CurrentLoginIP;
|
||
|
//info.IPAddressName = AdminCurrentUser.IPAddressName;
|
||
|
//info.Result = true;
|
||
|
long lg = _iLogRepository.Insert(info);
|
||
|
if (lg > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
Log4NetHelper.Error("", ex);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ����������Ϣ��д���û��IJ�����־��¼
|
||
|
/// ��Ҫ����д����ģ����־
|
||
|
/// </summary>
|
||
|
/// <param name="module">����ģ������</param>
|
||
|
/// <param name="operationType">��������</param>
|
||
|
/// <param name="note">������ϸ����</param>
|
||
|
/// <param name="AdminCurrentUser">�����û�</param>
|
||
|
/// <returns></returns>
|
||
|
public bool OnOperationLog(string module, string operationType, string note, AdminCurrentUser AdminCurrentUser)
|
||
|
{
|
||
|
//��Ȼʵ���������¼����������ǻ���Ҫ�жϸñ��Ƿ������ñ����棬�������ڣ���¼������־��
|
||
|
//OperationLogSettingInfo settingInfo = BLLFactory<OperationLogSetting>.Instance.FindByTableName(tableName, trans);
|
||
|
|
||
|
if (AdminCurrentUser != null)
|
||
|
{
|
||
|
bool login = operationType == DbLogType.Login.ToString();
|
||
|
bool visit = operationType == DbLogType.Visit.ToString();
|
||
|
bool exit = operationType == DbLogType.Exit.ToString();
|
||
|
bool other = operationType == DbLogType.Other.ToString();
|
||
|
bool insert = operationType == DbLogType.Create.ToString();
|
||
|
bool update = operationType == DbLogType.Update.ToString();
|
||
|
bool delete = operationType == DbLogType.Delete.ToString();
|
||
|
bool deletesoft = operationType == DbLogType.DeleteSoft.ToString();
|
||
|
bool exception = operationType == DbLogType.Exception.ToString();
|
||
|
if (login || visit || exit || other || insert || update || delete || deletesoft || exception)
|
||
|
{
|
||
|
ExceptionsLogsEntity info = new ExceptionsLogsEntity
|
||
|
{
|
||
|
Id = YitIdHelper.NextId()
|
||
|
};
|
||
|
//info.ModuleName = module;
|
||
|
//info.Type = operationType;
|
||
|
//info.Description = note;
|
||
|
//info.Date = info.CreatedTime = DateTime.Now;
|
||
|
//info.CreatedUserId = CurrentUser.UserId;
|
||
|
//info.Account = AdminCurrentUser.Account;
|
||
|
//info.UserName = AdminCurrentUser.UserName;
|
||
|
//info.OrganizeId = AdminCurrentUser.OrganizeId;
|
||
|
//info.IPAddress = AdminCurrentUser.CurrentLoginIP;
|
||
|
//info.IPAddressName = IpAddressUtil.GetCityByIp(AdminCurrentUser.CurrentLoginIP);
|
||
|
//info.Result = true;
|
||
|
long lg = _iLogRepository.Insert(info);
|
||
|
if (lg > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|