using Edu.Common.Enum.User;
using Edu.Model.Entity.User;
using Edu.Model.ViewModel.User;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Edu.Repository.User
{
///
/// 工作流审核抄送扩展表
///
public partial class Rb_Workflow_CopyToPeopleRepository : BaseRepository
{
///
/// 抄送我的审批(通用)
///
/// 搜索关键字
/// 员工id
/// app获取审核状态
/// 抄送我的阅读状态 0全部,1未读
/// 申请筛选类型
///
///
/// 总条数
///
public List CopyToMyAudit(string searchKey, int empId, AppAuditStatusEnum appAuditStatus, int readeType, int applyType, int pageIndex, int pageSize, out long rowCount)
{
string sql = $@"SELECT t.WorkFlowId,t.ReadStauts,t.TemplateType from (
(SELECT a.*,'请假' as TemplateName,e.EmName,ask.CreateTime as AuditCreateTime,ask.`Status` from rb_workflow_copytopeople a INNER JOIN rb_workflow_askforleave ask
ON a.WorkFlowId = ask.Id and a.TemplateType = 1 and a.EmployeeId = {empId}
INNER JOIN rb_employee e ON e.EmployeeId = ask.CreateBy)UNION
(SELECT a.*,'出差' as TemplateName,e.EmName,ask.CreateTime as AuditCreateTime,ask.`Status` from rb_workflow_copytopeople a INNER JOIN rb_workflow_evection ask
ON a.WorkFlowId = ask.Id and a.TemplateType = 2 and a.EmployeeId = {empId}
INNER JOIN rb_employee e ON e.EmployeeId = ask.CreateBy)UNION
(SELECT a.*,'外出' as TemplateName,e.EmName,ask.CreateTime as AuditCreateTime,ask.`Status` from rb_workflow_copytopeople a INNER JOIN rb_workflow_goout ask
ON a.WorkFlowId = ask.Id and a.TemplateType = 3 and a.EmployeeId = {empId}
INNER JOIN rb_employee e ON e.EmployeeId = ask.CreateBy)UNION
(SELECT a.*,'补卡' as TemplateName,e.EmName,ask.CreateTime as AuditCreateTime,ask.`Status` from rb_workflow_copytopeople a INNER JOIN rb_workflow_goout ask
ON a.WorkFlowId = ask.Id and a.TemplateType = 4 and a.EmployeeId = {empId}
INNER JOIN rb_employee e ON e.EmployeeId = ask.CreateBy)
) as t";
StringBuilder sb = new StringBuilder();
sb.Append($"where EmployeeId = {empId} and Stauts=2 ");
if (!string.IsNullOrWhiteSpace(searchKey))
{
sb.Append($" AND (TemplateName LIKE '%{searchKey}%' or EmName LIKE '%{searchKey}%')");
}
else
{
if (readeType == 1)
{
sb.Append($" AND ReadStauts=1");
}
if (applyType != 0)
{
sb.Append($" AND TemplateType={applyType}");
}
if (appAuditStatus == AppAuditStatusEnum.AuditComplete)
{
sb.Append($" AND (`Status`={(int)UserWFAuditStatus.Through} Or `Status`={(int)UserWFAuditStatus.NotThrough})");
}
else if (appAuditStatus == AppAuditStatusEnum.InComplete)
{
sb.Append($" AND `Status`={(int)UserWFAuditStatus.InReview}");
}
else if (appAuditStatus == AppAuditStatusEnum.ToWithdraw)
{
sb.Append($" AND `Status`={(int)UserWFAuditStatus.ToWithdraw}");
}
}
sb.Append($" ORDER BY AuditCreateTime DESC");
return GetPage(pageIndex, pageSize, out rowCount, $"{sql} {sb.ToString()}").ToList();
}
///
/// 获取申请单下所有的抄送人信息
///
///
///
///
public List GetCopyToPeopleList(int WorkFlowId, int TemplateType)
{
string where = $@" where 1=1 and c.{nameof(Rb_Workflow_CopyToPeople.WorkFlowId)}={WorkFlowId} and c.{nameof(Rb_Workflow_CopyToPeople.TemplateType)}={TemplateType}";
return Get($@" select c.*,e.EmName,e.EmPhoto,e.EmAccount,e.EmLoginMobile from Rb_Workflow_CopyToPeople c left join rb_employee e on c.EmployeeId=e.EmployeeId {where}").ToList();
}
}
}