<?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.ylx.massage.mapper.MaProjectMapper">

    <resultMap type="MaProject" id="MaProjectResult">
        <result property="id"    column="id"    />
        <result property="projectName"    column="project_name"    />
        <result property="projectDescribe"    column="project_describe"    />
        <result property="projectDuration"    column="project_duration"    />
        <result property="projectUsersNum"    column="project_users_num"    />
        <result property="projectOriginalPrice"    column="project_original_price"    />
        <result property="projectCurrentPrice"    column="project_current_price"    />
        <result property="projectMasterImage"    column="project_master_image"    />
        <result property="projectDetailImage"    column="project_detail_image"    />
        <result property="projectIsEnable"    column="project_is_enable"    />
        <result property="createUser"    column="create_user"    />
        <result property="updateUser"    column="update_user"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDelete"    column="is_delete"    />
    </resultMap>

    <sql id="selectMaProjectVo">
        select id, project_name, project_describe, project_duration, project_users_num, project_original_price, project_current_price, project_master_image, project_detail_image, project_is_enable, create_user, update_user, create_time, update_time, is_delete from ma_project
    </sql>

    <select id="selectMaProjectList" parameterType="MaProject" resultMap="MaProjectResult">
        <include refid="selectMaProjectVo"/>
        <where>
            is_delete !=1
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="projectDescribe != null  and projectDescribe != ''"> and project_describe = #{projectDescribe}</if>
            <if test="projectDuration != null "> and project_duration = #{projectDuration}</if>
            <if test="projectUsersNum != null "> and project_users_num = #{projectUsersNum}</if>
            <if test="projectOriginalPrice != null "> and project_original_price = #{projectOriginalPrice}</if>
            <if test="projectCurrentPrice != null "> and project_current_price = #{projectCurrentPrice}</if>
            <if test="projectMasterImage != null  and projectMasterImage != ''"> and project_master_image = #{projectMasterImage}</if>
            <if test="projectDetailImage != null  and projectDetailImage != ''"> and project_detail_image = #{projectDetailImage}</if>
            <if test="projectIsEnable != null "> and project_is_enable = #{projectIsEnable}</if>
            <if test="createUser != null  and createUser != ''"> and create_user = #{createUser}</if>
            <if test="updateUser != null  and updateUser != ''"> and update_user = #{updateUser}</if>
        </where>
    </select>

    <select id="selectMaProjectById" parameterType="Long" resultMap="MaProjectResult">
        <include refid="selectMaProjectVo"/>
        where is_delete !=1 and id = #{id}
    </select>

    <insert id="insertMaProject" parameterType="MaProject" useGeneratedKeys="true" keyProperty="id">
        insert into ma_project
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="projectName != null and projectName != ''">project_name,</if>
            <if test="projectDescribe != null and projectDescribe != ''">project_describe,</if>
            <if test="projectDuration != null">project_duration,</if>
            <if test="projectUsersNum != null">project_users_num,</if>
            <if test="projectOriginalPrice != null">project_original_price,</if>
            <if test="projectCurrentPrice != null">project_current_price,</if>
            <if test="projectMasterImage != null and projectMasterImage != ''">project_master_image,</if>
            <if test="projectDetailImage != null and projectDetailImage != ''">project_detail_image,</if>
            <if test="projectIsEnable != null">project_is_enable,</if>
            <if test="createUser != null and createUser != ''">create_user,</if>
            <if test="updateUser != null and updateUser != ''">update_user,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDelete != null">is_delete,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="projectName != null and projectName != ''">#{projectName},</if>
            <if test="projectDescribe != null and projectDescribe != ''">#{projectDescribe},</if>
            <if test="projectDuration != null">#{projectDuration},</if>
            <if test="projectUsersNum != null">#{projectUsersNum},</if>
            <if test="projectOriginalPrice != null">#{projectOriginalPrice},</if>
            <if test="projectCurrentPrice != null">#{projectCurrentPrice},</if>
            <if test="projectMasterImage != null and projectMasterImage != ''">#{projectMasterImage},</if>
            <if test="projectDetailImage != null and projectDetailImage != ''">#{projectDetailImage},</if>
            <if test="projectIsEnable != null">#{projectIsEnable},</if>
            <if test="createUser != null and createUser != ''">#{createUser},</if>
            <if test="updateUser != null and updateUser != ''">#{updateUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDelete != null">#{isDelete},</if>
         </trim>
    </insert>

    <update id="updateMaProject" parameterType="MaProject">
        update ma_project
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectName != null and projectName != ''">project_name = #{projectName},</if>
            <if test="projectDescribe != null and projectDescribe != ''">project_describe = #{projectDescribe},</if>
            <if test="projectDuration != null">project_duration = #{projectDuration},</if>
            <if test="projectUsersNum != null">project_users_num = #{projectUsersNum},</if>
            <if test="projectOriginalPrice != null">project_original_price = #{projectOriginalPrice},</if>
            <if test="projectCurrentPrice != null">project_current_price = #{projectCurrentPrice},</if>
            <if test="projectMasterImage != null and projectMasterImage != ''">project_master_image = #{projectMasterImage},</if>
            <if test="projectDetailImage != null and projectDetailImage != ''">project_detail_image = #{projectDetailImage},</if>
            <if test="projectIsEnable != null">project_is_enable = #{projectIsEnable},</if>
            <if test="createUser != null and createUser != ''">create_user = #{createUser},</if>
            <if test="updateUser != null and updateUser != ''">update_user = #{updateUser},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteMaProjectById" parameterType="Long">
        update ma_project set is_delete = 1 where id = #{id}
    </update>

    <delete id="deleteMaProjectByIds" parameterType="String">
        delete from ma_project where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
