Parcourir la Source

提交更改,上传

zhangkun il y a 5 ans
Parent
commit
47dea75a9c

+ 80 - 1
代码/MadRunFabric.SignTokenApi/SignTokenApi/Controllers/UserAccountController.cs

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
 using System.Linq;
3
 using System.Linq;
4
+using System.Reflection;
4
 using System.Security.Claims;
5
 using System.Security.Claims;
5
 using System.Threading.Tasks;
6
 using System.Threading.Tasks;
6
 using MadRunFabric.Common;
7
 using MadRunFabric.Common;
10
 using Microsoft.Extensions.Configuration;
11
 using Microsoft.Extensions.Configuration;
11
 using Microsoft.Extensions.Logging;
12
 using Microsoft.Extensions.Logging;
12
 using MongoDB.Driver;
13
 using MongoDB.Driver;
14
+using NPOI.SS.Formula.Functions;
13
 using SignTokenApi.IRepositories;
15
 using SignTokenApi.IRepositories;
14
 using SignTokenApi.Model.Dto;
16
 using SignTokenApi.Model.Dto;
15
 using SignTokenApi.Model.Input;
17
 using SignTokenApi.Model.Input;
177
             model.birthday = input.birthday;
179
             model.birthday = input.birthday;
178
             model.call_type = input.call_type;
180
             model.call_type = input.call_type;
179
             model.delete_flag = false;
181
             model.delete_flag = false;
180
-            //model.dept_id = input.dept_id;
182
+            model.dept_id = input.dept_id;
181
             model.extensionnumber = input.extensionnumber;
183
             model.extensionnumber = input.extensionnumber;
182
             model.group = input.group;
184
             model.group = input.group;
183
             model.groupid = input.groupid;
185
             model.groupid = input.groupid;
559
 
561
 
560
             return Success("根据条件获取坐席数据成功", agentlist);
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
 }

+ 1 - 1
代码/MadRunFabric.SignTokenApi/SignTokenApi/Model/Input/UserAccountInput.cs

153
         public int? call_type { get; set; } = 0;
153
         public int? call_type { get; set; } = 0;
154
 
154
 
155
         /// <summary>
155
         /// <summary>
156
-        /// 团队id
156
+        /// 团队id/岗位类型
157
         /// </summary>
157
         /// </summary>
158
         public string team_id { get; set; } = "";
158
         public string team_id { get; set; } = "";
159
 
159
 

+ 7 - 0
代码/MadRunFabric.SignTokenApi/SignTokenApi/appsettings.Development.json

27
     "Defaultdatabase": "5",
27
     "Defaultdatabase": "5",
28
     "InstanceName": "test"
28
     "InstanceName": "test"
29
   },
29
   },
30
+  "upload": {
31
+    "url": "http://yunwei.nuodajituan.com:28000/fileserverapi/api/upload",
32
+    "params": "uploadtype=excel",
33
+    "mbname": "工号.xlsx",
34
+    "mbkeys": "id,usercode,username,sex,mobile,remark,team_id,postlist,projectlist",
35
+    "dbkeys": "id,usercode,username,sex,mobile,remark,team_id,postlist,projectlist"
36
+  },
30
   "allprojectrole": "YWFJL|YWJL|YWZJ|CJGL|XTWH", //查看所有项目
37
   "allprojectrole": "YWFJL|YWJL|YWZJ|CJGL|XTWH", //查看所有项目
31
   "spring": {
38
   "spring": {
32
     "application": {
39
     "application": {

+ 0 - 2
代码/MadRunFabric.TestUserTypeApi/TestUserTypeApi/Controllers/TestUserTypeController.cs

21
 using System.Collections;
21
 using System.Collections;
22
 using System.Net.Http;
22
 using System.Net.Http;
23
 using System.Reflection;
23
 using System.Reflection;
24
-using com.pkuhit.iihip.sdk;
25
-using com.pkuhit.iihip.sdk.message;
26
 using System.Net.Http.Headers;
24
 using System.Net.Http.Headers;
27
 using Newtonsoft.Json;
25
 using Newtonsoft.Json;
28
 using System.Data;
26
 using System.Data;