feat: 增加新闻总数统计
This commit is contained in:
@@ -41,4 +41,12 @@ interface ArticleRepository : JpaRepository<Article, String>, 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<String>
|
||||
|
||||
@Query("select new com.lanyuanxiaoyao.digtal.market.CountGroupByString(article.code, count(article.code)) from Article article group by article.code")
|
||||
fun countGroupByCode(): List<CountGroupByString>
|
||||
}
|
||||
|
||||
data class CountGroupByString(
|
||||
val key: String,
|
||||
val count: Long,
|
||||
)
|
||||
|
||||
@@ -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<Map<String, Any>> {
|
||||
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()
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user