<?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.zhongzheng.modules.base.mapper.ProfileTpMapper">

    <resultMap type="com.zhongzheng.modules.base.domain.ProfileTp" id="ProfileTpResult">
        <result property="profileTpId" column="profile_tp_id"/>
        <result property="name" column="name"/>
        <result property="code" column="code"/>
        <result property="status" column="status"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="keyValue" column="key_value"/>
        <result property="userIds" column="user_ids"/>
        <result property="keyValue2" column="key_value2"/>
        <result property="goodsIds" column="goods_ids"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.base.vo.ProfileTpVo" id="ProfileTpVoResult">
        <result property="profileTpId" column="profile_tp_id"/>
        <result property="name" column="name"/>
        <result property="code" column="code"/>
        <result property="status" column="status"/>
        <result property="keyValue" column="key_value"/>
        <result property="userIds" column="user_ids"/>
        <result property="keyValue2" column="key_value2"/>
        <result property="goodsIds" column="goods_ids"/>
        <collection property="businessList" column="profile_tp_id" select="findBusinessList"/>
        <collection property="userList" column="user_ids" select="findUserList"/>
    </resultMap>

    <resultMap type="com.zhongzheng.modules.base.vo.ProfileTpBusinessVo" id="ProfileTpBusiness">
        <result property="id" column="id"/>
        <result property="educationTypeId" column="education_type_id"/>
        <result property="businessId" column="business_id"/>
        <result property="projectId" column="project_id"/>

        <result property="educationName" column="education_name"/>
        <result property="projectName" column="project_name"/>
        <result property="businessName" column="business_name"/>
    </resultMap>

    <resultMap type="com.zhongzheng.common.core.domain.entity.SysUser" id="ProfileTpSysUser">
        <result property="userId" column="user_id"/>
        <result property="nickName" column="nick_name"/>
    </resultMap>

    <select id="findUserList" resultMap="ProfileTpSysUser">
        SELECT
            u.nick_name,
            u.user_id
        FROM
            sys_user u
        WHERE
            FIND_IN_SET( u.user_id, #{user_ids})
    </select>

    <select id="findBusinessList" resultMap="ProfileTpBusiness">
        SELECT
            b.education_type_id,
            b.id,
            b.business_id,
            b.project_id,
            cet.education_name,
            cpt.project_name,
            cb.business_name
        FROM
            profile_tp_business b
                LEFT JOIN course_education_type cet ON b.education_type_id = cet.id
                LEFT JOIN course_project_type cpt ON b.project_id = cpt.id
                LEFT JOIN course_business cb ON b.business_id = cb.id
        WHERE
            b.profile_tp_id=#{profile_tp_id}
    </select>

    <select id="selectList" parameterType="com.zhongzheng.modules.base.bo.ProfileTpQueryBo" resultMap="ProfileTpVoResult">
        SELECT
            *
        FROM
            profile_tp p
        WHERE
            1 =1
        <if test="status != null and status.size()!=0 ">
            AND p.status in
            <foreach collection="status" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="goodsId != null">
            and FIND_IN_SET(#{goodsId},p.goods_ids)
        </if>
        order by p.create_time desc
    </select>
</mapper>
