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<SysCountry>
|
{
|
|
/// <summary>
|
/// 获取字典信息
|
/// </summary>
|
/// <param name="dictCode"></param>
|
/// <returns></returns>
|
public List<SysDictItem> GetDictItems(string dictCode)
|
{
|
var res = Context.Queryable<SysDictItem>()
|
.Where(a => a.DictId == SqlFunc.Subqueryable<SysDict>().Where(b => b.DictCode == dictCode)
|
.Select(b => b.Id))
|
.OrderBy(a=>a.SortOrder)
|
.ToList();
|
return res;
|
}
|
|
/// <summary>
|
/// 获取ipc
|
/// </summary>
|
/// <param name="year">年份</param>
|
/// <param name="parentCode">父编码</param>
|
/// <returns></returns>
|
public List<SysIpcClass> GetIpcClass(int year, string parentCode = "")
|
{
|
var res = Context.Queryable<SysIpcClass>()
|
.Where(a => a.Year == year)
|
.Where(a => a.ParentCode == parentCode)
|
.OrderBy(a => a.Sort1).OrderBy(a => a.Sort2)
|
.ToList();
|
return res;
|
}
|
|
/// <summary>
|
/// 获取ipc
|
/// </summary>
|
/// <param name="param">条件</param>
|
/// <returns></returns>
|
public List<IviewTree> GetIpcClassTree(int year,string json)
|
{
|
var whereList = new List<IConditionalModel>();
|
try
|
{
|
if (!string.IsNullOrWhiteSpace(json))
|
whereList = Context.Utilities.JsonToConditionalModels(json);
|
}
|
catch (Exception e)
|
{
|
throw new Exception("条件设置错误,请检查");
|
}
|
var res = Context.Queryable<SysIpcClass>()
|
.Where(a => a.Year == year)
|
.Where(whereList)
|
.OrderBy(a => a.Sort1).OrderBy(a => a.Sort2)
|
.ToList();
|
|
var parents = GetParents<SysIpcClass>(res);
|
var treedata = new List<SysIpcClass>();
|
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;
|
|
}
|
|
/// <summary>
|
/// 递归获取当前parentCodes的祖先节点
|
/// </summary>
|
/// <typeparam name="T"></typeparam>
|
/// <param name="parentCodes"></param>
|
/// <returns></returns>
|
private List<T> GetParents<T>(List<T> items,List<string> exceptCodes = null) where T:SysDictBase
|
{
|
exceptCodes = exceptCodes ?? items.Select(a => a.Code).ToList();
|
var list = new List<T>();
|
if (items?.Any(a => !string.IsNullOrWhiteSpace(a.ParentCode)) != true)
|
return list;
|
var items1 = Context.Queryable<T>().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<T>(pc2, exceptCodes).ToList();
|
list.AddRange(items2);
|
}
|
|
return list;
|
}
|
|
/// <summary>
|
/// 获取cpc
|
/// </summary>
|
/// <param name="parentCode">父编码</param>
|
/// <returns></returns>
|
public List<SysCpcClass> GetCpcClass( string parentCode = "")
|
{
|
var res = Context.Queryable<SysCpcClass>()
|
.Where(a => a.ParentCode == parentCode)
|
.WhereIF(parentCode.IsNullOrEmpty(), a=>a.Code.Length ==1)
|
.OrderBy(a=>a.Sort1).OrderBy(a => a.Sort2)
|
.ToList();
|
return res;
|
}
|
|
/// <summary>
|
/// 获取ipc
|
/// </summary>
|
/// <param name="param">条件</param>
|
/// <returns></returns>
|
public List<IviewTree> GetCpcClassTree(string param)
|
{
|
var whereList = new List<IConditionalModel>();
|
try
|
{
|
if (!string.IsNullOrWhiteSpace(param))
|
whereList = Context.Utilities.JsonToConditionalModels(param);
|
}
|
catch (Exception e)
|
{
|
throw new Exception("条件设置错误,请检查");
|
}
|
var res = Context.Queryable<SysCpcClass>()
|
.Where(whereList)
|
.OrderBy(a => a.Sort1).OrderBy(a => a.Sort2)
|
.ToList();
|
|
var parents = GetParents<SysCpcClass>(res);
|
var treedata = new List<SysCpcClass>();
|
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;
|
|
}
|
/// <summary>
|
/// 获取产业分类
|
/// </summary>
|
/// <returns></returns>
|
public List<IviewTree> GetStraindustryTree(string param)
|
{
|
var whereList = new List<IConditionalModel>();
|
try
|
{
|
if(!string.IsNullOrWhiteSpace(param))
|
whereList = Context.Utilities.JsonToConditionalModels(param);
|
}
|
catch (Exception e)
|
{
|
throw new Exception("条件设置错误,请检查");
|
}
|
var res = Context.Queryable<SysStraindustry>().Where(whereList).OrderBy(a => a.Code).ToList();
|
|
var parents = GetParents<SysStraindustry>(res);
|
var treedata = new List<SysStraindustry>();
|
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;
|
}
|
|
/// <summary>
|
/// 获取国民经济行业分类
|
/// </summary>
|
/// <returns></returns>
|
public List<IviewTree> GetEcoindustryTree(string param)
|
{
|
|
var whereList = new List<IConditionalModel>();
|
try
|
{
|
if (!string.IsNullOrWhiteSpace(param))
|
whereList = Context.Utilities.JsonToConditionalModels(param);
|
}
|
catch (Exception e)
|
{
|
throw new Exception("条件设置错误,请检查");
|
}
|
var res = Context.Queryable<SysEcoindustry>().Where(whereList).OrderBy(a=>a.Code).ToList();
|
|
var parents = GetParents<SysEcoindustry>(res);
|
var treedata = new List<SysEcoindustry>();
|
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;
|
}
|
|
/// <summary>
|
/// 插入搜索记录
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
public bool AddPatentSearchLog(SysPatentSearchLog model)
|
{
|
var id = Context.Insertable<SysPatentSearchLog>(model).ExecuteReturnIdentity();
|
return true;
|
}
|
/// <summary>
|
/// 获取搜索记录分页
|
/// </summary>
|
/// <param name="userId"></param>
|
/// <param name="pageIndex"></param>
|
/// <param name="pageSize"></param>
|
/// <returns></returns>
|
public Page<SysPatentSearchLog> GetPatentSearchLog(string userId, int pageIndex, int pageSize,string searchType)
|
{
|
if (pageIndex <= 0)
|
pageIndex = 1;
|
if (pageSize <= 0)
|
pageSize = 20;
|
|
var page = Context.Queryable<SysPatentSearchLog>()
|
.Where(a => a.UserId == userId)
|
.WhereIF(!string.IsNullOrWhiteSpace(searchType),a=>a.SearchType == searchType)
|
.OrderBy(a => a.SearchTime, OrderByType.Desc)
|
.ToPage(pageIndex, pageSize);
|
return page;
|
}
|
/// <summary>
|
/// 洛迦诺分类
|
/// </summary>
|
/// <returns></returns>
|
public List<IviewTree> GetLoccn(string param)
|
{
|
var whereList = new List<IConditionalModel>();
|
try
|
{
|
if (!string.IsNullOrWhiteSpace(param))
|
whereList = Context.Utilities.JsonToConditionalModels(param);
|
}
|
catch (Exception e)
|
{
|
throw new Exception("条件设置错误,请检查");
|
}
|
var res = Context.Queryable<SysLoccn>().Where(whereList).OrderBy(a => a.Sort1).OrderBy(a=>a.Sort2).ToList();
|
|
var parents = GetParents<SysLoccn>(res);
|
var treedata = new List<SysLoccn>();
|
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;
|
}
|
|
}
|
}
|