|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
using NPOI.SS.UserModel; |
|
|
|
|
using NPOI.SS.Util; |
|
|
|
|
using Tiobon.Core.Model.Models; |
|
|
|
|
using static Tiobon.Core.DataAccess.ReportHelper; |
|
|
|
|
using static Tiobon.Core.Model.Consts; |
|
|
|
|
|
|
|
|
@ -401,11 +402,11 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr |
|
|
|
|
var newFileName = Guid.NewGuid() + ".xlsx"; |
|
|
|
|
int listColIndex = 0; |
|
|
|
|
var items = await GetParaList("TrainingCategory"); |
|
|
|
|
var depts = await Db.Queryable<Ghro_Dept>().Select(x => new |
|
|
|
|
{ |
|
|
|
|
x.DeptID, |
|
|
|
|
x.DeptName |
|
|
|
|
}).ToListAsync(); |
|
|
|
|
//var depts = await Db.Queryable<Ghro_Dept>().Select(x => new |
|
|
|
|
//{ |
|
|
|
|
// x.DeptID, |
|
|
|
|
// x.DeptName |
|
|
|
|
//}).ToListAsync(); |
|
|
|
|
|
|
|
|
|
//var courses = await Db.Queryable<Ghre_Course>().Select(x => new |
|
|
|
|
//{ |
|
|
|
@ -430,10 +431,10 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr |
|
|
|
|
IDataValidation dataValidation1 = sheet.GetDataValidationHelper().CreateValidation(dvConstraint1, new CellRangeAddressList(1, 65535, 2, 2)); |
|
|
|
|
sheet.AddValidationData(dataValidation1); |
|
|
|
|
|
|
|
|
|
dvConstraint1 = sheet.GetDataValidationHelper().CreateExplicitListConstraint(depts.Select(x => x.DeptName).ToArray()); |
|
|
|
|
//设置编辑的区域 |
|
|
|
|
dataValidation1 = sheet.GetDataValidationHelper().CreateValidation(dvConstraint1, new CellRangeAddressList(1, 65535, 1, 1)); |
|
|
|
|
sheet.AddValidationData(dataValidation1); |
|
|
|
|
//dvConstraint1 = sheet.GetDataValidationHelper().CreateExplicitListConstraint(depts.Select(x => x.DeptName).ToArray()); |
|
|
|
|
////设置编辑的区域 |
|
|
|
|
//dataValidation1 = sheet.GetDataValidationHelper().CreateValidation(dvConstraint1, new CellRangeAddressList(1, 65535, 1, 1)); |
|
|
|
|
//sheet.AddValidationData(dataValidation1); |
|
|
|
|
|
|
|
|
|
//dvConstraint1 = sheet.GetDataValidationHelper().CreateExplicitListConstraint(courses.Select(x => x.CourseName).ToArray()); |
|
|
|
|
////设置编辑的区域 |
|
|
|
@ -488,4 +489,217 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr |
|
|
|
|
return ServiceResult<string>.OprateSuccess("计划维护_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now) + ".xlsx", physicsPath1); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Excel导入 |
|
|
|
|
|
|
|
|
|
public async Task<(List<Dictionary<string, object>>, int)> ValidImportExcel(ISqlSugarClient Db, List<QueryExportColumn> columns, DataTable dt) |
|
|
|
|
{ |
|
|
|
|
var CompanyCode = await QueryCompanyCode(); |
|
|
|
|
Type entityType = typeof(Ghre_Plan); |
|
|
|
|
var properties = entityType.GetGenericProperties(); |
|
|
|
|
int ErrorCount = 0; |
|
|
|
|
var dictList = new List<Dictionary<string, object>>(); |
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var dict = ReportHelper.GetDefaultDict(); |
|
|
|
|
var comments = new List<string>(); |
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
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 == "StaffId") |
|
|
|
|
{ |
|
|
|
|
value = value.Replace(",", ","); |
|
|
|
|
value = value.Replace(";", ","); |
|
|
|
|
value = value.Replace(";", ","); |
|
|
|
|
var value1 = value.Split(',').ToList(); |
|
|
|
|
var ids = await Db.Queryable<Ghra_Staff>().Where(o => value1.Contains(o.StaffName) || value1.Contains(o.StaffNo) || value1.Contains(o.StaffEname)).Select(x => x.StaffID).ToListAsync(); |
|
|
|
|
dict.Add("StaffIds", JsonHelper.ObjToJson(ids)); |
|
|
|
|
} |
|
|
|
|
else if (x.field == "CourseId") |
|
|
|
|
{ |
|
|
|
|
var ids = await Db.Queryable<Ghre_Course>().Where(o => o.CourseNo == value || o.CourseName == value).Select(x => x.Id).FirstAsync(); |
|
|
|
|
dict.Add("CourseId", ids); |
|
|
|
|
} |
|
|
|
|
else if (x.field == "SchoolId") |
|
|
|
|
{ |
|
|
|
|
var ids = await Db.Queryable<Ghre_School>().Where(o => o.SchoolNo == value || o.SchoolName == value).Select(x => x.Id).FirstAsync(); |
|
|
|
|
dict.Add("SchoolId", ids); |
|
|
|
|
} |
|
|
|
|
else if (x.field == "Months") |
|
|
|
|
{ |
|
|
|
|
value = value.Replace(",", ","); |
|
|
|
|
value = value.Replace(";", ","); |
|
|
|
|
value = value.Replace(";", ","); |
|
|
|
|
var value1 = value.Split(',').ToList(); |
|
|
|
|
|
|
|
|
|
var value2 = new List<string>(); |
|
|
|
|
|
|
|
|
|
value1.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
if (Convert.ToInt16(x) >= 1 && Convert.ToInt16(x) <= 12) |
|
|
|
|
value2.Add(Convert.ToInt16(x).ObjToString()); |
|
|
|
|
} |
|
|
|
|
catch (Exception) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ids = await Db.Queryable<Ghra_Staff>().Where(o => value1.Contains(o.StaffName) || value1.Contains(o.StaffNo) || value1.Contains(o.StaffEname)).Select(x => x.StaffID).ToListAsync(); |
|
|
|
|
dict.Add("Month", 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<Ghrs_ListCommonSql>().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" || x.dataSource == "OrgTreeWithoutPriv") |
|
|
|
|
{ |
|
|
|
|
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<ServiceResult<ExcelData>> 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); |
|
|
|
|
columns = columns.Where(x => x.label != "系统内置").ToList(); |
|
|
|
|
var (dictList, errorCount) = await ValidImportExcel(Db, columns, dt); |
|
|
|
|
Type entityType = typeof(Ghre_Plan); |
|
|
|
|
var properties = entityType.GetGenericProperties(); |
|
|
|
|
if (errorCount > 0) |
|
|
|
|
{ |
|
|
|
|
NPOIHelper.ExportExcel(dt, null, "导入数据", FileHelper.GetPhysicsPath() + errorFileName); |
|
|
|
|
data.filePath = "/Advanced" + errorFileName; |
|
|
|
|
data.ErrorCount = errorCount; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
dictList.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
if (menuName == "F_TrainPlan_Wait") |
|
|
|
|
x.Add("Status", "Wait"); |
|
|
|
|
else if (menuName == "F_TrainPlan_Temporary") |
|
|
|
|
x.Add("Status", "Temporary"); |
|
|
|
|
}); |
|
|
|
|
await Db.Insertable(dictList).AS(entityType.GetEntityTableName()).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
|
data.SuccessCount = dictList.Count; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ServiceResult<ExcelData>.OprateSuccess("导入成功!", data); |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |