<?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.yinet.system.mapper.TouchScreenGuidanceMapper">

    <resultMap type="TouchScreenGuidance" id="TouchScreenGuidanceResult">
        <id property="tsGuidanceId" column="ts_guidance_id"/>
        <result property="zName" column="zName"/>
        <result property="guidanceName" column="guidance_name"/>
        <result property="parentName" column="parent_name"/>
        <result property="parentId" column="parent_id"/>
        <result property="orderNum" column="order_num"/>
        <result property="iconUrl" column="icon_url"/>
        <result property="guidanceType" column="guidance_type"/>
        <result property="submitTime" column="submit_time"/>
        <result property="remark" column="remark"/>
    </resultMap>
    <select id="selectGuidanceList" resultMap="TouchScreenGuidanceResult">
		select * from touch_screen_guidance order by parent_id,order_num
	</select>
    <select id="selectTouchScreenGuidanceByGuidance" parameterType="TouchScreenGuidance" resultMap="TouchScreenGuidanceResult">
        select * from touch_screen_guidance
        <where>
            <if test="zName != null  and zeName != ''">and zName = #{zName}</if>
            <if test="guidanceName != null  and guidanceName != ''">and guidance_name = #{guidanceName}</if>
            <if test="parentId != null ">and parent_id = #{parentId}</if>
            <if test="orderNum != null ">and order_num = #{orderNum}</if>
            <if test="iconUrl != null  and iconUrl != ''">and icon_url = #{iconUrl}</if>
            <if test="guidanceType != null  and guidanceType != ''">and guidance_type = #{guidanceType}</if>
            <if test="submitTime != null ">and submit_time = #{submitTime}</if>
        </where>
    </select>
    <!--wx-->
    <!--<select id="selectGuidanceById" resultMap="TouchScreenGuidanceResult">
        SELECT ts_guidance_id, zName, guidance_name, parent_id, order_num,icon_url, guidance_type,
        submit_time, remark,(
        SELECT
        guidance_name FROM touch_screen_guidance WHERE ts_guidance_id = tsg.parent_id ) parent_name
        FROM
        touch_screen_guidance tsg
        WHERE
        ts_guidance_id = #{id}
    </select>-->
    <select id="selectGuidanceById" resultMap="TouchScreenGuidanceResult">
        SELECT ts_guidance_id, zName, guidance_name, parent_id, order_num,icon_url, guidance_type,
        submit_time, remark,(
        SELECT
        guidance_name FROM touch_screen_guidance WHERE ts_guidance_id = tsg.parent_id ) parent_name
        FROM
        touch_screen_guidance tsg
        WHERE
        ts_guidance_id = #{id}
    </select>

    <update id="updateGuidance" parameterType="com.yinet.system.domain.TouchScreenGuidance">
        UPDATE touch_screen_guidance
        SET
        zName = #{touchScreenGuidance.zName},
         guidance_name = #{touchScreenGuidance.guidanceName},
        parent_id=#{touchScreenGuidance.parentId},
        order_num=#{touchScreenGuidance.orderNum},
        icon_url=#{touchScreenGuidance.iconUrl},
        guidance_type=#{touchScreenGuidance.guidanceType},
        submit_time=#{touchScreenGuidance.submitTime},
        remark=#{touchScreenGuidance.remark}
        WHERE
        ts_guidance_id = #{touchScreenGuidance.tsGuidanceId};
    </update>
    <insert id="insertGuidance" parameterType="com.yinet.system.domain.TouchScreenGuidance">
        insert into
        touch_screen_guidance(ts_guidance_id,zName,guidance_name,parent_id,order_num,icon_url,guidance_type,submit_time,remark)
        VALUES (
        #{touchScreenGuidance.tsGuidanceId},
           #{touchScreenGuidance.zName},
        #{touchScreenGuidance.guidanceName},
        #{touchScreenGuidance.parentId},
        #{touchScreenGuidance.orderNum},
        #{touchScreenGuidance.iconUrl},
        #{touchScreenGuidance.guidanceType},
        sysdate(),
        #{touchScreenGuidance.remark}
        )
    </insert>
    <select id="selectCountGuidanceByParentId" resultType="Integer">
        select count(1) from touch_screen_guidance where parent_id=#{parentId}
    </select>
    <select id="selectCountGuidanceByParentId1" resultType="Integer">
        select count(1) from touch_screen_guidance where parent_id=#{parentId} and zName=#{zName}
    </select>
    <delete id="deleteGuidanceById" parameterType="String">
        delete from touch_screen_guidance where ts_guidance_id = #{guidanceId} or parent_id = #{guidanceId}
    </delete>
    <!--wx-->
    <select id="selectParentGuidanceList" resultMap="TouchScreenGuidanceResult">
        select * from touch_screen_guidance where parent_id=0 order by order_num
    </select>
<!--修改-->
    <select id="selectParentGuidance" resultMap="TouchScreenGuidanceResult">
        select * from touch_screen_guidance where parent_id=0 and zName=#{zName} order by order_num
    </select>

    <select id="selectGuidanceByName" resultMap="TouchScreenGuidanceResult">
        select * from touch_screen_guidance where guidance_name like concat('%', #{guidanceName}, '%')
    </select>
    <select id="selectGuidanceByParentId" resultMap="TouchScreenGuidanceResult">
        select * from touch_screen_guidance where parent_id=#{parentId} order by order_num
    </select>
<!---->
    <select id="selectGuidanceByParentId11" resultMap="TouchScreenGuidanceResult">
        select * from touch_screen_guidance where parent_id=0 order by order_num
    </select>

    <!--  正定-->
    <select id="selectGuidanceByzName" resultMap="TouchScreenGuidanceResult">
        select * from touch_screen_guidance where zName=#{zName}  order by order_num
    </select>

    <select id="selectGuidanceNotParentId" resultMap="TouchScreenGuidanceResult">
        select * from touch_screen_guidance where parent_id!=#{parentId} or ts_guidance_id!=0 order by order_num
    </select>



</mapper>