Security/Yuebon.Security.Repositories/TaskManagerRepository.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using Yuebon.Commons.DependencyInjection;
using Yuebon.Commons.Log;

namespace Yuebon.Security.Repositories
{
    /// <summary>
    /// 定时任务仓储接口的实现
    /// </summary>
    public class TaskManagerRepository : BaseRepository<TaskManager>, ITaskManagerRepository, IScopedDependency
    {
        public TaskManagerRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {
        }

        /// <summary>
        /// 异步按条件设置数据有效性,将EnabledMark设置为1:有效,0-为无效
        /// 禁用时会将状态更新为暂停
        /// </summary>
        /// <param name="bl">true为有效,false无效</param>
        /// <param name="where">条件</param>
        /// <param name="userId">操作用户</param>
        /// <returns></returns>
        public override  async Task<bool> SetEnabledMarkByWhereAsync(bool bl, string where, long userId)
        {
            if (HasInjectionData(where))
            {
                Log4NetHelper.Info(string.Format("检测出SQL注入的恶意数据, {0}", where));
                throw new Exception("检测出SQL注入的恶意数据");
            }
            if (string.IsNullOrEmpty(where))
            {
                where = "1=1";
            }
            string sql = $"update {tableName} set ";
            if (bl)
            {
                sql += "EnabledMark=1 ";
            }
            else
            {
                sql += "EnabledMark=0 ";
                sql += ",Status=0 ";
            }
            if (userId>0)
            {
                sql += ",LastModifyUserId='" + userId + "'";
            }
            DateTime lastModifyTime = DateTime.Now;
            sql += ",LastModifyTime=@LastModifyTime where " + where;

            var param = new List<Tuple<string, object>>();
            Tuple<string, object> tupel = new Tuple<string, object>(sql, new { @LastModifyTime = lastModifyTime });
            param.Add(tupel);
            Tuple<bool, string> result = await ExecuteTransactionAsync(param);
            return result.Item1;
        }


        /// <summary>
        /// 异步批量软删除信息,将DeleteMark设置为1-删除,0-恢复删除
后面还有 42 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。