<?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.yeejoin.amos.patrol.business.dao.mapper.CatalogTreeMapper">
	<!--统计-巡检计划 -->
	<select id="countCatalogTreeData" resultType="long">
	 SELECT
		count(1) AS total_num
		FROM
		p_catalog_tree a <!-- ,
		s_user b,
		s_company d -->
	WHERE <!-- a.create_by = b.id and d.comp_code = a.org_code 	 -->1=1
	<if test="name!=null"> and a.name like concat(concat("%",#{name}),"%") </if>
	<if test="parentId!=null"> and a.parent_id = #{parentId}</if>
	<if test="orgCode!=null"> and a.org_Code like #{orgCode}</if>
	</select>
	<!--巡检计划查询 -->
	<select id="getCatalogTreePageInfo" resultType="java.util.HashMap">
		SELECT
				a.id,a.org_Code,a.name,a.parent_id parentId,a.create_by as createBy,
                   (select name from p_catalog_tree where id = a.parent_id) as parentName
				FROM
				p_catalog_tree a 
		where 1=1
        <if test="name!=null"> and a.name like concat(concat("%",#{name}),"%") </if>
		<if test="parentId!=null"> and  a.parent_id = #{parentId} </if>
		<if test="orgCode!=null"> and   a.org_Code like #{orgCode}</if>
		
		order by id desc
		<choose>
	     <when test="pageSize==-1"></when>
	     <when test="pageSize!=-1">limit #{offset},#{pageSize}</when>  
	    </choose>
	</select>
	
	<select id="countCatalognum" resultType="java.util.HashMap">
	 SELECT
		a.id,a.name
		FROM
		p_catalog_tree a 
		
	WHERE 1=1
	<if test="name!=null"> and a.name =#{name} </if>
	</select>
	
</mapper>