diff --git a/Tiobon.Core.Api/Controllers/Base/BaseController.cs b/Tiobon.Core.Api/Controllers/Base/BaseController.cs index 7b903dc0..2b56f0f5 100644 --- a/Tiobon.Core.Api/Controllers/Base/BaseController.cs +++ b/Tiobon.Core.Api/Controllers/Base/BaseController.cs @@ -330,9 +330,9 @@ public class BaseController> ImportExcel(IFormFile file) + public async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { - var data = (await InvokeServiceAsync("ImportExcel", [file])) as ServiceResult; + var data = (await InvokeServiceAsync("ImportExcel", [file, menuName, MasterId])) as ServiceResult; return data; } #endregion diff --git a/Tiobon.Core.IServices/BASE/IBaseServices.cs b/Tiobon.Core.IServices/BASE/IBaseServices.cs index ab9c0160..b72fa092 100644 --- a/Tiobon.Core.IServices/BASE/IBaseServices.cs +++ b/Tiobon.Core.IServices/BASE/IBaseServices.cs @@ -157,7 +157,7 @@ namespace Tiobon.Core.IServices.BASE Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true); Task> ExportExcel(QueryExport body); - Task> ImportExcel(IFormFile file); + Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null); Task> DownloadExcel(string menuName); diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 504170bb..fc8028e7 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -935,7 +935,7 @@ public class BaseServices : IBaseServ } return result; } - public async virtual Task> ImportExcel(IFormFile file) + public async virtual Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { //long id = SnowFlakeSingle.instance.getID(); //var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; diff --git a/Tiobon.Core.Services/Ghre/Ghre_CertificateServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CertificateServices.cs index bb76cb93..0c017987 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CertificateServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CertificateServices.cs @@ -81,8 +81,6 @@ public class Ghre_CertificateServices : BaseServices> DownloadExcel(string menuName) { var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; @@ -100,7 +98,7 @@ public class Ghre_CertificateServices : BaseServices.OprateSuccess("人证对照表_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now) + ".xlsx", physicsPath1); return result; } - public override async Task> ImportExcel(IFormFile file) + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { var data = new ExcelData(); long id = SnowFlakeSingle.instance.getID(); diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseClassServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseClassServices.cs index ad41414c..6991757e 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseClassServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseClassServices.cs @@ -35,7 +35,7 @@ public class Ghre_CourseClassServices : BaseServices.OprateSuccess("课程分类_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now) + ".xlsx", physicsPath1); return result; } - public override async Task> ImportExcel(IFormFile file) + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { var data = new ExcelData(); long id = SnowFlakeSingle.instance.getID(); diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseSceneServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseSceneServices.cs index e58c3ae8..4d4698e6 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseSceneServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseSceneServices.cs @@ -81,7 +81,7 @@ public class Ghre_CourseSceneServices : BaseServices.OprateSuccess("课程场景_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now) + ".xlsx", physicsPath1); return result; } - public override async Task> ImportExcel(IFormFile file) + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { var data = new ExcelData(); long id = SnowFlakeSingle.instance.getID(); diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index 375b6578..7a5d32ea 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -691,7 +691,7 @@ public class Ghre_CourseServices : BaseServices.OprateSuccess("课程管理_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now) + ".xlsx", physicsPath1); return result; } - public override async Task> ImportExcel(IFormFile file) + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { var data = new ExcelData(); long id = SnowFlakeSingle.instance.getID(); diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs index 577d7480..53507260 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamRecordServices.cs @@ -1,4 +1,5 @@ using AgileObjects.AgileMapper.Extensions; +using Amazon.Auth.AccessControlPolicy; using MongoDB.Driver.Linq; using System.Net; using System.Text.RegularExpressions; @@ -1018,4 +1019,231 @@ public class Ghre_ExamRecordServices : BaseServices> DownloadExcel(string menuName) + { + var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; + var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}ExcelTemplate{Path.DirectorySeparatorChar}"}"; + if (!Directory.Exists(physicsPath + path)) + Directory.CreateDirectory(physicsPath + path); + + Type entityType = typeof(Ghre_ExamRecord); + var fileName = entityType.GetEntityTableName() + ".xlsx"; + + + var physicsPath1 = physicsPath + path + fileName; + //if (dataSourceLists.Any()) + // physicsPath1 = physicsPath + path + newFileName; + var result = ServiceResult.OprateSuccess("考试成绩_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now) + ".xlsx", physicsPath1); + return result; + } + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) + { + var data = new ExcelData(); + long id = SnowFlakeSingle.instance.getID(); + var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; + var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}import{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}"; + if (!Directory.Exists(physicsPath + path)) + Directory.CreateDirectory(physicsPath + path); + + var filepath = physicsPath + path + file.FileName; + using (var stream = File.Create(filepath)) + { + await file.CopyToAsync(stream); + } + string extension = Path.GetExtension(filepath); + + bool isExistError = false; + var id1 = SnowFlakeSingle.instance.getID(); + string errorFileName = path + SnowFlakeSingle.instance.getID() + extension; + + var dt = NPOIHelper.ImportExcel(filepath, "考试成绩"); + if (dt.Columns["Comments"] == null) + dt.Columns.Add("Comments", typeof(string)); + + var fields = new List + { + "工号", + "姓名", + "考试日期", + "考试分数", + "调整分", + "实操分", + "是否合格", + "备注" + }; + for (int i = 0; i < dt.Rows.Count; i++) + { + var comments = new List(); + + + bool isContinue = false; + + fields.ForEach(x => + { + if (!dt.Columns.Contains(x)) + { + comments.Add("未查询到【" + x + "】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + }); + + if (isContinue) + continue; + + var StaffNo = dt.Rows[i]["工号"].ToString(); + var StaffName = dt.Rows[i]["姓名"].ToString(); + var ExamDate = dt.Rows[i]["考试日期"].ToString(); + var Score = dt.Rows[i]["考试分数"].ToString(); + var AdjustScore = dt.Rows[i]["调整分"].ToString(); + var ActualScore = dt.Rows[i]["实操分"].ToString(); + var IsPass = dt.Rows[i]["是否合格"].ToString(); + + if (StaffNo.IsNullOrEmpty() && StaffName.IsNullOrEmpty()) + continue; + + var remarkSz = dt.Rows[i]["备注"].ToString(); + + var staff = await Db.Queryable().Where(x => x.StaffNo == StaffNo && x.StaffName == StaffName).FirstAsync(); + if (staff == null) + { + comments.Add($"未查询到该员工,工号或姓名填写错误!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + var exam = await Db.Queryable().Where(x => x.Id == MasterId).FirstAsync(); + + + + if (ExamDate.IsNullOrEmpty()) + ExamDate = DateTime.Now.ToString(); + if (Score.IsNullOrEmpty()) + Score = "0"; + + try + { + Convert.ToInt32(Score); + } + catch (Exception) + { + comments.Add($"考试分数填写有误!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + try + { + Convert.ToInt32(AdjustScore); + } + catch (Exception) + { + comments.Add($"调整分填写有误!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + try + { + Convert.ToInt32(ActualScore); + } + catch (Exception) + { + comments.Add($"实操分填写有误!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + try + { + Convert.ToDateTime(ExamDate); + } + catch (Exception) + { + comments.Add($"考试日期填写有误!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + //if (await base.AnyAsync(x => x.CertificateRuleId == rule.Id && x.StaffId == staff.StaffID && x.CourseId == course.Id)) + //{ + // comments.Add($"系统已存在相同证照数据!"); + // data.ErrorCount++; + // dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + // isExistError = true; + // continue; + //} + var snap = await Db.Queryable().FirstAsync(x => x.CourseId == exam.CourseId); + var ExamRecordId = SnowFlakeSingle.Instance.NextId(); + var StudyRecordId = SnowFlakeSingle.Instance.NextId(); + var dict1 = new Dictionary + { + { "Id", StudyRecordId }, + { "CreateBy", App.User.ID }, + { "CreateTime", DateTime.Now }, + { "ExamId", MasterId }, + { "StaffId", staff.StaffID }, + { "CourseId", exam.CourseId }, + { "CourseSnapId", snap?.Id }, + { "CourseSceneId", exam.CourseSceneId }, + { "JoinTime", DateTime.Now }, + { "RemarkSz", "导入考试成绩生成" } + }; + var dict = new Dictionary + { + { "Id", ExamRecordId }, + { "CreateBy", App.User.ID }, + { "CreateTime", DateTime.Now }, + { "ExamId", MasterId }, + { "StudyRecordId", StudyRecordId }, + { "StaffId", staff.StaffID }, + //{ "CourseId", exam.CourseId }, + { "CourseSnapId", snap?.Id }, + { "Score", Score }, + { "AdjustScore", Score }, + { "ActualScore", ActualScore }, + { "ExamDate", ExamDate }, + { "IsPass", IsPass=="是"?true:false }, + { "ScoreStatus", "HasScore" }, + { "Source", "ExcelImport" }, + { "ExamPaperId",exam.ExamPaperId }, + { "RemarkSz", remarkSz } + }; + try + { + await Db.Insertable(dict1).AS("Ghre_StudyRecord").ExecuteCommandAsync(); + await Db.Insertable(dict).AS("Ghre_ExamRecord").ExecuteCommandAsync(); + data.SuccessCount++; + //data.SuccessCount += list.Count; + } + catch (Exception E) + { + comments.Add(E.Message); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + + } + + if (isExistError) + { + NPOIHelper.ExportExcel(dt, null, "考试成绩", physicsPath + errorFileName); + data.filePath = errorFileName; + } + return ServiceResult.OprateSuccess("导入成功!", data); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index f9493f24..47bc596f 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -782,7 +782,7 @@ public class Ghre_QuestionServices : BaseServices> ImportExcel(IFormFile file) + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { var data = new ExcelData(); long id = SnowFlakeSingle.instance.getID(); diff --git a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs index 729f583d..fd1ea398 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs @@ -434,7 +434,7 @@ public class Ghre_StudyRecordServices : BaseServices> ImportExcel(IFormFile file) + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { var data = new ExcelData(); long id = SnowFlakeSingle.instance.getID(); diff --git a/Tiobon.Core.Services/Ghrh/Ghrh_YearHumanSettingsServices.cs b/Tiobon.Core.Services/Ghrh/Ghrh_YearHumanSettingsServices.cs index 15fa77c6..cf15e2b1 100644 --- a/Tiobon.Core.Services/Ghrh/Ghrh_YearHumanSettingsServices.cs +++ b/Tiobon.Core.Services/Ghrh/Ghrh_YearHumanSettingsServices.cs @@ -164,7 +164,7 @@ public class Ghrh_YearHumanSettingsServices : BaseServices> ImportExcel(IFormFile file) + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { var data = new ExcelData(); long id = SnowFlakeSingle.instance.getID();