Beispiel #1
0
        /// <summary>
        /// 获取所有等待脚本任务
        /// </summary>
        /// <returns></returns>
        public IList <ProInterface.Models.SCRIPT_TASK> AllScriptTask()
        {
            IList <ProInterface.Models.SCRIPT_TASK> reList = new List <ProInterface.Models.SCRIPT_TASK>();

            reList = FunSqlToClass.SqlToList <ProInterface.Models.SCRIPT_TASK>("select * from YL_SCRIPT_TASK where RUN_STATE='等待'", ConfigurationManager.AppSettings["dbType"], ConfigurationManager.AppSettings["dbConnSt"]);
            return(reList);
        }
Beispiel #2
0
        public void Execute(IJobExecutionContext context)
        {
            var scriptId = Convert.ToInt32(context.JobDetail.Key.Name.Replace("ScriptJob_", ""));
            var taskEnt  = FunSqlToClass.ClassSingle <SCRIPT_TASK>(
                ConfigurationManager.AppSettings["dbType"],
                ConfigurationManager.AppSettings["dbConnSt"],
                "where RUN_STATE='运行' AND SCRIPT_ID = " + scriptId,
                ConfigurationManager.AppSettings["dbPrefix"]
                );

            //如果有任务没有结束,则不添加任务
            if (taskEnt != null && taskEnt.ID != 0)
            {
                if (taskEnt.START_TIME != null && taskEnt.START_TIME.Value.AddHours(2) < DateTime.Now)
                {
                    Dictionary <string, object> dicStart = new Dictionary <string, object>();
                    dicStart.Add("RUN_STATE", "失败");
                    dicStart.Add("DISABLE_REASON", "运行超时");
                    FunSqlToClass.UpData <SCRIPT_TASK>(
                        ConfigurationManager.AppSettings["dbType"],
                        ConfigurationManager.AppSettings["dbConnSt"],
                        dicStart,
                        string.Format("where ID={0} ", scriptId),
                        ConfigurationManager.AppSettings["dbPrefix"]);
                }
                else
                {
                    return;
                }
            }


            var scriptEnt = FunSqlToClass.ClassSingle <SCRIPT>(
                ConfigurationManager.AppSettings["dbType"],
                ConfigurationManager.AppSettings["dbConnSt"],
                "where ID = " + scriptId,
                ConfigurationManager.AppSettings["dbPrefix"]
                );


            ScriptExt ext = new ScriptExt();

            if (scriptEnt.IS_GROUP == (short)1)//表示是任务组
            {
                IList <ProInterface.Models.SCRIPT_GROUP_LIST> reList = new List <ProInterface.Models.SCRIPT_GROUP_LIST>();
                reList = FunSqlToClass.SqlToList <ProInterface.Models.SCRIPT_GROUP_LIST>(string.Format("SELECT * FROM YL_SCRIPT_GROUP_LIST WHERE GROUP_ID={0} ORDER BY ORDER_INDEX", scriptId), ConfigurationManager.AppSettings["dbType"], ConfigurationManager.AppSettings["dbConnSt"]);
                if (reList.Count() > 0)
                {
                    long taskId = 0;
                    ext.AddScriptTask(reList[0].SCRIPT_ID, scriptId, ref taskId);
                    logger.InfoFormat("执行脚本 添加脚本【{0}】任务ID【{1}】", scriptId, taskId);
                }
            }
            else//普通脚本
            {
                long taskId = 0;
                ext.AddScriptTask(scriptId, null, ref taskId);
                logger.InfoFormat("执行脚本 添加脚本【{0}】任务ID【{1}】", scriptId, taskId);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 获取所有任务
        /// </summary>
        /// <returns></returns>
        public IList <ProInterface.Models.DATA_DOWN> AllDownData()
        {
            IList <ProInterface.Models.DATA_DOWN> reList = new List <ProInterface.Models.DATA_DOWN>();

            reList = FunSqlToClass.SqlToList <ProInterface.Models.DATA_DOWN>("select * from YL_DATA_DOWN where STATUS='正常' and CRON_EXPRESSION is not null", ConfigurationManager.AppSettings["dbType"], ConfigurationManager.AppSettings["dbConnSt"]);
            return(reList);
        }
Beispiel #4
0
        /// <summary>
        /// 获取所有脚本
        /// </summary>
        /// <returns></returns>
        public IList <ProInterface.Models.SCRIPT> AllScript()
        {
            IList <ProInterface.Models.SCRIPT> reList = new List <ProInterface.Models.SCRIPT>();

            reList = FunSqlToClass.SqlToList <ProInterface.Models.SCRIPT>("select * from YL_SCRIPT where STATUS='正常' and RUN_WHEN is not null", ConfigurationManager.AppSettings["dbType"], ConfigurationManager.AppSettings["dbConnSt"]);
            reList = reList.OrderBy(x => x.ID).ToList();
            return(reList);
        }
Beispiel #5
0
        /// <summary>
        /// 启动
        /// </summary>
        /// <param name="csharpCode"></param>
        /// <param name="scriptTaskID"></param>
        /// <param name="defaultDb"></param>
        /// <returns>程序集的实例</returns>
        public bool ScriptTaskStart(ref ErrorInfo error, int scriptTaskID)
        {
            var scriptEnt = FunSqlToClass.ClassSingle <SCRIPT_TASK>(
                ConfigurationManager.AppSettings["dbType"],
                ConfigurationManager.AppSettings["dbConnSt"],
                "where ID = " + scriptTaskID,
                ConfigurationManager.AppSettings["dbPrefix"]
                );

            if (scriptEnt == null)
            {
                error.IsError = true;
                error.Message = "脚本不存在";
                return(false);
            }

            string pathInterface = AppDomain.CurrentDomain.BaseDirectory + "ProInterface.dll";
            string pathServer    = AppDomain.CurrentDomain.BaseDirectory + "ProServer.dll";

            #region 判断类库是否存在
            if (!System.IO.File.Exists(pathInterface))
            {
                pathInterface = AppDomain.CurrentDomain.BaseDirectory + "Bin\\ProInterface.dll";
            }
            if (!System.IO.File.Exists(pathServer))
            {
                pathServer = AppDomain.CurrentDomain.BaseDirectory + "Bin\\ProServer.dll";
            }

            if (!System.IO.File.Exists(pathInterface))
            {
                error.Message = string.Format("类库【{0}】不存在", pathInterface);
                return(false);
            }
            if (!System.IO.File.Exists(pathServer))
            {
                error.Message = string.Format("类库【{0}】不存在", pathInterface);
                return(false);
            }
            #endregion

            CSharpCodeProvider objCSharpCodePrivoder = new CSharpCodeProvider();
            ICodeCompiler      objICodeCompiler      = objCSharpCodePrivoder.CreateCompiler();
            CompilerParameters objCompilerParameters = new CompilerParameters();
            objCompilerParameters.ReferencedAssemblies.Add("System.dll");
            objCompilerParameters.ReferencedAssemblies.Add(pathInterface);
            objCompilerParameters.ReferencedAssemblies.Add(pathServer);
            objCompilerParameters.GenerateExecutable = false;
            objCompilerParameters.GenerateInMemory   = true;

            string allCode = "";
            try
            {
                allCode = GenerateCode(scriptEnt.BODY_TEXT, AnalysisRunDate(scriptEnt.RUN_DATA));
            }
            catch
            {
                ErrorScriptTask(error.Message, Convert.ToInt32(scriptEnt.ID));
                return(false);
            }
            CompilerResults cr = objICodeCompiler.CompileAssemblyFromSource(objCompilerParameters, allCode);
            if (cr.Errors.HasErrors)
            {
                StringBuilder sb = new StringBuilder("编译错误:");
                foreach (CompilerError err in cr.Errors)
                {
                    sb.AppendLine(string.Format("行{0}列{1}:{2} <br />", err.Line - 12, err.Column, err.ErrorText));
                }
                error.IsError = true;
                error.Message = sb.ToString();

                ErrorScriptTask(error.Message, Convert.ToInt32(scriptEnt.ID));

                return(false);
            }
            else
            {
                // 通过反射,调用HelloWorld的实例
                objAssembly = cr.CompiledAssembly;
                object objScripRun = objAssembly.CreateInstance("ProServer.ScripRun");

                //创建任务
                var bodyText = objScripRun.GetType().GetMethod("ScriptTaskRun").Invoke(objScripRun, new object[] { scriptEnt.ID });
                var setnowdb = objScripRun.GetType().GetMethod("setnowdb").Invoke(objScripRun, new object[] { scriptEnt.SERVICE_FLAG });
                //运行脚本
                var run      = objScripRun.GetType().GetMethod("Run").Invoke(objScripRun, null);
                var errorMsg = objScripRun.GetType().GetMethod("GetError").Invoke(objScripRun, null);

                IList <ProInterface.Models.SCRIPT_GROUP_LIST> reList = FunSqlToClass.SqlToList <ProInterface.Models.SCRIPT_GROUP_LIST>(
                    string.Format("SELECT * FROM YL_SCRIPT_GROUP_LIST WHERE GROUP_ID={0} ORDER BY ORDER_INDEX", (scriptEnt.GROUP_ID == null) ? 0 : scriptEnt.GROUP_ID.Value),
                    ConfigurationManager.AppSettings["dbType"],
                    ConfigurationManager.AppSettings["dbConnSt"]);
                if (reList.Count() > 0 && (bool)run && string.IsNullOrEmpty(errorMsg.ToString()))
                {
                    var nowPlace = reList.SingleOrDefault(x => x.SCRIPT_ID == scriptEnt.SCRIPT_ID);
                    var last     = reList.Where(x => x.ORDER_INDEX > nowPlace.ORDER_INDEX).ToList();
                    if (last.Count() > 0)
                    {
                        long      taskId = 0;
                        ScriptExt ext    = new ScriptExt();
                        ext.AddScriptTask(last[0].SCRIPT_ID, last[0].GROUP_ID, ref taskId);
                    }
                }
                return(string.IsNullOrEmpty(errorMsg.ToString()));
            }
        }
Beispiel #6
0
        public void Execute(IJobExecutionContext context)
        {
            #region 检测运算实例是否存在,并把结束了的线程终止

            QuartzRunStatus         nowQrs = new QuartzRunStatus();
            IList <QuartzRunStatus> qrs    = new List <QuartzRunStatus>();

            try
            {
                qrs = ProInterface.JSON.EncodeToEntity <IList <QuartzRunStatus> >(System.IO.File.ReadAllText(statusLogPath));
            }
            catch { }
            foreach (var t in qrs.Where(x => x.StatusTime.AddHours(2) < DateTime.Now).ToList())
            {
                qrs.Remove(t);
            }
            if (qrs == null)
            {
                qrs = new List <QuartzRunStatus>();
            }
            nowQrs = qrs.SingleOrDefault(x => x.JobName == context.JobDetail.Key.Name);
            if (nowQrs == null)
            {
                nowQrs = new QuartzRunStatus();
            }
            if (nowQrs.IsRun)
            {
                return;
            }
            nowQrs.IsRun      = true;
            nowQrs.JobName    = context.JobDetail.Key.Name;
            nowQrs.StatusTime = DateTime.Now;
            if (qrs.SingleOrDefault(x => x.JobName == context.JobDetail.Key.Name) == null)
            {
                qrs.Add(nowQrs);
            }
            Fun.WriteAllText(statusLogPath, ProInterface.JSON.DecodeToStr(qrs));

            #endregion



            try
            {
                #region 添加发送的短信
                //添加数据
                string sql = @"
INSERT INTO YL_SMS_SEND(
   KEY,
   MESSAGE_ID,
   PHONE_NO,
   ADD_TIME,
   CONTENT,
   STAUTS)
SELECT 
   SYS_GUID() KEY,
   A.MESSAGE_ID,
   A.PHONE_NO,
   sysdate ADD_TIME,
   B.CONTENT,
   '等待' STAUTS
 FROM YL_USER_MESSAGE A,YL_MESSAGE B WHERE A.MESSAGE_ID=B.ID AND A.STATUS='等待' AND PHONE_NO IS NOT NULL
AND ((CEIL(((SYSDATE -CAST(A.STATUS_TIME AS DATE) )) * 24 * 60)>30 AND B.PUSH_TYPE='智能推送') OR B.PUSH_TYPE='短信推送')
";
                //更新状态
                string sqlUpdate = "UPDATE YL_USER_MESSAGE SET  STATUS='已推送',PUSH_TYPE='短信推送' WHERE STATUS='等待' AND PHONE_NO IS NOT NULL AND ((CEIL(((SYSDATE -CAST(STATUS_TIME AS DATE) )) * 24 * 60)>30 AND PUSH_TYPE='智能推送') OR PUSH_TYPE='短信推送')";

                FunSqlToClass.NonQuery(sql,
                                       ConfigurationManager.AppSettings["dbType"],
                                       ConfigurationManager.AppSettings["dbConnSt"],
                                       ConfigurationManager.AppSettings["dbPrefix"]);

                FunSqlToClass.NonQuery(sqlUpdate,
                                       ConfigurationManager.AppSettings["dbType"],
                                       ConfigurationManager.AppSettings["dbConnSt"],
                                       ConfigurationManager.AppSettings["dbPrefix"]);

                #endregion


                IList <ProInterface.Models.SMS_SEND> reList = new List <ProInterface.Models.SMS_SEND>();
                reList = FunSqlToClass.SqlToList <ProInterface.Models.SMS_SEND>("SELECT * FROM YL_SMS_SEND WHERE STAUTS='等待' OR (STAUTS='失败' AND TRY_NUM<5)", ConfigurationManager.AppSettings["dbType"], ConfigurationManager.AppSettings["dbConnSt"]);
                if (reList != null && reList.Count() > 0)
                {
                    reList = reList.OrderBy(x => x.ADD_TIME).ToList();
                    ProInterface.ErrorInfo error = new ErrorInfo();
                    int succNum = 0;

                    FunSqlToClass.NonQuery("UPDATE YL_SMS_SEND SET TRY_NUM=TRY_NUM+1 WHERE STAUTS='等待' OR (STAUTS='失败' AND TRY_NUM<5)",
                                           ConfigurationManager.AppSettings["dbType"],
                                           ConfigurationManager.AppSettings["dbConnSt"],
                                           ConfigurationManager.AppSettings["dbPrefix"]);

                    foreach (var t in reList.GroupBy(x => x.CONTENT).ToList())
                    {
                        var conten    = t.Key;
                        var phoneList = t.Select(x => x.PHONE_NO).ToArray();

                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic.Add("SEND_TIME", DateTime.Now);
                        dic.Add("STAUTS", "成功");

                        var allPage = t.Count() / 1000;
                        if (t.Count() % 1000 != 0)
                        {
                            allPage++;
                        }
                        for (var i = 0; i < allPage; i++)
                        {
                            FunSqlToClass.UpData <SMS_SEND>(
                                ConfigurationManager.AppSettings["dbType"],
                                ConfigurationManager.AppSettings["dbConnSt"],
                                dic,
                                string.Format(" where KEY IN ('{0}') ", string.Join("','", t.Skip(i * 1000).Take(1000).Select(x => x.KEY))),
                                ConfigurationManager.AppSettings["dbPrefix"]);
                        }

                        foreach (var phone in phoneList)
                        {
                            DbHelper.MasHelper.Send(phone, conten);
                        }
                        succNum += phoneList.Count();
                    }


                    //sms.SmsConnection("", ref error);
                    //foreach (var t in reList)
                    //{
                    //    Dictionary<string, object> dic = new Dictionary<string, object>();
                    //    dic.Add("SEND_TIME", DateTime.Now);
                    //    string[] listPhoneNo = new string[] { t.PHONE_NO };
                    //    if (sms.SmsSend("", ref error, t.PHONE_NO, t.CONTENT))
                    //    //if (SMSHandle.sendSms(listPhoneNo, t.CONTENT) == "0")
                    //    {
                    //        succNum++;
                    //        dic.Add("STAUTS", "成功");
                    //    }
                    //    else
                    //    {
                    //        dic.Add("STAUTS", "失败");
                    //    }
                    //    FunSqlToClass.UpData<SMS_SEND>(
                    //        ConfigurationManager.AppSettings["dbType"],
                    //        ConfigurationManager.AppSettings["dbConnSt"],
                    //        dic,
                    //        string.Format(" where KEY='{0}' ", t.KEY),
                    //        ConfigurationManager.AppSettings["dbPrefix"]);
                    //}
                    //sms.SmsDisconnection("", ref error);
                    //if (error.IsError)
                    //{
                    //    logger.Info(string.Format("断开短信猫失败【{0}】", error.Message));
                    //}


                    logger.Info(string.Format("成功发送【{0}】条短信", succNum));
                }
                qrs.Remove(nowQrs);
                Fun.WriteAllText(statusLogPath, ProInterface.JSON.DecodeToStr(qrs));
            }
            catch (Exception ex)
            {
                qrs.Remove(nowQrs);
                Fun.WriteAllText(statusLogPath, ProInterface.JSON.DecodeToStr(qrs));
                logger.Error("发送短信 运行异常", ex);
            }
        }
Beispiel #7
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);
            }
        }