Esempio n. 1
0
        /// <summary>
        /// 添加一个任务脚本
        /// </summary>
        /// <param name="scriptId"></param>
        public void AddScriptTask(int scriptId, int?groupId, ref long taskId)
        {
            var scriptEnt = FunSqlToClass.ClassSingle <SCRIPT>(
                ConfigurationManager.AppSettings["dbType"],
                ConfigurationManager.AppSettings["dbConnSt"],
                "where ID = " + scriptId,
                ConfigurationManager.AppSettings["dbPrefix"]
                );

            SCRIPT_TASK ent = new SCRIPT_TASK();

            ent.ID = FunSqlToClass.GetSeqID <SCRIPT_TASK>(
                ConfigurationManager.AppSettings["dbType"],
                ConfigurationManager.AppSettings["dbConnSt"],
                ConfigurationManager.AppSettings["dbPrefix"]
                );
            ent.SCRIPT_ID    = scriptId;
            ent.GROUP_ID     = groupId;
            ent.BODY_TEXT    = scriptEnt.BODY_TEXT;
            ent.BODY_HASH    = scriptEnt.BODY_HASH;
            ent.RUN_WHEN     = scriptEnt.RUN_WHEN;
            ent.RUN_ARGS     = scriptEnt.RUN_ARGS;
            ent.RUN_DATA     = scriptEnt.RUN_DATA;
            ent.RUN_STATE    = "等待";
            ent.DSL_TYPE     = "自动添加";
            ent.START_TIME   = DateTime.Now;
            ent.SERVICE_FLAG = scriptEnt.SERVICE_FLAG;
            FunSqlToClass.Save <SCRIPT_TASK>(
                ConfigurationManager.AppSettings["dbType"],
                ConfigurationManager.AppSettings["dbConnSt"],
                ent,
                ConfigurationManager.AppSettings["dbPrefix"]
                );

            taskId = ent.ID;
        }
Esempio n. 2
0
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                logger.Info("启动自动下载数据 开始");
                var downID = Convert.ToInt32(context.JobDetail.Key.Name.Replace("DownDataJob_", ""));
                logger.Info(string.Format("启动自动下载数据 数据ID{0}", downID));


                var down = FunSqlToClass.ClassSingle <DATA_DOWN>(
                    ConfigurationManager.AppSettings["dbType"],
                    ConfigurationManager.AppSettings["dbConnSt"],
                    "where ID = " + downID,
                    ConfigurationManager.AppSettings["dbPrefix"]
                    );

                string tableName = ProServer.Fun.ReplaceDataTime(down.CREATE_TABLE_NAME, DateTime.Now);
                var    eventEnt  = new DATA_DOWN_EVENT();
                eventEnt.ID = FunSqlToClass.GetSeqID <DATA_DOWN_EVENT>(
                    ConfigurationManager.AppSettings["dbType"],
                    ConfigurationManager.AppSettings["dbConnSt"],
                    ConfigurationManager.AppSettings["dbPrefix"]
                    );
                eventEnt.TARGET_NAME    = tableName;
                eventEnt.ALL_NUM        = 0;
                eventEnt.LAST_MONTH_NUM = 0;
                eventEnt.PATH           = down.TO_PATH;
                eventEnt.DATA_DOWN_ID   = downID;
                eventEnt.START_TIME     = DateTime.Now;

                FunSqlToClass.Save <DATA_DOWN_EVENT>(
                    ConfigurationManager.AppSettings["dbType"],
                    ConfigurationManager.AppSettings["dbConnSt"],
                    eventEnt,
                    ConfigurationManager.AppSettings["dbPrefix"]
                    );

                string createScript = "";
                if (!string.IsNullOrEmpty(down.CREATE_SCRIPT))
                {
                    createScript = down.CREATE_SCRIPT.Replace("{@TABLE_NAME}", eventEnt.TARGET_NAME);
                }

                var allDataDownTo = FunSqlToClass.SqlToList <ProInterface.Models.DATA_DOWN_TO>(string.Format("select * from YL_DATA_DOWN_TO where DATA_DOWN_ID='{0}'", downID), ConfigurationManager.AppSettings["dbType"], ConfigurationManager.AppSettings["dbConnSt"]);

                foreach (var to in allDataDownTo)
                {
                    var toServer = FunSqlToClass.ClassSingle <DB_SERVER>(
                        ConfigurationManager.AppSettings["dbType"],
                        ConfigurationManager.AppSettings["dbConnSt"],
                        "where ID = " + to.DB_SERVER_ID,
                        ConfigurationManager.AppSettings["dbPrefix"]
                        );

                    #region 在目标服务器上创建表
                    var db = new ProServer.ScriptExt();
                    try
                    {
                        try
                        {
                            db.execute("drop table " + eventEnt.TARGET_NAME, toServer);
                        }
                        catch (Exception e)
                        {
                        }
                        db.execute(createScript, toServer);
                    }
                    catch (Exception e)
                    {
                        logger.Info(string.Format("在服务器【{0}】上建表失败:\r\nSQL:{1}\r\n{2}", toServer.NICKNAME, createScript, e.Message));
                    }
                    #endregion


                    var allDataDownForm = FunSqlToClass.SqlToList <ProInterface.Models.DB_SERVER>(string.Format("select a.* from YL_DB_SERVER a,YL_DATA_DOWN_FORM b where a.ID=b.DB_SERVER_ID and b.DATA_DOWN_ID='{0}'", downID), ConfigurationManager.AppSettings["dbType"], ConfigurationManager.AppSettings["dbConnSt"]);
                    foreach (var from in allDataDownForm)
                    {
                        DATA_DOWN_TASK task = new DATA_DOWN_TASK();
                        task.ID = FunSqlToClass.GetSeqID <DATA_DOWN_EVENT>(
                            ConfigurationManager.AppSettings["dbType"],
                            ConfigurationManager.AppSettings["dbConnSt"],
                            ConfigurationManager.AppSettings["dbPrefix"]
                            );
                        task.NAME          = eventEnt.TARGET_NAME;
                        task.SELECT_SCRIPT = down.SELECT_SCRIPT;
                        task.EVENT_ID      = eventEnt.ID;
                        #region 替换SELECT_SCRIPT
                        foreach (var replace in JSON.EncodeToEntity <IList <KV> >(to.REPLACE_STR))
                        {
                            task.SELECT_SCRIPT = task.SELECT_SCRIPT.Replace(replace.K, replace.V);
                        }
                        task.SELECT_SCRIPT = ProServer.Fun.ReplaceDataTime(task.SELECT_SCRIPT, DateTime.Now);
                        #endregion

                        #region 生成@[00-99]
                        if (task.SELECT_SCRIPT.IndexOf("@") != -1)
                        {
                            task.SELECT_SCRIPT = Fun.GetSelectScript(task.SELECT_SCRIPT);
                        }
                        #endregion

                        //设置存放路径
                        task.TO_PATH = ProServer.Fun.ReplaceDataTime(down.TO_PATH, DateTime.Now);

                        int thisAllNum = 0;

                        task.ALL_NUM = thisAllNum;
                        int upMonthNum = 0;

                        task.LAST_MONTH_NUM   = upMonthNum;
                        task.SELECT_DB_SERVER = from.ID;
                        task.SELECT_SERVER    = string.Format("(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1})))(CONNECT_DATA=(SERVER=DEDICATED)(SID={2})))", from.IP, from.PORT, from.DBNAME);
                        task.SELECT_UID       = from.UID;
                        task.SELECT_PWD       = from.PASSWORD;
                        task.EVENT_TYPE       = 1;
                        if (down.SUCC_SCRIPT != null)
                        {
                            task.SUCC_SCRIPT = down.SUCC_SCRIPT.Replace("{@TABLE_NAME}", eventEnt.TARGET_NAME);
                        }
                        task.TO_DB_SERVER  = toServer.ID;
                        task.TO_SERVER     = toServer.DBNAME;
                        task.TO_UID        = toServer.UID;
                        task.TO_PWD        = toServer.PASSWORD;
                        task.CREATE_SCRIPT = createScript;
                        task.ERROR_NUM     = 0;
                        task.STATUS        = "等待";
                        task.PAGE_SIZE     = down.PAGE_SIZE;
                        task.SPLIT_STR     = down.SPLIT_STR;
                        task.IS_CANCEL     = 0;
                        task.ORDER_NUM     = task.ID;

                        FunSqlToClass.Save <DATA_DOWN_TASK>(
                            ConfigurationManager.AppSettings["dbType"],
                            ConfigurationManager.AppSettings["dbConnSt"],
                            task,
                            ConfigurationManager.AppSettings["dbPrefix"]
                            );
                    }
                }

                logger.Info("启动自动下载数据 结束");
            }
            catch (Exception ex)
            {
                logger.Error("启动自动下载数据 运行异常", ex);
            }
        }