From 3a95572688e7221c5f1459bc293d452df0477368 Mon Sep 17 00:00:00 2001
From: zhangli <1109134334@qq.com>
Date: Tue, 28 Jun 2022 16:20:11 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=AE=BF=E8=88=8D=E5=AF=BC?=
=?UTF-8?q?=E5=85=A5=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controllers/AccommodationController.cs | 67 ++++-
.../Views/Accommodation/Index.cshtml | 5 +-
.../Views/Accommodation/Index.js | 18 ++
.../Views/Accommodation/IndexImport.cshtml | 26 ++
.../Views/Accommodation/IndexImport.js | 180 +++++++++++++
.../Content/excel/AccommodationImport.xls | Bin 0 -> 31232 bytes
.../Learun.Application.Web.csproj | 2 +
.../Accommodation/AccommodationBLL.cs | 21 ++
.../Accommodation/AccommodationIBLL.cs | 2 +
.../Accommodation/AccommodationService.cs | 253 ++++++++++++++++++
10 files changed, 572 insertions(+), 2 deletions(-)
create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LogisticsManagement/Views/Accommodation/IndexImport.cshtml
create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LogisticsManagement/Views/Accommodation/IndexImport.js
create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.Web/Content/excel/AccommodationImport.xls
diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LogisticsManagement/Controllers/AccommodationController.cs b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LogisticsManagement/Controllers/AccommodationController.cs
index cecc6a18d..8ba4e596e 100644
--- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LogisticsManagement/Controllers/AccommodationController.cs
+++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Areas/LogisticsManagement/Controllers/AccommodationController.cs
@@ -8,6 +8,11 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
+using System.IO;
+using NPOI.HSSF.UserModel;
+using NPOI.SS.UserModel;
+using Learun.Application.Base.SystemModule;
+using System.Drawing;
namespace Learun.Application.Web.Areas.LogisticsManagement.Controllers
{
@@ -21,6 +26,7 @@ namespace Learun.Application.Web.Areas.LogisticsManagement.Controllers
public class AccommodationController : MvcControllerBase
{
private AccommodationIBLL accommodationIBLL = new AccommodationBLL();
+ private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL();
#region 视图功能
@@ -207,7 +213,15 @@ namespace Learun.Application.Web.Areas.LogisticsManagement.Controllers
{
return View();
}
-
+ ///
mX=zc5-Q~B zDWvA|O^6pLfp>Vw!@)hHLwmFuQYajwBt-+@C(mcgf*W#5gU}Q_dZi!>ZUS{E4WcY` zijjp*F|yDpl*Jomd60j4j!VC(VvoUvLR?EznxZ~<{1(7Zp3m4S(^zTm8-ae|E>D`# zHHJn}vUk1#*gKQU#sE1P3o?NL0A%?wuXrG%mtZAXtUwldJ~LXNEV6z<`#}P3;c5Hv z&DH|Tuv3K6)&hY-qr)R~qUJ5YmZGKkW$QpmC#8})5?xtIMLTMacEm66>|Q7gP^`pj z2zG=y>^lb?0*oD@*FbjXv_PD>v%mIGwa5B^gE?#)VA~^hq>2s5?Gdx_2okLmI>ojD z9(6zX)BMF8{4FT{Vg>%V{b$+{96VN$|37~}7?A+99r;c!NKu!9M$lDEE~8KRgaErY z=swxKfb&D391rIQWxU2RJoYMvke8XwsCKE~{Upc3*+Ci4S%$}6tK%(L|}$jbO6ZBnNBh0Os5!grc<+o zeaI{phXUYZ27fUyRSkfXjbaiFX96csSK*Kv1m^_Dkm2Adh=i-LBo%VyCD^A3{YgLS z{A3>7ObgKyM07~>5V3f)&k~^(S;FE;Pj2)x)-`bEbPX#H>&*o9_JY4HJTQC06EuJu zl&N!sCnQH8;e3owz7Z>aJt&V6) ^+Kn4rzhw9NVxty}=s7g!sI zRW(@|Lqp<}vtX`fYH@)|v$19^*|%fY#u~-EnV<$7v$<+ZC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t`1fi+-Toi< z?fffeuM~ONn$BGa`+tuwTX27`twehRv`r9kKaW0v&Jgi;P9q_ro2m~)Q;7W_qEBE5 zM11pZBt&$gjfaR1tQim)Ujgj{Fs14PS?#wS03%OyvC(gx5&%47wYTyl-vwr|mB( z#~zj>BpV|7AuzZ?L@LUNmHI(M-Y6T@e)vYmTPN`daa#Y;scBR$dOBnjQ7>^?Iv$W? zWJkuR3&yv>q G=TeG z+`Hnw7x%^ZY#&dL;N}_kv3Rlr_rSQ9$9+2P+3~mw9%O;NHgzlpcf`22XI>e_{XO~s ztRPxL#D5fm|K|f=`f3Cb_r&%PMGzZ9bb#mx(Fvk6#3m43AmaYq4I=)3S$FvMfanR) z3!*nf+)p=yi1~i-jc;b+uX*`H#2 #wG8$g(O9hJh;0pZl9>V*luKcMN81d$Tpsn)S R;y))(;J?s*Ut}!h|6fPji2(or literal 0 HcmV?d00001 diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj b/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj index 78b3fd178..c3d8d2f62 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj @@ -1352,6 +1352,7 @@ + @@ -7691,6 +7692,7 @@ + diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationBLL.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationBLL.cs index e3fb35e6c..12c98a70c 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationBLL.cs @@ -830,6 +830,27 @@ namespace Learun.Application.TwoDevelopment.LogisticsManagement } } + + public (DataTable failDt, int snum, int fnum) ExecuteImportExcel(DataTable dt, string fileGuid) + { + try + { + return accommodationService.ExecuteImportExcel(dt, fileGuid); + + } + catch (Exception ex) + { + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowBusinessException(ex); + } + + } + } #endregion } diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationIBLL.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationIBLL.cs index 2050f1292..9c3541bc6 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationIBLL.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationIBLL.cs @@ -106,6 +106,8 @@ namespace Learun.Application.TwoDevelopment.LogisticsManagement object GetFloorList(string parentID); object GetRoomList(string parentID); object GetBedList(string parentID); + (DataTable failDt, int snum,int fnum) ExecuteImportExcel(DataTable dt, string fileGuid); + #endregion } diff --git a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationService.cs b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationService.cs index 0f830c378..a022735b9 100644 --- a/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationService.cs +++ b/Learun.Framework.Ultimate V7/Learun.Framework.Module/Learun.Application.Module/Learun.Application.TwoDevelopment/LogisticsManagement/Accommodation/AccommodationService.cs @@ -1,5 +1,7 @@ using Dapper; using Learun.Application.TwoDevelopment.EducationalAdministration; +using Learun.Cache.Base; +using Learun.Cache.Factory; using Learun.DataBase.Repository; using Learun.Util; using System; @@ -19,6 +21,10 @@ namespace Learun.Application.TwoDevelopment.LogisticsManagement /// public class AccommodationService : RepositoryFactory { + #region 缓存定义 + private ICache cache = CacheFactory.CaChe(); + private string cacheKey = "Learun_adms_excelError_"; // +公司主键 + #endregion #region 获取数据 /// @@ -1908,6 +1914,253 @@ where ID='{ParentID}' } } + /// + /// 导入宿舍信息 + /// + /// + ///+ public (DataTable failDt, int snum, int fnum) ExecuteImportExcel(DataTable dt,string fileGuid) + { + int snum = 0; + int fnum = 0; + var db = this.BaseRepository("CollegeMIS"); + var msg = ""; + try + { + db.BeginTrans(); + var dormitoryBuildList = db.FindList ().ToList(); + + //系 专业 班级 + var deptList = db.FindList (); + var majorList = db.FindList (x => x.CheckMark == true); + var classList = db.FindList (x => x.CheckMark == true); + //学生 + var stuinfobasic = db.FindList (); + // 创建一个datatable容器用于保存导入失败的数据 + DataTable failDt = new DataTable(); + foreach (DataColumn dc in dt.Columns) + { + failDt.Columns.Add(dc.ColumnName, dc.DataType); + } + failDt.Columns.Add("导入错误", typeof(string)); + dt.Columns.Add("导入错误", typeof(string)); + var dic = new Dictionary (); + var user = LoginUserInfo.Get(); + foreach (DataRow dr in dt.Rows) + { + try + { + if (!string.IsNullOrEmpty(dr["宿舍楼"].ToString().Trim())) + { + + //系 专业 班级 + var DeptNo = deptList.Where(x => x.DeptName == dr["系部"].ToString().Trim()).FirstOrDefault()?.DeptNo; + var MajorNo = majorList.Where(x => x.MajorName == dr["专业"].ToString().Trim() && x.DeptNo == DeptNo) + .FirstOrDefault()?.MajorNo; + var ClassNo = classList.Where(x => + x.ClassName == dr["班级"].ToString() && x.DeptNo == DeptNo && x.MajorNo == MajorNo).FirstOrDefault()?.ClassNo; + if (string.IsNullOrEmpty(DeptNo)) + { + fnum++; + dr["导入错误"] = dr["系部"] + "导入错误"; + failDt.Rows.Add(dr.ItemArray); + continue; + } + if (string.IsNullOrEmpty(MajorNo)) + { + fnum++; + dr["导入错误"] = dr["专业"] + "导入错误"; + failDt.Rows.Add(dr.ItemArray); + continue; + } + if (string.IsNullOrEmpty(ClassNo)) + { + fnum++; + dr["导入错误"] = dr["班级"] + "导入错误"; + failDt.Rows.Add(dr.ItemArray); + continue; + } + var leaderno = stuinfobasic.Where(x => x.StuNo == dr["舍长学号"].ToString() && x.ClassNo == ClassNo).FirstOrDefault()?.StuNo; + var stuno = stuinfobasic.Where(x => x.StuNo == dr["学生学号"].ToString() && x.ClassNo == ClassNo).FirstOrDefault()?.StuNo; + if (string.IsNullOrEmpty(stuno)) + { + fnum++; + dr["导入错误"] = dr["学生学号"] + "导入错误"; + failDt.Rows.Add(dr.ItemArray); + continue; + } + if (string.IsNullOrEmpty(leaderno)) + { + fnum++; + dr["导入错误"] = dr["舍长学号"] + "导入错误"; + failDt.Rows.Add(dr.ItemArray); + continue; + } + + //宿舍楼 + var apartmentName = dr["宿舍楼"].ToString().Trim(); + var apartmentCode = dr["宿舍楼编号"].ToString(); + var apartment = dormitoryBuildList.Where(x => x.Name == apartmentName && x.BuildType == "1") + .FirstOrDefault(); + if (apartment == null) + { + //添加宿舍楼 + apartment = new Acc_DormitoryBuildEntity(); + apartment.Create(); + apartment.DNo = apartmentCode; + apartment.Name = apartmentName; + apartment.BuildType = "1"; + apartment.CreateBy = user.realName; + apartment.CreateTime = DateTime.Now; + apartment.Campus = user.companyId; + db.Insert(apartment); + + dormitoryBuildList.Add(apartment); + } + //单元 + var unitName = dr["单元"].ToString().Trim(); + var unitCode = dr["单元编号"].ToString(); + var unit = dormitoryBuildList.Where(x => x.Name == unitName && x.BuildType == "2" && x.ParentID == apartment.ID) + .FirstOrDefault(); + if (unit == null) + { + //添加单元 + unit = new Acc_DormitoryBuildEntity(); + unit.Create(); + unit.ParentID = apartment.ID; + unit.ApartmentId = apartment.ID; + unit.DNo = unitCode; + unit.Name = unitName; + unit.BuildType = "2"; + unit.CreateBy = user.realName; + unit.CreateTime = DateTime.Now; + unit.Campus = user.companyId; + db.Insert(unit); + + dormitoryBuildList.Add(unit); + } + //楼层 + var floorName = dr["楼层"].ToString().Trim(); + var floorCode = dr["楼层编号"].ToString(); + var floor = dormitoryBuildList.Where(x => x.Name == floorName && x.DNo == floorCode && x.BuildType == "3" && x.ParentID == unit.ID) + .FirstOrDefault(); + if (floor == null) + { + //添加楼层 + floor = new Acc_DormitoryBuildEntity(); + floor.Create(); + floor.ParentID = unit.ID; + floor.ApartmentId = apartment.ID; + floor.UnitId = unit.ID; + floor.DNo = floorCode; + floor.Name = floorName; + floor.BuildType = "3"; + floor.CreateBy = user.realName; + floor.CreateTime = DateTime.Now; + floor.Campus = user.companyId; + db.Insert(floor); + + dormitoryBuildList.Add(floor); + } + //寝室 + var dormitoryName = dr["寝室名称"].ToString().Trim(); + var dormitoryCode = dr["寝室编号"].ToString().Trim(); + var dormitory = dormitoryBuildList.Where(x => x.Name == dormitoryName && x.DNo == dormitoryCode && x.BuildType == "4" && x.ParentID == floor.ID) + .FirstOrDefault(); + if (dormitory == null) + { + //添加 + dormitory = new Acc_DormitoryBuildEntity(); + dormitory.Create(); + dormitory.Dept = DeptNo; + dormitory.Major = MajorNo; + dormitory.Class = ClassNo; + dormitory.ParentID = floor.ID; + dormitory.ApartmentId = apartment.ID; + dormitory.UnitId = unit.ID; + dormitory.FloorId = floor.ID; + dormitory.DNo = dormitoryCode; + dormitory.Name = dormitoryName; + dormitory.Sex = dr["性别"].ToString() == "女" ? "0" : "1"; + dormitory.BuildType = "4"; + dormitory.RoomType = Convert.ToInt32(dr["几人寝"].ToString()); + dormitory.Leader = leaderno; + dormitory.Starred = "3"; + dormitory.CreateBy = user.realName; + dormitory.CreateTime = DateTime.Now; + dormitory.Campus = user.companyId; + db.Insert(dormitory); + + dormitoryBuildList.Add(dormitory); + } + //床位 + var bedName = dr["床位"].ToString().Trim(); + var bedCode = bedName.Replace("床", "").Replace("号", ""); + var bed = dormitoryBuildList.Where(x => x.Name == bedName && x.DNo == bedCode && x.BuildType == "5" && x.ParentID == dormitory.ID) + .FirstOrDefault(); + if (bed == null) + { + bed = new Acc_DormitoryBuildEntity(); + bed.Create(); + bed.ParentID = dormitory.ID; + bed.ApartmentId = apartment.ID; + bed.UnitId = unit.ID; + bed.FloorId = floor.ID; + bed.DNo = bedCode; + bed.Name = bedName; + bed.Dept = DeptNo; + bed.Major = MajorNo; + bed.Class = ClassNo; + bed.StudentID = stuno; + bed.Leader = leaderno; + bed.BuildType = "5"; + bed.CreateBy = user.realName; + bed.CreateTime = DateTime.Now; + bed.Campus = user.companyId; + db.Insert(bed); + + dormitoryBuildList.Add(bed); + snum++; + } + + } + else + { + break; + } + } + catch (Exception e) + { + fnum++; + dr["导入错误"] = "出现异常:" + e.Message; + failDt.Rows.Add(dr.ItemArray); + continue; + } + } + + db.Commit(); + // 写入缓存如果有未导入的数据 + if (failDt.Rows.Count > 0) + { + string errordt = failDt.ToJson(); + + cache.Write (cacheKey + fileGuid, errordt, CacheId.excel); + } + return (failDt, snum, fnum); + } + catch (Exception ex) + { + db.Rollback(); + if (ex is ExceptionEx) + { + throw; + } + else + { + throw ExceptionEx.ThrowServiceException(ex); + } + } + } #endregion 提交数据 } } \ No newline at end of file