CommonMapper.xml 5.75 KB
<?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.hotent.base.dao.CommonDao">
	<cache/>
	<select id="query" parameterType="java.util.Map" resultType="java.util.HashMap">
		${sql} 
	</select>
	
	<select id="queryByPage" parameterType="java.util.Map" resultType="java.util.HashMap">
		${sql} 
	</select>
	
	<select id="queryByQueryFilter" parameterType="java.util.Map" resultType="java.util.HashMap">
		${sql} ${ew.customSqlSegment}
	</select>

	<select id="queryByCustomSql" parameterType="java.util.Map" resultType="java.util.HashMap">
		${sql} 
	    <if test="@com.hotent.base.ognl.Ognl@containsWhere(sql) and  @com.hotent.base.ognl.Ognl@isNotEmpty(@com.hotent.base.ognl.Ognl@withOutWhere(@com.hotent.base.ognl.Ognl@insertBeforeOrderBy(ew.customSqlSegment,ew.paramNameValuePairs.filterSql)))">
			<!--mybatisPlus的sql带where(表明有查询条件)|| 追加过滤sql不为空。用and拼接.-->
			<if test="@com.hotent.base.ognl.Ognl@containsWhere(ew.customSqlSegment) or @com.hotent.base.ognl.Ognl@isNotEmpty(ew.paramNameValuePairs.filterSql)">
				and
			</if>
			<!--本身的sql里面带有where,则去掉拼接sql里面的where-->
		    ${@com.hotent.base.ognl.Ognl@withOutWhere( @com.hotent.base.ognl.Ognl@insertBeforeOrderBy(ew.customSqlSegment,ew.paramNameValuePairs.filterSql))}
		</if>
		<if test="!@com.hotent.base.ognl.Ognl@containsWhere(sql)">
			${@com.hotent.base.ognl.Ognl@insertBeforeOrderBy(ew.customSqlSegment,ew.paramNameValuePairs.filterSql)}
		</if>
	</select>
	
	<insert id ="batchInsert" parameterType="java.util.Map">
        insert into ${tableName} (${insertFields}) values
        <foreach collection="valueList" item="item" index="index" separator=","  >
            (
           <foreach collection="item.keys" item="key" index="j" open="" close="" separator="," >
	         ${@com.hotent.base.ognl.Ognl@encodeValue(valueList,index,key)}
			</foreach>
            )
        </foreach>
    </insert >

	<insert id="batchInsert4Oracle" parameterType="java.util.Map" statementType="CALLABLE">
		<foreach collection="valueList" item="item" index="index" separator=";" open="begin" close=";end;" >
			insert into ${tableName} (${insertFields}) values
			(
			<foreach collection="item.keys" item="key" index="j" open="" close="" separator="," >
				${@com.hotent.base.ognl.Ognl@encodeValue(valueList,index,key)}
			</foreach>
			)
		</foreach>
	</insert>
    
    <update id="batchUpdate" parameterType="java.util.List" >
		<foreach collection="valueList" item="mapParam" index="index" open="" close="" separator=";">
			update ${tableName}
	         set
	         <foreach collection="mapParam.keys" item="key" open="" close="" separator=",">
				${key} = ${@com.hotent.base.ognl.Ognl@encodeValue(valueList,index,key)}
			</foreach>
	         where ${pkField} = #{valueList[${index}].${pkField}}
	         
	         <if test="!ignoreDataVersion and @com.hotent.base.ognl.Ognl@containsKey(valueList,index,'form_data_rev_')">
	         	and (form_data_rev_ = ${@com.hotent.base.ognl.Ognl@getOldFormDataRev(valueList,index,'form_data_rev_')} or form_data_rev_ is null)
	         </if>
	         <if test="!ignoreDataVersion and @com.hotent.base.ognl.Ognl@containsKey(valueList,index,'f_form_data_rev_')">
	         	and (f_form_data_rev_ = ${@com.hotent.base.ognl.Ognl@getOldFormDataRev(valueList,index,'f_form_data_rev_')} or f_form_data_rev_ is null)
	         </if>
	         
		</foreach>
	</update>
	
	<delete id="batchDelete" parameterType="java.util.List" >
		delete from ${tableName}  where ${pkField} in
		<foreach collection="pkValues" item="pkValue" index="index" open="(" close=")" separator=",">
			#{pkValue}
		</foreach>
	</delete>
	
	<update id="updateByCustom">
        update ${tableName}
         set
         <foreach collection="mapParam.keys" item="key" open="" close=""
			separator=",">
			${key} = #{mapParam[${key}]}
		</foreach>
         where ${pkField}=#{mapParam[${pkField}]}
    </update>

	<select id="documentationQueryByField" resultType="java.util.HashMap">
		SELECT * FROM ${tableName} WHERE ${pkField} IN
		<foreach collection="pkValues" item="pkValue" open="(" close=")" separator=",">
			#{pkValue}
		</foreach>
	</select>

	<select id="documentationQuery"  resultType="java.util.HashMap">
		${sql}
	</select>

	<insert id ="documentationBatchInsert" parameterType="java.util.Map">
		insert into ${tableName} (${insertFields}) values
		<foreach collection="valueList" item="item" index="index" separator=","  >
			(
			<foreach collection="item.keys" item="key" index="j" open="" close="" separator="," >
				${@com.hotent.base.ognl.Ognl@documentationEncodeValue(valueList,index,j,insertFields)}
			</foreach>
			)
		</foreach>
	</insert >

	<insert id ="documentationInsert" parameterType="java.util.Map">
		insert into ${tableName} (${insertFields}) values
		(
		<foreach collection="mapValue.keys" item="key" index="index" open="" close="" separator="," >
			${@com.hotent.base.ognl.Ognl@documentationEncodeValue(mapValue,index,insertFields)}
		</foreach>
		)
	</insert >

	<insert id ="documentationBatchInsert" databaseId="oracle"  parameterType="java.util.Map">
		insert into ${tableName} (${insertFields}) values
		<foreach collection="valueList" item="item" index="index" separator=","  >
			(
			<foreach collection="item.keys" item="key" index="j" open="" close="" separator="," >
				${@com.hotent.base.ognl.Ognl@documentationOracleEncodeValue(valueList,index,j,insertFields)}
			</foreach>
			)
		</foreach>
	</insert >

	<delete id="documentationBatchDelete" parameterType="java.util.List" >
		delete from ${tableName}  where ${pkField} in
		<foreach collection="pkValues" item="pkValue" index="index" open="(" close=")" separator=",">
			#{pkValue}
		</foreach>
	</delete>

</mapper>