<?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.yyqh.mapper.YyqhGuidanceMapper">

    <resultMap type="YyqhGuidance" id="YyqhGuidanceResult">
        <id property="yyqhGuidanceId" column="yyqh_guidance_id"/>
        <result property="guidanceName" column="guidance_name"/>
        <result property="parentName" column="parent_name"/>
        <result property="parentId" column="parent_id"/>
        <result property="sequenceId" column="sequence_id"/>
        <result property="guidanceType" column="guidance_type"/>
        <result property="orderNum" column="order_num"/>
        <result property="submitTime" column="submit_time"/>
        <result property="remark" column="remark"/>
    </resultMap>
    <select id="selectGuidanceList" resultMap="YyqhGuidanceResult">
		select * from yyqh_guidance order by parent_id,order_num
	</select>
    <select id="selectGuidanceById" resultMap="YyqhGuidanceResult">
        SELECT yyqh_guidance_id,guidance_name,parent_id,sequence_id,guidance_type,order_num,submit_time,remark,(
        SELECT
        guidance_name FROM yyqh_guidance WHERE yyqh_guidance_id = yg.parent_id ) parent_name
        FROM
        yyqh_guidance yg
        WHERE
        yyqh_guidance_id = #{id}
    </select>
    <update id="updateGuidance" parameterType="com.yinet.yyqh.domain.YyqhGuidance">
        UPDATE yyqh_guidance
        SET
        guidance_name = #{guidance.guidanceName},
        parent_id=#{guidance.parentId},
        guidance_type=#{guidance.guidanceType},
        order_num=#{guidance.orderNum},
        sequence_id=#{guidance.sequenceId},
        submit_time=#{guidance.submitTime},
        remark=#{guidance.remark}
        WHERE
        yyqh_guidance_id = #{guidance.yyqhGuidanceId};
    </update>
    <insert id="insertGuidance" parameterType="com.yinet.yyqh.domain.YyqhGuidance">
        insert into
        yyqh_guidance(guidance_name,parent_id,sequence_id,guidance_type,order_num,submit_time,remark)
        VALUES (
        #{guidance.guidanceName},
        #{guidance.parentId},
        #{guidance.sequenceId},
        #{guidance.guidanceType},
        #{guidance.orderNum},
        #{guidance.submitTime},
        #{guidance.remark}
        )
    </insert>
    <select id="selectCountGuidanceByParentId" resultType="Integer">
        select count(1) from yyqh_guidance where parent_id=#{parentId}
    </select>
    <delete id="deleteGuidanceById" parameterType="Long">
        delete from yyqh_guidance where yyqh_guidance_id = #{guidanceId} or parent_id = #{guidanceId}
    </delete>
    <select id="selectParentGuidanceList" resultMap="YyqhGuidanceResult">
        select * from yyqh_guidance where parent_id=0 order by order_num
    </select>
    <select id="selectGuidanceByName" resultMap="YyqhGuidanceResult">
        select * from yyqh_guidance where guidance_name like concat('%', #{guidanceName}, '%')
    </select>
    <select id="selectGuidanceByParentId" resultMap="YyqhGuidanceResult">
        select * from yyqh_guidance where parent_id=#{parentId} order by order_num
    </select>
    <select id="selectGuidanceNotParentId" resultMap="YyqhGuidanceResult">
        select * from yyqh_guidance where parent_id!=#{parentId} or yyqh_guidance_id!=0 order by order_num
    </select>
</mapper>