MenuManagerModelsService.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using System.Data.Common;
  5. using System.Linq;
  6. using System.Linq.Expressions;
  7. using System.Threading.Tasks;
  8. using YiSha.Data;
  9. using YiSha.Data.Repository;
  10. using YiSha.Entity.ZxOrTkMenuManagerModels;
  11. using YiSha.Enum.ZX;
  12. using YiSha.Model.Param.TK;
  13. using YiSha.Model.Result.TK;
  14. using YiSha.Util.Extension;
  15. using YiSha.Web.Code;
  16. namespace YiSha.Service.TK
  17. {
  18. /// <summary>
  19. /// 创 建:cmzx
  20. /// 日 期:2021-04-21 09:30
  21. /// 描 述:图库菜单管理服务实现类(部分类)
  22. /// </summary>
  23. public partial class MenuManagerModelsService
  24. {
  25. private IRepositoryFactory _baseRepository;
  26. public MenuManagerModelsService(IRepositoryFactory baseRepository)
  27. {
  28. _baseRepository = baseRepository;
  29. }
  30. /// <summary>
  31. /// 获取资讯彩种类型菜单树
  32. /// </summary>
  33. /// <returns></returns>
  34. public async Task<List<MenuManagerModelsTreeListModel>> GetZxMenuManagerTreeList(MenuManagerModelsListParam param)
  35. {
  36. var expression = ListFilterPartial(param);
  37. var s = await _baseRepository.BaseRepository(dbConnectType).FindList<MenuManagerModelsCommonEntity>(expression);
  38. var zxMenuManagerList = await _baseRepository.BaseRepository(dbConnectType).FindList<MenuManagerModelsCommonEntity>(expression);
  39. var result = zxMenuManagerList.ToList().ConvertAll<MenuManagerModelsTreeListModel>(item =>
  40. {
  41. return new MenuManagerModelsTreeListModel
  42. {
  43. Id = item.Id,
  44. ParentId = item.parentId,
  45. MenuName = item.menuName,
  46. ParentName = item.parentName,
  47. SortNo = item.sortNo,
  48. Type = item.type
  49. };
  50. });
  51. return result;
  52. }
  53. /// <summary>
  54. /// 保存数据(由于之前数据库设计不规范,无法实现在新增、修改时保存正确的操作用户信息,每张表的创建时间和创建人id、创建人姓名都不一样,且这些字段是必填项)
  55. /// </summary>
  56. /// <param name="entity">实体参数</param>
  57. /// <returns></returns>
  58. public async Task<int> SaveFormPartial(MenuManagerModelsCommonEntity entity)
  59. {
  60. OperatorInfo user = await Operator.Instance.Current(entity.Token);
  61. if (entity.Id.IsNullOrZero())
  62. {
  63. entity.createTime = DateTime.Now;
  64. entity.createUserId = user?.UserId;
  65. entity.createUserName = user?.UserName;
  66. return await _baseRepository.BaseRepository(dbConnectType).Insert(entity);
  67. }
  68. else
  69. {
  70. return await _baseRepository.BaseRepository(dbConnectType).Update(entity);
  71. }
  72. }
  73. /// <summary>
  74. /// 删除数据(由于之前数据库设计不规范,无法实现统一的删除功能,这里需要手动更改)
  75. /// </summary>
  76. /// <param name="ids">主键集合</param>
  77. /// <returns></returns>
  78. public async Task<int> DeleteFormByIdPartial(string ids)
  79. {
  80. ids = $"{string.Join(",", ids.Split(","))}";
  81. var where = $" id in ({ids}) ";
  82. var setField = " isdelete = @IsDelete ";
  83. var parameters = new List<DbParameter>();
  84. parameters.Add(DbParameterExtension.CreateDbParameter("@IsDelete", TkIsDeleteEnum.已删除.ParseToInt(), dbConnectType));
  85. string tableName = typeof(MenuManagerModelsCommonEntity).GetAttributeValue((TableAttribute ta) => ta.Name);
  86. string updateSql = $"update {tableName} set {setField} where {where}";
  87. return await _baseRepository.BaseRepository(dbConnectType).ExecuteBySql(updateSql, DbParameterExtension.ToDbParameter(parameters.ToArray()));
  88. }
  89. #region 私有方法
  90. /// <summary>
  91. /// 列表条件过滤
  92. /// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释)
  93. /// </summary>
  94. /// <param name="param"></param>
  95. /// <returns></returns>
  96. private Expression<Func<MenuManagerModelsCommonEntity, bool>> ListFilterPartial(MenuManagerModelsListParam param)
  97. {
  98. var expression = LinqExtensions.True<MenuManagerModelsCommonEntity>();
  99. expression = expression.And(d => d.isDelete == false);
  100. if (param != null)
  101. {
  102. if (param.Type != null)
  103. expression = expression.And(d => d.type == param.Type.ParseToInt());
  104. if (!string.IsNullOrEmpty(param.MenuName))
  105. expression = expression.And(d => d.menuName.Contains(param.MenuName));
  106. }
  107. return expression;
  108. }
  109. #endregion
  110. }
  111. }