package com.ruoyi.web.modules.epidemic.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;

/**
 * 单例配置 Mapper XML 结构检查
 */
@DisplayName("BizRiskFactorWeightMapper.xml")
class BizRiskFactorWeightMapperXmlTest
{

    @Test
    @DisplayName("upsert 更新全部五项权重字段")
    void updateAllWeightColumns() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("weight_breeding_density = #{weightBreedingDensity}"));
        assertTrue(xml.contains("weight_traffic_mobility = #{weightTrafficMobility}"));
        assertTrue(xml.contains("weight_quarantine_intensity = #{weightQuarantineIntensity}"));
        assertTrue(xml.contains("weight_meteorological_suitability = #{weightMeteorologicalSuitability}"));
        assertTrue(xml.contains("weight_past_disease_level = #{weightPastDiseaseLevel}"));
        assertTrue(xml.contains("where id = #{id}"));
    }

    private static String readMapperXml()
    {
        try (InputStream in = BizRiskFactorWeightMapperXmlTest.class.getClassLoader()
                .getResourceAsStream("mapper/epidemic/BizRiskFactorWeightMapper.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);
        }
    }
}
