From 5505c9884b67275780b25214cdbfcc4a2ac1578a Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期五, 17 六月 2022 17:36:05 +0800
Subject: [PATCH] 用户清单导入接口编写

---
 VueWebApi/Tools/ImportExcelData.cs |  278 +++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 208 insertions(+), 70 deletions(-)

diff --git a/VueWebApi/Tools/ImportExcelData.cs b/VueWebApi/Tools/ImportExcelData.cs
index 4dc51d4..02621fd 100644
--- a/VueWebApi/Tools/ImportExcelData.cs
+++ b/VueWebApi/Tools/ImportExcelData.cs
@@ -1,4 +1,5 @@
-锘縰sing System;
+锘縰sing Dapper;
+using System;
 using System.Collections.Generic;
 using System.Data;
 using System.Linq;
@@ -12,6 +13,72 @@
         public static ToMessage mes = new ToMessage(); //瀹氫箟鍏ㄥ眬杩斿洖淇℃伅瀵硅薄
 
         #region銆怑xcel妯℃澘涓婁紶楠岃瘉銆�
+        #region銆怑xcel妯℃澘涓婁紶楠岃瘉,鐢ㄦ埛娓呭崟妯℃澘銆�
+        public static string Two(string FileCode, out string code)
+        {
+            string Message = "";
+            code = "";
+            DataTable excelTable = new DataTable();
+            excelTable = ImportExcel.ExcelToTable(FileCode);
+            if (excelTable.Columns.Count != 6)
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[0].ColumnName != "搴忓彿")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[1].ColumnName != "鐢ㄦ埛缂栧彿(鍞竴)")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[2].ColumnName != "鐢ㄦ埛濮撳悕")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[3].ColumnName != "瀵嗙爜")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[4].ColumnName != "鎵嬫満鍙�")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[5].ColumnName != "閭")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[6].ColumnName != "鎵�灞炵粍缁�")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[7].ColumnName != "鍦ㄨ亴鐘舵��")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else if (excelTable.Columns[8].ColumnName != "宸ヨ祫绫诲瀷")
+            {
+                code = "300";
+                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
+            }
+            else
+            {
+                code = "200";
+                Message = "妯℃澘妫�楠岄�氳繃";
+            }
+            return Message;
+        }
+        #endregion
+
         #region銆怑xcel妯℃澘涓婁紶楠岃瘉,瑙掕壊鏉冮檺妯℃澘銆�
         public static string One(string FileCode, out string code)
         {
@@ -40,57 +107,6 @@
                 Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
             }
             else if (excelTable.Columns[3].ColumnName != "瑙掕壊绫诲瀷")
-            {
-                code = "300";
-                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
-            }
-            else
-            {
-                code = "200";
-                Message = "妯℃澘妫�楠岄�氳繃";
-            }
-            return Message;
-        }
-        #endregion
-
-        #region銆怑xcel妯℃澘涓婁紶楠岃瘉,鐢ㄦ埛瑙掕壊妯℃澘銆�
-        public static string Two(string FileCode, out string code)
-        {
-            string Message = "";
-            code = "";
-            DataTable excelTable = new DataTable();
-            excelTable = ImportExcel.ExcelToTable(FileCode);
-            if (excelTable.Columns.Count != 6)
-            {
-                code = "300";
-                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
-            }
-            else if (excelTable.Columns[0].ColumnName != "搴忓彿")
-            {
-                code = "300";
-                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
-            }
-            else if (excelTable.Columns[1].ColumnName != "鐢ㄦ埛缂栧彿(鍞竴)")
-            {
-                code = "300";
-                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
-            }
-            else if (excelTable.Columns[2].ColumnName != "鐢ㄦ埛濮撳悕")
-            {
-                code = "300";
-                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
-            }
-            else if (excelTable.Columns[3].ColumnName != "鎵�灞炵粍缁�")
-            {
-                code = "300";
-                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
-            }
-            else if (excelTable.Columns[4].ColumnName != "鍦ㄨ亴鐘舵��")
-            {
-                code = "300";
-                Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
-            }
-            else if (excelTable.Columns[5].ColumnName != "宸ヨ祫绫诲瀷")
             {
                 code = "300";
                 Message = "妯℃澘涓嶇鍚堣鑼�,璇锋鏌ュ垪鍚�";
@@ -1589,6 +1605,76 @@
         #endregion
 
         #region銆怑xcel涓婁紶鏁版嵁楠岃瘉銆�
+        #region銆怑xcel涓婁紶鏁版嵁楠岃瘉,鐢ㄦ埛瑙掕壊銆�
+        public static List<ExcelErro> TwoData(string FileCode, out string StuCode, out string message, out int count)
+        {
+            message = "";
+            StuCode = "";
+            count = 0;
+            string sql = "";
+            var dynamicParams = new DynamicParameters();
+            DataTable dt;
+            List<ExcelErro> list = new List<ExcelErro>();
+            DataTable excelTable = new DataTable();
+            list = ImportExcel.ExcelToTableErro(FileCode);    //楠岃瘉Excel鏁版嵁蹇呭~瀛楁鏄惁涓虹┖銆佸敮涓�瀛楁鏄惁閲嶅
+            excelTable = ImportExcel.ExcelToTable(FileCode);  //鑾峰彇Excel鏁版嵁
+            for (int i = 0; i < excelTable.Rows.Count; i++)
+            {
+                if (excelTable.Rows[i][1].ToString().Trim() != null && excelTable.Rows[i][1].ToString().Trim() != "")
+                {
+                    sql = @"select code  from TUser where code=:code";
+                    dynamicParams.Add("@code", excelTable.Rows[i][1].ToString().Trim());
+                    dt = DapperHelper.selectdata(sql, dynamicParams);
+                    if (dt.Rows.Count > 0)
+                    {
+                        ExcelErro erro = new ExcelErro();
+                        erro.RoeNumber = "/";
+                        erro.ErrorField = "{鐢ㄦ埛缂栧彿(鍞竴)}";
+                        erro.ErrorCont = "{鐢ㄦ埛缂栧彿(鍞竴)}瀛楁" + excelTable.Rows[i][1].ToString().Trim() + "宸插瓨鍦�";
+                        list.Add(erro);
+                    }
+                }
+                if (excelTable.Rows[i][6].ToString().Trim() != null && excelTable.Rows[i][6].ToString().Trim() != "")
+                {
+                    sql = @"select * from(
+                             select org_code,org_name  from  TOrganization where description='D' and parent_id in (select id   from TOrganization where description='F')
+                             union
+                             select org_code,org_name from TOrganization where parent_id in(select id  
+                             from  TOrganization where description='D' and parent_id in (select id   from TOrganization where description='F'))
+                             ) as AA where AA.org_name=:name";
+                    dynamicParams.Add("@code", excelTable.Rows[i][3].ToString().Trim());
+                    dt = DapperHelper.selectdata(sql, dynamicParams);
+                    if (dt == null || dt.Rows.Count <= 0)
+                    {
+                        ExcelErro erro = new ExcelErro();
+                        erro.RoeNumber = "/";
+                        erro.ErrorField = "{鎵�灞炵粍缁噠";
+                        erro.ErrorCont = "{鎵�灞炵粍缁噠瀛楁" + excelTable.Rows[i][3].ToString().Trim() + "涓嶅瓨鍦�";
+                        list.Add(erro);
+                    }
+                }
+            }
+            if (list.Count > 0)
+            {
+                int index = 0;
+                foreach (ExcelErro item in list)
+                {
+                    index++;
+                    item.Seq = index.ToString();
+                }
+                StuCode = "300";
+                message = "鏁版嵁楠岃瘉澶辫触";
+            }
+            else
+            {
+                StuCode = "200";
+                message = "鏁版嵁楠岃瘉鎴愬姛";
+                count = excelTable.Rows.Count;
+            }
+            return list;
+        }
+        #endregion
+
         #region銆怑xcel涓婁紶鏁版嵁楠岃瘉,瑙掕壊鏉冮檺銆�
         public static List<ExcelErro> OneData(string FileCode, out string StuCode, out string message, out int count)
         {
@@ -1599,20 +1685,6 @@
             DataTable dt;
             List<ExcelErro> list = new List<ExcelErro>();
             
-            return list;
-        }
-        #endregion
-
-        #region銆怑xcel涓婁紶鏁版嵁楠岃瘉,鐢ㄦ埛瑙掕壊銆�
-        public static List<ExcelErro> TwoData(string FileCode, out string StuCode, out string message, out int count)
-        {
-            message = "";
-            StuCode = "";
-            count = 0;
-            string sql = "";
-            DataTable dt;
-            List<ExcelErro> list = new List<ExcelErro>();
-
             return list;
         }
         #endregion
@@ -1949,14 +2021,80 @@
         #endregion
 
         #region[Excel涓婁紶鏁版嵁鎻愪氦]
-        #region[Excel鏁版嵁涓婁紶,瑙掕壊鏉冮檺]
-        public static string OneSubmit(string FileCode, string User, out string StuCode)
+        #region銆怑xcel鏁版嵁涓婁紶,鐢ㄦ埛瑙掕壊銆�
+        public static string TwoSubmit(string FileCode, string User, out string StuCode)
         {
             string message = "";
             StuCode = "";
+            string sql = "";
+            string ZZName = "", Enable = "", WageType = "";
+            DataTable dt;
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
             try
             {
+                list.Clear();
+                DataTable excelTable = new DataTable();
+                excelTable = ImportExcel.ExcelToTable(FileCode);
+                for (int i = 0; i < excelTable.Rows.Count; i++)
+                {
+                    if (excelTable.Rows[i][7].ToString().Trim() == "鍦ㄨ亴")
+                    {
+                        Enable = "Y";
+                    }
+                    else
+                    {
+                        Enable = "N";
+                    }
+                    //鐐规绠℃帶
+                    switch (excelTable.Rows[i][8].ToString().Trim())
+                    {
+                        case "璁′欢鍒�":
+                            WageType = "1";
+                            break;
+                        case "璁℃椂鍒�":
+                            WageType = "2";
+                            break;
+                        default:
+                            break;
+                    }
+                    if (excelTable.Rows[i][6].ToString().Trim() != null && excelTable.Rows[i][6].ToString().Trim() != "")
+                    {
+                        sql = @"select * from(
+                             select org_code,org_name  from  TOrganization where description='D' and parent_id in (select id   from TOrganization where description='F')
+                             union
+                             select org_code,org_name from TOrganization where parent_id in(select id  
+                             from  TOrganization where description='D' and parent_id in (select id   from TOrganization where description='F'))
+                             ) as AA where AA.org_name=:name";
+                        dynamicParams.Add("@code", excelTable.Rows[i][3].ToString().Trim());
+                        dt = DapperHelper.selectdata(sql, dynamicParams);
+                        ZZName = dt.Rows[0]["CODE"].ToString().Trim();
+                    }
 
+                    sql = @"insert into TUser(usercode,username,password,enable,mobile,lm_date,email,lm_user,stu_torgcode,wagetype) 
+                            values(@UserCode,@UserName,@password,@Enable,@Mobile,@CreateDate,@Email,@Operator,@StuOrg,@wagetype)";
+                    dynamicParams.Add("@UserCode", excelTable.Rows[i][1].ToString().Trim());
+                    dynamicParams.Add("@UserName", excelTable.Rows[i][2].ToString().Trim());
+                    dynamicParams.Add("@password", excelTable.Rows[i][3].ToString().Trim());
+                    dynamicParams.Add("@Enable", excelTable.Rows[i][7].ToString().Trim());
+                    dynamicParams.Add("@Mobile", excelTable.Rows[i][4].ToString().Trim());
+                    dynamicParams.Add("@CreateDate", DateTime.Now.ToString());
+                    dynamicParams.Add("@Email", excelTable.Rows[i][5].ToString().Trim());
+                    dynamicParams.Add("@Operator", User);
+                    dynamicParams.Add("@StuOrg", ZZName);
+                    dynamicParams.Add("@wagetype", WageType);
+                }
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    StuCode = "300";
+                    message = "瀵煎叆澶辫触锛�";
+                }
+                else
+                {
+                    StuCode = "200";
+                    message = "瀵煎叆鎴愬姛锛�";
+                }
             }
             catch (Exception e)
             {
@@ -1967,8 +2105,8 @@
         }
         #endregion
 
-        #region銆怑xcel鏁版嵁涓婁紶,鐢ㄦ埛瑙掕壊銆�
-        public static string TwoSubmit(string FileCode, string User, out string StuCode)
+        #region[Excel鏁版嵁涓婁紶,瑙掕壊鏉冮檺]
+        public static string OneSubmit(string FileCode, string User, out string StuCode)
         {
             string message = "";
             StuCode = "";

--
Gitblit v1.9.3