zoukankan      html  css  js  c++  java
  • 通用权限管理系统底层的软删除数据的处理方法介绍

    一、单条记录设置软删除:可同时设置记录是否可启用

            /// <summary>
            /// 设置删除标志
            /// </summary>
            /// <param name="id">主键</param>
            /// <param name="changeEnabled">修改有效状态</param>
            /// <param name="recordModifiedUser">记录修改者</param>
            /// <returns>影响行数</returns>
            public virtual int SetDeleted(object id, bool changeEnabled = false, bool recordModifiedUser = false)
            {
                List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
                parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldDeletionStateCode, 1));
                if (changeEnabled)
                {
                    parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldEnabled, 0));
                }
                if (recordModifiedUser && this.UserInfo != null)
                {
                    parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldModifiedUserId, this.UserInfo.Id));
                    //宋彪发现这里的错误 文字与格式字符串错误
                    //parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldModifiedOn, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldModifiedOn, DateTime.Now));
                }
                return this.SetProperty(new KeyValuePair<string, object>(this.PrimaryKey, id), parameters);
            }
            public virtual int SetProperty(KeyValuePair<string, object> whereParameter, List<KeyValuePair<string, object>> parameters)
            {
                List<KeyValuePair<string, object>> whereParameters = new List<KeyValuePair<string, object>>();
                whereParameters.Add(whereParameter);
                return DbLogic.SetProperty(DbHelper, this.CurrentTableName, whereParameters, parameters);
            }

    二、多条记录设置软删除标志:可同时设置记录是否可启用

            /// <summary>
            /// 批量删除标志
            /// </summary>
            /// <param name="ids">主键数组</param>
            /// <param name="enabled">有效</param>
            /// <param name="modifiedUser">修改者</param>
            /// <returns>影响行数</returns>
            public virtual int SetDeleted(object[] ids, bool enabled = false, bool modifiedUser = false)
            {
                List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
                parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldDeletionStateCode, 1));
                if (enabled)
                {
                    parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldEnabled, 0));
                }
                if (modifiedUser && this.UserInfo != null)
                {
                    parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldModifiedUserId, this.UserInfo.Id));
                    parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldModifiedBy, this.UserInfo.RealName));
                    parameters.Add(new KeyValuePair<string, object>(BaseBusinessLogic.FieldModifiedOn, DateTime.Now));
                }
                return this.SetProperty(ids, parameters);
            }
            public virtual int SetProperty(object[] ids, List<KeyValuePair<string, object>> parameters)
            {
                return this.SetProperty(this.PrimaryKey, ids, parameters);
            }
            public virtual int SetProperty(string name, object[] values, List<KeyValuePair<string, object>> parameters)
            {
                int result = 0;
                if (values == null)
                {
                    result += this.SetProperty(new KeyValuePair<string, object>(name, string.Empty), parameters);
                }
                else
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        result += this.SetProperty(new KeyValuePair<string, object>(name, values[i]), parameters);
                    }
                }
                return result;
            }
            public virtual int SetProperty(KeyValuePair<string, object> whereParameter, List<KeyValuePair<string, object>> parameters)
            {
                List<KeyValuePair<string, object>> whereParameters = new List<KeyValuePair<string, object>>();
                whereParameters.Add(whereParameter);
                return DbLogic.SetProperty(DbHelper, this.CurrentTableName, whereParameters, parameters);
            }
  • 相关阅读:
    【学习笔记】第二章 python安全编程基础---python爬虫基础(urllib)
    java Spring boot entity编写
    UI自动化基础
    初级:第五课 Tony and his family? 托尼和他的家人?
    初级:第四课 What do you do? 你是做什么的?
    初级:第三课 My Family 我的家人
    初级:第二课 Nice to Meet You 幸会
    初级:第一课 Self Introduction 自我介绍
    jmeter自定义函数
    Go笔记-结构、类型、常量
  • 原文地址:https://www.cnblogs.com/hnsongbiao/p/4516957.html
Copyright © 2011-2022 走看看