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")
|
@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>
|
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.JSON
|
||||||
import cn.hutool.json.JSONUtil
|
import cn.hutool.json.JSONUtil
|
||||||
|
import com.lanyuanxiaoyao.digtal.market.ArticleRepository
|
||||||
import com.lanyuanxiaoyao.squirrel.core.jvm.JvmManagement
|
import com.lanyuanxiaoyao.squirrel.core.jvm.JvmManagement
|
||||||
import jakarta.annotation.Resource
|
import jakarta.annotation.Resource
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@@ -16,26 +17,28 @@ import org.springframework.web.bind.annotation.RestController
|
|||||||
class SiteController {
|
class SiteController {
|
||||||
private val logger = LoggerFactory.getLogger(javaClass)
|
private val logger = LoggerFactory.getLogger(javaClass)
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private lateinit var articleRepository: ArticleRepository
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private lateinit var management: JvmManagement
|
private lateinit var management: JvmManagement
|
||||||
|
|
||||||
@GetMapping("list")
|
@GetMapping("list")
|
||||||
fun list() = management.exportSites()
|
fun list(): List<Map<String, Any>> {
|
||||||
.map { site ->
|
val countMap = articleRepository.countGroupByCode().associate { it.key to it.count }
|
||||||
mapOf(
|
return management.exportSites()
|
||||||
"code" to site.code,
|
.map { site ->
|
||||||
"name" to site.name,
|
mapOf(
|
||||||
"icon" to site.icon,
|
"code" to site.code,
|
||||||
"url" to site.home,
|
"name" to site.name,
|
||||||
"description" to site.description,
|
"icon" to site.icon,
|
||||||
"iframe" to site.properties.containsKey("iframe"),
|
"url" to site.home,
|
||||||
"children" to site.tags.map { tag ->
|
"description" to site.description,
|
||||||
mapOf(
|
"iframe" to site.properties.containsKey("iframe"),
|
||||||
"name" to tag.key,
|
"news" to (countMap[site.code] ?: 0)
|
||||||
"url" to tag.value,
|
)
|
||||||
)
|
}
|
||||||
})
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("source")
|
@GetMapping("source")
|
||||||
fun source(@RequestParam("code") code: String) = management.exportSites()
|
fun source(@RequestParam("code") code: String) = management.exportSites()
|
||||||
|
|||||||
@@ -12,7 +12,13 @@ function siteTab() {
|
|||||||
{
|
{
|
||||||
label: '名称',
|
label: '名称',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
width: 200,
|
width: 250,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '新闻数',
|
||||||
|
name: 'news',
|
||||||
|
width: 50,
|
||||||
|
className: 'text-center',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '链接',
|
label: '链接',
|
||||||
@@ -52,6 +58,9 @@ function siteTab() {
|
|||||||
type: 'editor',
|
type: 'editor',
|
||||||
name: 'source',
|
name: 'source',
|
||||||
language: 'json',
|
language: 'json',
|
||||||
|
options: {
|
||||||
|
wordWrap: 'on',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user