Exemplo n.º 1
0
        private void addChildDesignInput(S_D_Input child, S_D_Input parent, List <S_D_Input> synData, StringBuilder sb)
        {
            if (string.IsNullOrEmpty(child.ID))
            {
                child.ID = GuidHelper.CreateGuid();
            }
            if (string.IsNullOrEmpty(child.ParentID))
            {
                child.ParentID = parent.ID;
            }
            if (string.IsNullOrEmpty(child.FullID))
            {
                child.FullID = parent.FullID + "." + child.ID;
            }
            if (string.IsNullOrEmpty(child.ProjectInfoID))
            {
                child.ProjectInfoID = parent.ProjectInfoID;
            }
            if (child.SortIndex == 0)
            {
                child.SortIndex = synData.Count(a => a.ParentID == parent.ID) + 1;
            }
            if (!synData.Exists(a => a.ID == child.ID))
            {
                synData.Add(child);
            }
            var param = new DesignInputRequestData();

            param.Id            = child.ID;
            param.name          = child.Name;
            param.FullID        = child.FullID;
            param.parentId      = child.ParentID;
            param.ProjectInfoID = child.ProjectInfoID;
            param.sort          = child.SortIndex;
            param.type          = 8;
            var queueSql = string.Format(this.SaveQueueSqlTmp, SynType.Save.ToString(), "S_D_Input", child.ID, child.Type
                                         , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), JsonHelper.ToJson <DesignInputRequestData>(param).Replace("'", "''")
                                         , this.BaseServerUrl + "folder/edit");

            sb.AppendLine(queueSql);
        }
Exemplo n.º 2
0
        public void CreateDesignInputQueue()
        {
            var sourceSql      = @"select m.* from S_D_Input m 
left join S_I_ProjectInfo p on p.ID = m.ProjectInfoID 
where 1=1";
            var synProjectMode = ConfigurationManager.AppSettings["SynProjectMode"] != null ? ConfigurationManager.AppSettings["SynProjectMode"].ToString() : string.Empty;

            if (!string.IsNullOrEmpty(synProjectMode))
            {
                sourceSql += "and ModeCode in ('" + synProjectMode.Replace(",", "','") + "') ";
            }

            //取最近的同步记录时间,到当前时间的差异数据
            var synData     = this.SQLHelperInterface.ExecuteList <S_D_Input>("select * from S_D_Input where 1=1 ");
            var lastSynTime = synData.Max(a => a.SynTime);

            if (lastSynTime != null)
            {
                //判断同步增量数据 还是 所有数据
                var startDate = Convert.ToDateTime(lastSynTime).ToString();
                var endDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                sourceSql += " and m.ModifyDate >='" + startDate + "' and m.ModifyDate <='" + endDate + "'";
            }

            #region Remove
            var removeSb  = new StringBuilder();
            var removeUrl = this.BaseServerUrl + "folder/delete";
            var alldtSql  = @"select m.ID from S_D_Input m left join S_I_ProjectInfo p on p.ID = m.ProjectInfoID 
where 1=1";
            if (!string.IsNullOrEmpty(synProjectMode))
            {
                alldtSql += "and ModeCode in ('" + synProjectMode.Replace(",", "','") + "') ";
            }
            var alldt  = this.SQLHelpeProject.ExecuteDataTable(alldtSql);
            var allIDs = new List <string>();
            foreach (DataRow item in alldt.Rows)
            {
                allIDs.Add(item["ID"].ToString());
            }
            var removeList = synData.Where(a => !allIDs.Contains(a.ID) && a.Type == DesignInputType.Actual.ToString() && a.State == DataState.Normal.ToString()).ToList();
            foreach (var item in removeList)
            {
                var queueSql = string.Format(this.SaveQueueSqlTmp, SynType.Remove.ToString(), "S_D_Input", item.ID, item.Type
                                             , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), JsonHelper.ToJson <DeleteRequestData>(new DeleteRequestData()
                {
                    id = item.ID
                }), string.Format(removeUrl, item.Type == "Major" ? "Plan" : "Exchange"));
                removeSb.AppendLine(queueSql);
            }

            if (removeSb.Length > 0)
            {
                this.SQLHelperInterface.ExecuteNonQuery(removeSb.ToString());
            }
            #endregion

            #region Edit

            var saveUrl  = this.BaseServerUrl + "folder/edit";
            var saveSb   = new StringBuilder();
            var sourceDt = this.SQLHelpeProject.ExecuteDataTable(sourceSql);

            foreach (DataRow row in sourceDt.Rows)
            {
                var dic           = DataHelper.DataRowToDic(row);
                var ID            = dic.GetValue("ID");
                var projectInfoID = dic.GetValue("ProjectInfoID");
                var catagory      = dic.GetValue("Catagory");
                var inputType     = dic.GetValue("InputType");
                var name          = dic.GetValue("InfoName");
                var sortIndex     = dic.GetValue("SortIndex");

                if (!synData.Any(a => a.ProjectInfoID == projectInfoID))
                {
                    var initVirtualSql = initVirtualDesignInput(projectInfoID, sourceDt, synData);
                    saveSb.AppendLine(initVirtualSql);
                }
                //设置参数
                var root = synData.FirstOrDefault(a => a.ProjectInfoID == projectInfoID && a.Code == "Root");

                var typeInput = synData.FirstOrDefault(a => a.ProjectInfoID == projectInfoID && a.Type == DesignInputType.Virtual.ToString() &&
                                                       a.Name == inputType && a.Code == catagory);
                if (typeInput == null)
                {
                    var catagoryInput = synData.FirstOrDefault(a => a.ParentID == root.ID && a.Code == catagory);
                    if (catagoryInput == null)
                    {
                        catagoryInput = new S_D_Input()
                        {
                            Code = catagory,
                            Name = catagory,
                            Type = DesignInputType.Virtual.ToString()
                        };
                        //只可能是新增专业,缺专业对应目录
                        var majorEnum = GlobalData.MajorList.FirstOrDefault(a => a.Code == catagory);
                        if (majorEnum == null)
                        {
                            continue;
                        }
                        catagoryInput.Name = majorEnum.Name;
                        addChildDesignInput(catagoryInput, root, synData, saveSb);
                    }
                    typeInput = new S_D_Input()
                    {
                        Code = catagory,
                        Name = inputType,
                        Type = DesignInputType.Virtual.ToString()
                    };
                    addChildDesignInput(typeInput, catagoryInput, synData, saveSb);
                }
                var input = new S_D_Input()
                {
                    ID        = ID,
                    Code      = catagory,
                    Name      = name,
                    SortIndex = string.IsNullOrEmpty(sortIndex) ? 0 : Convert.ToInt32(sortIndex),
                    Type      = DesignInputType.Actual.ToString()
                };
                addChildDesignInput(input, typeInput, synData, saveSb);
            }

            if (saveSb.Length > 0)
            {
                this.SQLHelperInterface.ExecuteNonQuery(saveSb.ToString());
            }
            #endregion
        }