Beispiel #1
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(AdvertisementBoardDto dto)
        {
            AdvertisementBoard model = Mapper.Map <AdvertisementBoard>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new {
                        //这里进行赋值
                        model.Name,
                        model.Tag,
                        model.IsEnable
                    };
                    await dapper.UpdateAsync <AdvertisementBoard>(item, new { model.Id });
                }
            }
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(UserMaterialGroupDto dto)
        {
            UserMaterialGroup model = Mapper.Map <UserMaterialGroup>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new {
                        //这里进行赋值
                        model.Name
                    };
                    await dapper.UpdateAsync <UserMaterialGroup>(item, new { model.Id });
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 手机绑定
        /// </summary>
        public async Task MobileBindAsync(long userId, string mobile)
        {
            using (var _dapper = DapperFactory.Create())
            {
                var entity = await _dapper.QueryOneAsync <User>(new { Id = userId });

                if (entity.Account.Eq(entity.Mobile))
                {
                    var item = new
                    {
                        Account = mobile,
                        Mobile  = mobile
                    };
                    await _dapper.UpdateAsync <User>(item, new { entity.Id });
                }
                else
                {
                    var item = new
                    {
                        Mobile = mobile
                    };
                    await _dapper.UpdateAsync <User>(item, new { entity.Id });
                }
            }
        }
Beispiel #4
0
 public async Task IncreaseRunTimesAsync(long id)
 {
     using (var dapper = DapperFactory.Create())
     {
         //await dapper.ExecuteAsync($"UPDATE {dapper.Dialect.FormatTableName<TimedTask>()} SET {nameof(TimedTask.RunTimes)}={nameof(TimedTask.RunTimes)}+1 WHERE Id=@Id", new { Id = id });
     }
 }
Beispiel #5
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(AppVersionDto dto)
        {
            AppVersion model = Mapper.Map <AppVersion>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new
                    {
                        //这里进行赋值
                        model.Version,
                        model.Content,
                        model.DownLoadUrl,
                    };
                    await dapper.UpdateAsync <AppFeedback>(item, new { model.Id });
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        public override async Task DeleteAsync(params long[] id)
        {
            using (var dapper = DapperFactory.Create())
            {
                foreach (var i in id)
                {
                    //取得信息
                    var item = await dapper.QueryOneAsync <WxUserTag>(new { Id = id });

                    if (item == null)
                    {
                        continue;
                    }

                    //远程删除
                    //取得AccessToken
                    var token = await wxAccountService.GetAccessToken(item.AccountId);

                    var rsp = await wcUserTool.DeleteUserTag(token, item.TagId);

                    if (rsp.ErrCode != 0)
                    {
                        throw new KuDataNotFoundException(rsp.ToString());
                    }
                    await dapper.DeleteAsync <WxUserTag>(new { Id = id });
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// 获取微信AccessToken
        /// </summary>
        /// <param name="id">公众号ID</param>
        /// <returns></returns>
        public async Task <WcAccessToken> GetAccessToken(long id)
        {
            //取得公众号信息
            using (var dapper = DapperFactory.Create())
            {
                var account = await dapper.QueryOneAsync <WxAccount>(new { Id = id });

                if (account == null)
                {
                    throw new KuDataNotFoundException("无法取得公众号数据!");
                }
                if (account.AppId.IsNullOrEmpty() || account.AppSecret.IsNullOrEmpty())
                {
                    throw new KuDataNotFoundException("公众号未设置AppId或AppSecret!");
                }

                var token = await wcAccessTokenTool.GetAsync(account.AppId, account.AppSecret);

                if (token == null || token.Data == null)
                {
                    throw new KuDataNotFoundException("无法取得微信AccessToken,请检查AppId和AppSecret设置是否正确!");
                }
                return(token.Data);
            }
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(ProductUnitDto dto)
        {
            ProductUnit model = Mapper.Map <ProductUnit>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new {
                        //这里进行赋值
                        model.Name
                    };
                    await dapper.UpdateAsync <ProductUnit>(item, new { model.Id });
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(RoleDto dto)
        {
            Role model = Mapper.Map <Role>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new
                    {
                        //这里进行赋值
                        model.Name,
                        model.NameEn,
                        model.IsEnable,
                        model.Remarks
                    };
                    await dapper.UpdateAsync <Role>(item, new { model.Id });
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(TimedTaskDto dto)
        {
            TimedTask model = Mapper.Map <TimedTask>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                model.Status     = Domain.Enum.System.EmTimedTaskStatus.Disable;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new {
                        //这里进行赋值
                        model.Group,
                        model.Name,
                        model.AssemblyName,
                        model.TypeName,
                        model.Cron,
                        model.ValidStartTime,
                        model.ValidEndTime
                    };
                    await dapper.UpdateAsync <TimedTask>(item, new { model.Id });
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// 从缓存获取栏目列表
        /// </summary>
        /// <returns></returns>
        public async Task <List <ColumnDto> > GetListFromCacheAsync()
        {
            if (await _cache.ExistsAsync(CacheKeyDefinition.ContentColumnList))
            {
                return(await _cache.GetAsync <List <ColumnDto> >(CacheKeyDefinition.ContentColumnList));
            }

            using (var dapper = DapperFactory.Create())
            {
                var list = (await dapper.QueryListAsync <Column>(where : null, order: null)).ToList();
                foreach (var item in list)
                {
                    item.Subs = new List <Column>();
                }
                foreach (var item in list)
                {
                    if (item.ParentId.HasValue)
                    {
                        var p = list.FirstOrDefault(x => x.Id == item.ParentId.Value);
                        if (p != null)
                        {
                            p.Subs.Add(item);
                        }
                    }
                }

                var data = Mapper.Map <List <ColumnDto> >(list);
                await _cache.SetAsync(CacheKeyDefinition.ContentColumnList, data);

                return(data);
            }
        }
Beispiel #12
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(ColumnDto dto)
        {
            Column model = Mapper.Map <Column>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new
                    {
                        model.Name,
                        model.Title,
                        model.OrderIndex,
                        model.Tag
                    };
                    await dapper.UpdateAsync <Column>(item, new { model.Id });
                }
            }

            //清除缓存
            await _cache.RemoveAsync(CacheKeyDefinition.ContentColumnList);
        }
Beispiel #13
0
        /// <summary>
        /// 修改密码
        /// </summary>
        public async Task ChangePasswordAsync(long userId, string currentPwd, string newPwd)
        {
            if (currentPwd.IsNullOrEmpty())
            {
                //当前密码不能为空
                throw new KuArgNullException("当前密码不能为空!");
            }
            if (newPwd.IsNullOrEmpty())
            {
                //新密码不能为空
                throw new KuArgNullException("新密码不能为空!");
            }
            using (var _dapper = DapperFactory.Create())
            {
                var item = await _dapper.QueryOneAsync <User>(new { Id = userId });

                if (item == null)
                {
                    throw new KuDataNotFoundException("无法取得用户数据!");
                }

                if (!item.CheckPassword(currentPwd))
                {
                    throw new KuArgNullException("当前密码出错!");
                }

                item.Password = newPwd;
                item.EncryptPassword();

                await _dapper.UpdateAsync <User>(new { item.Password }, new { Id = userId });
            }
        }
Beispiel #14
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(AppDto dto)
        {
            App model = Mapper.Map <App>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.AppKey     = CryptHelper.EncryptMD5Short(model.Id.ToString());
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new
                    {
                        //这里进行赋值
                        model.Type,
                        model.Name,
                        model.Intro,
                        model.IconData,
                        model.DownloadUrl,
                    };
                    await dapper.UpdateAsync <App>(item, new { model.Id });
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(UserPointRecordDto dto)
        {
            UserPointRecord model = Mapper.Map <UserPointRecord>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new {
                        //TODO:这里进行赋值
                    };
                    await dapper.UpdateAsync <UserPointRecord>(item, new { model.Id });
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// 保存备注
        /// </summary>
        public async Task SaveRemarkAsync(WxUserDto dto)
        {
            using (var dapper = DapperFactory.Create())
            {
                var item = await dapper.QueryOneAsync <WxUser>(new { Id = dto.Id });

                if (item == null)
                {
                    throw new KuDataNotFoundException("无法取得微信用户数据!");
                }
                item.Remark = dto.Remark;

                //远程更新备注
                //取得微信AccessToken
                var token = await _wxAccountService.GetAccessToken(item.AccountId);

                var rsp = await wcUserTool.UpdateUserRemark(token, item.OpenId, item.Remark);

                if (rsp.ErrCode != 0)
                {
                    throw new KuArgNullException(rsp.ToString());
                }

                await dapper.UpdateAsync <WxUser>(new { dto.Remark }, new { dto.Id });
            }
        }
Beispiel #17
0
 public async Task UpdateTaskStatusAsync(long id, dynamic data)
 {
     using (var dapper = DapperFactory.Create())
     {
         await dapper.UpdateAsync <TimedTask>(data, new { Id = id });
     }
 }
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(PageViewRecordDto dto)
        {
            PageViewRecord model = Mapper.Map <PageViewRecord>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id = ID.NewID();
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new {
                        //这里进行赋值
                    };
                    await dapper.UpdateAsync <PageViewRecord>(item, new { model.Id });
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(MaskWordDto dto)
        {
            MaskWord model = Mapper.Map <MaskWord>(dto);

            model.Tag = model.Tag.Replace(",", ",");
            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.MatchCount = 0;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new {
                        //这里进行赋值
                        model.Word,
                        model.Level,
                        model.Tag
                    };
                    await dapper.UpdateAsync <MaskWord>(item, new { model.Id });
                }
            }
        }
Beispiel #20
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(SmsAccountDto dto)
        {
            SmsAccount model = Mapper.Map <SmsAccount>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new
                    {
                        model.Name,
                        model.ParameterConfig,
                        model.IsEnable,
                        model.Remarks,
                        model.Type
                    };
                    await dapper.UpdateAsync <SmsAccount>(item, new { model.Id });
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(ColumnDto dto)
        {
            Column model = Mapper.Map <Column>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;
                using (var dapper = DapperFactory.Create())
                {
                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new
                    {
                        model.Name,
                        model.Title,
                        model.OrderIndex
                    };
                    await dapper.UpdateAsync <Column>(item, new { model.Id });
                }
            }
        }
Beispiel #22
0
        public async Task <List <MenuDto> > GetMenuTreeAsync()
        {
            using (var dapper = DapperFactory.Create())
            {
                var list = await dapper.QueryListAsync <Menu>(where : null, order : null);

                foreach (var item in list)
                {
                    item.SubMenus = new List <Menu>();
                }
                foreach (var item in list)
                {
                    if (item.ParentId.HasValue)
                    {
                        var p = list.FirstOrDefault(x => x.Id == item.ParentId.Value);
                        if (p != null)
                        {
                            p.SubMenus.Add(item);
                        }
                    }
                }

                return(Mapper.Map <List <MenuDto> >(list.Where(x => x.ParentId == null).OrderBy(x => x.OrderIndex)));
            }
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(UserAddressDto dto)
        {
            UserAddress model = Mapper.Map <UserAddress>(dto);

            if (model.Id == 0)
            {
                //新增
                model.Id         = ID.NewID();
                model.CreateTime = DateTime.Now;
                model.IsDeleted  = false;

                using (var dapper = DapperFactory.Create())
                {
                    var user = await dapper.QueryOneAsync <User>(new { Id = model.UserId });

                    if (user == null)
                    {
                        throw new KuDataNotFoundException("无法取得用户信息!");
                    }

                    if (model.Default)
                    {
                        //更新其他地址为非默认地址
                        await dapper.UpdateAsync <UserAddress>(new { Default = false }, new { UserId = model.UserId, Default = true });
                    }

                    await dapper.InsertAsync(model);
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    if (model.Default)
                    {
                        //更新其他地址为非默认地址
                        await dapper.UpdateAsync <UserAddress>(new { Default = false }, new { UserId = model.UserId, Default = true });
                    }

                    var item = new {
                        //这里进行赋值
                        model.Consignee,
                        model.Mobile,
                        model.Province,
                        model.ProvinceCode,
                        model.City,
                        model.CityCode,
                        model.Region,
                        model.RegionCode,
                        model.Street,
                        model.StreetCode,
                        model.Address,
                        model.Default
                    };
                    await dapper.UpdateAsync <UserAddress>(item, new { model.Id });
                }
            }
        }
Beispiel #24
0
        public async Task AddAsync(string mobile, string templetTag, dynamic data)
        {
            if (string.IsNullOrEmpty(mobile))
            {
                throw new KuArgNullException("未设置手机号!");
            }
            if (string.IsNullOrEmpty(templetTag))
            {
                throw new KuArgNullException("未设置短信模板!");
            }
            Sms sms = new Sms
            {
                Id         = ID.NewID(),
                CreateTime = DateTime.Now,
                IsDeleted  = false,
                Data       = JsonConvert.SerializeObject(data),
                Mobile     = mobile
            };

            using (var dapper = DapperFactory.Create())
            {
                var templet = await dapper.QueryOneAsync <SmsTemplet>(new { Tag = templetTag, IsDeleted = false, IsEnable = true });

                if (templet == null)
                {
                    throw new KuDataNotFoundException("无法取得短信模板数据!");
                }
                var content = templet.Templet;
                if (data != null)
                {
                    foreach (var item in JsonConvert.DeserializeObject <Dictionary <string, string> >(sms.Data))
                    {
                        content = content.Replace("${" + item.Key + "}", item.Value);
                    }
                }
                sms.SmsTempletId = templet.Id;
                sms.Content      = content + $"【{templet.Signature}】";

                //创建队列
                var queue = new SmsQueue
                {
                    Id         = ID.NewID(),
                    CreateTime = DateTime.Now,
                    IsDeleted  = false,
                    Status     = EmSmsQueueStatus.WaitSend,
                    SmsId      = sms.Id,
                    ExpireTime = templet.ExpireMinute == 0 ? DateTime.Now.AddDays(1) : DateTime.Now.AddMinutes(templet.ExpireMinute)
                };

                using (var trans = dapper.BeginTrans())
                {
                    await dapper.InsertAsync(sms);

                    await dapper.InsertAsync(queue);

                    trans.Commit();
                }
            }
        }
Beispiel #25
0
 /// <summary>
 /// 增加点击数
 /// </summary>
 public async Task <bool> IncreaseVisitsAsync(long id, int count = 1)
 {
     using (var dapper = DapperFactory.Create())
     {
         var sql = $"update {dapper.Dialect.FormatTableName<Album>()} set {nameof(Album.Visits)}={nameof(Album.Visits)}+{count} where Id=@Id";
         return((await dapper.ExecuteAsync(sql, new { Id = id })) == 1);
     }
 }
Beispiel #26
0
        public async Task <List <FunctionDto> > GetSubsAsync(long?parentId)
        {
            using (var dapper = DapperFactory.Create())
            {
                var list = await dapper.QueryListAsync <Function>(new { ParentId = parentId }, "CreateTime asc");

                return(Mapper.Map <List <FunctionDto> >(list));
            }
        }
Beispiel #27
0
        /// <summary>
        /// 检查是否收藏
        /// </summary>
        public async Task <bool> HasUserCollectedAsync(long id, long userId)
        {
            using (var dapper = DapperFactory.Create())
            {
                var count = await dapper.QueryCountAsync <ArticleUserEvent>(new { ArticleId = id, UserId = userId, Event = EmArticleUserEvent.Collect, IsCancel = false, IsDeleted = false });

                return(count > 0);
            }
        }
Beispiel #28
0
        public async Task <List <MenuDto> > GetSubsAsync(long?parentId)
        {
            using (var dapper = DapperFactory.Create())
            {
                var list = await dapper.QueryListAsync <Menu>(new { ParentId = parentId }, new { OrderIndex = "asc", CreateTime = "asc" });

                return(Mapper.Map <List <MenuDto> >(list));
            }
        }
Beispiel #29
0
        /// <summary>
        /// 分页查询数据
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="size">条数</param>
        /// <param name="where">查询条件</param>
        /// <param name="sort">排序</param>
        /// <returns>count:条数;items:分页数据</returns>
        public override async Task <(int count, List <AdvertisementDto> items)> GetListAsync(int page, int size, AdvertisementSearch search, dynamic sort)
        {
            using (var dapper = DapperFactory.Create())
            {
                var builder = new QueryBuilder().Select <Advertisement>().From <Advertisement>("m").Where(search).Sort(sort as object).Limit(page, size);
                var data    = await dapper.QueryPageAsync <Advertisement>(builder);

                return(data.count, Mapper.Map <List <AdvertisementDto> >(data.items));
            }
        }
Beispiel #30
0
        /// <summary>
        /// 保存数据
        /// </summary>
        public async Task SaveAsync(MenuDto dto)
        {
            Menu model = Mapper.Map <Menu>(dto);

            if (model.Id == 0)
            {
                //新增
                using (var dapper = DapperFactory.CreateWithTrans())
                {
                    //取得父功能
                    if (model.ParentId.HasValue)
                    {
                        var pModel = await dapper.QueryOneAsync <Menu>(new { Id = model.ParentId.Value });

                        if (pModel == null)
                        {
                            throw new VinoDataNotFoundException("无法取得父级菜单数据!");
                        }
                        if (!pModel.HasSubMenu)
                        {
                            await dapper.UpdateAsync <Menu>(new { HasSubMenu = true }, new { pModel.Id });
                        }
                    }
                    else
                    {
                        model.ParentId = null;
                    }

                    model.Id         = ID.NewID();
                    model.CreateTime = DateTime.Now;
                    await dapper.InsertAsync(model);

                    dapper.Commit();
                }
            }
            else
            {
                //更新
                using (var dapper = DapperFactory.Create())
                {
                    var item = new
                    {
                        //这里进行赋值
                        model.Name,
                        model.AuthCode,
                        model.IsShow,
                        model.OrderIndex,
                        model.Icon,
                        model.Url,
                        model.Tag
                    };
                    await dapper.UpdateAsync <Menu>(item, new { model.Id });
                }
            }
        }