<?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.xintong.visualinspection.dao.master.MenuDao" >
    <resultMap id="BaseResultMap" type="com.xintong.visualinspection.bean.Menu" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="menuname" property="menuname" jdbcType="VARCHAR" />
        <result column="url" property="url" jdbcType="VARCHAR" />
        <result column="iconClass" property="iconClass" jdbcType="VARCHAR" />
        <result column="parentId" property="parentId" jdbcType="INTEGER" />
        <result column="type" property="type" jdbcType="INTEGER" />     
        <result column="sortNo" property="sortNo" jdbcType="INTEGER" />  
        <result column="status" property="status" jdbcType="INTEGER" />        
    </resultMap>

   <select id="getMenu" parameterType="com.xintong.visualinspection.bean.Menu" resultMap="BaseResultMap">
        SELECT 
        id,menuname,url,iconClass,parentId,type,sortNo,status 
         FROM sys_menu
         where status!=-1
         <if test="id != null and id != 0">and id = #{id}</if>
         <if test="menuname != null">and menuname = #{menuname}</if>
         <if test="iconClass != null">and iconClass = #{iconClass}</if>
         <if test="url != null">and url = #{url}</if>
         <if test="parentId != null and parentId != 0">and parentId = #{parentId}</if>
         <if test="type != null and type != 0">and type = #{type}</if>
         <if test="sortNo != null and sortNo != 0">and sortNo = #{sortNo}</if>
         <if test="status != null">and status = #{status}</if>
         order by sortNo,id
    </select>
    
	<select id="getMenuByParent" parameterType="com.xintong.visualinspection.bean.Menu" resultMap="BaseResultMap">
        SELECT 
        id,menuname,url,iconClass,parentId,type,sortNo,status 
         FROM sys_menu
         where status!=-1
         <if test="parentId != null and parentId != 0">and (parentId = #{parentId} or id = #{parentId})</if>
    	order by sortNo,id
    </select>
    
    <insert id="insert" parameterType="com.xintong.visualinspection.bean.Menu" >
        INSERT INTO
        sys_menu
        (menuname,url,iconClass,parentId,type,sortNo,status)
        VALUES
        (#{menuname},#{url},#{iconClass},#{parentId},#{type},#{sortNo},#{status})
    </insert>

    <update id="update" parameterType="com.xintong.visualinspection.bean.Menu" >
        UPDATE
        sys_menu
        SET
         id = #{id}
         <if test="menuname != null">, menuname = #{menuname}</if>
         <if test="iconClass != null">, iconClass = #{iconClass}</if>
         <if test="url != null">, url = #{url}</if>
         <if test="parentId != null and parentId != 0">, parentId = #{parentId}</if>
         <if test="type != null and type != 0">, type = #{type}</if>
         <if test="sortNo != null and sortNo != 0">, sortNo = #{sortNo}</if>
         <if test="status != null and status != 0">, status = #{status}</if>
        WHERE
        id = #{id}
    </update>

    <delete id="delete" parameterType="java.lang.Integer" >
        update sys_menu
         set status=-1
        WHERE
        id =#{id}
    </delete>
</mapper>