<?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.xinelu.manage.mapper.servicepackagecontent.ServicePackageContentMapper">

    <resultMap type="ServicePackageContent" id="ServicePackageContentResult">
        <result property="id" column="id"/>
        <result property="servicePackageId" column="service_package_id"/>
        <result property="serviceWayName" column="service_way_name"/>
        <result property="serviceWayCode" column="service_way_code"/>
        <result property="serviceWayId" column="service_way_id"/>
        <result property="serviceContent" column="service_content"/>
        <result property="serviceContentId" column="service_content_id"/>
        <result property="serviceFrequencyText" column="service_frequency_text"/>
        <result property="serviceFrequencyStart" column="service_frequency_start"/>
        <result property="serviceFrequencyEnd" column="service_frequency_end"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectServicePackageContentVo">
        select id,
               service_package_id,
               service_way_name,
               service_way_code,
               service_way_id,
               service_content,
               service_content_id,
               service_frequency_text,
               service_frequency_start,
               service_frequency_end,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from service_package_content
    </sql>

    <select id="selectServicePackageContentList" parameterType="ServicePackageContent"
            resultMap="ServicePackageContentResult">
        <include refid="selectServicePackageContentVo"/>
        <where>
            <if test="servicePackageId != null ">
                and service_package_id =
                #{servicePackageId}
            </if>
            <if test="serviceWayName != null  and serviceWayName != ''">
                and service_way_name like concat('%',
                #{serviceWayName},
                '%'
                )
            </if>
            <if test="serviceWayCode != null  and serviceWayCode != ''">
                and service_way_code =
                #{serviceWayCode}
            </if>
            <if test="serviceWayId != null ">
                and service_way_id =
                #{serviceWayId}
            </if>
            <if test="serviceContent != null  and serviceContent != ''">
                and service_content =
                #{serviceContent}
            </if>
            <if test="serviceContentId != null ">
                and service_content_id =
                #{serviceContentId}
            </if>
            <if test="serviceFrequencyText != null  and serviceFrequencyText != ''">
                and service_frequency_text =
                #{serviceFrequencyText}
            </if>
            <if test="serviceFrequencyStart != null ">
                and service_frequency_start =
                #{serviceFrequencyStart}
            </if>
            <if test="serviceFrequencyEnd != null ">
                and service_frequency_end =
                #{serviceFrequencyEnd}
            </if>
        </where>
    </select>

    <select id="selectServicePackageContentById" parameterType="Long"
            resultMap="ServicePackageContentResult">
        <include refid="selectServicePackageContentVo"/>
        where id = #{id}
    </select>

    <select id="countByPackageIdAndServiceWayName" resultType="java.lang.Long">
        select id
        from service_package_content
        where service_package_id = #{id}
          and service_way_name = #{serviceWayName}
    </select>

    <select id="countByServiceWayIdAndServiceContent" resultType="java.lang.Long">
        select id
        from service_package_content
        where service_way_id = #{serviceWayId}
          and service_content = #{serviceContent}
    </select>

    <select id="countByServiceContentIdAndServiceFrequency" resultType="java.lang.Integer">
        select count(*)
        from service_package_content
        <where>
            <if test="serviceContentId != null ">
                and service_content_id =
                #{serviceContentId}
            </if>
            <if test="vo.serviceFrequencyText != null  and vo.serviceFrequencyText != ''">
                and service_frequency_text =
                #{vo.serviceFrequencyText}
            </if>
            <if test="vo.serviceFrequencyStart != null ">
                and service_frequency_start =
                #{vo.serviceFrequencyStart}
            </if>
            <if test="vo.serviceFrequencyEnd != null ">
                and service_frequency_end =
                #{vo.serviceFrequencyEnd}
            </if>
        </where>
    </select>

    <insert id="insertServicePackageContent" parameterType="ServicePackageContent" useGeneratedKeys="true"
            keyProperty="id">
        insert into service_package_content
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="servicePackageId != null">service_package_id,
            </if>
            <if test="serviceWayName != null">service_way_name,
            </if>
            <if test="serviceWayCode != null">service_way_code,
            </if>
            <if test="serviceWayId != null">service_way_id,
            </if>
            <if test="serviceContent != null">service_content,
            </if>
            <if test="serviceContentId != null">service_content_id,
            </if>
            <if test="serviceFrequencyText != null">service_frequency_text,
            </if>
            <if test="serviceFrequencyStart != null">service_frequency_start,
            </if>
            <if test="serviceFrequencyEnd != null">service_frequency_end,
            </if>
            <if test="remark != null">remark,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="servicePackageId != null">#{servicePackageId},
            </if>
            <if test="serviceWayName != null">#{serviceWayName},
            </if>
            <if test="serviceWayCode != null">#{serviceWayCode},
            </if>
            <if test="serviceWayId != null">#{serviceWayId},
            </if>
            <if test="serviceContent != null">#{serviceContent},
            </if>
            <if test="serviceContentId != null">#{serviceContentId},
            </if>
            <if test="serviceFrequencyText != null">#{serviceFrequencyText},
            </if>
            <if test="serviceFrequencyStart != null">#{serviceFrequencyStart},
            </if>
            <if test="serviceFrequencyEnd != null">#{serviceFrequencyEnd},
            </if>
            <if test="remark != null">#{remark},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateServicePackageContent" parameterType="ServicePackageContent">
        update service_package_content
        <trim prefix="SET" suffixOverrides=",">
            <if test="servicePackageId != null">service_package_id =
            #{servicePackageId},
            </if>
            <if test="serviceWayName != null">service_way_name =
            #{serviceWayName},
            </if>
            <if test="serviceWayCode != null">service_way_code =
            #{serviceWayCode},
            </if>
            <if test="serviceWayId != null">service_way_id =
            #{serviceWayId},
            </if>
            <if test="serviceContent != null">service_content =
            #{serviceContent},
            </if>
            <if test="serviceContentId != null">service_content_id =
            #{serviceContentId},
            </if>
            <if test="serviceFrequencyText != null">service_frequency_text =
            #{serviceFrequencyText},
            </if>
            <if test="serviceFrequencyStart != null">service_frequency_start =
            #{serviceFrequencyStart},
            </if>
            <if test="serviceFrequencyEnd != null">service_frequency_end =
            #{serviceFrequencyEnd},
            </if>
            <if test="remark != null">remark =
            #{remark},
            </if>
            <if test="createBy != null">create_by =
            #{createBy},
            </if>
            <if test="createTime != null">create_time =
            #{createTime},
            </if>
            <if test="updateBy != null">update_by =
            #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
            #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteServicePackageContentById" parameterType="Long">
        delete
        from service_package_content
        where id = #{id}
    </delete>

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

    <delete id="deleteServicePackageContentByPackageIds">
        delete from service_package_content where service_package_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteServicePackageContentByPackageId" parameterType="java.lang.Long">
        delete
        from service_package_content
        where service_package_id = #{id}
    </delete>


</mapper>