BllService.cs
8.27 KB
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
135
136
137
138
139
140
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using HHECS.Application.Service;
using HHECS.BllModel;
using HHECS.Dal;
using HHECS.Dal.Repository;
using HHECS.DAL;
using HHECS.DAL.Repository;
using HHECS.Model.Entities;
using HHECS.Model.Enums;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http;
namespace HHECS.BLL.Services
{
/// <summary>
/// 系统相关服务,比如字典查询,设备关系维护等
/// </summary>
public class BllService : BaseService
{
#region System
public BllResult<List<Config>> GetAllConfig()
{
try
{
ConfigRepository configRepository = new ConfigRepository();
return BllResultFactory.Success(configRepository.Where(t => true).ToList());
}
catch (Exception ex)
{
return BllResultFactory.Error<List<Config>>($"异常:{ex.Message}");
}
}
public BllResult<Config> GetConfig(string code)
{
try
{
ConfigRepository configRepository = new ConfigRepository();
return BllResultFactory.Success(configRepository.Where(t => t.Code == code).First());
}
catch (Exception ex)
{
return BllResultFactory.Error<Config>($"异常:{ex.Message}");
}
}
public BllResult<Config> GetConfig(int id)
{
try
{
ConfigRepository configRepository = new ConfigRepository();
return BllResultFactory.Success(configRepository.Where(t => t.Id == id).First());
}
catch (Exception ex)
{
return BllResultFactory.Error<Config>($"异常:{ex.Message}");
}
}
public BllResult DeleteConfigByIds(List<int> list)
{
try
{
ConfigRepository configRepository = new ConfigRepository();
configRepository.Delete(t => list.Contains(t.Id));
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error<Config>($"异常:{ex.Message}");
}
}
/// <summary>
/// 插入或更新字典明细
/// </summary>
/// <param name="currentDictDetial"></param>
/// <returns></returns>
public BllResult SaveDictDetail(DictDetail currentDictDetial)
{
try
{
DictDetailRepository dictDetailRepository = new DictDetailRepository();
dictDetailRepository.InsertOrUpdate(currentDictDetial);
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
/// <summary>
/// 插入或更新字典主表
/// </summary>
/// <param name="currentDict"></param>
/// <returns></returns>
public BllResult SaveDict(Dict currentDict)
{
try
{
DictRepository dictRepository = new DictRepository();
dictRepository.InsertOrUpdate(currentDict);
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
public BllResult DeleteDictByIds(List<int> list)
{
using (var uw = DALHelper.GetFreeSql().CreateUnitOfWork())
{
try
{
var dictres = new DictRepository();
var dictdetailres = new DictDetailRepository();
dictres.UnitOfWork = uw;
dictdetailres.UnitOfWork = uw;
var dicts = dictres.Where(t => list.Contains(t.Id)).IncludeMany(a => a.DictDetails).ToList();
dictres.Delete(dicts);
dictdetailres.Delete(dicts.SelectMany(t => t.DictDetails));
uw.Commit();
return BllResultFactory.Success();
}
catch (Exception ex)
{
uw.Rollback();
return BllResultFactory.Error(ex.Message);
}
}
}
/// <summary>
/// 插入或更新config
/// </summary>
/// <param name="config"></param>
/// <returns></returns>
public BllResult SaveConfig(Config config)
{
try
{
ConfigRepository configRepository = new ConfigRepository();
configRepository.InsertOrUpdate(config);
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
public BllResult<Dict> GetDictWithDetails(Expression<Func<Dict, bool>> filter)
{
try
{
DictRepository dictRepository = new DictRepository();
var a = dictRepository.Where(filter).IncludeMany(t => t.DictDetails).First();
if (a == null)
{
return BllResultFactory.Error<Dict>("未查询到数据");
}
else
{
return BllResultFactory.Success(a);
}
}
catch (Exception ex)
{
return BllResultFactory.Error<Dict>($"异常:{ex.Message}");
}
}
public BllResult<Dict> GetDictWithDetails(Expression<Func<Dict, bool>> filter, Expression<Func<DictDetail, bool>> exp)
{
try
{
DictRepository dictRepository = new DictRepository();
var a = dictRepository.Where(filter).IncludeMany(t => t.DictDetails, then => then.Where(exp)).First();
if (a == null)
{
return BllResultFactory.Error<Dict>("未查询到数据");
}
else
{
return BllResultFactory.Success(a);
}
}
catch (Exception ex)
{
return BllResultFactory.Error<Dict>($"异常:{ex.Message}");
}
}
public BllResult DeleteDictDetailByIds(List<int> lists)
{
try
{
DictDetailRepository dictDetailRepository = new DictDetailRepository();
dictDetailRepository.Delete(t => lists.Contains(t.Id));
return BllResultFactory.Success();
}
catch (Exception ex)
{
return BllResultFactory.Error(ex.Message);
}
}
public BllResult InsertCollectionLog(string printRecive)
{
var results = printRecive.Split("/n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
BusCollectionResultRepository busCollectionLogRepository = new BusCollectionResultRepository();
List<BusCollectionResult> collectionLogs = new List<BusCollectionResult>();
foreach (var result in results)
{
var busCollectionLog = new BusCollectionResult();
busCollectionLog.Keys = Guid.NewGuid();
busCollectionLog.Value = result;
busCollectionLog.ExternalEquipmentCode = "";
busCollectionLog.CreateTime = DateTime.Now;
busCollectionLog.CreateBy = "";
collectionLogs.Add(busCollectionLog);
}
using (var uw = DALHelper.GetFreeSql().CreateUnitOfWork())
{
try
{
busCollectionLogRepository.UnitOfWork = uw;
busCollectionLogRepository.Insert(collectionLogs);
uw.Commit();
return BllResultFactory.Success();
}
catch (Exception ex)
{
uw?.Rollback();
return BllResultFactory.Error(ex.Message);
}
}
}
#endregion
}
}