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)); }
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)); }
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 <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)); }
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)); }
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)); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="pageNo"></param> /// <param name="pageSize"></param> /// <param name="conn"></param> /// <param name="whereEnumerable"></param> /// <param name="param"></param> /// <param name="loadNow"></param> /// <returns></returns> public static Task <PageModel <IEnumerable <T> > > GetPageList <T>(int pageNo, int pageSize, IDbConnection conn, IEnumerable <string> whereEnumerable, object param = null, bool loadNow = true) where T : BaseModel { return(GetPageList <T>(pageNo, pageSize, conn, EntityTools.GetTableName <T>(), whereEnumerable, EntityTools.GetFields <T>(), new[] { SqlCharConst.DefaultOrder }, nameof(T), param, loadNow)); }
/// <summary> /// 保存.表单打印模板 /// </summary> /// <param name="templateVo"></param> /// <param name="templateId"></param> /// <returns></returns> public int SaveFormPrintTemplate(EntityEmrPrintTemplate templateVo, out int templateId) { int affectRows = 0; string Sql = string.Empty; SqlHelper svc = null; templateId = 0; try { svc = new SqlHelper(EnumBiz.onlineDB); List <DacParm> lstPara = new List <DacParm>(); bool isExsit = true; if (templateVo.templateId <= 0) { isExsit = false; templateVo.templateId = svc.GetNextID(EntityTools.GetTableName(templateVo), EntityTools.GetFieldName(templateVo, EntityEmrPrintTemplate.Columns.templateId)); } lstPara.Add(svc.GetInsertParm(templateVo)); if (templateVo.templateId > 0) { using (TransactionScope scope = svc.TransactionScope) { if (DelFormPrintTemplate((int)templateVo.templateId) < 0) { return(-1); } affectRows = svc.Commit(lstPara); scope.Complete(); } } else { affectRows = svc.Commit(lstPara); } templateId = (int)templateVo.templateId; if (templateId > 0 && affectRows <= 0) { affectRows = 1; } } catch (Exception ex) { ExceptionLog.OutPutException(Function.GetExceptionCaption(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message)); affectRows = -1; } finally { svc = null; } return(affectRows); }
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())); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="conn"></param> /// <param name="tableName"></param> /// <param name="whereList"></param> /// <param name="fieldList"></param> /// <param name="param"></param> /// <returns></returns> public static async Task <T> GetItem <T>(IDbConnection conn, string tableName, IEnumerable <string> whereList, IEnumerable <string> fieldList, object param = null) where T : BaseModel { var whereSql = GetWhereSql(whereList); var sql = $@" {SqlCharConst.SELECT} {string.Join(",", fieldList)} {SqlCharConst.FROM} {EntityTools.GetTableName<T>()} {whereSql}"; Logger.Debug($"{nameof(GetItem)}:{sql}"); return(await conn.QueryFirstOrDefaultAsync <T>(sql, param)); }
public async Task <object> TestDb() { using (IDbConnection conn = new MySqlConnection(AppSetting.DbConnMap["Mysql"].ConnStr)) { var param = new UserInfo() { UserName = "******", LoginPwd = "monster" }; var whereList = new List <string>() { $"{nameof(UserInfo.UserName)} = @{nameof(UserInfo.UserName)}", $"{nameof(UserInfo.LoginPwd)} = @{nameof(UserInfo.LoginPwd)}" }; //根据用户唯一标识查找用户信息 var clientUserInfo = await DapperTools.GetItem <UserInfo>(conn, EntityTools.GetTableName <UserInfo>(), whereList, param); return(clientUserInfo); // try // { // // var content = // "<p><span style=\"font-size:30px\"><span style=\"font-family:Impact, serif\">🤣</span></span></p><p><span style=\"font-size:30px\"><span style=\"font-family:Impact, serif\">真逗呢</span></span></p><p><span style=\"font-size:30px\"><span style=\"font-family:Impact, serif\">哈哈哈</span></span></p>"; // var param = new {content}; // // var result = conn.Execute($@"INSERT INTO article_info // ( title, author, category, content,articleType) // // VALUES( '', '', '', @content,0)",param); // return result; // // } // catch (Exception e) // { // return JsonConvert.SerializeObject(e); // } // IEnumerable<ArticleInfo> articleInfos = conn.Query<ArticleInfo>( // $@" //{SqlCharConst.SELECT} {string.Join(",", EntityTools.GetFields<ArticleInfo>())} //{SqlCharConst.FROM} {EntityTools.GetTableName<ArticleInfo>()} //{SqlCharConst.WHERE} {SqlCharConst.DefaultWhere} //"); } }
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)); }
/// <summary> /// 单表修改 /// </summary> /// <param name="conn"></param> /// <param name="whereEnumerable"></param> /// <param name="param">表的映射模型</param> /// <returns></returns> public static async Task <int> SelectiveEdit <T>(IDbConnection conn, IEnumerable <string> whereEnumerable, T param) where T : BaseModel { param.UpdateTime = new DateTime(); var whereSql = GetWhereSql(whereEnumerable); var tableName = EntityTools.GetTableName <T>(); var validProperties = GetSelectiveField(param); var sql = $@" {SqlCharConst.UPDATE} {tableName} {SqlCharConst.SET} {string.Join(",", validProperties.Select(u => $"{u.Name} = @{u.Name}"))} {whereSql} "; Logger.Debug($"{nameof(SelectiveEdit)}:{sql}"); var result = await conn.ExecuteAsync(sql, param); return(result); }
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)); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="conn"></param> /// <param name="param"></param> /// <returns></returns> public static async Task <int> CreateSelectiveItem <T>(IDbConnection conn, T param) where T : BaseModel { var tableName = EntityTools.GetTableName <T>(); var fields = GetSelectiveField(param).Select(u => u.Name); var sql = $@" {SqlCharConst.INSERT} {SqlCharConst.INTO} {tableName} ( {string.Join(",", fields)} ) {SqlCharConst.VALUES} ( {string.Join(",", fields.Select(u => $"@{u}"))} ) "; Logger.Debug($"{nameof(CreateSelectiveItem)}:{sql}"); var result = await conn.ExecuteAsync(sql, param); return(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}>不存在!")); } }
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)); }
/// <summary> /// 保存 /// </summary> /// <param name="vo"></param> /// <param name="rptId"></param> /// <returns></returns> internal int SaveContagion(EntityRptContagion vo, string reqNo, out decimal rptId) { int affectRows = 0; rptId = 0; string Sql = string.Empty; IDataParameter[] parm = null; SqlHelper svc = null; try { List <DacParm> lstParm = new List <DacParm>(); svc = new SqlHelper(EnumBiz.onlineDB); EntityRptContagionData voData = new EntityRptContagionData(); if (vo.rptId <= 0) // new { rptId = svc.GetNextID(EntityTools.GetTableName(vo), EntityTools.GetFieldName(vo, EntityRptContagion.Columns.rptId)); vo.rptId = rptId; lstParm.Add(svc.GetInsertParm(vo)); voData.rptId = rptId; voData.xmlData = vo.xmlData; lstParm.Add(svc.GetInsertParm(voData)); if (!string.IsNullOrEmpty(reqNo)) { Sql = @"update rptContagion set reques_no = ? where rptId = ?"; parm = svc.CreateParm(2); parm[0].Value = reqNo; parm[1].Value = rptId; lstParm.Add(svc.GetDacParm(EnumExecType.ExecSql, Sql, parm)); } } else // edit { lstParm.Add(svc.GetUpdateParm(vo, new List <string>() { EntityRptContagion.Columns.reportTime, EntityRptContagion.Columns.reportOperCode, EntityRptContagion.Columns.reportOperName, EntityRptContagion.Columns.reportId, EntityRptContagion.Columns.registerCode, EntityRptContagion.Columns.patType, EntityRptContagion.Columns.patNo, EntityRptContagion.Columns.patName, EntityRptContagion.Columns.patSex, EntityRptContagion.Columns.birthday, EntityRptContagion.Columns.idCard, EntityRptContagion.Columns.contactAddr, EntityRptContagion.Columns.contactTel, EntityRptContagion.Columns.deptCode, EntityRptContagion.Columns.formId, EntityRptContagion.Columns.operCode, EntityRptContagion.Columns.recordDate, EntityRptContagion.Columns.status }, new List <string>() { EntityRptContagion.Columns.rptId })); voData.rptId = vo.rptId; voData.xmlData = vo.xmlData; lstParm.Add(svc.GetUpdateParm(voData, new List <string>() { EntityRptEventData.Columns.xmlData }, new List <string>() { EntityRptEventData.Columns.rptId })); rptId = vo.rptId; } affectRows = svc.Commit(lstParm); } catch (Exception e) { ExceptionLog.OutPutException(e); affectRows = -1; } finally { svc = null; } return(affectRows); }
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(); }
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)); } }
public async Task ValidateAsync(ResourceOwnerPasswordValidationContext context) { if (true) { //验证失败 context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "invalid custom credential"); } Logger.Debug(JsonConvert.SerializeObject(AppSetting)); UserInfo clientUserInfo = null; IDbConnection conn = new MySqlConnection(AppSetting.DbConnMap["Mysql"].ConnStr); // var param = new UserInfo() // { // UserName = context.UserName, // LoginPwd = context.Password // }; var whereList = new List <string>() { $"{nameof(UserInfo.UserName)} = '{context.UserName}'", $"{nameof(UserInfo.LoginPwd)} = '{context.Password}'" }; //根据用户唯一标识查找用户信息 clientUserInfo = await DapperTools.GetItem <UserInfo>(conn, EntityTools.GetTableName <UserInfo>(), whereList); // clientUserInfo = conn.QueryFirst<UserInfo>( // $"select * from article_info WHERE {nameof(UserInfo.UserName)} = {context.UserName} AND {nameof(UserInfo.LoginPwd)} = {context.Password}"); //此处使用context.UserName, context.Password 用户名和密码来与数据库的数据做校验 if (clientUserInfo != null) { // var user = _users.FindByUsername(context.UserName); //验证通过返回结果 //subjectId 为用户唯一标识 一般为用户id //authenticationMethod 描述自定义授权类型的认证方法 //authTime 授权时间 //claims 需要返回的用户身份信息单元 此处应该根据我们从数据库读取到的用户信息 添加Claims 如果是从数据库中读取角色信息,那么我们应该在此处添加 context.Result = new GrantValidationResult(clientUserInfo.RoleCode, OidcConstants.AuthenticationMethods.Password, _clock.UtcNow.UtcDateTime, new[] { new Claim(JwtClaimTypes.Id, clientUserInfo.Id.ToString()), }); // context.Result = new GrantValidationResult( //// user.SubjectId ?? throw new ArgumentException("Subject ID not set", nameof(user.SubjectId)), //// OidcConstants.AuthenticationMethods.Password, _clock.UtcNow.UtcDateTime, //// user.Claims // ); } else { //验证失败 context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "invalid custom credential"); } return; }
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}>不存在!")); } }
/// <summary> /// 保存.电子申请单 /// </summary> /// <param name="formVo"></param> /// <param name="formId"></param> /// <returns></returns> public int SaveForm(EntityFormDesign formVo, out int formId) { int affectRows = 0; string Sql = string.Empty; SqlHelper svc = null; formId = 0; try { svc = new SqlHelper(EnumBiz.onlineDB); List <DacParm> lstPara = new List <DacParm>(); bool isExsit = true; if (formVo.Formid <= 0) { isExsit = false; formVo.Formid = svc.GetNextID(EntityTools.GetTableName(formVo), EntityTools.GetFieldName(formVo, EntityFormDesign.Columns.Formid)); } lstPara.Add(svc.GetInsertParm(formVo)); if (Function.Int(formVo.Formtype) < 3) { if (isExsit == false) { string tbName = "emrFormRtf" + formVo.Formid.ToString(); // 自动生成 EntityEmrBasicInfo vo = new EntityEmrBasicInfo(); vo.typeId = 1; vo.formId = formVo.Formid; vo.caseName = formVo.Formname; vo.caseCode = formVo.Formid.ToString(); vo.pyCode = SpellCodeHelper.GetPyCode(formVo.Formname); vo.wbCode = SpellCodeHelper.GetWbCode(formVo.Formname); vo.tableName = tbName; vo.attribute = 0; vo.showType = 0; vo.caseStyle = 0; vo.catalogId = 23; // 其他类 vo.fieldXml = EmrTool.GetBasicFieldXml(formVo.Layout); vo.status = 1; lstPara.Add(svc.GetInsertParm(vo)); if (svc.enumDBMS == EnumDBMS.Oracle) { } else { Sql = @"if exists (select 1 from sysobjects where id = object_id('{0}') and type = 'U') drop table {1}"; lstPara.Add(svc.GetDacParm(EnumExecType.ExecSql, string.Format(Sql, tbName, tbName))); Sql = @"create table {0} ( registerid varchar(20) not null, recorddate datetime not null, fieldname varchar(50) not null, rowindex numeric(10,0) not null, tablecode varchar(100) null, contentrtf image null, printrtf image null, isprint numeric(1,0) not null, constraint pk_{0} primary key (registerid, recorddate, fieldname, rowindex) )"; } lstPara.Add(svc.GetDacParm(EnumExecType.ExecSql, string.Format(Sql, tbName, tbName))); } else { EntityEmrBasicInfo vo = new EntityEmrBasicInfo(); vo.formId = formVo.Formid; vo.caseName = formVo.Formname; vo.pyCode = SpellCodeHelper.GetPyCode(formVo.Formname); vo.wbCode = SpellCodeHelper.GetWbCode(formVo.Formname); vo.fieldXml = EmrTool.GetBasicFieldXml(formVo.Layout); DataTable dt = svc.Select(vo, new List <string>() { EntityEmrBasicInfo.Columns.formId }); if (dt != null && dt.Rows.Count > 0) { //lstPara.Add(svc.GetUpdateParm(vo, new List<string>() { EntityEmrBasicInfo.Columns.caseName, EntityEmrBasicInfo.Columns.pyCode, // EntityEmrBasicInfo.Columns.wbCode, EntityEmrBasicInfo.Columns.fieldXml }, // new List<string>() { EntityEmrBasicInfo.Columns.formId })); Sql = @"update emrBasicInfo set caseName = ?, pyCode = ?, wbCode = ?, fieldXml = ? where formId = ?"; IDataParameter[] parms = svc.CreateParm(5); parms[0].Value = vo.caseName; parms[1].Value = vo.pyCode; parms[2].Value = vo.wbCode; parms[3].Value = vo.fieldXml; if (!string.IsNullOrEmpty(vo.fieldXml) && vo.fieldXml.Trim() != null) { parms[3].ParameterName = "xmltype"; } parms[4].Value = vo.formId; lstPara.Add(svc.GetDacParm(EnumExecType.ExecSql, Sql, parms)); } } } if (formVo.Formid > 0) { using (TransactionScope scope = svc.TransactionScope) { if (DelForm((int)formVo.Formid, (int)formVo.Version) < 0) { return(-1); } affectRows = svc.Commit(lstPara); scope.Complete(); } } else { affectRows = svc.Commit(lstPara); } formId = (int)formVo.Formid; if (formId > 0 && affectRows <= 0) { affectRows = 1; } } catch (Exception ex) { ExceptionLog.OutPutException(Function.GetExceptionCaption(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName, System.Reflection.MethodBase.GetCurrentMethod().Name, ex.Message)); affectRows = -1; } finally { svc = null; } return(affectRows); }
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)); }
/// <summary> /// 保存.电子申请单 /// </summary> /// <param name="formVo"></param> /// <param name="formId"></param> /// <returns></returns> public int SaveForm(EntityFormDesign formVo, out int formId) { int affectRows = 0; string Sql = string.Empty; SqlHelper svc = null; formId = 0; try { svc = new SqlHelper(EnumBiz.onlineDB); List <DacParm> lstPara = new List <DacParm>(); bool isExsit = true; if (formVo.Formid <= 0) { isExsit = false; formVo.Formid = svc.GetNextID(EntityTools.GetTableName(formVo), EntityTools.GetFieldName(formVo, EntityFormDesign.Columns.Formid)); } lstPara.Add(svc.GetInsertParm(formVo)); if (isExsit == false) { string tbName = "emrFormRtf" + formVo.Formid.ToString(); // 自动生成 EntityEmrBasicInfo vo = new EntityEmrBasicInfo(); vo.typeId = 1; vo.formId = formVo.Formid; vo.formName = formVo.Formname; vo.caseCode = formVo.Formid.ToString(); vo.pyCode = SpellCodeHelper.GetPyCode(formVo.Formname); vo.wbCode = SpellCodeHelper.GetWbCode(formVo.Formname); vo.tableName = tbName; vo.attribute = 0; vo.showType = 0; vo.caseStyle = 0; vo.catalogId = 23; // 其他类 vo.fieldXml = EmrTool.GetBasicFieldXml(formVo.Layout); vo.status = 1; lstPara.Add(svc.GetInsertParm(vo)); Sql = @"if exists (select 1 from sysobjects where id = object_id('{0}') and type = 'U') drop table {1}"; lstPara.Add(svc.GetDacParm(EnumExecType.ExecSql, string.Format(Sql, tbName, tbName))); Sql = @"create table {0} ( registerid varchar(20) not null, recorddate datetime not null, fieldname varchar(50) not null, rowindex numeric(10,0) not null, tablecode varchar(100) null, contentrtf image null, printrtf image null, isprint numeric(1,0) not null, constraint pk_{0} primary key (registerid, recorddate, fieldname, rowindex) )"; lstPara.Add(svc.GetDacParm(EnumExecType.ExecSql, string.Format(Sql, tbName, tbName))); } else { EntityEmrBasicInfo vo = new EntityEmrBasicInfo(); vo.formId = formVo.Formid; vo.formName = formVo.Formname; vo.pyCode = SpellCodeHelper.GetPyCode(formVo.Formname); vo.wbCode = SpellCodeHelper.GetWbCode(formVo.Formname); vo.fieldXml = EmrTool.GetBasicFieldXml(formVo.Layout); DataTable dt = svc.Select(vo, new List <string>() { EntityEmrBasicInfo.Columns.formId }); if (dt != null && dt.Rows.Count > 0) { lstPara.Add(svc.GetUpdateParm(vo, new List <string>() { EntityEmrBasicInfo.Columns.formName, EntityEmrBasicInfo.Columns.pyCode, EntityEmrBasicInfo.Columns.wbCode, EntityEmrBasicInfo.Columns.fieldXml }, new List <string>() { EntityEmrBasicInfo.Columns.formId })); } } if (formVo.Formid > 0) { using (TransactionScope scope = svc.TransactionScope) { if (DelForm((int)formVo.Formid, (int)formVo.Version) < 0) { return(-1); } affectRows = svc.Commit(lstPara); scope.Complete(); } } else { affectRows = svc.Commit(lstPara); } formId = (int)formVo.Formid; if (formId > 0 && affectRows <= 0) { affectRows = 1; } } catch (Exception e) { ExceptionLog.OutPutException(e); affectRows = -1; } finally { svc = null; } return(affectRows); }
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)); }