ForkWindingDetectionLogService.cs
5.33 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
using FreeSql;
using HHECS.Application.Error;
using HHECS.BllModel;
using HHECS.Dal;
using HHECS.Dal.Repository;
using HHECS.Infrastructure.CommonHelper;
using HHECS.Infrastructure.Json;
using HHECS.Model.Entities;
using HHECS.Model.Enums;
using HHECS.Model.ViewEntity;
using NPOI.POIFS.FileSystem;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace HHECS.Application.Service
{
public class ForkWindingDetectionLogService : BaseService
{
public string Load(ForkWindingDetectionLog entity, PageReq pageReq)
{
return Execute(() =>
{
using var forkWindingDetection_LogRepository = new ForkWindingDetection_LogRepository();
var query = forkWindingDetection_LogRepository.Where(GetExpression(entity));
var total = query.Count();
var data = query.OrderBy(a => a.EquipmentCode)
.OrderByDescending(a => a.TestTime)
.Page(pageReq.page, pageReq.limit).ToList();
Response.Result = data;
Response.Count = total;
return Response.ToJson();
});
}
public Expression<Func<ForkWindingDetectionLog, bool>> GetExpression(ForkWindingDetectionLog entity)
{
Expression<Func<ForkWindingDetectionLog, bool>> filter = t => true;
if (!string.IsNullOrWhiteSpace(entity.EquipmentName))
{
filter = filter.And(t => t.EquipmentName.Contains(entity.EquipmentName));
}
if (!string.IsNullOrWhiteSpace(entity.WarehouseCode))
{
filter = filter.And(x => x.WarehouseCode == entity.WarehouseCode);
}
return filter;
}
public string Ins(ForkWindingDetectionLog entity, User user)
{
return Execute(() =>
{
entity.CreatedBy = user.UserCode;
entity.Created = DateTime.Now;
new ForkWindingDetection_LogRepository().Insert(entity);
return Response.ToJson();
});
}
public string Upd(ForkWindingDetectionLog entity, User user)
{
return Execute(() =>
{
entity.UpdatedBy = user.UserCode;
entity.Updated = DateTime.Now;
var result = InsertOrUpdate(entity);
if (!result.Success)
{
Response.ResponseError(result.Msg);
}
return Response.ToJson();
});
}
public BllResult<ForkWindingDetectionLog> InsertOrUpdate(ForkWindingDetectionLog entity)
{
try
{
ForkWindingDetection_LogRepository forkWindingDetection_LogRepository = new ForkWindingDetection_LogRepository();
entity = forkWindingDetection_LogRepository.InsertOrUpdate(entity);
return BllResultFactory.Success(entity);
}
catch (Exception ex)
{
return BllResultFactory.Error<ForkWindingDetectionLog>($"出现异常:{ex.Message}", ErrorCodeConst.DEZ0001.ToString());
}
}
public string DelByIds(int[] ids)
{
return Execute(() =>
{
using ForkWindingDetection_LogRepository forkWindingDetection_LogRepository = new ForkWindingDetection_LogRepository();
forkWindingDetection_LogRepository.Delete(t => ids.Contains(t.Id));
return Response.ToJson();
});
}
public string Export(ForkWindingDetectionLog entity)
{
return Execute(() =>
{
using ForkWindingDetection_LogRepository forkWindingDetection_LogRepository = new ForkWindingDetection_LogRepository();
var result = forkWindingDetection_LogRepository.Where(GetExpression(entity))
.OrderByDescending(a => new { a.EquipmentCode, a.TestTime })
.ToList();
Response.Result = result;
Response.Count = result.Count;
return Response.ToJson();
});
}
/// <summary>
/// 仓库查询设备
/// </summary>
public dynamic QueryEqByWare(string warehouseCode)
{
var response = new Response();
return Execute(() =>
{
EquipmentRepository equipmentRepository = new EquipmentRepository();
//不显示链条机2、滚筒输送机4、液压升降台5、过渡滚筒机8、称重滚筒输送机(双层)9
var res = equipmentRepository.Where(x => x.WarehouseCode == warehouseCode && x.EquipmentTypeId != 2 && x.EquipmentTypeId != 4 && x.EquipmentTypeId != 5 && x.EquipmentTypeId != 8 && x.EquipmentTypeId != 9).ToList();
if (res.Count > 0)
{
response.Result = res;
response.Status = true;
}
if (!response.Status) response.Message = "通过该仓库编码查询不到设备!请检查";
return response.ToJson();
});
}
}
}