package com.lanyuanxiaoyao.digtal.market.service

import com.lanyuanxiaoyao.digtal.market.ArticleRepository
import jakarta.annotation.Resource
import org.jsoup.Jsoup
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service

@Service
class CleanService {
    private val logger = LoggerFactory.getLogger(javaClass)

    @Resource
    private lateinit var articleRepository: ArticleRepository

    fun cleanHtml() {
        articleRepository
            .findAllByHtmlIsNotNull()
            .forEach { article ->
                val html = article.html!!
                val document = Jsoup.parse(html)
                document.allElements.forEach { it.removeAttr("style") }
                article.html = document
                    .body()
                    .html()
                articleRepository.save(article)
            }
    }
}