using Edu.AOP.CustomerAttribute;
using Edu.Common.Enum;
using Edu.Common.Enum.User;
using Edu.Model.CacheModel;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using Edu.Repository.User;
using System;
using System.Collections.Generic;
using System.Linq;
using VT.FW.DB;
namespace Edu.Module.User
{
///
/// 助教处理类
///
public class AssistModule
{
///
/// 助教仓储层对象
///
private readonly RB_AssistRepository assistRepository = new RB_AssistRepository();
///
/// 账号处理类
///
private readonly AccountModule accountModule = new AccountModule();
///
/// 部门仓储层对象
///
private readonly RB_DepartmentRepository departmentRepository = new RB_DepartmentRepository();
///
/// 岗位仓储层对象
///
private readonly RB_PostRepository postRepository = new RB_PostRepository();
///
/// 获取助教列表
///
///
///
public List GetAssistListModule(RB_Assist_ViewModel query)
{
return assistRepository.GetAssistListRepository(query);
}
///
/// 获取助教分页列表
///
///
///
///
///
///
public List GetAssistPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Assist_ViewModel query)
{
var list= assistRepository.GetAssistPageListRepository(pageIndex, pageSize, out rowsCount, query);
if (list != null && list.Count > 0)
{
string postIds = string.Join(",", list.Where(qitem => qitem.Post_Id > 0).Select(qitem => qitem.Post_Id));
string deptIds = string.Join(",", list.Where(qitem => qitem.Dept_Id > 0).Select(qitem => qitem.Dept_Id));
List postList = new List();
List deptList = new List();
if (!string.IsNullOrEmpty(postIds))
{
postList = postRepository.GetPostListRepository(new RB_Post_ViewModel() { QPostIds = postIds });
}
if (!string.IsNullOrEmpty(deptIds))
{
deptList = departmentRepository.GetDepartmentListRepository(new RB_Department_ViewModel() { QDeptIds = deptIds });
}
foreach (var item in list)
{
item.DeptName = deptList?.Where(qitem => qitem.DeptId == item.Dept_Id)?.FirstOrDefault()?.DeptName ?? "";
item.PostName = postList?.Where(qitem => qitem.PostId == item.Post_Id)?.FirstOrDefault()?.PostName ?? "";
}
}
return list;
}
///
/// 添加修改助教
///
///
///
public bool SetAssistModule(RB_Assist model)
{
bool flag;
if (model.AId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Assist.School_Id),model.School_Id },
{nameof(RB_Assist.Teacher_Id),model.Teacher_Id },
{nameof(RB_Assist.AssistName),model.AssistName.Trim() },
{nameof(RB_Assist.AssistTel),model.AssistTel },
{nameof(RB_Assist.AssistIcon),model.AssistIcon },
{nameof(RB_Assist.AssistIntro),model.AssistIntro },
{nameof(RB_Assist.UpdateBy),model.UpdateBy },
{nameof(RB_Assist.UpdateTime),model.UpdateTime },
{nameof(RB_Teacher_ViewModel.Dept_Id),model.Dept_Id },
{nameof(RB_Teacher_ViewModel.Post_Id),model.Post_Id },
};
flag = assistRepository.Update(fileds, new WhereHelper(nameof(RB_Assist.AId), model.AId));
}
else
{
var newId = assistRepository.Insert(model);
model.AId = newId;
flag = newId > 0;
}
return flag;
}
///
/// 根据编号获取助教实体
///
///
///
public RB_Assist_ViewModel GetAssistModule(int AId)
{
return assistRepository.GetEntity(AId);
}
///
/// 根据编号移除助教
///
///
///
[TransactionCallHandler]
public virtual bool RemoveAssistModule(int AId)
{
bool flag = false;
var model = GetAssistModule(AId);
if (model != null && model.AId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Assist.Status),(int)DateStateEnum.Delete },
};
flag = assistRepository.Update(fileds, new WhereHelper(nameof(RB_Assist.AId), AId));
var accountList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel()
{
AccountId=model.AId,
Account = model.AssistTel,
AccountType = AccountTypeEnum.Assist
});
if (accountList != null && accountList.Count > 0)
{
flag = accountModule.SetAccountStatusModule(new RB_Account_ViewModel()
{
AccountType = AccountTypeEnum.Assist,
AccountId = model.AId,
UpdateTime = DateTime.Now,
Status = DateStateEnum.Delete
});
}
}
return flag;
}
///
/// 助教重新申请
///
///
///
public bool ReApplyAssistModule(object AId)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Assist.AuditStatus),(int)AccountStatusEnum.Normal },
};
bool flag = assistRepository.Update(fileds, new WhereHelper(nameof(RB_Assist.AId), AId));
return flag;
}
///
/// 讲师审核
///
/// 助教编号
/// 审核状态
/// 审核备注
/// 用户信息
///
[TransactionCallHandler]
public virtual bool AuditAssistModule(int AId, int AuditStatus, string AuditRemark, UserInfo user)
{
bool flag = false;
var model = GetAssistModule(AId);
if (model != null && model.AId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Assist_ViewModel.AuditStatus),AuditStatus },
{nameof(RB_Assist_ViewModel.Remark),AuditRemark },
};
flag = assistRepository.Update(fileds, new WhereHelper(nameof(RB_Assist_ViewModel.AId), AId));
AccountStatusEnum statusEnum = (AccountStatusEnum)AuditStatus;
if (statusEnum == AccountStatusEnum.Pass && flag)
{
var accountList = accountModule.GetAccountListExtModule(new RB_Account_ViewModel()
{
Account = model.AssistTel,
AccountType = AccountTypeEnum.Assist
});
if (accountList == null || (accountList != null && accountList.Count == 0))
{
flag = accountModule.SetAccountModule(new RB_Account_ViewModel()
{
Account = model.AssistTel,
Password = Common.DES.Encrypt(Common.Config.DefaultPwd),
AccountType = AccountTypeEnum.Assist,
AccountId = model.AId,
CreateBy = user.Id,
UpdateBy = user.Id,
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
Group_Id = model.Group_Id,
School_Id = model.School_Id,
});
}
}
}
return flag;
}
}
}