<?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="com.jeeplus.assess.program.serviceType.mapper.ProgramServiceTypeMapper">

    <resultMap id="BaseResultMap" type="com.jeeplus.assess.program.serviceType.service.dto.ProgramServiceTypeDTO">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="createBy.id" column="create_by" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_date" jdbcType="TIMESTAMP"/>
            <result property="updateBy.id" column="update_by" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_date" jdbcType="TIMESTAMP"/>
            <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
            <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="parentId" column="parent_id" jdbcType="VARCHAR"/>
            <result property="level" column="level" jdbcType="INTEGER"/>
            <result property="sort" column="sort" jdbcType="INTEGER"/>
            <result property="parentIds" column="parent_ids" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        pst.id,
        pst.create_by_id,
        pst.create_time,
        pst.update_by_id,
        pst.update_time,
        pst.del_flag,
        pst.remarks,
        pst.name,
        pst.parent_id,
        pst.level,
        pst.sort
    </sql>

    <select id="findList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from program_service_type pst
        ${ew.customSqlSegment}
    </select>

    <select id="queryById" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>
        from program_service_type pst
        where pst.del_flag = '0' and pst.id = #{id}
    </select>

    <select id="getList" resultMap="map">
        select
        <include refid="Base_Column_List"></include>
        from program_service_type pst
        where pst.del_flag = '0' and pst.parent_id = '0'
    </select>

    <resultMap id="map" type="com.jeeplus.assess.program.serviceType.service.dto.ProgramServiceTypeDTO">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="createBy.id" column="create_by" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_date" jdbcType="TIMESTAMP"/>
        <result property="updateBy.id" column="update_by" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_date" jdbcType="TIMESTAMP"/>
        <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
        <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="parentId" column="parent_id" jdbcType="VARCHAR"/>
        <result property="level" column="level" jdbcType="INTEGER"/>
        <result property="sort" column="sort" jdbcType="INTEGER"/>
        <result property="parentIds" column="parent_ids" jdbcType="VARCHAR"/>
        <collection property="childrenList" column="id" select="getChildList" ofType="com.jeeplus.assess.program.serviceType.service.dto.ProgramServiceTypeDTO"/>
    </resultMap>

    <select id="getChildList" resultType="com.jeeplus.assess.program.serviceType.service.dto.ProgramServiceTypeDTO">
        select
        <include refid="Base_Column_List"></include>
        from program_service_type pst
        where pst.del_flag = '0' and pst.parent_id = ${id}
    </select>

</mapper>
