public JsonResponse UpdateItem([FromBody] JsonRequest model) { try { UpdateView view = model.Data.DeserialObject <UpdateView>(); if (view == null || view.KID <= 0 || view.Update == null) { return(new JsonResponse { Code = 1, Msg = "参数不合法" }); } SysLoginUser user = UserInfoUtil.UserInfo(model.Token); if (!user.IsAdmin) { return(new JsonResponse { Code = 1, Msg = "暂无操作权限" }); } OpertionUser opt = new OpertionUser(); view.Update = AddBaseInfo <Category>(view.Update, model.Token, false, ref opt); Result res = BlogHelper.Update_Category(view.Update, view.KID, opt); return(FastJson(res, model.Token, res.IsSucceed ? 0 : 1, res.IsSucceed ? "操作成功" : "操作失败")); } catch (Exception ex) { LogHelper.WriteLog(ex, "CategoryController/UpdateItem"); return(new JsonResponse { Code = 1, Msg = "程序错误" + ex.Message }); } }
/// <summary> /// 删除数据,逗号连接多条 /// </summary> /// <param name="kid">主键ID,多个逗号连接</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Delete(string kid, OpertionUser opertionUser) { var deldic = new Dictionary <string, object>(); deldic.Add(nameof(Bloginfo.IsDeleted), 1); var keydic = new Dictionary <string, object>(); if (kid.IndexOf(",") > -1) { keydic.Add(nameof(Bloginfo.KID) + "|i", kid); } else { keydic.Add(nameof(Bloginfo.KID), kid); } var ret = BloginfoRepository.Instance.Update <Bloginfo>(deldic, keydic); DbLog.WriteDbLog(nameof(Bloginfo), "删除记录", kid, null, OperLogType.除, opertionUser); return(new Result() { IsSucceed = ret > 0 }); }
public JsonResponse DeleteItem([FromBody] JsonRequest model) { try { UpdateView view = model.Data.DeserialObject <UpdateView>(); if (view == null || view.KID <= 0) { return(new JsonResponse { Code = 1, Msg = "参数不合法" }); } view.Update = new Dictionary <string, object>(); view.Update.Add(nameof(Sysrole.IsDeleted), 0); OpertionUser opt = new OpertionUser(); view.Update = AddBaseInfo <Sysrole>(view.Update, model.Token, false, ref opt); Result res = BlogHelper.Update_Sysrole(view.Update, view.KID, opt); return(FastJson(res, model.Token, res.IsSucceed ? 0 : 1, res.IsSucceed ? "操作成功" : "操作失败")); } catch (Exception ex) { LogHelper.WriteLog(ex, "AdminRoleController/DeleteItem"); return(new JsonResponse { Code = 1, Msg = "程序错误" + ex.Message }); } }
/// <summary> /// 获取操作者信息 /// </summary> /// <param name="token">The token.</param> /// <returns></returns> public static OpertionUser GetLoginOpt(string token) { OpertionUser opt = null; try { opt = new OpertionUser(); if (string.IsNullOrEmpty(token)) { return(opt); } var type = token.Substring(31, 1).Toint(); var sysuser = BlogHelper.GetSysLoginUserByToken(token); if (type == 1) { opt.UserId = sysuser.Model.KID.ToString(); opt.UserName = sysuser.Model.UserName; opt.UserClientIp = GetIP(); } else if (type == 2) { opt.UserId = sysuser.MemberModel.KID.ToString(); opt.UserName = sysuser.MemberModel.UserName; opt.UserClientIp = GetIP(); } } catch (Exception ex) { } return(opt); }
public JsonResponse StartOrStop([FromBody] JsonRequest model) { try { UpdateView up = model?.Data?.ToString().DeserializeObject <UpdateView>(); if (up == null || up.Update == null || string.IsNullOrEmpty(up.Num)) { return(new JsonResponse { Code = 1, Msg = "参数不合法" }); } var opt = new OpertionUser(); var infodic = AddBaseInfo <Bloginfo>(up.Update, model.Token, false, ref opt); var dicwhere = new Dictionary <string, object>() { { nameof(Bloginfo.BlogNum), up.Num } }; var res1 = BlogHelper.UpdateByWhere_Bloginfo(infodic, dicwhere, opt); Task.Run(() => { CacheHelper.DelCacheItem(ConfigUtil.BlogListCacheKey); CacheHelper.DelCacheItem($"{ConfigUtil.BlogItemCacheKeyPrefix}{up.Num}"); }); return(FastResponse(res1, model.Token, 0, 0, res1.Message)); } catch (Exception ex) { LogHelper.WriteLog(ex, "AdminBlogController/UpdateItemBlog"); return(new JsonResponse { Code = 1, Msg = "程序视乎开小差" + ex.Message }); } }
/// <summary> /// 添加实体 /// </summary> /// <param name="entity">The entity.</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Add(Logintoken entity, OpertionUser opertionUser) { if (entity.Token.IsNull()) { return(new Result() { IsSucceed = false, Message = "Token不允许为空,请重试" }); } try { var ret = new LogintokenRepository(entity.Token).Add <Logintoken>(entity); DbLog.WriteDbLog(nameof(Logintoken), "添加记录", ret, entity.ToJsonString(), null, OperLogType.添加); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); } catch (Exception ex) { FastDev.Log.LogHelper.WriteLog(ex, "LogintokenLogic.Add Entity异常"); return(new Result() { IsSucceed = false, Message = ex.Message }); } }
/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Add(Dictionary <string, object> dicwhere, OpertionUser opertionUser) { var ret = SysmenuRepository.Instance.Add <Sysmenu>(dicwhere); DbLog.WriteDbLog(nameof(Sysmenu), "添加记录", ret, dicwhere.ToJsonString(), opertionUser, OperLogType.添加); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); }
/// <summary> /// Edits the specified dicwhere. /// </summary> /// <param name="dicwhere">修改条件</param> /// <param name="kID">当前数据主键KID</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Update(Dictionary <string, object> dicwhere, int kID, OpertionUser opertionUser) { var ret = SysmenuRepository.Instance.UpdateByKey <Sysmenu>(dicwhere, kID); DbLog.WriteDbLog(nameof(Sysmenu), "修改记录", kID, dicwhere, OperLogType.编辑, opertionUser); return(new Result() { IsSucceed = ret > 0 }); }
/// <summary> /// Deletes the specified kid. /// </summary> /// <param name="dicwhere">删除条件</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result DeleteByWhere(Dictionary <string, object> dicwhere, OpertionUser opertionUser) { var deldic = new Dictionary <string, object>(); deldic.Add(nameof(Bloginfo.IsDeleted), 1); var ret = BloginfoRepository.Instance.Update <Bloginfo>(deldic, dicwhere); DbLog.WriteDbLog(nameof(Bloginfo), "批量删除记录", dicwhere.ToJsonString(), dicwhere, OperLogType.除, opertionUser); return(new Result() { IsSucceed = ret > 0 }); }
/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Add(Dictionary <string, object> dicwhere, OpertionUser opertionUser) { var ret = CommentRepository.Instance.Add <Comment>(dicwhere); DbLog.WriteDbLog(nameof(Comment), "添加记录", ret, dicwhere.ToJsonString(), opertionUser, OperLogType.添加); Task.Run(() => { if (ret > 0) { CommentRepository.UpdateBloginfo(dicwhere[nameof(Comment.BlogNum)].ToString()); } }); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); }
/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Add(Dictionary <string, object> dicwhere, OpertionUser opertionUser) { try { var memid = dicwhere[nameof(ArticlePraise.MemberId)].ToString(); var blognum = dicwhere[nameof(ArticlePraise.BlogNum)].ToString(); var ap = ArticlePraiseLogic.GetModelByWhere(new Dictionary <string, object>() { { nameof(ArticlePraise.MemberId), memid }, { nameof(ArticlePraise.BlogNum), blognum } }); if (ap != null || ap?.KID > 0) { return(new Result() { IsSucceed = false, Message = "该文章你已点赞" }); } var ret = ArticlePraiseRepository.Instance.Add <ArticlePraise>(dicwhere); Task.Run(() => { if (ret > 0) { ArticlePraiseRepository.UpdateBloginfo(blognum); } }); DbLog.WriteDbLog(nameof(ArticlePraise), "添加记录", ret, dicwhere.ToJsonString(), opertionUser, OperLogType.添加); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); } catch (Exception ex) { LogHelper.WriteLog(ex, "ArticlePraiseLogic/add"); return(new Result() { IsSucceed = false, Message = "系统错误" + ex.Message }); } }
public JsonResponse AddItemBlog([FromBody] JsonRequest model) { try { UpdateView up = model?.Data?.ToString().DeserializeObject <UpdateView>(); if (up == null || up.Update == null) { return(new JsonResponse { Code = 1, Msg = "参数不合法" }); } var opt = new OpertionUser(); var content = up.Update[nameof(Blogcontent.Content)].ToString(); var blognum = Guid.NewGuid().ToString().Replace("-", ""); var infodic = AddBaseInfo <Bloginfo>(up.Update, model.Token, true, ref opt); infodic.Add(nameof(Bloginfo.BlogNum), blognum); //var contdic = AddBaseInfo<Blogcontent>(updic, model.Token, true, ref opt); infodic.Add(nameof(Blogcontent.BloginfoNum), blognum); var res1 = BlogHelper.Add_Bloginfo(infodic, opt); //var res2 = BlogHelper.Add_Blogcontent(infodic, opt); if (!res1.IsSucceed) { return(new JsonResponse { Code = 1, Msg = $"添加失败{res1.SerializeObject()};" }); } Task.Run(() => { CacheHelper.DelCacheItem(ConfigUtil.BlogListCacheKey); CacheHelper.DelCacheItem($"{ConfigUtil.BlogItemCacheKeyPrefix}{up.Num}"); }); return(FastResponse("", model.Token, 0, 0, "添加成功")); } catch (Exception ex) { LogHelper.WriteLog(ex, "AdminBlogController/AddItemBlog"); return(new JsonResponse { Code = 1, Msg = "程序视乎开小差" + ex.Message }); } }
/// <summary> /// Edits the specified dicwhere. /// </summary> /// <param name="dicwhere">修改条件</param> /// <param name="kID">当前数据主键KID</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Update(Dictionary <string, object> dicwhere, int kID, OpertionUser opertionUser) { var ret = ArticlePraiseRepository.Instance.UpdateByKey <ArticlePraise>(dicwhere, kID); Task.Run(() => { if (ret > 0) { var model = ArticlePraiseRepository.Instance.GetEntityByKey <ArticlePraise>(kID); ArticlePraiseRepository.UpdateBloginfo(model.BlogNum); } }); DbLog.WriteDbLog(nameof(ArticlePraise), "修改记录", kID, dicwhere, OperLogType.编辑, opertionUser); return(new Result() { IsSucceed = ret > 0 }); }
/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Add(Dictionary <string, object> dicwhere, OpertionUser opertionUser) { try { var ret = AccessRepository.Instance.Add <Access>(dicwhere); DbLog.WriteDbLog(nameof(Access), "添加记录", ret, dicwhere.ToJsonString(), opertionUser, OperLogType.添加); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); } catch (Exception ex) { LogHelper.WriteLog(ex, "AccessLogic/add"); return(new Result() { IsSucceed = false, Message = "系统错误" + ex.Message }); } }
/// <summary> /// Edits the specified dicwhere. /// </summary> /// <param name="dicwhere">修改条件</param> /// <param name="kID">当前数据主键KID</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Update(Dictionary <string, object> dicwhere, int kID, OpertionUser opertionUser) { var res = new Result() { IsSucceed = false }; var ret = BloginfoRepository.Instance.UpdateByKey <Bloginfo>(dicwhere, kID); if (ret > 0) { var cont = ""; if (dicwhere.ContainsKey(nameof(Blogcontent.Content))) { cont = dicwhere[nameof(Blogcontent.Content)].ToString(); } var t = BlogcontentRepository.Instance.UpdateByKey <Blogcontent>(dicwhere, kID); res.IsSucceed = t > 0; } DbLog.WriteDbLog(nameof(Bloginfo), "修改记录", kID, dicwhere, OperLogType.编辑, opertionUser); return(res); }
/// <summary> /// 根据字典添加多条数据 /// </summary> /// <param name="diclst">The diclst.</param> /// <param name="opertionUser">操作者信息</param> /// <returns></returns> public static Result Adds(List <Dictionary <string, object> > diclst, OpertionUser opertionUser) { try { var ret = BloginfoRepository.Instance.Adds <Bloginfo>(diclst); DbLog.WriteDbLog <List <Dictionary <string, object> > >(nameof(Bloginfo), "添加记录", ret, diclst, opertionUser, OperLogType.添加); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); } catch (Exception ex) { FastDev.Log.LogHelper.WriteLog(ex, "BloginfoLogic.Adds diclst异常"); return(new Result() { IsSucceed = false, Message = ex.Message }); } }
/// <summary> /// 添加实体 /// </summary> /// <param name="entity">The entity.</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Add(Bloginfo entity, OpertionUser opertionUser) { try { var ret = BloginfoRepository.Instance.Add <Bloginfo>(entity); DbLog.WriteDbLog(nameof(Bloginfo), "添加记录", ret, entity.ToJsonString(), opertionUser, OperLogType.添加); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); } catch (Exception ex) { FastDev.Log.LogHelper.WriteLog(ex, "BloginfoLogic.Add Entity异常"); return(new Result() { IsSucceed = false, Message = ex.Message }); } }
/// <summary> /// 批量添加实体 /// </summary> /// <param name="entity">The entity.</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Adds(List <Sysmenu> entity, OpertionUser opertionUser) { try { var ret = SysmenuRepository.Instance.Adds <Sysmenu>(entity); DbLog.WriteDbLog <List <Sysmenu> >(nameof(Sysmenu), "添加记录", ret, entity, opertionUser, OperLogType.添加); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); } catch (Exception ex) { FastDev.Log.LogHelper.WriteLog(ex, "SysmenuLogic.Add Entity异常"); return(new Result() { IsSucceed = false, Message = ex.Message }); } }
/// <summary> /// Adds the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result Add(Dictionary <string, object> dicwhere, OpertionUser opertionUser) { var res = new Result() { IsSucceed = false }; if (!dicwhere.ContainsKey(nameof(Blogcontent.Content))) { return(new Result { IsSucceed = false }); } var ret = BloginfoRepository.Instance.Add <Bloginfo>(dicwhere); if (ret > 0) { var content = BlogcontentRepository.Instance.Add <Blogcontent>(new Dictionary <string, object>() { { nameof(Blogcontent.BloginfoNum), dicwhere[nameof(Blogcontent.BloginfoNum)] }, { nameof(Blogcontent.Content), dicwhere[nameof(Blogcontent.Content)] }, { nameof(Blogcontent.CreateUserId), dicwhere[nameof(Blogcontent.CreateUserId)] }, { nameof(Blogcontent.CreateUserName), dicwhere[nameof(Blogcontent.CreateUserName)] } }); if (content <= 0) { return(new Result { IsSucceed = false, Message = "部分添加失败" }); } res.IsSucceed = true; } DbLog.WriteDbLog(nameof(Bloginfo), "添加记录", ret, dicwhere.ToJsonString(), opertionUser, OperLogType.添加); return(res); }
/// <summary> /// 修改次数 /// </summary> /// <param name="fields">需要修改的字段</param> /// <param name="addNums">次数 负数表示减少 正数表示增加</param> /// <param name="whereKey">字典条件</param> /// <param name="opertionUser">操作者信息</param> /// <returns></returns> public static Result UpdateNums(string fields, int addNums, Dictionary <string, object> whereKey, OpertionUser opertionUser) { var ret = BloginfoRepository.Instance.UpdateNums <Bloginfo>(fields, addNums, whereKey); DbLog.WriteDbLog(nameof(Bloginfo), "修改记录", whereKey.ToJsonString(), whereKey, OperLogType.编辑, opertionUser); return(new Result() { IsSucceed = ret > 0, Message = ret.ToString() }); }
/// <summary> /// Edits the specified dicwhere. /// </summary> /// <param name="valuedata">修改的值</param> /// <param name="dicwhere">修改条件</param> /// <param name="opertionUser">操作者信息</param> /// <returns>Result.</returns> public static Result UpdateByWhere(Dictionary <string, object> valuedata, Dictionary <string, object> dicwhere, OpertionUser opertionUser) { var ret = BloginfoRepository.Instance.Update <Bloginfo>(valuedata, dicwhere); DbLog.WriteDbLog(nameof(Bloginfo), "批量修改记录", valuedata.ToJsonString(), valuedata, OperLogType.编辑, opertionUser); return(new Result() { IsSucceed = ret > 0 }); }
/// <summary> /// 异步写日志 主要用于后台程序记录 1添加 2编辑 3修改 4常规日志 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tableName">日志表名 方法内会自动统一转小写</param> /// <param name="logContent">日志内容</param> /// <param name="kIDValue">主键字段对应的值 如 KID 的值</param> /// <param name="reqParams">请求的对象 仅用于日志展示</param> /// <param name="opertionUser">操作用户</param> /// <param name="operLogType">枚举操作类型</param> /// <param name="keyFields">主键字段名 默认KID</param> public static void WriteDbLog <T>(string tableName, string logContent, object kIDValue, T reqParams, OpertionUser opertionUser, OperLogType operLogType = OperLogType.常规日志, string keyFields = "KID") { ThreadPool.QueueUserWorkItem(state => { if (IsWriteOpertionLog) { #region 得到原始数据 日志表前一条记录 var oldlog = GetObjectLastState(tableName, kIDValue, keyFields); var newlog = ""; using (CommonRepository db = new CommonRepository(tableName, keyFields)) { var dr = db.GetRow($"{keyFields}='{kIDValue.ToString()}'"); newlog = dr.Table.ToJsonString(); } #endregion var dic = new Dictionary <string, object>(); dic.Add(nameof(Fd_sys_operationlog.TableName), tableName.ToLower().Trim()); dic.Add(nameof(Fd_sys_operationlog.TablePriKeyField), keyFields); dic.Add(nameof(Fd_sys_operationlog.TablePriKeyValue), kIDValue); dic.Add(nameof(Fd_sys_operationlog.CreateTime), DateTime.Now.ToStr()); dic.Add(nameof(Fd_sys_operationlog.LogContent), logContent); dic.Add(nameof(Fd_sys_operationlog.CreateUserId), opertionUser.IsNull() ? "1" : opertionUser.UserId); dic.Add(nameof(Fd_sys_operationlog.CreateUserName), opertionUser.IsNull() ? "系统用户" : opertionUser.UserName); dic.Add(nameof(Fd_sys_operationlog.IpAddr), (opertionUser.IsNull() ? IPHelper.GetClientIP() : opertionUser.UserClientIp)); dic.Add(nameof(Fd_sys_operationlog.OperType), operLogType.GetHashCode()); dic.Add(nameof(Fd_sys_operationlog.ReqData), reqParams.IsNull() ? "" : reqParams.ToJsonString()); dic.Add(nameof(Fd_sys_operationlog.ResOldData), oldlog); dic.Add(nameof(Fd_sys_operationlog.ResResult), newlog); Add(dic); } }, null); }
/// <summary> /// 异步写日志 主要用于后台程序记录 1添加 2编辑 3修改 4常规日志 /// </summary> /// <param name="tableName">日志表名 方法内会自动统一转小写</param> /// <param name="logContent">日志内容</param> /// <param name="kIDValue">主键字段对应的值 如 KID 的值</param> /// <param name="reqParams">请求的字典数据,仅用于日志展示</param> /// <param name="operLogType">操作类型</param> /// <param name="keyFields">主键字段名 默认KID</param> public static void WriteDbLog(string tableName, string logContent, object kIDValue, Dictionary <string, object> reqParams, OperLogType operLogType = OperLogType.常规日志, OpertionUser opertionUser = null, string keyFields = "KID") { ThreadPool.QueueUserWorkItem(state => { if (IsWriteOpertionLog) { #region 得到原始数据 日志表前一条记录 var oldlog = GetObjectLastState(tableName, kIDValue, keyFields); var newlog = ""; using (CommonRepository db = new CommonRepository(tableName, keyFields)) { var dr = db.GetRow($"{keyFields}='{kIDValue.ToString()}'"); newlog = dr.Table.ToDictionary().ToJsonString(); } #endregion #region 处理修改者信息 object updateUserId = "1", updateUserName = "******", clientIpAddr = IPHelper.GetClientIP(); if (opertionUser != null) { updateUserId = opertionUser?.UserId; updateUserName = opertionUser?.UserName; clientIpAddr = opertionUser?.UserClientIp; } else { if (reqParams != null) { if (reqParams.ContainsKey("UpdateUserId")) { updateUserId = reqParams["UpdateUserId"]; } if (reqParams.ContainsKey("UpdateUserName")) { updateUserName = reqParams["UpdateUserName"]; } if (reqParams.ContainsKey("ClientIpAddr")) { clientIpAddr = reqParams["ClientIpAddr"]; } } } #endregion var dic = new Dictionary <string, object>(); dic.Add(nameof(Fd_sys_operationlog.TableName), tableName.ToLower().Trim()); dic.Add(nameof(Fd_sys_operationlog.TablePriKeyField), keyFields); dic.Add(nameof(Fd_sys_operationlog.TablePriKeyValue), kIDValue); dic.Add(nameof(Fd_sys_operationlog.CreateTime), DateTime.Now.ToStr()); dic.Add(nameof(Fd_sys_operationlog.LogContent), logContent); dic.Add(nameof(Fd_sys_operationlog.CreateUserId), updateUserId); dic.Add(nameof(Fd_sys_operationlog.CreateUserName), updateUserName); dic.Add(nameof(Fd_sys_operationlog.IpAddr), clientIpAddr); dic.Add(nameof(Fd_sys_operationlog.OperType), operLogType.GetHashCode()); dic.Add(nameof(Fd_sys_operationlog.ReqData), reqParams.IsNull() ? "" : reqParams.ToJsonString()); dic.Add(nameof(Fd_sys_operationlog.ResOldData), oldlog); dic.Add(nameof(Fd_sys_operationlog.ResResult), newlog); Add(dic); } }, null); }
public JsonResponse AddPraise([FromBody] JsonRequest model) { var res = new Result { IsSucceed = false }; try { CommentView item = model?.Data.ToString()?.DeserialObject <CommentView>(); if (item == null || string.IsNullOrEmpty(item.BlogNum)) { return(new JsonResponse { Code = 1, Msg = "参数不合法" }); } var mem = UtilConst.GetLoginOpt(model.Token); var dic = new Dictionary <string, object> { { nameof(ArticlePraise.MemberId), mem.UserId }, { nameof(ArticlePraise.BlogNum), item.BlogNum }, { nameof(ArticlePraise.IsDeleted), 0 } }; var dodic = new Dictionary <string, object> { { nameof(ArticlePraise.MemberId), mem.UserId }, { nameof(ArticlePraise.BlogNum), item.BlogNum }, }; var ap = BlogHelper.GetModelByWhere_ArticlePraise(dodic); var opt = new OpertionUser(); bool isadd = true;//记录点赞还是取消点赞 #region 点赞处理 //取消点赞 if (ap != null && ap.KID > 0) { isadd = false; dodic.Add(nameof(ArticlePraise.IsDeleted), 1); dodic = UtilConst.AddBaseInfo <ArticlePraise>(dodic, model.Token, false, ref opt); res = BlogHelper.Update_ArticlePraise(dodic, ap.KID, opt); } //点赞 else { dodic.Add(nameof(ArticlePraise.IpAddress), GetIP()); dodic = UtilConst.AddBaseInfo <ArticlePraise>(dodic, model.Token, true, ref opt); res = BlogHelper.Add_ArticlePraise(dodic, opt); } #endregion #region 处理list 和 item 缓存 Task.Run(() => { if (res.IsSucceed) { string key = $"{CJJ.Blog.Apiv2.Models.ConfigUtil.BlogItemCacheKeyPrefix}{item.BlogNum}"; BloginfoView bloginfoView = CacheHelper.GetCacheItem(key)?.ToString()?.DeserialObject <BloginfoView>(); bloginfoView.Start += isadd ? 1 : -1; CacheHelper.AddCacheItem(key, bloginfoView.SerializObject(), DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.High); string alllistkey = ConfigUtil.BlogListCacheKey; string allinfo = CacheHelper.GetCacheItem(alllistkey)?.ToString(); List <Bloginfo> cachelist = allinfo?.DeserialObjectToList <Bloginfo>(); Bloginfo info = cachelist.FirstOrDefault(x => x.BlogNum == item.BlogNum); if (cachelist != null && cachelist.Count > 0 && info != null && info.KID > 0) { cachelist.FirstOrDefault(x => x.BlogNum == item.BlogNum).Start += isadd ? 1 : -1; CacheHelper.AddCacheItem(alllistkey, cachelist.SerializObject(), DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.High); } } }); #endregion return(new JsonResponse { Code = res.IsSucceed ? 0 : 1, Data = res }); } catch (Exception ex) { LogHelper.WriteLog(ex, "BlogController/AddPraise"); return(new JsonResponse { Code = 1, Msg = "程序好像开小差了" + ex.Message }); } }
public JsonResponse AddItem(CommentView model) { try { if (string.IsNullOrEmpty(model.Token)) { return(new JsonResponse() { Code = 1, Msg = "请从新登录" }); } var opt = new OpertionUser(); var member = UtilConst.Memberinfo(model.Token); var comment = new Dictionary <string, object>() { { nameof(Comment.Memberid), member.MemberModel.KID }, { nameof(Comment.MemberName), member.MemberModel.UserName }, { nameof(Comment.ToMemberid), model.ToMemberid }, { nameof(Comment.Content), model.Content }, { nameof(Comment.BlogNum), model.BlogNum }, { nameof(Comment.Avatar), member.MemberModel.UserIcon }, }; var sessionid = model.Commentid; if (!string.IsNullOrEmpty(model.Commentid)) { comment.Add(nameof(Comment.Commentid), model.Commentid); } else { sessionid = Guid.NewGuid().ToString("N"); comment.Add(nameof(Comment.Commentid), sessionid); } var dic = UtilConst.AddBaseInfo <Comment>(comment, model.Token, true, ref opt); Result res = BlogHelper.Add_Comment(dic, opt); #region 处理list、item缓存问题 Task.Run(() => { if (res.IsSucceed && model.ToMemberid.Toint() == 0) { List <Bloginfo> bloglist = CacheHelper.GetCacheItem(ConfigUtil.BlogListCacheKey)?.ToString()?.DeserialObjectToList <Bloginfo>(); Bloginfo info = bloglist.FirstOrDefault(x => x.BlogNum == model.BlogNum); if (bloglist != null && bloglist.Count > 0 && info != null && info.KID > 0) { bloglist.FirstOrDefault(x => x.BlogNum == model.BlogNum).Comments += 1; CacheHelper.AddCacheItem(ConfigUtil.BlogListCacheKey, bloglist.SerializObject(), DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.High); } var blogview = CacheHelper.GetCacheItem($"{ConfigUtil.BlogItemCacheKeyPrefix}{model.BlogNum}")?.DeserialObject <BloginfoView>(); if (blogview != null && blogview.KID > 0) { blogview.Comments += 1; CacheHelper.AddCacheItem($"{ConfigUtil.BlogItemCacheKeyPrefix}{model.BlogNum}", blogview.SerializObject(), DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.High); } } }); #endregion return(new JsonResponse() { Code = res.IsSucceed ? 0 : 1, Data = sessionid }); } catch (Exception ex) { LogHelper.WriteLog(ex, "CommentController/additem"); return(new JsonResponse() { Code = 1, Msg = "程序视乎开小差了" + ex.Message }); } }
/// <summary> /// Exports the excel file. /// </summary> /// <param name="dicwhere">查询条件</param> /// <param name="fileFullName">文件名全路径</param> /// <param name="opertionUser">操作者信息</param> /// <returns>System.String.</returns> public static Result ExportExcelFile(Dictionary <string, object> dicwhere, string fileFullName, OpertionUser opertionUser) { Result ret = new Result(); try { ret.IsSucceed = FastDev.ExcelHelper.Excel.OutputToExcel(GetDataTable(dicwhere, 0, 0), fileFullName); } catch (Exception ex) { ret.IsSucceed = false; ret.Message = ex.Message; } return(ret); }
/// <summary> /// Adds the base information. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dic">The dic.</param> /// <param name="token">The token.</param> /// <param name="isAdd">if set to <c>true</c> [is add].</param> /// <param name="opt">The opt.</param> /// <returns></returns> public static Dictionary <string, object> AddBaseInfo <T>(Dictionary <string, object> dic, string token, bool isAdd, ref OpertionUser opt) { var user = UtilConst.GetLoginOpt(token); var propertys = typeof(T).GetProperties(); if (propertys.Count(x => x.Name == "CreateTime") > 0 && isAdd) { dic.Add("CreateTime", DateTime.Now);; } if (propertys.Count(x => x.Name == "CreateUserId") > 0 && isAdd) { dic.Add("CreateUserId", user.UserId); } if (propertys.Count(x => x.Name == "CreateUserName") > 0 && isAdd) { dic.Add("CreateUserName", user.UserName); } if (propertys.Count(x => x.Name == "UpdateUserId") > 0) { dic.Add("UpdateUserId", user.UserId); } if (propertys.Count(x => x.Name == "UpdateUserName") > 0) { dic.Add("UpdateUserName", user.UserName); } if (propertys.Count(x => x.Name == "UpdateTime") > 0) { dic.Add("UpdateTime", DateTime.Now); } opt.UserId = user.UserId; opt.UserName = user.UserName; opt.UserClientIp = GetIP(); return(dic); }