WarehouseService.cs
6.12 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
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 System;
using System.Text;
namespace Hh.Mes.Service.Warehous
{
public class WarehouseService : RepositorySqlSugar<base_warehouse>
{
/// <summary>
/// 查询方法
/// </summary>
/// <param name="page">页码</param>
/// <param name="model">传入的参数</param>
/// <returns></returns>
public Response Load(PageReq page, base_warehouse model)
{
var result = new Response();
var stringBuilder = new StringBuilder();
string sqlWhere = SqlWhere(model);
stringBuilder.Append($@"select t1.*, t2.workshopName workshopname,t3.lineName from base_warehouse
t1 left join base_workshop t2 on t1.workShopCode=t2.workShopCode
left join base_line t3 on t1.lineCode=t3.lineCode where {sqlWhere} ");
//查询条件
var parameters = new
{
name = model.name,
code = model.code,
workshopCode = model.workshopCode,
lineCode = model.lineCode
};
var index = base.Context.Ado.GetDataTable(stringBuilder.ToString(), parameters).Rows.Count;//获取行数
if (page != null)//分页
{
stringBuilder.Append($" order by t1.id desc offset {(page.page - 1) * page.limit} row fetch next {page.limit} row only ");
}
var list = base.Context.Ado.GetDataTable(stringBuilder.ToString(), parameters);
result.Result = list;
result.Count = index;
return result;
}
/// <summary>
/// 添加
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
public dynamic Ins(base_warehouse model)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
model.lineId = null;
model.workshopId = null;
var prefix = base.GetDictionaryDictValue("base_warehouse");
var maxValue = GetTableMaxValue<base_warehouse>("id");
model.code = prefix + maxValue;
model.createBy = sysWebUser.Account;
model.createTime = DateTime.Now;
response.Status = Add(model);
if (!response.Status)
{
response.Message = "添加失败";
}
return response;
});
}
/// <summary>
/// 编辑方法
/// </summary>
/// <param name="model">参数</param>
/// <returns></returns>
public dynamic Upd(base_warehouse model)
{
var response = new Response();
return ExceptionsHelp.Instance.ExecuteT(() =>
{
model.updateBy = sysWebUser.Account;
model.updateTime = DateTime.Now;
response.Status = base.Context.Updateable(model).IgnoreColumns(it => new { it.createBy, it.createTime }).ExecuteCommand() > 0;
if (!response.Status)
{
response.Message = "编辑失败";
}
return response;
});
}
/// <summary>
/// 删除方法
/// </summary>
/// <param name="ids">需要删除的id</param>
/// <returns></returns>
public dynamic DelByIds(string[] ids)
{
var response = new Response {Message = ""};
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var index = 0;
foreach (var code in ids)
{
var isExit = Context.Queryable<base_location>().Any(u => u.warehouseCode == code);//是否存在
if (isExit)
{
index++;
//提示
response.Code = 300;
response.Message += $"仓库:{code}在库存里面存在数据不能删除 <br>";
}
}
if (index > 0) return response;
var temp = Context.Deleteable<base_warehouse>().In(x => x.code, ids).ExecuteCommand() > 0;
if (!temp)
{
response.Message = "删除失败,反复出现请联系管理员";
}
return response;
});
}
public string SqlWhere(base_warehouse model)
{
var stringBuilder = new StringBuilder();
stringBuilder.Append("1=1");
if (!string.IsNullOrWhiteSpace(model.name))
{
stringBuilder.Append($" and t1.name like '%'+@name+'%' ");
}
if (!string.IsNullOrWhiteSpace(model.code))
{
stringBuilder.Append($" and t1.code like '%'+@code+'%' ");
}
if (!string.IsNullOrWhiteSpace(model.workshopCode))
{
stringBuilder.Append($" and t1.workshopCode like '%'+@workshopCode+'%' ");
}
if (!string.IsNullOrWhiteSpace(model.lineCode))
{
stringBuilder.Append($" and t1.lineCode like '%'+@lineCode+'%' ");
}
return stringBuilder.ToString();
}
/// <summary>
/// 导出
/// </summary>
public dynamic ExportData(PageReq page, base_warehouse entity)
{
return ExceptionsHelp.Instance.ExecuteT(() =>
{
var result = new Response();
var ds = Load(null, entity);
if (ds == null || ds.Count == 0)
{
result.Result = "[]";
result.Count = 0;
}
else
{
result.Result = ds.Result;
result.Count = ds.Count;
}
return result;
}, catchRetrunValue: "list");
}
}
}