123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Model.ViewModel;
- using Ropin.Inspection.Model.ViewModel.SYS;
- using Ropin.Inspection.Repository.SYS.Interface;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ropin.Inspection.Repository.SYS
- {
- public class TsysPrivRepository: RepositoryBase<TSYS_Priv, string>, ITsysPrivRepository
- {
- public TsysPrivRepository(InspectionDbContext dbContext) : base(dbContext)
- {
- }
-
- public TSYS_Priv GetPrivEntity(string code)
- {
- TSYS_Priv priv = new TSYS_Priv();
- priv= DbContext.Set<TSYS_Priv>().Where(i => i.C_Code==code).FirstOrDefault();
- return priv;
- }
- public List<TsysPrivTreeModel> GetAllPrivList(string ParentCode,string name,string status)
- {
- string sql = string.Empty;
- MySqlConnector.MySqlParameter[] parameters = new[] {
- new MySqlConnector.MySqlParameter("ParentCode", ParentCode) ,
- new MySqlConnector.MySqlParameter("name", "%" +name+"%"),
- new MySqlConnector.MySqlParameter("status", status)
- };
- sql = @" select P.*,M.C_Name as C_ModuleName,T.C_Name as C_TypeName from TSYS_Priv P
- LEFT JOIN TBDM_CodeDetail M on (P.C_Module=M.C_Code)
- LEFT JOIN TBDM_CodeDetail T on (P.C_Type=T.C_Code) WHERE 1=1";
- if (!string.IsNullOrEmpty(ParentCode))
- {
- if (ParentCode == "null")
- {
- sql += " and (P.C_ParentCode is null or P.C_ParentCode='') ";
- }
- else
- {
- sql += " and P.C_ParentCode=@ParentCode ";
- }
- }
- if (!string.IsNullOrEmpty(name))
- {
- sql += " and P.C_Name like @name ";
- }
- if (!string.IsNullOrEmpty(status))
- {
- sql += " and P.C_Status =@status ";
- }
- List<TsysPrivTreeModel> result = EntityFrameworkCoreExtensions.GetList<TsysPrivTreeModel>(DbContext.Database, sql, parameters).ToList();
- return result;
- }
- public async Task<List<TsysPrivTreeModel>> GetPrivTree(TsysPrivSearch model)
- {
- List< TsysPrivTreeModel > treeList = new List< TsysPrivTreeModel >();
- if (model==null)
- {
- model = new TsysPrivSearch();
- }
- //treeModels = GetAllPrivList("null","",model.C_Status);
- List<TsysPrivTreeModel> treeModels = GetAllPrivList("", "", model.C_Status);
- if (treeModels.First()==null)
- {
- treeModels = null;
- }
- if (treeModels!=null&& treeModels.Count>0)
- {
- foreach (var item in treeModels.Where(m => m.C_ParentCode == null).OrderBy(m => m.I_Sort))
- {
- //获得子级
- var children = GetChildLevel(treeModels, new List<TsysPrivTreeModel>(), item.C_Code);
- if (children != null && children.Count > 0)
- {
- item.Open = true;
- item.Children = children;
- }
- else
- {
- item.Open = false;
- item.Children = null;
- }
- treeList.Add(item);
- }
- //treeModels = GetChildren(model, treeModels);
- }
- if (treeList.Count>0)
- {
- return await Task.Run(() => treeList);
- }
- else
- {
- return await Task.Run(() => treeModels);
- }
- }
- List<TsysPrivTreeModel> GetChildLevel(List<TsysPrivTreeModel> model, List<TsysPrivTreeModel> list,string code)
- {
- //var data = model.Where(m => m.C_ParentCode.Equals(code)).OrderBy(m => m.I_Sort).ToList();
- foreach (var row in model.Where(m => m.C_ParentCode == code).OrderBy(m => m.I_Sort))
- {
- var res = GetChildLevel(model, new List<TsysPrivTreeModel>(), row.C_Code);
- if (res != null && res.Count > 0)
- {
- row.Open = true;
- row.Children = res;
- }
- else
- {
- row.Open = false;
- row.Children = null;
- }
- list.Add(row);
- }
- return list;
- }
- public List<TsysPrivTreeModel> GetChildren(TsysPrivSearch model, List<TsysPrivTreeModel> list)
- {
- foreach (TsysPrivTreeModel item in list)
- {
- List<TsysPrivTreeModel> ChildrenList = GetAllPrivList(item.C_Code,"",model.C_Status);
- //item.Children = ChildrenList;
- if (ChildrenList != null&& ChildrenList.Count>0&& ChildrenList.FirstOrDefault()!=null)
- {
- item.Children = ChildrenList;
- GetChildren(model, ChildrenList);
- }
- }
- return list;
- }
- }
- }
|