<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="pwc.taxtech.atms.dao.OrganizationServiceTemplateGroupMapper">

    <resultMap id="OrganizationServiceTemplateGroupDto" type="pwc.taxtech.atms.dpo.OrganizationServiceTemplateGroupDto">
        <id column="ID" jdbcType="VARCHAR" property="ID"/>
        <result column="SERVICE_TYPE_ID" jdbcType="VARCHAR" property="serviceTypeId"/>
        <result column="ORGANIZATION_ID" jdbcType="VARCHAR" property="organizationId"/>
        <result column="TEMPLATE_GROUP_ID" jdbcType="VARCHAR" property="templateGroupId"/>
        <result column="TEMPLATE_GROUP_NAME" jdbcType="VARCHAR" property="templateGroupName"/>
    </resultMap>

    <select id="getSingleOrgByOrgIDToOSTGDto" parameterType="map" resultMap="OrganizationServiceTemplateGroupDto">
        SELECT
        M.ID AS ID,
        M.SERVICE_TYPE_ID AS SERVICE_TYPE_ID,
        M.ORGANIZATION_ID AS ORGANIZATION_ID,
        M.TEMPLATE_GROUP_ID AS TEMPLATE_GROUP_ID,
        T.NAME AS TEMPLATE_GROUP_NAME
        FROM
        ORGANIZATION_SERVICE_TEMPLATE_GROUP AS M
        LEFT JOIN
        TEMPLATE_GROUP AS T
        ON
        M.TEMPLATE_GROUP_ID = T.ID
        WHERE
        M.ORGANIZATION_ID = #{ORGID}
        ORDER BY
        M.SERVICE_TYPE_ID
    </select>

    <select id="getOrgnizationServiceTemplateGroupOrgNames" parameterType="java.lang.Long" resultType="java.lang.String">
        SELECT
        Q.NAME
        FROM
        ORGANIZATION_SERVICE_TEMPLATE_GROUP P
        LEFT JOIN
        ORGANIZATION Q
        ON
        P.ORGANIZATION_ID = Q.ID
        WHERE
        P.TEMPLATE_GROUP_ID = #{TEMPLATEGROUPDTOID,JDBCTYPE=VARCHAR}
        AND Q.IS_ACTIVE = 1
    </select>

</mapper>