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

@DisplayName("BizMedicalResourceMapper.xml")
class BizMedicalResourceMapperXmlTest
{

    @Test
    @DisplayName("列表筛选与排序")
    void listSql() throws Exception
    {
        String xml = readMapperXml();
        assertTrue(xml.contains("resource_type = #{resourceType}"));
        assertTrue(xml.contains("resource_type = '004001'"));
        assertTrue(xml.contains("resource_type = '004003'"));
        assertTrue(xml.contains("resource_name like concat('%', #{resourceName}, '%')"));
        assertTrue(xml.contains("town_dept_id = #{townDeptId}"));
        assertTrue(xml.contains("offline_time is null"));
        assertTrue(xml.contains("offline_time is not null"));
        assertTrue(xml.contains("order by create_time desc, id desc"));
        assertTrue(xml.contains("del_flag = '0'"));
        assertTrue(xml.contains("selectVetResourceBySysUserId"));
        assertTrue(xml.contains("sys_user_id = #{sysUserId}"));
        assertTrue(xml.contains("account_assigned = 1"));
        assertTrue(xml.contains("countBySysUserId"));
        assertTrue(xml.contains("from biz_medical_resource"));
        assertTrue(xml.contains("town_dept_id"));
        assertTrue(xml.contains("town_name"));
    }

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