MenuAuthorizeService.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using YiSha.Data.Repository;
  8. using YiSha.Entity.SystemManage;
  9. using YiSha.Enum;
  10. using YiSha.Model.Param.SystemManage;
  11. using YiSha.Util;
  12. using YiSha.Util.Extension;
  13. using YiSha.Util.Model;
  14. namespace YiSha.Service.SystemManage
  15. {
  16. public partial class MenuAuthorizeService
  17. {
  18. private IRepositoryFactory _baseRepository;
  19. public MenuAuthorizeService(IRepositoryFactory baseRepository)
  20. {
  21. _baseRepository = baseRepository;
  22. }
  23. #region 获取数据
  24. public async Task<List<MenuAuthorizeEntity>> GetListPartial(MenuAuthorizeEntity param)
  25. {
  26. var expression = LinqExtensions.True<MenuAuthorizeEntity>();
  27. expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);
  28. if (param != null)
  29. {
  30. if (param.AuthorizeId.ParseToLong() > 0)
  31. {
  32. expression = expression.And(t => t.AuthorizeId == param.AuthorizeId);
  33. }
  34. if (param.AuthorizeType.ParseToInt() > 0)
  35. {
  36. expression = expression.And(t => t.AuthorizeType == param.AuthorizeType);
  37. }
  38. if (!param.AuthorizeIds.IsEmpty())
  39. {
  40. int[] authorizeIdArr = TextHelper.SplitToArray<int>(param.AuthorizeIds, ',');
  41. expression = expression.And(t => authorizeIdArr.Contains(t.AuthorizeId ?? 0));
  42. }
  43. }
  44. var list = await _baseRepository.BaseRepository(dbConnectType).FindList<MenuAuthorizeEntity>(expression);
  45. return list.ToList();
  46. }
  47. public async Task<MenuAuthorizeEntity> GetEntityPartial(int id)
  48. {
  49. return await _baseRepository.BaseRepository(dbConnectType).FindEntity<MenuAuthorizeEntity>(id);
  50. }
  51. #endregion
  52. #region 提交数据
  53. public async Task SaveFormPartial(MenuAuthorizeEntity entity)
  54. {
  55. if (entity.Id.IsNullOrZero())
  56. {
  57. await entity.Create();
  58. await _baseRepository.BaseRepository(dbConnectType).Insert(entity);
  59. }
  60. else
  61. {
  62. await _baseRepository.BaseRepository(dbConnectType).Update(entity);
  63. }
  64. }
  65. #endregion
  66. /// <summary>
  67. /// 列表条件过滤
  68. /// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释)
  69. /// </summary>
  70. /// <param name="param"></param>
  71. /// <returns></returns>
  72. private Expression<Func<MenuAuthorizeEntity, bool>> ListFilterPartial(MenuAuthorizeListParam param)
  73. {
  74. var expression = LinqExtensions.True<MenuAuthorizeEntity>();
  75. expression = expression.And(t => t.BaseIsDelete == (int)IsDeleteEnum.No);
  76. if (param != null)
  77. {
  78. }
  79. return expression;
  80. }
  81. }
  82. }