using OASystem.Domain.Common;
using OASystem.Domain.Dtos.Groups;
using OASystem.Domain.Entities.Groups;
using OASystem.Infrastructure.Repositories.Groups;
namespace OASystem.API.OAMethodLib
{
///
/// 团组流程管控
///
public static class GroupStepForDelegation
{
private readonly static GrpScheduleRepository _grpScheduleRep = AutofacIocManager.Instance.GetService();
///
/// 创建流程管控
///
/// 团组Id
public static async void CreateWorkStep(int DiId)
{
//var _grpScheduleRep = AutofacIocManager.Instance.GetService();
//判断是否已存在团组的流程管控
Grp_ScheduleInfo check = _grpScheduleRep.Query(s => s.DiId == DiId).First();
if (check == null)
{
_grpScheduleRep.BeginTran();
GroupsConfig _groupConfig = AutofacIocManager.Instance.GetService();
DateTime dftBeginDt = DateTime.Now.AddDays(_groupConfig.ExBeginDays);//默认预计开始时间
DateTime dftEndDt = DateTime.Now.AddDays(_groupConfig.ExEndDays);//默认预计结束时间
#region 主流程
Grp_ScheduleInfo _primary = new Grp_ScheduleInfo();
_primary.CreateUserId = _groupConfig.AutoCreate;
_primary.DiId = DiId;
_primary.Exception = 0;
_primary.ExpectBeginDt = dftBeginDt;
_primary.ExpectEndDt = dftEndDt;
_primary.Leader = _groupConfig.Leader;
_primary.PrimaryStep = GrpSchedulePrimaryStepEnum.Wait;
_primary.Remark = "请设置各流程负责人、预计开始/结束时间";
int _primaryId = await _grpScheduleRep.AddAsyncReturnId(_primary);
if (_primaryId > 0)
{
#region 子流程
List entityList = new List();
#region 模板
Grp_ScheduleDetailInfo _model = new Grp_ScheduleDetailInfo();
_model.CreateUserId = _groupConfig.AutoCreate;
_model.Duty = _groupConfig.DefaultUser;
_model.Exception = 0;
_model.ExpectBeginDt = dftBeginDt;
_model.ExpectEndDt = dftEndDt;
_model.Remark = "未设置负责人";
_model.ScheduleId = _primaryId;
_model.StepStatus = 0;
#endregion
#region 经费预算
Grp_ScheduleDetailInfo grp_budget202 = _model.DeepClone();
grp_budget202.JobContent = GrpSchedulePrimaryStepEnum.BudgetChild02.GetEnumDescription();
grp_budget202.ParentStep = (int)GrpSchedulePrimaryStepEnum.Budget;
grp_budget202.Step = (int)GrpSchedulePrimaryStepEnum.BudgetChild02;
grp_budget202.SLevel = 2;
entityList.Add(grp_budget202);
#endregion
#region 市场部人员报价对接/反馈
//上传明细单
Grp_ScheduleDetailInfo grp_feedback302 = _model.DeepClone();
grp_feedback302.JobContent = GrpSchedulePrimaryStepEnum.FeedbackChild02.GetEnumDescription();
grp_feedback302.ParentStep = (int)GrpSchedulePrimaryStepEnum.Feedback;
grp_feedback302.Step = (int)GrpSchedulePrimaryStepEnum.FeedbackChild02;
grp_feedback302.SLevel = 2;
entityList.Add(grp_feedback302);
//录入最终总经费预算
Grp_ScheduleDetailInfo grp_feedback303 = _model.DeepClone();
grp_feedback303.JobContent = GrpSchedulePrimaryStepEnum.FeedbackChild03.GetEnumDescription();
grp_feedback303.ParentStep = (int)GrpSchedulePrimaryStepEnum.Feedback;
grp_feedback303.Step = (int)GrpSchedulePrimaryStepEnum.FeedbackChild03;
grp_feedback303.SLevel = 2;
entityList.Add(grp_feedback303);
//完成报价对接/反馈
Grp_ScheduleDetailInfo grp_feedback304 = _model.DeepClone();
grp_feedback304.JobContent = GrpSchedulePrimaryStepEnum.FeedbackChild04.GetEnumDescription();
grp_feedback304.ParentStep = (int)GrpSchedulePrimaryStepEnum.Feedback;
grp_feedback304.Step = (int)GrpSchedulePrimaryStepEnum.FeedbackChild04;
grp_feedback304.SLevel = 2;
entityList.Add(grp_feedback304);
#endregion
#region (目前为空)报批流程
#endregion
#region 护照/签证
//收集资料
Grp_ScheduleDetailInfo grp_visa502 = _model.DeepClone();
grp_visa502.JobContent = GrpSchedulePrimaryStepEnum.VisaChild02.GetEnumDescription();
grp_visa502.ParentStep = (int)GrpSchedulePrimaryStepEnum.Visa;
grp_visa502.Step = (int)GrpSchedulePrimaryStepEnum.VisaChild02;
grp_visa502.SLevel = 2;
entityList.Add(grp_visa502);
//取护照资料
Grp_ScheduleDetailInfo grp_visa503 = _model.DeepClone();
grp_visa503.JobContent = GrpSchedulePrimaryStepEnum.VisaChild03.GetEnumDescription();
grp_visa503.ParentStep = (int)GrpSchedulePrimaryStepEnum.Visa;
grp_visa503.Step = (int)GrpSchedulePrimaryStepEnum.VisaChild03;
grp_visa503.SLevel = 2;
entityList.Add(grp_visa503);
//填资料
Grp_ScheduleDetailInfo grp_visa504 = _model.DeepClone();
grp_visa504.JobContent = GrpSchedulePrimaryStepEnum.VisaChild04.GetEnumDescription();
grp_visa504.ParentStep = (int)GrpSchedulePrimaryStepEnum.Visa;
grp_visa504.Step = (int)GrpSchedulePrimaryStepEnum.VisaChild04;
grp_visa504.SLevel = 2;
entityList.Add(grp_visa504);
//送签
Grp_ScheduleDetailInfo grp_visa505 = _model.DeepClone();
grp_visa505.JobContent = GrpSchedulePrimaryStepEnum.VisaChild05.GetEnumDescription();
grp_visa505.ParentStep = (int)GrpSchedulePrimaryStepEnum.Visa;
grp_visa505.Step = (int)GrpSchedulePrimaryStepEnum.VisaChild05;
grp_visa505.SLevel = 2;
entityList.Add(grp_visa505);
//出签+取护照
Grp_ScheduleDetailInfo grp_visa506 = _model.DeepClone();
grp_visa506.JobContent = GrpSchedulePrimaryStepEnum.VisaChild06.GetEnumDescription();
grp_visa506.ParentStep = (int)GrpSchedulePrimaryStepEnum.Visa;
grp_visa506.Step = (int)GrpSchedulePrimaryStepEnum.VisaChild06;
grp_visa506.SLevel = 2;
entityList.Add(grp_visa506);
//归还护照
Grp_ScheduleDetailInfo grp_visa507 = _model.DeepClone();
grp_visa507.JobContent = GrpSchedulePrimaryStepEnum.VisaChild07.GetEnumDescription();
grp_visa507.ParentStep = (int)GrpSchedulePrimaryStepEnum.Visa;
grp_visa507.Step = (int)GrpSchedulePrimaryStepEnum.VisaChild07;
grp_visa507.SLevel = 2;
entityList.Add(grp_visa507);
//签证费用录入
Grp_ScheduleDetailInfo grp_visa508 = _model.DeepClone();
grp_visa508.JobContent = GrpSchedulePrimaryStepEnum.VisaChild08.GetEnumDescription();
grp_visa508.ParentStep = (int)GrpSchedulePrimaryStepEnum.Visa;
grp_visa508.Step = (int)GrpSchedulePrimaryStepEnum.VisaChild08;
grp_visa508.SLevel = 2;
entityList.Add(grp_visa508);
#endregion
#region 业务操作
//机票
Grp_ScheduleDetailInfo grp_busJP601 = _model.DeepClone();
grp_busJP601.JobContent = GrpSchedulePrimaryStepEnum.BusinessJP.GetEnumDescription();
grp_busJP601.ParentStep = (int)GrpSchedulePrimaryStepEnum.Business;
grp_busJP601.Step = (int)GrpSchedulePrimaryStepEnum.BusinessJP;
grp_busJP601.SLevel = 2;
entityList.Add(grp_busJP601);
//机票-询价并导入黑屏代码
Grp_ScheduleDetailInfo grp_busJP6012 = _model.DeepClone();
grp_busJP6012.JobContent = GrpSchedulePrimaryStepEnum.BusinessJPChild02.GetEnumDescription();
grp_busJP6012.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessJP;
grp_busJP6012.Step = (int)GrpSchedulePrimaryStepEnum.BusinessJPChild02;
grp_busJP6012.SLevel = 3;
entityList.Add(grp_busJP6012);
//机票-机票已占位
Grp_ScheduleDetailInfo grp_busJP6013 = _model.DeepClone();
grp_busJP6013.JobContent = GrpSchedulePrimaryStepEnum.BusinessJPChild03.GetEnumDescription();
grp_busJP6013.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessJP;
grp_busJP6013.Step = (int)GrpSchedulePrimaryStepEnum.BusinessJPChild03;
grp_busJP6013.SLevel = 3;
entityList.Add(grp_busJP6013);
//机票-已出票
Grp_ScheduleDetailInfo grp_busJP6014 = _model.DeepClone();
grp_busJP6014.JobContent = GrpSchedulePrimaryStepEnum.BusinessJPChild04.GetEnumDescription();
grp_busJP6014.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessJP;
grp_busJP6014.Step = (int)GrpSchedulePrimaryStepEnum.BusinessJPChild04;
grp_busJP6014.SLevel = 3;
entityList.Add(grp_busJP6014);
//机票-机票费用录入
Grp_ScheduleDetailInfo grp_busJP6015 = _model.DeepClone();
grp_busJP6015.JobContent = GrpSchedulePrimaryStepEnum.BusinessJPChild05.GetEnumDescription();
grp_busJP6015.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessJP;
grp_busJP6015.Step = (int)GrpSchedulePrimaryStepEnum.BusinessJPChild05;
grp_busJP6015.SLevel = 3;
entityList.Add(grp_busJP6015);
//酒店
Grp_ScheduleDetailInfo grp_busJD602 = _model.DeepClone();
grp_busJD602.JobContent = GrpSchedulePrimaryStepEnum.BusinessJD.GetEnumDescription();
grp_busJD602.ParentStep = (int)GrpSchedulePrimaryStepEnum.Business;
grp_busJD602.Step = (int)GrpSchedulePrimaryStepEnum.BusinessJD;
grp_busJD602.SLevel = 2;
entityList.Add(grp_busJD602);
//酒店-酒店费用录入
Grp_ScheduleDetailInfo grp_busJD6022 = _model.DeepClone();
grp_busJD6022.JobContent = GrpSchedulePrimaryStepEnum.BusinessJDChild02.GetEnumDescription();
grp_busJD6022.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessJD;
grp_busJD6022.Step = (int)GrpSchedulePrimaryStepEnum.BusinessJDChild02;
grp_busJD6022.SLevel = 3;
entityList.Add(grp_busJD6022);
//OP
Grp_ScheduleDetailInfo grp_busOP603 = _model.DeepClone();
grp_busOP603.JobContent = GrpSchedulePrimaryStepEnum.BusinessOP.GetEnumDescription();
grp_busOP603.ParentStep = (int)GrpSchedulePrimaryStepEnum.Business;
grp_busOP603.Step = (int)GrpSchedulePrimaryStepEnum.BusinessOP;
grp_busOP603.SLevel = 2;
entityList.Add(grp_busOP603);
//OP-OP询价
Grp_ScheduleDetailInfo grp_busOP6032 = _model.DeepClone();
grp_busOP6032.JobContent = GrpSchedulePrimaryStepEnum.BusinessOPChild02.GetEnumDescription();
grp_busOP6032.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessOP;
grp_busOP6032.Step = (int)GrpSchedulePrimaryStepEnum.BusinessOPChild02;
grp_busOP6032.SLevel = 3;
entityList.Add(grp_busOP6032);
//OP-OP费用录入
Grp_ScheduleDetailInfo grp_busOP6033 = _model.DeepClone();
grp_busOP6033.JobContent = GrpSchedulePrimaryStepEnum.BusinessOPChild03.GetEnumDescription();
grp_busOP6033.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessOP;
grp_busOP6033.Step = (int)GrpSchedulePrimaryStepEnum.BusinessOPChild03;
grp_busOP6033.SLevel = 3;
entityList.Add(grp_busOP6032);
//商邀
Grp_ScheduleDetailInfo grp_busSY604 = _model.DeepClone();
grp_busSY604.JobContent = GrpSchedulePrimaryStepEnum.BusinessSY.GetEnumDescription();
grp_busSY604.ParentStep = (int)GrpSchedulePrimaryStepEnum.Business;
grp_busSY604.Step = (int)GrpSchedulePrimaryStepEnum.BusinessSY;
grp_busSY604.SLevel = 2;
entityList.Add(grp_busSY604);
//商邀-商邀报批
Grp_ScheduleDetailInfo grp_busSY6042 = _model.DeepClone();
grp_busSY6042.JobContent = GrpSchedulePrimaryStepEnum.BusinessSYChild02.GetEnumDescription();
grp_busSY6042.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessSY;
grp_busSY6042.Step = (int)GrpSchedulePrimaryStepEnum.BusinessSYChild02;
grp_busSY6042.SLevel = 3;
entityList.Add(grp_busSY6042);
//商邀-商邀费用录入
Grp_ScheduleDetailInfo grp_busSY6043 = _model.DeepClone();
grp_busSY6043.JobContent = GrpSchedulePrimaryStepEnum.BusinessSYChild03.GetEnumDescription();
grp_busSY6043.ParentStep = (int)GrpSchedulePrimaryStepEnum.BusinessSY;
grp_busSY6043.Step = (int)GrpSchedulePrimaryStepEnum.BusinessSYChild03;
grp_busSY6043.SLevel = 3;
entityList.Add(grp_busSY6043);
#endregion
#region 费用审批
//机票费用审批
Grp_ScheduleDetailInfo grp_cost702 = _model.DeepClone();
grp_cost702.JobContent = GrpSchedulePrimaryStepEnum.CostAuditChild02.GetEnumDescription();
grp_cost702.ParentStep = (int)GrpSchedulePrimaryStepEnum.CostAudit;
grp_cost702.Step = (int)GrpSchedulePrimaryStepEnum.CostAuditChild02;
grp_cost702.Duty = _groupConfig.Boss;
grp_cost702.SLevel = 2;
entityList.Add(grp_cost702);
//酒店费用审批
Grp_ScheduleDetailInfo grp_cost703 = _model.DeepClone();
grp_cost703.JobContent = GrpSchedulePrimaryStepEnum.CostAuditChild03.GetEnumDescription();
grp_cost703.ParentStep = (int)GrpSchedulePrimaryStepEnum.CostAudit;
grp_cost703.Step = (int)GrpSchedulePrimaryStepEnum.CostAuditChild03;
grp_cost703.Duty = _groupConfig.Boss;
grp_cost703.SLevel = 2;
entityList.Add(grp_cost703);
//OP费用审批
Grp_ScheduleDetailInfo grp_cost704 = _model.DeepClone();
grp_cost704.JobContent = GrpSchedulePrimaryStepEnum.CostAuditChild04.GetEnumDescription();
grp_cost704.ParentStep = (int)GrpSchedulePrimaryStepEnum.CostAudit;
grp_cost704.Step = (int)GrpSchedulePrimaryStepEnum.CostAuditChild04;
grp_cost704.Duty = _groupConfig.Boss;
grp_cost704.SLevel = 2;
entityList.Add(grp_cost704);
//OP费用审批
Grp_ScheduleDetailInfo grp_cost705 = _model.DeepClone();
grp_cost705.JobContent = GrpSchedulePrimaryStepEnum.CostAuditChild05.GetEnumDescription();
grp_cost705.ParentStep = (int)GrpSchedulePrimaryStepEnum.CostAudit;
grp_cost705.Step = (int)GrpSchedulePrimaryStepEnum.CostAuditChild05;
grp_cost705.Duty = _groupConfig.Boss;
grp_cost705.SLevel = 2;
entityList.Add(grp_cost705);
//增减款项审批
Grp_ScheduleDetailInfo grp_cost706 = _model.DeepClone();
grp_cost706.JobContent = GrpSchedulePrimaryStepEnum.CostAuditChild06.GetEnumDescription();
grp_cost706.ParentStep = (int)GrpSchedulePrimaryStepEnum.CostAudit;
grp_cost706.Step = (int)GrpSchedulePrimaryStepEnum.CostAuditChild06;
grp_cost706.Duty = _groupConfig.Boss;
grp_cost706.SLevel = 2;
entityList.Add(grp_cost706);
#endregion
#region 付款给供应商
//OP费用付款
Grp_ScheduleDetailInfo grp_pay802 = _model.DeepClone();
grp_pay802.JobContent = GrpSchedulePrimaryStepEnum.PayChild02.GetEnumDescription();
grp_pay802.ParentStep = (int)GrpSchedulePrimaryStepEnum.Pay;
grp_pay802.Step = (int)GrpSchedulePrimaryStepEnum.PayChild02;
grp_pay802.SLevel = 2;
entityList.Add(grp_pay802);
//商邀费用付款
Grp_ScheduleDetailInfo grp_pay803 = _model.DeepClone();
grp_pay803.JobContent = GrpSchedulePrimaryStepEnum.PayChild03.GetEnumDescription();
grp_pay803.ParentStep = (int)GrpSchedulePrimaryStepEnum.Pay;
grp_pay803.Step = (int)GrpSchedulePrimaryStepEnum.PayChild03;
grp_pay803.SLevel = 2;
entityList.Add(grp_pay803);
//增减款项付款
Grp_ScheduleDetailInfo grp_pay804 = _model.DeepClone();
grp_pay804.JobContent = GrpSchedulePrimaryStepEnum.PayChild04.GetEnumDescription();
grp_pay804.ParentStep = (int)GrpSchedulePrimaryStepEnum.Pay;
grp_pay804.Step = (int)GrpSchedulePrimaryStepEnum.PayChild04;
grp_pay804.SLevel = 2;
entityList.Add(grp_pay804);
#endregion
#region (目前为空)出行事项会议
#endregion
#region (目前为空)送机
#endregion
#region (目前为空)接机
#endregion
#region 收款
//收款完成
Grp_ScheduleDetailInfo grp_col01 = _model.DeepClone();
grp_col01.JobContent = GrpSchedulePrimaryStepEnum.CollectChild01.GetEnumDescription();
grp_col01.ParentStep = (int)GrpSchedulePrimaryStepEnum.Collect;
grp_col01.Step = (int)GrpSchedulePrimaryStepEnum.CollectChild01;
grp_col01.ExpectBeginDt = dftEndDt;
grp_col01.ExpectEndDt = dftEndDt.AddMonths(3);
grp_col01.SLevel = 2;
entityList.Add(grp_col01);
#endregion
#region (目前为空)团组完成
#endregion
//SqlSugar批量添加
_grpScheduleRep.bulkInsert(entityList);
#endregion
#region 流程管控成员
string sqlPerson = string.Format(@"Select u.Id As SysUserId,u.CnName As SysUserName,JobName as JobStr
From Sys_Users As u With(Nolock)
Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id
Inner Join Sys_JobPost as j With(Nolock) On u.JobPostId=j.Id
Where d.Id={0} And u.Id not in({1})", DepartmentCode.IC, _groupConfig.FilterUser);
List personList = await _grpScheduleRep.GetEntityList_SchedulePersonBySql(sqlPerson);
if (personList.Count > 0)
{
foreach (var item in personList)
{
item.CreateUserId = _groupConfig.DefaultUser;
item.ScheduleId = _primaryId;
}
_grpScheduleRep.bulkInsert(personList);
}
#endregion
}
else
{
_grpScheduleRep.RollbackTran();
}
#endregion
_grpScheduleRep.CommitTran();
}
}
public static async void ChangeStepForPrimary(int DiId, GrpSchedulePrimaryStepEnum primary, int isDel, int exception, string remark)
{
//var _grpScheduleRep = AutofacIocManager.Instance.GetService();
string sqlPrimary = string.Format(@" Select * From Grp_Schedule With(Nolock) Where IsDel=0 And DiId={0} ", DiId);
Grp_ScheduleInfo _grpPrimaryInfo = _grpScheduleRep.GetSingleInfoBySqlWithNolock(sqlPrimary);
if (_grpPrimaryInfo != null)
{
_grpPrimaryInfo.PrimaryStep = primary;
_grpPrimaryInfo.IsDel = isDel;
_grpPrimaryInfo.Exception = exception;
_grpPrimaryInfo.Remark += ";" + remark;
var result = await _grpScheduleRep._sqlSugar.Updateable()
.Where(s => s.Id == _grpPrimaryInfo.Id)
.UpdateColumns(s => new { s.PrimaryStep, s.IsDel, s.Exception, s.Remark })
.ExecuteCommandAsync();
}
}
#region 流程管控步骤推进
///
/// 刷新团组管控最新状态,或推进流程到下一节点
///
/// 团组流程Id
public static async void RefreshWorkStep(int scheduleId, bool auto = false)
{
//var _grpScheduleRep = AutofacIocManager.Instance.GetService();
string sqlPrimary = string.Format(@" Select * From Grp_Schedule With(Nolock) Where IsDel=0 And Id={0} ", scheduleId);
Grp_ScheduleInfo _grpPrimaryInfo = _grpScheduleRep.GetSingleInfoBySqlWithNolock(sqlPrimary);
if (_grpPrimaryInfo != null)
{
List _list = _grpScheduleRep._sqlSugar.Queryable()
.Where(s => s.ScheduleId == scheduleId && s.IsDel != 1 && s.ParentStep == (int)_grpPrimaryInfo.PrimaryStep && s.StepStatus != 2)
.ToList();
if (_list.Count > 0)
{
//未完成主流程节点下所有步骤任务
}
else
{
//可推进节点
if (auto)
{
int nextPrimaryStep = (int)_grpPrimaryInfo.PrimaryStep + 1;
var result = await _grpScheduleRep._sqlSugar.Updateable()
.Where(s => s.Id == _grpPrimaryInfo.Id)
.UpdateColumns(s => new { nextPrimaryStep })
.ExecuteCommandAsync();
}
}
//eg:CheckStep_Budget
//switch (_grpPrimaryInfo.PrimaryStep)
//{
// case GrpSchedulePrimaryStepEnum.Budget: CheckStep_Budget(scheduleId); break;
//}
}
}
///
/// 暂无需求,先保存,可扩展至查询验证主流程下每一个详细流程步骤对应的业务操作是否完成,需要其他业务提供验证方法
/// 查看流程-经费预算
///
///
/// true:已完成所有步骤,false:存在未完成的步骤(Grp_ScheduleDetail.StepStatus:0/1/2)
private static bool CheckStep_Budget(int scheduleId)
{
List _list = _grpScheduleRep._sqlSugar.Queryable()
.Where(s => s.ScheduleId == scheduleId && s.IsDel != 1 && s.ParentStep == (int)GrpSchedulePrimaryStepEnum.Budget)
.ToList();
foreach (var item in _list)
{
switch (item.Step)
{
case (int)GrpSchedulePrimaryStepEnum.BudgetChild01:
//验证方法
break;
case (int)GrpSchedulePrimaryStepEnum.BudgetChild02: break;
}
}
return false;
}
#endregion
}
}