public JsonResult Edit(string id, DepartmentTaskEntity model)
        {
            var user    = OperatorProvider.Provider.Current();
            var success = true;
            var message = "保存成功!";

            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    model.TaskId       = Guid.NewGuid().ToString();
                    model.Status       = "未开始";
                    model.CreateUserId = model.ModifyUserId = user.UserId;
                    model.CreateUser   = model.ModifyUser = user.UserName;
                    model.CreateTime   = model.ModifyTime = DateTime.Now;
                    model.CreateDeptId = user.DeptId;
                    model.CreateDept   = user.DeptName;
                }
                else
                {
                    model.TaskId       = id;
                    model.ModifyTime   = DateTime.Now;
                    model.ModifyUserId = user.UserId;
                    model.ModifyUser   = user.UserName;
                }

                if (model.SubTasks == null)
                {
                    model.SubTasks = new List <DepartmentTaskEntity>();
                }
                foreach (var item in model.SubTasks)
                {
                    item.CreateUserId = item.ModifyUserId = user.UserId;
                    item.CreateUser   = item.ModifyUser = user.UserName;
                    item.CreateTime   = item.ModifyTime = DateTime.Now;
                    item.CreateDeptId = user.DeptId;
                    item.CreateDept   = user.DeptName;
                    item.ParentTaskId = model.TaskId;
                    if (item.Status != "已完成" && item.Status != "已取消")
                    {
                        item.Status = "未开始";
                    }
                }

                var bll = new DepartmentTaskBLL();
                bll.Edit(model);

                WorkmeetingBLL meetBll      = new WorkmeetingBLL();
                var            deptbll      = new DepartmentBLL();
                var            trainingtype = Config.GetValue("TrainingType");
                foreach (var item in model.SubTasks)
                {
                    if (item.IsPublish == true)
                    {
                        continue;
                    }

                    var dept = deptbll.GetEntity(item.DutyDepartmentId);
                    if (dept == null)
                    {
                        continue;
                    }
                    if (dept.Nature != "班组")
                    {
                        continue;
                    }

                    var job = new MeetingJobEntity();
                    job.JobId                 = Guid.NewGuid().ToString();
                    job.CreateDate            = DateTime.Now;
                    job.CreateUserId          = user.UserId;
                    job.GroupId               = dept.DepartmentId;
                    job.Relation              = new MeetingAndJobEntity();
                    job.Relation.MeetingJobId = Guid.NewGuid().ToString();
                    job.Relation.JobId        = job.JobId;
                    job.IsFinished            = job.Relation.IsFinished = "undo";
                    job.Relation.JobUserId    = item.DutyUserId;
                    job.Relation.JobUser      = item.DutyUser;
                    job.Job               = item.Content;
                    job.TemplateId        = item.TaskId;
                    job.StartTime         = DateTime.Parse(item.StartDate.Value.ToString("yyyy/MM/dd") + " 08:30");
                    job.EndTime           = DateTime.Parse(item.EndDate.Value.ToString("yyyy/MM/dd") + " 17:30");
                    job.RiskLevel         = "低风险";
                    job.TaskType          = "管理任务";
                    job.Relation.JobUsers = new List <JobUserEntity>()
                    {
                        new JobUserEntity()
                        {
                            UserId = item.DutyUserId, UserName = item.DutyUser, JobUserId = Guid.NewGuid().ToString(), JobType = "ischecker", CreateDate = DateTime.Now, MeetingJobId = job.Relation.MeetingJobId
                        }
                    };
                    if (job.DangerousList == null)
                    {
                        job.DangerousList = new List <JobDangerousEntity>();
                    }

                    job = meetBll.PostJob(job);
                    if (string.IsNullOrEmpty(job.Relation.StartMeetingId))
                    {
                        message = "任务已分配至班前会,等待下发。";
                    }
                    else
                    {
                        var meeting = meetBll.GetEntity(job.Relation.StartMeetingId);
                        if (meeting.IsOver)
                        {
                            message = "任务已下发。";
                        }
                        else
                        {
                            message = "任务已分配至班前会,等待下发。";
                        }
                    }

                    if (!string.IsNullOrEmpty(job.Relation.StartMeetingId))
                    {
                        var meeting = meetBll.GetDetail(job.Relation.StartMeetingId);
                        if (meeting != null && meeting.IsOver && job.NeedTrain)
                        {
                            if (trainingtype == "人身风险预控")
                            {
                                var training = new HumanDangerTrainingEntity()
                                {
                                    TrainingId = Guid.NewGuid().ToString(), TrainingTask = job.Job, CreateTime = DateTime.Now, CreateUserId = user.UserId, MeetingJobId = job.Relation.MeetingJobId, DeptId = job.GroupId, TrainingPlace = job.JobAddr, No = job.TicketCode
                                };
                                if (!string.IsNullOrEmpty(job.TemplateId))
                                {
                                    training.HumanDangerId = job.TemplateId;
                                }
                                training.TrainingUsers = job.Relation.JobUsers.Select(x => new TrainingUserEntity()
                                {
                                    TrainingUserId = Guid.NewGuid().ToString(), UserId = x.UserId, UserName = x.UserName, TrainingRole = x.JobType == "ischecker" ? 1 : 0
                                }).ToList();
                                new HumanDangerTrainingBLL().Add(training);
                            }
                            else
                            {
                                var dangerbll  = new DangerBLL();
                                var messagebll = new MessageBLL();

                                var danger = dangerbll.Save(job);
                                if (danger != null)
                                {
                                    messagebll.SendMessage("危险预知训练", danger.Id);
                                }
                            }
                        }
                    }
                    var msgbll = new MessageBLL();
                    msgbll.SendMessage("工作提示", job.Relation.MeetingJobId);

                    item.IsPublish = true;
                }

                bll.Publish(model.SubTasks.Where(x => x.IsPublish == true).ToList());
            }
            catch (Exception ex)
            {
                success = false;
                message = ex.Message;
            }
            return(Json(new AjaxResult()
            {
                type = success ? ResultType.success : ResultType.error, message = message
            }));
        }