package com.ruoyi.web.modules.prosperity.mapper;

import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

/**
 * 大屏项目查询 SQL 片段
 */
@DisplayName("BizCommonProsperityProjectMapper 大屏 SQL")
class BizCommonProsperityProjectMapperScreenXmlTest
{

    @Test
    @DisplayName("含 selectPublishedForScreen 与年份 distinct")
    void screenSqlPresent() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("selectPublishedForScreen"));
        assertTrue(xml.contains("screenPublishedWhere"));
        assertTrue(xml.contains("publish_status = 1"));
        assertTrue(xml.contains("selectDistinctStatYearsFromPublished"));
        assertTrue(xml.contains("selectPublishedTypeDetailsByYear"));
        assertTrue(xml.contains("heMeiVillageCount"));
    }

    private static String readMapperXml()
    {
        try (InputStream in = BizCommonProsperityProjectMapperScreenXmlTest.class.getClassLoader()
                .getResourceAsStream("mapper/prosperity/BizCommonProsperityProjectMapper.xml"))
        {
            if (in == null)
            {
                throw new IllegalStateException("mapper xml not found");
            }
            return IOUtils.toString(in, StandardCharsets.UTF_8);
        }
        catch (Exception ex)
        {
            throw new RuntimeException(ex);
        }
    }
}
