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', + }, } } }