后厨api
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

116 righe
3.1 KiB

  1. using BPA.SAAS.KitChenManage.Core;
  2. using BPA.SAAS.KitChenManage.Core.Base;
  3. using Furion;
  4. using SqlSugar;
  5. using System;
  6. using System.Linq;
  7. using System.Linq.Dynamic.Core;
  8. using System.Linq.Expressions;
  9. using System.Reflection;
  10. namespace BPA.KitChen.GroupMeal.SqlSugar
  11. {
  12. public class SqlSugarDb
  13. {
  14. public static SqlSugarScope Db { get; set; }
  15. public static SqlSugarScope SqlSugarScope(ConnectionConfig configConnection)
  16. {
  17. //全局过滤
  18. Db = new SqlSugarScope(configConnection, db =>
  19. {
  20. //全局过滤
  21. TableFilterItem(db);
  22. db.Aop.OnLogExecuting = (sql, pars) =>
  23. {
  24. //sql 执行前
  25. };
  26. db.Aop.OnLogExecuted = (sql, pars) =>
  27. {
  28. //sql 执行后
  29. };
  30. db.Aop.OnError = ex =>
  31. {
  32. //sql 异常
  33. };
  34. });
  35. return Db;
  36. }
  37. #region 全局过滤器及配置
  38. /// <summary>
  39. /// 全局过滤
  40. /// </summary>
  41. private static void TableFilterItem(SqlSugarClient db)
  42. {
  43. //添加默认值
  44. DataExecuting(db);
  45. db.QueryFilter.AddTableFilter<IGroupId>(it => it.GroupId == "");
  46. }
  47. /// <summary>
  48. /// 附默认值
  49. /// </summary>
  50. /// <param name="db"></param>
  51. private static void DataExecuting(SqlSugarClient db)
  52. {
  53. //全局字段赋值
  54. db.Aop.DataExecuting = (oldValue, entityInfo) =>
  55. {
  56. InsertByObject(entityInfo);
  57. UpdateByObject(oldValue, entityInfo);
  58. };
  59. }
  60. /// <summary>
  61. ///插入数据时附默认值
  62. /// </summary>
  63. /// <param name="entityInfo"></param>
  64. private static void InsertByObject(DataFilterModel entityInfo)
  65. {
  66. if (entityInfo.OperationType != DataFilterType.InsertByObject) return;
  67. switch (entityInfo.PropertyName)
  68. {
  69. case "CreateAt":
  70. entityInfo.SetValue(DateTime.Now);
  71. break;
  72. case "CreateBy":
  73. entityInfo.SetValue("");
  74. break;
  75. case "GroupId":
  76. entityInfo.SetValue(CurrentUser.GroupId);
  77. break;
  78. }
  79. }
  80. /// <summary>
  81. /// 修改数据时附默认值
  82. /// </summary>
  83. /// <param name="oldValue"></param>
  84. /// <param name="entityInfo"></param>
  85. private static void UpdateByObject(object oldValue, DataFilterModel entityInfo)
  86. {
  87. if (entityInfo.OperationType != DataFilterType.UpdateByObject) return;
  88. switch (entityInfo.PropertyName)
  89. {
  90. case "UpdateAt":
  91. entityInfo.SetValue(DateTime.Now);
  92. break;
  93. case "UpdateBy":
  94. entityInfo.SetValue("");
  95. break;
  96. }
  97. }
  98. #endregion
  99. }
  100. }