Пример #1
0
        public ActionResult SetAutoAllotAjax(EditorAutoAllotEntity autoAllotEntity)
        {
            ExecResult execResult = new ExecResult();

            try
            {
                autoAllotEntity.JournalID = JournalID;
                IContributionFacadeService service = ServiceContainer.Instance.Container.Resolve<IContributionFacadeService>();
                // 如果是按照学科分类进行设置
                if (autoAllotEntity.SubjectAuthorMap != null && autoAllotEntity.AllotPattern == 1)
                {
                    foreach (SubjectAuthorMapEntity item in autoAllotEntity.SubjectAuthorMap)
                    {
                        item.JournalID = JournalID;
                    }
                }
                execResult = service.SetAllowAllot(autoAllotEntity);
            }
            catch (Exception ex)
            {
                execResult.result = EnumJsonResult.error.ToString();
                execResult.msg = "设置投稿自动分配出现异常:" + ex.Message;
                WKT.Log.LogProvider.Instance.Error("设置投稿自动分配出现异常:" + ex.Message);
            }

            return Content(JsonConvert.SerializeObject(execResult));
        }
 /// <summary>
 /// 更新投稿自动配置
 /// </summary>
 /// <param name="cSetEntity"></param>
 /// <returns></returns>
 public bool SetAutoAllot(EditorAutoAllotEntity cSetEntity)
 {
     return EditorAutoAllotDataAccess.Instance.SetAutoAllot(cSetEntity);
 }
        /// <summary>
        /// 保存投稿自动分配设置
        /// </summary>
        /// <param name="cSetEntity"></param>
        /// <returns></returns>
        private bool SaveAutoAllot(EditorAutoAllotEntity cSetEntity)
        {
            bool flag = false;
            string sql = @" IF EXISTS(SELECT TOP 1 1 FROM dbo.EditorAutoAllot e WITH(NOLOCK) WHERE e.JournalID=@JournalID)
                            BEGIN
                                UPDATE TOP(1) dbo.EditorAutoAllot SET AllotPattern=@AllotPattern,OddAuthorID=@OddAuthorID,AuthorID=@AuthorID WHERE JournalID=@JournalID
                            END
                            ELSE
                            BEGIN
                            INSERT INTO dbo.EditorAutoAllot(JournalID,AllotPattern,AuthorID,OddAuthorID) VALUES(@JournalID,@AllotPattern,@AuthorID,@OddAuthorID)
                            END";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@JournalID", DbType.Int64, cSetEntity.JournalID);
            db.AddInParameter(cmd, "@AllotPattern", DbType.Byte, cSetEntity.AllotPattern);
            db.AddInParameter(cmd, "@AuthorID", DbType.Int64, cSetEntity.AuthorID);
            db.AddInParameter(cmd, "@OddAuthorID", DbType.Int64, cSetEntity.OddAuthorID);

            try
            {
                db.ExecuteNonQuery(cmd);
                flag = true;
            }
            catch (SqlException sqlEx)
            {
                throw sqlEx;
            }
            return flag;
        }
        /// <summary>
        /// 保存投稿自动分配设置
        /// </summary>
        /// <param name="cSetEntity"></param>
        /// <returns></returns>
        private bool SaveAutoAllotTran(EditorAutoAllotEntity cSetEntity)
        {
            bool flag = false;

            IDbConnection connection = db.GetConnection();
            connection.Open();
            IDbTransaction transaction = connection.BeginTransaction();
            try
            {
                # region 保存投稿自动分配设置

                string sql = @" IF EXISTS(SELECT TOP 1 1 FROM dbo.EditorAutoAllot e WITH(NOLOCK) WHERE e.JournalID=@JournalID)
                            BEGIN
                                UPDATE TOP(1) dbo.EditorAutoAllot SET AllotPattern=@AllotPattern,OddAuthorID=@OddAuthorID,AuthorID=@OddAuthorID WHERE JournalID=@JournalID
                            END
                            ELSE
                            BEGIN
                                INSERT INTO dbo.EditorAutoAllot(JournalID,AllotPattern,AuthorID,OddAuthorID) VALUES(@JournalID,@AllotPattern,@AuthorID,@OddAuthorID)
                            END";
                DbCommand cmd = db.GetSqlStringCommand(sql);

                db.AddInParameter(cmd, "@JournalID", DbType.Int64, cSetEntity.JournalID);
                db.AddInParameter(cmd, "@AllotPattern", DbType.Byte, cSetEntity.AllotPattern);
                db.AddInParameter(cmd, "@AuthorID", DbType.Int64, cSetEntity.AuthorID);
                db.AddInParameter(cmd, "@OddAuthorID", DbType.Int64, cSetEntity.OddAuthorID);

                db.ExecuteNonQuery(cmd, (DbTransaction)transaction);

                # endregion

                # region 保存学科分配匹配设置

                List<SubjectAuthorMapEntity> listSubjectInsertMap = new List<SubjectAuthorMapEntity>();
                List<SubjectAuthorMapEntity> listSubjectUpdateMap = new List<SubjectAuthorMapEntity>();
                foreach (SubjectAuthorMapEntity item in cSetEntity.SubjectAuthorMap)
                {
                    bool isexists = CheckSubjectMapIsExists(item);
                    if (isexists)
                    {
                        listSubjectUpdateMap.Add(item);
                    }
                    else
                    {
                        listSubjectInsertMap.Add(item);
                    }
                }

                # region insert

                if (listSubjectInsertMap.Count > 0)
                {
                    StringBuilder sbSaveSubjectSql = new StringBuilder("");
                    sbSaveSubjectSql.Append(" INSERT INTO SubjectAuthorMap(JournalID,SubjectCategoryID,AuthorID) ");
                    sbSaveSubjectSql.Append(" VALUES ");

                    int i = 1;
                    foreach (SubjectAuthorMapEntity item in listSubjectInsertMap)
                    {
                        sbSaveSubjectSql.Append(" (@JournalID").Append(i).Append(",@SubjectCategoryID").Append(i).Append(",@AuthorID").Append(i).Append("),");
                        i++;
                    }
                    sbSaveSubjectSql.Remove(sbSaveSubjectSql.Length - 1, 1);// 移除掉最后一个,
                    i = 1;
                    DbCommand cmdSaveSubject = db.GetSqlStringCommand(sbSaveSubjectSql.ToString());
                    foreach (SubjectAuthorMapEntity item in listSubjectInsertMap)
                    {
                        db.AddInParameter(cmdSaveSubject, "@JournalID" + i.ToString(), DbType.Int64, item.JournalID);
                        db.AddInParameter(cmdSaveSubject, "@SubjectCategoryID" + i.ToString(), DbType.Int32, item.SubjectCategoryID);
                        db.AddInParameter(cmdSaveSubject, "@AuthorID" + i.ToString(), DbType.Int64, item.AuthorID);
                        i++;
                    }
                    db.ExecuteNonQuery(cmdSaveSubject, (DbTransaction)transaction);
                }

                # endregion

                # region update

                if (listSubjectUpdateMap.Count > 0)
                {
                    StringBuilder sbUpdateSubjectSql = new StringBuilder("");

                    int i = 1;
                    foreach (SubjectAuthorMapEntity item in listSubjectUpdateMap)
                    {
                        sbUpdateSubjectSql.Append("UPDATE dbo.SubjectAuthorMap SET AuthorID=@AuthorID").Append(i).Append(" WHERE JournalID=@JournalID").Append(i).Append(" AND SubjectCategoryID=@SubjectCategoryID").Append(i).Append(";");
                        i++;
                    }
                    i = 1;
                    DbCommand cmdUpdateSubject = db.GetSqlStringCommand(sbUpdateSubjectSql.ToString());
                    foreach (SubjectAuthorMapEntity item in listSubjectUpdateMap)
                    {
                        db.AddInParameter(cmdUpdateSubject, "@JournalID" + i.ToString(), DbType.Int64, item.JournalID);
                        db.AddInParameter(cmdUpdateSubject, "@SubjectCategoryID" + i.ToString(), DbType.Int32, item.SubjectCategoryID);
                        db.AddInParameter(cmdUpdateSubject, "@AuthorID" + i.ToString(), DbType.Int64, item.AuthorID);
                        i++;
                    }
                    db.ExecuteNonQuery(cmdUpdateSubject, (DbTransaction)transaction);
                }

                # endregion

                # endregion

                transaction.Commit();
                flag = true;
            }
 /// <summary>
 /// 更新投稿自动配置
 /// </summary>
 /// <param name="cSetEntity"></param>
 /// <returns></returns>
 public bool SetAutoAllot(EditorAutoAllotEntity cSetEntity)
 {
     bool flag = false;
     if (cSetEntity.SubjectAuthorMap != null && cSetEntity.SubjectAuthorMap.Count > 0)
     {
         flag = SaveAutoAllotTran(cSetEntity);
     }
     else
     {
         flag = SaveAutoAllot(cSetEntity);
     }
     return flag;
 }
 public EditorAutoAllotEntity MakeEditorAutoAllot(IDataReader dr)
 {
     EditorAutoAllotEntity editorAutoAllotEntity = null;
     if (dr.Read())
     {
         editorAutoAllotEntity = new EditorAutoAllotEntity();
         editorAutoAllotEntity.PKID = (Int64)dr["PKID"];
         editorAutoAllotEntity.JournalID = (Int64)dr["JournalID"];
         editorAutoAllotEntity.AllotPattern = (Byte)dr["AllotPattern"];
         editorAutoAllotEntity.AuthorID = (Int64)dr["AuthorID"];
         editorAutoAllotEntity.OddAuthorID = (Int64)dr["OddAuthorID"];
         editorAutoAllotEntity.AddDate = (DateTime)dr["AddDate"];
     }
     return editorAutoAllotEntity;
 }
Пример #7
0
 /// <summary>
 /// 更新投稿自动配置
 /// </summary>
 /// <param name="cSetEntity"></param>
 /// <returns></returns>
 public bool SetAutoAllot(EditorAutoAllotEntity cSetEntity)
 {
     return EditorAutoAllotBusProvider.SetAutoAllot(cSetEntity);
 }
        public EditorAutoAllotEntity GetContributeAutoAllotInfo(EditorAutoAllotQuery query)
        {
            try
            {
                IEditorAutoAllotService cSetService = ServiceContainer.Instance.Container.Resolve<IEditorAutoAllotService>();
                EditorAutoAllotEntity cSetEntity = cSetService.GetEditorAutoAllot(query);
                if (cSetEntity == null)
                {
                    cSetEntity = new EditorAutoAllotEntity();
                    cSetEntity.SubjectAuthorMap = new List<SubjectAuthorMapEntity>();
                }
                else
                {
                    if (cSetEntity.SubjectAuthorMap == null)
                    {
                        cSetEntity.SubjectAuthorMap = new List<SubjectAuthorMapEntity>();
                    }
                }
                if (cSetEntity.SubjectAuthorMap.Count == 0)
                {
                    # region 获取学科分类

                    IDictValueService service = ServiceContainer.Instance.Container.Resolve<IDictValueService>();
                    DictValueQuery dictQuery = new DictValueQuery();
                    dictQuery.JournalID = query.JournalID;
                    dictQuery.DictKey = EnumDictKey.SubjectCat.ToString();
                    List<DictValueEntity> listDictValue = service.GetDictValueList(dictQuery);
                    SubjectAuthorMapEntity subjectItem = null;
                    foreach (DictValueEntity item in listDictValue)
                    {
                        subjectItem = new SubjectAuthorMapEntity();
                        subjectItem.SubjectCategoryID = item.ValueID;
                        subjectItem.CategoryName = item.ValueText;
                        subjectItem.AuthorID = 0;
                        cSetEntity.SubjectAuthorMap.Add(subjectItem);
                    }

                    # endregion
                }
                else
                {
                    IDictValueService service = ServiceContainer.Instance.Container.Resolve<IDictValueService>();
                    IDictionary<int, string> dictValues = service.GetDictValueDcit(query.JournalID, EnumDictKey.SubjectCat.ToString());
                    string subjectCategoryName = "";
                    foreach (SubjectAuthorMapEntity item in cSetEntity.SubjectAuthorMap)
                    {
                         dictValues.TryGetValue(item.SubjectCategoryID,out subjectCategoryName);
                         item.CategoryName = subjectCategoryName;
                         subjectCategoryName = "";
                    }
                }
                return cSetEntity;
            }
 /// <summary>
 /// 设置稿件自动分配
 /// </summary>
 /// <param name="cSetEntity"></param>
 /// <returns></returns>
 public ExecResult SetAllowAllot(EditorAutoAllotEntity cSetEntity)
 {
     HttpClientHelper clientHelper = new HttpClientHelper();
     ExecResult execResult = clientHelper.PostAuth<ExecResult, EditorAutoAllotEntity>(GetAPIUrl(APIConstant.CONTRIBUTION_SETALLOWALLOT), cSetEntity);
     return execResult;
 }