From 0092c2dd790c0e41a06e773db937beed932abd7c Mon Sep 17 00:00:00 2001 From: pzy <2829717936@qq.com> Date: 星期四, 03 十月 2024 23:10:59 +0800 Subject: [PATCH] task测试 --- WebAPI/WebBLL/JCJM/GYZL/Gy_CustomerService.cs | 25 ++++ WebAPI/WebBLL/JCJM/IMPL/Gy_CustomerImpl.cs | 207 ++++++++++++++++++++++++++++++++++ WebAPI/Utility/TreeUtil.cs | 74 ++++++++++++ 3 files changed, 306 insertions(+), 0 deletions(-) diff --git a/WebAPI/Utility/TreeUtil.cs b/WebAPI/Utility/TreeUtil.cs new file mode 100644 index 0000000..9214747 --- /dev/null +++ b/WebAPI/Utility/TreeUtil.cs @@ -0,0 +1,74 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Web; + +namespace WebAPI.Utility +{ + public class TreeUtil + { + public class TreeModel + { + public string id { get; set; } + public string title { get; set; } + public List<TreeModel> children = new List<TreeModel>(); + } + + #region 閫掑綊鍑芥暟 + /// <summary> + /// 閫掑綊鍑芥暟 + /// </summary> + public void digui(DataTable dt, List<TreeModel> tree, int num) + { + for (int m = 0; m < tree.Count; m++) + { + tree[m].children = new List<TreeModel>(); + for (int i = 0; i < dt.Rows.Count; i++)//绗竴娆″惊鐜紝寰楀埌鎵�鏈夋牴鑺傜偣鐨勫瓙闆� + { + var strLen = dt.Rows[i]["hnumber"].ToString().Split('.'); + if (strLen.Length == num && dt.Rows[i]["hnumber"].ToString().Contains(tree[m].id + ".")) + { + TreeModel tbjson = new TreeModel(); + tbjson.id = dt.Rows[i]["hitemid"].ToString(); + tbjson.title = dt.Rows[i]["hname"].ToString(); + tree[m].children.Add(tbjson); + } + } + var strLens = tree[m].id.Split('.'); + for (int i = 0; i < tree[m].children.Count; i++) + { + digui(dt, tree[m].children, strLens.Length + 2);//鍐嶆鐢ㄥ瓙闆嗗幓寰幆锛屾嬁鍑哄瓙闆嗙殑瀛愰泦 + } + } + + } + #endregion + + #region 鍒嗙被 鏍戝舰鍥�(鏍规嵁浠g爜灞曞紑鏍戠姸鍥�) + public void getTreeByLevel(DataTable dt, List<TreeModel> tree, int num) + { + for (int m = 0; m < tree.Count; m++) + { + tree[m].children = new List<TreeModel>(); + for (int i = 0; i < dt.Rows.Count; i++)//绗竴娆″惊鐜紝寰楀埌鎵�鏈夋牴鑺傜偣鐨勫瓙闆� + { + var HLevel = (int)dt.Rows[i]["hlevel"]; + var HParentID = dt.Rows[i]["hparentid"].ToString(); + if (HLevel == num && HParentID == tree[m].id) + { + TreeModel tbjson = new TreeModel(); + tbjson.id = dt.Rows[i]["hitemid"].ToString(); + tbjson.title = dt.Rows[i]["hname"].ToString(); + tree[m].children.Add(tbjson); + } + } + for (int i = 0; i < tree[m].children.Count; i++) + { + getTreeByLevel(dt, tree[m].children, num + 1);//鍐嶆鐢ㄥ瓙闆嗗幓寰幆锛屾嬁鍑哄瓙闆嗙殑瀛愰泦 + } + } + } + #endregion + } +} \ No newline at end of file diff --git a/WebAPI/WebBLL/JCJM/GYZL/Gy_CustomerService.cs b/WebAPI/WebBLL/JCJM/GYZL/Gy_CustomerService.cs new file mode 100644 index 0000000..3c33e30 --- /dev/null +++ b/WebAPI/WebBLL/JCJM/GYZL/Gy_CustomerService.cs @@ -0,0 +1,25 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WebAPI.WebBLL.JCJM.GYZL +{ + interface Gy_CustomerService + { + /// <summary> + /// 瀵煎叆excel + /// </summary> + void ImportExcel(); + + /// <summary> + /// 涓婁紶excel + /// </summary> + /// <returns></returns> + DataTable UploadExcel(DataSet ExcelDs); + } + + +} diff --git a/WebAPI/WebBLL/JCJM/IMPL/Gy_CustomerImpl.cs b/WebAPI/WebBLL/JCJM/IMPL/Gy_CustomerImpl.cs new file mode 100644 index 0000000..53ae588 --- /dev/null +++ b/WebAPI/WebBLL/JCJM/IMPL/Gy_CustomerImpl.cs @@ -0,0 +1,207 @@ +锘縰sing SyntacticSugar.constant; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Web; +using WebAPI.Exceptions; +using WebAPI.WebBLL.JCJM.GYZL; + +namespace WebAPI.WebBLL.JCJM.IMPL +{ + public class Gy_CustomerImpl : Gy_CustomerService + { + // 绾跨▼璁℃暟鍣� + List<Task> taskList = new List<Task>(); + SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); + #region 瀵煎叆EXCEL + public void ImportExcel() + { + throw new NotImplementedException(); + } + #endregion + + + /// <summary> + /// 鍒ゆ柇鍒� + /// </summary> + /// <param name="provisional"></param> + /// <returns></returns> + private static string JudgmentColumns(DataTable provisional) + { + var error = ""; + //鏌ヨ娌℃湁鐨勫垪 + if (!provisional.Columns.Contains("瀹㈡埛浠g爜")) + error += "娌℃湁鎵惧埌銆愬鎴蜂唬鐮併�戠殑鏍囬,"; + + if (!provisional.Columns.Contains("瀹㈡埛鍚嶇О")) + error += "娌℃湁鎵惧埌銆愬鎴峰悕绉般�戠殑鏍囬,"; + return error; + } + + #region 涓婁紶EXCEL + public DataTable UploadExcel(DataSet ExcelDs) + { + //鍒涘缓涓存椂琛� + DataTable provisional = new DataTable("dt2"); + + //娣诲姞鍒楀悕 + for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++) + { + provisional.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString()); + } + + //娣诲姞鏁版嵁 + for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++) + { + DataRow row = provisional.NewRow(); + for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++) + { + row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); + } + provisional.Rows.Add(row); + } + + //鍒ゆ柇鍒� + string error = JudgmentColumns(provisional); + if (error.Length > 0) + { + throw new ExcelException($"Excel妯℃澘瀛樺湪閿欒,{error}\r\n"); + } + + for (int i = 0; i <= provisional.Rows.Count - 1; i++) + { + string HRegionNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鍦板尯浠g爜"].ToString()); + string HRegionName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鍦板尯鍚嶇О"].ToString()); + string HCurrencyNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["榛樿璐у竵浠g爜"].ToString()); + string HCurrencyName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["榛樿璐у竵鍚嶇О"].ToString()); + //string HBillingNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["缁撶畻鏂瑰紡浠g爜"].ToString()); + //string HBillingName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["缁撶畻鏂瑰紡鍚嶇О"].ToString()); + + string HCusTypeNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["瀹㈡埛鍒嗙被浠g爜"].ToString()); + string HCusTypeName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["瀹㈡埛鍒嗙被鍚嶇О"].ToString()); + + //璁板綍浠诲姟 + var tasks = new List<Task>(); + + //濡傛灉褰撳墠鍦板尯浠g爜鍜屽湴鍖哄悕绉颁笉涓虹┖鍒欏垽鏂槸鍚﹀瓨鍦� + if (!String.IsNullOrEmpty(HRegionName) || !String.IsNullOrEmpty(HRegionNumber)) + { + tasks.Add(JudgeRegion(HRegionNumber, HRegionName)); + } + + // 濡傛灉褰撳墠璐у竵浠g爜鍜岃揣甯佸悕绉颁笉涓虹┖鍒欏垽鏂槸鍚﹀瓨鍦� + if (!String.IsNullOrEmpty(HCurrencyName) || !String.IsNullOrEmpty(HCurrencyNumber)) + { + tasks.Add(JudgeCurrency(HCurrencyNumber, HCurrencyName)); + } + + //濡傛灉褰撳墠瀹㈡埛鍒嗙被浠g爜鍜屽悕绉� + if (!String.IsNullOrEmpty(HCusTypeName) || !String.IsNullOrEmpty(HCusTypeNumber)) + { + tasks.Add(JudgeCusType(HCusTypeNumber, HCusTypeName)); + } + try + { + //绛夊緟浠诲姟瀹屾垚 + Task.WaitAll(tasks.ToArray()); + } + catch (AggregateException ae) + { + string msg = ae.Message; + ae.Handle(ex => { + if (ex is EmptyException) + msg = ex.Message; + Console.WriteLine(ex.Message); + return ex is EmptyException; + }); + throw new Exception("绗�" + i +1 +"鏈夐棶棰�: " +msg); + } + + + //鑾峰彇鐪熷疄琛屾暟 + int line = i + 1; + } + return provisional; + } + + /// <summary> + /// 鍒ゆ柇鍦板尯鏄惁姝g‘ + /// </summary> + private Task<int> JudgeRegion(string HNumber, string HName) + { + return Task<int>.Factory.StartNew(() => + { + try + { + SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); + DataSet ds = oCN.RunProcReturn("select * from Gy_AreaSet where HNumber = '" + HNumber + "' and HName = '" + HName + "'", "Gy_AreaSet"); + if (ds.Tables[0].Rows.Count == EmptyConstant.EMPTY) + { + throw new EmptyException("褰撳墠鍦板尯涓嶅瓨鍦紝璇烽噸鏂伴�夋嫨"); + } + return (int)ds.Tables[0].Rows[0][0]; + } + catch (Exception e) + { + throw new EmptyException(e.Message); + } + }); + } + + /// <summary> + /// 鍒ゆ柇璐у竵鏄惁姝g‘ + /// </summary> + private Task<int> JudgeCurrency(string HNumber, string HName) + { + { + return Task<int>.Factory.StartNew(() => + { + try + { + SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); + DataSet ds = oCN.RunProcReturn("select * from Gy_Currency where HNumber = '" + HNumber + "' and HName = '" + HName + "'", "Gy_Currency"); + if (ds.Tables[0].Rows.Count == EmptyConstant.EMPTY) + { + throw new EmptyException("褰撳墠璐у竵涓嶅瓨鍦紝璇烽噸鏂伴�夋嫨"); + } + return (int)ds.Tables[0].Rows[0][0]; + } + catch (Exception e) + { + throw new EmptyException(e.Message); + } + }); + } + } + + /// <summary> + /// 鍒ゆ柇瀹㈡埛鍒嗙被 + /// </summary> + private Task<int> JudgeCusType(string HNumber, string HName) + { + { + return Task<int>.Factory.StartNew(() => + { + try + { + SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); + DataSet ds = oCN.RunProcReturn("select * from Gy_CusType where HNumber = '" + HNumber + "' and HName = '" + HName + "'", "Gy_CusType"); + if (ds.Tables[0].Rows.Count == EmptyConstant.EMPTY) + { + throw new EmptyException("褰撳墠鍒嗙被涓嶅瓨鍦紝璇烽噸鏂伴�夋嫨"); + } + return (int)ds.Tables[0].Rows[0][0]; + } + catch (Exception e) + { + throw new EmptyException(e.Message); + } + }); + } + } + #endregion + } + +} \ No newline at end of file -- Gitblit v1.9.1