<?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.mapper.DepartmentMapper">
    <resultMap id="oneMore" type="com.pojo.dto.DepartmentVO">
        <id property="depId" column="dep_id"></id>
        <result property="depName" column="dep_name"></result>
        <collection property="accountEntities" ofType="com.pojo.entity.AccountRealEntity">
            <id property="id" column="id"></id>
            <result property="userName" column="user_name"></result>
            <result property="balance" column="balance"></result>
            <result property="depId" column="dep_id"></result>
        </collection>
    </resultMap>
    <resultMap id="findByStep" type="com.pojo.dto.DepartmentVO">
        <id property="depId" column="dep_id"></id>
        <result property="depName" column="dep_name"></result>
        <collection property="accountEntities"
                    select="com.mapper.AccountMapper.findByDepId"
                    fetchType="lazy"
                    column="dep_id">
        </collection>
    </resultMap>


    <select id="findById" parameterType="java.lang.Integer" resultType="com.pojo.entity.DepartmentEntity">
        select * from department where dep_id = #{depId}
    </select>

    <select id="findByStep" parameterType="java.lang.Integer" resultMap="findByStep">
        select * from department where dep_id = #{depId}
    </select>

    <select id="oneFindMore" parameterType="java.lang.Integer" resultMap="oneMore">
        select a.*,b.* from department a left join account b on a.dep_id = b.dep_id
        where a.dep_id = #{id1}
    </select>

</mapper>
