yl
2024-09-26 7d1ef31efa71b7514e1d912de43ff2096880ef92
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using VueWebCoreApi.Tools;
 
namespace VueWebCoreApi.DLL.DAL
{
    public class KanBanManagerentDAL
    {
        public static ToMessage mes = new ToMessage(); //定义全局返回信息对象
 
        #region[车间看板,上生产信息]
        public static ToMessage WorkShopProduceTopData(string wkshopcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                string[] wkshoplist = Array.ConvertAll<string, string>(wkshopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
                sql = @"select * from h_v_JLKanBan_WorkshopTop where wkshp_code in @wkshoplist";
                dynamicParams.Add("@wkshoplist", wkshoplist);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[车间看板,下左近一周不良趋势]
        public static ToMessage WorkShopProduceBottomLeftData(string wkshopcode)
        {
            string sql = "";
            Dictionary<object, object> dir = new Dictionary<object, object>();
            try
            {
                //存储过程名(当前时间往前一周)
                string[] wkshoplist = Array.ConvertAll<string, string>(wkshopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
                sql = @"h_p_JLKanBan_WorkshopBottomLeft";
                for (int i = 0; i < wkshoplist.Length; i++)
                {
                    var dynamicParams = new DynamicParameters();
                    dynamicParams.Add("@wkshop_code", wkshoplist[i].ToString());
                    var dt = DapperHelper.selectProcedure(sql, dynamicParams);
                    dir.Add(wkshoplist[i].ToString(), dt);
                }
 
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = dir;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[车间看板,下右近一月不良统计]
        public static ToMessage WorkShopProduceBottomRightData(string wkshopcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                string[] wkshoplist = Array.ConvertAll<string, string>(wkshopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
                sql = @"select * from h_v_JLKanBan_WorkshopBottomRight where wkshp_code in @wkshoplist";
                dynamicParams.Add("@wkshoplist", wkshoplist);
                var data = DapperHelper.selectdata(sql, dynamicParams);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
 
        #region[车间综合看板,左上生产订单]
        public static ToMessage WorkShopCompreLeftTop(string wkshopcode)
        {
            var sql = "";
            var dynamicParams = new DynamicParameters();
            Dictionary<object, object> dir = new Dictionary<object, object>();
            Dictionary<object, object> dir0 = new Dictionary<object, object>();
            Dictionary<object, object> dir1 = new Dictionary<object, object>();
            try
            {
                string[] wkshoplist = Array.ConvertAll<string, string>(wkshopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
                sql = @"select * from h_v_JLKanBan_WorkShopCompreLeftTop";
                var data = DapperHelper.selecttable(sql);
                sql = @"select * from h_v_JLKanBan_WorkShopCompreLeftCenter";
                var data1 = DapperHelper.selecttable(sql);
                for (int i = 0; i < wkshoplist.Length; i++)
                {
                    var top0 = data.AsEnumerable()
                               .Where(row => row.Field<string>("wkshp_code") == wkshoplist[i].ToString()) // 添加查询条件
                               .Select(group => new
                               {
                                   wkshp_code = group.Field<string>("wkshp_code"),
                                   plan_qty = group.Field<decimal>("plan_qty"),
                                   good_qty = group.Field<decimal>("good_qty")
                               }).DefaultIfEmpty(new { wkshp_code = wkshoplist[i].ToString(), plan_qty = 0m, good_qty = 0m })//为空时指定默认值
                               .ToList();
                    dir0.Add(wkshoplist[i].ToString(), top0);
 
                    var top1 = data1.AsEnumerable()
                               .Where(row => row.Field<string>("wkshp_code") == wkshoplist[i].ToString()) // 添加查询条件
                               .Select(group => new
                               {
                                   wkshp_code = group.Field<string>("wkshp_code"),
                                   plan_qty = group.Field<decimal>("plan_qty"),
                                   quantity = group.Field<decimal>("quantity")
                               }).DefaultIfEmpty(new { wkshp_code = wkshoplist[i].ToString(), plan_qty = 0m, quantity = 0m })//为空时指定默认值
                               .ToList();
                    dir1.Add(wkshoplist[i].ToString(), top1);
                }
                dir.Add("LeftTop", dir0);
                dir.Add("LeftBottom", dir1);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = dir;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[车间综合看板,右上销售订单]
        public static ToMessage WorkShopCompreRightTop()
        {
            var sql = "";
            Dictionary<object, object> dir = new Dictionary<object, object>();
            try
            {
                sql = @"select * from h_v_JLKanBan_WorkShopCompreRightTop";
                var data = DapperHelper.selecttable(sql);
                sql = @"select * from h_v_JLKanBan_WorkShopCompreRightCenter";
                var data1 = DapperHelper.selecttable(sql);
                dir.Add("RightTop", data);
                dir.Add("RightBottom", data1);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = dir;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[车间综合看板,左下采购订单]
        public static ToMessage WorkShopCompreLeftBottom()
        {
            var sql = "";
            Dictionary<object, object> dir = new Dictionary<object, object>();
            try
            {
                sql = @"select * from h_v_JLKanBan_WorkShopCompreLeftBottom_Top";
                var data = DapperHelper.selecttable(sql);
                sql = @"select * from h_v_JLKanBan_WorkShopCompreLeftBottom_Bottom";
                var data1 = DapperHelper.selecttable(sql);
                dir.Add("BottomLeftTop", data);
                dir.Add("BottomLeftBottom", data1);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = dir;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[车间综合看板,右下库存]
        public static ToMessage WorkShopCompreRightBottom()
        {
            var sql = "";
            Dictionary<object, object> dir = new Dictionary<object, object>();
            try
            {
                sql = @"select * from h_v_JLKanBan_WorkShopCompreRightBottom";
                var data = DapperHelper.selecttable(sql);
                dir.Add("Y", data.Rows[0]["BaseQuantity"].ToString());
                dir.Add("B", data.Rows[1]["BaseQuantity"].ToString());
                dir.Add("C", data.Rows[2]["BaseQuantity"].ToString());
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = dir;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
 
        #region[仓库看板,左上产品待入库列表]
        public static ToMessage WareHouseTopLeftData()
        {
            string sql = "";
            try
            {
                //获取仓库生产加工单待入库列表
                sql = @"select * from h_v_JLKanBan_WareHouseTopLeft order by voucherdate";
                var data = DapperHelper.selecttable(sql);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[仓库看板,左下委外待入库列表]
        public static ToMessage WareHouseTopBottomData()
        {
            string sql = "";
            try
            {
                //获取仓库生产加工单待入库列表
                sql = @"select * from h_v_JLKanBan_WareHouseTopBottom order by voucherdate";
                var data = DapperHelper.selecttable(sql);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[仓库看板,右上成品库、半成品库top5库存排行]
        public static ToMessage WareHouseRightTopData()
        {
            string sql = "";
            try
            {
                sql = @"select * from h_v_JLKanBan_WareHouseRightTop";
                var data = DapperHelper.selecttable(sql);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
 
        #region[仓库看板,右下原料库库top5库存排行]
        public static ToMessage WareHouseRightBottomData()
        {
            string sql = "";
            try
            {
                sql = @"select * from h_v_JLKanBan_WareHouseRightBottom";
                var data = DapperHelper.selecttable(sql);
                mes.code = "200";
                mes.message = "查询成功!";
                mes.data = data;
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.message = e.Message;
                mes.data = null;
            }
            return mes;
        }
        #endregion
    }
}