|
|
|
@ -4,20 +4,201 @@ using Tiobon.Core.Model.Models; |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services |
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 培训讲师异动 (服务) |
|
|
|
|
/// </summary> |
|
|
|
|
public class Ghre_TeacherChangeServices : BaseServices<Ghre_TeacherChange, Ghre_TeacherChangeDto, InsertGhre_TeacherChangeInput, EditGhre_TeacherChangeInput>, IGhre_TeacherChangeServices |
|
|
|
|
{ |
|
|
|
|
/// <summary> |
|
|
|
|
/// 培训讲师异动 (服务) |
|
|
|
|
/// </summary> |
|
|
|
|
public class Ghre_TeacherChangeServices : BaseServices<Ghre_TeacherChange, Ghre_TeacherChangeDto, InsertGhre_TeacherChangeInput, EditGhre_TeacherChangeInput>, IGhre_TeacherChangeServices |
|
|
|
|
private readonly IBaseRepository<Ghre_TeacherChange> _dal; |
|
|
|
|
private IGhre_AttachmentServices _ghre_AttachmentServices; |
|
|
|
|
private IGhre_TeacherChangeAttachmentServices _ghre_TeacherChangeAttachmentServices; |
|
|
|
|
public Ghre_TeacherChangeServices(ICaching caching, |
|
|
|
|
IGhre_AttachmentServices ghre_AttachmentServices, |
|
|
|
|
IGhre_TeacherChangeAttachmentServices ghre_TeacherChangeAttachmentServices, IBaseRepository<Ghre_TeacherChange> dal) |
|
|
|
|
{ |
|
|
|
|
this._dal = dal; |
|
|
|
|
base.BaseDal = dal; |
|
|
|
|
base._caching = caching; |
|
|
|
|
_ghre_AttachmentServices = ghre_AttachmentServices; |
|
|
|
|
_ghre_TeacherChangeAttachmentServices = ghre_TeacherChangeAttachmentServices; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override async Task<ServicePageResult<Ghre_TeacherChangeDto>> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) |
|
|
|
|
{ |
|
|
|
|
var result = await base.QueryFilterPage(filter, condition, IsEnable); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override async Task<ServiceFormResult<Ghre_TeacherChangeDto>> QueryForm(QueryForm body) |
|
|
|
|
{ |
|
|
|
|
var data = await base.QueryForm(body); |
|
|
|
|
var entitys = data.result.DT_TableDataT1; |
|
|
|
|
var ids = entitys.Select(x => x.Id).ToList(); |
|
|
|
|
var teacherAttachments = await _ghre_TeacherChangeAttachmentServices.QueryDto(x => ids.Contains(x.TeacherChangeId.Value)); |
|
|
|
|
var ids1 = teacherAttachments.Select(x => x.Id.ToString()).ToList(); |
|
|
|
|
var attachments = await _ghre_AttachmentServices.QueryDto(x => ids1.Contains(x.TableName)); |
|
|
|
|
|
|
|
|
|
teacherAttachments.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.Attachments = attachments.Where(o => o.TableName == x.Id.ToString()).ToList(); |
|
|
|
|
}); |
|
|
|
|
entitys.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.TeacherAttachments = teacherAttachments.Where(o => o.TeacherChangeId == x.Id).ToList(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
data.result.DT_TableDataT1 = entitys; |
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override async Task<long> Add(InsertGhre_TeacherChangeInput entity) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
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 id = await base.Add(entity); |
|
|
|
|
var sql = $"SELECT MAX(id)+1 FROM Ghre_Teacher WHERE Id !='{id}'"; |
|
|
|
|
var id1 = await Db.Ado.GetLongAsync(sql); |
|
|
|
|
sql = $"UPDATE Ghre_Teacher SET Id={id1} WHERE Id ='{id}'"; |
|
|
|
|
await Db.Ado.ExecuteCommandAsync(sql); |
|
|
|
|
id = id1; |
|
|
|
|
|
|
|
|
|
if (entity.TeacherAttachments != null && entity.TeacherAttachments.Any()) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < entity.TeacherAttachments.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var insert = entity.TeacherAttachments[i]; |
|
|
|
|
insert.TeacherChangeId = id; |
|
|
|
|
var teacherAttachmentId = await _ghre_TeacherChangeAttachmentServices.Add(insert); |
|
|
|
|
if (insert.Attachments != null && insert.Attachments.Any()) |
|
|
|
|
for (int j = 0; j < insert.Attachments.Count; j++) |
|
|
|
|
{ |
|
|
|
|
await Db.Updateable<Ghre_Attachment>() |
|
|
|
|
.SetColumns(it => new Ghre_Attachment() { TableName = teacherAttachmentId.ToString(), UpdateTime = DateTime.Now }) |
|
|
|
|
.Where(it => it.RelativePath == insert.Attachments[j].RelativePath) |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override async Task<bool> Update(long Id, EditGhre_TeacherChangeInput editModel) |
|
|
|
|
{ |
|
|
|
|
if (editModel.TeacherType == "In") |
|
|
|
|
{ |
|
|
|
|
editModel.SchoolId = null; |
|
|
|
|
var staff = await Db.Queryable<Ghra_Staff>().FirstAsync(x => x.StaffID == editModel.StaffId); |
|
|
|
|
if (staff != null) |
|
|
|
|
{ |
|
|
|
|
editModel.TeacherNo = staff.StaffNo; |
|
|
|
|
editModel.TeacherName = staff.StaffName; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
editModel.DeptID = null; |
|
|
|
|
editModel.StaffId = null; |
|
|
|
|
} |
|
|
|
|
var result = await base.Update(Id, editModel, null, ["Status"]); |
|
|
|
|
await _ghre_TeacherChangeAttachmentServices.Delete(x => x.TeacherChangeId == Id); |
|
|
|
|
if (editModel.TeacherAttachments != null && editModel.TeacherAttachments.Any()) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < editModel.TeacherAttachments.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var insert = editModel.TeacherAttachments[i]; |
|
|
|
|
insert.TeacherId = Id; |
|
|
|
|
var TeacherAttachmentId = await _ghre_TeacherChangeAttachmentServices.Add(Mapper.Map(insert).ToANew<InsertGhre_TeacherChangeAttachmentInput>()); |
|
|
|
|
if (insert.Attachments != null && insert.Attachments.Any()) |
|
|
|
|
for (int j = 0; j < insert.Attachments.Count; j++) |
|
|
|
|
{ |
|
|
|
|
await Db.Updateable<Ghre_Attachment>() |
|
|
|
|
.SetColumns(it => new Ghre_Attachment() { TableName = TeacherAttachmentId.ToString(), UpdateTime = DateTime.Now }) |
|
|
|
|
.Where(it => it.RelativePath == insert.Attachments[j].RelativePath) |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
public async Task<ServiceResult<long>> InsertByStatus(InsertGhre_TeacherChangeInput insertModel, string status) |
|
|
|
|
{ |
|
|
|
|
var data = ServiceResult<long>.OprateSuccess("新增成功", 0); |
|
|
|
|
insertModel.Status = status; |
|
|
|
|
var id = await Add(insertModel); |
|
|
|
|
|
|
|
|
|
data.Success = id > 0; |
|
|
|
|
if (data.Success) |
|
|
|
|
data.Data = id; |
|
|
|
|
else |
|
|
|
|
return ServiceResult<long>.OprateFailed("发布成功!"); |
|
|
|
|
|
|
|
|
|
return data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult> UpdateStatus(InsertGhre_TeacherChangeInput input, string status) |
|
|
|
|
{ |
|
|
|
|
private readonly IBaseRepository<Ghre_TeacherChange> _dal; |
|
|
|
|
public Ghre_TeacherChangeServices(ICaching caching, IBaseRepository<Ghre_TeacherChange> dal) |
|
|
|
|
|
|
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
|
var api = request.Path.ObjToString().TrimEnd('/').ToLower(); |
|
|
|
|
var ip = GetUserIp(UserContext.Context); |
|
|
|
|
|
|
|
|
|
var entities = new List<Ghre_TeacherChange>(); |
|
|
|
|
foreach (var id in input.Ids) |
|
|
|
|
{ |
|
|
|
|
this._dal = dal; |
|
|
|
|
base.BaseDal = dal; |
|
|
|
|
base._caching = caching; |
|
|
|
|
if (!BaseDal.Any(id)) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
var entity = await BaseDal.QueryById(id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (status) |
|
|
|
|
{ |
|
|
|
|
case DIC_REQUEST_STATUS.Active: |
|
|
|
|
entity.AgreeReason = input.Reason; |
|
|
|
|
entity.AgreeTime = DateTime.Now; |
|
|
|
|
entity.AgreeUserId = App.User.ID; |
|
|
|
|
break; |
|
|
|
|
case DIC_REQUEST_STATUS.Temporary: |
|
|
|
|
entity.RefuseReason = input.Reason; |
|
|
|
|
entity.RefuseTime = DateTime.Now; |
|
|
|
|
entity.RefuseUserId = App.User.ID; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
entity.UpdateIP = ip; |
|
|
|
|
entity.UpdateProg = api; |
|
|
|
|
entity.Status = status; |
|
|
|
|
entities.Add(entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var result = await BaseDal.Update(entities); |
|
|
|
|
return ServiceResult.OprateSuccess("执行成功!"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |