|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
using System;
|
|
2
|
2
|
using System.Collections.Generic;
|
|
3
|
3
|
using System.Linq;
|
|
|
4
|
+using System.Reflection;
|
|
4
|
5
|
using System.Security.Claims;
|
|
5
|
6
|
using System.Threading.Tasks;
|
|
6
|
7
|
using MadRunFabric.Common;
|
|
|
@@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Mvc;
|
|
10
|
11
|
using Microsoft.Extensions.Configuration;
|
|
11
|
12
|
using Microsoft.Extensions.Logging;
|
|
12
|
13
|
using MongoDB.Driver;
|
|
|
14
|
+using NPOI.SS.Formula.Functions;
|
|
13
|
15
|
using SignTokenApi.IRepositories;
|
|
14
|
16
|
using SignTokenApi.Model.Dto;
|
|
15
|
17
|
using SignTokenApi.Model.Input;
|
|
|
@@ -177,7 +179,7 @@ namespace SignTokenApi.Controllers
|
|
177
|
179
|
model.birthday = input.birthday;
|
|
178
|
180
|
model.call_type = input.call_type;
|
|
179
|
181
|
model.delete_flag = false;
|
|
180
|
|
- //model.dept_id = input.dept_id;
|
|
|
182
|
+ model.dept_id = input.dept_id;
|
|
181
|
183
|
model.extensionnumber = input.extensionnumber;
|
|
182
|
184
|
model.group = input.group;
|
|
183
|
185
|
model.groupid = input.groupid;
|
|
|
@@ -559,5 +561,82 @@ namespace SignTokenApi.Controllers
|
|
559
|
561
|
|
|
560
|
562
|
return Success("根据条件获取坐席数据成功", agentlist);
|
|
561
|
563
|
}
|
|
|
564
|
+
|
|
|
565
|
+ /// <summary>
|
|
|
566
|
+ /// 上传文件并将设备信息导入数据库
|
|
|
567
|
+ /// </summary>
|
|
|
568
|
+ /// <returns></returns>
|
|
|
569
|
+ [HttpPost("importexcel")]
|
|
|
570
|
+ public async Task<IActionResult> ImportExcel(int headrow = 0)
|
|
|
571
|
+ {
|
|
|
572
|
+ string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
|
|
|
573
|
+
|
|
|
574
|
+ Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
|
|
|
575
|
+ if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
|
|
|
576
|
+ return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
|
|
|
577
|
+
|
|
|
578
|
+ NPOIHelper npoi = new NPOIHelper();
|
|
|
579
|
+ var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
|
|
|
580
|
+ int num = dtExcel.Rows.Count;
|
|
|
581
|
+ var cols = dtExcel.Columns;
|
|
|
582
|
+ int colnum = cols.Count;
|
|
|
583
|
+
|
|
|
584
|
+ string dbkeys = _configuration["upload:dbkeys"].ToString();
|
|
|
585
|
+ string[] dbcols = dbkeys.Split(",");
|
|
|
586
|
+ string errmsg = string.Empty;
|
|
|
587
|
+
|
|
|
588
|
+ if (num > 0)
|
|
|
589
|
+ {
|
|
|
590
|
+ int index = 1;
|
|
|
591
|
+ foreach (System.Data.DataRow dr in dtExcel.Rows)
|
|
|
592
|
+ {
|
|
|
593
|
+ Sys_User_Account model = new Sys_User_Account();
|
|
|
594
|
+
|
|
|
595
|
+ model.create_time = DateTime.Now;
|
|
|
596
|
+ model.create_user = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
|
|
|
597
|
+ model.lock_flag = true;//导入禁用,需要重新编辑
|
|
|
598
|
+ model.dept_id = "import";
|
|
|
599
|
+ var dbcolslist = dbcols.ToList();
|
|
|
600
|
+
|
|
|
601
|
+ Type t = model.GetType();
|
|
|
602
|
+ PropertyInfo[] PropertyList = t.GetProperties();
|
|
|
603
|
+
|
|
|
604
|
+ foreach (PropertyInfo item in PropertyList)
|
|
|
605
|
+ {
|
|
|
606
|
+ if (dbcolslist.Contains(item.Name))
|
|
|
607
|
+ {
|
|
|
608
|
+ object v = Convert.ChangeType(dr[dbcolslist.IndexOf(item.Name)].ToString(), item.PropertyType);
|
|
|
609
|
+ item.SetValue(model, v, null);
|
|
|
610
|
+ }
|
|
|
611
|
+ }
|
|
|
612
|
+
|
|
|
613
|
+ bool b = await _sys_user_accountRepository.Add(model);
|
|
|
614
|
+ if (!b)
|
|
|
615
|
+ {
|
|
|
616
|
+ if (!string.IsNullOrEmpty(errmsg))
|
|
|
617
|
+ {
|
|
|
618
|
+ errmsg = errmsg + "\r\n第" + index + "行导入失败!";
|
|
|
619
|
+ }
|
|
|
620
|
+ else
|
|
|
621
|
+ {
|
|
|
622
|
+ errmsg = "第" + index + "行导入失败!";
|
|
|
623
|
+ }
|
|
|
624
|
+ }
|
|
|
625
|
+ index++;
|
|
|
626
|
+ }
|
|
|
627
|
+ }
|
|
|
628
|
+ else
|
|
|
629
|
+ {
|
|
|
630
|
+ return Error("文件中无数据");
|
|
|
631
|
+ }
|
|
|
632
|
+
|
|
|
633
|
+ if (!string.IsNullOrEmpty(errmsg))
|
|
|
634
|
+ {
|
|
|
635
|
+ //删除已导入的部分
|
|
|
636
|
+ return Error(errmsg);
|
|
|
637
|
+ }
|
|
|
638
|
+
|
|
|
639
|
+ return Success("导入成功");
|
|
|
640
|
+ }
|
|
562
|
641
|
}
|
|
563
|
642
|
}
|