From 31cf16415f7be0e65ce146a0c5d6ab8d0a7672d6 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Wed, 19 Feb 2025 15:14:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E5=BA=93=E5=AF=B9=E5=BA=94=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E5=90=8D=E7=A7=B0=E5=8F=AF=E4=BB=A5=E5=A4=9A=E9=80=89?= =?UTF-8?q?=EF=BC=8C=E4=B8=94=E5=90=8C=E4=B8=80=E8=AF=95=E9=A2=98=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E4=B8=8D=E5=90=8C=E8=AF=BE=E7=A8=8B=EF=BC=8C=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E5=91=88=E7=8E=B0=E5=9C=A8=E7=9B=B8=E5=90=8C=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=A0=BC=20=E9=A2=98=E5=BA=93=E2=80=94=E2=80=94?= =?UTF-8?q?=E3=80=90=E8=AF=BE=E7=A8=8B=E5=88=86=E7=B1=BB=E3=80=91=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E9=9A=90=E8=97=8F=EF=BC=8C=E5=8F=A6=E5=A4=96=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E3=80=90=E8=AF=BE=E7=A8=8B=E5=88=86=E7=B1=BB=E3=80=91?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E6=9D=A1=E4=BB=B6=20=E5=9F=B9=E8=AE=AD?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E6=96=B0=E5=A2=9EExcel=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tiobon.Core.Api/Tiobon.Core.Model.xml | 10 + Tiobon.Core.DataAccess/ReportHelper.cs | 9 +- .../Base/Ghre/Ghre_Question.Dto.Base.cs | 11 +- .../Models/Ghre/Ghre_Question.cs | 11 +- .../View/Ghre/Ghre_Question.Dto.View.cs | 2 +- Tiobon.Core.Services/BASE/BaseServices.cs | 2 +- .../Ghre/Ghre_QuestionServices.cs | 233 +++++++++++------- .../Ghre/Ghre_RequestServices.cs | 188 +++++++++++++- .../Ghre/Ghre_StaffGroupServices.cs | 8 +- Tiobon.Core/Tiobon.Core.Model.xml | 10 + 10 files changed, 373 insertions(+), 111 deletions(-) diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml index 52ad6bc8..06637722 100644 --- a/Tiobon.Core.Api/Tiobon.Core.Model.xml +++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml @@ -5665,6 +5665,11 @@ 预留字段12 + + + 课程Ids + + 题目答案 (Dto.Base) @@ -20691,6 +20696,11 @@ 预留字段12 + + + 课程Ids + + 题目答案 (Model) diff --git a/Tiobon.Core.DataAccess/ReportHelper.cs b/Tiobon.Core.DataAccess/ReportHelper.cs index 92109734..28d2075a 100644 --- a/Tiobon.Core.DataAccess/ReportHelper.cs +++ b/Tiobon.Core.DataAccess/ReportHelper.cs @@ -6,6 +6,7 @@ using NPOI.POIFS.NIO; using NPOI.SS.Formula.Functions; using NPOI.SS.UserModel; using NPOI.SS.Util; +using NPOI.Util.Collections; using NPOI.XSSF.UserModel; using SqlSugar; using System; @@ -920,12 +921,18 @@ public static class ReportHelper dict.Add(x.field, id2); } } - else if (x.dataSource == "OrgTreeWithoutPriv") + else if (x.dataSource == "OrgTreeWithPriv") { string sql = @$"SELECT DeptID FROM Ghro_Dept WHERE DeptName = '{value}' OR DeptNo = '{value}' OR DeptEname = '{value}'"; var id2 = await Db.Ado.GetLongAsync(sql); dict.Add(x.field, id2); } + else if (x.dataSource == "StaffWithoutPriv") + { + string sql = @$"SELECT StaffID FROM Ghra_Staff WHERE StaffName = '{value}' OR StaffNo = '{value}' OR StaffEname = '{value}'"; + var id2 = await Db.Ado.GetLongAsync(sql); + dict.Add(x.field, id2); + } else dict.Add(x.field, value); } diff --git a/Tiobon.Core.Model/Base/Ghre/Ghre_Question.Dto.Base.cs b/Tiobon.Core.Model/Base/Ghre/Ghre_Question.Dto.Base.cs index fc48212e..7587b4da 100644 --- a/Tiobon.Core.Model/Base/Ghre/Ghre_Question.Dto.Base.cs +++ b/Tiobon.Core.Model/Base/Ghre/Ghre_Question.Dto.Base.cs @@ -6,9 +6,9 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -*V0.01 2024/4/28 15:54:29 SimonHsiao 初版 +*V0.01 2025/2/19 10:56:52 SimonHsiao 初版 * -* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved. +* Copyright(c) 2025 Tiobon Corporation. All Rights Reserved. *┌──────────────────────────────────┐ *│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │ *│ 作者:SimonHsiao │ @@ -26,7 +26,6 @@ public class Ghre_QuestionBase /// /// 课程Id /// - [Display(Name = "CourseIds"), Description("课程Id")] public long? CourseId { get; set; } /// @@ -139,4 +138,10 @@ public class Ghre_QuestionBase /// 预留字段12 /// public int? ReverseI2 { get; set; } + + /// + /// 课程Ids + /// + [Display(Name = "CourseIds"), Description("课程Ids"), MaxLength(2000, ErrorMessage = "课程Ids 不能超过 2000 个字符")] + public string CourseIds { get; set; } } diff --git a/Tiobon.Core.Model/Models/Ghre/Ghre_Question.cs b/Tiobon.Core.Model/Models/Ghre/Ghre_Question.cs index 0a6d6733..dbfb63d5 100644 --- a/Tiobon.Core.Model/Models/Ghre/Ghre_Question.cs +++ b/Tiobon.Core.Model/Models/Ghre/Ghre_Question.cs @@ -6,9 +6,9 @@ * * Ver 变更日期 负责人 变更内容 * ─────────────────────────────────── -*V0.01 2024/4/28 15:54:29 SimonHsiao 初版 +*V0.01 2025/2/19 10:56:52 SimonHsiao 初版 * -* Copyright(c) 2024 Tiobon Corporation. All Rights Reserved. +* Copyright(c) 2025 Tiobon Corporation. All Rights Reserved. *┌──────────────────────────────────┐ *│ 此技术信息为本公司机密信息,未经本公司书面同意禁止向第三方披露. │ *│ 作者:SimonHsiao │ @@ -27,7 +27,6 @@ public class Ghre_Question : BasePoco /// /// 课程Id /// - [Display(Name = "CourseIds"), Description("课程Id")] public long? CourseId { get; set; } /// @@ -140,4 +139,10 @@ public class Ghre_Question : BasePoco /// 预留字段12 /// public int? ReverseI2 { get; set; } + + /// + /// 课程Ids + /// + [Display(Name = "CourseIds"), Description("课程Ids"), MaxLength(2000, ErrorMessage = "课程Ids 不能超过 2000 个字符")] + public string CourseIds { get; set; } } diff --git a/Tiobon.Core.Model/View/Ghre/Ghre_Question.Dto.View.cs b/Tiobon.Core.Model/View/Ghre/Ghre_Question.Dto.View.cs index ee09cd01..f0fb4d8f 100644 --- a/Tiobon.Core.Model/View/Ghre/Ghre_Question.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghre/Ghre_Question.Dto.View.cs @@ -32,7 +32,7 @@ public class Ghre_QuestionDto : Ghre_Question //public long CourseTypeId { get; set; } public string CourseClassId { get; set; } - + public string CourseType { get; set; } diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 84912332..fdb2e9b3 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -950,7 +950,7 @@ public class BaseServices : IBaseServ } return result; } - public async virtual Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) + public virtual async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) { var data = new ExcelData(); var (path, filepath) = await ReportHelper.GetImportFilePath(file, menuName); diff --git a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs index d57f07cd..5bdfde09 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_QuestionServices.cs @@ -1,5 +1,4 @@ -using Microsoft.IdentityModel.Tokens; -using NPOI.HSSF.UserModel; +using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.SS.Util; using NPOI.XSSF.UserModel; @@ -188,6 +187,44 @@ public class Ghre_QuestionServices : BaseServices(value); + + if (jsonParam.columnValue != null) + { + + switch (jsonParam.operationKey) + { + case "Include": + conditions += @$" AND EXISTS + (SELECT 1 + FROM Ghre_Course Course + WHERE IsEnable = 1 + AND {jsonParam.columnValue} IN + (SELECT value FROM openjson (CourseClassId)) + AND Course.Id IN + (SELECT value FROM openjson (A.CourseIDs)))"; + break; + case "NotInclude": + if (jsonParam.columnValue != null) + conditions += @$" AND NOT EXISTS + (SELECT 1 + FROM Ghre_Course Course + WHERE IsEnable = 1 + AND {jsonParam.columnValue} IN + (SELECT value FROM openjson (CourseClassId)) + AND Course.Id IN + (SELECT value FROM openjson (A.CourseIDs)))"; + break; + break; + default: + break; + } + } + continue; + } + if (!string.IsNullOrWhiteSpace(value)) conditions = DealConditions(conditions, name, value); @@ -196,25 +233,33 @@ public class Ghre_QuestionServices : BaseServices(sql) .OrderBy(filter.orderBy) .ToPageListAsync(filter.pageNum, filter.pageSize, totalCount); - var classsIds1 = data.Select(x => x.CourseClassId).Distinct().ToList(); - var classsIds = new List(); - - classsIds1.ForEach(x => + var courseIds = new List(); + data.ForEach(x => { - if (!string.IsNullOrWhiteSpace(x)) - { - var courseClassIds = JsonConvert.DeserializeObject>(x); - classsIds = classsIds.Concat(courseClassIds).ToList(); - } + if (x.CourseIds.IsNotEmptyOrNull()) + courseIds.AddRange(JsonHelper.JsonToObj>(x.CourseIds)); }); - classsIds = classsIds.Distinct().ToList(); - var classs = await _ghre_CourseClassServices.Query(x => classsIds.Contains(x.Id)); + courseIds = courseIds.Distinct().ToList(); + //var classsIds1 = data.Select(x => x.CourseClassId).Distinct().ToList(); + //var classsIds = new List(); + + //classsIds1.ForEach(x => + //{ + // if (!string.IsNullOrWhiteSpace(x)) + // { + // var courseClassIds = JsonConvert.DeserializeObject>(x); + // classsIds = classsIds.Concat(courseClassIds).ToList(); + // } + //}); + //classsIds = classsIds.Distinct().ToList(); + var courses = await _ghre_CourseServices.Query(x => courseIds.Contains(x.Id)); data.ForEach(async x => { @@ -222,8 +267,8 @@ public class Ghre_QuestionServices : BaseServices x.CourseClassId.Contains(a.Id.ToString())).ToList(); - x.CourseType = string.Join(",", courseClass.Select(a => a.ClassName + " (" + a.ClassNo + ")")); + var courseClass = courses.Where(a => x.CourseIds.Contains(a.Id.ToString())).ToList(); + x.CourseName = string.Join(",", courseClass.Select(a => a.CourseName + " (" + a.CourseNo + ")")); }); @@ -267,7 +312,6 @@ public class Ghre_QuestionServices : BaseServices { new FromGhre_QuestionQuestionAnswerList() @@ -370,7 +414,7 @@ public class Ghre_QuestionServices : BaseServices x.isActive = 0); data.PageData.baseData.questionNo = question.QuestionNo; - data.PageData.baseData.courseID.Add(question.CourseId); + data.PageData.baseData.courseID = JsonHelper.JsonToObj>(question.CourseIds); data.PageData.baseData.CreateDataInfo = question.CreateDataInfo; data.PageData.baseData.UpdateDataInfo = question.UpdateDataInfo; @@ -442,47 +486,48 @@ public class Ghre_QuestionServices : BaseServices new InsertGhre_QuestionAnswerInput() - { - QuestionNo = x.No, - AnswerContent = x.label, - ImageUrl = x.imageUrl, - ImageWidthPc = x.imgWidthPc, - ImageWidthApp = x.imgWidthApp, - }).ToList(); - int i = 100; - insertAnswers.ForEach(x => - { - x.TaxisNo = i; - x.QuestionId = id; - if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) - x.IsCorrect = true; - if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) - x.IsCorrect = true; - i = i + 100; - }); - - if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent) && string.IsNullOrWhiteSpace(b.ImageUrl)).Any()) - throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); - if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) - throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); - await _ghre_QuestionAnswerServices.Add(insertAnswers); - } + var insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() + { + QuestionNo = x.No, + AnswerContent = x.label, + ImageUrl = x.imageUrl, + ImageWidthPc = x.imgWidthPc, + ImageWidthApp = x.imgWidthApp, + }).ToList(); + int i = 100; + insertAnswers.ForEach(x => + { + x.TaxisNo = i; + x.QuestionId = id; + if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) + x.IsCorrect = true; + if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) + x.IsCorrect = true; + i = i + 100; + }); + + if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent) && string.IsNullOrWhiteSpace(b.ImageUrl)).Any()) + throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); + if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) + throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); + await _ghre_QuestionAnswerServices.Add(insertAnswers); + //} await Db.Ado.CommitTranAsync(); return ServiceResult.OprateSuccess("新增成功!"); } @@ -576,49 +621,49 @@ public class Ghre_QuestionServices : BaseServices new InsertGhre_QuestionAnswerInput() - { - QuestionNo = x.No, - AnswerContent = x.label, - ImageUrl = x.imageUrl, - ImageWidthPc = x.imgWidthPc, - ImageWidthApp = x.imgWidthApp, - }).ToList(); - i = 100; - insertAnswers.ForEach(x => - { - x.TaxisNo = i; - x.QuestionId = id; - if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) - x.IsCorrect = true; - if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) - x.IsCorrect = true; - i = i + 100; - }); - if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent)).Any()) - throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); - if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) - throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); - - await _ghre_QuestionAnswerServices.Add(insertAnswers); - } + insertAnswers = questionType.detail.answerList.Select(x => new InsertGhre_QuestionAnswerInput() + { + QuestionNo = x.No, + AnswerContent = x.label, + ImageUrl = x.imageUrl, + ImageWidthPc = x.imgWidthPc, + ImageWidthApp = x.imgWidthApp, + }).ToList(); + i = 100; + insertAnswers.ForEach(x => + { + x.TaxisNo = i; + x.QuestionId = id; + if (questionType.detail.answer != null && questionType.detail.answer == x.QuestionNo && (insert.QuestionType == "Single" || insert.QuestionType == "TrueOrFalse")) + x.IsCorrect = true; + if (questionType.detail.answer1 != null && questionType.detail.answer1.Contains(x.QuestionNo) && (insert.QuestionType == "ShortAnswer" || insert.QuestionType == "Multiple" || insert.QuestionType == "Completion")) + x.IsCorrect = true; + i = i + 100; + }); + if (insertAnswers.Where(b => string.IsNullOrWhiteSpace(b.AnswerContent)).Any()) + throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词存在空值!" : "答案选项存在空值!"); + if (!insertAnswers.Where(b => b.IsCorrect == true).Any()) + throw new Exception(insert.QuestionType == "ShortAnswer" ? "关键词未填写!" : "正确答案未标记!"); + + await _ghre_QuestionAnswerServices.Add(insertAnswers); + //} await Db.Ado.CommitTranAsync(); return ServiceResult.OprateSuccess("更新成功!"); diff --git a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs index eec02991..eec562d9 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_RequestServices.cs @@ -1,4 +1,6 @@ -using Serilog; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using Serilog; +using System.Collections.Generic; using static Tiobon.Core.Model.Consts; namespace Tiobon.Core.Services; @@ -323,6 +325,190 @@ FROM Ghre_Request A } + #region Excel导入 + + public static async Task<(List>, int)> ValidImportExcel(ISqlSugarClient Db, List columns, DataTable dt) + { + Type entityType = typeof(Ghre_Request); + var properties = entityType.GetGenericProperties(); + int ErrorCount = 0; + var dictList = new List>(); + for (int i = 0; i < dt.Rows.Count; i++) + { + var dict = ReportHelper.GetDefaultDict(); + var comments = new List(); + for (int j = 0; j < columns.Count; j++) + { + var x = columns[j]; + if (!dt.Columns.Contains(x.label)) + comments.Add("未查询到【" + x.label + "】列!"); + else + { + var value = dt.Rows[i][x.label].ToString(); + var courseSource = dt.Rows[i]["课程来源"].ToString(); + if (x.label == "需求课程" || x.label == "新增课程") + { + if (x.label == "需求课程" && courseSource == "已有课程" && value.IsNullOrEmpty()) + { + comments.Add(x.label + "不能为空!"); + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + } + else if (x.label == "新增课程" && courseSource == "新增课程" && value.IsNullOrEmpty()) + { + comments.Add(x.label + "不能为空!"); + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + } + } + else + if (x.required == "true" && value.IsNullOrEmpty()) + { + comments.Add(x.label + "不能为空!"); + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + } + + if (x.dataSourceType.IsNullOrEmpty() && value.IsNotEmptyOrNull()) + { + if (x.dataType == "int" || x.dataType == "decimal") + { + try + { + Convert.ToDecimal(value); + } + catch (Exception) + { + comments.Add(x.label + "无效的数字类型!"); + } + } + else if (x.dataType == "date") + { + try + { + Convert.ToDateTime(value); + } + catch (Exception) + { + comments.Add(x.label + "无效的日期类型!"); + } + } + } + + if (value.IsNotEmptyOrNull()) + { + if (x.field == "TrainStaffIds") + { + value = value.Replace(",", ","); + value = value.Replace(";", ","); + value = value.Replace(";", ","); + var value1 = value.Split(',').ToList(); + var ids = await Db.Queryable().Where(o => value1.Contains(o.StaffName) || value1.Contains(o.StaffNo) || value1.Contains(o.StaffEname)).Select(x => x.StaffID).ToListAsync(); + dict.Add("TrainStaffId", JsonHelper.ObjToJson(ids)); + } + else + { + if (x.elementType == "Switch") + value = value == "是" ? "true" : "false"; + if (x.dataSourceId.IsNotEmptyOrNull() && x.dataSourceType.IsNotEmptyOrNull() && !x.dataSource.StartsWith("OrgTreeWith") + && !x.dataSource.StartsWith("StaffWith")) + { + + if (x.dataSourceType == "CommonList") + { + var commonSql = await Db.Queryable().Where(o => o.ListCommonSqlId == x.dataSourceId).FirstAsync(); + + if (commonSql != null) + { + string sql = @$"SELECT [value] + FROM ({commonSql.SelectSql}) A + WHERE label = '{value}'"; + sql = sql.Replace("{@LangID}", "1"); + sql = sql.Replace("{@UserID}", App.User.ID.ObjToString()); + sql = sql.Replace("{@KeyWords}", null); + var id2 = await Db.Ado.GetLongAsync(sql); + if (properties.Any(o => o.Name == x.field)) + dict.Add(x.field, id2); + } + } + else if (x.dataSourceType == "ParaDetailNo") + { + var sql = @$"SELECT ParaDetailNo + FROM Ghrs_ParaDetail + WHERE ParaMasterId IN (SELECT ParaMasterId + FROM Ghrs_ParaMaster + WHERE ParaMasterId = {x.dataSourceId.ObjToInt()}) + AND IsEnable = 1 + AND ParaDetailName = '{value}'"; + var id2 = await Db.Ado.GetStringAsync(sql); + + if (properties.Any(o => o.Name == x.field)) + dict.Add(x.field, id2); + } + } + else if (x.dataSource == "OrgTreeWithPriv") + { + string sql = @$"SELECT DeptID FROM Ghro_Dept WHERE DeptName = '{value}' OR DeptNo = '{value}' OR DeptEname = '{value}'"; + var id2 = await Db.Ado.GetLongAsync(sql); + if (properties.Any(o => o.Name == x.field)) + dict.Add(x.field, id2); + } + else if (x.dataSource == "StaffWithoutPriv") + { + string sql = @$"SELECT StaffID FROM Ghra_Staff WHERE StaffName = '{value}' OR StaffNo = '{value}' OR StaffEname = '{value}'"; + var id2 = await Db.Ado.GetLongAsync(sql); + if (properties.Any(o => o.Name == x.field)) + dict.Add(x.field, id2); + } + else + { + if (properties.Any(o => o.Name == x.field)) + dict.Add(x.field, value); + + } + } + } + } + } + if (comments.Any()) + { + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + ErrorCount++; + continue; + } + else + dictList.Add(dict); + } + + return (dictList, ErrorCount); + } + public override async Task> ImportExcel(IFormFile file, string menuName = null, long? MasterId = null) + { + var data = new ExcelData(); + var (path, filepath) = await ReportHelper.GetImportFilePath(file, menuName); + var id1 = SnowFlakeSingle.instance.getID(); + string errorFileName = path + SnowFlakeSingle.instance.getID() + FileHelper.GetPostfixStr(filepath); + + var dt = ReportHelper.ReadImportExcel(filepath); + var columns = await QueryExportColumn(menuName); + + var (dictList, errorCount) = await ValidImportExcel(Db, columns, dt); + Type entityType = typeof(Ghre_Request); + var properties = entityType.GetGenericProperties(); + if (errorCount > 0) + { + NPOIHelper.ExportExcel(dt, null, "导入数据", FileHelper.GetPhysicsPath() + errorFileName); + data.filePath = "/Advanced" + errorFileName; + data.ErrorCount = errorCount; + } + else + { + await Db.Insertable(dictList).AS(entityType.GetEntityTableName()).ExecuteCommandAsync(); + + data.SuccessCount = dictList.Count; + } + + return ServiceResult.OprateSuccess("导入成功!", data); + } + #endregion + #region 牛尾培训需求同步 public async Task Ushio_Sync() diff --git a/Tiobon.Core.Services/Ghre/Ghre_StaffGroupServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StaffGroupServices.cs index cc73c863..0534fc84 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StaffGroupServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StaffGroupServices.cs @@ -1,10 +1,4 @@ -using NPOI.SS.Formula.Functions; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using Tiobon.Core.Model; - -namespace Tiobon.Core.Services; +namespace Tiobon.Core.Services; /// /// 员工群组 (服务) diff --git a/Tiobon.Core/Tiobon.Core.Model.xml b/Tiobon.Core/Tiobon.Core.Model.xml index 52ad6bc8..06637722 100644 --- a/Tiobon.Core/Tiobon.Core.Model.xml +++ b/Tiobon.Core/Tiobon.Core.Model.xml @@ -5665,6 +5665,11 @@ 预留字段12 + + + 课程Ids + + 题目答案 (Dto.Base) @@ -20691,6 +20696,11 @@ 预留字段12 + + + 课程Ids + + 题目答案 (Model)