public JsonResult Rollback(int versionid)
        {
            return(this.Visit(Core.EnumUserRole.Admin, () =>
            {
                try
                {
                    string currentVersion = "1.01";
                    var latestVersion = TaskHelper.GetLatestBusinessVersion();
                    if (latestVersion != null)
                    {
                        double version;
                        double.TryParse(latestVersion.businessversion, out version);
                        currentVersion = (version + 0.01).ToString("F2");
                    }

                    List <taskjson_model> taskjsonList = new List <taskjson_model>();
                    var versioninfo = TaskHelper.GetBusinessVersion(versionid);
                    if (versioninfo != null)
                    {
                        var taskList = GetTaskJsonList(versioninfo.taskjson);
                        foreach (var item in taskList)
                        {
                            var totask = TaskHelper.GetTask(item.id);
                            if (totask != null)
                            {
                                var totaskversion = TaskHelper.GetVersion(totask.id, totask.taskversion);
                                var fromtaskversion = TaskHelper.GetVersion(totask.id, item.v);
                                //停止原来的任务
                                bool result = TaskHelper.AddTaskCommand(new tb_command_model
                                {
                                    command = "",
                                    commandcreatetime = DateTime.Now,
                                    taskid = totask.id,
                                    nodeid = totask.nodeid,
                                    commandname = EnumTaskCommandName.StopTask.ToString(),
                                    commandstate = (int)EnumTaskCommandState.None
                                });
                                var model = new tb_version_model
                                {
                                    taskid = totask.id,
                                    version = totaskversion.version + 1,
                                    versioncreatetime = DateTime.Now,
                                    zipfile = fromtaskversion.zipfile,
                                    zipfilename = fromtaskversion.zipfilename
                                };
                                TaskHelper.AddVersion(model);
                                TaskHelper.AddTaskCommand(new tb_command_model
                                {
                                    command = "",
                                    commandcreatetime = DateTime.Now,
                                    taskid = totask.id,
                                    nodeid = totask.nodeid,
                                    commandname = EnumTaskCommandName.StartTask.ToString(),
                                    commandstate = (int)EnumTaskCommandState.None
                                });
                                totask.taskversion = model.version;
                                totask.taskupdatetime = DateTime.Now;
                                totask.businessversion = currentVersion;
                                TaskHelper.UpdateTask(totask);
                                taskjsonList.Add(new taskjson_model {
                                    id = totask.id, v = model.version, n = 1
                                });
                            }
                        }
                        using (DbConn PubConn = DbConfig.CreateConn(Config.TaskConnectString))
                        {
                            PubConn.Open();
                            tb_businessversion_dal dal = new tb_businessversion_dal();
                            var result = dal.Add(PubConn, new tb_businessversion_model
                            {
                                createtime = DateTime.Now,
                                businessversion = currentVersion,
                                description = "【回滚操作】" + versioninfo.description,
                                taskjson = JsonConvert.SerializeObject(taskjsonList)
                            });
                            if (!result)
                            {
                                return Json(new { code = -1, msg = "回滚版本发布失败" });
                            }
                        }
                    }
                    else
                    {
                        return Json(new { code = -1, msg = "版本不存在" });
                    }
                }
                catch (Exception ex)
                {
                    return Json(new { code = -1, msg = ex.Message });
                }
                return Json(new { code = 1, msg = "回滚成功" });
            }));
        }
        public JsonResult Sync(string ids, string description)
        {
            List <string> idList = ids.Split(',').ToList();

            return(this.Visit(Core.EnumUserRole.Admin, () =>
            {
                try
                {
                    string currentVersion = "1.0";
                    var latestVersion = TaskHelper.GetLatestBusinessVersion();
                    if (latestVersion != null)
                    {
                        double version;
                        double.TryParse(latestVersion.businessversion, out version);
                        currentVersion = (version + 0.1).ToString("F1");
                    }

                    List <taskjson_model> taskjsonList = new List <taskjson_model>();
                    List <tb_tasksyncmap_model> tasksynclist = TaskHelper.GetTaskSyncMapList();
                    foreach (var item in tasksynclist)
                    {
                        if (idList.Exists(id => id == item.id.ToString()))
                        {
                            //有些任务可能已经删除掉,就不再同步
                            var totask = TaskHelper.GetTask(item.totaskid);
                            if (totask != null)
                            {
                                var totaskversion = TaskHelper.GetVersion(totask.id, totask.taskversion);
                                var fromtask = TaskHelper.GetTask(item.fromtaskid);
                                var fromtaskversion = TaskHelper.GetVersion(fromtask.id, fromtask.taskversion);
                                //停止原来的任务
                                bool result = TaskHelper.AddTaskCommand(new tb_command_model
                                {
                                    command = "",
                                    commandcreatetime = DateTime.Now,
                                    taskid = totask.id,
                                    nodeid = totask.nodeid,
                                    commandname = EnumTaskCommandName.StopTask.ToString(),
                                    commandstate = (int)EnumTaskCommandState.None
                                });
                                //复制源任务到发布任务,并启动同步后的任务
                                var model = new tb_version_model
                                {
                                    taskid = totask.id,
                                    version = totaskversion.version + 1,
                                    versioncreatetime = DateTime.Now,
                                    zipfile = fromtaskversion.zipfile,
                                    zipfilename = fromtaskversion.zipfilename,
                                    commit_id = string.Empty
                                };
                                TaskHelper.AddVersion(model);
                                TaskHelper.AddTaskCommand(new tb_command_model
                                {
                                    command = "",
                                    commandcreatetime = DateTime.Now,
                                    taskid = totask.id,
                                    nodeid = totask.nodeid,
                                    commandname = EnumTaskCommandName.StartTask.ToString(),
                                    commandstate = (int)EnumTaskCommandState.None
                                });
                                totask.taskversion = model.version;
                                totask.taskupdatetime = DateTime.Now;
                                totask.businessversion = currentVersion;
                                TaskHelper.UpdateTask(totask);
                                taskjsonList.Add(new taskjson_model {
                                    id = totask.id, v = model.version, n = 1
                                });
                            }
                        }
                        else
                        {
                            var totask = TaskHelper.GetTask(item.totaskid);
                            if (totask != null)
                            {
                                taskjsonList.Add(new taskjson_model {
                                    id = totask.id, v = totask.taskversion, n = 0
                                });
                            }
                        }
                    }

                    using (DbConn PubConn = DbConfig.CreateConn(Config.TaskConnectString))
                    {
                        PubConn.Open();
                        tb_businessversion_dal dal = new tb_businessversion_dal();
                        var result = dal.Add(PubConn, new tb_businessversion_model
                        {
                            createtime = DateTime.Now,
                            businessversion = currentVersion,
                            description = description,
                            taskjson = JsonConvert.SerializeObject(taskjsonList)
                        });
                        if (!result)
                        {
                            return Json(new { code = -1, msg = "业务版本发布失败" });
                        }
                    }
                }
                catch (Exception ex)
                {
                    return Json(new { code = -1, msg = ex.Message });
                }
                return Json(new { code = 1, msg = "" });
            }));
        }