Commit 9a419340 authored by 黄奎's avatar 黄奎

页面修改

parent d106e9d3
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Edu.Model.ViewModel.LearningGarden; using Edu.Model.ViewModel.LearningGarden;
using Edu.Repository.LearningGarden; using Edu.Repository.LearningGarden;
using VT.FW.DB; using VT.FW.DB;
...@@ -68,10 +69,6 @@ namespace Edu.Module.Course ...@@ -68,10 +69,6 @@ namespace Edu.Module.Course
return flag; return flag;
} }
/// <summary> /// <summary>
/// 批量新增修改学习园地 /// 批量新增修改学习园地
/// </summary> /// </summary>
...@@ -80,6 +77,8 @@ namespace Edu.Module.Course ...@@ -80,6 +77,8 @@ namespace Edu.Module.Course
public bool SetBatchWebNewsModule(List<RB_LearningGarden_ViewModel> list) public bool SetBatchWebNewsModule(List<RB_LearningGarden_ViewModel> list)
{ {
bool flag = false; bool flag = false;
Task.Run(() =>
{
foreach (var model in list) foreach (var model in list)
{ {
if (model.Id > 0) if (model.Id > 0)
...@@ -103,6 +102,7 @@ namespace Edu.Module.Course ...@@ -103,6 +102,7 @@ namespace Edu.Module.Course
flag = newId > 0; flag = newId > 0;
} }
} }
});
return flag; return flag;
} }
......
...@@ -90,5 +90,41 @@ WHERE 1=1 ...@@ -90,5 +90,41 @@ WHERE 1=1
builder.AppendFormat(" order by a.UpdateTime desc "); builder.AppendFormat(" order by a.UpdateTime desc ");
return Get<RB_LearningGarden_ViewModel>(builder.ToString()).ToList(); return Get<RB_LearningGarden_ViewModel>(builder.ToString()).ToList();
} }
/// <summary>
/// 批量新增
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public bool BatchInsertLearningGardenRepository(List<RB_LearningGarden_ViewModel> list)
{
StringBuilder builder = new StringBuilder();
builder.Append("INSERT INTO RB_LearningGarden (Title,Img,Content,Digest,LinkUrl,TypeId,Status,CreateDate,CreateBy,Group_Id,School_Id,UpdateTime,WeChatAccountId,Author,GardenType) VALUES");
list.ForEach(x =>
{
builder.Append($"('{x.Title}','{x.Img}','{x.Content}','{x.Digest}','{x.LinkUrl}','{x.TypeId}',{(int)x.Status},'{x.CreateDate}',{x.CreateBy},{x.Group_Id},{x.School_Id},'{x.UpdateTime}','{x.WeChatAccountId}','{x.Author}',{x.GardenType}),");
});
builder = builder.Remove(builder.Length - 1, 1);
return base.Execute(builder.ToString()) > 0;
}
/// <summary>
/// 批量修改
/// </summary>
/// <param name="list"></param>
/// <returns></returns>
public bool BatchUpdateLearningGardenRepository(List<RB_LearningGarden_ViewModel> list)
{
StringBuilder builder = new StringBuilder();
builder.Append("INSERT INTO RB_LearningGarden (Id,Title,Img,Content,TypeId,Digest,LinkUrl,UpdateTime) VALUES");
list.ForEach(x =>
{
builder.Append($"({x.Id},'{x.Title}','{x.Img}','{x.Content}','{x.TypeId}','{x.Digest}','{x.LinkUrl}','{x.UpdateTime}'),");
});
builder = builder.Remove(builder.Length - 1, 1);
builder.Append("ON DUPLICATE KEY UPDATE Title=VALUES(Title),Img=VALUES(Img),Content=VALUES(Content),TypeId=VALUES(TypeId),Digest=VALUES(Digest),LinkUrl=VALUES(LinkUrl),UpdateTime=VALUES(UpdateTime);");
return Execute(builder.ToString()) > 0;
}
} }
} }
...@@ -158,7 +158,6 @@ namespace Edu.WebApi.Controllers.LearningGarden ...@@ -158,7 +158,6 @@ namespace Edu.WebApi.Controllers.LearningGarden
[HttpPost] [HttpPost]
public ApiResult GetGoodsData() public ApiResult GetGoodsData()
{ {
int pageIndex = 1; int pageIndex = 1;
int pageSize = 20; int pageSize = 20;
int pageCount = 0; int pageCount = 0;
...@@ -167,18 +166,16 @@ namespace Edu.WebApi.Controllers.LearningGarden ...@@ -167,18 +166,16 @@ namespace Edu.WebApi.Controllers.LearningGarden
string token = Cache.WeChat.WeChatReidsCache2.GetToken(tokenKey); string token = Cache.WeChat.WeChatReidsCache2.GetToken(tokenKey);
if (Common.Config.IsLocal == 1) if (Common.Config.IsLocal == 1)
{ {
token = "49_j9OOoNVD3jcqJPXX3nb6jalJ9L4AlsltW60JCULR0PikrvW-CYzoFJXK9iS7sK3ygztuf0q5DRGmdJwU7MTqH8tNDtqsMthLHbuiHVVlWIAcycqq24kLKS9K4-FxFMoR-tzLdQOpkYZvDWrEXOFaABAMDU"; token = "53_OVLlSPNJ0hmSrsEUfnJ6kTxFRGxfkcuJJjpBjsDuaSGmtYu95vZNNyh-wIXbFSZ9DtxzFJ1eN0At2QmJ_aWLPFjz4yrz2VrWvmR3KrEQKqfwvxesG82V2WpAgDnxW_tvvWYXRRRX1oguxCtHXSShADAKFF";
} }
Common.Plugin.LogHelper.Write("GetGoodsData_Common.Config.IsLocal:" + Common.Config.IsLocal);
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
Common.Plugin.LogHelper.Write("GetGoodsData_getToken:key" + tokenKey);
token = Common.Plugin.WeChatHelper.GetAccessToken(Common.Config.WeChatAccountAppId, Common.Config.WeChatAccountAppSecret); token = Common.Plugin.WeChatHelper.GetAccessToken(Common.Config.WeChatAccountAppId, Common.Config.WeChatAccountAppSecret);
Common.Plugin.LogHelper.Write("GetGoodsData_token:" + token);
Cache.WeChat.WeChatReidsCache2.Set(tokenKey, token); Cache.WeChat.WeChatReidsCache2.Set(tokenKey, token);
} }
var resultTotalCount = HttpHelper.HttpGet("https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=" + token); var resultTotalCount = HttpHelper.HttpGet("https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=" + token);
Common.Plugin.LogHelper.Write("GetGoodsData_resultTotalCount:" + resultTotalCount); Common.Plugin.LogHelper.WriteInfo("GetGoodsData: " + resultTotalCount);
JObject parm = JObject.Parse(resultTotalCount); JObject parm = JObject.Parse(resultTotalCount);
List<WeChatLearningGardenItem> allList = new List<WeChatLearningGardenItem>(); List<WeChatLearningGardenItem> allList = new List<WeChatLearningGardenItem>();
...@@ -194,7 +191,8 @@ namespace Edu.WebApi.Controllers.LearningGarden ...@@ -194,7 +191,8 @@ namespace Edu.WebApi.Controllers.LearningGarden
} }
pageIndex++; pageIndex++;
} }
Common.Plugin.LogHelper.WriteInfo("GetGoodsData: " + allList.Count());
Common.Plugin.LogHelper.WriteInfo("GetGoodsData: " + Common.Plugin.JsonHelper.Serialize(allList));
List<RB_LearningGarden_ViewModel> learningGardenList = new List<RB_LearningGarden_ViewModel>(); List<RB_LearningGarden_ViewModel> learningGardenList = new List<RB_LearningGarden_ViewModel>();
//查询数据库信息 //查询数据库信息
...@@ -208,7 +206,6 @@ namespace Edu.WebApi.Controllers.LearningGarden ...@@ -208,7 +206,6 @@ namespace Edu.WebApi.Controllers.LearningGarden
{ {
RB_LearningGarden_ViewModel extModel = new RB_LearningGarden_ViewModel() RB_LearningGarden_ViewModel extModel = new RB_LearningGarden_ViewModel()
{ {
Id = 0, Id = 0,
WeChatAccountId = item.media_id, WeChatAccountId = item.media_id,
Title = itemNews.title, Title = itemNews.title,
...@@ -238,7 +235,6 @@ namespace Edu.WebApi.Controllers.LearningGarden ...@@ -238,7 +235,6 @@ namespace Edu.WebApi.Controllers.LearningGarden
} }
learningGardenModule.SetBatchWebNewsModule(learningGardenList); learningGardenModule.SetBatchWebNewsModule(learningGardenList);
return ApiResult.Success(""); return ApiResult.Success("");
} }
...@@ -265,22 +261,25 @@ namespace Edu.WebApi.Controllers.LearningGarden ...@@ -265,22 +261,25 @@ namespace Edu.WebApi.Controllers.LearningGarden
} }
/// <summary>
/// 获取公众号列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
static List<WeChatLearningGardenItem> GetGoodsList(int pageIndex, int pageSize) static List<WeChatLearningGardenItem> GetGoodsList(int pageIndex, int pageSize)
{ {
string tokenKey = Cache.CacheKey.DATA_WeChatAccountToken + Common.Config.WeChatAccountAppId; string tokenKey = Cache.CacheKey.DATA_WeChatAccountToken + Common.Config.WeChatAccountAppId;
string token = Cache.WeChat.WeChatReidsCache2.GetToken(tokenKey); string token = Cache.WeChat.WeChatReidsCache2.GetToken(tokenKey);
if (Common.Config.IsLocal == 1) if (Common.Config.IsLocal == 1)
{ {
token = "49_j9OOoNVD3jcqJPXX3nb6jalJ9L4AlsltW60JCULR0PikrvW-CYzoFJXK9iS7sK3ygztuf0q5DRGmdJwU7MTqH8tNDtqsMthLHbuiHVVlWIAcycqq24kLKS9K4-FxFMoR-tzLdQOpkYZvDWrEXOFaABAMDU"; token = "53_OVLlSPNJ0hmSrsEUfnJ6kTxFRGxfkcuJJjpBjsDuaSGmtYu95vZNNyh-wIXbFSZ9DtxzFJ1eN0At2QmJ_aWLPFjz4yrz2VrWvmR3KrEQKqfwvxesG82V2WpAgDnxW_tvvWYXRRRX1oguxCtHXSShADAKFF";
} }
if (string.IsNullOrEmpty(token)) if (string.IsNullOrEmpty(token))
{ {
token = Common.Plugin.WeChatHelper.GetAccessToken(Common.Config.WeChatAccountAppId, Common.Config.WeChatAccountAppSecret); token = Common.Plugin.WeChatHelper.GetAccessToken(Common.Config.WeChatAccountAppId, Common.Config.WeChatAccountAppSecret);
Cache.WeChat.WeChatReidsCache2.Set(tokenKey, token); Cache.WeChat.WeChatReidsCache2.Set(tokenKey, token);
} }
WeChatLearningGarden model = new WeChatLearningGarden();
string newImaApi = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=" + token; string newImaApi = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=" + token;
List<WeChatLearningGardenItem> list = new List<WeChatLearningGardenItem>(); List<WeChatLearningGardenItem> list = new List<WeChatLearningGardenItem>();
var resultInfo = new var resultInfo = new
...@@ -290,16 +289,54 @@ namespace Edu.WebApi.Controllers.LearningGarden ...@@ -290,16 +289,54 @@ namespace Edu.WebApi.Controllers.LearningGarden
count = pageSize count = pageSize
}; };
string jsonData = HttpHelper.HttpPost(newImaApi, JsonHelper.Serialize(resultInfo), ""); string jsonData = HttpHelper.HttpPost(newImaApi, JsonHelper.Serialize(resultInfo), "");
if (jsonData != null && !string.IsNullOrEmpty(jsonData)) if (jsonData != null && !string.IsNullOrEmpty(jsonData))
{ {
JObject jObj = JObject.Parse(jsonData); JObject jObj = JObject.Parse(jsonData);
var item = jObj.GetStringValue("item"); var item = jObj.GetStringValue("item");
list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<WeChatLearningGardenItem>>(item); if (!string.IsNullOrEmpty(item))
//if (model != null && model.item != null) {
//{ JArray jArray = JArray.Parse(item);
// list.Add(model.item); if (jArray != null && jArray.Count > 0)
//} {
foreach (var jItem in jArray)
{
JObject sObj = JObject.Parse(jItem.ToString());
JObject dObj = JObject.Parse(sObj.GetStringValue("content"));
var newsItem = new List<WeChatLearningGardenNewsItem>();
JArray subArray = JArray.Parse(dObj.GetStringValue("news_item"));
if (subArray != null && subArray.Count > 0)
{
foreach (var sItem in subArray)
{
var contentObj = JObject.Parse(sItem.ToString());
newsItem.Add(new WeChatLearningGardenNewsItem()
{
title = contentObj.GetStringValue("title"),
author = contentObj.GetStringValue("author"),
digest = contentObj.GetStringValue("digest"),
content = contentObj.GetStringValue("content"),
show_cover_pic = contentObj.GetInt("show_cover_pic"),
url = contentObj.GetStringValue("url"),
thumb_url = contentObj.GetStringValue("thumb_url"),
});
}
}
var content = new WeChatLearningGardenContent()
{
news_item = newsItem,
create_time = dObj.GetLong("create_time"),
update_time = dObj.GetLong("update_time"),
};
WeChatLearningGardenItem model = new WeChatLearningGardenItem()
{
media_id = sObj.GetStringValue("media_id"),
update_time = sObj.GetStringValue("update_time"),
content = content
};
list.Add(model);
}
}
}
} }
return list; return list;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment