@ -1,5 +1,4 @@
using NPOI.SS.UserModel ;
using static Tiobon . Core . Model . Consts ;
using static Tiobon . Core . Model . Consts ;
namespace Tiobon.Core.Services ;
@ -532,218 +531,68 @@ WHERE A.IsEnable = 1 AND A.Id = {entitys[i].YearHumanId}");
# endregion
//#region Excel导入
//public override async Task<ServiceResult<ExcelData>> 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;
// try
// {
// DataTable dt = NPOIHelper.ImportExcel(filepath, "年度人力配置");
// if (dt.Columns["Comments"] == null)
// dt.Columns.Add("Comments", typeof(string));
// for (int i = 0; i < dt.Rows.Count; i++)
// {
// var comments = new List<string>();
// if (!dt.Columns.Contains("年度"))
// {
// comments.Add("未查询到【年度】列!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// if (!dt.Columns.Contains("部门"))
// {
// comments.Add("未查询到【部门】列!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// if (!dt.Columns.Contains("岗位"))
// {
// comments.Add("未查询到【岗位】列!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// if (!dt.Columns.Contains("职称"))
// {
// comments.Add("未查询到【职称】列!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// if (!dt.Columns.Contains("职等"))
// {
// comments.Add("未查询到【职等】列!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// for (int j = 1; j <= 12; j++)
// {
// if (!dt.Columns.Contains(j + "月"))
// {
// comments.Add($"未查询到【{j}月】列!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// }
// var year = dt.Rows[i]["年度"].ToString();
// var deptName = dt.Rows[i]["部门"].ToString();
// var titleName = dt.Rows[i]["岗位"].ToString();
// var jobName = dt.Rows[i]["职称"].ToString();
// var gradeName = dt.Rows[i]["职等"].ToString();
// var dept = await Db.Queryable<Ghro_Dept>().Where(x => x.DeptName == deptName).FirstAsync();
// if (dept == null)
// {
// comments.Add($"无效的部门名称!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// var title = await Db.Queryable<Ghra_Title>().Where(x => x.TitleName == titleName).FirstAsync();
// if (title == null)
// {
// comments.Add($"无效的岗位名称!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// var job = await Db.Queryable<Ghra_Job>().Where(x => x.JobName == jobName).FirstAsync();
// if (job == null)
// {
// comments.Add($"无效的职称名称!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// var grade = await Db.Queryable<Ghra_Grade>().Where(x => x.GradeName == gradeName).FirstAsync();
// if (grade == null)
// {
// comments.Add($"无效的职等名称!");
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// if (1 == 1)
// {
// var dict = new Dictionary<string, object>
// {
// { "Id", SnowFlakeSingle.Instance.NextId() },
// { "CreateBy", App.User.ID },
// { "CreateTime", DateTime.Now },
// { "WorkState", 1 },
// { "Year", year },
// { "DeptId", dept.DeptID },
// { "TitleId", title.TitleID },
// { "GradeId", grade.GradeID },
// { "JobId", job.JobID }
// };
// for (int j = 1; j <= 12; j++)
// dict.Add("M" + j, dt.Rows[i][j + "月"].ToString());
// await Db.Insertable(dict).AS("Ghrh_YearHumanSettings").ExecuteCommandAsync();
// if (comments.Any())
// {
// data.ErrorCount++;
// dt.Rows[i]["Comments"] = string.Join(";", comments.Select(a => a));
// isExistError = true;
// continue;
// }
// else
// {
// data.SuccessCount++;
// }
// }
// else
// {
// dt.Rows[i]["Comments"] = "试题在系统中已存在!";
// data.ErrorCount++;
// isExistError = true;
// continue;
// }
// }
// if (isExistError)
// {
// NPOIHelper.ExportExcel(dt, null, "年度人力配置", physicsPath + errorFileName);
// data.filePath = "/Advanced" + errorFileName;
// }
// }
// catch (Exception)
// {
// }
// return ServiceResult<ExcelData>.OprateSuccess("导入成功!", data);
//}
//public override async Task<ServiceResult<string>> 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(Ghrh_YearHumanSettings);
// var fileName = entityType.GetEntityTableName() + ".xlsx";
// //physicsPath = physicsPath + path + fileName;
// IWorkbook hssfworkbook;
// ISheet sheet;
// using (FileStream file = new FileStream(physicsPath + path + fileName, FileMode.Open, FileAccess.Read))
// {
// //hssfworkbook = new HSSFWorkbook(file);
// //hssfworkbook = new XSSFWorkbook(file);
// hssfworkbook = WorkbookFactory.Create(file);
// }
// //ISheet sheet2 = hssfworkbook.CreateSheet("下拉数据");
// var newFileName = Guid.NewGuid() + ".xlsx";
// int listColIndex = 0;
// var physicsPath1 = physicsPath + path + fileName;
// //if (dataSourceLists.Any())
// // physicsPath1 = physicsPath + path + newFileName;
// var result = ServiceResult<string>.OprateSuccess("人力需求维护_" + DateTimeHelper.ConvertToSecondString1(DateTime.Now) + ".xlsx", physicsPath1);
// return result;
//}
//#endregion
#region Excel导入
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 ) ;
string errorFileName = path + SnowFlakeSingle . instance . getID ( ) + FileHelper . GetPostfixStr ( filepath ) ;
var dt = ReportHelper . ReadImportExcel ( filepath ) ;
var columns = await QueryExportColumn ( menuName ) ;
var ( dictList , errorCount ) = await ReportHelper . ValidImportExcel ( Db , columns , dt ) ;
if ( errorCount > 0 )
{
NPOIHelper . ExportExcel ( dt , null , "导入数据" , FileHelper . GetPhysicsPath ( ) + errorFileName ) ;
data . filePath = "/Advanced" + errorFileName ;
data . ErrorCount = errorCount ;
}
else
{
for ( int i = 0 ; i < dictList . Count ; i + + )
{
var dict = dictList [ i ] ;
if ( menuName = = "F_ManReqMainten" )
dict . Add ( "Status" , "Wait" ) ;
else
if ( menuName = = "F_ManReqMaintenTemporary" )
dict . Add ( "Status" , "Temporary" ) ;
if ( dict . ContainsKey ( "Quality" ) )
{
await _ ghrh_HumanRequestDetailServices . Add ( new InsertGhrh_HumanRequestDetailInput ( )
{
RequestId = dict [ "Id" ] . ObjToLong ( ) ,
DetailName = dict [ "Quality" ] . ObjToString ( ) ,
Source = "Quality"
} ) ;
dict . Remove ( "Quality" ) ;
}
if ( dict . ContainsKey ( "Experience" ) )
{
await _ ghrh_HumanRequestDetailServices . Add ( new InsertGhrh_HumanRequestDetailInput ( )
{
RequestId = dict [ "Id" ] . ObjToLong ( ) ,
DetailName = dict [ "Experience" ] . ObjToString ( ) ,
Source = "Experience"
} ) ;
dict . Remove ( "Experience" ) ;
}
await Db . Insertable ( dict ) . AS ( "Ghrh_HumanRequest" ) . ExecuteCommandAsync ( ) ;
var sql = $"SELECT ISNULL(MAX(id)+1,1) FROM Ghrh_HumanRequest WHERE Id !='{dict[" Id "]}'" ;
var id1 = await Db . Ado . GetLongAsync ( sql ) ;
sql = $"UPDATE Ghrh_HumanRequest SET Id={id1} WHERE Id ='{dict[" Id "]}';" +
$"UPDATE Ghrh_HumanRequestDetail SET RequestId={id1} WHERE RequestId ='{dict[" Id "]}';" ;
await Db . Ado . ExecuteCommandAsync ( sql ) ;
}
data . SuccessCount = dictList . Count ;
}
return ServiceResult < ExcelData > . OprateSuccess ( "导入成功!" , data ) ;
}
# endregion
}