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_EvectionRepository : BaseRepository { /// /// 获取出差分页列表 /// /// /// /// /// /// public List GetEvectionPageList(int pageIndex, int pageSize, Rb_Workflow_Evection_Extend dmodel, out long count) { string where = $@" where 1=1 and t.{nameof(Rb_Workflow_Evection_Extend.RB_GroupId)}={dmodel.RB_GroupId}"; if (dmodel.RB_BranchId.HasValue && dmodel.RB_BranchId > -1) { where += $@" and t.{nameof(Rb_Workflow_Evection_Extend.RB_BranchId) }={dmodel.RB_BranchId}"; } if (dmodel.CreateBy.HasValue && dmodel.CreateBy > 0) { where += $@" and t.{nameof(Rb_Workflow_Evection_Extend.CreateBy)}={dmodel.CreateBy}"; } if (dmodel.Status.HasValue && (int)dmodel.Status > 0) { where += $@" and t.{nameof(Rb_Workflow_Evection_Extend.Status)}={(int)dmodel.Status}"; } if (dmodel.ToAuditId.HasValue && dmodel.ToAuditId > 0) { where += $@" and CONCAT(',',t.ToAuditIdStr,',') like '%,{dmodel.ToAuditId},%'"; } if (dmodel.AuditedId.HasValue && dmodel.AuditedId > 0) { where += $@" and CONCAT(',',t.AuditedIdStr,',') like '%,{dmodel.AuditedId},%'"; } string sql = $@"SELECT * FROM(select e.EmName, case when ask.`Status`=1 then (select group_concat(EmName) from rb_employee where instr(concat(',',(select case when ToAuditId='' then '0' else ToAuditId END from rb_workflow_auditrelevance audr where audr.WorkFlowId=ask.Id and audr.TemplateType={(int)WFTTemplateTypeEnum.Evection} and audr.Stauts=1 ORDER BY audr.Sort ASC limit 0,1),','),concat(',',EmployeeId,','))) ELSE '' END as ToAuditName, case when ask.`Status`=1 then (select ToAuditId from rb_workflow_auditrelevance audr where audr.WorkFlowId=ask.Id and audr.TemplateType={(int)WFTTemplateTypeEnum.Evection} and audr.Stauts=1 ORDER BY audr.Sort ASC limit 0,1) ELSE '' END as ToAuditIdStr, (select group_concat(AuditedId) from rb_workflow_auditrelevance audr where audr.WorkFlowId=ask.Id and audr.TemplateType={(int)WFTTemplateTypeEnum.Evection} and audr.AuditedId!='' ORDER BY audr.Sort ASC) as AuditedIdStr ,ask.* from rb_workflow_evection ask left JOIN rb_employee e on ask.CreateBy=e.EmployeeId )t {where} ORDER BY t.CreateTime DESC"; var pageList = GetPage(pageIndex, pageSize, out count, sql).ToList(); return pageList; } /// /// 根据id 获取数据详情 /// /// /// public Rb_Workflow_Evection_Extend GetModel(int Id) { string where = $@" where 1=1 and ask.Id ={Id}"; return Get($@"select ask.*,e.EmName,e.EmAccount,e.EmLoginMobile,e.EmPhoto from Rb_Workflow_Evection ask left join rb_employee e on ask.CreateBy=e.EmployeeId {where}").FirstOrDefault(); } /// /// 根据id 获取出差及模板详细信息 /// /// /// public Rb_Workflow_Evection_Extend GetEntityDetial(int id) { return Get($@"SELECT we.*,e.EmName,e.EmPhoto,t.TemplateType from rb_workflow_evection we LEFT JOIN rb_employee e on we.CreateBy = e.EmployeeId LEFT JOIN rb_workflow_template t on t.Id = we.TemplateId where we.Id = {id}").FirstOrDefault(); } /// /// 验证改时间段是否有重复数据 /// /// 员工id /// 开始时间 /// 结束时间 /// true 有重复数据,fasle没有重复数据 public bool ValverifyTime(int empId, string startTime, string endTime) { return Get($"SELECT e.Id from rb_workflow_evection e INNER JOIN rb_workflow_travel t on e.Id = t.EvectionId where e.CreateBy = {empId} and (('{startTime}'>=t.StartTime and '{startTime}'<=t.EndTime) or ('{endTime}'>=t.StartTime and '{endTime}'<=t.EndTime)) and (((e.`Status` = 1 or e.`Status` = 5) AND e.IsCancel = 1) or ((e.`Status` = 1 or e.`Status` = 4 ) AND e.IsCancel = 2))").Count() > 0 ? true : false; } /// /// 获取当月出差所有的数据 /// /// 用户编号 /// 月份 /// public List GetSignInInfoForEvection(int uid,string month) { string Month = Convert.ToDateTime(month).ToString("yyyy-MM"); return Get($@"select t.* from rb_workflow_evection e left join rb_workflow_travel t on e.Id=t.EvectionId where e.Status in (1,5) and e.IsCancel=1 and e.CreateBy={uid} and (DATE_FORMAT(t.StartTime,'%Y-%m')='{Month}' or DATE_FORMAT(t.EndTime,'%Y-%m')='{Month}')").ToList(); } } }