username@email.com
2023-12-11 72e4a4d81cb1b9776ffb7287e0c5ed67592eda8b
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
using AutoMapper;
using DTO;
using DTO.Models;
using IServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using zhengcaioa.IService;
using zhengcaioa.Models;
 
namespace Services
{
    public class WfHistorieservice: IWfHistoryService
    {
        private readonly zhengcaioaContext _context;
        private readonly IMapper _mapper;
        public WfHistorieservice(zhengcaioaContext context, IMapper mapper)
        {
            _context = context;
            _mapper = mapper;
        }
 
        public ResultEntity save(WfHistoryDTO dto)
        {
            ResultEntity resultEntity = new ResultEntity();
            try
            {
                var model = _mapper.Map<WfHistory>(dto);
                if (String.IsNullOrEmpty(model.Id))
                {
                    model.Id = Guid.NewGuid().ToString();
                    _context.WfHistories.Add(model);
                }
                else
                {
                    var updateWfHistory = _context.WfHistories.Find(model.Id);
                    updateWfHistory.RunProcessId = model.RunProcessId;
                    updateWfHistory.SendUserId = model.SendUserId;
                    updateWfHistory.DeelUserId = model.DeelUserId;
                    updateWfHistory.Sendtime = model.Sendtime;
                    updateWfHistory.Resivetime = model.Resivetime;
                    updateWfHistory.Step = model.Step;
                    updateWfHistory.ChuliStatus = model.ChuliStatus;
                    updateWfHistory.Deelurl = model.Deelurl;
                    updateWfHistory.NeeddeelType = model.NeeddeelType;
                    updateWfHistory.Sort = model.Sort;
                    updateWfHistory.Content = model.Content;
 
 
                    updateWfHistory.RecStatus = model.RecStatus;
                    // updateWfHistory.Creater = WfHistory.Creater;
                    //updateWfHistory.Createtime = WfHistory.Createtime;
                    updateWfHistory.Modifier = model.Modifier;
                    updateWfHistory.Modifytime = model.Modifytime;
 
                }
 
                _context.SaveChanges();
                resultEntity.ReturnID = model.Id;
                resultEntity.Result = true;
            }
            catch (Exception ex)
            {
                resultEntity.Result = false;
                resultEntity.Message = "保存失败,请联系管理员";
 
            }
            return resultEntity;
        }
 
        public WfHistoryDTO Get(string id)
        {
            WfHistory entity = _context.WfHistories.Find(id);
            if (entity.RecStatus != "A")
            {
                entity = new WfHistory();
            }
 
            var WfHistoryDTO = _mapper.Map<WfHistoryDTO>(entity);
            return WfHistoryDTO;
        }
 
        public ResultDataEntity<WfHistoryDTO> SearchByPaging(WfHistoryDTOSearch searchEntity)
        {
 
 
 
            ResultDataEntity<WfHistoryDTO> data = new ResultDataEntity<WfHistoryDTO>();
            List<WfHistoryDTO> list = new List<WfHistoryDTO>();
 
 
 
 
            var listCode = (from a in _context.SysCodeDtls
                            join b in _context.SysCodes
                            on a.CodeId equals b.Id
                            where a.RecStatus == "A"
                                          && b.RecStatus == "A"
                            select new CodeDataEntity()
                            {
                                CodeId = b.Id,
                                CodeTable = b.CodeTable,
                                CodeField = b.CodeField,
                                CodeSn = a.CodeSn,
                                Comments = a.Comments,
                                Contents = a.Contents,
                                RecStatus = a.RecStatus,
                                Sort = a.Sort
                            }
                      );
            DateTime Applytimestart = DateTime.Now;
            DateTime Applytimeend = DateTime.Now;
            if (!string.IsNullOrWhiteSpace(searchEntity.Applytime))
            {
                string[] Applytimes = searchEntity.Applytime.Split("|");
                DateTime.TryParse(Applytimes[0], out Applytimestart);
                DateTime.TryParse(Applytimes[1], out Applytimeend);
                Applytimeend = Applytimeend.AddDays(1);
            }
 
            ///WfHistories
            var query = (from a in _context.WfHistories
 
 
 
 
 
                         join k in _context.WfRunProcesses.Where(x => x.RecStatus == "A")
                      on a.RunProcessId equals k.Id
 
                         join e in listCode.Where(x => x.CodeTable == "wf_run_process" && x.CodeField == "shenpi_status")
                        on k.ShenpiStatus equals e.CodeSn
                        into esssss
                         from eee in esssss.DefaultIfEmpty()
 
                         join f in listCode.Where(x => x.CodeTable == "wf_needdeel" && x.CodeField == "needdeel_type")
                    on a.NeeddeelType equals f.CodeSn
                    into fsssss
                         from fff in fsssss.DefaultIfEmpty()
 
                         join d in _context.WfApplytypes
                       on k.Applytiye equals d.Applyno
 
                         join b in _context.PltUsers
                        on k.Creater equals b.Id
 
 
                         join c in _context.HrDepts
                        on b.DeptId equals c.Id
 
 
                         where a.RecStatus == "A"
                          && (string.IsNullOrWhiteSpace(searchEntity.Applytime) || (k.Applytime >= Applytimestart && k.Applytime <= Applytimeend))
                          && (string.IsNullOrWhiteSpace(searchEntity.DeptId) || b.DeptId == searchEntity.DeptId.Trim())
                           && (string.IsNullOrWhiteSpace(searchEntity.ApplyUserName) || b.UserName.Contains(searchEntity.ApplyUserName.Trim()))
                            && (string.IsNullOrWhiteSpace(searchEntity.Applytiye) || k.Applytiye == searchEntity.Applytiye.Trim())
                             && (string.IsNullOrWhiteSpace(searchEntity.ShenpiStatus) || k.ShenpiStatus == searchEntity.ShenpiStatus.Trim())
                               && (string.IsNullOrWhiteSpace(searchEntity.RunProcessId) || a.RunProcessId == searchEntity.RunProcessId.Trim())
 
                                && (string.IsNullOrWhiteSpace(searchEntity.Applyno) || k.Applyno == searchEntity.Applyno.Trim())
                                 && (string.IsNullOrWhiteSpace(searchEntity.Creater) || a.DeelUserId == searchEntity.Creater.Trim())
 
                         select new WfHistoryDTO
                         {
                             Id = a.Id,
                             //DocType = a.DocType,
                             //ApplytimeName = a.Applytime.ToString("yyyy-MM-dd"),
                             //DocTypeName = ggg.DocName,
                             //DocDept = a.DocDept,
                             //DocDeptName = kkk.DeptName,
                             //DocNo = a.DocNo,
                             //DocTitle = a.DocTitle,
                             //// DocContent = a.DocContent,
                             //DocZtc = a.DocZtc,
                             //DocCsdw = a.DocCsdw,
                             //Applytime = a.Applytime,
                             //PrintStatus = a.PrintStatus,
                             //PrintStatusName = eee.Comments,
                             //Printtimes = a.Printtimes ?? 0,
 
                             ApplytimeName = k.Applytime.Value.ToString("yyyy-MM-dd"),
                             Applyno = k.Applyno,
                             CreaterName = b.UserName,
                             DeptName = c.DeptName,
                             Applytiye = d.Applytiye,
                             Content = k.Content,
                             ShenpiStatusName = eee.Comments,
                             Resivetime = a.Resivetime,
                             NeeddeelType = a.NeeddeelType,
                             NeeddeelTypeName = fff.Comments,
                             Contentyijian = a.Content,
                             Sort = a.Sort,
                             Deelurl = a.Deelurl,
                             Creater = a.Creater,
                             Createtime = a.Createtime,
                             Step = a.Step,
                             RecStatus = a.RecStatus,
                             Modifier = a.Modifier,
                             Modifytime = a.Modifytime,
 
                         }
                ).OrderByDescending(x=>x.Applyno).ThenBy(x => x.Sort).ThenByDescending(x=>x.Resivetime).ToList();
 
 
 
            //if (searchEntity.totalrows == 0)
                searchEntity.totalrows = query.Count();
            var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
            data.LoadData(searchEntity, lianlist);
            return data;
        }
 
        public ResultEntity ModifyStatus(string id, string userid)
        {
 
            ResultEntity result = new ResultEntity();
            result.Result = true;
 
            var model = _context.WfHistories.Find(id);
            if (model != null)
            {
                model.RecStatus = "D";
                model.Modifier = userid;
                model.Modifytime = DateTime.Now;
                _context.SaveChanges();
            }
 
            return result;
        }
 
 
 
        /// <summary>
        /// 获取所有有效流程类型
        /// </summary>
        /// <returns></returns>
        public List<WfHistoryDTO> GetList(string RunProcessId = "")
        {
 
 
            var listRole = _context.WfHistories.Where(r => r.RecStatus == "A").OrderBy(x=>x.Sort).ToList();
            if (!string.IsNullOrEmpty(RunProcessId))
            {
                listRole = listRole.Where(x => x.RunProcessId == RunProcessId).ToList();
            }
 
            var list = _mapper.Map<List<WfHistoryDTO>>(listRole);
            return list;
        }
        /// <summary>
        /// 查询历史审批意见
        /// </summary>
        /// <returns></returns>
        public List<WfHistoryDTO> GetListshenpi(string RunProcessId)
        {
 
 
            var listRole = (from a in _context.WfHistories.Where(x => x.RecStatus == "A" && x.NeeddeelType =="1" && x.ChuliStatus != "0" && x.RunProcessId == RunProcessId)
 
                            join b in _context.PltUsers
                            on a.DeelUserId  equals b.Id
 
 
                            select new WfHistoryDTO
                            {
                                RunProcessId = a.RunProcessId,
                                SendUserId = a.SendUserId,
                                DeelUserId = a.DeelUserId,
                                Sendtime = a.Sendtime,
                                Resivetime = a.Resivetime,
                                Step = a.Step,
                                ChuliStatus = a.ChuliStatus,
                                Deelurl = a.Deelurl,
                                NeeddeelType = a.NeeddeelType,
                                Sort = a.Sort,
                                Content = a.Content,
 
 
                                RecStatus = a.RecStatus,
                                Creater = a.Creater,
                                Createtime = a.Createtime,
                                Modifier = a.Modifier,
                                Modifytime = a.Modifytime,
                                ChuliStatusName = a.Step == "提交"? "提交" : a.ChuliStatus == "2" ? "同意" : "拒绝",
                                DeelUserIdName = b.UserName,
                                ModifytimeName = a.Modifytime.ToString("yyyy-MM-dd HH:mm:ss"),
                            }
                             ).OrderBy(x => x.Modifytime).ToList();
 
 
 
            //    _context.WfHistories.Where(r => r.RecStatus == "A").OrderBy(x => x.Sort).ToList();
            //if (!string.IsNullOrEmpty(RunProcessId))
            //{
            //    listRole = listRole.Where(x => x.RunProcessId == RunProcessId).ToList();
            //}
 
 
 
 
            return listRole;
        }
 
 
        public ResultDataEntity<WfHistoryDTO> SearchByPagingGuanLi(WfHistoryDTOSearch searchEntity)
        {
 
 
 
            ResultDataEntity<WfHistoryDTO> data = new ResultDataEntity<WfHistoryDTO>();
            List<WfHistoryDTO> list = new List<WfHistoryDTO>();
 
 
 
 
            var listCode = (from a in _context.SysCodeDtls
                            join b in _context.SysCodes
                            on a.CodeId equals b.Id
                            where a.RecStatus == "A"
                                          && b.RecStatus == "A"
                            select new CodeDataEntity()
                            {
                                CodeId = b.Id,
                                CodeTable = b.CodeTable,
                                CodeField = b.CodeField,
                                CodeSn = a.CodeSn,
                                Comments = a.Comments,
                                Contents = a.Contents,
                                RecStatus = a.RecStatus,
                                Sort = a.Sort
                            }
                      );
            DateTime Applytimestart = DateTime.Now;
            DateTime Applytimeend = DateTime.Now;
            if (!string.IsNullOrWhiteSpace(searchEntity.Applytime))
            {
                string[] Applytimes = searchEntity.Applytime.Split("|");
                DateTime.TryParse(Applytimes[0], out Applytimestart);
                DateTime.TryParse(Applytimes[1], out Applytimeend);
                Applytimeend = Applytimeend.AddDays(1);
            }
 
            ///WfHistories
            var query = (from k in _context.WfRunProcesses
 
 
 
 
 
                         join a in _context.WfHistories
                      on k.Id equals a.RunProcessId
                        into asssss
                         from aaa in asssss.DefaultIfEmpty()
 
                         join e in listCode.Where(x => x.CodeTable == "wf_run_process" && x.CodeField == "shenpi_status")
                        on k.ShenpiStatus equals e.CodeSn
                        into esssss
                         from eee in esssss.DefaultIfEmpty()
 
                    //     join f in listCode.Where(x => x.CodeTable == "wf_needdeel" && x.CodeField == "needdeel_type")
                    //on a.NeeddeelType equals f.CodeSn
                    //into fsssss
                    //     from fff in fsssss.DefaultIfEmpty()
 
                         join d in _context.WfApplytypes
                       on k.Applytiye equals d.Applyno
 
                         join b in _context.PltUsers
                        on k.Creater equals b.Id
 
 
                         join c in _context.HrDepts
                        on b.DeptId equals c.Id
 
 
                         where k.RecStatus == "A"
                          && (string.IsNullOrWhiteSpace(searchEntity.Applytime) || (k.Applytime >= Applytimestart && k.Applytime <= Applytimeend))
                          && (string.IsNullOrWhiteSpace(searchEntity.DeptId) || b.DeptId == searchEntity.DeptId.Trim())
                           && (string.IsNullOrWhiteSpace(searchEntity.ApplyUserName) || b.UserName.Contains(searchEntity.ApplyUserName.Trim()))
                            && (string.IsNullOrWhiteSpace(searchEntity.Applytiye) || k.Applytiye == searchEntity.Applytiye.Trim())
                             && (string.IsNullOrWhiteSpace(searchEntity.ShenpiStatus) || k.ShenpiStatus == searchEntity.ShenpiStatus.Trim())
                               && (string.IsNullOrWhiteSpace(searchEntity.RunProcessId) || k.Id == searchEntity.RunProcessId.Trim())
 
                                && (string.IsNullOrWhiteSpace(searchEntity.Applyno) || k.Applyno == searchEntity.Applyno.Trim())
                                 && (string.IsNullOrWhiteSpace(searchEntity.Creater) || k.Creater == searchEntity.Creater.Trim())
 
                         select new WfHistoryDTO
                         {
                             Id = k.Id,
                              
 
                             ApplytimeName = k.Applytime.Value.ToString("yyyy-MM-dd"),
                             Applyno = k.Applyno,
                             CreaterName = b.UserName,
                             DeptName = c.DeptName,
                             Applytiye = d.Applytiye,
                             Content = k.Content,
                             ShenpiStatusName = eee.Comments,
                              
                             Deelurl = aaa.Deelurl,
                             Creater = k.Creater,
                             Createtime = k.Createtime,
                             Step = k.Step,
                             RecStatus = k.RecStatus,
                             Modifier = k.Modifier,
                             Modifytime = k.Modifytime,
 
                         }
                ).Distinct().ToList().OrderByDescending(x => x.Applyno);
 
 
 
            //if (searchEntity.totalrows == 0)
            searchEntity.totalrows = query.Count();
            var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
            data.LoadData(searchEntity, lianlist);
            return data;
        }
 
    }
}