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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using VueWebApi.DDKanBanModel;
using VueWebApi.Models;
using VueWebApi.Tools;
 
namespace VueWebApi.DLL.DAL
{
    public class KanBanManagerentDAL
    {
        public static DataTable dt;    //定义全局变量dt
        public static bool res;       //定义全局变量dt
        public static ToMessage mes = new ToMessage(); //定义全局返回信息对象
        public static string strProcName = ""; //定义全局sql变量
        public static List<SqlParameter> listStr = new List<SqlParameter>(); //定义全局参数集合
        public static SqlParameter[] parameters; //定义全局SqlParameter参数数组
 
        #region[大岛车间综合看板,获取生产车间]
        public static ToMessage ShopSearch()
        {
            string sql = "";
            string search = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //获取车间信息
                sql = @"select org_code ,org_name from TOrganization where is_delete='0' and description='W'";
                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 LineSearchTopLeftData(string shopcode)
        {
            string sql = "";
            List<ShopTopLeft> list = new List<ShopTopLeft>();
            var dynamicParams = new DynamicParameters();
            try
            {
                if (shopcode != null || shopcode != "") //产线编码不为空
                {
                    string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
                    //查询产线下已开工的加工单信息
                    sql = @"select distinct E.saleOrderCode,A.wo_code,P.plan_qty,M.partcode,M.partname,M.partspec,T.name as uomname   from TK_Wrk_Record A
                                    inner join TK_Wrk_Man P on A.wo_code=P.wo_code
                                    left join TMateriel_Info M on P.materiel_code=M.partcode
                                    left join TUom T on M.uom_code=T.code 
                                    left join TKimp_Ewo E on P.m_po=E.wo and P.sourceid=E.id
                                    where P.status<>'CLOSED' and P.status<>'NEW' and P.wkshp_code in @shopcode and A.style='S' and A.step_seq='1'";
                    var data0 = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
                
                    if (data0.Rows.Count > 0)
                    {
                        for (int j = 0; j < data0.Rows.Count; j++)
                        {
                            string saleOrderCode = data0.Rows[j]["SALEORDERCODE"].ToString();//销售订单号
                            string wo_code = data0.Rows[j]["WO_CODE"].ToString();//工单号
                            string plan_qty = data0.Rows[j]["PLAN_QTY"].ToString();//任务数量
                            string partcode = data0.Rows[j]["PARTCODE"].ToString();//产品编码
                            string partname = data0.Rows[j]["PARTNAME"].ToString();//产品名称
                            string partspec = data0.Rows[j]["PARTSPEC"].ToString();//产品规格
                            string uomname = data0.Rows[j]["UOMNAME"].ToString();//单位名称
                            ShopTopLeft lineone = new ShopTopLeft();
                            lineone.saleordercode = saleOrderCode;
                            lineone.workcode = wo_code;
                            lineone.qty = plan_qty;
                            lineone.partnumber = partcode;
                            lineone.partname = partname;
                            lineone.partspec = partspec;
                            lineone.uom = uomname;
                            lineone.children = new List<TreeTwo>();
 
                            //查新工单下工序信息
                            sql = @"select A.seq,T.stepcode,T.stepname,A.plan_qty,A.good_qty,A.ng_qty,A.status  
                                            from TK_Wrk_Step A
                                            left join TStep T on A.step_code=T.stepcode
                                            where A.wo_code=@wo_code";
                            dynamicParams.Add("@wo_code", wo_code);
                            var data1 = DapperHelper.selectdata(sql, dynamicParams);
                            for (int k = 0; k < data1.Rows.Count; k++)
                            {
                                string stepseq = data1.Rows[k]["SEQ"].ToString();//工序序号
                                string stepcode = data1.Rows[k]["STEPCODE"].ToString();//工序编码
                                string stepname = data1.Rows[k]["STEPNAME"].ToString();//工序名称
                                string planqty = data1.Rows[k]["PLAN_QTY"].ToString();//任务数量
                                string good_qty = data1.Rows[k]["GOOD_QTY"].ToString();//报工数量
                                string ng_qty = data1.Rows[k]["NG_QTY"].ToString();//不良数量
                                string status = data1.Rows[k]["STATUS"].ToString();//状态
                                TreeTwo linetwo = new TreeTwo();
                                linetwo.stepseq = stepseq;
                                linetwo.stepcode = stepcode;
                                linetwo.stepname = stepname;
                                linetwo.planqty = planqty;
                                linetwo.goodqty = good_qty;
                                linetwo.ngqty = ng_qty;
                                linetwo.status = status;
                                lineone.children.Add(linetwo);
                            }
                            list.Add(lineone);
                        }
                    }
                    else
                    {
                        mes.code = "300";
                        mes.Message = "当前车间下无在生产任务!";
                        mes.data = null;
                    }
                }
                else
                {
                    mes.code = "300";
                    mes.Message = "车间参数不能为空!";
                    mes.data = null;
                }
            }
            catch (Exception e)
            {
                mes.code = "300";
                mes.count = 0;
                mes.Message = e.Message;
                mes.data = null;
            }
            mes.code = "200";
            mes.Message = "查询成功!";
            mes.data = list;
            return mes;
        }
        #endregion\
 
        #region[大岛车间综合看板,左下列表接口]
        public static ToMessage LineSearchBottomLeftData(string shopcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
            try
            {
                //获取任务列表信息
                sql = @"select A.*,ROW_NUMBER() OVER(ORDER BY (case when A.warning<=2 then A.planenddate end) asc ,A.planstartdate asc) AS RowNum from(
                         select  A.status,A.lm_date,E.saleOrderCode,A.wo_code,M.partcode,M.partname,M.partspec,U.name,
                         A.plan_qty,B.good_qty,B.ng_qty,E.planstartdate,E.planenddate, datediff(day,getdate(),E.planenddate) warning
                         from TK_Wrk_Man A 
                         inner join TK_Wrk_Step B on A.wo_code=B.wo_code
                         inner join TKimp_Ewo E on A.m_po=E.wo and A.sourceid=E.id
                         left  join TMateriel_Info M on A.materiel_code=M.partcode
                         left  join TUom U on M.uom_code=U.code
                         where A.status<>'CLOSED' and A.wkshp_code in @shopcode and A.is_delete<>'1' and B.isend='Y'
                         )as A ";
                var data = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
                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[大岛车间综合看板,右上top排行接口,当日]
        public static ToMessage LineSearchTopRightData(string shopcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
            try
            {
                //获取产品报工top5信息
                sql = @"select top 5 A.org_name as wkshname,A.name as linename,A.partname,isnull(sum(A.good_qty),0) as good_qty from(
                        select W.org_name,E.name,M.partname,A.good_qty  from TK_Wrk_Record A
                        inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code
                        inner join TMateriel_Info M on A.materiel_code=M.partcode
                        inner  join TEqpInfo E on A.eqp_code=E.code
                        inner  join TOrganization W on E.wksp_code=W.org_code and W.description='W'
                        where A.style='B' and S.isend='Y' and W.org_code in @shopcode and datediff(day,GETDATE(),A.lm_date)=0
                        union all
                        select C.name as linename,'' as wkshname,M.partname,A.sqty as good_qty  from TK_Wrk_OutRecord A
                        inner join TK_Wrk_Step S on A.wo_code=S.wo_code and A.step_code=S.step_code
                        inner join TMateriel_Info M on A.materiel_code=M.partcode
                        inner  join TCustomer C on A.wx_code=C.code and C.btype='WX'
                        where A.style='S' and S.isend='Y' and datediff(day,GETDATE(),A.lm_date)=0
                        ) as A group by A.org_name,A.name,A.partname order by good_qty desc";
                var data = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
                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[大岛车间综合看板,右下top排行接口,当前时间往前一周]
        public static ToMessage LineSearchBottomRightData(string shopcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
            try
            {
                //获取报工不良top5信息
                sql = @"select isnull(COUNT(B.name),0) cont,B.name   
                        from CSR_WorkRecord_Defect A
                        inner join TDefect B on A.defect_code=B.code
                        inner join TK_Wrk_Man M on A.wo_code=M.wo_code
                        where DateDiff(dd,A.lm_date,getdate())<=7 and M.wkshp_code in @shopcode
                        group by B.name order by cont desc";
                var data = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
                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 PurchaseLeftTop()
        {
            string sql = "";
            try
            {
                //获取本月采购订单数、本月采购进货单数、本月采购入库单数
                sql = @"select * from h_v_DDKanBan_PurchaseLeftTop ";
                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 PurchaseLeftBottom()
        {
            string sql = "";
            try
            {
                //获取采购订单跟踪列表
                sql = @"select * from h_v_DDKanBan_PurchaseLeftBottom ";
                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[采购订单跟踪管理看板,右侧Top]
        public static ToMessage PurchaseRight()
        {
            string sql = "";
            try
            {
                //获取采购订单跟踪列表
                sql = @"select * from h_v_DDKanBan_PurchaseRight ";
                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 WareHouseTopLeftData()
        {
            string sql = "";
            try
            {
                //获取仓库生产加工单待入库列表
                sql = @"select * from h_v_DDKanBan_WareHouseTopLeft";
                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_DDKanBan_WareHouseTopBottom";
                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_DDKanBan_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_DDKanBan_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
 
 
        #region[车间看板公告]
        public static ToMessage WkspReportNotice(string shopcode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                string[] selects = Array.ConvertAll<string, string>(shopcode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries), s => s.ToString()); //string分割转string[] 
                //获取车间公告信息
                sql = @"select contents  from TSystemAnnouncement
                       where wksp_code in @shopcode";
                var data = DapperHelper.selectlist(sql, new { shopcode = selects.ToArray() });
                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
    }
}