From 94fe020aa6932e60599126e46ef01255e44d59d1 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Mon, 4 Nov 2024 21:55:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=96=B0=E9=97=BB?= =?UTF-8?q?=E6=80=BB=E6=95=B0=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lanyuanxiaoyao/digtal/market/Entity.kt | 8 +++++ .../market/controller/SiteController.kt | 35 ++++++++++--------- .../resources/static/component/site-tab.js | 11 +++++- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/com/lanyuanxiaoyao/digtal/market/Entity.kt b/src/main/kotlin/com/lanyuanxiaoyao/digtal/market/Entity.kt index 9231830..43874c8 100644 --- a/src/main/kotlin/com/lanyuanxiaoyao/digtal/market/Entity.kt +++ b/src/main/kotlin/com/lanyuanxiaoyao/digtal/market/Entity.kt @@ -41,4 +41,12 @@ interface ArticleRepository : JpaRepository, JpaSpecificationEx @Query("select article.id from Article article where article.description is not null and article.subtitle is not null and article.score is not null") fun findAllId(): List + + @Query("select new com.lanyuanxiaoyao.digtal.market.CountGroupByString(article.code, count(article.code)) from Article article group by article.code") + fun countGroupByCode(): List } + +data class CountGroupByString( + val key: String, + val count: Long, +) diff --git a/src/main/kotlin/com/lanyuanxiaoyao/digtal/market/controller/SiteController.kt b/src/main/kotlin/com/lanyuanxiaoyao/digtal/market/controller/SiteController.kt index 4b93406..c67b3ca 100644 --- a/src/main/kotlin/com/lanyuanxiaoyao/digtal/market/controller/SiteController.kt +++ b/src/main/kotlin/com/lanyuanxiaoyao/digtal/market/controller/SiteController.kt @@ -2,6 +2,7 @@ package com.lanyuanxiaoyao.digtal.market.controller import cn.hutool.json.JSON import cn.hutool.json.JSONUtil +import com.lanyuanxiaoyao.digtal.market.ArticleRepository import com.lanyuanxiaoyao.squirrel.core.jvm.JvmManagement import jakarta.annotation.Resource import org.slf4j.LoggerFactory @@ -16,26 +17,28 @@ import org.springframework.web.bind.annotation.RestController class SiteController { private val logger = LoggerFactory.getLogger(javaClass) + @Resource + private lateinit var articleRepository: ArticleRepository + @Resource private lateinit var management: JvmManagement @GetMapping("list") - fun list() = management.exportSites() - .map { site -> - mapOf( - "code" to site.code, - "name" to site.name, - "icon" to site.icon, - "url" to site.home, - "description" to site.description, - "iframe" to site.properties.containsKey("iframe"), - "children" to site.tags.map { tag -> - mapOf( - "name" to tag.key, - "url" to tag.value, - ) - }) - } + fun list(): List> { + val countMap = articleRepository.countGroupByCode().associate { it.key to it.count } + return management.exportSites() + .map { site -> + mapOf( + "code" to site.code, + "name" to site.name, + "icon" to site.icon, + "url" to site.home, + "description" to site.description, + "iframe" to site.properties.containsKey("iframe"), + "news" to (countMap[site.code] ?: 0) + ) + } + } @GetMapping("source") fun source(@RequestParam("code") code: String) = management.exportSites() diff --git a/src/main/resources/static/component/site-tab.js b/src/main/resources/static/component/site-tab.js index 21e3086..70f5824 100644 --- a/src/main/resources/static/component/site-tab.js +++ b/src/main/resources/static/component/site-tab.js @@ -12,7 +12,13 @@ function siteTab() { { label: '名称', name: 'name', - width: 200, + width: 250, + }, + { + label: '新闻数', + name: 'news', + width: 50, + className: 'text-center', }, { label: '链接', @@ -52,6 +58,9 @@ function siteTab() { type: 'editor', name: 'source', language: 'json', + options: { + wordWrap: 'on', + }, } } }