<?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">
<!-- 不使用namespace的话sql搜索定位会比较方便 -->
<mapper namespace="com.blueland.dao.PubOrgDao">
	<resultMap id="RM_PubOrgEntity" type="com.blueland.bo.PubOrgEntity">
        <result property="orgId" column="ORG_ID"/>
        <result property="orgName" column="ORG_NAME"/>
        <result property="orgFullName" column="ORG_FULL_NAME"/>
        <result property="orgFullPathName" column="ORG_FULL_PATH_NAME"/>
        <result property="orgFullPathId" column="ORG_FULL_PATH_ID"/>
        <result property="orgParentId" column="ORG_PARENT_ID"/>
        <result property="orgType" column="ORG_TYPE"/>
        <result property="orgLevel" column="ORG_LEVEL"/>
        <result property="orgAreaType" column="ORG_AREA_TYPE"/>
        <result property="orgSort" column="ORG_SORT"/>
        <result property="orgWorkPhone" column="ORG_WORK_PHONE"/>
        <result property="orgWorkAddress" column="ORG_WORK_ADDRESS"/>
        <result property="orgPrincipal" column="ORG_PRINCIPAL"/>
        <result property="orgStatus" column="ORG_STATUS"/>
        <result property="orgCreateTime" column="ORG_CREATE_TIME"/>
        <result property="remark" column="REMARK"/>
        <result property="fundCode" column="FUND_CODE"/>
        <result property="fundName" column="FUND_NAME"/>
        <result property="companyId" column="COMPANY_ID"/>
        <result property="deptId" column="DEPT_ID"/>
        <result property="deptName" column="DEPT_NAME"/>
        <result property="companyName" column="COMPANY_NAME"/>
        <result property="orgBranchLeader" column="ORG_BRANCH_LEADER"/>
	</resultMap>

	<sql id="PubOrgEntityColumns">
        	ORG_ID,
        	ORG_NAME,
        	ORG_FULL_NAME,
        	ORG_FULL_PATH_NAME,
        	ORG_FULL_PATH_ID,
        	ORG_PARENT_ID,
        	ORG_TYPE,
        	ORG_LEVEL,
        	ORG_AREA_TYPE,
        	ORG_SORT,
        	ORG_WORK_PHONE,
        	ORG_WORK_ADDRESS,
        	ORG_PRINCIPAL,
        	ORG_STATUS,
        	ORG_CREATE_TIME,
        	REMARK,
        	FUND_CODE,
        	FUND_NAME,
        	COMPANY_ID,
        	DEPT_ID,
        	DEPT_NAME,
        	COMPANY_NAME,
        	ORG_BRANCH_LEADER
	</sql>
	
	<sql id="PubOrgEntityQueryColumns">
        	ORG_ID,
        	ORG_NAME,
        	ORG_FULL_NAME,
        	ORG_FULL_PATH_NAME,
        	ORG_FULL_PATH_ID,
        	ORG_PARENT_ID,
        	ORG_TYPE,
        	ORG_LEVEL,
        	ORG_AREA_TYPE,
        	ORG_SORT,
        	ORG_WORK_PHONE,
        	ORG_WORK_ADDRESS,
        	ORG_PRINCIPAL,
        	ORG_STATUS,
        	ORG_CREATE_TIME,
        	REMARK,
        	FUND_CODE,
        	FUND_NAME,
        	COMPANY_ID,
        	DEPT_ID,
        	DEPT_NAME,
        	COMPANY_NAME,
        	ORG_BRANCH_LEADER
	</sql>
	<!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql -->
	<insert id="insert" useGeneratedKeys="false" keyProperty="orgId">
        INSERT INTO t_pub_org (<include refid="PubOrgEntityColumns"/>) VALUES (
        	#{orgId,jdbcType=VARCHAR},
        	#{orgName,jdbcType=VARCHAR},
        	#{orgFullName,jdbcType=VARCHAR},
        	#{orgFullPathName,jdbcType=VARCHAR},
        	#{orgFullPathId,jdbcType=VARCHAR},
        	#{orgParentId,jdbcType=VARCHAR},
        	#{orgType,jdbcType=VARCHAR},
        	#{orgLevel,jdbcType=INTEGER},
        	#{orgAreaType,jdbcType=VARCHAR},
        	#{orgSort,jdbcType=INTEGER},
        	#{orgWorkPhone,jdbcType=VARCHAR},
        	#{orgWorkAddress,jdbcType=VARCHAR},
        	#{orgPrincipal,jdbcType=VARCHAR},
        	#{orgStatus,jdbcType=VARCHAR},
        	#{orgCreateTime,jdbcType=TIMESTAMP},
        	#{remark,jdbcType=VARCHAR},
        	#{fundCode,jdbcType=VARCHAR},
        	#{fundName,jdbcType=VARCHAR},
        	#{companyId,jdbcType=VARCHAR},
        	#{deptId,jdbcType=VARCHAR},
        	#{deptName,jdbcType=VARCHAR},
        	#{companyName,jdbcType=VARCHAR},
        	#{orgBranchLeader,jdbcType=VARCHAR}
        )
	</insert>

    <select id="get" resultMap="RM_PubOrgEntity">
		SELECT <include refid="PubOrgEntityQueryColumns"/>
	    FROM t_pub_org 
        WHERE 
	        ORG_ID = #{orgId,jdbcType=VARCHAR} 
	</select>
	
    <!--
    	分页查询已经使用Dialect进行分页,也可以不使用Dialect直接编写分页
    	因为分页查询将传 offset,pageSize,lastRows 三个参数,不同的数据库可以根于此三个参数属性应用不同的分页实现
    -->
    <select id="findList" resultMap="RM_PubOrgEntity">
    	SELECT <include refid="PubOrgEntityQueryColumns"/>
	    FROM t_pub_org 
		<include refid="findList_where"/>
		
		<if test="@Ognl@isNotEmpty(bo.sortColumns)">
			ORDER BY ${bo.sortColumns}
		</if>
    </select>

	<select id="findPage" resultMap="RM_PubOrgEntity">
		SELECT <include refid="PubOrgEntityQueryColumns"/>
		FROM t_pub_org
		<include refid="findList_where"/>

		<if test="@Ognl@isNotEmpty(bo.sortColumns)">
			ORDER BY ${bo.sortColumns}
		</if>
	</select>
	
	<sql id="findList_where">
		<!-- ognl访问静态方法的表达式 为@class@method(args),以下为调用rapid中的Ognl.isNotEmpty()方法,还有其它方法如isNotBlank()可以使用，具体请查看Ognl类 -->
		<where>	      				
	       <if test="@Ognl@isNotEmpty(bo.orgId)">
				AND ORG_ID = #{bo.orgId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgName)">
				AND ORG_NAME = #{bo.orgName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgFullName)">
				AND ORG_FULL_NAME = #{bo.orgFullName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgFullPathName)">
				AND ORG_FULL_PATH_NAME = #{bo.orgFullPathName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgFullPathId)">
				AND ORG_FULL_PATH_ID = #{bo.orgFullPathId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgParentId)">
				AND ORG_PARENT_ID = #{bo.orgParentId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgType)">
				AND ORG_TYPE = #{bo.orgType,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgLevel)">
				AND ORG_LEVEL = #{bo.orgLevel,jdbcType=INTEGER}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgAreaType)">
				AND ORG_AREA_TYPE = #{bo.orgAreaType,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgSort)">
				AND ORG_SORT = #{bo.orgSort,jdbcType=INTEGER}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgWorkPhone)">
				AND ORG_WORK_PHONE = #{bo.orgWorkPhone,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgWorkAddress)">
				AND ORG_WORK_ADDRESS = #{bo.orgWorkAddress,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgPrincipal)">
				AND ORG_PRINCIPAL = #{bo.orgPrincipal,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgStatus)">
				AND ORG_STATUS = #{bo.orgStatus,jdbcType=VARCHAR}
			</if>
	       
	       <if test="@Ognl@isNotEmpty(bo.remark)">
				AND REMARK = #{bo.remark,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.fundCode)">
				AND FUND_CODE = #{bo.fundCode,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.fundName)">
				AND FUND_NAME = #{bo.fundName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.companyId)">
				AND COMPANY_ID = #{bo.companyId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.deptId)">
				AND DEPT_ID = #{bo.deptId,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.deptName)">
				AND DEPT_NAME = #{bo.deptName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.companyName)">
				AND COMPANY_NAME = #{bo.companyName,jdbcType=VARCHAR}
			</if>
	       <if test="@Ognl@isNotEmpty(bo.orgBranchLeader)">
				AND ORG_BRANCH_LEADER = #{bo.orgBranchLeader,jdbcType=VARCHAR}
			</if>
		</where>
	</sql>
    
	
</mapper>

