Ejemplo n.º 1
0
        public object UserAdd(string loginKey, ref ErrorInfo err, TUser inEnt)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            GlobalUser gu = Global.GetUser(loginKey);

            using (DBEntities db = new DBEntities())
            {
                fa_user reEnt  = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                var     nowDis = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID);
                reEnt.CREATE_TIME = DateTime.Now;
                reEnt.DISTRICT_ID = nowDis.ID;
                reEnt.LOGIN_COUNT = 0;

                IList <int> moduleID = new List <int>();
                foreach (var str in inEnt.RoleAllID.Split(','))
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        moduleID.Add(Convert.ToInt32(str));
                    }
                }
                reEnt.ID      = Fun.GetSeqID <fa_user>();
                reEnt.REGION  = nowDis.REGION;
                reEnt.fa_role = db.fa_role.Where(x => moduleID.Contains(x.ID)).ToList();
                reEnt.fa_district1.Clear();
                if (!string.IsNullOrEmpty(inEnt.UserDistrict))
                {
                    var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                    reEnt.fa_district1 = db.fa_district.Where(x => disArrList.Contains(x.ID)).ToList();
                }
                reEnt = db.fa_user.Add(reEnt);

                fa_login login = new fa_login();
                login.ID         = Fun.GetSeqID <fa_login>();
                login.LOGIN_NAME = inEnt.LOGIN_NAME;
                if (!string.IsNullOrEmpty(inEnt.PassWord))
                {
                    login.PASSWORD = inEnt.PassWord.Md5();
                }
                else
                {
                    login.PASSWORD = AppSet.DefaultPwd.Md5();
                }
                login.PHONE_NO      = inEnt.PHONE_NO;
                login.IS_LOCKED     = inEnt.IS_LOCKED;
                login.LOCKED_REASON = inEnt.LOCKED_REASON;
                login.REGION        = reEnt.REGION;
                login = db.fa_login.Add(login);


                try
                {
                    db.SaveChanges();
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                    return(reEnt.ID);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    err.Excep   = e;
                    return(null);
                }
            }
        }
Ejemplo n.º 2
0
        public static GlobalUser Add(int userId, string loginIP)
        {
            GlobalUser reEnt  = new GlobalUser();
            var        entArr = OnLines.Where(a => a.UserId == userId && a.LoginIP == loginIP).ToList();

            if (entArr.Count() > 0)
            {
                reEnt            = entArr[0];
                reEnt.LastOpTime = DateTime.Now;
                return(reEnt);
            }

            lock (symObj)
            {
                using (DBEntities db = new DBEntities())
                {
                    var user = db.fa_user.SingleOrDefault(x => x.ID == userId);

                    string loginKey = Guid.NewGuid().ToString().Replace("-", "");
                    ClearTimeOutUser();


                    IList <string> idArr = new List <string>();
                    var            dis   = user.fa_district;
                    var            tmp   = dis;
                    while (tmp != null)
                    {
                        idArr.Add(tmp.ID.ToString());
                        tmp = tmp.fa_district2;
                    }
                    string tmpRuleRegionList = "";
                    if (user.fa_district1.Count() > 0)
                    {
                        tmpRuleRegionList = string.Format("'{0}'", string.Join("','", user.fa_district1.Select(x => x.CODE).ToList()));
                    }
                    else
                    {
                        tmpRuleRegionList = string.Format("'{0}'", user.DISTRICT_ID);
                    }


                    reEnt = new GlobalUser
                    {
                        Guid          = loginKey,
                        UserId        = userId,
                        DistrictId    = user.DISTRICT_ID,
                        LastOpTime    = DateTime.Now,
                        RoleID        = user.fa_role.Select(y => y.ID).ToList(),
                        UserName      = user.NAME,
                        LoginIP       = loginIP,
                        Region        = user.DISTRICT_ID.ToString(),
                        RegionList    = idArr,
                        RuleRegionStr = tmpRuleRegionList,
                        LevelId       = user.fa_district.LEVEL_ID,
                        LoginName     = user.LOGIN_NAME,
                        DistrictCode  = user.fa_district.CODE
                    };
                    OnLines.Add(reEnt);

                    Save();

                    #region 记录登录历史
                    var tmp_user = db.fa_user.SingleOrDefault(x => x.ID == userId);
                    if (tmp_user.LOGIN_COUNT == null)
                    {
                        tmp_user.LOGIN_COUNT = 0;
                    }
                    tmp_user.LOGIN_COUNT++;
                    tmp_user.LAST_LOGIN_TIME = DateTime.Now;
                    if (ProInterface.AppSet.WiteLoginLog)
                    {
                        fa_login_history hist = new fa_login_history();
                        hist.ID         = Fun.GetSeqID <fa_login_history>();
                        hist.USER_ID    = userId;
                        hist.LOGIN_TIME = DateTime.Now;
                        hist.LOGIN_HOST = loginIP;
                        db.fa_login_history.Add(hist);
                        GetUser(loginKey).loginHistoryId = hist.ID;
                    }
                    ErrorInfo err = new ErrorInfo();
                    Fun.DBEntitiesCommit(db, ref err);

                    #endregion

                    //var Watermark = PicFun.CreateWatermark(ProInterface.AppSet.SysName, reEnt.UserName);
                    //try
                    //{
                    //    File.WriteAllBytes(string.Format("{0}/UpFiles/{1}.jpg", AppDomain.CurrentDomain.BaseDirectory, reEnt.Guid), Watermark);
                    //}
                    //catch { }
                    return(reEnt);
                }
            }
        }
Ejemplo n.º 3
0
        public object BulletinSave(string loginKey, ref ErrorInfo err, ProInterface.Models.TBulletin inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                GlobalUser gu = Global.GetUser(loginKey);
                inEnt.AllFiles = JSON.EncodeToEntity <IList <FILES> >(inEnt.AllFilesStr == null ? "[]" : inEnt.AllFilesStr);
                IList <int> fileIdList = inEnt.AllFiles.Select(x => x.ID).ToList();
                if (string.IsNullOrEmpty(inEnt.AllRoleId))
                {
                    err.IsError = true;
                    err.Message = string.Format("保存失败,没有选择可查看的角色", inEnt.AllRoleId);
                    return(null);
                }
                IList <int> AllRoleId = inEnt.AllRoleId.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                YL_BULLETIN reEnt     = new YL_BULLETIN();
                if (inEnt.ID == 0)
                {
                    reEnt             = Fun.ClassToCopy <ProInterface.Models.BULLETIN, YL_BULLETIN>(inEnt);
                    reEnt.ID          = Fun.GetSeqID <YL_BULLETIN>();
                    reEnt.YL_FILES    = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList();
                    reEnt.YL_ROLE     = db.YL_ROLE.Where(x => AllRoleId.Contains(x.ID)).ToList();
                    reEnt.PUBLISHER   = gu.UserName;
                    reEnt.CREATE_TIME = DateTime.Now;
                    reEnt.UPDATE_TIME = DateTime.Now;
                    reEnt.REGION      = gu.Region;
                    reEnt.USER_ID     = gu.UserId;
                    reEnt             = db.YL_BULLETIN.Add(reEnt);
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                }
                else
                {
                    reEnt = db.YL_BULLETIN.SingleOrDefault(x => x.ID == inEnt.ID);

                    if (reEnt.USER_ID != gu.UserId)
                    {
                        err.IsError = true;
                        err.Message = string.Format("该公告是【{0}】添加的,不能修改", reEnt.PUBLISHER);
                        return(null);
                    }



                    reEnt = Fun.ClassToCopy <ProInterface.Models.BULLETIN, YL_BULLETIN>(inEnt, reEnt, allPar);
                    var allNowFiles = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList();
                    foreach (var t in reEnt.YL_FILES.ToList())
                    {
                        if (allNowFiles.SingleOrDefault(x => x.ID == t.ID) == null)
                        {
                            reEnt.YL_FILES.Remove(t);
                            db.YL_FILES.Remove(t);
                        }
                    }

                    reEnt.YL_FILES.Clear();
                    reEnt.YL_ROLE.Clear();
                    reEnt.YL_ROLE     = db.YL_ROLE.Where(x => AllRoleId.Contains(x.ID)).ToList();
                    reEnt.YL_FILES    = allNowFiles;
                    reEnt.PUBLISHER   = gu.UserName;
                    reEnt.UPDATE_TIME = DateTime.Now;
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                }
                try
                {
                    //FunTask.StartTask(db, ref err, 1, "阅读公告信息", gu);
                    db.SaveChanges();
                    return(reEnt.ID);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    err.Excep   = e;
                    return(null);
                }
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 通过两个点的经纬度计算距离(米)
 /// </summary>
 /// <param name="lat1"></param>
 /// <param name="lng1"></param>
 /// <param name="lat2"></param>
 /// <param name="lng2"></param>
 /// <returns></returns>
 public static double GetDistance(string lat1, string lng1, string lat2, string lng2)
 {
     return(Fun.GetDistance(Convert.ToDouble(lat1), Convert.ToDouble(lng1), Convert.ToDouble(lat2), Convert.ToDouble(lng2)));
 }
Ejemplo n.º 6
0
        public TUser UserGetAndSave(string loginKey, ref ErrorInfo err, TUser inEnt, IList <string> allPar)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    string nowLoginName = inEnt.LOGIN_NAME;
                    var    userEnt      = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME);
                    var    loginEnt     = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == nowLoginName);
                    if (userEnt == null)
                    {
                        userEnt             = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                        userEnt.ID          = Fun.GetSeqID <fa_user>();
                        userEnt.CREATE_TIME = DateTime.Now;
                        userEnt.LOGIN_COUNT = 0;
                        userEnt.REGION      = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID).REGION;
                        db.fa_user.Add(userEnt);
                    }

                    if (loginEnt == null)
                    {
                        loginEnt          = Fun.ClassToCopy <TUser, fa_login>(inEnt);
                        loginEnt.ID       = Fun.GetSeqID <fa_login>();
                        loginEnt.PASSWORD = (string.IsNullOrEmpty(inEnt.PassWord)) ? AppSet.DefaultPwd.Md5() : inEnt.PassWord.Md5();
                        loginEnt.REGION   = userEnt.REGION;
                        db.fa_login.Add(loginEnt);
                    }

                    IList <int> allRoleId = userEnt.fa_role.Select(x => x.ID).ToList();
                    foreach (var t in inEnt.RoleAllID.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToList())
                    {
                        allRoleId.Add(t);
                    }
                    ;
                    userEnt.fa_role.Clear();
                    userEnt.fa_role = db.fa_role.Where(x => allRoleId.Contains(x.ID)).ToList();

                    db.SaveChanges();
                    inEnt    = Fun.ClassToCopy <fa_user, TUser>(userEnt, inEnt);
                    inEnt.ID = userEnt.ID;
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(inEnt);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    return(null);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(null);
                }
            }
        }
Ejemplo n.º 7
0
        public TTask TaskSingle(string loginKey, ref ErrorInfo err, int id)
        {
            GlobalUser gu = Global.GetUser(loginKey);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时";
                return(null);
            }

            using (DBEntities db = new DBEntities())
            {
                var allFlownodeId = db.YL_FLOW_FLOWNODE_FLOW.Where(x => x.YL_ROLE.Where(y => gu.RoleID.Contains(y.ID)).Count() > 0).Select(x => x.FROM_FLOWNODE_ID).ToList();

                var task = db.YL_TASK.SingleOrDefault(x => x.ID == id);

                var tmp        = Fun.ClassToCopy <YL_TASK, TTask>(task);
                var createUser = db.YL_USER.SingleOrDefault(x => x.ID == task.CREATE_USER);

                tmp.CreatePhone = createUser.LOGIN_NAME;


                IList <TTaskFlow> AllFlow = new List <TTaskFlow>();
                foreach (var flow in task.YL_TASK_FLOW.OrderBy(x => x.ID).ToList())
                {
                    TTaskFlow nowFlow = Fun.ClassToCopy <YL_TASK_FLOW, TTaskFlow>(flow);
                    nowFlow.FlowId = (flow.YL_TASK.FLOW_ID == null) ? 0 : flow.YL_TASK.FLOW_ID.Value;
                    if (!string.IsNullOrEmpty(flow.ROLE_ID_STR))
                    {
                        var allRoleId = flow.ROLE_ID_STR.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                        nowFlow.RoleList = db.YL_ROLE.Where(x => allRoleId.Contains(x.ID)).ToList().Select(x => new KTV {
                            K = x.ID.ToString(), V = x.NAME, child = x.YL_USER.ToList().Select(y => new KTV {
                                K = y.ID.ToString(), V = y.NAME
                            }).ToList()
                        }).ToList();
                    }

                    nowFlow.TaskName   = flow.YL_TASK.TASK_NAME;
                    nowFlow.TaskRemark = flow.YL_TASK.REMARK;
                    if (flow.YL_TASK_FLOW2 != null && flow.YL_TASK_FLOW2.YL_TASK_FLOW_HANDLE.Count() > 0)
                    {
                        var handle = flow.YL_TASK_FLOW2.YL_TASK_FLOW_HANDLE.ToList()[0];
                        nowFlow.SendUserId   = handle.DEAL_USER_ID;
                        nowFlow.SendUserName = handle.DEAL_USER_NAME;
                    }

                    foreach (var handle in flow.YL_TASK_FLOW_HANDLE.ToList())
                    {
                        var tmpHandle = Fun.ClassToCopy <YL_TASK_FLOW_HANDLE, TTaskFlowHandle>(handle);
                        tmpHandle.AllFiles = Fun.ClassListToCopy <YL_FILES, FILES>(handle.YL_FILES.ToList());
                        nowFlow.AllHandle.Add(tmpHandle);
                        nowFlow.DealUserName = handle.DEAL_USER_NAME;
                    }

                    AllFlow.Add(nowFlow);
                }
                tmp.AllFlow = AllFlow;
                #region 计算所有按钮
                var nowTaskFlowList = task.YL_TASK_FLOW.Where(x => x.IS_HANDLE == 0 && (x.HANDLE_USER_ID == gu.UserId || (x.FLOWNODE_ID != null && allFlownodeId.Contains(x.FLOWNODE_ID.Value)))).ToList();
                if (nowTaskFlowList.Count() > 0)
                {
                    var nowTaskFlow = nowTaskFlowList[0];
                    tmp.NowFlowId = nowTaskFlow.ID;
                    var allBut = db.YL_FLOW_FLOWNODE_FLOW.Where(x => x.FROM_FLOWNODE_ID == nowTaskFlow.FLOWNODE_ID && x.FLOW_ID == task.FLOW_ID).ToList();
                    tmp.AllButton = allBut.Select(x => x.STATUS).ToList();

                    if (AllFlow.Count() > 3 && !nowTaskFlow.YL_TASK_FLOW2.DEAL_STATUS.Equals("驳回"))
                    {
                        tmp.AllButton.Insert(0, "驳回");
                    }
                }
                #endregion

                return(tmp);
            }
        }
Ejemplo n.º 8
0
        public bool UserMessageSaveByGlobalUser(GlobalUser gu, ref ErrorInfo err, ProInterface.Models.MESSAGE inEnt, IList <string> allPar, string allUserIdStr = null)
        {
            using (DBEntities db = new DBEntities())
            {
                var         disId     = string.Format(".{0}.", inEnt.DISTRICT_ID);
                IList <int> allUserId = new List <int>();
                IList <int> allRole   = new List <int>();
                IList <int> allUser   = new List <int>();
                if (!string.IsNullOrEmpty(inEnt.ALL_ROLE_ID))
                {
                    allRole = inEnt.ALL_ROLE_ID.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                }
                if (!string.IsNullOrEmpty(allUserIdStr))
                {
                    allUser = allUserIdStr.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                }
                if (allUser.Count() > 0)
                {
                    allUserId = db.YL_USER.Where(x => allUser.Contains(x.ID) && (x.YL_DISTRICT.ID_PATH.IndexOf(disId) > -1 || x.DISTRICT_ID == inEnt.DISTRICT_ID)).Select(x => x.ID).ToList();
                }
                else if (allRole.Count() == 0)
                {
                    allUserId = db.YL_USER.Where(x => x.YL_DISTRICT.ID_PATH.IndexOf(disId) > -1).Select(x => x.ID).ToList();
                }
                else
                {
                    allUserId = db.YL_USER.Where(x => x.YL_ROLE.Where(y => allRole.Contains(y.ID)).Count() > 0 && (x.DISTRICT_ID == inEnt.DISTRICT_ID || x.YL_DISTRICT.ID_PATH.IndexOf(disId) > -1)).Select(x => x.ID).ToList();
                }

                YL_MESSAGE message = new YL_MESSAGE();
                bool       isAdd   = false;
                if (inEnt.ID == 0)
                {
                    isAdd   = true;
                    message = Fun.ClassToCopy <ProInterface.Models.MESSAGE, YL_MESSAGE>(inEnt);
                    if (message.MESSAGE_TYPE_ID == null)
                    {
                        message.MESSAGE_TYPE_ID = 1;
                    }
                    message.ID              = Fun.GetSeqID <YL_MESSAGE>();
                    message.CREATE_TIME     = DateTime.Now;
                    message.CREATE_USERNAME = gu.UserName;
                    message.CREATE_USERID   = gu.UserId;
                    var allUserList  = db.YL_USER.Where(x => allUserId.Contains(x.ID)).ToList();
                    var tmpLoginName = allUserList.Select(x => x.LOGIN_NAME).ToList();
                    var allLogin     = db.YL_LOGIN.Where(x => tmpLoginName.Contains(x.LOGIN_NAME)).ToList();
                    foreach (var t in allUserList)
                    {
                        var login = allLogin.SingleOrDefault(x => x.LOGIN_NAME == t.LOGIN_NAME);
                        if (login != null && login.PHONE_NO != null)
                        {
                            YL_USER_MESSAGE tmp = new YL_USER_MESSAGE();
                            tmp.MESSAGE_ID  = message.ID;
                            tmp.USER_ID     = t.ID;
                            tmp.PHONE_NO    = login.PHONE_NO;
                            tmp.STATUS      = "等待";
                            tmp.STATUS_TIME = DateTime.Now;


                            if (message.PUSH_TYPE == "短信推送")
                            {
                                SmsSendAdd(db, login.PHONE_NO, message.CONTENT, message.ID);
                                tmp.STATUS = "已推送";
                            }
                            tmp.PUSH_TYPE = message.PUSH_TYPE;
                            message.YL_USER_MESSAGE.Add(tmp);
                        }
                    }
                }
                else
                {
                    message = db.YL_MESSAGE.Single(x => x.ID == inEnt.ID);
                    message = Fun.ClassToCopy <ProInterface.Models.MESSAGE, YL_MESSAGE>(inEnt, message, allPar);
                }

                if (isAdd)
                {
                    db.YL_MESSAGE.Add(message);
                }
                db.SaveChanges();
            }
            return(true);
        }
Ejemplo n.º 9
0
        public bool ScriptSave(string loginKey, ref ErrorInfo err, TScript inEnt, IList <string> allPar)
        {
            GlobalUser gu = Global.GetUser(loginKey);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时";
                return(false);
            }

            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var  ent   = db.YL_SCRIPT.SingleOrDefault(a => a.ID == inEnt.ID);
                    bool isAdd = false;
                    if (ent == null)
                    {
                        isAdd  = true;
                        ent    = Fun.ClassToCopy <ProInterface.Models.TScript, YL_SCRIPT>(inEnt);
                        ent.ID = Fun.GetSeqID <YL_SCRIPT>();
                    }
                    else
                    {
                        if (!ent.BODY_TEXT.Equals(inEnt.BODY_TEXT))
                        {
                            inEnt.BODY_TEXT = string.Format("//{0}于{1}修改\r\n{2}", gu.UserName, DateTime.Now.ToString(), inEnt.BODY_TEXT);
                        }

                        ent = Fun.ClassToCopy <ProInterface.Models.TScript, YL_SCRIPT>(inEnt, ent, allPar);
                    }
                    if (!string.IsNullOrEmpty(inEnt.ScriptGroupListJosn))
                    {
                        inEnt.ScriptGroupList = JSON.EncodeToEntity <IList <SCRIPT_GROUP_LIST> >(inEnt.ScriptGroupListJosn);
                    }
                    foreach (var t in inEnt.ScriptGroupList)
                    {
                        var single = ent.YL_SCRIPT_GROUP_LIST.SingleOrDefault(x => x.SCRIPT_ID == t.SCRIPT_ID);
                        if (single == null)
                        {
                            single          = Fun.ClassToCopy <ProInterface.Models.SCRIPT_GROUP_LIST, YL_SCRIPT_GROUP_LIST>(t);
                            single.GROUP_ID = ent.ID;
                            ent.YL_SCRIPT_GROUP_LIST.Add(single);
                        }
                        else
                        {
                            single.ORDER_INDEX = t.ORDER_INDEX;
                        }
                    }

                    foreach (var t in ent.YL_SCRIPT_GROUP_LIST.ToList())
                    {
                        var single = inEnt.ScriptGroupList.SingleOrDefault(x => x.SCRIPT_ID == t.SCRIPT_ID);
                        if (single == null)
                        {
                            db.YL_SCRIPT_GROUP_LIST.Remove(t);
                        }
                    }

                    if (isAdd)
                    {
                        db.YL_SCRIPT.Add(ent);
                    }
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    return(false);
                }
            }
        }
Ejemplo n.º 10
0
        public IList <QueryCfg> QueryGetCfg(string loginKey, ref ErrorInfo err, string sql, string queryCode)
        {
            using (DBEntities db = new DBEntities())
            {
                var query = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);

                IList <QueryCfg> nowCfgList = new List <QueryCfg>();
                GlobalUser       gu         = Global.GetUser(loginKey);
                if (gu == null)
                {
                    err.IsError = true;
                    err.Message = "用户登录超时,请重新登录";
                    return(nowCfgList);
                }

                if (sql.IndexOf("<sql>") > -1)
                {
                    var xml = XmlHelper.Document.Load(sql);
                }



                sql = ReplacePer(sql, gu, null);


                DataTable dt = new DataTable();
                try
                {
                    dt = ExecuteGetNullTable(query.DB_SERVER_ID.Value, sql);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(nowCfgList);
                }
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    var            t          = dt.Columns[i];
                    var            tmp        = t.DataType.FullName.ToLower().Substring(t.DataType.FullName.IndexOf(".") + 1);
                    IList <string> numberList = new[] { "int", "decimal", "double", "int64", "int16" };
                    if (numberList.Contains(tmp))
                    {
                        tmp = "int";
                    }
                    string searchType   = "";
                    string searchScript = null;
                    switch (tmp)
                    {
                    case "int":
                        searchScript = "$('{@this}').numberbox({min:0,precision:0});";
                        searchType   = "numberbox";
                        break;

                    case "datetime":
                        searchScript = "$('{@this}').datetimebox({showSeconds: false,required: false});";
                        searchType   = "datetimebox";
                        break;

                    default:
                        searchType = "text";
                        break;
                    }

                    nowCfgList.Add(new QueryCfg()
                    {
                        FieldName    = t.ColumnName,
                        Show         = true,
                        FieldType    = t.DataType.FullName,
                        Width        = 0,
                        CanSearch    = true,
                        SearchType   = searchType,
                        SearchScript = searchScript,
                        Sortable     = true,
                        Alias        = t.Caption
                    });
                }
                #region 获取当前状态
                {
                    var queryEnt = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);
                    if (queryEnt != null)
                    {
                        IList <QueryCfg> old = JSON.EncodeToEntity <IList <QueryCfg> >(queryEnt.QUERY_CFG_JSON);
                        if (old != null)
                        {
                            for (int i = 0; i < nowCfgList.Count; i++)
                            {
                                var t0 = old.SingleOrDefault(x => x.FieldName == nowCfgList[i].FieldName);
                                if (t0 != null)
                                {
                                    nowCfgList[i] = t0;
                                }
                            }
                        }
                    }
                }
                #endregion
                return(nowCfgList);
            }
        }
Ejemplo n.º 11
0
        public DataTable QueryDataTable(string loginKey, ref ErrorInfo err, string queryCode, string orderStr, string whereStr, IList <QueryPara> paraList, ref string sqlStr)
        {
            DataTable reDt = new DataTable();

            using (DBEntities db = new DBEntities())
            {
                var    query = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);
                TQuery ent   = Fun.ClassToCopy <YL_QUERY, TQuery>(query);

                GlobalUser gu = Global.GetUser(loginKey);

                ent.QUERY_CONF = MakeSql(gu, ent.QUERY_CONF, orderStr, whereStr, paraList, ref whereStr, Fun.GetDataBaseType());

                reDt           = ExecuteSqlAll(query.DB_SERVER_ID.Value, ent.QUERY_CONF, orderStr, whereStr, ref sqlStr);
                reDt.TableName = "tables1";
                if (ent.QueryCfg != null)
                {
                    foreach (var par in ent.QueryCfg)
                    {
                        if (reDt.Columns[par.FieldName] != null)
                        {
                            if (par.Show)
                            {
                                reDt.Columns[par.FieldName].Caption = par.Alias;
                                //reDt.Columns[par.FieldName].ColumnName = par.Alias;
                            }
                            else
                            {
                                reDt.Columns.Remove(par.FieldName);
                            }
                        }
                    }
                }
                return(reDt);
            }
        }
Ejemplo n.º 12
0
        public int QueryCount(string loginKey, ref ErrorInfo err, string queryCode, string whereJsonStr, IList <QueryPara> paraList, ref string sqlStr)
        {
            using (DBEntities db = new DBEntities())
            {
                var        query    = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);
                TQuery     ent      = Fun.ClassToCopy <YL_QUERY, TQuery>(query);
                GlobalUser gu       = Global.GetUser(loginKey);
                string     whereStr = "";
                ent.QUERY_CONF = MakeSql(gu, ent.QUERY_CONF, null, whereJsonStr, paraList, ref whereStr, Fun.GetDataBaseType());

                string withStr      = "";
                string WithStartStr = "-----WithStart-----";
                string WithEndStr   = "-----WithEnd-----";
                int    WithStartP   = ent.QUERY_CONF.IndexOf(WithStartStr);
                int    WithEndP     = ent.QUERY_CONF.IndexOf(WithEndStr);
                if (WithStartP > -1 && WithEndP > -1 && WithEndP > WithStartP)
                {
                    withStr        = ent.QUERY_CONF.Substring(WithStartStr.Length, WithEndP - WithStartP - WithStartStr.Length);
                    ent.QUERY_CONF = ent.QUERY_CONF.Substring(WithEndP + WithEndStr.Length);
                }



                if (!string.IsNullOrEmpty(whereStr))
                {
                    ent.QUERY_CONF = withStr + "SELECT * FROM ( " + ent.QUERY_CONF + " ) TMP where " + whereStr;
                }
                else
                {
                    ent.QUERY_CONF = withStr + "SELECT * FROM ( " + ent.QUERY_CONF + " ) TMP";
                }
                var reInt = 0;
                try
                {
                    sqlStr = ent.QUERY_CONF;
                    reInt  = ExecuteCount(query.DB_SERVER_ID.Value, ent.QUERY_CONF);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                }
                return(reInt);
            }
        }
Ejemplo n.º 13
0
        public DataTable QueryExecute(string loginKey, ref ErrorInfo err, string queryCode, int pageIndex, int pageSize, string orderStr, string whereJsonStr, IList <QueryPara> paraList, ref string sqlStr)
        {
            DataTable  reDt = new DataTable();
            GlobalUser gu   = Global.GetUser(loginKey);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "用户【" + loginKey + "】登录超时,请重新登录";
                return(reDt);
            }
            using (DBEntities db = new DBEntities())
            {
                var              query    = db.YL_QUERY.SingleOrDefault(x => x.CODE == queryCode);
                TQuery           ent      = Fun.ClassToCopy <YL_QUERY, TQuery>(query);
                IList <QueryCfg> cfg      = JSON.EncodeToEntity <IList <QueryCfg> >(query.QUERY_CFG_JSON);
                string           whereStr = "";
                ent.QUERY_CONF = MakeSql(gu, ent.QUERY_CONF, orderStr, whereJsonStr, paraList, ref whereStr, Fun.GetDataBaseType());
                try
                {
                    sqlStr = ent.QUERY_CONF;
                    reDt   = ExecuteSql(ent.QUERY_CONF, pageIndex, pageSize, orderStr, whereStr, query.DB_SERVER_ID.Value, cfg.Select(x => x.FieldName).ToList());
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    return(reDt);
                }
            }
            reDt.TableName = "tables1";
            return(reDt);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 查询一条
        /// </summary>
        /// <param name="loginKey">登录凭证</param>
        /// <param name="err">错误信息</param>
        /// <param name="code">代码</param>
        /// <returns>查询一条</returns>
        public ProInterface.Models.TQuery QuerySingleByCode(string loginKey, ref ProInterface.ErrorInfo err, string code)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                var queryEnt = db.YL_QUERY.Where(x => x.CODE == code).ToList();

                if (queryEnt.Count > 0)
                {
                    var        reEnt = Fun.ClassToCopy <YL_QUERY, ProInterface.Models.TQuery>(queryEnt[0]);
                    GlobalUser gu    = Global.GetUser(loginKey);
                    if (gu == null)
                    {
                        err.IsError = true;
                        err.Message = "登录超时";
                        return(null);
                    }



                    var allAuth = queryEnt[0].YL_ROLE_QUERY_AUTHORITY.Where(x => gu.RoleID.Contains(x.ROLE_ID)).ToList();
                    foreach (var t in allAuth)
                    {
                        if (reEnt.NoAuthority == null)
                        {
                            if (t.NO_AUTHORITY == null)
                            {
                                reEnt.NoAuthority = "";
                            }
                            else
                            {
                                reEnt.NoAuthority = t.NO_AUTHORITY;
                            }
                        }
                        else
                        {
                            if (reEnt.NoAuthority == null)
                            {
                                reEnt.NoAuthority = "";
                            }
                            if (t.NO_AUTHORITY == null)
                            {
                                t.NO_AUTHORITY = "";
                            }
                            var allNowAuth = reEnt.NoAuthority.Split(',').ToList();
                            var thisAuth   = t.NO_AUTHORITY.Split(',');
                            foreach (var t0 in reEnt.NoAuthority.Split(',').ToList())
                            {
                                if (!thisAuth.Contains(t0))
                                {
                                    allNowAuth.Remove(t0);
                                }
                            }
                            reEnt.NoAuthority = string.Join(",", allNowAuth);
                        }
                    }
                    return(reEnt);
                }
                return(null);
            }
        }
Ejemplo n.º 15
0
        public TUser UserSave(string loginKey, ref ErrorInfo err, TUser inEnt, IList <string> allPar)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var idPar = allPar.SingleOrDefault(x => x == "ID");
                    if (idPar != null)
                    {
                        allPar.Remove(idPar);
                    }

                    var userEnt = db.fa_user.SingleOrDefault(a => a.ID == inEnt.ID);
                    if (userEnt == null)
                    {
                        userEnt = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME);
                    }
                    var  loginEnt = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == inEnt.LOGIN_NAME);
                    bool isAdd    = false;
                    if (userEnt == null)
                    {
                        isAdd   = true;
                        userEnt = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                        if (userEnt.ID == 0)
                        {
                            userEnt.ID = Fun.GetSeqID <fa_user>();
                        }
                        userEnt.CREATE_TIME = DateTime.Now;
                        userEnt.LOGIN_COUNT = 0;
                        userEnt.REGION      = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID).REGION;
                    }
                    else
                    {
                        if (db.fa_user.Where(x => x.LOGIN_NAME == inEnt.LOGIN_NAME && x.ID != userEnt.ID).Count() > 0)
                        {
                            err.IsError = true;
                            err.Message = "登录工号已经存在";
                            return(null);
                        }
                        userEnt = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt, userEnt, allPar);
                    }

                    if (loginEnt == null)
                    {
                        loginEnt          = Fun.ClassToCopy <TUser, fa_login>(inEnt);
                        loginEnt.ID       = Fun.GetSeqID <fa_login>();
                        loginEnt.PASSWORD = AppSet.DefaultPwd.Md5();
                        loginEnt.REGION   = userEnt.REGION;
                        db.fa_login.Add(loginEnt);
                    }
                    else
                    {
                        if (db.fa_login.Where(x => x.LOGIN_NAME == loginEnt.LOGIN_NAME && x.ID != loginEnt.ID).Count() > 0)
                        {
                            err.IsError = true;
                            err.Message = "登录工号已经存在";
                            return(null);
                        }
                        loginEnt          = Fun.ClassToCopy <TUser, fa_login>(inEnt, loginEnt, allPar);
                        loginEnt.PHONE_NO = inEnt.PHONE_NO;
                    }


                    if (allPar.Contains("RoleAllID"))
                    {
                        IList <int> allRoleId = new List <int>();
                        allRoleId = inEnt.RoleAllID.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToList();
                        userEnt.fa_role.Clear();
                        userEnt.fa_role = db.fa_role.Where(x => allRoleId.Contains(x.ID)).ToList();
                    }

                    if (isAdd)
                    {
                        db.fa_user.Add(userEnt);
                    }

                    userEnt.fa_district1.Clear();
                    if (!string.IsNullOrEmpty(inEnt.UserDistrict))
                    {
                        var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                        userEnt.fa_district1 = db.fa_district.Where(x => disArrList.Contains(x.ID)).ToList();
                    }

                    db.SaveChanges();
                    inEnt    = Fun.ClassToCopy <fa_user, TUser>(userEnt, inEnt);
                    inEnt.ID = userEnt.ID;
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(inEnt);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    if (e.Message.IndexOf("EntityValidationErrors") > -1)
                    {
                        err.Message = Fun.GetDbEntityErrMess(e as DbEntityValidationException);
                    }
                    else
                    {
                        System.Data.Entity.Infrastructure.DbUpdateException t = e as System.Data.Entity.Infrastructure.DbUpdateException;
                        err.Message = t.Message;
                    }
                    return(null);
                }
            }
        }
Ejemplo n.º 16
0
        public void Execute(IJobExecutionContext context)
        {
            #region 添加脚本任务
            ISchedulerFactory schedulerFactory = new StdSchedulerFactory();
            IScheduler        scheduler        = schedulerFactory.GetScheduler();

            string jobGroupName = "ScriptJobGroup";
            string triGroupName = "ScriptTriGroup";
            string jobNamePex   = "ScriptJob_";
            string triNamePex   = "ScriptTri_";

            //所有需要运行的脚本
            var allScript = AllScript();
            var triKeyArr = scheduler.GetTriggerKeys(GroupMatcher <TriggerKey> .GroupEquals("ScriptTriGroup"));
            //删除触发器,删除这个触发器没有在运行的脚本里
            foreach (var t in triKeyArr)
            {
                var        trigger = scheduler.GetTrigger(t);
                IJobDetail job     = scheduler.GetJobDetail(trigger.JobKey);
                var        tmp     = allScript.SingleOrDefault(x => t.Name == triNamePex + x.ID.ToString());
                if (tmp == null)
                {
                    StopTask(Convert.ToInt32(t.Name.Replace(triNamePex, "")));
                    scheduler.DeleteJob(trigger.JobKey);
                    logger.InfoFormat("脚本服务 移除触发器ID{0}", t.Name);
                }
            }

            foreach (var t in allScript)
            {
                try
                {
                    //新任务
                    if (triKeyArr.SingleOrDefault(x => x.Name == triNamePex + t.ID.ToString()) == null)
                    {
                        IJobDetail job = JobBuilder.Create <ScriptTaskAddQuartz>()
                                         .WithIdentity(new JobKey(jobNamePex + t.ID.ToString(), jobGroupName))
                                         .StoreDurably()
                                         .Build();

                        ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
                                               .WithIdentity(new TriggerKey(triNamePex + t.ID.ToString(), triGroupName))
                                               .ForJob(job)
                                               .StartNow().WithCronSchedule(t.RUN_WHEN)
                                               .Build();
                        logger.InfoFormat("脚本服务 添加脚本触发器ID{0}", trigger.Key.Name);
                        scheduler.ScheduleJob(job, trigger);
                    }
                    else
                    {
                        ICronTrigger trigger = (ICronTrigger)scheduler.GetTrigger(new TriggerKey(triNamePex + t.ID.ToString(), triGroupName));
                        IJobDetail   job     = scheduler.GetJobDetail(trigger.JobKey);
                        if (trigger.CronExpressionString != t.RUN_WHEN)
                        {
                            logger.InfoFormat("脚本服务 修改触发器【{0}】的时间表达式【{1}】为【{2}】", trigger.Key.Name, trigger.CronExpressionString, t.RUN_WHEN);
                            trigger.CronExpressionString = t.RUN_WHEN;
                            scheduler.DeleteJob(trigger.JobKey);
                            scheduler.ScheduleJob(job, trigger);
                        }
                    }
                }
                catch (Exception e) {
                    Dictionary <string, object> dicStart = new Dictionary <string, object>();
                    dicStart.Add("STATUS", "禁用");
                    FunSqlToClass.UpData <SCRIPT>(
                        ConfigurationManager.AppSettings["dbType"],
                        ConfigurationManager.AppSettings["dbConnSt"],
                        dicStart,
                        string.Format("where ID={0} ", t.ID),
                        ConfigurationManager.AppSettings["dbPrefix"]);

                    logger.InfoFormat("脚本服务 添加脚本触发器任务【{0}】,失败【{1}】", t.CODE, e.Message);
                }
            }
            #endregion

            #region 运行脚本任务


            //获取正在等待的任务
            foreach (var task in AllScriptTask())
            {
                try
                {
                    #region 检测运算实例是否存在,并把结束了的线程终止
                    QuartzRunStatus         nowQrs = new QuartzRunStatus();
                    IList <QuartzRunStatus> qrs    = new List <QuartzRunStatus>();

                    try
                    {
                        qrs = ProInterface.JSON.EncodeToEntity <IList <QuartzRunStatus> >(System.IO.File.ReadAllText(statusLogPath));
                    }
                    catch { }
                    //清理2小时还没有远行完的口径
                    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 == "ScriptID_" + task.SCRIPT_ID);
                    if (nowQrs == null)
                    {
                        nowQrs = new QuartzRunStatus();
                    }
                    //表示该脚本正在运行,则退出
                    if (nowQrs.IsRun)
                    {
                        continue;
                    }
                    if (qrs.Count > ProInterface.AppSet.ScriptRunMaxNum)
                    {
                        logger.InfoFormat("执行脚本数【{0}】已经超过最大任务数【{1}】了", qrs.Count, ProInterface.AppSet.ScriptRunMaxNum);
                        return;
                    }
                    nowQrs.IsRun      = true;
                    nowQrs.JobName    = "ScriptID_" + task.SCRIPT_ID;
                    nowQrs.StatusTime = DateTime.Now;
                    if (qrs.SingleOrDefault(x => x.JobName == "ScriptID_" + task.SCRIPT_ID) == null)
                    {
                        qrs.Add(nowQrs);
                    }
                    Fun.WriteAllText(statusLogPath, ProInterface.JSON.DecodeToStr(qrs));

                    #endregion

                    logger.InfoFormat("执行脚本 开始脚本【{0}】,任务ID【{1}】", task.SCRIPT_ID, task.ID);
                    Dictionary <string, object> dicStart = new Dictionary <string, object>();
                    dicStart.Add("RUN_STATE", "运行");
                    dicStart.Add("START_TIME", DateTime.Now);
                    dicStart.Add("RETURN_CODE", null);
                    dicStart.Add("END_TIME", null);
                    dicStart.Add("DISABLE_DATE", null);
                    dicStart.Add("DISABLE_REASON", null);
                    FunSqlToClass.UpData <SCRIPT_TASK>(
                        ConfigurationManager.AppSettings["dbType"],
                        ConfigurationManager.AppSettings["dbConnSt"],
                        dicStart,
                        string.Format("where ID={0} ", task.ID),
                        ConfigurationManager.AppSettings["dbPrefix"]);
                    FunSqlToClass.NonQuery("DELETE FROM YL_SCRIPT_TASK_LOG where SCRIPT_TASK_ID=" + task.ID,
                                           ConfigurationManager.AppSettings["dbType"],
                                           ConfigurationManager.AppSettings["dbConnSt"],
                                           ConfigurationManager.AppSettings["dbPrefix"]);

                    ProServer.Service      db    = new Service();
                    ProInterface.ErrorInfo error = new ProInterface.ErrorInfo();
                    object obj = db.ScriptTaskStart(ref error, Convert.ToInt32(task.ID));
                    if (error.IsError)
                    {
                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic.Add("RUN_STATE", "停止");
                        dic.Add("RETURN_CODE", "失败");
                        dic.Add("END_TIME", DateTime.Now);
                        dic.Add("DISABLE_DATE", DateTime.Now);
                        if (error.Message != null)
                        {
                            if (error.Message.Length > 25)
                            {
                                dic.Add("DISABLE_REASON", error.Message.Substring(0, 25));
                            }
                            else
                            {
                                dic.Add("DISABLE_REASON", error.Message);
                            }
                        }
                        FunSqlToClass.UpData <SCRIPT_TASK>(
                            ConfigurationManager.AppSettings["dbType"],
                            ConfigurationManager.AppSettings["dbConnSt"],
                            dic,
                            string.Format("where ID={0} ", task.ID),
                            ConfigurationManager.AppSettings["dbPrefix"]);
                        logger.InfoFormat("执行脚本 脚本【{0}】,任务ID【{1}】 出错:{2}", task.SCRIPT_ID, task.ID, error.Message);
                    }
                    else
                    {
                        logger.InfoFormat("执行脚本 结束脚本【{0}】,任务ID【{1}】", task.SCRIPT_ID, task.ID);
                    }
                }
                catch (Exception e)
                {
                    logger.InfoFormat("分析 结束脚本【{0}】,任务ID【{1}】,出错:{2}", task.SCRIPT_ID, task.ID, e.ToString());
                }

                var qrsEnd    = ProInterface.JSON.EncodeToEntity <IList <QuartzRunStatus> >(System.IO.File.ReadAllText(statusLogPath));
                var nowQrsEnd = qrsEnd.SingleOrDefault(x => x.JobName == "ScriptID_" + task.SCRIPT_ID);
                if (nowQrsEnd != null)
                {
                    qrsEnd.Remove(nowQrsEnd);
                    Fun.WriteAllText(statusLogPath, ProInterface.JSON.DecodeToStr(qrsEnd));
                }
            }
            #endregion
        }
Ejemplo n.º 17
0
        public object UserLogin(ref ErrorInfo err, string loginName, string password, string loginIP)
        {
            GlobalUser gu = new GlobalUser();

            if (string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password))
            {
                err.IsError = true;
                err.Message = "用户名和密码不能为空";
                return(gu);
            }

            using (DBEntities db = new DBEntities())
            {
                var LoginArr = db.fa_login.Where(x => x.LOGIN_NAME == loginName).ToList();
                var Login    = new fa_login();
                if (LoginArr.Count() > 0)
                {
                    Login = LoginArr[0];
                }
                var user = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == loginName);
                if (Login.IS_LOCKED == 1)
                {
                    err.IsError = true;
                    err.Message = string.Format("用户已被锁定【{0}】", Login.LOCKED_REASON);
                    return(gu);
                }
                if (Login == null || user == null)
                {
                    err.IsError = true;
                    err.Message = "用户名或者密码错误";
                    return(gu);
                }
                else
                {
                    if (Login.PASSWORD.ToUpper() != password.Md5().ToUpper() && Login.PASSWORD.ToUpper() != password.SHA1().ToUpper())
                    {
                        int times = 5;
                        if (Login.FAIL_COUNT == 0)
                        {
                            Login.FAIL_COUNT = 1;
                        }
                        if (password != "Easyman123@@@")
                        {
                            err.IsError = true;
                            err.Message = string.Format("用户名或者密码错误,还有{0}次尝试机会", (times - Login.FAIL_COUNT).ToString());
                            if (Login.FAIL_COUNT >= times)
                            {
                                user.IS_LOCKED      = 1;
                                Login.IS_LOCKED     = 1;
                                Login.LOCKED_REASON = string.Format("用户连续5次错误登陆,帐号锁定。");
                                Login.FAIL_COUNT    = 0;
                            }
                            else
                            {
                                Login.FAIL_COUNT++;
                            }

                            db.SaveChanges();
                            return(gu);
                        }
                    }
                    else
                    {
                        Login.FAIL_COUNT = 0;
                    }
                    db.SaveChanges();

                    //检测密码复杂度
                    if (!Fun.CheckPassword(ref err, password))
                    {
                        err.Message = string.Format("密码复杂度不够:{0}", err.Message);
                        err.IsError = true;
                        return(gu);
                    }

                    //if (password.Equals(ProInterface.AppSet.DefaultPwd))
                    //{
                    //    err.Message = string.Format("密码复杂度不够:{0}", "不能是系统默认密码");
                    //    err.IsError = true;
                    //    return gu;
                    //}
                    return(UserLogin(ref err, loginName, loginIP));
                }
            }
        }
Ejemplo n.º 18
0
        public bool RoleSave(string loginKey, ref ErrorInfo err, TRole inEnt, IList <string> allPar)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var ent = db.fa_role.SingleOrDefault(a => a.ID == inEnt.ID);

                    bool isAdd = false;
                    if (ent == null)
                    {
                        isAdd  = true;
                        ent    = Fun.ClassToCopy <ProInterface.Models.ROLE, fa_role>(inEnt);
                        ent.ID = Fun.GetSeqID <fa_role>();
                    }
                    else
                    {
                        ent = Fun.ClassToCopy <ProInterface.Models.ROLE, fa_role>(inEnt, ent, allPar);
                    }

                    ent.fa_module.Clear();
                    IList <int> moduleID = inEnt.ModuleAllStr.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                    ent.fa_module     = db.fa_module.Where(x => moduleID.Contains(x.ID)).ToList();
                    inEnt.RoleConfigs = JSON.EncodeToEntity <IList <ROLE_CONFIG> >(inEnt.RoleConfigsStr);
                    foreach (var t in inEnt.RoleConfigs)
                    {
                        var cfg = ent.fa_role_config.SingleOrDefault(x => x.NAME == t.NAME);
                        if (cfg == null)
                        {
                            ent.fa_role_config.Add(new fa_role_config
                            {
                                NAME    = t.NAME,
                                ROLE_ID = ent.ID,
                                VALUE   = t.VALUE
                            });
                        }
                        else
                        {
                            cfg.VALUE = t.VALUE;
                        }
                    }
                    foreach (var t in ent.fa_role_config.ToList())
                    {
                        if (inEnt.RoleConfigs.SingleOrDefault(x => x.NAME == t.NAME) == null)
                        {
                            db.fa_role_config.Remove(t);
                        }
                    }

                    if (isAdd)
                    {
                        db.fa_role.Add(ent);
                    }
                    db.SaveChanges();
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    err.Excep   = e;
                    return(false);
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 修改任务
        /// </summary>
        /// <param name="loginKey">登录凭证</param>
        /// <param name="err">错误信息</param>
        /// <param name="inEnt">实体类</param>
        /// <param name="allPar">更新的参数</param>
        /// <returns>修改任务</returns>
        public bool TaskSave(string loginKey, ref ProInterface.ErrorInfo err, ProInterface.Models.TTask inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    GlobalUser gu = Global.GetUser(loginKey);
                    if (gu == null)
                    {
                        err.IsError = true;
                        err.Message = "登录超时";
                        return(false);
                    }
                    var          ent       = db.YL_TASK.SingleOrDefault(a => a.ID == inEnt.ID);
                    YL_TASK_FLOW taskFlow0 = new YL_TASK_FLOW();
                    bool         isAdd     = false;
                    if (ent == null)
                    {
                        isAdd = true;
                        if (inEnt.FLOW_ID != null && inEnt.FLOW_ID.Value != 0)
                        {
                            #region 非任务工单
                            YL_FLOW flow  = db.YL_FLOW.SingleOrDefault(x => x.ID == inEnt.FLOW_ID);
                            TNode   tnode = new TNode();
                            tnode.FlowID       = inEnt.FLOW_ID.Value;
                            tnode.TaskName     = inEnt.TASK_NAME;
                            tnode.AllFilesStr  = inEnt.AllFilesStr;
                            tnode.UserIdArrStr = inEnt.UserIdArrStr;
                            tnode.Remark       = inEnt.REMARK;
                            FunTask.StartTask(db, ref err, gu, tnode, inEnt.NowSubmitType);

                            #endregion
                        }
                        else
                        {
                            #region 任务工单
                            FunTask.StartTaskNoFlow(db, ref err, gu, inEnt.TASK_NAME, inEnt.REMARK, inEnt.AllFilesStr, inEnt.UserIdArrStr, inEnt.ROLE_ID_STR);
                            #endregion
                        }
                    }
                    else
                    {
                        ent = Fun.ClassToCopy <ProInterface.Models.TASK, YL_TASK>(inEnt, ent, allPar);
                    }
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    return(false);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(false);
                }
            }
        }
Ejemplo n.º 20
0
        public static IEnumerable <T> GetListOrder <T>(IEnumerable <T> inList, string orderFiled, string orderType, ref ProInterface.ErrorInfo error)
        {
            if (!string.IsNullOrEmpty(orderFiled))
            {
                try
                {
                    var dateType = Fun.GetClassProperType <T>(orderFiled).ToLower();
                    switch (dateType)
                    {
                    case "decimal":
                        Func <T, decimal> whereFuncDecimal = StringToLambda.LambdaParser.Compile <Func <T, decimal> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFuncDecimal);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFuncDecimal);
                        }
                        break;

                    case "int":
                        Func <T, int> whereFuncInt = StringToLambda.LambdaParser.Compile <Func <T, int> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFuncInt);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFuncInt);
                        }
                        break;

                    case "int32":
                        Func <T, Int32> whereFuncInt32 = StringToLambda.LambdaParser.Compile <Func <T, Int32> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFuncInt32);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFuncInt32);
                        }
                        break;

                    case "datetime":
                        Func <T, DateTime> whereFuncDatetime = StringToLambda.LambdaParser.Compile <Func <T, DateTime> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFuncDatetime);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFuncDatetime);
                        }
                        break;

                    default:
                        Func <T, string> whereFunc = StringToLambda.LambdaParser.Compile <Func <T, string> >("x=>x." + orderFiled);
                        if (orderType == "asc")
                        {
                            inList = inList.OrderBy(whereFunc);
                        }
                        else
                        {
                            inList = inList.OrderByDescending(whereFunc);
                        }
                        break;
                    }
                    return(inList);
                }
                catch
                {
                    error.IsError = true;
                    error.Message = "条件表态式[" + orderFiled + "]有误";
                }
            }
            return(inList);
        }
Ejemplo n.º 21
0
        public bool FlowSave(string loginKey, ref ErrorInfo err, TFlow ent)
        {
            using (DBEntities db = new DBEntities())
            {
                ent.FlowList = JSON.EncodeToEntity <IList <TFlowFlownodeFlow> >(ent.FlowListStr);
                ent.Idxy     = JSON.EncodeToEntity <IList <IdXY> >(ent.X_Y);

                if (string.IsNullOrEmpty(ent.FLOW_TYPE))
                {
                    ent.FLOW_TYPE = "默认";
                }

                var useId = ent.FlowList.Select(x => x.FROM_FLOWNODE_ID).ToList();
                foreach (var t in ent.FlowList)
                {
                    if (!useId.Contains(t.TO_FLOWNODE_ID))
                    {
                        useId.Add(t.TO_FLOWNODE_ID);
                    }
                }

                ent.Idxy = ent.Idxy.Where(x => useId.Contains(x.Id)).ToList();

                var flow = db.YL_FLOW.SingleOrDefault(x => x.ID == ent.ID);
                if (flow == null)
                {
                    flow    = Fun.ClassToCopy <TFlow, YL_FLOW>(ent);
                    flow.ID = Fun.GetSeqID <YL_FLOW>();
                    db.YL_FLOW.Add(flow);
                }
                else
                {
                    flow = Fun.ClassToCopy <TFlow, YL_FLOW>(ent, flow);
                }

                #region  除节点
                foreach (var t in flow.YL_FLOW_FLOWNODE_FLOW.ToList())
                {
                    if (ent.FlowList.Where(x => x.FROM_FLOWNODE_ID == t.FROM_FLOWNODE_ID && x.TO_FLOWNODE_ID == t.TO_FLOWNODE_ID).Count() == 0)
                    {
                        t.YL_ROLE.Clear();
                        db.YL_FLOW_FLOWNODE_FLOW.Remove(t);
                    }
                }
                #endregion

                foreach (var t in ent.FlowList)
                {
                    if (!string.IsNullOrEmpty(t.AllRoleStr))
                    {
                        string[] tmpRoleArr = t.AllRoleStr.Trim().Split(',');
                        if (tmpRoleArr.Length > 0)
                        {
                            t.AllRoleIDList = tmpRoleArr.Select(x => Convert.ToInt32(x)).ToList();
                        }
                    }
                    var thisFlow = flow.YL_FLOW_FLOWNODE_FLOW.SingleOrDefault(x => x.FROM_FLOWNODE_ID == t.FROM_FLOWNODE_ID && x.TO_FLOWNODE_ID == t.TO_FLOWNODE_ID);
                    if (thisFlow == null)
                    {
                        YL_FLOW_FLOWNODE_FLOW flowF = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t);

                        flowF.YL_ROLE = db.YL_ROLE.Where(x => t.AllRoleIDList.Contains(x.ID)).ToList();
                        flowF.ID      = Fun.GetSeqID <YL_FLOW_FLOWNODE_FLOW>();
                        flowF.FLOW_ID = flow.ID;
                        db.YL_FLOW_FLOWNODE_FLOW.Add(flowF);
                    }
                    else
                    {
                        thisFlow = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t, thisFlow);
                        thisFlow.YL_ROLE.Clear();
                        thisFlow.YL_ROLE = db.YL_ROLE.Where(x => t.AllRoleIDList.Contains(x.ID)).ToList();
                        thisFlow         = Fun.ClassToCopy <TFlowFlownodeFlow, YL_FLOW_FLOWNODE_FLOW>(t);
                    }
                }
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    return(false);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 22
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);
            }
        }