BlLogOperation.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using ProjectBase.Data.BaseDAL;
  2. using ProjectBase.Util;
  3. using SIASUN.Autopilot.DAL.IDALSQL;
  4. using SIASUN.Autopilot.Model;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data.Common;
  8. using System.Text;
  9. namespace SIASUN.Autopilot.BLL
  10. {
  11. public class BlLogOperation : BaseBLL<MoLogOperation>
  12. {
  13. private IDalLogOperation dalLogOperation;
  14. /// <summary>
  15. /// 构造函数
  16. /// </summary>
  17. public BlLogOperation() : base()
  18. {
  19. base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
  20. dalLogOperation = baseDal as IDalLogOperation;
  21. }
  22. /// <summary>
  23. /// 获取组织ID与组织名称的集合
  24. /// </summary>
  25. /// <returns></returns>
  26. public Dictionary<string, string> GetGroupName()
  27. {
  28. Dictionary<string, string> dic = new Dictionary<string, string>();
  29. //BlAuthoryGroup bl = new BlAuthoryGroup();
  30. List<MoAuthoryGroup> group = BLLFactory<BlAuthoryGroup>.Instance.GetAll();
  31. if (group.Count == 0 || group == null)
  32. {
  33. return null;
  34. }
  35. foreach (MoAuthoryGroup item in group)
  36. {
  37. dic.Add(item.GroupId, item.GroupName);
  38. }
  39. return dic;
  40. }
  41. /// <summary>
  42. /// 根据相关信息,写入用户的操作日志记录
  43. /// </summary>
  44. /// <param name="userId">操作用户</param>
  45. /// <param name="tableName">操作表名称</param>
  46. /// <param name="operationType">操作类型</param>
  47. /// <param name="note">操作详细表述,目前数据表不包含这个字段,赋值为空</param>
  48. /// <param name="trans">事务对象</param>
  49. /// <returns></returns>
  50. public static bool OnOperationLog(string userId, string tableName, string operationType, string note = null, DbTransaction trans = null)
  51. {
  52. //虽然实现了这个事件,但是我们还需要判断该表是否在配置表里面,如果不在,则不记录操作日志。
  53. //BlLogOperationSetting blSetting = new BlLogOperationSetting();
  54. MoLogOperationSetting settingInfo = BLLFactory<BlLogOperationSetting>.Instance.FindByTableName(tableName, trans);
  55. if (settingInfo != null)
  56. {
  57. bool insert = operationType == "增加" && settingInfo.InsertLog;
  58. bool update = operationType == "修改" && settingInfo.UpdateLog;
  59. bool delete = operationType == "删除" && settingInfo.DeleteLog;
  60. if (insert || update || delete)
  61. {
  62. MoLogOperation info = new MoLogOperation();
  63. info.TableName = tableName;
  64. info.Type = operationType;
  65. info.Time = DateTime.Now;
  66. if (!string.IsNullOrEmpty(userId))
  67. {
  68. //BlAuthoryUser blUser = new BlAuthoryUser();
  69. MoAuthoryUser userInfo = BLLFactory<BlAuthoryUser>.Instance.FindByID(new string[] { userId }, trans);
  70. if (userInfo != null)
  71. {
  72. info.Account = userId;
  73. info.Name = userInfo.UserName;
  74. info.GroupId = userInfo.GroupId;
  75. }
  76. }
  77. info.Ip = SysEnvironment.Ip;
  78. info.Mac = SysEnvironment.Mac;
  79. //BlLogOperation bl = new BlLogOperation();
  80. return BLLFactory<BlLogOperation>.Instance.Insert(info, trans);
  81. //return true;
  82. }
  83. }
  84. return false;
  85. }
  86. }
  87. }