wx
2022-12-30 0c188ee217146c88ca96d99b5795d1883b733840
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System.Collections.Generic;
using System.Linq;
using CommonHelper;
using CommonHelper.Format;
using GasolineBlend.Entity;
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>
        /// 获取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>
        /// 获取产业分类
        /// </summary>
        /// <returns></returns>
        public List<IviewTree> GetStraindustryTree()
        {
            var data = Context.Queryable<SysStraindustry>().OrderBy(a => a.Code).ToList();
            var tree = TreeHelper.GenerateIviewTree(data, a => a.Code,
                a => a.Code.Contains(".") ? a.Code.Substring(0, a.Code.IndexOf(".")) : null,
                a => a.Code,
                a=>a.Name
            ).ToList();
            return tree;
        }
 
        /// <summary>
        /// 获取国民经济行业分类
        /// </summary>
        /// <returns></returns>
        public List<IviewTree> GetEcoindustryTree()
        {
            var data = Context.Queryable<SysEcoindustry>().OrderBy(a=>a.Code).ToList();
            var tree = TreeHelper.GenerateIviewTree(data, a => a.Code,
                a =>a.Code.Length>3?a.Code.Substring(0,a.Code.Length-1):(a.Code.Length==3?a.Code.Substring(0,1): null),
                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()
        {
            var data = Context.Queryable<SysLoccn>().OrderBy(a => a.Sort1).OrderBy(a=>a.Sort2).ToList();
            var tree = TreeHelper.GenerateIviewTree(data, a => a.Code,
                a => a.ParentCode,
                a => a.Code,
                a => a.Desc).ToList();
            return tree;
        }
 
    }
}