Compare commits
No commits in common. "7d5f8984df1a0aeac3aeb7b5ceba0b9a1722e4b1" and "34ea470652484d4e96bde12742674b25edbf7d0d" have entirely different histories.
7d5f8984df
...
34ea470652
|
|
@ -180,8 +180,6 @@ namespace Learn.Archives.API.Controllers
|
||||||
admin.RoleId = (long)roleDic[imp.Role];
|
admin.RoleId = (long)roleDic[imp.Role];
|
||||||
admin.Password = imp.Password.Trim().GetMD5();
|
admin.Password = imp.Password.Trim().GetMD5();
|
||||||
insertInfo.Add(admin);
|
insertInfo.Add(admin);
|
||||||
//excel内预计新增的账号也计入重复
|
|
||||||
accountH.Add(admin.Account);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorExcelInfo.Count != 0)
|
if (errorExcelInfo.Count != 0)
|
||||||
|
|
|
||||||
|
|
@ -31,20 +31,13 @@ namespace Learn.Archives.API.Controllers
|
||||||
readonly Repository<Position> positionService;
|
readonly Repository<Position> positionService;
|
||||||
readonly UserCenterService _userCenterService;
|
readonly UserCenterService _userCenterService;
|
||||||
readonly LiveUserInfo userInfo;
|
readonly LiveUserInfo userInfo;
|
||||||
readonly Repository<School> schoolService;
|
public StudentController(Repository<Student> baseService, LiveUserInfo userInfo, IHttpContextAccessor httpContextAccessor, UserCenterService userCenterService, Repository<Position> positionService) : base(baseService)
|
||||||
readonly Repository<Classes> classesService;
|
|
||||||
readonly Repository<User> userService;
|
|
||||||
|
|
||||||
public StudentController(Repository<Student> baseService, LiveUserInfo userInfo, IHttpContextAccessor httpContextAccessor, UserCenterService userCenterService, Repository<Position> positionService, Repository<School> schoolService, Repository<Classes> classesService, Repository<User> userService) : base(baseService)
|
|
||||||
{
|
{
|
||||||
this.baseService = baseService;
|
this.baseService = baseService;
|
||||||
this.userInfo = userInfo;
|
this.userInfo = userInfo;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_userCenterService = userCenterService;
|
_userCenterService = userCenterService;
|
||||||
this.positionService = positionService;
|
this.positionService = positionService;
|
||||||
this.schoolService = schoolService;
|
|
||||||
this.classesService = classesService;
|
|
||||||
this.userService = userService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[NonAction]
|
[NonAction]
|
||||||
|
|
@ -308,7 +301,7 @@ namespace Learn.Archives.API.Controllers
|
||||||
ReliefType =s.ReliefType,
|
ReliefType =s.ReliefType,
|
||||||
StudentType =s.StudentType.ToEnum<StudentTypeEnum>(),
|
StudentType =s.StudentType.ToEnum<StudentTypeEnum>(),
|
||||||
});
|
});
|
||||||
var addExcelUser = new UserExcelExportData()
|
userCenterImp.Add(new UserExcelExportData()
|
||||||
{
|
{
|
||||||
UserType = "学生",
|
UserType = "学生",
|
||||||
Account = s.Id.ToString(),
|
Account = s.Id.ToString(),
|
||||||
|
|
@ -319,10 +312,7 @@ namespace Learn.Archives.API.Controllers
|
||||||
Phone = s.Phone,
|
Phone = s.Phone,
|
||||||
RealName = s.RealName,
|
RealName = s.RealName,
|
||||||
Stages = s.Grade.Contains("初")? StudentStagesEnum.初中.ToString() : StudentStagesEnum.高中.ToString()
|
Stages = s.Grade.Contains("初")? StudentStagesEnum.初中.ToString() : StudentStagesEnum.高中.ToString()
|
||||||
};
|
});
|
||||||
userCenterImp.Add(addExcelUser);
|
|
||||||
if (!string.IsNullOrWhiteSpace(s.高考选科))
|
|
||||||
addExcelUser.GKSubject = s.高考选科;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果有错误数据则返回excel
|
//如果有错误数据则返回excel
|
||||||
|
|
@ -351,145 +341,6 @@ 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.Length == 0)
|
|
||||||
Oh.ModelError("导入失败:无有效数据");
|
|
||||||
|
|
||||||
var updateArr = new List<Student>();
|
|
||||||
var impError = new List<StudentInfoImportError>();
|
|
||||||
var userCenterUpdate = new List<User>();
|
|
||||||
|
|
||||||
var db = schoolService.Context;
|
|
||||||
var schoolDic = await schoolService.AsQueryable().ToDictionaryAsync(s => s.Name, s => s.Id);
|
|
||||||
|
|
||||||
foreach (var schoolGroup in dataList.GroupBy(s => s.School))
|
|
||||||
{
|
|
||||||
if (!schoolDic.ContainsKey(schoolGroup.Key))
|
|
||||||
Oh.ModelError($"未能识别的学校[{schoolGroup.Key}]");
|
|
||||||
var schoolId = (long)schoolDic[schoolGroup.Key];
|
|
||||||
var names = schoolGroup.Select(r => r.RealName)
|
|
||||||
.Where(n => !string.IsNullOrWhiteSpace(n)).Distinct().ToList();
|
|
||||||
var userDic = new Dictionary<string, long>();
|
|
||||||
for (int i = 0; i < names.Count; i += 500)
|
|
||||||
{
|
|
||||||
var batch = names.Skip(i).Take(500).ToList();
|
|
||||||
var part = await db.Queryable<School>()
|
|
||||||
.LeftJoin<Classes>((s, c) => c.SchoolId == s.Id)
|
|
||||||
.LeftJoin<Position>((s, c, p) => p.ClassId == c.Id)
|
|
||||||
.LeftJoin<PositionRelation>((s, c, p, pr) => pr.PositionId == p.Id)
|
|
||||||
.LeftJoin<User>((s, c, p, pr, u) => u.Id == pr.UserId)
|
|
||||||
.Where((s, c, p, pr, u) =>
|
|
||||||
s.Id == schoolId &&
|
|
||||||
u.UserType == UserTypeEnum.学生.GetHashCode() &&
|
|
||||||
batch.Contains(u.RealName) &&
|
|
||||||
s.Enable && p.Enable && pr.Enable &&
|
|
||||||
!p.DeleteState && !c.DeleteState && !u.DeleteState && !s.DeleteState)
|
|
||||||
.Select((s, c, p, pr, u) => new
|
|
||||||
{
|
|
||||||
Name = c.GradeLevel.ToString() + c.GraduationYear.ToString() + c.Name + u.RealName,
|
|
||||||
u.Id,
|
|
||||||
}).ToListAsync();
|
|
||||||
foreach (var kv in part)
|
|
||||||
userDic[kv.Name] = (long)kv.Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var row in schoolGroup)
|
|
||||||
{
|
|
||||||
var ginfo = GradeHelper.GetStudentGradeBaseByGrade(row.Grade);
|
|
||||||
var key = (ginfo?.GradeLevel.ToString() ?? string.Empty) + (ginfo?.GradeYear.ToString() ?? string.Empty) + row.Class + row.RealName;
|
|
||||||
if (!userDic.ContainsKey(key))
|
|
||||||
{
|
|
||||||
row.ErrorMsg = "未能匹配到学校下对应的班级学生";
|
|
||||||
impError.Add(row);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var uid = (long)userDic[key];
|
|
||||||
var u = new Student()
|
|
||||||
{
|
|
||||||
UserCenterId = uid,
|
|
||||||
AmountRelief = decimal.TryParse(row.AmountRelief, out var v) ? v : 0,
|
|
||||||
ReliefApplication = row.ReliefApplication?.Contains("已申请") ?? false,
|
|
||||||
ReliefType = row.ReliefType,
|
|
||||||
ReliefSubTime = row.ReliefSubTime,
|
|
||||||
StudentType = row.StudentType.ToEnum<StudentTypeEnum>(),
|
|
||||||
Status = row.Status.ToEnum<UserStatusEnum>(),
|
|
||||||
JoinTime = row.JoinTime,
|
|
||||||
ExitTime = row.ExitTime,
|
|
||||||
Remark = row.Remark,
|
|
||||||
};
|
|
||||||
updateArr.Add(u);
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(row.高考选科))
|
|
||||||
{
|
|
||||||
var gradeStd = ginfo is null ? row.Grade : GradeHelper.GetGrade(ginfo.GradeLevel, ginfo.GradeYear);
|
|
||||||
var subjectArr = row.高考选科.Split(",")
|
|
||||||
.Select(s => s.ToEnum<SubjectEnum>())
|
|
||||||
.ToArray();
|
|
||||||
userCenterUpdate.Add(new User
|
|
||||||
{
|
|
||||||
Id = uid,
|
|
||||||
Phone = row.Phone,
|
|
||||||
GLSubject = (int?)subjectArr[0],
|
|
||||||
GSubject1 = (int?)subjectArr[1],
|
|
||||||
GSubject2 = (int?)subjectArr[2],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (impError.Count != 0)
|
|
||||||
return File(impError.ExportExcel(), "application/ms-excel", $"导入错误学生{DateTime.Now.ToString("MMddHHmm")}.xlsx");
|
|
||||||
|
|
||||||
if (updateArr.Count > 0)
|
|
||||||
{
|
|
||||||
await baseService.AsUpdateable(updateArr)
|
|
||||||
.UpdateColumns(s => new
|
|
||||||
{
|
|
||||||
s.AmountRelief,
|
|
||||||
s.ReliefApplication,
|
|
||||||
s.ReliefType,
|
|
||||||
s.ReliefSubTime,
|
|
||||||
s.StudentType,
|
|
||||||
s.Status,
|
|
||||||
s.JoinTime,
|
|
||||||
s.ExitTime,
|
|
||||||
s.Remark
|
|
||||||
})
|
|
||||||
//更新忽略null并且忽略默认值 (比如int默认值是0就不更新)
|
|
||||||
.IgnoreColumns(ignoreAllNullColumns: true, ignoreAllDefaultValue: true)
|
|
||||||
.WhereColumns(it => new { it.UserCenterId })
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
}
|
|
||||||
if (userCenterUpdate.Count > 0)
|
|
||||||
await userService.AsUpdateable(userCenterUpdate)
|
|
||||||
.UpdateColumns(s => new
|
|
||||||
{
|
|
||||||
s.Phone,
|
|
||||||
s.GLSubject,
|
|
||||||
s.GSubject1,
|
|
||||||
s.GSubject2,
|
|
||||||
})
|
|
||||||
//更新忽略null并且忽略默认值 (比如int默认值是0就不更新)
|
|
||||||
.IgnoreColumns(ignoreAllNullColumns: true, ignoreAllDefaultValue: true)
|
|
||||||
.WhereColumns(it => new { it.Id })
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Oh.Error("需要测试");
|
|
||||||
return Ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -514,7 +365,6 @@ namespace Learn.Archives.API.Controllers
|
||||||
StudentType = "选填: 可选值:\r\n复读生\r\n艺术生\r\n春招生\r\n领导承诺批准全免\r\n资源班\r\n国际班\r\n合同制收费学校\r\n渠道商家属\r\n新开班但领导承诺第一学期不收费",
|
StudentType = "选填: 可选值:\r\n复读生\r\n艺术生\r\n春招生\r\n领导承诺批准全免\r\n资源班\r\n国际班\r\n合同制收费学校\r\n渠道商家属\r\n新开班但领导承诺第一学期不收费",
|
||||||
Phone="选填",
|
Phone="选填",
|
||||||
Remark="选填",
|
Remark="选填",
|
||||||
高考选科 = "填写学科\r\n 例如 物理 \r\n多学科情况下 物理,化学,生物"
|
|
||||||
} };
|
} };
|
||||||
return File(resultList.ExportExcel(), "application/ms-excel",
|
return File(resultList.ExportExcel(), "application/ms-excel",
|
||||||
$"导入学生模板{DateTime.Now.ToString("MMddHHmm")}.xlsx");
|
$"导入学生模板{DateTime.Now.ToString("MMddHHmm")}.xlsx");
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ using System.Threading.Tasks;
|
||||||
using UserCenter.Model.Interface;
|
using UserCenter.Model.Interface;
|
||||||
using MiniExcelLibs;
|
using MiniExcelLibs;
|
||||||
using MiniExcelLibs.OpenXml;
|
using MiniExcelLibs.OpenXml;
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Learn.Archives.Core.Model.Dto;
|
|
||||||
|
|
||||||
namespace Learn.Archives.Core.Common
|
namespace Learn.Archives.Core.Common
|
||||||
{
|
{
|
||||||
|
|
@ -148,35 +146,7 @@ namespace Learn.Archives.Core.Common
|
||||||
};
|
};
|
||||||
return JsonSerializer.Serialize(o, jsonOptions);
|
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>
|
/// <summary>
|
||||||
/// 获取应用有效程序集
|
/// 获取应用有效程序集
|
||||||
|
|
|
||||||
|
|
@ -214,12 +214,6 @@ namespace Learn.Archives.Core.Model.Dto
|
||||||
[ExcelColumn(Name = "备注",Width =50)]
|
[ExcelColumn(Name = "备注",Width =50)]
|
||||||
public string? Remark { get; set; }
|
public string? Remark { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 高考选科
|
|
||||||
/// <para></para>
|
|
||||||
/// </summary>
|
|
||||||
[ExcelColumn(Name = "高考选科", Width = 20)]
|
|
||||||
public string? 高考选科 { get; set; }
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// id
|
/// id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -317,11 +311,6 @@ namespace Learn.Archives.Core.Model.Dto
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcelColumn(Name="学段")]
|
[ExcelColumn(Name="学段")]
|
||||||
public string? Stages { get; set; }
|
public string? Stages { get; set; }
|
||||||
/// <summary>
|
|
||||||
/// 选修方向
|
|
||||||
/// </summary>
|
|
||||||
[ExcelColumnName("选修方向")]
|
|
||||||
public string? GKSubject { get; set; }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue