唐召明
authored
10 months ago
1
using Hh.Mes.Common.log ;
2
3
4
5
6
using Hh.Mes.POJO.Response ;
using Hh.Mes.Service.Repository ;
using System.Data ;
using Hh.Mes.Common ;
using System.Linq ;
唐召明
authored
10 months ago
7
8
9
10
11
using Hh.Mes.POJO.Entity ;
using Hh.Mes.Pojo.System ;
using SqlSugar ;
using System ;
using System.Linq.Expressions ;
唐召明
authored
6 months ago
12
using Hh.Mes.POJO.WebEntity.configure ;
13
14
15
16
17
18
namespace Hh.Mes.Service.Configure
{
/// < summary >
/// 公司设置
/// </ summary >
19
public class SysCompanyService : RepositorySqlSugar < dynamic >
20
{
唐召明
authored
10 months ago
21
22
23
24
25
26
27
28
29
30
/// < summary >
/// 主页面错误信息提示
/// </ summary >
public dynamic LogTips ()
{
var response = new Response ();
return ExceptionsHelp . Instance . ExecuteT (() =>
{
# region cpu ,硬盘,内存
唐召明
authored
7 months ago
31
32
var tempServerLog = string . Empty ;// "cpu 使用率:80%,内存使用率:80%,C盘使用率:80%,"
唐召明
authored
7 months ago
33
if ( Environment . OSVersion . Platform == PlatformID . Win32NT )
34
{
唐召明
authored
7 months ago
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var cpu = ComputerHelp . GetCpuUsage ();
if ( int . TryParse ( cpu . Replace ( "%" , "" ), out int cpuUsage ) && cpuUsage >= 80 )
{
tempServerLog += $ "cpu 使用率:{cpu};" ;
}
var memory = ComputerHelp . GetMemery ();
if ( int . TryParse ( memory . Item4 . Replace ( "%" , "" ), out int memoryUsage ) && memoryUsage >= 80 )
{
tempServerLog += $ "内存 使用率:{memory.Item4};" ;
}
var disk = ComputerHelp . GetDriveInfos ();
var driveInfos = disk . Where ( x => (( x . TotalSize - x . TotalFreeSpace ) * 100 / x . TotalSize ) >= 80 ). Select ( x => new
{
dirName = x . Name ,
usage = (( x . TotalSize - x . TotalFreeSpace ) * 100 / x . TotalSize ). ToString ( "N1" ) + "%"
}). ToList ();
foreach ( var item in driveInfos )
{
tempServerLog += $ "{item.dirName}盘使用率:{item.usage};" ;
}
55
}
唐召明
authored
7 months ago
56
57
58
# endregion
赖素文
authored
about a year ago
59
# region 日志
唐召明
authored
10 months ago
60
赖素文
authored
about a year ago
61
62
var log = @" -- 接口
select count ( 1 ) as total from sys_interface_log t ( nolock )
63
64
where t . flag is null
and t . response NOT LIKE ' % 200 % '
赖素文
authored
about a year ago
65
-- 定时器
66
67
select count ( 1 ) as total from sys_job_log t ( nolock )
where t . flag is null
赖素文
authored
about a year ago
68
69
70
-- PDA
select count ( 1 ) as total from sys_interface_log t ( nolock )
where t . flag is null and [ system ] = ' app Android '
71
and t . response NOT LIKE ' % 200 % '
赖素文
authored
about a year ago
72
-- 客户端
赖素文
authored
about a year ago
73
74
75
76
77
78
select * from (
select clientName ,
seconds = ISNULL ( DATEDIFF ( second , LastSeenDate , GETDATE ()), 130 )
from [ dbo ].[ daq_client_status ] with ( nolock )
) t
where t . seconds >= 120
赖素文
authored
about a year ago
79
80
81
82
83
84
-- 数据库
DECLARE @DriveInfo TABLE ( drive VARCHAR ( 10 ), freeSpaceMB INT );
INSERT INTO @DriveInfo EXEC xp_fixeddrives ;
SELECT drive , freeSpaceMB
FROM @DriveInfo
WHERE FreeSpaceMB < 30480 " ;
85
86
87
88
89
90
91
92
var ds = Context . Ado . GetDataSetAll ( log );
var interLog = ds . Tables [ 0 ]. Rows [ 0 ][ "total" ]. ToString ();
if ( interLog == "0" ) interLog = "" ;
var jobLog = ds . Tables [ 1 ]. Rows [ 0 ][ "total" ]. ToString ();
if ( jobLog == "0" ) jobLog = "" ;
var pdaLog = ds . Tables [ 2 ]. Rows [ 0 ][ "total" ]. ToString ();
if ( pdaLog == "0" ) pdaLog = "" ;
唐召明
authored
10 months ago
93
94
string currentUser = sysWebUser . Account ;
唐召明
authored
6 months ago
95
var temp = Context . Queryable < daq_client_config >(). Where ( LinqWhere ( currentUser )). Select ( x => new
唐召明
authored
10 months ago
96
{
唐召明
authored
6 months ago
97
x . name ,
唐召明
authored
10 months ago
98
99
100
101
x . lastSeenDate ,
}). ToList ();
// var clientOnlineInfo = ds . Tables [ 3 ];
赖素文
authored
about a year ago
102
赖素文
authored
about a year ago
103
104
# endregion
105
106
107
108
109
110
111
112
response . Result = new
{
interLog ,
jobLog ,
pdaLog ,
唐召明
authored
10 months ago
113
114
clientOnlineInfo = temp . Select ( x => new
{
唐召明
authored
6 months ago
115
clientName = x . name ,
唐召明
authored
10 months ago
116
117
seconds = ( DateTime . Now - x . lastSeenDate ). TotalSeconds ,
}). ToList (),
118
赖素文
authored
about a year ago
119
120
serverLog = string . IsNullOrWhiteSpace ( tempServerLog ) ? "" : tempServerLog ,
唐召明
authored
10 months ago
121
sqlServerLog = ds . Tables [ 4 ]. Rows . Count > 0 ? ds . Tables [ 4 ] : null
122
123
124
125
126
};
return response ;
});
}
唐召明
authored
6 months ago
127
public Expression < Func < daq_client_config , bool >> LinqWhere ( string user )
唐召明
authored
10 months ago
128
{
唐召明
authored
6 months ago
129
var exp = Expressionable . Create < daq_client_config >();
唐召明
authored
10 months ago
130
exp . And ( x => x . lastSeenDate <= DateTime . Now . AddMinutes (- 5 ));
赖素文
authored
5 months ago
131
exp . And ( x => SystemVariable . SoftTypes . Contains ( x . type ));
唐召明
authored
10 months ago
132
133
134
135
136
137
138
139
140
if ( user != SystemVariable . DefaultCreated )
{
var projectKeys = GetProjectInfoKeys ( user );
var projectCodes = Context . Queryable < base_project >(). Where ( x => projectKeys . Contains ( x . keys )). Select ( x => x . projectCode ). ToList ();
exp . And ( x => projectCodes . Contains ( x . projectCode ));
}
return exp . ToExpression ();
}
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
public dynamic UpdateLogTips ( string flag )
{
var response = new Response ();
return ExceptionsHelp . Instance . ExecuteT (() =>
{
if ( flag == "inter" )
{
string sql = "update sys_interface_log set flag=1 where flag is null" ;
var result = base . Context . Ado . ExecuteCommand ( sql );
return result > 0 ? response . ResponseSuccess () : response . ResponseError ();
}
else if ( flag == "job" )
{
string sql = "update sys_job_log set flag=1 where flag is null" ;
var result = base . Context . Ado . ExecuteCommand ( sql );
return result > 0 ? response . ResponseSuccess () : response . ResponseError ();
}
else if ( flag == "upstream" )
{
string sql = "update sys_interface_log set flag=1 where flag is null and [system] ='api' and [type] like 'API%'" ;
var result = base . Context . Ado . ExecuteCommand ( sql );
return result > 0 ? response . ResponseSuccess () : response . ResponseError ();
}
else if ( flag == "pda" )
{
string sql = "update sys_interface_log set flag=1 where flag is null and [system] ='app Android'" ;
var result = base . Context . Ado . ExecuteCommand ( sql );
return result > 0 ? response . ResponseSuccess () : response . ResponseError ();
}
return response ;
});
}
}
}