diff --git a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeEduBG.Dto.View.cs b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeEduBG.Dto.View.cs index b05c722a..6e5f9e6a 100644 --- a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeEduBG.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeEduBG.Dto.View.cs @@ -39,7 +39,8 @@ public class Ghrh_ResumeEduBGDto : Ghrh_ResumeEduBG public string EndDate1 { get; set; } public string IsGraduateLabel { get; set; } - + public string StaffName { get; set; } public List AttachmentIDs { get; set; } + } diff --git a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeHome.Dto.View.cs b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeHome.Dto.View.cs index ab22799b..638af21f 100644 --- a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeHome.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeHome.Dto.View.cs @@ -44,6 +44,7 @@ public class Ghrh_ResumeHomeDto : Ghrh_ResumeHome /// 关系 /// public string RelationTypeLabel { get; set; } + public string StaffName { get; set; } diff --git a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeLicence.Dto.View.cs b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeLicence.Dto.View.cs index f48fdc22..2f4c9306 100644 --- a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeLicence.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeLicence.Dto.View.cs @@ -43,5 +43,6 @@ public class Ghrh_ResumeLicenceDto : Ghrh_ResumeLicence /// 失效日 /// public string EndDate1 { get; set; } + public string StaffName { get; set; } } diff --git a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeTraining.Dto.View.cs b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeTraining.Dto.View.cs index b2149e73..34b339ae 100644 --- a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeTraining.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeTraining.Dto.View.cs @@ -48,4 +48,5 @@ public class Ghrh_ResumeTrainingDto : Ghrh_ResumeTraining /// 合格 /// public string IsPassLabel { get; set; } + public string StaffName { get; set; } } diff --git a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeWorkExp.Dto.View.cs b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeWorkExp.Dto.View.cs index ba6c1be9..de58fd65 100644 --- a/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeWorkExp.Dto.View.cs +++ b/Tiobon.Core.Model/View/Ghrh/Ghrh_ResumeWorkExp.Dto.View.cs @@ -40,4 +40,5 @@ public class Ghrh_ResumeWorkExpDto : Ghrh_ResumeWorkExp public List AttachmentIDs { get; set; } + public string StaffName { get; set; } } diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index 7c95cb94..ae0917af 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -812,6 +812,8 @@ public partial class CommonServices : BaseServices>, ICommon if (x.multipleSearchValue == "true") x.searchColumnDefaultValue = new List(); + if (x.isPrimaryKey == "false") + x.isPrimaryKey = null; }); Db.Ado.CommitTran(); diff --git a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeEduBGServices.cs b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeEduBGServices.cs index 703975f7..d54fd9f7 100644 --- a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeEduBGServices.cs +++ b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeEduBGServices.cs @@ -32,15 +32,49 @@ public class Ghrh_ResumeEduBGServices : BaseServices + /// 字典映射、全称、单位转换等 + /// + /// + private async Task SetLabel(Ghrh_ResumeEduBGDto x) + { + if (x != null) + { if (x.IsGraduate != null) x.IsGraduateLabel = x.IsGraduate == true ? "是" : "否"; x.DegreeLevelLabel = await GetParaLabel("EducationalBGLevel", x.DegreeLevel); x.BeginDate1 = DateTimeHelper.ConvertToDayString(x.BeginDate); x.EndDate1 = DateTimeHelper.ConvertToDayString(x.EndDate); + } + } + #endregion + + #region 查询 + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + { + var result = await base.QueryFilterPage(filter, condition, IsEnable); + var list = result.result.DT_TableDataT1; + + var resumeIds = list.Where(x => x.ResumeId != null).Select(x => x.ResumeId.Value).ToList(); + var resumes = await Db.Queryable().Where(x => resumeIds.Contains(x.Id)).ToListAsync(); + + list.ForEach(async x => + { + await SetLabel(x); + x.StaffName = resumes.Where(o => x.ResumeId == o.Id).FirstOrDefault()?.StaffName; }); - return data; + + return result; + } + #endregion + public override async Task> Add(List listEntity) { var result = new List(); @@ -59,4 +93,251 @@ public class Ghrh_ResumeEduBGServices : BaseServices> QueryResumeFormColumn(long resumeTemplateID = 0) + { + resumeTemplateID = await Db.Ado.GetLongAsync("select top 1 Id from Ghrh_ResumeTemplate where IsEnable=1 and IsPublish=1"); + var sql = @$"DECLARE @ResumeTemplateID BIGINT = {resumeTemplateID} + + SELECT A.ColumnName, A.ResumeInfoColumnName ColumnNameDesc, D.GroupType, A.MapTableName, A.MapColumnName, +A.DataType, A.ColumnType, A.IsRequired, A.DataSourceType, A.DataSource, A.DataSourceID + FROM Ghrh_ResumeInfoColumn A + LEFT JOIN Ghrh_ResumeTemplateInfoGroupColumn B + ON B.ResumeInfoColumnID = A.ID + AND B.IsDisplay = 1 + AND B.IsEnable = 1 + AND A.IsEnable = 1 + JOIN Ghrh_ResumeTemplateInfoGroup C + ON B.ResumeTemplateInfoGroupID = C.Id + JOIN Ghrh_ResumeInfoGroup D + ON C.ResumeInfoGroupId = D.ID AND D.IsEnable = 1 + WHERE C.ResumeTemplateID = @ResumeTemplateID + AND D.GroupType = 'Education' and b.StaffInfoColumnNo !='AttachmentIDs' + ORDER BY D.GroupType, b.SortNo"; + + return await Db.Ado.SqlQueryAsync(sql); + } + + #region Excel导入 + public override async Task> 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_Teacher); + + DataTable dt = new DataTable("TempTable"); + + var formColumns = await QueryResumeFormColumn(); + string fileName = path + SnowFlakeSingle.instance.getID() + ".xlsx"; + dt.Columns.Add("姓名", typeof(string)); + formColumns + .ToList() + .ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + dt.Columns.Add(x.ColumnNameDesc, typeof(string)); + }); + + var dr = dt.NewRow(); + dt.Rows.Add(dr); + NPOIHelper.ExportExcel(dt, null, "教育背景", physicsPath + fileName); + + var physicsPath1 = physicsPath + 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 formColumns = await QueryResumeFormColumn(); + + for (int i = 0; i < dt.Rows.Count; i++) + { + var comments = new List(); + bool isContinue = false; + + var dict = new Dictionary + { + { "Id", SnowFlakeSingle.Instance.NextId() }, + { "CreateBy", App.User.ID }, + { "CreateTime", DateTime.Now }, + { "UpdateTime", DateTime.Now } + }; + if (!dt.Columns.Contains("姓名")) + { + comments.Add("未查询到【姓名】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + + formColumns.ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + { + comments.Add("未查询到【" + x.ColumnNameDesc + "】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + }); + + if (isContinue) + continue; + + for (int j = 0; j < formColumns.Count; j++) + { + var column = formColumns[j]; + var value = dt.Rows[i][column.ColumnNameDesc].ToString(); + if (column.IsRequired == true && value.IsNullOrEmpty()) + { + comments.Add(column.ColumnNameDesc + "不能为空!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + if (column.DataSourceType.IsNullOrEmpty()) + { + if (column.DataType == "int" || column.DataType == "decimal") + { + try + { + Convert.ToInt64(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的数字类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + else if (column.DataType == "date") + { + try + { + Convert.ToDateTime(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的日期类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + } + + + if (value.IsNotEmptyOrNull()) + { + if (column.ColumnType == "Switch") + value = value == "是" ? "true" : "false"; + if (column.DataSource.IsNotEmptyOrNull() && column.DataSourceType.IsNotEmptyOrNull()) + { + + if (column.DataSourceType == "CommonList") + { + var commonSql = await Db.Queryable().Where(x => x.ListCommonSqlId == column.DataSource.ObjToInt()).FirstAsync(); + + if (commonSql != null) + { + string sql = @$"SELECT [value] + FROM ({commonSql.SelectSql}) A + WHERE label = '{value}'"; + sql = sql.Replace("{@LangID}", "1"); + var id2 = await Db.Ado.GetLongAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else if (column.DataSourceType == "ParaDetailNo") + { + var sql = @$"SELECT ParaDetailNo + FROM Ghrs_ParaDetail + WHERE ParaMasterId IN (SELECT ParaMasterId + FROM Ghrs_ParaMaster + WHERE ParaMasterId = {column.DataSource.ObjToInt()}) + AND IsEnable = 1 + AND ParaDetailName = '{value}'"; + var id2 = await Db.Ado.GetStringAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else + dict.Add(column.ColumnName, value); + } + + } + + var StaffName = dt.Rows[i]["姓名"].ToString(); + + var resume = await Db.Queryable().Where(x => x.StaffName == StaffName || x.StaffEname == StaffName).FirstAsync(); + if (resume is null) + { + comments.Add("未查询到【" + StaffName + "】相关数据!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + else dict.Add("ResumeId", resume.Id); + if (isExistError) + continue; + try + { + await Db.Insertable(dict).AS("Ghrh_ResumeEduBG").ExecuteCommandAsync(); + data.SuccessCount++; + } + 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 = "/Advanced" + errorFileName; + } + + return ServiceResult.OprateSuccess("导入成功!", data); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeHomeServices.cs b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeHomeServices.cs index c73475d2..8705cd02 100644 --- a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeHomeServices.cs +++ b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeHomeServices.cs @@ -21,8 +21,7 @@ public class Ghrh_ResumeHomeServices : BaseServices { - x.GenderLabel = await GetParaLabel("Gender", x.Gender); - x.RelationTypeLabel = await GetParaLabel("SocialRelationType", x.RelationType); + await SetLabel(x); x.AttachmentIDs = attachments .Where(o => o.TableName == x.Id.ToString()) .Select(o => new ResumeAttachment() @@ -56,4 +55,284 @@ public class Ghrh_ResumeHomeServices : BaseServices + /// 字典映射、全称、单位转换等 + /// + /// + private async Task SetLabel(Ghrh_ResumeHomeDto x) + { + if (x != null) + { + x.GenderLabel = await GetParaLabel("Gender", x.Gender); + x.RelationTypeLabel = await GetParaLabel("SocialRelationType", x.RelationType); + } + } + #endregion + + #region 查询 + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + { + var result = await base.QueryFilterPage(filter, condition, IsEnable); + var list = result.result.DT_TableDataT1; + var resumeIds = list.Where(x => x.ResumeId != null).Select(x => x.ResumeId.Value).ToList(); + var resumes = await Db.Queryable().Where(x => resumeIds.Contains(x.Id)).ToListAsync(); + + list.ForEach(async x => + { + await SetLabel(x); + x.StaffName = resumes.Where(o => x.ResumeId == o.Id).FirstOrDefault()?.StaffName; + }); + + return result; + + } + #endregion + + + #region Excel导入 + + public async Task> QueryResumeFormColumn(long resumeTemplateID = 0) + { + resumeTemplateID = await Db.Ado.GetLongAsync("select top 1 Id from Ghrh_ResumeTemplate where IsEnable=1 and IsPublish=1"); + var sql = @$"DECLARE @ResumeTemplateID BIGINT = {resumeTemplateID} + + SELECT A.ColumnName, A.ResumeInfoColumnName ColumnNameDesc, D.GroupType, A.MapTableName, A.MapColumnName, +A.DataType, A.ColumnType, A.IsRequired, A.DataSourceType, A.DataSource, A.DataSourceID + FROM Ghrh_ResumeInfoColumn A + LEFT JOIN Ghrh_ResumeTemplateInfoGroupColumn B + ON B.ResumeInfoColumnID = A.ID + AND B.IsDisplay = 1 + AND B.IsEnable = 1 + AND A.IsEnable = 1 + JOIN Ghrh_ResumeTemplateInfoGroup C + ON B.ResumeTemplateInfoGroupID = C.Id + JOIN Ghrh_ResumeInfoGroup D + ON C.ResumeInfoGroupId = D.ID AND D.IsEnable = 1 + WHERE C.ResumeTemplateID = @ResumeTemplateID + AND D.GroupType = 'Family' and b.StaffInfoColumnNo !='AttachmentIDs' + ORDER BY D.GroupType, b.SortNo"; + + return await Db.Ado.SqlQueryAsync(sql); + } + public override async Task> 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); + + DataTable dt = new DataTable("TempTable"); + + var formColumns = await QueryResumeFormColumn(); + string fileName = path + SnowFlakeSingle.instance.getID() + ".xlsx"; + dt.Columns.Add("姓名", typeof(string)); + formColumns + .ToList() + .ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + dt.Columns.Add(x.ColumnNameDesc, typeof(string)); + }); + + var dr = dt.NewRow(); + dt.Rows.Add(dr); + NPOIHelper.ExportExcel(dt, null, "社会关系", physicsPath + fileName); + + var physicsPath1 = physicsPath + 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 formColumns = await QueryResumeFormColumn(); + + for (int i = 0; i < dt.Rows.Count; i++) + { + var comments = new List(); + bool isContinue = false; + + var dict = new Dictionary + { + { "Id", SnowFlakeSingle.Instance.NextId() }, + { "CreateBy", App.User.ID }, + { "CreateTime", DateTime.Now }, + { "UpdateTime", DateTime.Now } + }; + if (!dt.Columns.Contains("姓名")) + { + comments.Add("未查询到【姓名】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + + formColumns.ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + { + comments.Add("未查询到【" + x.ColumnNameDesc + "】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + }); + + if (isContinue) + continue; + + for (int j = 0; j < formColumns.Count; j++) + { + var column = formColumns[j]; + var value = dt.Rows[i][column.ColumnNameDesc].ToString(); + if (column.IsRequired == true && value.IsNullOrEmpty()) + { + comments.Add(column.ColumnNameDesc + "不能为空!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + if (column.DataSourceType.IsNullOrEmpty()) + { + if (column.DataType == "int" || column.DataType == "decimal") + { + try + { + Convert.ToInt64(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的数字类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + else if (column.DataType == "date") + { + try + { + Convert.ToDateTime(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的日期类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + } + + + if (value.IsNotEmptyOrNull()) + { + if (column.ColumnType == "Switch") + value = value == "是" ? "true" : "false"; + if (column.DataSource.IsNotEmptyOrNull() && column.DataSourceType.IsNotEmptyOrNull()) + { + + if (column.DataSourceType == "CommonList") + { + var commonSql = await Db.Queryable().Where(x => x.ListCommonSqlId == column.DataSource.ObjToInt()).FirstAsync(); + + if (commonSql != null) + { + string sql = @$"SELECT [value] + FROM ({commonSql.SelectSql}) A + WHERE label = '{value}'"; + sql = sql.Replace("{@LangID}", "1"); + var id2 = await Db.Ado.GetLongAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else if (column.DataSourceType == "ParaDetailNo") + { + var sql = @$"SELECT ParaDetailNo + FROM Ghrs_ParaDetail + WHERE ParaMasterId IN (SELECT ParaMasterId + FROM Ghrs_ParaMaster + WHERE ParaMasterId = {column.DataSource.ObjToInt()}) + AND IsEnable = 1 + AND ParaDetailName = '{value}'"; + var id2 = await Db.Ado.GetStringAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else + dict.Add(column.ColumnName, value); + } + + } + + var StaffName = dt.Rows[i]["姓名"].ToString(); + + var resume = await Db.Queryable().Where(x => x.StaffName == StaffName || x.StaffEname == StaffName).FirstAsync(); + if (resume is null) + { + comments.Add("未查询到【" + StaffName + "】相关数据!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + else dict.Add("ResumeId", resume.Id); + if (isExistError) + continue; + try + { + await Db.Insertable(dict).AS("Ghrh_ResumeHome").ExecuteCommandAsync(); + data.SuccessCount++; + } + 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 = "/Advanced" + errorFileName; + } + + return ServiceResult.OprateSuccess("导入成功!", data); + } + #endregion + } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeLicenceServices.cs b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeLicenceServices.cs index 2e3365c9..0d990e2a 100644 --- a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeLicenceServices.cs +++ b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeLicenceServices.cs @@ -19,8 +19,9 @@ public class Ghrh_ResumeLicenceServices : BaseServices x.Id.ToString()).ToList(); var attachments = await Db.Queryable().Where(x => ids.Contains(x.TableName)).ToListAsync(); - data.ForEach(x => + data.ForEach(async x => { + await SetLabel(x); x.AttachmentIDs = attachments .Where(o => o.TableName == x.Id.ToString()) .Select(o => new ResumeAttachment() @@ -32,8 +33,6 @@ public class Ghrh_ResumeLicenceServices : BaseServices + /// 字典映射、全称、单位转换等 + /// + /// + private async Task SetLabel(Ghrh_ResumeLicenceDto x) + { + if (x != null) + { + x.BeginDate1 = DateTimeHelper.ConvertToDayString(x.BeginDate); + x.EndDate1 = DateTimeHelper.ConvertToDayString(x.EndDate); + } + } + #endregion + + #region 查询 + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + { + var result = await base.QueryFilterPage(filter, condition, IsEnable); + var list = result.result.DT_TableDataT1; + var resumeIds = list.Where(x => x.ResumeId != null).Select(x => x.ResumeId.Value).ToList(); + var resumes = await Db.Queryable().Where(x => resumeIds.Contains(x.Id)).ToListAsync(); + + list.ForEach(async x => + { + await SetLabel(x); + x.StaffName = resumes.Where(o => x.ResumeId == o.Id).FirstOrDefault()?.StaffName; + }); + + return result; + + } + #endregion + #region Excel导入 + + public async Task> QueryResumeFormColumn(long resumeTemplateID = 0) + { + resumeTemplateID = await Db.Ado.GetLongAsync("select top 1 Id from Ghrh_ResumeTemplate where IsEnable=1 and IsPublish=1"); + var sql = @$"DECLARE @ResumeTemplateID BIGINT = {resumeTemplateID} + + SELECT A.ColumnName, A.ResumeInfoColumnName ColumnNameDesc, D.GroupType, A.MapTableName, A.MapColumnName, +A.DataType, A.ColumnType, A.IsRequired, A.DataSourceType, A.DataSource, A.DataSourceID + FROM Ghrh_ResumeInfoColumn A + LEFT JOIN Ghrh_ResumeTemplateInfoGroupColumn B + ON B.ResumeInfoColumnID = A.ID + AND B.IsDisplay = 1 + AND B.IsEnable = 1 + AND A.IsEnable = 1 + JOIN Ghrh_ResumeTemplateInfoGroup C + ON B.ResumeTemplateInfoGroupID = C.Id + JOIN Ghrh_ResumeInfoGroup D + ON C.ResumeInfoGroupId = D.ID AND D.IsEnable = 1 + WHERE C.ResumeTemplateID = @ResumeTemplateID + AND D.GroupType = 'Licence' and b.StaffInfoColumnNo !='AttachmentIDs' + ORDER BY D.GroupType, b.SortNo"; + + return await Db.Ado.SqlQueryAsync(sql); + } + public override async Task> 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); + + DataTable dt = new DataTable("TempTable"); + + var formColumns = await QueryResumeFormColumn(); + string fileName = path + SnowFlakeSingle.instance.getID() + ".xlsx"; + dt.Columns.Add("姓名", typeof(string)); + formColumns + .ToList() + .ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + dt.Columns.Add(x.ColumnNameDesc, typeof(string)); + }); + + var dr = dt.NewRow(); + dt.Rows.Add(dr); + NPOIHelper.ExportExcel(dt, null, "证件", physicsPath + fileName); + + var physicsPath1 = physicsPath + 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 formColumns = await QueryResumeFormColumn(); + + for (int i = 0; i < dt.Rows.Count; i++) + { + var comments = new List(); + bool isContinue = false; + + var dict = new Dictionary + { + { "Id", SnowFlakeSingle.Instance.NextId() }, + { "CreateBy", App.User.ID }, + { "CreateTime", DateTime.Now }, + { "UpdateTime", DateTime.Now } + }; + if (!dt.Columns.Contains("姓名")) + { + comments.Add("未查询到【姓名】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + + formColumns.ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + { + comments.Add("未查询到【" + x.ColumnNameDesc + "】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + }); + + if (isContinue) + continue; + + for (int j = 0; j < formColumns.Count; j++) + { + var column = formColumns[j]; + var value = dt.Rows[i][column.ColumnNameDesc].ToString(); + if (column.IsRequired == true && value.IsNullOrEmpty()) + { + comments.Add(column.ColumnNameDesc + "不能为空!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + if (column.DataSourceType.IsNullOrEmpty()) + { + if (column.DataType == "int" || column.DataType == "decimal") + { + try + { + Convert.ToInt64(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的数字类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + else if (column.DataType == "date") + { + try + { + Convert.ToDateTime(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的日期类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + } + + + if (value.IsNotEmptyOrNull()) + { + if (column.ColumnType == "Switch") + value = value == "是" ? "true" : "false"; + if (column.DataSource.IsNotEmptyOrNull() && column.DataSourceType.IsNotEmptyOrNull()) + { + + if (column.DataSourceType == "CommonList") + { + var commonSql = await Db.Queryable().Where(x => x.ListCommonSqlId == column.DataSource.ObjToInt()).FirstAsync(); + + if (commonSql != null) + { + string sql = @$"SELECT [value] + FROM ({commonSql.SelectSql}) A + WHERE label = '{value}'"; + sql = sql.Replace("{@LangID}", "1"); + var id2 = await Db.Ado.GetLongAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else if (column.DataSourceType == "ParaDetailNo") + { + var sql = @$"SELECT ParaDetailNo + FROM Ghrs_ParaDetail + WHERE ParaMasterId IN (SELECT ParaMasterId + FROM Ghrs_ParaMaster + WHERE ParaMasterId = {column.DataSource.ObjToInt()}) + AND IsEnable = 1 + AND ParaDetailName = '{value}'"; + var id2 = await Db.Ado.GetStringAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else + dict.Add(column.ColumnName, value); + } + + } + + var StaffName = dt.Rows[i]["姓名"].ToString(); + + var resume = await Db.Queryable().Where(x => x.StaffName == StaffName || x.StaffEname == StaffName).FirstAsync(); + if (resume is null) + { + comments.Add("未查询到【" + StaffName + "】相关数据!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + else dict.Add("ResumeId", resume.Id); + if (isExistError) + continue; + try + { + await Db.Insertable(dict).AS("Ghrh_ResumeLicence").ExecuteCommandAsync(); + data.SuccessCount++; + } + 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 = "/Advanced" + errorFileName; + } + + return ServiceResult.OprateSuccess("导入成功!", data); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs index fa90628f..04c3cec0 100644 --- a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs +++ b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeServices.cs @@ -1,5 +1,4 @@ -using Amazon.Runtime.Internal.Transform; -using DinkToPdf; +using DinkToPdf; using DinkToPdf.Contracts; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; diff --git a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeTrainingServices.cs b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeTrainingServices.cs index 3a98c31b..596a7fb0 100644 --- a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeTrainingServices.cs +++ b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeTrainingServices.cs @@ -19,12 +19,9 @@ public class Ghrh_ResumeTrainingServices : BaseServices x.Id.ToString()).ToList(); var attachments = await Db.Queryable().Where(x => ids.Contains(x.TableName)).ToListAsync(); - data.ForEach(x => + data.ForEach(async x => { - x.BeginDate1 = DateTimeHelper.ConvertToDayString(x.BeginDate); - x.EndDate1 = DateTimeHelper.ConvertToDayString(x.EndDate); - if (x.IsPass != null) - x.IsPassLabel = x.IsPass == true ? "是" : "否"; + await SetLabel(x); x.AttachmentIDs = attachments .Where(o => o.TableName == x.Id.ToString()) .Select(o => new ResumeAttachment() @@ -40,6 +37,41 @@ public class Ghrh_ResumeTrainingServices : BaseServices + /// 字典映射、全称、单位转换等 + /// + /// + private async Task SetLabel(Ghrh_ResumeTrainingDto x) + { + if (x != null) + { + x.BeginDate1 = DateTimeHelper.ConvertToDayString(x.BeginDate); + x.EndDate1 = DateTimeHelper.ConvertToDayString(x.EndDate); + if (x.IsPass != null) + x.IsPassLabel = x.IsPass == true ? "是" : "否"; + } + } + #endregion + + #region 查询 + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + { + var result = await base.QueryFilterPage(filter, condition, IsEnable); + var list = result.result.DT_TableDataT1; + var resumeIds = list.Where(x => x.ResumeId != null).Select(x => x.ResumeId.Value).ToList(); + var resumes = await Db.Queryable().Where(x => resumeIds.Contains(x.Id)).ToListAsync(); + + list.ForEach(async x => + { + await SetLabel(x); + x.StaffName = resumes.Where(o => x.ResumeId == o.Id).FirstOrDefault()?.StaffName; + }); + + return result; + + } + #endregion public override async Task> Add(List listEntity) { var result = new List(); @@ -58,4 +90,248 @@ public class Ghrh_ResumeTrainingServices : BaseServices> QueryResumeFormColumn(long resumeTemplateID = 0) + { + resumeTemplateID = await Db.Ado.GetLongAsync("select top 1 Id from Ghrh_ResumeTemplate where IsEnable=1 and IsPublish=1"); + var sql = @$"DECLARE @ResumeTemplateID BIGINT = {resumeTemplateID} + + SELECT A.ColumnName, A.ResumeInfoColumnName ColumnNameDesc, D.GroupType, A.MapTableName, A.MapColumnName, +A.DataType, A.ColumnType, A.IsRequired, A.DataSourceType, A.DataSource, A.DataSourceID + FROM Ghrh_ResumeInfoColumn A + LEFT JOIN Ghrh_ResumeTemplateInfoGroupColumn B + ON B.ResumeInfoColumnID = A.ID + AND B.IsDisplay = 1 + AND B.IsEnable = 1 + AND A.IsEnable = 1 + JOIN Ghrh_ResumeTemplateInfoGroup C + ON B.ResumeTemplateInfoGroupID = C.Id + JOIN Ghrh_ResumeInfoGroup D + ON C.ResumeInfoGroupId = D.ID AND D.IsEnable = 1 + WHERE C.ResumeTemplateID = @ResumeTemplateID + AND D.GroupType = 'Training' and b.StaffInfoColumnNo !='AttachmentIDs' + ORDER BY D.GroupType, b.SortNo"; + + return await Db.Ado.SqlQueryAsync(sql); + } + public override async Task> 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); + + DataTable dt = new DataTable("TempTable"); + + var formColumns = await QueryResumeFormColumn(); + string fileName = path + SnowFlakeSingle.instance.getID() + ".xlsx"; + dt.Columns.Add("姓名", typeof(string)); + formColumns + .ToList() + .ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + dt.Columns.Add(x.ColumnNameDesc, typeof(string)); + }); + + var dr = dt.NewRow(); + dt.Rows.Add(dr); + NPOIHelper.ExportExcel(dt, null, "培训记录", physicsPath + fileName); + + var physicsPath1 = physicsPath + 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 formColumns = await QueryResumeFormColumn(); + + for (int i = 0; i < dt.Rows.Count; i++) + { + var comments = new List(); + bool isContinue = false; + + var dict = new Dictionary + { + { "Id", SnowFlakeSingle.Instance.NextId() }, + { "CreateBy", App.User.ID }, + { "CreateTime", DateTime.Now }, + { "UpdateTime", DateTime.Now } + }; + if (!dt.Columns.Contains("姓名")) + { + comments.Add("未查询到【姓名】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + + formColumns.ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + { + comments.Add("未查询到【" + x.ColumnNameDesc + "】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + }); + + if (isContinue) + continue; + + for (int j = 0; j < formColumns.Count; j++) + { + var column = formColumns[j]; + var value = dt.Rows[i][column.ColumnNameDesc].ToString(); + if (column.IsRequired == true && value.IsNullOrEmpty()) + { + comments.Add(column.ColumnNameDesc + "不能为空!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + if (column.DataSourceType.IsNullOrEmpty()) + { + if (column.DataType == "int" || column.DataType == "decimal") + { + try + { + Convert.ToInt64(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的数字类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + else if (column.DataType == "date") + { + try + { + Convert.ToDateTime(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的日期类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + } + + + if (value.IsNotEmptyOrNull()) + { + if (column.ColumnType == "Switch") + value = value == "是" ? "true" : "false"; + if (column.DataSource.IsNotEmptyOrNull() && column.DataSourceType.IsNotEmptyOrNull()) + { + + if (column.DataSourceType == "CommonList") + { + var commonSql = await Db.Queryable().Where(x => x.ListCommonSqlId == column.DataSource.ObjToInt()).FirstAsync(); + + if (commonSql != null) + { + string sql = @$"SELECT [value] + FROM ({commonSql.SelectSql}) A + WHERE label = '{value}'"; + sql = sql.Replace("{@LangID}", "1"); + var id2 = await Db.Ado.GetLongAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else if (column.DataSourceType == "ParaDetailNo") + { + var sql = @$"SELECT ParaDetailNo + FROM Ghrs_ParaDetail + WHERE ParaMasterId IN (SELECT ParaMasterId + FROM Ghrs_ParaMaster + WHERE ParaMasterId = {column.DataSource.ObjToInt()}) + AND IsEnable = 1 + AND ParaDetailName = '{value}'"; + var id2 = await Db.Ado.GetStringAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else + dict.Add(column.ColumnName, value); + } + + } + + var StaffName = dt.Rows[i]["姓名"].ToString(); + + var resume = await Db.Queryable().Where(x => x.StaffName == StaffName || x.StaffEname == StaffName).FirstAsync(); + if (resume is null) + { + comments.Add("未查询到【" + StaffName + "】相关数据!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + else dict.Add("ResumeId", resume.Id); + if (isExistError) + continue; + try + { + await Db.Insertable(dict).AS("Ghrh_ResumeTraining").ExecuteCommandAsync(); + data.SuccessCount++; + } + 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 = "/Advanced" + errorFileName; + } + + return ServiceResult.OprateSuccess("导入成功!", data); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeWorkExpServices.cs b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeWorkExpServices.cs index 8cc5f6fc..79e27b9a 100644 --- a/Tiobon.Core.Services/Ghrh/Ghrh_ResumeWorkExpServices.cs +++ b/Tiobon.Core.Services/Ghrh/Ghrh_ResumeWorkExpServices.cs @@ -19,8 +19,9 @@ public class Ghrh_ResumeWorkExpServices : BaseServices x.Id.ToString()).ToList(); var attachments = await Db.Queryable().Where(x => ids.Contains(x.TableName)).ToListAsync(); - data.ForEach(x => + data.ForEach(async x => { + await SetLabel(x); x.AttachmentIDs = attachments .Where(o => o.TableName == x.Id.ToString()) .Select(o => new ResumeAttachment() @@ -32,8 +33,6 @@ public class Ghrh_ResumeWorkExpServices : BaseServices + /// 字典映射、全称、单位转换等 + /// + /// + private async Task SetLabel(Ghrh_ResumeWorkExpDto x) + { + if (x != null) + { + x.BeginDate1 = DateTimeHelper.ConvertToDayString(x.BeginDate); + x.EndDate1 = DateTimeHelper.ConvertToDayString(x.EndDate); + } + } + #endregion + + #region 查询 + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + { + var result = await base.QueryFilterPage(filter, condition, IsEnable); + var list = result.result.DT_TableDataT1; + var resumeIds = list.Where(x => x.ResumeId != null).Select(x => x.ResumeId.Value).ToList(); + var resumes = await Db.Queryable().Where(x => resumeIds.Contains(x.Id)).ToListAsync(); + + list.ForEach(async x => + { + await SetLabel(x); + x.StaffName = resumes.Where(o => x.ResumeId == o.Id).FirstOrDefault()?.StaffName; + }); + + return result; + + } + #endregion + + #region Excel导入 + + public async Task> QueryResumeFormColumn(long resumeTemplateID = 0) + { + resumeTemplateID = await Db.Ado.GetLongAsync("select top 1 Id from Ghrh_ResumeTemplate where IsEnable=1 and IsPublish=1"); + var sql = @$"DECLARE @ResumeTemplateID BIGINT = {resumeTemplateID} + + SELECT A.ColumnName, A.ResumeInfoColumnName ColumnNameDesc, D.GroupType, A.MapTableName, A.MapColumnName, +A.DataType, A.ColumnType, A.IsRequired, A.DataSourceType, A.DataSource, A.DataSourceID + FROM Ghrh_ResumeInfoColumn A + LEFT JOIN Ghrh_ResumeTemplateInfoGroupColumn B + ON B.ResumeInfoColumnID = A.ID + AND B.IsDisplay = 1 + AND B.IsEnable = 1 + AND A.IsEnable = 1 + JOIN Ghrh_ResumeTemplateInfoGroup C + ON B.ResumeTemplateInfoGroupID = C.Id + JOIN Ghrh_ResumeInfoGroup D + ON C.ResumeInfoGroupId = D.ID AND D.IsEnable = 1 + WHERE C.ResumeTemplateID = @ResumeTemplateID + AND D.GroupType = 'WorkExp' and b.StaffInfoColumnNo !='AttachmentIDs' + ORDER BY D.GroupType, b.SortNo"; + + return await Db.Ado.SqlQueryAsync(sql); + } + public override async Task> 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); + + DataTable dt = new DataTable("TempTable"); + + var formColumns = await QueryResumeFormColumn(); + string fileName = path + SnowFlakeSingle.instance.getID() + ".xlsx"; + dt.Columns.Add("姓名", typeof(string)); + formColumns + .ToList() + .ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + dt.Columns.Add(x.ColumnNameDesc, typeof(string)); + }); + + var dr = dt.NewRow(); + dt.Rows.Add(dr); + NPOIHelper.ExportExcel(dt, null, "工作经历", physicsPath + fileName); + + var physicsPath1 = physicsPath + 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 formColumns = await QueryResumeFormColumn(); + + for (int i = 0; i < dt.Rows.Count; i++) + { + var comments = new List(); + bool isContinue = false; + + var dict = new Dictionary + { + { "Id", SnowFlakeSingle.Instance.NextId() }, + { "CreateBy", App.User.ID }, + { "CreateTime", DateTime.Now }, + { "UpdateTime", DateTime.Now } + }; + if (!dt.Columns.Contains("姓名")) + { + comments.Add("未查询到【姓名】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + + formColumns.ForEach(x => + { + if (!dt.Columns.Contains(x.ColumnNameDesc)) + { + comments.Add("未查询到【" + x.ColumnNameDesc + "】列!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + }); + + if (isContinue) + continue; + + for (int j = 0; j < formColumns.Count; j++) + { + var column = formColumns[j]; + var value = dt.Rows[i][column.ColumnNameDesc].ToString(); + if (column.IsRequired == true && value.IsNullOrEmpty()) + { + comments.Add(column.ColumnNameDesc + "不能为空!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + if (column.DataSourceType.IsNullOrEmpty()) + { + if (column.DataType == "int" || column.DataType == "decimal") + { + try + { + Convert.ToInt64(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的数字类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + else if (column.DataType == "date") + { + try + { + Convert.ToDateTime(value); + } + catch (Exception) + { + comments.Add(column.ColumnNameDesc + "无效的日期类型!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + continue; + } + } + } + + + if (value.IsNotEmptyOrNull()) + { + if (column.ColumnType == "Switch") + value = value == "是" ? "true" : "false"; + if (column.DataSource.IsNotEmptyOrNull() && column.DataSourceType.IsNotEmptyOrNull()) + { + + if (column.DataSourceType == "CommonList") + { + var commonSql = await Db.Queryable().Where(x => x.ListCommonSqlId == column.DataSource.ObjToInt()).FirstAsync(); + + if (commonSql != null) + { + string sql = @$"SELECT [value] + FROM ({commonSql.SelectSql}) A + WHERE label = '{value}'"; + sql = sql.Replace("{@LangID}", "1"); + var id2 = await Db.Ado.GetLongAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else if (column.DataSourceType == "ParaDetailNo") + { + var sql = @$"SELECT ParaDetailNo + FROM Ghrs_ParaDetail + WHERE ParaMasterId IN (SELECT ParaMasterId + FROM Ghrs_ParaMaster + WHERE ParaMasterId = {column.DataSource.ObjToInt()}) + AND IsEnable = 1 + AND ParaDetailName = '{value}'"; + var id2 = await Db.Ado.GetStringAsync(sql); + + dict.Add(column.ColumnName, id2); + } + } + else + dict.Add(column.ColumnName, value); + } + + } + + var StaffName = dt.Rows[i]["姓名"].ToString(); + + var resume = await Db.Queryable().Where(x => x.StaffName == StaffName || x.StaffEname == StaffName).FirstAsync(); + if (resume is null) + { + comments.Add("未查询到【" + StaffName + "】相关数据!"); + data.ErrorCount++; + dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a)); + isExistError = true; + isContinue = true; + } + else dict.Add("ResumeId", resume.Id); + if (isExistError) + continue; + try + { + await Db.Insertable(dict).AS("Ghrh_ResumeWorkExp").ExecuteCommandAsync(); + data.SuccessCount++; + } + 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 = "/Advanced" + errorFileName; + } + + return ServiceResult.OprateSuccess("导入成功!", data); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core/Tiobon.Core.Model.xml b/Tiobon.Core/Tiobon.Core.Model.xml index 6298a9b7..963cf0d2 100644 --- a/Tiobon.Core/Tiobon.Core.Model.xml +++ b/Tiobon.Core/Tiobon.Core.Model.xml @@ -11368,6 +11368,136 @@ TableID + + + Ghrs_ListCommonSql (Dto.Base) + + + + + ListCommonSqlId + + + + + ListCommonSqlNo + + + + + ListCommonSqlName + + + + + ListCommonSqlType + + + + + ListCommonSqlType2 + + + + + ListComment + + + + + SelectSql + + + + + JsonTitle + + + + + WhereSql + + + + + OrderBySql + + + + + SqlTopCountSql + + + + + SqlGetIDSql + + + + + RemarkSz + + + + + SortNo + + + + + IsDefault + + + + + Reverse1 + + + + + Reverse2 + + + + + Reverse3 + + + + + Reverse4 + + + + + Reverse5 + + + + + Reverse6 + + + + + Reverse7 + + + + + Reverse8 + + + + + Reverse9 + + + + + SqlIDToName + + Ghrs_MailOutbox (Dto.Base) @@ -12272,6 +12402,11 @@ 学历编号 + + + LegalCompanyNo + + 计薪类别编号 @@ -12857,6 +12992,11 @@ Ghrs_LangKey (Dto.EditInput) + + + Ghrs_ListCommonSql (Dto.EditInput) + + Ghrs_MailOutbox (Dto.EditInput) @@ -13327,6 +13467,11 @@ Ghrs_LangKey (Dto.InsertInput) + + + Ghrs_ListCommonSql (Dto.InsertInput) + + Ghrs_MailOutbox (Dto.InsertInput) @@ -25034,6 +25179,136 @@ TableID + + + Ghrs_ListCommonSql (Model) + + + + + ListCommonSqlId + + + + + ListCommonSqlNo + + + + + ListCommonSqlName + + + + + ListCommonSqlType + + + + + ListCommonSqlType2 + + + + + ListComment + + + + + SelectSql + + + + + JsonTitle + + + + + WhereSql + + + + + OrderBySql + + + + + SqlTopCountSql + + + + + SqlGetIDSql + + + + + RemarkSz + + + + + SortNo + + + + + IsDefault + + + + + Reverse1 + + + + + Reverse2 + + + + + Reverse3 + + + + + Reverse4 + + + + + Reverse5 + + + + + Reverse6 + + + + + Reverse7 + + + + + Reverse8 + + + + + Reverse9 + + + + + SqlIDToName + + Ghrs_MailOutbox (Model) @@ -25943,6 +26218,11 @@ 学历编号 + + + LegalCompanyNo + + 计薪类别编号 @@ -28807,6 +29087,21 @@ 修改信息 + + + Ghrs_ListCommonSql(Dto.View1) + + + + + 创建信息 + + + + + 修改信息 + + Ghrs_MailOutbox(Dto.View1) diff --git a/Tiobon.Core/Tiobon.Core.xml b/Tiobon.Core/Tiobon.Core.xml index c26be6aa..3fa85f99 100644 --- a/Tiobon.Core/Tiobon.Core.xml +++ b/Tiobon.Core/Tiobon.Core.xml @@ -1829,6 +1829,11 @@ Ghrs_LangKey(Controller) + + + Ghrs_ListCommonSql(Controller) + + Ghrs_MailOutbox(Controller)