|
@@ -9,6 +9,7 @@ using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Net.Http.Json;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
|
|
+using System.Text.Json.Serialization;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using Azure;
|
|
using Azure;
|
|
using Azure.Cosmos;
|
|
using Azure.Cosmos;
|
|
@@ -75,14 +76,16 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
+ List<IdNameCode> schools= new List<IdNameCode>();
|
|
List<Elegant> elegants = new List<Elegant>();
|
|
List<Elegant> elegants = new List<Elegant>();
|
|
if ($"{_scope}".Equals("area"))
|
|
if ($"{_scope}".Equals("area"))
|
|
{
|
|
{
|
|
- string sql = $"select value c.id from c where c.areaId ='{_code}'";
|
|
|
|
- var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<string>(sql, "Base");
|
|
|
|
|
|
+ string sql = $"select c.name ,c.picture, c.id from c where c.areaId ='{_code}'";
|
|
|
|
+ var result = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<IdNameCode>(sql, "Base");
|
|
if (result.list.IsNotEmpty())
|
|
if (result.list.IsNotEmpty())
|
|
{
|
|
{
|
|
- string sqlE = $"select value c from c where c.school in ({string.Join(",", result.list.Select(z => $"'{z}'"))})";
|
|
|
|
|
|
+ schools.AddRange(result.list);
|
|
|
|
+ string sqlE = $"select value c from c where c.school in ({string.Join(",", result.list.Select(z => $"'{z.id}'"))}) and c.pk='Elegant' and contains(c.code,'Elegant-')";
|
|
var resultE = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Elegant>(sqlE);
|
|
var resultE = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).GetList<Elegant>(sqlE);
|
|
if (resultE.list.IsNotEmpty())
|
|
if (resultE.list.IsNotEmpty())
|
|
{
|
|
{
|
|
@@ -99,19 +102,105 @@ namespace TEAMModelOS.Controllers
|
|
elegants.AddRange(resultE.list);
|
|
elegants.AddRange(resultE.list);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ List<ClassifiedItemSchool > schoolDatas= new List<ClassifiedItemSchool>();
|
|
|
|
+ if (schools.IsNotEmpty()) {
|
|
|
|
+ foreach (var school in schools) {
|
|
|
|
+ var esSchool = elegants.FindAll(z => z.school.Equals(school.id));
|
|
|
|
+ List<ClassifiedItem> itemschool = ClassifyHierarchy(esSchool);
|
|
|
|
+ if (!itemschool.Select(z => z.id).Contains("德育风采"))
|
|
|
|
+ {
|
|
|
|
+ itemschool.Add(new ClassifiedItem()
|
|
|
|
+ {
|
|
|
|
+ videoCount = 0,
|
|
|
|
+ imageCount = 0,
|
|
|
|
+ docCount = 0,
|
|
|
|
+ otherCount = 0,
|
|
|
|
+ count= 0,
|
|
|
|
+ id="德育风采"
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (!itemschool.Select(z => z.id).Contains("艺术特色"))
|
|
|
|
+ {
|
|
|
|
+ itemschool.Add(new ClassifiedItem()
|
|
|
|
+ {
|
|
|
|
+ videoCount = 0,
|
|
|
|
+ imageCount = 0,
|
|
|
|
+ docCount = 0,
|
|
|
|
+ otherCount = 0,
|
|
|
|
+ count= 0,
|
|
|
|
+ id="艺术特色"
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ List<ClassifiedItem> schoolItems= new List<ClassifiedItem>();
|
|
|
|
+ foreach (var item in itemschool)
|
|
|
|
+ {
|
|
|
|
+ if (item.pid== null) {
|
|
|
|
+ var es = elegants.FindAll(z => item.sid.Contains(z.id));
|
|
|
|
+ if (es.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ var video = es.SelectMany(z => z.attachments).Where(a => !string.IsNullOrWhiteSpace(a.type) && a.type.Equals("video"));
|
|
|
|
+ if (video.Any())
|
|
|
|
+ {
|
|
|
|
+ item.videoCount = video.Count();
|
|
|
|
+ }
|
|
|
|
+ var image = es.SelectMany(z => z.attachments).Where(a => !string.IsNullOrWhiteSpace(a.type) &&a.type.Equals("image"));
|
|
|
|
+ if (image.Any())
|
|
|
|
+ {
|
|
|
|
+ item.imageCount = image.Count();
|
|
|
|
+ }
|
|
|
|
+ var doc = es.SelectMany(z => z.attachments).Where(a => !string.IsNullOrWhiteSpace(a.type) && a.type.Equals("doc"));
|
|
|
|
+ if (doc.Any())
|
|
|
|
+ {
|
|
|
|
+ item.docCount = doc.Count();
|
|
|
|
+ }
|
|
|
|
+ var other = es.SelectMany(z => z.attachments).Where(a => string.IsNullOrWhiteSpace(a.type) || (!a.type.Equals("doc") && !a.type.Equals("video") && !a.type.Equals("image") && !a.type.Equals("doc")));
|
|
|
|
+ if (other.Any())
|
|
|
|
+ {
|
|
|
|
+ item.otherCount = other.Count();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ schoolItems.Add(item);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ schoolDatas.Add(new ClassifiedItemSchool { id= school.id, name = school.name, picture= school.picture, items =schoolItems });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
List<ClassifiedItem> items = ClassifyHierarchy(elegants);
|
|
List<ClassifiedItem> items = ClassifyHierarchy(elegants);
|
|
- string rs = string.Empty;
|
|
|
|
- List<dynamic> comments = new List<dynamic>();
|
|
|
|
- foreach (var es in elegants) {
|
|
|
|
- comments.Add(new { comment = $"{es.title} {es.content}" });
|
|
|
|
|
|
+ int videoCount = 0;
|
|
|
|
+ int imageCount = 0;
|
|
|
|
+ int docCount = 0;
|
|
|
|
+ int otherCount = 0;
|
|
|
|
+ if (!items.Select(z=>z.id).Contains("德育风采")) {
|
|
|
|
+ items.Add(new ClassifiedItem()
|
|
|
|
+ {
|
|
|
|
+ videoCount = 0,
|
|
|
|
+ imageCount = 0,
|
|
|
|
+ docCount = 0,
|
|
|
|
+ otherCount = 0,
|
|
|
|
+ count= 0,
|
|
|
|
+ id="德育风采"
|
|
|
|
+ });
|
|
}
|
|
}
|
|
- if (comments.IsNotEmpty()) {
|
|
|
|
- rs= comments.ToJsonString();
|
|
|
|
|
|
+ if (!items.Select(z => z.id).Contains("艺术特色"))
|
|
|
|
+ {
|
|
|
|
+ items.Add(new ClassifiedItem()
|
|
|
|
+ {
|
|
|
|
+ videoCount = 0,
|
|
|
|
+ imageCount = 0,
|
|
|
|
+ docCount = 0,
|
|
|
|
+ otherCount = 0,
|
|
|
|
+ count= 0,
|
|
|
|
+ id="艺术特色"
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
+ List<ItemCommentKeyCount> itemKeys = new List<ItemCommentKeyCount>();
|
|
foreach (var item in items)
|
|
foreach (var item in items)
|
|
{
|
|
{
|
|
var es = elegants.FindAll(z => item.sid.Contains(z.id));
|
|
var es = elegants.FindAll(z => item.sid.Contains(z.id));
|
|
if (es.IsNotEmpty()) {
|
|
if (es.IsNotEmpty()) {
|
|
|
|
+
|
|
var video = es.SelectMany(z => z.attachments).Where(a =>!string.IsNullOrWhiteSpace(a.type) && a.type.Equals("video"));
|
|
var video = es.SelectMany(z => z.attachments).Where(a =>!string.IsNullOrWhiteSpace(a.type) && a.type.Equals("video"));
|
|
if (video.Any()) {
|
|
if (video.Any()) {
|
|
item.videoCount = video.Count();
|
|
item.videoCount = video.Count();
|
|
@@ -132,23 +221,43 @@ namespace TEAMModelOS.Controllers
|
|
item.otherCount = other.Count();
|
|
item.otherCount = other.Count();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- List<CommentKeyCount> keyCounts = new List<CommentKeyCount>();
|
|
|
|
- if (!string.IsNullOrWhiteSpace(rs)) {
|
|
|
|
- var httpClient= _httpClientFactory.CreateClient();
|
|
|
|
- if (!httpClient.DefaultRequestHeaders.Contains("x-functions-key")) {
|
|
|
|
- httpClient.DefaultRequestHeaders.Add("x-functions-key", "2BcXFR_hvzG1pZjqIkaM7Dx74Hcu6m0PwwOacFpDpq44AzFuHJBRXA==");
|
|
|
|
- }
|
|
|
|
- string paramJson = JsonConvert.SerializeObject(new { rs = $"{rs}", fmt = "0" });
|
|
|
|
- var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
|
|
|
|
- HttpResponseMessage httpResponse= await httpClient.PostAsync("https://malearn.teammodel.cn/api/txtwc", content);
|
|
|
|
- if (httpResponse.IsSuccessStatusCode) {
|
|
|
|
- string str = await httpResponse.Content.ReadAsStringAsync();
|
|
|
|
- if (str.Contains("freq"))
|
|
|
|
- { keyCounts= str.ToObject<List<CommentKeyCount>>(); }
|
|
|
|
|
|
+ if (item.pid==null) {
|
|
|
|
+ videoCount+=item.videoCount;
|
|
|
|
+ imageCount+=item.imageCount;
|
|
|
|
+ docCount += item.docCount;
|
|
|
|
+ otherCount += item.otherCount;
|
|
|
|
+ List<dynamic> comments = new List<dynamic>();
|
|
|
|
+ foreach (var e in es)
|
|
|
|
+ {
|
|
|
|
+ comments.Add(new { comment = $"{e.title},{e.content}" });
|
|
|
|
+ }
|
|
|
|
+ string rs = string.Empty;
|
|
|
|
+ if (comments.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ rs= comments.ToJsonString();
|
|
|
|
+ }
|
|
|
|
+ List<CommentKeyCount> keyCounts = new List<CommentKeyCount>();
|
|
|
|
+ if (!string.IsNullOrWhiteSpace(rs))
|
|
|
|
+ {
|
|
|
|
+ var httpClient = _httpClientFactory.CreateClient();
|
|
|
|
+ if (!httpClient.DefaultRequestHeaders.Contains("x-functions-key"))
|
|
|
|
+ {
|
|
|
|
+ httpClient.DefaultRequestHeaders.Add("x-functions-key", "2BcXFR_hvzG1pZjqIkaM7Dx74Hcu6m0PwwOacFpDpq44AzFuHJBRXA==");
|
|
|
|
+ }
|
|
|
|
+ string paramJson = JsonConvert.SerializeObject(new { rs = $"{rs}", fmt = "0" });
|
|
|
|
+ var content = new StringContent(paramJson, Encoding.UTF8, "application/json");
|
|
|
|
+ HttpResponseMessage httpResponse = await httpClient.PostAsync("https://malearn.teammodel.cn/api/txtwc", content);
|
|
|
|
+ if (httpResponse.IsSuccessStatusCode)
|
|
|
|
+ {
|
|
|
|
+ string str = await httpResponse.Content.ReadAsStringAsync();
|
|
|
|
+ if (str.Contains("freq"))
|
|
|
|
+ { keyCounts= str.ToObject<List<CommentKeyCount>>(); }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ itemKeys.Add(new ItemCommentKeyCount { id= item.id, keyCounts=keyCounts});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return Ok(new { keyCounts,items= items.Select(z=>new {z.id ,z.pid,z.count,z.videoCount,z.docCount,z.imageCount,z.otherCount })});
|
|
|
|
|
|
+ return Ok(new { schoolDatas, videoCount, imageCount,otherCount,docCount , itemKeys, items = items.Select(z=>new {z.id ,z.pid,z.count,z.videoCount,z.docCount,z.imageCount,z.otherCount })});
|
|
}
|
|
}
|
|
|
|
|
|
private List<ClassifiedItem> ClassifyHierarchy(List<Elegant> inputArray)
|
|
private List<ClassifiedItem> ClassifyHierarchy(List<Elegant> inputArray)
|
|
@@ -197,15 +306,27 @@ namespace TEAMModelOS.Controllers
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+ class ItemCommentKeyCount {
|
|
|
|
+ public string id { get; set; }
|
|
|
|
+ public List<CommentKeyCount> keyCounts { get; set; } = new List<CommentKeyCount>();
|
|
|
|
+ }
|
|
class CommentKeyCount
|
|
class CommentKeyCount
|
|
{
|
|
{
|
|
public int id { get; set; }
|
|
public int id { get; set; }
|
|
public string word { get; set; }
|
|
public string word { get; set; }
|
|
public int freq { get; set; }
|
|
public int freq { get; set; }
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
+ class ClassifiedItemSchool {
|
|
|
|
+ public string id { get; set; }
|
|
|
|
+ public string name { get; set; }
|
|
|
|
+ public string picture { get; set; }
|
|
|
|
+ public List<ClassifiedItem> items { get; set; } = new List<ClassifiedItem>();
|
|
|
|
+ }
|
|
|
|
+
|
|
class ClassifiedItem
|
|
class ClassifiedItem
|
|
{
|
|
{
|
|
|
|
+
|
|
|
|
+ [System.Text.Json.Serialization.JsonIgnoreAttribute]
|
|
public List<string> sid { get; set; } = new List<string>();
|
|
public List<string> sid { get; set; } = new List<string>();
|
|
public string id { get; set; }
|
|
public string id { get; set; }
|
|
public int count { get; set; }
|
|
public int count { get; set; }
|