赖素文
authored
|
1
2
3
4
5
6
7
8
9
10
|
using Hh.Mes.Common.log;
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Linq;
using System.Linq.Expressions;
using Hh.Mes.Pojo.System;
|
唐召明
authored
|
11
|
using Hh.Mes.Service.SystemAuth;
|
唐召明
authored
|
12
|
using System.Collections.Generic;
|
唐召明
authored
|
13
|
using Hh.Mes.POJO.WebEntity.configure;
|
赖素文
authored
|
14
15
16
17
18
19
|
namespace Hh.Mes.Service.Configure
{
/// <summary>
/// 客户端状态
/// </summary>
|
唐召明
authored
|
20
|
public class DaqClientStatusService : RepositorySqlSugar<daq_client_config>
|
赖素文
authored
|
21
|
{
|
唐召明
authored
|
22
23
|
public DaqClientStatusService(IAuth auth) : base(auth) { }
|
唐召明
authored
|
24
|
public dynamic Load(PageReq pageReq, daq_client_config entity)
|
赖素文
authored
|
25
26
27
28
29
30
|
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var result = new Response();
var expression = LinqWhere(entity);
//先组合查询表达式(多表查询查看IOT 设备列表案例)
|
唐召明
authored
|
31
|
var query = Context.Queryable<daq_client_config, base_project>((c, p) => new JoinQueryInfos(JoinType.Left, c.projectCode == p.projectCode)).Where(expression).OrderBy((c, p) => c.projectCode);
|
赖素文
authored
|
32
33
|
//Exel false 分页
if (!entity.Exel)
|
唐召明
authored
|
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
|
{
int total = 0;
result.Result = query.Select((c, p) => new
{
c.id,
c.name,
c.type,
c.projectCode,
p.projectName,
c.lastSeenDate,
c.factoryCode,
factoryName = SqlFunc.Subqueryable<base_factory>().Where(s => s.projectKeys == p.keys && s.factoryCode == c.factoryCode).Select(s => s.factoryName),
c.remark,
}).ToOffsetPage(pageReq.page, pageReq.limit, ref total);
result.Count = total;
}
else
{
result.Result = query.ToList();
result.Count = result.Result.Count;
}
return result;
}, catchRetrunValue: "list");
}
public dynamic LoadStatus(PageReq pageReq, daq_client_config entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var result = new Response();
|
唐召明
authored
|
64
|
var expression = StatusLinqWhere(entity);
|
唐召明
authored
|
65
66
67
68
|
//先组合查询表达式(多表查询查看IOT 设备列表案例)
var query = Context.Queryable<daq_client_config, base_project>((c, p) => new JoinQueryInfos(JoinType.Left, c.projectCode == p.projectCode)).Where(expression).OrderBy((c, p) => c.lastSeenDate);
//Exel false 分页
if (!entity.Exel)
|
赖素文
authored
|
69
70
|
{
int total = 0;
|
唐召明
authored
|
71
72
73
|
result.Result = query.Select((c, p) => new
{
c.id,
|
唐召明
authored
|
74
75
|
c.name,
c.type,
|
唐召明
authored
|
76
77
78
|
c.projectCode,
p.projectName,
c.lastSeenDate,
|
唐召明
authored
|
79
80
|
c.factoryCode,
factoryName = SqlFunc.Subqueryable<base_factory>().Where(s => s.projectKeys == p.keys && s.factoryCode == c.factoryCode).Select(s => s.factoryName),
|
唐召明
authored
|
81
82
|
c.remark,
}).ToOffsetPage(pageReq.page, pageReq.limit, ref total);
|
赖素文
authored
|
83
84
85
86
|
result.Count = total;
}
else
{
|
唐召明
authored
|
87
|
result.Result = query.ToList();
|
赖素文
authored
|
88
89
90
91
92
|
result.Count = result.Result.Count;
}
return result;
}, catchRetrunValue: "list");
}
|
唐召明
authored
|
93
|
|
唐召明
authored
|
94
|
public dynamic Ins(daq_client_config entity)
|
赖素文
authored
|
95
96
97
98
|
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
|
唐召明
authored
|
99
|
if (string.IsNullOrWhiteSpace(entity.name))
|
唐召明
authored
|
100
101
102
103
104
105
106
107
|
{
return response.ResponseError($"客户端名称不能为空!");
}
if (string.IsNullOrWhiteSpace(entity.projectCode))
{
return response.ResponseError($"项目信息不能为空!");
}
|
唐召明
authored
|
108
109
|
entity.created = DateTime.Now;
entity.createdBy = sysWebUser?.Account;
|
唐召明
authored
|
110
111
|
Context.Insertable(entity).ExecuteCommand();
return response.ResponseSuccess();
|
赖素文
authored
|
112
113
|
});
}
|
唐召明
authored
|
114
|
|
唐召明
authored
|
115
|
public dynamic Upd(daq_client_config entity)
|
赖素文
authored
|
116
117
118
119
|
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
|
唐召明
authored
|
120
|
Context.Updateable<daq_client_config>().SetColumns(x => new daq_client_config
|
唐召明
authored
|
121
|
{
|
唐召明
authored
|
122
123
|
name = entity.name,
type = entity.type,
|
唐召明
authored
|
124
|
projectCode = entity.projectCode,
|
唐召明
authored
|
125
|
factoryCode = entity.factoryCode,
|
唐召明
authored
|
126
127
|
remark = entity.remark
}).Where(x => x.id == entity.id).ExecuteCommand();
|
唐召明
authored
|
128
|
return response.ResponseSuccess();
|
赖素文
authored
|
129
130
|
});
}
|
唐召明
authored
|
131
|
|
唐召明
authored
|
132
|
public dynamic DelByIds(Guid[] ids)
|
赖素文
authored
|
133
134
135
136
|
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var response = new Response();
|
唐召明
authored
|
137
|
Context.Deleteable<daq_client_config>(t => ids.Contains(t.id)).ExecuteCommand();
|
赖素文
authored
|
138
139
140
|
return response;
});
}
|
唐召明
authored
|
141
|
|
唐召明
authored
|
142
|
public Response ExportData(daq_client_config entity)
|
赖素文
authored
|
143
144
145
|
{
return Load(null, entity);
}
|
唐召明
authored
|
146
|
|
唐召明
authored
|
147
|
public Expression<Func<daq_client_config, base_project, bool>> LinqWhere(daq_client_config client)
|
赖素文
authored
|
148
|
{
|
唐召明
authored
|
149
|
var exp = Expressionable.Create<daq_client_config, base_project>();
|
唐召明
authored
|
150
151
|
//数据过滤条件
//if (!string.IsNullOrWhiteSpace(model.XXX)) exp.And(x => x.XXX.Contains(model.XXX));
|
唐召明
authored
|
152
|
if (!string.IsNullOrWhiteSpace(client.name))
|
赖素文
authored
|
153
|
{
|
唐召明
authored
|
154
|
exp.And((c, p) => c.name.Contains(client.name));
|
唐召明
authored
|
155
156
157
158
|
}
if (!string.IsNullOrWhiteSpace(client.remark))
{
exp.And((c, p) => c.remark.Contains(client.remark));
|
赖素文
authored
|
159
|
}
|
唐召明
authored
|
160
|
if (!string.IsNullOrWhiteSpace(client.projectCode))
|
赖素文
authored
|
161
|
{
|
唐召明
authored
|
162
|
exp.And((c, p) => c.projectCode == client.projectCode);
|
赖素文
authored
|
163
|
}
|
唐召明
authored
|
164
165
166
167
168
169
170
171
|
string user = sysWebUser.Account;
if (user != SystemVariable.DefaultCreated)
{
var projectRoleKeys = GetProjectRoleKeys(user);
exp.And((c, p) => SqlFunc.Subqueryable<sys_role_projects_rel>().Where(x => projectRoleKeys.Contains(x.project_roles_key) && x.project_key == p.keys).Any());
}
|
唐召明
authored
|
172
|
return exp.ToExpression();//拼接表达式
|
唐召明
authored
|
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
}
public Expression<Func<daq_client_config, base_project, bool>> StatusLinqWhere(daq_client_config client)
{
var exp = Expressionable.Create<daq_client_config, base_project>();
//数据过滤条件
//if (!string.IsNullOrWhiteSpace(model.XXX)) exp.And(x => x.XXX.Contains(model.XXX));
if (!string.IsNullOrWhiteSpace(client.name))
{
exp.And((c, p) => c.name.Contains(client.name));
}
if (!string.IsNullOrWhiteSpace(client.remark))
{
exp.And((c, p) => c.remark.Contains(client.remark));
}
if (!string.IsNullOrWhiteSpace(client.projectCode))
{
exp.And((c, p) => c.projectCode == client.projectCode);
}
|
赖素文
authored
|
192
|
exp.And((c, p) => SystemVariable.SoftTypes.Contains(c.type));
|
唐召明
authored
|
193
194
195
196
197
198
199
200
201
|
string user = sysWebUser.Account;
if (user != SystemVariable.DefaultCreated)
{
var projectRoleKeys = GetProjectRoleKeys(user);
exp.And((c, p) => SqlFunc.Subqueryable<sys_role_projects_rel>().Where(x => projectRoleKeys.Contains(x.project_roles_key) && x.project_key == p.keys).Any());
}
return exp.ToExpression();//拼接表达式
|
赖素文
authored
|
202
|
}
|
唐召明
authored
|
203
|
|
唐召明
authored
|
204
|
public Dictionary<string, string> GetProjectInfo()
|
唐召明
authored
|
205
206
207
208
209
210
211
212
|
{
try
{
var projects = Context.Queryable<base_project>().Select(x => new base_project
{
projectCode = x.projectCode,
projectName = x.projectName
}).Distinct().ToList();
|
唐召明
authored
|
213
214
215
216
217
218
219
220
221
222
223
224
225
|
return projects.ToDictionary(x => x.projectCode, y => y.projectName);
}
catch (Exception)
{
return new Dictionary<string, string>();
}
}
public Dictionary<string, string> GetSoftType()
{
try
{
var dictTypeId = Context.Queryable<sys_dict_type>().Where(x => x.dictType == "softType").Select(x => x.id).First();
|
唐召明
authored
|
226
|
var softTypes = Context.Queryable<sys_dict_data>().Where(x => x.headerId == dictTypeId).OrderBy(x => x.dictSort).ToList();
|
唐召明
authored
|
227
|
return softTypes.ToDictionary(x => x.dictValue, y => y.dictLabel);
|
唐召明
authored
|
228
229
230
|
}
catch (Exception)
{
|
唐召明
authored
|
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
return new Dictionary<string, string>();
}
}
public Response<List<base_factory>> GetFactorys(string projectCode)
{
var response = new Response<List<base_factory>>();
try
{
var projectKey = Context.Queryable<base_project>().Where(x => x.projectCode == projectCode).Select(x => x.keys).First();
var factorys = Context.Queryable<base_factory>().Where(x => x.projectKeys == projectKey).Select(x => new base_factory
{
factoryCode = x.factoryCode,
factoryName = x.factoryName
}).ToList();
response.Result = factorys;
response.Status = true;
}
catch (Exception ex)
{
response.ResponseErr(ex.Message);
|
唐召明
authored
|
252
|
}
|
唐召明
authored
|
253
|
return response;
|
唐召明
authored
|
254
|
}
|
赖素文
authored
|
255
256
|
}
}
|