WaitMOMSendService.cs
3.37 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
using Hh.Mes.Common.Request;
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.EnumEntitys;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.WebEntity.log;
using Hh.Mes.Service.Repository;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace Hh.Mes.Service.WebService.Wo
{
public class WaitMOMSendService : RepositorySqlSugar<MOMSendErrorLog>
{
public Response<List<MOMSendErrorLog>> GetMOMSends(PageReq pageReq, MOMSendErrorLog entity)
{
var response = new Response<List<MOMSendErrorLog>>();
int total = 0;
var data = Context.Queryable<MOMSendErrorLog>().Where(LinqWhere(entity)).OrderBy(x => x.createTime, OrderByType.Desc).ToPageList(pageReq.page, pageReq.limit, ref total);
response.Count = data.Count;
response.Result = data;
return response;
}
public Response AddLog(string code, EnumWaitMOMSend sendType, string ramark = "")
{
var response = new Response();
try
{
var codeInfo = string.Empty;
if (sendType == EnumWaitMOMSend.物料)
{
codeInfo = $"物料编码:{code}";
}
else if (sendType == EnumWaitMOMSend.工艺路线)
{
codeInfo = $"产品编码:{code}";
}
//物料或工艺路线已经存在,再次重复发送不记录日志
if (ramark.Contains("已存在,请勿重复发送"))
{
return response.ResponseSuccess();
}
var oldLog = Context.Queryable<MOMSendErrorLog>().First(x => x.code == code && x.sendType == sendType);
if (oldLog is null)
{
var entity = new MOMSendErrorLog
{
code = code,
codeInfo = codeInfo,
sendType = sendType,
remarks = ramark,
createTime = DateTime.Now,
};
Context.Insertable(entity).ExecuteCommand();
}
else
{
oldLog.remarks = ramark;
oldLog.createTime = DateTime.Now;
Context.Updateable(oldLog).ExecuteCommand();
}
return response.ResponseSuccess();
}
catch (Exception ex)
{
return response.ResponseError(ex.Message);
}
}
public Expression<Func<MOMSendErrorLog, bool>> LinqWhere(MOMSendErrorLog model)
{
var exp = Expressionable.Create<MOMSendErrorLog>();
if (!string.IsNullOrWhiteSpace(model.code))
{
exp.And(x => x.code.Contains(model.code));
}
if (model.startTime != null)
{
exp.And(x => x.createTime >= model.startTime);
}
if (model.endTime != null)
{
exp.And(x => x.createTime <= model.endTime);
}
if (model.queryType != 0)
{
exp.And(x => x.sendType == (EnumWaitMOMSend)model.queryType);
}
return exp.ToExpression();//拼接表达式
}
}
}