RepositoryTask.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using SqlSugar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. using System.Text;
  7. using wms.dto;
  8. using wms.dto.request.hj;
  9. using wms.dto.request.hj.dto;
  10. using wms.sqlsugar.model;
  11. using wms.sqlsugar.model.hj;
  12. using wms.util.Check;
  13. using static wms.dto.request.hj.dto.ReportResponse;
  14. namespace wms.sqlsugar
  15. {
  16. /// <summary>
  17. /// 创建仓储
  18. /// </summary>
  19. /// <typeparam name="T"></typeparam>
  20. public class RepositoryTask<T> : SimpleClient<T> where T :class, new()
  21. {
  22. public RepositoryTask()
  23. {
  24. //固定数据库用法
  25. base.Context = SqlSugarHelper.Db.GetConnectionScopeWithAttr<T>();
  26. //动态库用法一般用于维护数据库连接字符串根据用法
  27. //if (!SqlSugarHelper.Db.IsAnyConnection("用户读出来的数据库ConfigId"))
  28. //{
  29. // SqlSugarHelper.Db.AddConnection(new ConnectionConfig() { 数据库读出来信息 });
  30. //}
  31. //base.Context = SqlSugarHelper.Db.GetConnectionScope("用户读出来的数据库ConfigId");
  32. }
  33. public T InsertReturnEntity(T t)
  34. {
  35. return base.Context.Insertable(t).ExecuteReturnEntity();
  36. }
  37. public int InsertableSplitTable(T t)
  38. {
  39. return base.Context.Insertable(t).SplitTable().ExecuteCommand();
  40. }
  41. public int InsertableSplitTable(List<T> t)
  42. {
  43. return base.Context.Insertable(t).SplitTable().ExecuteCommand();
  44. }
  45. //public int DelableSplitTable<T>(List<long> ids) where T:BaseModel
  46. //{
  47. // return base.Context.Deleteable<T>(p=> ids.Contains(p.Id)).SplitTable().ExecuteCommand();
  48. //}
  49. /// <summary>
  50. /// 该方法默认不更新CreatedUserId,CreatedTime
  51. /// </summary>
  52. /// <param name="entity"></param>
  53. /// <returns></returns>
  54. public bool UpdateEntity(T entity)
  55. {
  56. return base.Context.Updateable(entity).IgnoreColumns(new string[] { "AddWho", "AddTime" }).ExecuteCommand() > 0;
  57. }
  58. public bool UpdateModelColumns(Expression<Func<T, T>> Columns, Expression<Func<T, bool>> WhereExpression)
  59. {
  60. return base.Update(Columns, WhereExpression);
  61. }
  62. public T GetModelByExpression(Expression<Func<T, bool>> WhereExpression)
  63. {
  64. return base.GetSingle(WhereExpression);
  65. }
  66. public List<hjSysConfig> GetTunList(TunnelRequest request)
  67. {
  68. var list = base.Context.Queryable<hjSysConfig>()
  69. .WhereIF(!string.IsNullOrEmpty(request.WareHouse), p => p.Default2 == request.WareHouse)
  70. .WhereIF(!string.IsNullOrEmpty(request.Tunnel), p => p.Default1 == request.Tunnel)
  71. .ToList();
  72. return list;
  73. }
  74. public bool UpdateTunStatu(long id, string statu, long userId)
  75. {
  76. return base.Context.Updateable<hjSysConfig>().SetColumns(it => new hjSysConfig()
  77. {
  78. SContent = statu,
  79. EditTime = DateTime.Now
  80. }).Where(it => it.Id == id).ExecuteCommand() > 0;
  81. }
  82. }
  83. }