staging #44
|
|
@ -180,6 +180,8 @@ namespace Learn.Archives.API.Controllers
|
|||
admin.RoleId = (long)roleDic[imp.Role];
|
||||
admin.Password = imp.Password.Trim().GetMD5();
|
||||
insertInfo.Add(admin);
|
||||
//excel内预计新增的账号也计入重复
|
||||
accountH.Add(admin.Account);
|
||||
}
|
||||
|
||||
if (errorExcelInfo.Count != 0)
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ namespace Learn.Archives.API.Controllers
|
|||
ReliefType =s.ReliefType,
|
||||
StudentType =s.StudentType.ToEnum<StudentTypeEnum>(),
|
||||
});
|
||||
userCenterImp.Add(new UserExcelExportData()
|
||||
var addExcelUser = new UserExcelExportData()
|
||||
{
|
||||
UserType = "学生",
|
||||
Account = s.Id.ToString(),
|
||||
|
|
@ -312,7 +312,10 @@ namespace Learn.Archives.API.Controllers
|
|||
Phone = s.Phone,
|
||||
RealName = s.RealName,
|
||||
Stages = s.Grade.Contains("初") ? StudentStagesEnum.初中.ToString() : StudentStagesEnum.高中.ToString()
|
||||
});
|
||||
};
|
||||
userCenterImp.Add(addExcelUser);
|
||||
if (!string.IsNullOrWhiteSpace(s.高考选科))
|
||||
addExcelUser.GKSubject = s.高考选科;
|
||||
}
|
||||
|
||||
//如果有错误数据则返回excel
|
||||
|
|
@ -341,10 +344,51 @@ namespace Learn.Archives.API.Controllers
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导入excel 更新学生信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost, ResultIgnore]
|
||||
[HttpLogEnable]
|
||||
public async Task<IActionResult> ImportUpdateStudent(IFormFile? file)
|
||||
{
|
||||
var dataList = await _httpContextAccessor
|
||||
.ParsingExcelAsync<StudentInfoImportError>();
|
||||
if (dataList == null || dataList.Count() == 0)
|
||||
Oh.ModelError("导入失败:无有效数据");
|
||||
var insertInfo = new List<Student>();
|
||||
var impError = new List<StudentInfoImportError>();
|
||||
var userCenterImp = new List<UserExcelExportData>();
|
||||
|
||||
|
||||
//如果有错误数据则返回excel
|
||||
if (impError.Count() != 0)
|
||||
return File(impError.ExportExcel(), "application/ms-excel", $"导入错误学生{DateTime.Now.ToString("MMddHHmm")}.xlsx");
|
||||
//调用 用户中心 导入接口
|
||||
var importRes = await _userCenterService.CallAPI_ImportJsonData(_httpContextAccessor.HttpContext, userCenterImp);
|
||||
|
||||
var hUAccount = importRes.InsertUsers.ToDictionary(s => s.Account, s => s.Id);
|
||||
//基于结果判断添加成功`
|
||||
insertInfo = insertInfo
|
||||
.Where(s => hUAccount.ContainsKey(s.UserCenterId.ToString())).Select(s =>
|
||||
{
|
||||
s.UserCenterId = hUAccount[s.UserCenterId.ToString()];
|
||||
return s;
|
||||
}).ToList();
|
||||
//部分成功的数据写入数据库
|
||||
await baseService.InsertRangeAsync(insertInfo);
|
||||
//处理数据
|
||||
var errorExcelInfo = importRes.ErrorExcelExport.Select(s => s.Adapt<StudentInfoImportError>());
|
||||
//如果有错误数据则返回excel
|
||||
if (errorExcelInfo.Count() != 0)
|
||||
return File(errorExcelInfo.ExportExcel(), "application/ms-excel", $"导入错误学生{DateTime.Now.ToString("MMddHHmm")}.xlsx");
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 下载导入模板
|
||||
/// </summary>
|
||||
|
|
@ -365,6 +409,7 @@ namespace Learn.Archives.API.Controllers
|
|||
StudentType = "选填: 可选值:\r\n复读生\r\n艺术生\r\n春招生\r\n领导承诺批准全免\r\n资源班\r\n国际班\r\n合同制收费学校\r\n渠道商家属\r\n新开班但领导承诺第一学期不收费",
|
||||
Phone="选填",
|
||||
Remark="选填",
|
||||
高考选科 = "填写学科\r\n 例如 物理 \r\n多学科情况下 物理,化学,生物"
|
||||
} };
|
||||
return File(resultList.ExportExcel(), "application/ms-excel",
|
||||
$"导入学生模板{DateTime.Now.ToString("MMddHHmm")}.xlsx");
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ using System.Threading.Tasks;
|
|||
using UserCenter.Model.Interface;
|
||||
using MiniExcelLibs;
|
||||
using MiniExcelLibs.OpenXml;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Learn.Archives.Core.Model.Dto;
|
||||
|
||||
namespace Learn.Archives.Core.Common
|
||||
{
|
||||
|
|
@ -146,7 +148,35 @@ namespace Learn.Archives.Core.Common
|
|||
};
|
||||
return JsonSerializer.Serialize(o, jsonOptions);
|
||||
}
|
||||
/// <summary>
|
||||
/// 解析Excel为对象数组
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<T[]?> ParsingExcelAsync<T>(this IHttpContextAccessor context) where T: class, new()
|
||||
{
|
||||
if (context == null) Oh.ModelError("传入无效的请求上下文数据");
|
||||
var fl =context?.HttpContext?.Request.Form.Files[0];
|
||||
if (fl == null) Oh.ModelError("传入无效的Excel数据");
|
||||
if (!Path.GetExtension(fl.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
|
||||
Oh.ModelError("请选择导入文件为.xlsx的后缀名!");
|
||||
|
||||
try
|
||||
{
|
||||
//分析excel
|
||||
IEnumerable<T> dataList;
|
||||
using var stream = new MemoryStream();
|
||||
{
|
||||
await fl.CopyToAsync(stream);
|
||||
return stream.Query<T>().ToArray();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Oh.Error<T[]>("分析失败"+ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取应用有效程序集
|
||||
|
|
|
|||
|
|
@ -214,6 +214,12 @@ namespace Learn.Archives.Core.Model.Dto
|
|||
[ExcelColumn(Name = "备注",Width =50)]
|
||||
public string? Remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 高考选科
|
||||
/// <para></para>
|
||||
/// </summary>
|
||||
[ExcelColumn(Name = "高考选科", Width = 20)]
|
||||
public string? 高考选科 { get; set; }
|
||||
/// <summary>
|
||||
/// id
|
||||
/// </summary>
|
||||
|
|
@ -311,6 +317,11 @@ namespace Learn.Archives.Core.Model.Dto
|
|||
/// </summary>
|
||||
[ExcelColumn(Name="学段")]
|
||||
public string? Stages { get; set; }
|
||||
/// <summary>
|
||||
/// 选修方向
|
||||
/// </summary>
|
||||
[ExcelColumnName("选修方向")]
|
||||
public string? GKSubject { get; set; }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue