using System; using System.Collections.Generic; using System.Linq; using CommonHelper; using CommonHelper.Format; using GasolineBlend.Entity; using GasolineBlend.Entity.ViewModel; using Pissa.Service.Extend; using SqlSugar; namespace Pissa.Service.DbService { public class SysService:Repository { /// /// 获取字典信息 /// /// /// public List GetDictItems(string dictCode) { var res = Context.Queryable() .Where(a => a.DictId == SqlFunc.Subqueryable().Where(b => b.DictCode == dictCode) .Select(b => b.Id)) .OrderBy(a=>a.SortOrder) .ToList(); return res; } /// /// 获取ipc /// /// 年份 /// 父编码 /// public List GetIpcClass(int year, string parentCode = "") { var res = Context.Queryable() .Where(a => a.Year == year) .Where(a => a.ParentCode == parentCode) .OrderBy(a => a.Sort1).OrderBy(a => a.Sort2) .ToList(); return res; } /// /// 获取ipc /// /// 条件 /// public List GetIpcClassTree(int year,string json) { var whereList = new List(); try { if (!string.IsNullOrWhiteSpace(json)) whereList = Context.Utilities.JsonToConditionalModels(json); } catch (Exception e) { throw new Exception("条件设置错误,请检查"); } var res = Context.Queryable() .Where(a => a.Year == year) .Where(whereList) .OrderBy(a => a.Sort1).OrderBy(a => a.Sort2) .ToList(); var parents = GetParents(res); var treedata = new List(); foreach (var sysIpcClass in res.Concat(parents)) { if(treedata.All(a=>a.Code!=sysIpcClass.Code)) treedata.Add(sysIpcClass); } var tree = TreeHelper.GenerateIviewTree(treedata, a => a.Code, a => a.ParentCode, a => a.Code, a => a.Desc).ToList(); return tree; } /// /// 递归获取当前parentCodes的祖先节点 /// /// /// /// private List GetParents(List items,List exceptCodes = null) where T:SysDictBase { exceptCodes = exceptCodes ?? items.Select(a => a.Code).ToList(); var list = new List(); if (items?.Any(a => !string.IsNullOrWhiteSpace(a.ParentCode)) != true) return list; var items1 = Context.Queryable().Where(a => items.Select(p=>p.ParentCode).Distinct().Contains(a.Code) && !exceptCodes.Contains(a.Code)).ToList(); list.AddRange(items1); var pc2 = items1.Where(a => !string.IsNullOrWhiteSpace(a.ParentCode)).ToList(); if (pc2.Count() > 0) { var items2 = GetParents(pc2, exceptCodes).ToList(); list.AddRange(items2); } return list; } /// /// 获取cpc /// /// 父编码 /// public List GetCpcClass( string parentCode = "") { var res = Context.Queryable() .Where(a => a.ParentCode == parentCode) .WhereIF(parentCode.IsNullOrEmpty(), a=>a.Code.Length ==1) .OrderBy(a=>a.Sort1).OrderBy(a => a.Sort2) .ToList(); return res; } /// /// 获取ipc /// /// 条件 /// public List GetCpcClassTree(string param) { var whereList = new List(); try { if (!string.IsNullOrWhiteSpace(param)) whereList = Context.Utilities.JsonToConditionalModels(param); } catch (Exception e) { throw new Exception("条件设置错误,请检查"); } var res = Context.Queryable() .Where(whereList) .OrderBy(a => a.Sort1).OrderBy(a => a.Sort2) .ToList(); var parents = GetParents(res); var treedata = new List(); foreach (var item in res.Concat(parents)) { if (treedata.All(a => a.Code != item.Code)) treedata.Add(item); } var tree = TreeHelper.GenerateIviewTree(treedata, a => a.Code, a => a.ParentCode, a => a.Code, a => a.Desc).ToList(); return tree; } /// /// 获取产业分类 /// /// public List GetStraindustryTree(string param) { var whereList = new List(); try { if(!string.IsNullOrWhiteSpace(param)) whereList = Context.Utilities.JsonToConditionalModels(param); } catch (Exception e) { throw new Exception("条件设置错误,请检查"); } var res = Context.Queryable().Where(whereList).OrderBy(a => a.Code).ToList(); var parents = GetParents(res); var treedata = new List(); foreach (var item in res.Concat(parents)) { if (treedata.All(a => a.Code != item.Code)) treedata.Add(item); } var tree = TreeHelper.GenerateIviewTree(treedata, a => a.Code, a => a.ParentCode, a => a.Code, a => a.Name).ToList(); return tree; } /// /// 获取国民经济行业分类 /// /// public List GetEcoindustryTree(string param) { var whereList = new List(); try { if (!string.IsNullOrWhiteSpace(param)) whereList = Context.Utilities.JsonToConditionalModels(param); } catch (Exception e) { throw new Exception("条件设置错误,请检查"); } var res = Context.Queryable().Where(whereList).OrderBy(a=>a.Code).ToList(); var parents = GetParents(res); var treedata = new List(); foreach (var item in res.Concat(parents)) { if (treedata.All(a => a.Code != item.Code)) treedata.Add(item); } var tree = TreeHelper.GenerateIviewTree(treedata, a => a.Code, a => a.ParentCode, a => a.Code, a => a.Name).ToList(); return tree; } /// /// 插入搜索记录 /// /// /// public bool AddPatentSearchLog(SysPatentSearchLog model) { var id = Context.Insertable(model).ExecuteReturnIdentity(); return true; } /// /// 获取搜索记录分页 /// /// /// /// /// public Page GetPatentSearchLog(string userId, int pageIndex, int pageSize,string searchType) { if (pageIndex <= 0) pageIndex = 1; if (pageSize <= 0) pageSize = 20; var page = Context.Queryable() .Where(a => a.UserId == userId) .WhereIF(!string.IsNullOrWhiteSpace(searchType),a=>a.SearchType == searchType) .OrderBy(a => a.SearchTime, OrderByType.Desc) .ToPage(pageIndex, pageSize); return page; } /// /// 洛迦诺分类 /// /// public List GetLoccn(string param) { var whereList = new List(); try { if (!string.IsNullOrWhiteSpace(param)) whereList = Context.Utilities.JsonToConditionalModels(param); } catch (Exception e) { throw new Exception("条件设置错误,请检查"); } var res = Context.Queryable().Where(whereList).OrderBy(a => a.Sort1).OrderBy(a=>a.Sort2).ToList(); var parents = GetParents(res); var treedata = new List(); foreach (var item in res.Concat(parents)) { if (treedata.All(a => a.Code != item.Code)) treedata.Add(item); } var tree = TreeHelper.GenerateIviewTree(treedata, a => a.Code, a => a.ParentCode, a => a.Code, a => a.Desc).ToList(); return tree; } } }