package com.cretin.webapi

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.cretin.webcore.utils.GsonGet
import com.cretin.webdb.entity.TbV2StrTranslateItem
import com.cretin.webdb.entity.TbV2StrTranslateProject
import com.cretin.webdb.self.ModuleConfigModel
import com.cretin.webdb.service.ITbV2StrTranslateItemService
import com.cretin.webdb.service.ITbV2StrTranslateProjectService
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
class WebApiApplicationTests {

    @Autowired
    private var tbV2StrTranslateItemService: ITbV2StrTranslateItemService? = null

    @Autowired
    private var tbV2StrTranslateProjectService: ITbV2StrTranslateProjectService? = null

    @Test
    fun contextLoads() {
        tbV2StrTranslateProjectService?.list()?.forEach {
            val items = tbV2StrTranslateItemService?.list(QueryWrapper<TbV2StrTranslateItem>().apply {
                this.eq("app_id", it.id)
                this.eq("item_channel", it.projectChannel)
            })
            if (items?.isEmpty() == false) {
                val moduleSet = items?.map { ModuleConfigModel(it.itemModule, true) }?.toMutableSet()
                it.projectModuleConfig = GsonGet.getGson().toJson(moduleSet)
                tbV2StrTranslateProjectService?.updateById(it)
            }
        }
    }

}
