123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Data.Common;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Threading.Tasks;
- using YiSha.Data;
- using YiSha.Data.Repository;
- using YiSha.Entity.ZxOrTkMenuManagerModels;
- using YiSha.Enum.ZX;
- using YiSha.Model.Param.TK;
- using YiSha.Model.Result.TK;
- using YiSha.Util.Extension;
- using YiSha.Web.Code;
- namespace YiSha.Service.TK
- {
- /// <summary>
- /// 创 建:cmzx
- /// 日 期:2021-04-21 09:30
- /// 描 述:图库菜单管理服务实现类(部分类)
- /// </summary>
- public partial class MenuManagerModelsService
- {
- private IRepositoryFactory _baseRepository;
- public MenuManagerModelsService(IRepositoryFactory baseRepository)
- {
- _baseRepository = baseRepository;
- }
- /// <summary>
- /// 获取资讯彩种类型菜单树
- /// </summary>
- /// <returns></returns>
- public async Task<List<MenuManagerModelsTreeListModel>> GetZxMenuManagerTreeList(MenuManagerModelsListParam param)
- {
- var expression = ListFilterPartial(param);
- var s = await _baseRepository.BaseRepository(dbConnectType).FindList<MenuManagerModelsCommonEntity>(expression);
- var zxMenuManagerList = await _baseRepository.BaseRepository(dbConnectType).FindList<MenuManagerModelsCommonEntity>(expression);
- var result = zxMenuManagerList.ToList().ConvertAll<MenuManagerModelsTreeListModel>(item =>
- {
- return new MenuManagerModelsTreeListModel
- {
- Id = item.Id,
- ParentId = item.parentId,
- MenuName = item.menuName,
- ParentName = item.parentName,
- SortNo = item.sortNo,
- Type = item.type
- };
- });
- return result;
- }
- /// <summary>
- /// 保存数据(由于之前数据库设计不规范,无法实现在新增、修改时保存正确的操作用户信息,每张表的创建时间和创建人id、创建人姓名都不一样,且这些字段是必填项)
- /// </summary>
- /// <param name="entity">实体参数</param>
- /// <returns></returns>
- public async Task<int> SaveFormPartial(MenuManagerModelsCommonEntity entity)
- {
- OperatorInfo user = await Operator.Instance.Current(entity.Token);
- if (entity.Id.IsNullOrZero())
- {
- entity.createTime = DateTime.Now;
- entity.createUserId = user?.UserId;
- entity.createUserName = user?.UserName;
- return await _baseRepository.BaseRepository(dbConnectType).Insert(entity);
- }
- else
- {
- return await _baseRepository.BaseRepository(dbConnectType).Update(entity);
- }
- }
- /// <summary>
- /// 删除数据(由于之前数据库设计不规范,无法实现统一的删除功能,这里需要手动更改)
- /// </summary>
- /// <param name="ids">主键集合</param>
- /// <returns></returns>
- public async Task<int> DeleteFormByIdPartial(string ids)
- {
- ids = $"{string.Join(",", ids.Split(","))}";
- var where = $" id in ({ids}) ";
- var setField = " isdelete = @IsDelete ";
- var parameters = new List<DbParameter>();
- parameters.Add(DbParameterExtension.CreateDbParameter("@IsDelete", TkIsDeleteEnum.已删除.ParseToInt(), dbConnectType));
- string tableName = typeof(MenuManagerModelsCommonEntity).GetAttributeValue((TableAttribute ta) => ta.Name);
- string updateSql = $"update {tableName} set {setField} where {where}";
- return await _baseRepository.BaseRepository(dbConnectType).ExecuteBySql(updateSql, DbParameterExtension.ToDbParameter(parameters.ToArray()));
- }
- #region 私有方法
- /// <summary>
- /// 列表条件过滤
- /// 建议该方法放在Partial部分类中,因为代码生成时当前类会被覆盖(该方法在生成时将会被注释)
- /// </summary>
- /// <param name="param"></param>
- /// <returns></returns>
- private Expression<Func<MenuManagerModelsCommonEntity, bool>> ListFilterPartial(MenuManagerModelsListParam param)
- {
- var expression = LinqExtensions.True<MenuManagerModelsCommonEntity>();
- expression = expression.And(d => d.isDelete == false);
- if (param != null)
- {
- if (param.Type != null)
- expression = expression.And(d => d.type == param.Type.ParseToInt());
- if (!string.IsNullOrEmpty(param.MenuName))
- expression = expression.And(d => d.menuName.Contains(param.MenuName));
- }
- return expression;
- }
- #endregion
- }
- }
|