<?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.leromro.core.mapper.VolunteerInfoMapper">

    <resultMap type="VolunteerInfo" id="VolunteerInfoResult">
        <result property="volunteerInfoId"    column="volunteer_info_id"    />
        <result property="volunteerId"    column="volunteer_id"    />
        <result property="name"    column="name"    />
        <result property="idCard"    column="id_card"    />
        <result property="score"    column="score"    />
        <result property="serviceCategory"    column="service_category"    />
        <result property="skillDescribe"    column="skill_describe"    />
        <result property="phonenumber"    column="phonenumber"    />
        <result property="sex"    column="sex"    />
        <result property="status"    column="status"    />
        <result property="idCardPicture"    column="id_card_picture"    />
        <result property="certificationPicture"    column="certification_picture"    />
        <result property="volunteerPicture"    column="volunteer_picture"    />
        <result property="city"    column="city"    />
        <result property="address"    column="address"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectLVolunteerInfoVo">
        select volunteer_id, name, id_card, score, service_category, skill_describe, phonenumber, sex, status, id_card_picture, certification_picture, volunteer_picture, worked_company, level, is_on_job, city, address, create_time, update_time, remark from l_volunteer_info
    </sql>


    <insert id="newVolunteerByUserId">
        INSERT INTO l_volunteer_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="volunteerId != null">volunteer_id,</if>
            <if test="name != null">name,</if>
            <if test="idCard != null">id_card,</if>
            <if test="idCardPicture != null">id_card_picture,</if>
            <if test="serviceCategory != null">service_category,</if>
            <if test="skillDescribe != null">skill_describe,</if>
            <if test="phonenumber != null">phonenumber,</if>
            <if test="sex != null">sex,</if>
            <if test="age != null">age,</if>
            <if test="status != null">status,</if>
            <if test="certificationPicture != null">certification_picture,</if>
            <if test="volunteerPicture != null">volunteer_picture,</if>
            <if test="city != null">city,</if>
            <if test="address != null">address,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
        </trim>
        VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="volunteerId != null">#{volunteerId},</if>
            <if test="name != null">#{name},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="idCardPicture != null">#{idCardPicture},</if>
            <if test="serviceCategory != null">#{serviceCategory},</if>
            <if test="skillDescribe != null">#{skillDescribe},</if>
            <if test="phonenumber != null">#{phonenumber},</if>
            <if test="sex != null">#{sex},</if>
            <if test="age != null">#{age},</if>
            <if test="status != null">#{status},</if>
            <if test="certificationPicture != null">#{certificationPicture},</if>
            <if test="volunteerPicture != null">#{volunteerPicture},</if>
            <if test="city != null">#{city},</if>
            <if test="address != null">#{address},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <select id="webList" resultType="com.leromro.core.domain.VolunteerInfo"
            parameterType="com.leromro.core.domain.VolunteerInfo">
        select * from l_volunteer_info
        <where>
            <if test="name != null  and name != ''"> and lvi.name like concat('%', #{name}, '%')</if>
            <if test="score != null "> and lvi.score = #{score}</if>
            <if test="serviceCategory != null "> and lvi.service_category = #{serviceCategory}</if>
            <if test="skillDescribe != null  and skillDescribe != ''"> and lvi.skill_describe = #{skillDescribe}</if>
            <if test="city != null  and city != ''"> and lvi.city = #{city}</if>
            <if test="appStatus != null  and appStatus != '' and appStatus == 1"> and app_status in (1,3)</if>
            <if test="appStatus != null  and appStatus != '' and appStatus == 2"> and app_status = 2</if>
        </where>
    </select>
    <select id="selectLVolunteerInfoByVolunteerId" resultType="com.leromro.core.domain.VolunteerInfo">
        select name , service_category , phonenumber,address ,skill_describe , age ,certification_picture ,volunteer_id ,score from l_volunteer_info
        where volunteer_id = #{volunteerId} and service_category = #{serviceCategory}
    </select>
    <select id="selectVolunteerInfoSimple" resultType="com.leromro.core.domain.vo.VolunteerInfoVO">
<!--  select volunteer_id, skill_describe,age ,service_category,name,volunteer_picture,score,lvi.business_management_id-->
<!--        from l_volunteer_info lvi left join l_business_management lbm on lvi.business_management_id = lbm.business_management_id-->
<!--        where app_status = 2-->
<!--        <if test="name != null  and name != ''"> and lvi.name like concat('%', #{name}, '%')</if>-->
<!--        <if test="score != null "> and lvi.score = #{score}</if>-->
<!--        <if test="serviceCategory != null and serviceCategory != ''"> and lvi.service_category = #{serviceCategory}</if>-->
<!--        <if test="skillDescribe != null  and skillDescribe != ''"> and lvi.skill_describe = #{skillDescribe}</if>-->
<!--        <if test="city != null  and city != ''"> and lvi.city = #{city}</if>-->
<!--        <if test="address != null  and address != ''"> and lvi.address = #{address}</if>-->
<!--        <if test="businessManagementId != null and businessManagementId != '' ">and lvi.business_management_id in (select lbm.business_management_id from l_business_management where find_in_set(#{businessManagementId},lbm.ancestors) ) or lvi.business_management_id = 28 </if>-->

        select volunteer_id, skill_describe,age ,service_category,name,volunteer_picture,score,business_management_id
        from l_volunteer_info lvi
        where app_status = 2
        and lvi.business_management_id in (select lbm.business_management_id from l_business_management lbm
            where find_in_set(#{businessManagementId},lbm.ancestors) or lbm.business_management_id = #{businessManagementId})

        <if test="name != null  and name != ''"> and lvi.name like concat('%', #{name}, '%')</if>
        <if test="score != null "> and lvi.score = #{score}</if>
        <if test="serviceCategory != null and serviceCategory != ''"> and lvi.service_category = #{serviceCategory}</if>
        <if test="skillDescribe != null  and skillDescribe != ''"> and lvi.skill_describe = #{skillDescribe}</if>
        <if test="city != null  and city != ''"> and lvi.city = #{city}</if>
        <if test="address != null  and address != ''"> and lvi.address = #{address}</if>


    </select>
    <select id="getCurrentOrgVolunteerList" resultType="com.leromro.core.domain.VolunteerInfo">
        select * from l_volunteer_info
        where app_status = 2
    </select>


</mapper>