public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            var keyDto = acceptParam.AnalyzeParam <KeyReq <long> >();

            if (keyDto == null || keyDto.Key <= 0)
            {
                return(ResultModel.GetParamErrorModel(string.Empty, "参数异常!"));
            }

            var idField = EntityTools.GetField <ArticleInfo>(nameof(ArticleInfo.Id));

            var whereArr = new List <string>
            {
                SqlCharConst.DefaultWhere,
                $"{idField} = {keyDto.Key}"
//        $"Id = @Id"
            };

            var conn = context.GetConnection(appSetting.GetMysqlConn().FlagKey, appSetting.GetMysqlConn().ConnStr);

//      var info = await DapperTools.GetItem<ArticleInfo>(conn, EntityTools.GetTableName<ArticleInfo>(), whereArr, new { Id = keyDto.Key});
            var info = await DapperTools.GetItem <ArticleInfo>(conn, EntityTools.GetTableName <ArticleInfo>(), whereArr);

            if (info == null)
            {
                return(ResultModel.GetParamErrorModel(string.Empty, "此文章不存在或已删除!"));
            }

            return(ResultModel.GetSuccessModel(String.Empty, info));
        }
Exemple #2
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <KeyReq <int> >();

            if (req == null || req.Key <= 0)
            {
                return(ResultModel.GetParamErrorModel());
            }

            var conn = appSetting.GetMysqlConn(context);

            var result = await DapperTools.Edit(conn, EntityTools.GetTableName <AttentionInfo>(), new[]
            {
                $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.AttentionUser))}={req.Key}",
                $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.UserId))}={userId}",
                $"{nameof(BaseModel.ValidFlag)}={(int)ValidFlagMenu.UnUseFul}"
            },
                                                new[]
            {
                $"{nameof(BaseModel.ValidFlag)}=@{nameof(BaseModel.ValidFlag)}",
                $"{nameof(BaseModel.UpdateTime)}=@{nameof(BaseModel.UpdateTime)}",
            },
                                                new
            {
                ValidFlag  = ValidFlagMenu.UnUseFul,
                UpdateTime = DateTime.Now,
            });

            return(ResultModel.GetSuccessModel(result));
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <KeyReq <long> >();

            if (req == null || req.Key <= 0)
            {
                return(ResultModel.GetParamErrorModel());
            }

            var dbConnection = appSetting.GetMysqlConn(context);

            var result = await DapperTools.Edit(dbConnection, EntityTools.GetTableName <ArticleInfo>(), new[]
            {
                $"{EntityTools.GetField<BaseModel>(nameof(BaseModel.Id))} = {req.Key} ",
                $"{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.UserId))} = {userId}",
            }, new[]
            {
                $"{nameof(BaseModel.ValidFlag)} = {((int) ValidFlagMenu.UnUseFul)}",
                $"{nameof(BaseModel.UpdateTime)} = @{nameof(BaseModel.UpdateTime)}"
            }, new
            {
                UpdateTime = DateTime.Now
            });

//      var result = await dbConnection.ExecuteAsync($@"
//{SqlCharConst.UPDATE} {EntityTools.GetTableName<ArticleInfo>()}
//{SqlCharConst.SET} {EntityTools.GetField<BaseModel>(nameof(BaseModel.ValidFlag))} = {((int) ValidFlagMenu.UseFul)}
//{SqlCharConst.WHERE} {EntityTools.GetField<BaseModel>(nameof(BaseModel.Id))} = {req.Key}
//{SqlCharConst.AND} {EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.UserId))} = {userId}
//");

            return(ResultModel.GetSuccessModel(result));
        }
Exemple #4
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <CreateArticleReq>();

            if (req == null)
            {
                return(ResultModel.GetNullErrorModel(string.Empty));
            }

            string msg;

            if ((msg = req.ValidInfo()) != string.Empty)
            {
                return(ResultModel.GetNullErrorModel(string.Empty, msg));
            }

            var createArticleParam = (CreateArticleParam)req;

            createArticleParam.UserId = userId;

            var mysqlConn = appSetting.GetMysqlConn();

            var dbConnection = context.GetConnection(mysqlConn.FlagKey, mysqlConn.ConnStr);

            var result =
                await DapperTools.CreateItem(dbConnection, EntityTools.GetTableName <ArticleInfo>(), createArticleParam);

            return(ResultModel.GetSuccessModel(string.Empty, result));
        }
Exemple #5
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            //解析参数
            var pageModel = acceptParam.AnalyzeParam <PageModel <FilterReq> >();

            if (pageModel == null)
            {
                return(ResultModel.GetNullErrorModel(string.Empty));
            }

            //动态sql
//      StringBuilder whereBuilder = new StringBuilder();
            List <string> whereList = new List <string>();

            if (pageModel.Result.ValidFlag != null && pageModel.Result.ValidFlag >= 0)
            {
//        whereBuilder.Append($@"
//{SqlCharConst.WHERE} {EntityTools.GetField<ArticleTag>(nameof(ArticleTag.ValidFlag))} = {pageModel.Result.ValidFlag}
//");
                whereList.Add($"{EntityTools.GetField<ArticleTag>(nameof(ArticleTag.ValidFlag))} = {pageModel.Result.ValidFlag}");
            }

            //获取连接
            var mysqlConn = appSetting.GetMysqlConn();

            var dbConnection = context.GetConnection(mysqlConn.FlagKey, mysqlConn.ConnStr);

            //采用工具类分页查询
            var pageList = await DapperTools.GetPageList <ArticleTag>(pageModel.PageNo, pageModel.PageSize, dbConnection,
                                                                      whereList);

            //返回结果集
            return(ResultModel.GetSuccessModel(string.Empty, pageList));
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var updateUserDto = acceptParam.AnalyzeParam <UpdateUserReq>();

            if (updateUserDto == null)
            {
                return(ResultModel.GetNullErrorModel());
            }

            var msg = updateUserDto.ValidInfo();

            if (msg != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(msg));
            }

            var dbConnection = appSetting.GetMysqlConn(context);

            var result = await DapperTools.Edit(dbConnection, EntityTools.GetTableName <UserInfo>(), new List <string>()
            {
                $"{nameof(BaseModel.Id)} = {userId}"
            }, null, updateUserDto);

//      var result = await dbConnection.ExecuteAsync($@"
//{SqlCharConst.UPDATE} {EntityTools.GetTableName<UserInfo>()}
//{SqlCharConst.SET} {string.Join(",", updateUserDto.GetType().GetProperties().Select(u => $"{u.Name} = @{u.Name}"))}
//{SqlCharConst.WHERE} {nameof(BaseModel.Id)} = {userId}
//",updateUserDto);

            return(ResultModel.GetSuccessModel(result));
        }
Exemple #7
0
        public async Task <ResultModel> Run(SendMsgReq req, AppSetting appSetting, HttpContext context)
        {
            if (req == null)
            {
                return(ResultModel.GetNullErrorModel());
            }

            var msg = req.ValidInfo();

            if (msg != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(msg));
            }

            var conn = appSetting.GetMysqlConn(context);

            var param = new MsgInfo()
            {
                Content  = req.Content,
                MsgNo    = Guid.NewGuid().ToString(),
                Sender   = req.Sender,
                Receiver = req.Receiver,
                TypeId   = (int)req.MsgType
            };

            var result = await DapperTools.CreateSelectiveItem(conn, param);

            if (result > 0)
            {
                Logger.Debug($"发送消息成功:{param.MsgNo}");
            }

            return(ResultModel.GetSuccessModel(result));
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <KeyReq <int> >();

            if (req == null || req.Key <= 0)
            {
                return(ResultModel.GetParamErrorModel());
            }

            if (userId == req.Key)
            {
                return(ResultModel.GetParamErrorModel("查询人与被关注人相同"));
            }

            var conn = appSetting.GetMysqlConn(context);

            var isExists = await DapperTools.IsExists(conn, EntityTools.GetTableName <AttentionInfo>(),
                                                      new[]
            {
                $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.AttentionUser))} ={req.Key}",
                $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.UserId))} ={userId}",
                $"{nameof(BaseModel.ValidFlag)}={(int) ValidFlagMenu.UseFul}"
            });

            return(ResultModel.GetSuccessModel(isExists));
        }
Exemple #9
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            var dto = acceptParam.AnalyzeParam <UserLoginReq>();

            if (dto == null)
            {
                return(ResultModel.GetNullErrorModel());
            }

            var msg = dto.ValidInfo();

            if (msg != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(msg));
            }

            var whereList = new List <string>()
            {
                $"{nameof(UserLoginReq.UserName)} = @{nameof(UserLoginReq.UserName)}",
                $"{nameof(UserLoginReq.LoginPwd)} = @{nameof(UserLoginReq.LoginPwd)}",
            };

            var userInfo = await DapperTools.GetItem <UserInfo>(appSetting.GetMysqlConn(context), EntityTools.GetTableName <UserInfo>(), whereList, dto);

            var cusRedisHelper = MemoryCache.GetInstance().TryGet <CusRedisHelper>(appSetting.GetRedisConn().FlagKey);

            var token = Guid.NewGuid().ToString().Replace("-", "");

//      cusRedisHelper.StringSetAsync("user_api_token")

            //使用 is4 =-= gg

            throw new NotImplementedException();
        }
Exemple #10
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var item = await DapperTools.GetItem <UserInfo>(appSetting.GetMysqlConn(context), EntityTools.GetTableName <UserInfo>(),
                                                            new List <string>()
            {
                $"id = {userId}"
            });

            return(ResultModel.GetSuccessModel(item));
        }
Exemple #11
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            var mysqlConn = appSetting.GetMysqlConn();

            var dbConnection = context.GetConnection(mysqlConn.FlagKey, mysqlConn.ConnStr);

            IEnumerable <ArticleInfo> articleInfos = await dbConnection.QueryAsync <ArticleInfo>($@"
{SqlCharConst.SELECT} {string.Join(",", EntityTools.GetFields<ArticleInfo>())}
{SqlCharConst.FROM} {EntityTools.GetTableName<ArticleInfo>()}
{SqlCharConst.WHERE} {SqlCharConst.DefaultWhere}
");

            return(ResultModel.GetSuccessModel(string.Empty, articleInfos.ToList()));
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            var whereEnumerable = GetWhereEnumerable(acceptParam, out var page, out var msg);

            if (msg != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(msg));
            }

            var conn = appSetting.GetMysqlConn(context);

            var tableMapper = typeof(CommentInfo).GetCustomAttribute <TableMapperAttribute>();

            var fieldList = GetFieldEnumerable(tableMapper).ToList();

            var orderEnumerable = GetOrderEnumerable(tableMapper);

            #region 查询用户信息

            fieldList.Add($@"
(
  {SqlCharConst.SELECT} {EntityTools.GetField<UserInfo>(nameof(UserInfo.DisplayName))}
  {SqlCharConst.FROM} {EntityTools.GetTableName<UserInfo>()}
  {SqlCharConst.WHERE} {nameof(BaseModel.Id)} = {tableMapper.Alias}.{EntityTools.GetField<CommentInfo>(nameof(CommentInfo.ActionUser))}
)
 {SqlCharConst.AS} {EntityTools.GetField<CommentDto>(nameof(CommentDto.NickName))}
"); //查询用户名

            fieldList.Add($@"
(
  {SqlCharConst.SELECT} {EntityTools.GetField<UserInfo>(nameof(UserInfo.FaceImg))}
  {SqlCharConst.FROM} {EntityTools.GetTableName<UserInfo>()}
  {SqlCharConst.WHERE} {nameof(BaseModel.Id)} = {tableMapper.Alias}.{EntityTools.GetField<CommentInfo>(nameof(CommentInfo.ActionUser))}
)
 {SqlCharConst.AS} {EntityTools.GetField<CommentDto>(nameof(CommentDto.FaceImg))}
"); //查询用户头像

            #endregion

            var pageList = await DapperTools.GetPageList <CommentDto>(page.PageNo, page.PageSize, conn, tableMapper.TableName,
                                                                      whereEnumerable, fieldList, orderEnumerable, tableMapper.Alias, page.Result);

            return(ResultModel.GetSuccessModel(pageList));
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            var req = acceptParam.AnalyzeParam <KeyReq <long> >();

            if (req == null || req.Key <= 0)
            {
                return(ResultModel.GetNullErrorModel());
            }

            var conn = appSetting.GetMysqlConn(context);

            var item = await DapperTools.GetItem <ArticleSingleDto>(conn, EntityTools.GetTableName <ArticleInfo>(), new []
            {
                $"{nameof(BaseModel.Id)} = {req.Key}",
                $"{nameof(BaseModel.ValidFlag)} = {(int)ValidFlagMenu.UseFul}",
            });

            return(ResultModel.GetSuccessModel(item));
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            var createUserInfoDto = acceptParam.AnalyzeParam <CreateUserInfoReq>();

            string msg;

            if (createUserInfoDto == null)
            {
                return(ResultModel.GetNullErrorModel(string.Empty));
            }

            //设置默认显示名为登录名
            createUserInfoDto.DisplayName = createUserInfoDto.UserName;

            if ((msg = createUserInfoDto.ValidInfo()) != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(string.Empty, msg));
            }

            var conn = appSetting.GetMysqlConn(context);

            var userNameField = EntityTools.GetField <UserInfo>(nameof(UserInfo.UserName));

            //查看用户名是否已存在
            var isExists = await DapperTools.IsExists(conn, EntityTools.GetTableName <UserInfo>(), new List <string>()
            {
                $"{userNameField} = @{userNameField}"
            }, new { createUserInfoDto.UserName });

            if (isExists)
            {
                return(ResultModel.GetParamErrorModel(string.Empty, "用户名已存在!"));
            }

//      Predicates.Field<UserInfo>(u => u.Id > 0, Operator.Eq, true);
//      Predicates.Exists<>()

            var result = await DapperTools.CreateItem(conn, EntityTools.GetTableName <UserInfo>(), createUserInfoDto);

            return(ResultModel.GetSuccessModel(string.Empty, result));
        }
Exemple #15
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <EditArticleReq>();

            if (req == null || req.Id <= 0)
            {
                return(ResultModel.GetNullErrorModel(string.Empty));
            }

            string msg;

            if ((msg = req.ValidInfo()) != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(string.Empty, msg));
            }

            var conn = appSetting.GetMysqlConn(context);

            var result = await DapperTools.SelectiveEdit(conn, new[]
            {
                $"{nameof(BaseModel.Id)} = {req.Id}",
                $"{nameof(BaseModel.ValidFlag)} = {(int) ValidFlagMenu.UseFul}",
                $"{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.UserId))}={userId}"
            }, new ArticleInfo()
            {
                Id          = req.Id,
                ArticleType = req.ArticleType,
                Author      = req.Author,
                Category    = string.Join(",", req.Category),
                Content     = req.Content,
                PublishTime = req.PublishTime,
                UpdateTime  = new DateTime(),
                Title       = req.Title,
                Description = req.Description,
                FaceImg     = req.FaceImg,
                Status      = req.Status
            });

            return(ResultModel.GetSuccessModel(result));
        }
Exemple #16
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            var req = acceptParam.AnalyzeParam <KeyReq <long> >();

            if (req == null || req.Key <= 0)
            {
                return(ResultModel.GetParamErrorModel());
            }

            var conn = appSetting.GetMysqlConn(context);

            var pageViewField = EntityTools.GetField <ArticleInfo>(nameof(ArticleInfo.PageView));

            var result = await DapperTools.Edit(conn, EntityTools.GetTableName <ArticleInfo>(), new[]
            {
                $"{nameof(BaseModel.Id)} = {req.Key}"
            }, new []
            {
                $"{pageViewField} = {pageViewField} + 1"
            }, null);

            return(ResultModel.GetSuccessModel(result));
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <SingleActionArticleReq>();

            if (req == null)
            {
                return(ResultModel.GetNullErrorModel());
            }

            string msg;

            if ((msg = req.ValidInfo()) != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(msg));
            }
            if (Enum.TryParse(req.ActionKey, true, out ArticleOptMenu opt))
            {
                var conn = appSetting.GetMysqlConn(context);

                var count = await DapperTools.SelectSingle <int?>(conn, EntityTools.GetTableName <ArticleOptInfo>(),
                                                                  new List <string>()
                {
                    $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int) opt}",
                    $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {req.ArticleId}",
                    $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.ActionUser))} = {userId}",
                    $"{nameof(BaseModel.ValidFlag)}={(int)ValidFlagMenu.UseFul}"
                }, EntityTools.GetField <ArticleOptInfo>(nameof(ArticleOptInfo.Count)));

                count = count ?? 0;

                return(ResultModel.GetSuccessModel(count));
            }
            else
            {
                return(ResultModel.GetDealErrorModel($"操作<{req.ActionKey}>不存在!"));
            }
        }
Exemple #18
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <CreateArticleCommentReq>();

            if (req == null)
            {
                return(ResultModel.GetNullErrorModel());
            }

            var msg = req.ValidInfo();

            if (msg != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(msg));
            }

            var param = (CreateCommentParam)req;

            param.ActionUser = userId;

            var conn = appSetting.GetMysqlConn(context);

            var result = await DapperTools.CreateItem(conn, EntityTools.GetTableName <CommentInfo>(), param);

            if (result > 0)
            {
//        var task = new BaseSendMsgDeal().Run(new SendMsgReq()
//        {
//          Content = "收到一条评论信息,请赶快查看吧~",
//          MsgType = MsgTypeMenu.Comment,
//          Receiver = req.JoinKey,
//          Sender = userId
//        }, appSetting, context);
            }

            return(ResultModel.GetSuccessModel(result));
        }
Exemple #19
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            //解析参数
            var pageModel = acceptParam.AnalyzeParam <PageModel <ArticlePageFilterAuthReq> >();

            if (pageModel == null)
            {
                return(ResultModel.GetNullErrorModel(string.Empty));
            }

            //动态sql
            var whereArr = new List <string>()
            {
                $"{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.ValidFlag))} = {(int) ValidFlagMenu.UseFul}",
                $"{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.UserId))} = {userId}"
            };

            var tableMapper = typeof(ArticleInfo).GetCustomAttribute <TableMapperAttribute>();

            var fields = EntityTools.GetFields <ArticleInfo>().ToList();

            fields.Add($@"
(
  {SqlCharConst.SELECT} {SqlCharConst.COUNT}(0)
	{SqlCharConst.FROM} {EntityTools.GetTableName<CommentInfo>()}
	{SqlCharConst.WHERE} {EntityTools.GetField<CommentInfo>(nameof(CommentInfo.CommentType))} = {(int) CommentTypeMenu.Article}
	{SqlCharConst.AND} {EntityTools.GetField<CommentInfo>(nameof(CommentInfo.JoinKey))} = {tableMapper.Alias}.{nameof(BaseModel.Id)}
  {SqlCharConst.AND} {nameof(BaseModel.ValidFlag)} = {(int) ValidFlagMenu.UseFul}
) {SqlCharConst.AS} {EntityTools.GetField<ArticleInfoDto>(nameof(ArticleInfoDto.CommentCount))}
"); //评论数量

            fields.Add($@"
(
  {SqlCharConst.SELECT} {SqlCharConst.COUNT}(0)
	{SqlCharConst.FROM} {EntityTools.GetTableName<ArticleOptInfo>()}
	{SqlCharConst.WHERE} {EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int) ArticleOptMenu.Like}
	{SqlCharConst.AND} {EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {tableMapper.Alias}.{nameof(BaseModel.Id)}
  {SqlCharConst.AND} {nameof(BaseModel.ValidFlag)} = {(int) ValidFlagMenu.UseFul}
) {SqlCharConst.AS} {EntityTools.GetField<ArticleInfoDto>(nameof(ArticleInfoDto.LikeCount))}
"); //点赞数量

            if (pageModel.Result != null && pageModel.Result.ArticleType > 0)
            {
                if (pageModel.Result.ArticleType > 0)
                {
                    whereArr.Add($@"
{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.ArticleType))} = {pageModel.Result.ArticleType}
");
                }

                if (pageModel.Result.FilterType == 1)
                {
                    whereArr.Add($@"
{SqlCharConst.EXISTS} (

	{SqlCharConst.SELECT} * {SqlCharConst.FROM} {EntityTools.GetTableName<ArticleOptInfo>()}
	{SqlCharConst.WHERE} {EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int) ArticleOptMenu.Collect}
	{SqlCharConst.AND} {nameof(BaseModel.ValidFlag)} = {(int) ValidFlagMenu.UseFul}
	{SqlCharConst.AND} {EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.ActionUser))} = {userId}
	{SqlCharConst.AND} {EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {tableMapper.Alias}.{nameof(BaseModel.Id)}
	
)
");
                }
                else if (pageModel.Result.FilterType == 2)
                {
                    whereArr.Add($"{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.UserId))} = {userId}");
                }
            }


            //获取连接
            var mysqlConn = appSetting.GetMysqlConn();

            var dbConnection = context.GetConnection(mysqlConn.FlagKey, mysqlConn.ConnStr);

            //采用工具类分页查询
            var pageList = await DapperTools.GetPageList <ArticleInfoDto>(pageModel.PageNo, pageModel.PageSize, dbConnection,
                                                                          tableMapper.TableName,
                                                                          whereArr, fields, new[]
            {
                SqlCharConst.DefaultOrder
            }, tableMapper.Alias, pageModel.Result);

            //返回结果集
            return(ResultModel.GetSuccessModel(string.Empty, pageList));
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <AttentionUserReq>();

            if (req == null)
            {
                return(ResultModel.GetNullErrorModel());
            }

            var msg = req.ValidInfo();

            if (msg != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(msg));
            }

            if (req.AttentionUser == userId)
            {
                return(ResultModel.GetParamErrorModel());
            }

            var conn = appSetting.GetMysqlConn(context);

            AttentionInfo oldInfo = await DapperTools.GetItem <AttentionInfo>(conn, EntityTools.GetTableName <AttentionInfo>(),
                                                                              new[]
            {
                $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.AttentionUser))} ={req.AttentionUser}",
                $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.UserId))} ={userId}",
            },
                                                                              new[]
            {
                nameof(BaseModel.Id),
            });

//      var isExists = await DapperTools.IsExists(conn, EntityTools.GetTableName<AttentionInfo>(),
//        new[]
//        {
//          $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.AttentionUser))} ={req.AttentionUser}",
//          $"{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.UserId))} ={userId}",
//        });

            if (oldInfo == null)
            {
                var param = (CreateAttentionParam)req;

                param.UserId = userId;

                var result = await DapperTools.CreateItem(conn, EntityTools.GetTableName <AttentionInfo>(), param);

                return(ResultModel.GetSuccessModel(result));
            }
            else
            {
                var editParam = new
                {
                    UpdateTime = DateTime.Now,
                    ValidFlag  = (int)ValidFlagMenu.UseFul,
                    req.Description,
                    req.GroupKey,
                };

                var setFieldList = new List <string>();

                setFieldList.Add(nameof(BaseModel.UpdateTime));
                setFieldList.Add(nameof(BaseModel.ValidFlag));

                var result = await DapperTools.Edit(conn, EntityTools.GetTableName <AttentionInfo>(), new[]
                {
                    $"{nameof(BaseModel.Id)}={oldInfo.Id}"
                }, null, editParam);

                return(ResultModel.GetSuccessModel(result));
            }
        }
Exemple #21
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <SingleActionArticleReq>();

            if (req == null)
            {
                return(ResultModel.GetNullErrorModel());
            }

            string msg;

            if ((msg = req.ValidInfo()) != string.Empty)
            {
                return(ResultModel.GetParamErrorModel(msg));
            }

            if (Enum.TryParse(req.ActionKey, true, out ArticleOptMenu opt))
            {
                var conn = appSetting.GetMysqlConn(context);

                var info = await DapperTools.GetItem <ArticleOptInfo>(conn, EntityTools.GetTableName <ArticleOptInfo>(),
                                                                      new List <string>()
                {
                    $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int) opt}",
                    $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {req.ArticleId}",
                    $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.ActionUser))} = {userId}",
                }, new[]
                {
                    nameof(BaseModel.Id),
                    nameof(BaseModel.ValidFlag)
                }, null);

                //        var validFlag = await DapperTools.SelectSingle<int?>(conn, EntityTools.GetTableName<ArticleOptInfo>(),
                //          new List<string>()
                //          {
                //            $"{nameof(BaseModel.Id)} = {req.ArticleId}",
                //            $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int) opt}",
                //            $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {req.ArticleId}",
                //          }, nameof(BaseModel.ValidFlag));

                if (info != null)
                {
                    EditValidFlagParam param = new EditValidFlagParam()
                    {
                        Id         = info.Id,
                        UpdateTime = DateTime.Now
                    };
                    if (info.ValidFlag == (int)ValidFlagMenu.UnUseFul)
                    {
                        param.ValidFlag = ValidFlagMenu.UseFul;
                    }
                    else
                    {
                        param.ValidFlag = ValidFlagMenu.UnUseFul;
                    }

                    var result = await DapperTools.Edit(conn, EntityTools.GetTableName <ArticleOptInfo>(), new[]
                    {
                        $"{nameof(BaseModel.Id)} = {info.Id}",
                        $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.ActionUser))} = {userId}",
                    }, null, param);


                    return(ResultModel.GetSuccessModel(null, $"修改成功-{result}"));
                }
                else
                {
                    var param = new CreateArticleOptInfoParam()
                    {
                        ActionKey   = opt.ToString(),
                        Count       = 1,
                        OptionType  = (int)opt,
                        RelationKey = req.ArticleId,
                        ActionUser  = userId
                    };

                    var result = await DapperTools.CreateItem(conn, EntityTools.GetTableName <ArticleOptInfo>(), param);

                    return(ResultModel.GetSuccessModel(null, $"添加成功-{result}"));
                }

//        return ResultModel.GetSuccessModel(validFlag);

//        if (await DapperTools.IsExists(conn, EntityTools.GetTableName<ArticleOptInfo>(), new List<string>()
//        {
//          $"{nameof(BaseModel.Id)} = {req.ArticleId}",
//          $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.OptionType))} = {(int)opt}",
//          $"{EntityTools.GetField<ArticleOptInfo>(nameof(ArticleOptInfo.RelationKey))} = {req.ArticleId}",
//        }))
//        {
//          return ResultModel.GetDealErrorModel("请勿重复操作!");
//        }
//        else
//        {
//
//          var param = new CreateArticleOptInfoParam()
//          {
//            ActionKey = opt.ToString(),
//            Count = 1,
//            OptionType = (int) opt,
//            RelationKey = req.ArticleId
//          };
//
//          var result = await DapperTools.CreateItem(conn, EntityTools.GetTableName<ArticleOptInfo>(), param);
//
//          return ResultModel.GetSuccessModel(result);
//
//        }
            }
            else
            {
                return(ResultModel.GetDealErrorModel($"操作<{req.ActionKey}>不存在!"));
            }
        }
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context)
        {
            //解析参数
            var pageModel = acceptParam.AnalyzeParam <PageModel <ArticlePageFilterReq> >();

            if (pageModel == null)
            {
                return(ResultModel.GetNullErrorModel(string.Empty));
            }

            var publishTimeFieldName = EntityTools.GetField <ArticleInfo>(nameof(ArticleInfo.PublishTime));

            //动态sql
            var whereArr = new List <string>()
            {
                $"{publishTimeFieldName} <= @{publishTimeFieldName}"
            };//只返回已发布的文章

            if (pageModel.Result.ValidFlag != null && pageModel.Result.ValidFlag >= 0)
            {
                whereArr.Add($@"
{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.ValidFlag))} = {pageModel.Result.ValidFlag}
");
            }

            if (pageModel.Result.ArticleType != null && pageModel.Result.ArticleType > 0)
            {
                whereArr.Add($@"
{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.ArticleType))} = {pageModel.Result.ArticleType}
");
            }

//      if (pageModel.Result.FilterType == 1)
//      {
//        whereArr.Add($@"
//{EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.UserId))} = {acceptParam.GetUserId()}
//");
//      }

            //获取连接
            var mysqlConn = appSetting.GetMysqlConn();

            var dbConnection = context.GetConnection(mysqlConn.FlagKey, mysqlConn.ConnStr);

            var param = new ArticleInfo()
            {
                PublishTime = DateTime.Now
            };

            //采用工具类分页查询
            var pageList = await DapperTools.GetPageList <ArticleInfo>(pageModel.PageNo, pageModel.PageSize, dbConnection,
                                                                       whereArr, param);

            //返回结果集
            return(ResultModel.GetSuccessModel(string.Empty, pageList));

//      var count = await dbConnection.QueryFirstAsync<int>($@"
//{SqlCharConst.SELECT} {SqlCharConst.COUNT}(1)
//{SqlCharConst.FROM} {EntityTools.GetTableName<ArticleInfo>()}
//{whereBuilder}
//");
//
//      PageModel<IEnumerable<ArticleInfo>> resultPage = new PageModel<IEnumerable<ArticleInfo>>()
//      {
//        Count = count,
//        PageNo = pageModel.PageNo,
//        PageSize = pageModel.PageSize
//      };
//
//      if ((pageModel.PageNo - 1) * pageModel.PageSize <= count)
//      {
//        IEnumerable<ArticleInfo> articleInfos = await dbConnection.QueryAsync<ArticleInfo>($@"
//{SqlCharConst.SELECT} {string.Join(",", EntityTools.GetFields<ArticleInfo>())}
//{SqlCharConst.FROM} {EntityTools.GetTableName<ArticleInfo>()}
//{whereBuilder}
//
//{SqlCharConst.ORDERBY} {EntityTools.GetField<ArticleInfo>(nameof(ArticleInfo.Id))} {SqlCharConst.DESC}
//
//{SqlCharConst.LIMIT} {(pageModel.PageNo - 1) * pageModel.PageSize},{pageModel.PageSize}
//
//");
//
//        resultPage.Result = articleInfos.ToList();
//      }
//
//      return ResultModel.GetSuccessModel(string.Empty, resultPage);
        }
Exemple #23
0
        public async Task <ResultModel> Run(AcceptParam acceptParam, AppSetting appSetting, HttpContext context, long userId)
        {
            var req = acceptParam.AnalyzeParam <PageModel <AttentionPageFilterReq> >();

            if (req == null || req.PageNo == 0 || req.Result == null)
            {
                return(ResultModel.GetParamErrorModel());
            }

            var conn            = appSetting.GetMysqlConn(context);
            var attentionMapper = typeof(AttentionInfo).GetCustomAttribute <TableMapperAttribute>();
            var userMapper      = typeof(UserInfo).GetCustomAttribute <TableMapperAttribute>();

            var joinRelation = string.Empty;

            var whereList = new List <string>()
            {
                $"{attentionMapper.Alias}.{nameof(BaseModel.ValidFlag)}={(int) ValidFlagMenu.UseFul}"
            };

            if (req.Result.FilterType == 1)
            {
                whereList.Add(
                    $"{attentionMapper.Alias}.{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.AttentionUser))}={userId}");
                joinRelation = $"{attentionMapper.Alias}.userId = {userMapper.Alias}.id";
            }
            else
            {
                whereList.Add(
                    $"{attentionMapper.Alias}.{EntityTools.GetField<AttentionInfo>(nameof(AttentionInfo.UserId))}={userId}");
                joinRelation = $"{attentionMapper.Alias}.attentionUser = {userMapper.Alias}.id";
            }

            var whereSql = DapperTools.GetWhereSql(whereList);

            var selectCountSql = $@"
{SqlCharConst.SELECT} {SqlCharConst.COUNT}(1) 
{SqlCharConst.FROM} {attentionMapper.TableName} {SqlCharConst.AS} {attentionMapper.Alias}
{whereSql}
";

            Logger.Debug(selectCountSql);

            var count = await conn.QueryFirstAsync <int>(selectCountSql);

            var resultPage = new PageModel <IEnumerable <AttentionInfoDto> >()
            {
                Count    = count,
                PageNo   = req.PageNo,
                PageSize = req.PageSize
            };

            if ((req.PageNo - 1) * req.PageSize <= count)
            {
                var fieldList = new List <string>();
                fieldList.AddRange(EntityTools.GetFields <AttentionInfoDto>($"{attentionMapper.Alias}."
                                                                            , null
                                                                            , (propertyInfo => propertyInfo.Name != nameof(AttentionInfoDto.UserInfo))));
                fieldList.AddRange(EntityTools.GetFields <UserInfoDto>($"{userMapper.Alias}."));

                var pageSql = $@"
{SqlCharConst.SELECT} 
	{string.Join(',', fieldList)}

{SqlCharConst.FROM} 
  {attentionMapper.TableName} {SqlCharConst.AS} {attentionMapper.Alias}
	{SqlCharConst.INNER} {SqlCharConst.JOIN} 
    {userMapper.TableName} {SqlCharConst.AS} {userMapper.Alias}
      {SqlCharConst.ON} {joinRelation}

{DapperTools.GetWhereSql(whereList)}

{SqlCharConst.ORDERBY}

  {attentionMapper.Alias}.{nameof(BaseModel.UpdateTime)} {SqlCharConst.DESC},
  {attentionMapper.Alias}.{nameof(BaseModel.CreateTime)} {SqlCharConst.DESC}

{SqlCharConst.LIMIT} {(req.PageNo - 1) * req.PageSize},{req.PageSize}
";

                Logger.Debug(pageSql);

                var info = await conn.QueryAsync <AttentionInfoDto, UserInfoDto, AttentionInfoDto>(pageSql,
                                                                                                   (attention, user) =>
                {
                    attention.UserInfo = user;
                    return(attention);
                }
                                                                                                   //The field we should split and read the second object from (default: "Id")
                                                                                                   //当select中的列出现 不同表的重复列名 需要使用在此配置
                                                                                                   //,splitOn: "Name,BookID"
                                                                                                   );

                resultPage.Result = info.ToList();

//        return ResultModel.GetSuccessModel(info);
            }
            //      var result = await DapperTools.GetPageList<AttentionInfo>(req.PageNo, req.PageSize, conn, whereList);

            //      return ResultModel.GetSuccessModel(result);

            return(ResultModel.GetSuccessModel(resultPage));
        }