username@email.com
2024-09-09 cc170291673472d3cda8d7ea77f6bd3a3b5dbb83
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 202403/02   
 *        Description: 暂无
 ***********************************************************************/
 
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.Expression;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Filter;
using CoreCms.Net.Loging;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Helper;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Web.Admin.Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using NPOI.HSSF.UserModel;
using SqlSugar;
 
namespace CoreCms.Net.Web.Admin.Controllers
{
    /// <summary>
    /// 操作日志表
    ///</summary>
    [Description("操作日志表")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    [RequiredErrorForAdmin]
    [Authorize(Permissions.Name)]
    public class SysOperRecordController : ControllerBase
    {
        private readonly IWebHostEnvironment _webHostEnvironment;
        private readonly ISysOperRecordServices _SysOperRecordServices;
 
        /// <summary>
        /// 构造函数
        ///</summary>
        public SysOperRecordController(IWebHostEnvironment webHostEnvironment
            , ISysOperRecordServices SysOperRecordServices
            )
        {
            _webHostEnvironment = webHostEnvironment;
            _SysOperRecordServices = SysOperRecordServices;
        }
 
        #region 获取列表============================================================
        // POST: Api/SysOperRecord/GetPageList
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("获取列表")]
        public async Task<AdminUiCallBack> GetPageList()
        {
            var jm = new AdminUiCallBack();
            var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
            var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
            var where = PredicateBuilder.True<SysOperRecord>();
            //获取排序字段
            var orderField = Request.Form["orderField"].FirstOrDefault();
 
            Expression<Func<SysOperRecord, object>> orderEx = orderField switch
            {
                "id" => p => p.id,
                "userId" => p => p.userId,
                "userName" => p => p.userName,
                "model" => p => p.model,
                "description" => p => p.description,
                "url" => p => p.url,
                "requestMethod" => p => p.requestMethod,
                "operMethod" => p => p.operMethod,
                "param" => p => p.param,
                "result" => p => p.result,
                "ip" => p => p.ip,
                "spendTime" => p => p.spendTime,
                "state" => p => p.state,
                "createTime" => p => p.createTime,
                _ => p => p.id
            };
 
            //设置排序方式
            var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
            var orderBy = orderDirection switch
            {
                "asc" => OrderByType.Asc,
                "desc" => OrderByType.Desc,
                _ => OrderByType.Desc
            };
            //查询筛选
 
            //主键 int
            var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
            if (id > 0)
            {
                where = where.And(p => p.id == id);
            }
            //用户id int
            var userId = Request.Form["userId"].FirstOrDefault().ObjectToInt(0);
            if (userId > 0)
            {
                where = where.And(p => p.userId == userId);
            }
            //用户名 nvarchar
            var userName = Request.Form["userName"].FirstOrDefault();
            if (!string.IsNullOrEmpty(userName))
            {
                where = where.And(p => p.userName.Contains(userName));
            }
            //操作模块 nvarchar
            var model = Request.Form["model"].FirstOrDefault();
            if (!string.IsNullOrEmpty(model))
            {
                where = where.And(p => p.model.Contains(model));
            }
            //操作方法 nvarchar
            var description = Request.Form["description"].FirstOrDefault();
            if (!string.IsNullOrEmpty(description))
            {
                where = where.And(p => p.description.Contains(description));
            }
            //请求地址 nvarchar
            var url = Request.Form["url"].FirstOrDefault();
            if (!string.IsNullOrEmpty(url))
            {
                where = where.And(p => p.url.Contains(url));
            }
            //请求方式 nvarchar
            var requestMethod = Request.Form["requestMethod"].FirstOrDefault();
            if (!string.IsNullOrEmpty(requestMethod))
            {
                where = where.And(p => p.requestMethod.Contains(requestMethod));
            }
            //调用方法 nvarchar
            var operMethod = Request.Form["operMethod"].FirstOrDefault();
            if (!string.IsNullOrEmpty(operMethod))
            {
                where = where.And(p => p.operMethod.Contains(operMethod));
            }
            //请求参数 nvarchar
            var param = Request.Form["param"].FirstOrDefault();
            if (!string.IsNullOrEmpty(param))
            {
                where = where.And(p => p.param.Contains(param));
            }
            //返回结果 nvarchar
            var result = Request.Form["result"].FirstOrDefault();
            if (!string.IsNullOrEmpty(result))
            {
                where = where.And(p => p.result.Contains(result));
            }
            //ip地址 nvarchar
            var ip = Request.Form["ip"].FirstOrDefault();
            if (!string.IsNullOrEmpty(ip))
            {
                where = where.And(p => p.ip.Contains(ip));
            }
            //请求耗时,单位毫秒 nvarchar
            var spendTime = Request.Form["spendTime"].FirstOrDefault();
            if (!string.IsNullOrEmpty(spendTime))
            {
                where = where.And(p => p.spendTime.Contains(spendTime));
            }
            //状态,0成功,1异常 int
            var state = Request.Form["state"].FirstOrDefault().ObjectToInt(0);
            if (state > 0)
            {
                where = where.And(p => p.state == state);
            }
            //登录时间 datetime
            var createTime = Request.Form["createTime"].FirstOrDefault();
            if (!string.IsNullOrEmpty(createTime))
            {
                if (createTime.Contains("到"))
                {
                    var dts = createTime.Split("到");
                    var dtStart = dts[0].Trim().ObjectToDate();
                    where = where.And(p => p.createTime > dtStart);
                    var dtEnd = dts[1].Trim().ObjectToDate();
                    where = where.And(p => p.createTime < dtEnd);
                }
                else
                {
                    var dt = createTime.ObjectToDate();
                    where = where.And(p => p.createTime > dt);
                }
            }
            //获取数据
            var list = await _SysOperRecordServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true);
            //返回数据
            jm.data = list;
            jm.code = 0;
            jm.count = list.TotalCount;
            jm.msg = "数据调用成功!";
            return jm;
        }
        #endregion
 
        #region 首页数据============================================================
        // POST: Api/SysOperRecord/GetIndex
        /// <summary>
        /// 首页数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("首页数据")]
        public AdminUiCallBack GetIndex()
        {
            //返回数据
            var jm = new AdminUiCallBack { code = 0 };
            return jm;
        }
        #endregion
 
        #region 预览数据============================================================
        // POST: Api/SysOperRecord/GetDetails/10
        /// <summary>
        /// 预览数据
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("预览数据")]
        public async Task<AdminUiCallBack> GetDetails([FromBody] FMIntId entity)
        {
            var jm = new AdminUiCallBack();
 
            var model = await _SysOperRecordServices.QueryByIdAsync(entity.id, false);
            if (model == null)
            {
                jm.msg = "不存在此信息";
                return jm;
            }
            jm.code = 0;
            jm.data = model;
 
            return jm;
        }
        #endregion
 
        #region 选择导出============================================================
        // POST: Api/SysOperRecord/SelectExportExcel/10
        /// <summary>
        /// 选择导出
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("选择导出")]
        public async Task<AdminUiCallBack> SelectExportExcel([FromBody] FMArrayIntIds entity)
        {
            var jm = new AdminUiCallBack();
 
            //创建Excel文件的对象
            var book = new HSSFWorkbook();
            //添加一个sheet
            var mySheet = book.CreateSheet("Sheet1");
            //获取list数据
            var listModel = await _SysOperRecordServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id, OrderByType.Asc, true);
            //给sheet1添加第一行的头部标题
            var headerRow = mySheet.CreateRow(0);
            var headerStyle = ExcelHelper.GetHeaderStyle(book);
 
            var cell0 = headerRow.CreateCell(0);
            cell0.SetCellValue("主键");
            cell0.CellStyle = headerStyle;
            mySheet.SetColumnWidth(0, 10 * 256);
 
            var cell1 = headerRow.CreateCell(1);
            cell1.SetCellValue("用户id");
            cell1.CellStyle = headerStyle;
            mySheet.SetColumnWidth(1, 10 * 256);
 
            var cell2 = headerRow.CreateCell(2);
            cell2.SetCellValue("用户名");
            cell2.CellStyle = headerStyle;
            mySheet.SetColumnWidth(2, 10 * 256);
 
            var cell3 = headerRow.CreateCell(3);
            cell3.SetCellValue("操作模块");
            cell3.CellStyle = headerStyle;
            mySheet.SetColumnWidth(3, 10 * 256);
 
            var cell4 = headerRow.CreateCell(4);
            cell4.SetCellValue("操作方法");
            cell4.CellStyle = headerStyle;
            mySheet.SetColumnWidth(4, 10 * 256);
 
            var cell5 = headerRow.CreateCell(5);
            cell5.SetCellValue("请求地址");
            cell5.CellStyle = headerStyle;
            mySheet.SetColumnWidth(5, 10 * 256);
 
            var cell6 = headerRow.CreateCell(6);
            cell6.SetCellValue("请求方式");
            cell6.CellStyle = headerStyle;
            mySheet.SetColumnWidth(6, 10 * 256);
 
            var cell7 = headerRow.CreateCell(7);
            cell7.SetCellValue("调用方法");
            cell7.CellStyle = headerStyle;
            mySheet.SetColumnWidth(7, 10 * 256);
 
            var cell8 = headerRow.CreateCell(8);
            cell8.SetCellValue("请求参数");
            cell8.CellStyle = headerStyle;
            mySheet.SetColumnWidth(8, 10 * 256);
 
            var cell9 = headerRow.CreateCell(9);
            cell9.SetCellValue("返回结果");
            cell9.CellStyle = headerStyle;
            mySheet.SetColumnWidth(9, 10 * 256);
 
            var cell10 = headerRow.CreateCell(10);
            cell10.SetCellValue("ip地址");
            cell10.CellStyle = headerStyle;
            mySheet.SetColumnWidth(10, 10 * 256);
 
            var cell11 = headerRow.CreateCell(11);
            cell11.SetCellValue("请求耗时,单位毫秒");
            cell11.CellStyle = headerStyle;
            mySheet.SetColumnWidth(11, 10 * 256);
 
            var cell12 = headerRow.CreateCell(12);
            cell12.SetCellValue("状态,0成功,1异常");
            cell12.CellStyle = headerStyle;
            mySheet.SetColumnWidth(12, 10 * 256);
 
            var cell13 = headerRow.CreateCell(13);
            cell13.SetCellValue("登录时间");
            cell13.CellStyle = headerStyle;
            mySheet.SetColumnWidth(13, 10 * 256);
 
            headerRow.Height = 30 * 20;
            var commonCellStyle = ExcelHelper.GetCommonStyle(book);
 
            //将数据逐步写入sheet1各个行
            for (var i = 0; i < listModel.Count; i++)
            {
                var rowTemp = mySheet.CreateRow(i + 1);
 
                var rowTemp0 = rowTemp.CreateCell(0);
                rowTemp0.SetCellValue(listModel[i].id.ToString());
                rowTemp0.CellStyle = commonCellStyle;
 
                var rowTemp1 = rowTemp.CreateCell(1);
                rowTemp1.SetCellValue(listModel[i].userId.ToString());
                rowTemp1.CellStyle = commonCellStyle;
 
                var rowTemp2 = rowTemp.CreateCell(2);
                rowTemp2.SetCellValue(listModel[i].userName.ToString());
                rowTemp2.CellStyle = commonCellStyle;
 
                var rowTemp3 = rowTemp.CreateCell(3);
                rowTemp3.SetCellValue(listModel[i].model.ToString());
                rowTemp3.CellStyle = commonCellStyle;
 
                var rowTemp4 = rowTemp.CreateCell(4);
                rowTemp4.SetCellValue(listModel[i].description.ToString());
                rowTemp4.CellStyle = commonCellStyle;
 
                var rowTemp5 = rowTemp.CreateCell(5);
                rowTemp5.SetCellValue(listModel[i].url.ToString());
                rowTemp5.CellStyle = commonCellStyle;
 
                var rowTemp6 = rowTemp.CreateCell(6);
                rowTemp6.SetCellValue(listModel[i].requestMethod.ToString());
                rowTemp6.CellStyle = commonCellStyle;
 
                var rowTemp7 = rowTemp.CreateCell(7);
                rowTemp7.SetCellValue(listModel[i].operMethod.ToString());
                rowTemp7.CellStyle = commonCellStyle;
 
                var rowTemp8 = rowTemp.CreateCell(8);
                rowTemp8.SetCellValue(listModel[i].param.ToString());
                rowTemp8.CellStyle = commonCellStyle;
 
                var rowTemp9 = rowTemp.CreateCell(9);
                rowTemp9.SetCellValue(listModel[i].result.ToString());
                rowTemp9.CellStyle = commonCellStyle;
 
                var rowTemp10 = rowTemp.CreateCell(10);
                rowTemp10.SetCellValue(listModel[i].ip.ToString());
                rowTemp10.CellStyle = commonCellStyle;
 
                var rowTemp11 = rowTemp.CreateCell(11);
                rowTemp11.SetCellValue(listModel[i].spendTime.ToString());
                rowTemp11.CellStyle = commonCellStyle;
 
                var rowTemp12 = rowTemp.CreateCell(12);
                rowTemp12.SetCellValue(listModel[i].state.ToString());
                rowTemp12.CellStyle = commonCellStyle;
 
                var rowTemp13 = rowTemp.CreateCell(13);
                rowTemp13.SetCellValue(listModel[i].createTime.ToString());
                rowTemp13.CellStyle = commonCellStyle;
 
            }
            // 导出excel
            string webRootPath = _webHostEnvironment.WebRootPath;
            string tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-SysOperRecord导出(选择结果).xls";
            string filePath = webRootPath + tpath;
            DirectoryInfo di = new DirectoryInfo(filePath);
            if (!di.Exists)
            {
                di.Create();
            }
            FileStream fileHssf = new FileStream(filePath + fileName, FileMode.Create);
            book.Write(fileHssf);
            fileHssf.Close();
 
            jm.code = 0;
            jm.msg = GlobalConstVars.ExcelExportSuccess;
            jm.data = tpath + fileName;
 
            return jm;
        }
        #endregion
 
        #region 查询导出============================================================
        // POST: Api/SysOperRecord/QueryExportExcel/10
        /// <summary>
        /// 查询导出
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("查询导出")]
        public async Task<AdminUiCallBack> QueryExportExcel()
        {
            var jm = new AdminUiCallBack();
 
            var where = PredicateBuilder.True<SysOperRecord>();
            //查询筛选
 
            //主键 int
            var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
            if (id > 0)
            {
                where = where.And(p => p.id == id);
            }
            //用户id int
            var userId = Request.Form["userId"].FirstOrDefault().ObjectToInt(0);
            if (userId > 0)
            {
                where = where.And(p => p.userId == userId);
            }
            //用户名 nvarchar
            var userName = Request.Form["userName"].FirstOrDefault();
            if (!string.IsNullOrEmpty(userName))
            {
                where = where.And(p => p.userName.Contains(userName));
            }
            //操作模块 nvarchar
            var model = Request.Form["model"].FirstOrDefault();
            if (!string.IsNullOrEmpty(model))
            {
                where = where.And(p => p.model.Contains(model));
            }
            //操作方法 nvarchar
            var description = Request.Form["description"].FirstOrDefault();
            if (!string.IsNullOrEmpty(description))
            {
                where = where.And(p => p.description.Contains(description));
            }
            //请求地址 nvarchar
            var url = Request.Form["url"].FirstOrDefault();
            if (!string.IsNullOrEmpty(url))
            {
                where = where.And(p => p.url.Contains(url));
            }
            //请求方式 nvarchar
            var requestMethod = Request.Form["requestMethod"].FirstOrDefault();
            if (!string.IsNullOrEmpty(requestMethod))
            {
                where = where.And(p => p.requestMethod.Contains(requestMethod));
            }
            //调用方法 nvarchar
            var operMethod = Request.Form["operMethod"].FirstOrDefault();
            if (!string.IsNullOrEmpty(operMethod))
            {
                where = where.And(p => p.operMethod.Contains(operMethod));
            }
            //请求参数 nvarchar
            var param = Request.Form["param"].FirstOrDefault();
            if (!string.IsNullOrEmpty(param))
            {
                where = where.And(p => p.param.Contains(param));
            }
            //返回结果 nvarchar
            var result = Request.Form["result"].FirstOrDefault();
            if (!string.IsNullOrEmpty(result))
            {
                where = where.And(p => p.result.Contains(result));
            }
            //ip地址 nvarchar
            var ip = Request.Form["ip"].FirstOrDefault();
            if (!string.IsNullOrEmpty(ip))
            {
                where = where.And(p => p.ip.Contains(ip));
            }
            //请求耗时,单位毫秒 nvarchar
            var spendTime = Request.Form["spendTime"].FirstOrDefault();
            if (!string.IsNullOrEmpty(spendTime))
            {
                where = where.And(p => p.spendTime.Contains(spendTime));
            }
            //状态,0成功,1异常 int
            var state = Request.Form["state"].FirstOrDefault().ObjectToInt(0);
            if (state > 0)
            {
                where = where.And(p => p.state == state);
            }
            //登录时间 datetime
            var createTime = Request.Form["createTime"].FirstOrDefault();
            if (!string.IsNullOrEmpty(createTime))
            {
                var dt = createTime.ObjectToDate();
                where = where.And(p => p.createTime > dt);
            }
            //获取数据
            //创建Excel文件的对象
            var book = new HSSFWorkbook();
            //添加一个sheet
            var mySheet = book.CreateSheet("Sheet1");
            //获取list数据
            var listModel = await _SysOperRecordServices.QueryListByClauseAsync(where, p => p.id, OrderByType.Asc, true);
            //给sheet1添加第一行的头部标题
            var headerRow = mySheet.CreateRow(0);
            var headerStyle = ExcelHelper.GetHeaderStyle(book);
 
            var cell0 = headerRow.CreateCell(0);
            cell0.SetCellValue("主键");
            cell0.CellStyle = headerStyle;
            mySheet.SetColumnWidth(0, 10 * 256);
 
            var cell1 = headerRow.CreateCell(1);
            cell1.SetCellValue("用户id");
            cell1.CellStyle = headerStyle;
            mySheet.SetColumnWidth(1, 10 * 256);
 
            var cell2 = headerRow.CreateCell(2);
            cell2.SetCellValue("用户名");
            cell2.CellStyle = headerStyle;
            mySheet.SetColumnWidth(2, 10 * 256);
 
            var cell3 = headerRow.CreateCell(3);
            cell3.SetCellValue("操作模块");
            cell3.CellStyle = headerStyle;
            mySheet.SetColumnWidth(3, 10 * 256);
 
            var cell4 = headerRow.CreateCell(4);
            cell4.SetCellValue("操作方法");
            cell4.CellStyle = headerStyle;
            mySheet.SetColumnWidth(4, 10 * 256);
 
            var cell5 = headerRow.CreateCell(5);
            cell5.SetCellValue("请求地址");
            cell5.CellStyle = headerStyle;
            mySheet.SetColumnWidth(5, 10 * 256);
 
            var cell6 = headerRow.CreateCell(6);
            cell6.SetCellValue("请求方式");
            cell6.CellStyle = headerStyle;
            mySheet.SetColumnWidth(6, 10 * 256);
 
            var cell7 = headerRow.CreateCell(7);
            cell7.SetCellValue("调用方法");
            cell7.CellStyle = headerStyle;
            mySheet.SetColumnWidth(7, 10 * 256);
 
            var cell8 = headerRow.CreateCell(8);
            cell8.SetCellValue("请求参数");
            cell8.CellStyle = headerStyle;
            mySheet.SetColumnWidth(8, 10 * 256);
 
            var cell9 = headerRow.CreateCell(9);
            cell9.SetCellValue("返回结果");
            cell9.CellStyle = headerStyle;
            mySheet.SetColumnWidth(9, 10 * 256);
 
            var cell10 = headerRow.CreateCell(10);
            cell10.SetCellValue("ip地址");
            cell10.CellStyle = headerStyle;
            mySheet.SetColumnWidth(10, 10 * 256);
 
            var cell11 = headerRow.CreateCell(11);
            cell11.SetCellValue("请求耗时,单位毫秒");
            cell11.CellStyle = headerStyle;
            mySheet.SetColumnWidth(11, 10 * 256);
 
            var cell12 = headerRow.CreateCell(12);
            cell12.SetCellValue("状态,0成功,1异常");
            cell12.CellStyle = headerStyle;
            mySheet.SetColumnWidth(12, 10 * 256);
 
            var cell13 = headerRow.CreateCell(13);
            cell13.SetCellValue("登录时间");
            cell13.CellStyle = headerStyle;
            mySheet.SetColumnWidth(13, 10 * 256);
 
 
            headerRow.Height = 30 * 20;
            var commonCellStyle = ExcelHelper.GetCommonStyle(book);
 
            //将数据逐步写入sheet1各个行
            for (var i = 0; i < listModel.Count; i++)
            {
                var rowTemp = mySheet.CreateRow(i + 1);
 
 
                var rowTemp0 = rowTemp.CreateCell(0);
                rowTemp0.SetCellValue(listModel[i].id.ToString());
                rowTemp0.CellStyle = commonCellStyle;
 
 
 
                var rowTemp1 = rowTemp.CreateCell(1);
                rowTemp1.SetCellValue(listModel[i].userId.ToString());
                rowTemp1.CellStyle = commonCellStyle;
 
 
 
                var rowTemp2 = rowTemp.CreateCell(2);
                rowTemp2.SetCellValue(listModel[i].userName.ToString());
                rowTemp2.CellStyle = commonCellStyle;
 
 
 
                var rowTemp3 = rowTemp.CreateCell(3);
                rowTemp3.SetCellValue(listModel[i].model.ToString());
                rowTemp3.CellStyle = commonCellStyle;
 
 
 
                var rowTemp4 = rowTemp.CreateCell(4);
                rowTemp4.SetCellValue(listModel[i].description.ToString());
                rowTemp4.CellStyle = commonCellStyle;
 
 
 
                var rowTemp5 = rowTemp.CreateCell(5);
                rowTemp5.SetCellValue(listModel[i].url.ToString());
                rowTemp5.CellStyle = commonCellStyle;
 
 
 
                var rowTemp6 = rowTemp.CreateCell(6);
                rowTemp6.SetCellValue(listModel[i].requestMethod.ToString());
                rowTemp6.CellStyle = commonCellStyle;
 
 
 
                var rowTemp7 = rowTemp.CreateCell(7);
                rowTemp7.SetCellValue(listModel[i].operMethod.ToString());
                rowTemp7.CellStyle = commonCellStyle;
 
 
 
                var rowTemp8 = rowTemp.CreateCell(8);
                rowTemp8.SetCellValue(listModel[i].param.ToString());
                rowTemp8.CellStyle = commonCellStyle;
 
 
 
                var rowTemp9 = rowTemp.CreateCell(9);
                rowTemp9.SetCellValue(listModel[i].result.ToString());
                rowTemp9.CellStyle = commonCellStyle;
 
 
 
                var rowTemp10 = rowTemp.CreateCell(10);
                rowTemp10.SetCellValue(listModel[i].ip.ToString());
                rowTemp10.CellStyle = commonCellStyle;
 
 
 
                var rowTemp11 = rowTemp.CreateCell(11);
                rowTemp11.SetCellValue(listModel[i].spendTime.ToString());
                rowTemp11.CellStyle = commonCellStyle;
 
 
 
                var rowTemp12 = rowTemp.CreateCell(12);
                rowTemp12.SetCellValue(listModel[i].state.ToString());
                rowTemp12.CellStyle = commonCellStyle;
 
 
 
                var rowTemp13 = rowTemp.CreateCell(13);
                rowTemp13.SetCellValue(listModel[i].createTime.ToString());
                rowTemp13.CellStyle = commonCellStyle;
 
 
            }
            // 写入到excel
            string webRootPath = _webHostEnvironment.WebRootPath;
            string tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
            string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-SysOperRecord导出(查询结果).xls";
            string filePath = webRootPath + tpath;
            DirectoryInfo di = new DirectoryInfo(filePath);
            if (!di.Exists)
            {
                di.Create();
            }
            FileStream fileHssf = new FileStream(filePath + fileName, FileMode.Create);
            book.Write(fileHssf);
            fileHssf.Close();
 
            jm.code = 0;
            jm.msg = GlobalConstVars.ExcelExportSuccess;
            jm.data = tpath + fileName;
 
            return jm;
        }
        #endregion
 
 
 
    }
}