|
|
@@ -11,6 +11,9 @@ using Microsoft.AspNetCore.Mvc;
|
|
11
|
11
|
using TVShoppingCallCenter_ZLJ.Models.Inputs;
|
|
12
|
12
|
using SqlSugar;
|
|
13
|
13
|
using System.Common.Helpers;
|
|
|
14
|
+using Microsoft.Extensions.Configuration;
|
|
|
15
|
+using System.Data;
|
|
|
16
|
+using System.Reflection;
|
|
14
|
17
|
|
|
15
|
18
|
namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
|
|
16
|
19
|
{
|
|
|
@@ -22,12 +25,14 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
|
|
22
|
25
|
private readonly ICus_VipInfoRepository _cus_vip_infoRepository;
|
|
23
|
26
|
private readonly ISys_UserAccountRepository _sys_user_accountRepository;
|
|
24
|
27
|
private readonly ICus_MsgRepository _cus_msgRepository;
|
|
|
28
|
+ private readonly IConfiguration _configuration;
|
|
25
|
29
|
|
|
26
|
|
- public VipInfoController(ICus_VipInfoRepository cus_vip_infoRepository, ISys_UserAccountRepository sys_user_accountRepository, ICus_MsgRepository cus_msgRepository)
|
|
|
30
|
+ public VipInfoController(ICus_VipInfoRepository cus_vip_infoRepository, ISys_UserAccountRepository sys_user_accountRepository, ICus_MsgRepository cus_msgRepository,IConfiguration configuration)
|
|
27
|
31
|
{
|
|
28
|
32
|
_cus_vip_infoRepository = cus_vip_infoRepository;
|
|
29
|
33
|
_sys_user_accountRepository = sys_user_accountRepository;
|
|
30
|
34
|
_cus_msgRepository = cus_msgRepository;
|
|
|
35
|
+ _configuration = configuration;
|
|
31
|
36
|
}
|
|
32
|
37
|
|
|
33
|
38
|
[HttpGet]
|
|
|
@@ -512,6 +517,88 @@ namespace TVShoppingCallCenter_ZLJ.Controllers.Customer
|
|
512
|
517
|
}
|
|
513
|
518
|
//return Success("导出成功");
|
|
514
|
519
|
}
|
|
|
520
|
+
|
|
|
521
|
+ /// <summary>
|
|
|
522
|
+ /// 上传文件并导入数据库
|
|
|
523
|
+ /// </summary>
|
|
|
524
|
+ /// <returns></returns>
|
|
|
525
|
+ [HttpPost("importexcel")]
|
|
|
526
|
+ public async Task<IActionResult> ImportExcel( int headrow = 0)
|
|
|
527
|
+ {
|
|
|
528
|
+
|
|
|
529
|
+ //string usercode = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
|
|
|
530
|
+
|
|
|
531
|
+ Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
|
|
|
532
|
+ 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"))
|
|
|
533
|
+ return Error($"请正确上传Excel文件:file.ContentType={_upfile.ContentType}");
|
|
|
534
|
+
|
|
|
535
|
+ NPOIHelper npoi = new NPOIHelper();
|
|
|
536
|
+ var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
|
|
|
537
|
+ int num = dtExcel.Rows.Count;
|
|
|
538
|
+ var cols = dtExcel.Columns;
|
|
|
539
|
+ int colnum = cols.Count;
|
|
|
540
|
+
|
|
|
541
|
+ string dbkeys = _configuration["upload:acotdbkeys"].ToString();
|
|
|
542
|
+ string[] dbcols = dbkeys.Split(",");
|
|
|
543
|
+ string errmsg = string.Empty;
|
|
|
544
|
+
|
|
|
545
|
+ if (num > 0)
|
|
|
546
|
+ {
|
|
|
547
|
+ int index = 1;
|
|
|
548
|
+ foreach (DataRow dr in dtExcel.Rows)
|
|
|
549
|
+ {
|
|
|
550
|
+ var model = new T_Cus_VipInfo();
|
|
|
551
|
+
|
|
|
552
|
+ model.F_State = 1;
|
|
|
553
|
+ model.F_CreateBy = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Sid).Value;
|
|
|
554
|
+ model.F_CreateOn = DateTime.Now;
|
|
|
555
|
+
|
|
|
556
|
+ var dbcolslist = dbcols.ToList();
|
|
|
557
|
+
|
|
|
558
|
+ Type t = model.GetType();
|
|
|
559
|
+ PropertyInfo[] PropertyList = t.GetProperties();
|
|
|
560
|
+
|
|
|
561
|
+ foreach (PropertyInfo item in PropertyList)
|
|
|
562
|
+ {
|
|
|
563
|
+ if (dbcolslist.Contains(item.Name))
|
|
|
564
|
+ {
|
|
|
565
|
+ object v = Convert.ChangeType(dr[dbcolslist.IndexOf(item.Name)].ToString(), item.PropertyType);
|
|
|
566
|
+ item.SetValue(model, v, null);
|
|
|
567
|
+
|
|
|
568
|
+ }
|
|
|
569
|
+ }
|
|
|
570
|
+
|
|
|
571
|
+ int b = await _cus_vip_infoRepository.Add(model);
|
|
|
572
|
+
|
|
|
573
|
+
|
|
|
574
|
+ if (b>0)
|
|
|
575
|
+ {
|
|
|
576
|
+ if (!string.IsNullOrEmpty(errmsg))
|
|
|
577
|
+ {
|
|
|
578
|
+ errmsg = errmsg + "\r\n第" + index + "行导入失败!";
|
|
|
579
|
+ }
|
|
|
580
|
+ else
|
|
|
581
|
+ {
|
|
|
582
|
+ errmsg = "第" + index + "行导入失败!";
|
|
|
583
|
+ }
|
|
|
584
|
+ }
|
|
|
585
|
+ index++;
|
|
|
586
|
+
|
|
|
587
|
+ }
|
|
|
588
|
+ }
|
|
|
589
|
+ else
|
|
|
590
|
+ {
|
|
|
591
|
+ return Error("文件中无数据");
|
|
|
592
|
+ }
|
|
|
593
|
+
|
|
|
594
|
+ if (!string.IsNullOrEmpty(errmsg))
|
|
|
595
|
+ {
|
|
|
596
|
+ //删除已导入的部分
|
|
|
597
|
+ return Error(errmsg);
|
|
|
598
|
+ }
|
|
|
599
|
+
|
|
|
600
|
+ return Success("导入成功");
|
|
|
601
|
+ }
|
|
515
|
602
|
#endregion
|
|
516
|
603
|
}
|
|
517
|
604
|
}
|