duan
2024-08-21 22bd5bc1ce2b49284cc2f042c7f4f48619fcf85b
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
using DIXWeb.DAL;
using DIXWeb.DataRepository;
using DIXWeb.Entity.GlobalM;
using DIXWeb.Entity.Workflow;
using DIXWeb.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Dynamic;
using System.Text;
 
namespace DIXWeb.Business.GlobalM
{
    public class WorkListBusiness : BaseBusiness<WorkList>
    {
        #region Íⲿ½Ó¿Ú
 
        /// <summary>
        /// »ñÈ¡Êý¾ÝÁбí
        /// </summary>
        /// <param name="condition">²éѯÀàÐÍ</param>
        /// <param name="keyword">¹Ø¼ü×Ö</param>
        /// <returns></returns>
        public List<WorkListModel> GetDataList(int viewType, string subject, string billno, Pagination pagination)
        {
            var plist = new List<System.Data.Common.DbParameter>();
            plist.Add(GlobalDataHelper.NewSqlParameter("@Subject", subject));
            plist.Add(GlobalDataHelper.NewSqlParameter("@BillNo", billno));
            plist.Add(GlobalDataHelper.NewSqlParameter("@viewType", viewType));
            plist.Add(GlobalDataHelper.NewSqlParameter("@UserId", GlobalDataHelper.GetLoginUserNo()));
            List<WorkListModel> rlist = Service.GetListByProcNew<WorkListModel>("wp_wf_getMyworklist", plist);
 
            return rlist.GetPagination(pagination).ToList();
        }
 
        /// <summary>
        /// »ñÈ¡Ö¸¶¨µÄµ¥ÌõÊý¾Ý
        /// </summary>
        /// <param name="id">Ö÷¼ü</param>
        /// <returns></returns>
        public WorkListModel GetWorkListInst(int btid, string bizdataids)
        {
            WorkListModel rm = null;
            List<WorkListModel> rlist = Service.GetListByProcNew<WorkListModel>("wp_wf_getworklist", new List<System.Data.Common.DbParameter>() { new System.Data.SqlClient.SqlParameter("@btid", btid) });
            if (rlist != null && rlist.Count > 0)
            {
                rm = rlist[0];
                string userindex = GlobalDataHelper.GetLoginUser().Id.ToString().PadLeft(3, '0');
                userindex = userindex.Substring(0, 3);
                if (rm.Id == 0) rm.BillNo = rm.BillCode + userindex + System.DateTime.Now.ToString("yyMMddHHmmssfff");
            }
            else rm = new WorkListModel();
            rm.BizDataIds = bizdataids;
            return rm;
        }
 
        /// <summary>
        /// »ñÈ¡Ö¸¶¨µÄµ¥ÌõÊý¾Ý
        /// </summary>
        /// <param name="id">Ö÷¼ü</param>
        /// <returns></returns>
        public WorkListModel GetWorkListInstNew(int instid, string billno, int btid)
        {
            WorkListModel rm = null;
            List<WorkListModel> rlist = Service.GetListByProcNew<WorkListModel>("wp_workflow_getworklist", new List<System.Data.Common.DbParameter>()
            { new System.Data.SqlClient.SqlParameter("@id", instid),
            new System.Data.SqlClient.SqlParameter("@billno", billno) ,
            new System.Data.SqlClient.SqlParameter("@btid", btid) });
            if (rlist != null && rlist.Count > 0)
            {
                rm = rlist[0];
                if (billno == "")
                {
 
                    string userindex = GlobalDataHelper.GetLoginUser().Id.ToString().PadLeft(3, '0');
                    userindex = userindex.Substring(0, 3);
                    if (rm.Id == 0) rm.BillNo = rm.BillCode + userindex + System.DateTime.Now.ToString("yyMMddHHmmssfff");
                }
            }
            else rm = new WorkListModel();
            return rm;
        }
        void SetupSysInfo(WorkList data, bool isCreate)
        {
            if (isCreate)
            {
                data.CreateTime = DateTime.Now;
                data.CreateUserId = GlobalDataHelper.GetLoginUserNo();
            }
            data.CHtime = DateTime.Now;
            data.ChUserId = GlobalDataHelper.GetLoginUserNo();
        }
        /// <summary>
        /// Ìí¼ÓÊý¾Ý
        /// </summary>
        /// <param name="newData">Êý¾Ý</param>
        public ResultMessage SubmitBill(WorkListModel newData)
        {
            SetupSysInfo(newData, true);
            var plist = new List<System.Data.Common.DbParameter>();
            plist.Add(GlobalDataHelper.NewSqlParameter("@Subject", newData.Subject));
            plist.Add(GlobalDataHelper.NewSqlParameter("@BillNo", newData.BillNo));
            plist.Add(GlobalDataHelper.NewSqlParameter("@BillTypeId", newData.BillTypeId));
            plist.Add(GlobalDataHelper.NewSqlParameter("@UserId", GlobalDataHelper.GetLoginUserNo()));
 
 
            ResultMessage rm = Service.SubmitDataByProc("wp_worklist_submitbill", plist);
            return rm;
        }
 
        /// <summary>
        /// Ìí¼ÓÊý¾Ý
        /// </summary>
        /// <param name="newData">Êý¾Ý</param>
        public ResultMessage AddData(WorkListModel newData)
        {
            SetupSysInfo(newData, true);
            var plist = new List<System.Data.Common.DbParameter>();
            plist.Add(GlobalDataHelper.NewSqlParameter("@Subject", newData.Subject));
            plist.Add(GlobalDataHelper.NewSqlParameter("@BillNo", newData.BillNo));
            plist.Add(GlobalDataHelper.NewSqlParameter("@BillTypeId", newData.BillTypeId));
            plist.Add(GlobalDataHelper.NewSqlParameter("@UserId", GlobalDataHelper.GetLoginUserNo()));
            plist.Add(GlobalDataHelper.NewSqlParameter("@BizDataIds", newData.BizDataIds));
 
 
            ResultMessage rm = Service.SubmitDataByProc("wp_worklist_newdata", plist);
            return rm;
        }
 
        /// <summary>
        /// ¸üÐÂÊý¾Ý
        /// </summary>
        public ResultMessage UpdateData(WorkListModel theData)
        {
            SetupSysInfo(theData, false);
            return null;
        }
        
        /// <summary>
        /// É¾³ýÊý¾Ý
        /// </summary>
        /// <param name="theData">ɾ³ýµÄÊý¾Ý</param>
        public void DeleteData(List<string> ids)
        {
            Delete(ids);
        }
        public ResultMessage HandleBill(string ids, int type)
        {
            ids = string.IsNullOrEmpty(ids) ? "" : ids.Trim();
            ids = ids.Replace("[", "").Replace("]", "");
            string[] idarray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            string sucessids = "", failids = "";
            int success = 0, fail = 0;
            for (int i = 0; i < idarray.Length; i++)
            {
                var plist = new List<System.Data.Common.DbParameter>();
                plist.Add(GlobalDataHelper.NewSqlParameter("@id", idarray[i]));
                plist.Add(GlobalDataHelper.NewSqlParameter("@type", type));
                plist.Add(GlobalDataHelper.NewSqlParameter("@UserId", GlobalDataHelper.GetLoginUserNo()));
                ResultMessage rm = Service.SubmitDataByProc("wp_worklist_audit", plist);
                if (rm.Count > 0) { sucessids += idarray[i] + ","; success += 1; }
                else { failids += idarray[i] + ","; fail += 1; }
            }
 
            return new ResultMessage(1, "Ö´Ðнá¹ûΪ¡¾³É¹¦:" + success.ToString() + "±Ê,ID·Ö±ðΪ:" + sucessids + ";Ö´ÐÐʧ°Ü£º" + fail.ToString() + "±Ê,ID·Ö±ðΪ:" + failids + "¡¿");
        }
        #endregion
 
        #region Ë½ÓгÉÔ±
 
        #endregion
 
        #region Êý¾ÝÄ£ÐÍ
 
        #endregion
 
 
        public Receive GetMyNeedDealt(string Code, int UserId, int pageIndex = 1, int pageSize = 5)
        {
            Receive receive = new Receive();
            try
            {
                using (DBContext db = new DBContext())
                {
                    System.Data.SqlClient.SqlParameter[] paramList = new System.Data.SqlClient.SqlParameter[] {
                        new System.Data.SqlClient.SqlParameter("@Code", Code),
                        new System.Data.SqlClient.SqlParameter("@UserId", UserId),
                        new System.Data.SqlClient.SqlParameter("@pageIndex", pageIndex),
                        new System.Data.SqlClient.SqlParameter("@pageSize", pageSize),
                        new System.Data.SqlClient.SqlParameter("@Total", 0),
                    };
                    int index = paramList.Length - 1;
                    paramList[index].Direction = ParameterDirection.Output;
                    receive.rows = db.Database.SqlQuery<ReceiveNeedDealt>("EXEC meta.p_myNeedDealt @Code,@UserId,@pageIndex,@pageSize,@Total output ", paramList).ToList();
                    receive.total = int.Parse(paramList[index].Value.ToString());
                    receive.Code = 200;
                    receive.Message = "SUCCESS"; 
                }
            }
            catch (Exception ex)
            {
                receive.Code = 500;
                receive.Message = ex.Message;
            }
            return receive;
        }
 
        public Receive GetInRepair(string Code, int UserId, int pageIndex = 1, int pageSize = 5)
        {
            Receive receive = new Receive();
            try
            {
                using (DBContext db = new DBContext())
                {
                    System.Data.SqlClient.SqlParameter[] paramList = new System.Data.SqlClient.SqlParameter[] {
                        new System.Data.SqlClient.SqlParameter("@Code", Code),
                        new System.Data.SqlClient.SqlParameter("@UserId", UserId),
                        new System.Data.SqlClient.SqlParameter("@pageIndex", pageIndex),
                        new System.Data.SqlClient.SqlParameter("@pageSize", pageSize),
                        new System.Data.SqlClient.SqlParameter("@Total", 0),
                    };
                    int index = paramList.Length - 1;
                    paramList[index].Direction = ParameterDirection.Output;
                    receive.rows = db.Database.SqlQuery<ReceiveNeedDealt>("EXEC meta.p_myInRepair @Code,@UserId,@pageIndex,@pageSize,@Total output ", paramList).ToList();
                    receive.total = int.Parse(paramList[index].Value.ToString());
                    receive.Code = 200;
                    receive.Message = "SUCCESS";
                }
            }
            catch (Exception ex)
            {
                receive.Code = 500;
                receive.Message = ex.Message;
            }
            return receive;
        }
 
        public Receive ApproveAgree(int[] BillflowIdArr, int UserId,string Remark,string AppendixUrl)
        {
            Receive record = null;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < BillflowIdArr.Length; i++)
            {
                sb.Append(BillflowIdArr[i] + ",");
            }
            using (DBContext db = new DBContext())
            {
                System.Data.SqlClient.SqlParameter[] paramList = new System.Data.SqlClient.SqlParameter[] {
                    new System.Data.SqlClient.SqlParameter("@BillflowIdStr", sb.ToString()),
                    new System.Data.SqlClient.SqlParameter("@UserId", UserId),
                    new System.Data.SqlClient.SqlParameter("@Remark", Remark),
                    new System.Data.SqlClient.SqlParameter("@AppendixUrl", AppendixUrl),
                };
                record = db.Database.SqlQuery<Receive>("EXEC meta.p_ApproveAgree @BillflowIdStr,@UserId,@Remark,@AppendixUrl ", paramList).FirstOrDefault();
            }
            return record;
        }
 
        public Receive ApproveAgreeAll(int UserId, string Remark, string AppendixUrl)
        {
            Receive record = null;
            using (DBContext db = new DBContext())
            {
                System.Data.SqlClient.SqlParameter[] paramList = new System.Data.SqlClient.SqlParameter[] {
                    new System.Data.SqlClient.SqlParameter("@UserId", UserId),
                    new System.Data.SqlClient.SqlParameter("@Remark", Remark),
                    new System.Data.SqlClient.SqlParameter("@AppendixUrl", AppendixUrl),
                };
                record = db.Database.SqlQuery<Receive>("EXEC meta.p_ApproveAgreeAll @UserId,@Remark,@AppendixUrl ", paramList).FirstOrDefault();
            }
            return record;
        }
 
        public Receive ApproveRefuse(int[] BillflowIdArr, int UserId,string Remark)
        {
            Receive record = null;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < BillflowIdArr.Length; i++)
            {
                sb.Append(BillflowIdArr[i] + ",");
            }
            using (DBContext db = new DBContext())
            {
                System.Data.SqlClient.SqlParameter[] paramList = new System.Data.SqlClient.SqlParameter[] {
                    new System.Data.SqlClient.SqlParameter("@BillflowIdStr", sb.ToString()),
                    new System.Data.SqlClient.SqlParameter("@UserId", UserId),
                    new System.Data.SqlClient.SqlParameter("@Remark", Remark),
                };
                record = db.Database.SqlQuery<Receive>("EXEC meta.p_ApproveRefuse @BillflowIdStr,@UserId,@Remark ", paramList).FirstOrDefault();
            }
            return record;
        }
        public Receive ApproveKeepRemart(int[] BillflowIdArr, int UserId, string Remark)
        {
            Receive record = null;
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < BillflowIdArr.Length; i++)
            {
                sb.Append(BillflowIdArr[i] + ",");
            }
            using (DBContext db = new DBContext())
            {
                System.Data.SqlClient.SqlParameter[] paramList = new System.Data.SqlClient.SqlParameter[] {
                    new System.Data.SqlClient.SqlParameter("@BillflowIdStr", sb.ToString()),
                    new System.Data.SqlClient.SqlParameter("@UserId", UserId),
                    new System.Data.SqlClient.SqlParameter("@Remark", Remark),
                };
                record = db.Database.SqlQuery<Receive>("EXEC meta.p_ApproveKeepRemart @BillflowIdStr,@UserId,@Remark ", paramList).FirstOrDefault();
            }
            return record;
        }
        public List<ReceiveBillProcess> GetBillProcess(int BillId)
        {
            List<ReceiveBillProcess> list = null;
            using (DBContext db = new DBContext())
            {
                System.Data.SqlClient.SqlParameter[] paramList = new System.Data.SqlClient.SqlParameter[] {
                    new System.Data.SqlClient.SqlParameter("@BillId", BillId),
                };
                list = db.Database.SqlQuery<ReceiveBillProcess>("EXEC meta.p_getBillProcess @BillId ", paramList).ToList();
            }
            return list;
        }
 
        public Receive GetMyApproved(string Code, int UserId, int pageIndex = 1, int pageSize = 5)
        {
            Receive receive = new Receive();
            try
            {
                using (DBContext db = new DBContext())
                {
                    System.Data.SqlClient.SqlParameter[] paramList = new System.Data.SqlClient.SqlParameter[] {
                        new System.Data.SqlClient.SqlParameter("@Code", Code),
                        new System.Data.SqlClient.SqlParameter("@UserId", UserId),
                        new System.Data.SqlClient.SqlParameter("@pageIndex", pageIndex),
                        new System.Data.SqlClient.SqlParameter("@pageSize", pageSize),
                        new System.Data.SqlClient.SqlParameter("@Total", 0),
                    };
                    int index = paramList.Length - 1;
                    paramList[index].Direction = ParameterDirection.Output;
                    receive.rows = db.Database.SqlQuery<ReceiveNeedDealt>("EXEC meta.p_myApproved @Code,@UserId,@pageIndex,@pageSize,@Total output ", paramList).ToList();
                    receive.total = int.Parse(paramList[index].Value.ToString());
                    receive.Code = 200;
                    receive.Message = "SUCCESS";
                }
            }
            catch (Exception ex)
            {
                receive.Code = 500;
                receive.Message = ex.Message;
            }
            return receive;
        }
    }
    public class WorkListModel : WorkList
    {
        public string BillCode { get; set; }
        public string BizDataIds { get; set; }
        public int ViewType { get; set; }
    }
}