|
|
|
@ -5,12 +5,12 @@ using Tiobon.Core.Services.BASE; |
|
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
using static Tiobon.Core.Model.Consts; |
|
|
|
|
using Tiobon.Core.Common.UserManager; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Model; |
|
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
@ -22,20 +22,49 @@ public class Ghre_TeacherChangeServices : BaseServices<Ghre_TeacherChange, Ghre_ |
|
|
|
|
private readonly IBaseRepository<Ghre_TeacherChange> _dal; |
|
|
|
|
private IGhre_AttachmentServices _ghre_AttachmentServices; |
|
|
|
|
private IGhre_TeacherChangeAttachmentServices _ghre_TeacherChangeAttachmentServices; |
|
|
|
|
private IGhre_TeacherAttachmentServices _ghre_TeacherAttachmentServices; |
|
|
|
|
public Ghre_TeacherChangeServices(ICaching caching, |
|
|
|
|
IGhre_AttachmentServices ghre_AttachmentServices, |
|
|
|
|
IGhre_TeacherChangeAttachmentServices ghre_TeacherChangeAttachmentServices, IBaseRepository<Ghre_TeacherChange> dal) |
|
|
|
|
IGhre_TeacherChangeAttachmentServices ghre_TeacherChangeAttachmentServices, |
|
|
|
|
IGhre_TeacherAttachmentServices ghre_TeacherAttachmentServices, |
|
|
|
|
IBaseRepository<Ghre_TeacherChange> dal) |
|
|
|
|
{ |
|
|
|
|
this._dal = dal; |
|
|
|
|
base.BaseDal = dal; |
|
|
|
|
base._caching = caching; |
|
|
|
|
_ghre_AttachmentServices = ghre_AttachmentServices; |
|
|
|
|
_ghre_TeacherChangeAttachmentServices = ghre_TeacherChangeAttachmentServices; |
|
|
|
|
_ghre_TeacherAttachmentServices = ghre_TeacherAttachmentServices; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override async Task<ServicePageResult<Ghre_TeacherChangeDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) |
|
|
|
|
{ |
|
|
|
|
var result = await base.QueryFilterPage(filter, condition, IsEnable); |
|
|
|
|
|
|
|
|
|
var data = result.result.DT_TableDataT1; |
|
|
|
|
|
|
|
|
|
var schoolIds = data.Where(x => x.SchoolId != null).Select(x => x.SchoolId.Value).Distinct().ToList(); |
|
|
|
|
var deptIDs = data.Where(x => x.DeptID != null).Select(x => x.DeptID).Distinct().ToList(); |
|
|
|
|
var teacherIds = data.Where(x => x.TeacherId != null).Select(x => x.TeacherId).Distinct().ToList(); |
|
|
|
|
|
|
|
|
|
var depts = await Db.Queryable<Ghro_Dept>().Where(x => deptIDs.Contains(x.DeptID)).Select(x => new { x.DeptID, x.DeptName }).ToListAsync(); |
|
|
|
|
var schools = await Db.Queryable<Ghre_School>().Where(x => schoolIds.Contains(x.Id)).Select(x => new { x.Id, x.SchoolName }).ToListAsync(); |
|
|
|
|
var teachers = await Db.Queryable<Ghre_Teacher>().Where(x => teacherIds.Contains(x.Id)).Select(x => new { x.Id, TeacherName = x.TeacherName + " (" + x.TeacherNo + ")" }).ToListAsync(); |
|
|
|
|
|
|
|
|
|
data.ForEach(async x => |
|
|
|
|
{ |
|
|
|
|
x.TeacherTypeLabel = await GetParaLabel("TrainingTeacherType", x.TeacherType); |
|
|
|
|
x.TeacherLevelLabel = await GetParaLabel("TrainingTeacherLevel", x.TeacherLevel); |
|
|
|
|
x.OriginTeacherLevelLabel = await GetParaLabel("TrainingTeacherLevel", x.OriginTeacherLevel); |
|
|
|
|
x.ChangeTypeLabel = await GetParaLabel("TrainingTeacherChangeType", x.ChangeType); |
|
|
|
|
x.OriginChangeTypeLabel = await GetParaLabel("TrainingTeacherChangeType", x.OriginChangeType); |
|
|
|
|
x.DeptOrSchoolName = x.TeacherType == "Out" ? schools.FirstOrDefault(o => o.Id == x.SchoolId)?.SchoolName : depts.FirstOrDefault(o => o.DeptID == x.DeptID)?.DeptName; |
|
|
|
|
x.TeacherName = teachers.FirstOrDefault(o => o.Id == x.TeacherId)?.TeacherName; |
|
|
|
|
x.OriginChangeDate1 = DateTimeHelper.ConvertToDayString(x.OriginChangeDate); |
|
|
|
|
x.ChangeDate1 = DateTimeHelper.ConvertToDayString(x.ChangeDate); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
result.result.DT_TableDataT1 = data; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -63,22 +92,15 @@ public class Ghre_TeacherChangeServices : BaseServices<Ghre_TeacherChange, Ghre_ |
|
|
|
|
|
|
|
|
|
public override async Task<long> Add(InsertGhre_TeacherChangeInput entity) |
|
|
|
|
{ |
|
|
|
|
#region 校验 当天是否能发起 |
|
|
|
|
if (await Db.Queryable<Ghre_TeacherChange>().AnyAsync(x => x.TeacherId == entity.TeacherId && ((x.Status == "Wait") || (x.Status != "Wait" && x.WorkState != 2)))) |
|
|
|
|
throw new Exception("讲师当天只能发起一笔有效异动!"); |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
if (entity.TeacherType == "In") |
|
|
|
|
{ |
|
|
|
|
entity.SchoolId = null; |
|
|
|
|
var staff = await Db.Queryable<Ghra_Staff>().FirstAsync(x => x.StaffID == entity.StaffId); |
|
|
|
|
if (staff != null) |
|
|
|
|
{ |
|
|
|
|
entity.TeacherNo = staff.StaffNo; |
|
|
|
|
entity.TeacherName = staff.StaffName; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
entity.DeptID = null; |
|
|
|
|
entity.StaffId = null; |
|
|
|
|
} |
|
|
|
|
var teacher = await Db.Queryable<Ghre_Teacher>().FirstAsync(x => x.Id == entity.TeacherId); |
|
|
|
|
|
|
|
|
|
entity.SchoolId = teacher.SchoolId; |
|
|
|
|
entity.DeptID = teacher.DeptID; |
|
|
|
|
|
|
|
|
|
var id = await base.Add(entity); |
|
|
|
|
var sql = $"SELECT ISNULL(MAX(id)+1,1) FROM Ghre_TeacherChange WHERE Id !='{id}'"; |
|
|
|
@ -104,6 +126,7 @@ public class Ghre_TeacherChangeServices : BaseServices<Ghre_TeacherChange, Ghre_ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -154,7 +177,44 @@ public class Ghre_TeacherChangeServices : BaseServices<Ghre_TeacherChange, Ghre_ |
|
|
|
|
|
|
|
|
|
data.Success = id > 0; |
|
|
|
|
if (data.Success) |
|
|
|
|
{ |
|
|
|
|
data.Data = id; |
|
|
|
|
#region 状态是Wait 直接会写至主数据 |
|
|
|
|
if (status == "Wait") |
|
|
|
|
{ |
|
|
|
|
var teacher = Mapper.Map(insertModel).ToANew<Ghre_Teacher>(); |
|
|
|
|
teacher.Id = insertModel.TeacherId.Value; |
|
|
|
|
await Db.Updateable(teacher).UpdateColumns(it => new { it.TeacherLevel, it.Price, it.SkillPoints }).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
|
var teacherAttachmentIds = await Db.Queryable<Ghre_TeacherAttachment>().Where(x => x.TeacherId == insertModel.TeacherId).Select(x => x.Id).ToListAsync(); |
|
|
|
|
if (teacherAttachmentIds.Any()) |
|
|
|
|
await Db.Updateable<Ghre_TeacherAttachment>() |
|
|
|
|
.SetColumns(it => new Ghre_TeacherAttachment() |
|
|
|
|
{ |
|
|
|
|
IsEnable = 0 |
|
|
|
|
}) |
|
|
|
|
.Where(it => teacherAttachmentIds.Contains(it.Id)) |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
|
if (insertModel.TeacherAttachments != null && insertModel.TeacherAttachments.Any()) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < insertModel.TeacherAttachments.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var insert = Mapper.Map(insertModel.TeacherAttachments[i]).ToANew<InsertGhre_TeacherAttachmentInput>(); ; |
|
|
|
|
insert.TeacherId = teacher.Id; |
|
|
|
|
var teacherAttachmentId = await _ghre_TeacherAttachmentServices.Add(insert); |
|
|
|
|
if (insertModel.TeacherAttachments[i].Attachments != null && insertModel.TeacherAttachments[i].Attachments.Any()) |
|
|
|
|
for (int j = 0; j < insertModel.TeacherAttachments[i].Attachments.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var attachment = await Db.Queryable<Ghre_Attachment>().FirstAsync(x => x.RelativePath == insert.Attachments[j].RelativePath); |
|
|
|
|
attachment.TableName = teacherAttachmentId.ToString(); |
|
|
|
|
await Db.Insertable(attachment).ExecuteReturnSnowflakeIdAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
return ServiceResult<long>.OprateFailed("发布成功!"); |
|
|
|
|
|
|
|
|
@ -201,4 +261,65 @@ public class Ghre_TeacherChangeServices : BaseServices<Ghre_TeacherChange, Ghre_ |
|
|
|
|
return ServiceResult.OprateSuccess("执行成功!"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult<Ghre_TeacherChangeDto>> QueryLast(int teacherId) |
|
|
|
|
{ |
|
|
|
|
var change = new Ghre_TeacherChangeDto(); |
|
|
|
|
var change1 = await Db.Queryable<Ghre_TeacherChange>().OrderByDescending(x => x.CreateTime).FirstAsync(x => x.TeacherId == teacherId && (x.Status == "Active" || x.Status == "Wait")); |
|
|
|
|
if (change1 != null) |
|
|
|
|
{ |
|
|
|
|
change = Mapper.Map(change1).ToANew<Ghre_TeacherChangeDto>(); |
|
|
|
|
change.OriginChangeDate = change.ChangeDate; |
|
|
|
|
change.OriginChangeType = change.ChangeType; |
|
|
|
|
change.OriginPrice = change.Price; |
|
|
|
|
change.OriginSkillPoints = change.SkillPoints; |
|
|
|
|
change.OriginTeacherLevel = change.TeacherLevel; |
|
|
|
|
|
|
|
|
|
change.ChangeDate = null; |
|
|
|
|
change.ChangeType = null; |
|
|
|
|
change.Price = null; |
|
|
|
|
change.SkillPoints = null; |
|
|
|
|
change.TeacherLevel = null; |
|
|
|
|
change.RemarkSz = null; |
|
|
|
|
change.DeptOrSchoolName = change.TeacherType == "Out" ? (await Db.Queryable<Ghre_School>().FirstAsync(o => o.Id == change.SchoolId))?.SchoolName : (await Db.Queryable<Ghro_Dept>().FirstAsync(o => o.DeptID == change.DeptID))?.DeptName; |
|
|
|
|
|
|
|
|
|
var teacherAttachments = await Db.Queryable<Ghre_TeacherChangeAttachment>().Where(x => x.TeacherChangeId == change.Id).ToListAsync(); |
|
|
|
|
|
|
|
|
|
change.TeacherAttachments = Mapper.Map(teacherAttachments).ToANew<List<Ghre_TeacherChangeAttachmentDto>>(); |
|
|
|
|
var ids1 = teacherAttachments.Select(x => x.Id.ToString()).ToList(); |
|
|
|
|
var attachments = await _ghre_AttachmentServices.QueryDto(x => ids1.Contains(x.TableName)); |
|
|
|
|
change.TeacherAttachments.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.Attachments = attachments.Where(o => o.TableName == x.Id.ToString()).ToList(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
var teacher = await Db.Queryable<Ghre_Teacher>().FirstAsync(x => x.Id == teacherId); |
|
|
|
|
if (teacher != null) |
|
|
|
|
{ |
|
|
|
|
change.TeacherType = teacher.TeacherType; |
|
|
|
|
change.OriginTeacherLevel = teacher.TeacherLevel; |
|
|
|
|
change.OriginPrice = teacher.Price; |
|
|
|
|
change.OriginSkillPoints = teacher.SkillPoints; |
|
|
|
|
change.SchoolId = teacher.SchoolId; |
|
|
|
|
change.DeptID = teacher.DeptID; |
|
|
|
|
change.DeptOrSchoolName = change.OriginTeacherLevel == "Out" ? (await Db.Queryable<Ghre_School>().FirstAsync(o => o.Id == change.SchoolId))?.SchoolName : (await Db.Queryable<Ghro_Dept>().FirstAsync(o => o.DeptID == change.DeptID))?.DeptName; |
|
|
|
|
change.PhotoUrl = teacher.PhotoUrl; |
|
|
|
|
|
|
|
|
|
var teacherAttachments = await Db.Queryable<Ghre_TeacherAttachment>().Where(x => x.TeacherId == teacher.Id).ToListAsync(); |
|
|
|
|
|
|
|
|
|
change.TeacherAttachments = Mapper.Map(teacherAttachments).ToANew<List<Ghre_TeacherChangeAttachmentDto>>(); |
|
|
|
|
var ids1 = teacherAttachments.Select(x => x.Id.ToString()).ToList(); |
|
|
|
|
var attachments = await _ghre_AttachmentServices.QueryDto(x => ids1.Contains(x.TableName)); |
|
|
|
|
change.TeacherAttachments.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.Attachments = attachments.Where(o => o.TableName == x.Id.ToString()).ToList(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ServiceResult<Ghre_TeacherChangeDto>.OprateSuccess("执行成功!", change); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |