<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.base.system.param.dao.ibatis.ParamDaoImpl">
    
	<!-- 字段和属性映射 -->
	<resultMap type="ParamEntity" id="ParamEntity-Map">
		<result property="id" column="id" />
		<result property="name" column="name" />
		<result property="firstOrganize" column="firstOrganize" />
		<result property="secondOrganize" column="secondOrganize" />
		<result property="paramKey" column="paramKey" />
		<result property="paramValue" column="paramValue" />
		<result property="validStatus" column="validStatus" />
		<result property="modStatus" column="modStatus" />
		<result property="displayType" column="displayType" />
		<result property="remark" column="remark" />
		<result property="createTime" column="createTime" />
		<result property="createUserId" column="createUserId" />
		<result property="createUserName" column="createUserName" />
	</resultMap>
	
	
	
	<!-- 表所有列 -->
	<sql id="_columns">
		<trim suffixOverrides="," suffix="">
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('id') or colPickMode == 1 and data.containsKey('id')))">
				a.id as id,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('name') or colPickMode == 1 and data.containsKey('name')))">
				a.name as name,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('firstOrganize') or colPickMode == 1 and data.containsKey('firstOrganize')))">
				a.firstOrganize as firstOrganize,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('secondOrganize') or colPickMode == 1 and data.containsKey('secondOrganize')))">
				a.secondOrganize as secondOrganize,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('paramKey') or colPickMode == 1 and data.containsKey('paramKey')))">
				a.paramKey as paramKey,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('paramValue') or colPickMode == 1 and data.containsKey('paramValue')))">
				a.paramValue as paramValue,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('validStatus') or colPickMode == 1 and data.containsKey('validStatus')))">
				a.validStatus as validStatus,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('modStatus') or colPickMode == 1 and data.containsKey('modStatus')))">
				a.modStatus as modStatus,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('displayType') or colPickMode == 1 and data.containsKey('displayType')))">
				a.displayType as displayType,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('remark') or colPickMode == 1 and data.containsKey('remark')))">
				a.remark as remark,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createTime') or colPickMode == 1 and data.containsKey('createTime')))">
				a.createTime as createTime,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createUserId') or colPickMode == 1 and data.containsKey('createUserId')))">
				a.createUserId as createUserId,
			</if>
			<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('createUserName') or colPickMode == 1 and data.containsKey('createUserName')))">
				a.createUserName as createUserName,
			</if>
		</trim>
	</sql>
	<!-- 新增 -->
	<insert id="insert" parameterType="ParamEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mortals_xhx_param 
		(name,firstOrganize,secondOrganize,paramKey,paramValue,
			validStatus,modStatus,displayType,remark,createTime,
			createUserId,createUserName
		)VALUES(#{name},#{firstOrganize},#{secondOrganize},#{paramKey},#{paramValue},
			#{validStatus},#{modStatus},#{displayType},#{remark},#{createTime},
			#{createUserId},#{createUserName})
	</insert>
	<!-- 批量新增 -->
	<insert id="insertBatch" parameterType="paramDto">
		insert into mortals_xhx_param 
		(name,firstOrganize,secondOrganize,paramKey,paramValue,
			validStatus,modStatus,displayType,remark,createTime,
			createUserId,createUserName
		)
		VALUES
		<foreach collection="data.dataList" item="item" index="index" separator="," >  
		(#{item.name},#{item.firstOrganize},#{item.secondOrganize},#{item.paramKey},#{item.paramValue},
			#{item.validStatus},#{item.modStatus},#{item.displayType},#{item.remark},#{item.createTime},
			#{item.createUserId},#{item.createUserName})
		</foreach>
	</insert>
	<!-- 根据ParamDto更新 -->
	<update id="update" parameterType="paramDto">
		update mortals_xhx_param as a
		   set
		   <trim suffixOverrides="," suffix="">
				<if test="(colPickMode==0 and data.containsKey('name')) or (colPickMode==1 and !data.containsKey('name'))">
					a.name=#{data.name},
				</if>
				<if test="(colPickMode==0 and data.containsKey('firstOrganize')) or (colPickMode==1 and !data.containsKey('firstOrganize'))">
					a.firstOrganize=#{data.firstOrganize},
				</if>
				<if test="(colPickMode==0 and data.containsKey('secondOrganize')) or (colPickMode==1 and !data.containsKey('secondOrganize'))">
					a.secondOrganize=#{data.secondOrganize},
				</if>
				<if test="(colPickMode==0 and data.containsKey('paramKey')) or (colPickMode==1 and !data.containsKey('paramKey'))">
					a.paramKey=#{data.paramKey},
				</if>
				<if test="(colPickMode==0 and data.containsKey('paramValue')) or (colPickMode==1 and !data.containsKey('paramValue'))">
					a.paramValue=#{data.paramValue},
				</if>
				<if test="(colPickMode==0 and data.containsKey('validStatus')) or (colPickMode==1 and !data.containsKey('validStatus'))">
					a.validStatus=#{data.validStatus},
				</if>
				<if test="(colPickMode==0 and data.containsKey('validStatusIncrement')) or (colPickMode==1 and !data.containsKey('validStatusIncrement'))">
					a.validStatus=ifnull(a.validStatus,0) + #{data.validStatusIncrement},
				</if>
				<if test="(colPickMode==0 and data.containsKey('modStatus')) or (colPickMode==1 and !data.containsKey('modStatus'))">
					a.modStatus=#{data.modStatus},
				</if>
				<if test="(colPickMode==0 and data.containsKey('modStatusIncrement')) or (colPickMode==1 and !data.containsKey('modStatusIncrement'))">
					a.modStatus=ifnull(a.modStatus,0) + #{data.modStatusIncrement},
				</if>
				<if test="(colPickMode==0 and data.containsKey('displayType')) or (colPickMode==1 and !data.containsKey('displayType'))">
					a.displayType=#{data.displayType},
				</if>
				<if test="(colPickMode==0 and data.containsKey('displayTypeIncrement')) or (colPickMode==1 and !data.containsKey('displayTypeIncrement'))">
					a.displayType=ifnull(a.displayType,0) + #{data.displayTypeIncrement},
				</if>
				<if test="(colPickMode==0 and data.containsKey('remark')) or (colPickMode==1 and !data.containsKey('remark'))">
					a.remark=#{data.remark},
				</if>
				<if test="(colPickMode==0 and data.containsKey('createTime')) or (colPickMode==1 and !data.containsKey('createTime'))">
					a.createTime=#{data.createTime},
				</if>
				<if test="(colPickMode==0 and data.containsKey('createUserId')) or (colPickMode==1 and !data.containsKey('createUserId'))">
					a.createUserId=#{data.createUserId},
				</if>
				<if test="(colPickMode==0 and data.containsKey('createUserIdIncrement')) or (colPickMode==1 and !data.containsKey('createUserIdIncrement'))">
					a.createUserId=ifnull(a.createUserId,0) + #{data.createUserIdIncrement},
				</if>
				<if test="(colPickMode==0 and data.containsKey('createUserName')) or (colPickMode==1 and !data.containsKey('createUserName'))">
					a.createUserName=#{data.createUserName},
				</if>
		    </trim>
		   <trim suffixOverrides="where" suffix="">
			    where
			    <trim prefixOverrides="and" prefix="">
					<include refid="_condition_"/>
			   	</trim>
			</trim>
	</update>

	<!-- 根据主健查询 -->
	<select id="getByKey" parameterType="paramDto" resultMap="ParamEntity-Map">
		select <include refid="_columns"/>
		from mortals_xhx_param as a
	   where a.id=#{condition.id}
	</select>
	<!-- 根据主健删除 -->
	<delete id="deleteByKey" parameterType="paramDto">
		delete a.* from mortals_xhx_param as a where a.id=#{condition.id}
	</delete>
	<!-- 根据主健删除一批，针对单一主健有效 -->
	<delete id="deleteByKeys">
		delete from mortals_xhx_param where id in
		<foreach collection="array" item="item" index="index" open="(" separator="," close=")">
			#{item}
		</foreach>
	</delete>
	<!-- 根据paramDto删除一批 -->
	<delete id="deleteByMap" parameterType="paramDto">
		delete a.* from mortals_xhx_param as a
		<trim suffixOverrides="where" suffix="">
			 where 
			<trim prefixOverrides="and" prefix="">
				<include refid="_condition_"/>
			</trim>
		</trim>
	</delete>
	<!-- 获取列表 -->
	<select id="getList" parameterType="paramDto" resultMap="ParamEntity-Map">
		select <include refid="_columns"/>
		  from mortals_xhx_param as a
		 <trim suffixOverrides="where" suffix="">
			 where 
			 <trim prefixOverrides="and" prefix="">
			 	<include refid="_condition_"/>
			 </trim>
		 </trim>
		 <include refid="_orderCols_"/>
	</select>
	<!-- 获取 -->
	<select id="getListCount" parameterType="paramDto" resultType="int">
		select count(1)
		  from mortals_xhx_param as a
		 <trim suffixOverrides="where" suffix="">
			 where 
			 <trim prefixOverrides="and" prefix="">
				<include refid="_condition_"/>
			</trim>
		</trim>
	</select>
	
	<!-- 条件映射 -->
	<sql id="_condition_">
		<if test="condition != null and !condition.isEmpty()">
				<if test="condition.containsKey('id')">
					<if test="condition.id != null">
						and a.id=#{condition.id}
					</if>
				</if>
				<if test="condition.containsKey('id')">
					<if test="condition.id != null ">
						and a.id = #{condition.id}
					</if>
					<if test="condition.id == null">
						and a.id is null
					</if>
				</if>
				<if test="condition.containsKey('idList')">
					 and a.id in 
					<foreach collection="condition.idList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('idStart') and condition.idStart != null">
					<![CDATA[ and a.id >= #{condition.idStart} ]]>
				</if>
				<if test="condition.containsKey('idEnd') and condition.idEnd != null">
					<![CDATA[ and a.id <= #{condition.idEnd} ]]>
				</if>
				<if test="condition.containsKey('name')">
					<if test="condition.name != null and condition.name != ''">
						and a.name like #{condition.name}
					</if>
					<if test="condition.name == null">
						and a.name is null
					</if>
				</if>
				<if test="condition.containsKey('nameList')">
					 and a.name in 
					<foreach collection="condition.nameList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('firstOrganize')">
					<if test="condition.firstOrganize != null and condition.firstOrganize != ''">
						and a.firstOrganize like #{condition.firstOrganize}
					</if>
					<if test="condition.firstOrganize == null">
						and a.firstOrganize is null
					</if>
				</if>
				<if test="condition.containsKey('firstOrganizeList')">
					 and a.firstOrganize in 
					<foreach collection="condition.firstOrganizeList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('secondOrganize')">
					<if test="condition.secondOrganize != null and condition.secondOrganize != ''">
						and a.secondOrganize like #{condition.secondOrganize}
					</if>
					<if test="condition.secondOrganize == null">
						and a.secondOrganize is null
					</if>
				</if>
				<if test="condition.containsKey('secondOrganizeList')">
					 and a.secondOrganize in 
					<foreach collection="condition.secondOrganizeList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('paramKey')">
					<if test="condition.paramKey != null and condition.paramKey != ''">
						and a.paramKey like #{condition.paramKey}
					</if>
					<if test="condition.paramKey == null">
						and a.paramKey is null
					</if>
				</if>
				<if test="condition.containsKey('paramKeyList')">
					 and a.paramKey in 
					<foreach collection="condition.paramKeyList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('paramValue')">
					<if test="condition.paramValue != null and condition.paramValue != ''">
						and a.paramValue like #{condition.paramValue}
					</if>
					<if test="condition.paramValue == null">
						and a.paramValue is null
					</if>
				</if>
				<if test="condition.containsKey('paramValueList')">
					 and a.paramValue in 
					<foreach collection="condition.paramValueList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('validStatus')">
					<if test="condition.validStatus != null ">
						and a.validStatus = #{condition.validStatus}
					</if>
					<if test="condition.validStatus == null">
						and a.validStatus is null
					</if>
				</if>
				<if test="condition.containsKey('validStatusList')">
					 and a.validStatus in 
					<foreach collection="condition.validStatusList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('validStatusStart') and condition.validStatusStart != null">
					<![CDATA[ and a.validStatus >= #{condition.validStatusStart} ]]>
				</if>
				<if test="condition.containsKey('validStatusEnd') and condition.validStatusEnd != null">
					<![CDATA[ and a.validStatus <= #{condition.validStatusEnd} ]]>
				</if>
				<if test="condition.containsKey('modStatus')">
					<if test="condition.modStatus != null ">
						and a.modStatus = #{condition.modStatus}
					</if>
					<if test="condition.modStatus == null">
						and a.modStatus is null
					</if>
				</if>
				<if test="condition.containsKey('modStatusList')">
					 and a.modStatus in 
					<foreach collection="condition.modStatusList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('modStatusStart') and condition.modStatusStart != null">
					<![CDATA[ and a.modStatus >= #{condition.modStatusStart} ]]>
				</if>
				<if test="condition.containsKey('modStatusEnd') and condition.modStatusEnd != null">
					<![CDATA[ and a.modStatus <= #{condition.modStatusEnd} ]]>
				</if>
				<if test="condition.containsKey('displayType')">
					<if test="condition.displayType != null ">
						and a.displayType = #{condition.displayType}
					</if>
					<if test="condition.displayType == null">
						and a.displayType is null
					</if>
				</if>
				<if test="condition.containsKey('displayTypeList')">
					 and a.displayType in 
					<foreach collection="condition.displayTypeList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('displayTypeStart') and condition.displayTypeStart != null">
					<![CDATA[ and a.displayType >= #{condition.displayTypeStart} ]]>
				</if>
				<if test="condition.containsKey('displayTypeEnd') and condition.displayTypeEnd != null">
					<![CDATA[ and a.displayType <= #{condition.displayTypeEnd} ]]>
				</if>
				<if test="condition.containsKey('remark')">
					<if test="condition.remark != null and condition.remark != ''">
						and a.remark like #{condition.remark}
					</if>
					<if test="condition.remark == null">
						and a.remark is null
					</if>
				</if>
				<if test="condition.containsKey('remarkList')">
					 and a.remark in 
					<foreach collection="condition.remarkList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('createTime')">
					<if test="condition.createTime != null ">
						and a.createTime = #{condition.createTime}
					</if>
					<if test="condition.createTime == null">
						and a.createTime is null
					</if>
				</if>
				<if test="condition.containsKey('createTimeStart') and condition.createTimeStart != null and condition.createTimeStart!=''">
					<![CDATA[ and a.createTime >= STR_TO_DATE(left(concat(#{condition.createTimeStart},' 00:00:00'),19),'%Y-%m-%d %k:%i:%s') ]]>
				</if>
				<if test="condition.containsKey('createTimeEnd') and condition.createTimeEnd != null and condition.createTimeEnd!=''">
					<![CDATA[ and a.createTime <= STR_TO_DATE(left(concat(#{condition.createTimeEnd},' 23:59:59'),19),'%Y-%m-%d %k:%i:%s') ]]>
				</if>
				<if test="condition.containsKey('createUserId')">
					<if test="condition.createUserId != null ">
						and a.createUserId = #{condition.createUserId}
					</if>
					<if test="condition.createUserId == null">
						and a.createUserId is null
					</if>
				</if>
				<if test="condition.containsKey('createUserIdList')">
					 and a.createUserId in 
					<foreach collection="condition.createUserIdList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
				<if test="condition.containsKey('createUserIdStart') and condition.createUserIdStart != null">
					<![CDATA[ and a.createUserId >= #{condition.createUserIdStart} ]]>
				</if>
				<if test="condition.containsKey('createUserIdEnd') and condition.createUserIdEnd != null">
					<![CDATA[ and a.createUserId <= #{condition.createUserIdEnd} ]]>
				</if>
				<if test="condition.containsKey('createUserName')">
					<if test="condition.createUserName != null and condition.createUserName != ''">
						and a.createUserName like #{condition.createUserName}
					</if>
					<if test="condition.createUserName == null">
						and a.createUserName is null
					</if>
				</if>
				<if test="condition.containsKey('createUserNameList')">
					 and a.createUserName in 
					<foreach collection="condition.createUserNameList" open="(" close=")" index="index" item="item" separator=",">
						#{item}
					</foreach>
				</if>
		</if>
	</sql>
	<sql id="_orderCols_">
		<if test="orderColList != null and !orderColList.isEmpty()">
	        order by
	        <trim suffixOverrides=","  suffix="">
				<foreach collection="orderColList" open="" close="" index="index" item="item" separator=",">
						${item.colName} ${item.sortKind}
				</foreach>
			</trim>
		</if>
		<if test="(orderColList == null or orderColList.isEmpty()) and orderCol != null and !orderCol.isEmpty()">
			order by
			<trim suffixOverrides=","  suffix="">
				<if test="orderCol.containsKey('id')">
					a.id
					<if test="orderCol.id!= null">
						${orderCol.id}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('name')">
					a.name
					<if test="orderCol.name!= null">
						${orderCol.name}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('firstOrganize')">
					a.firstOrganize
					<if test="orderCol.firstOrganize!= null">
						${orderCol.firstOrganize}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('secondOrganize')">
					a.secondOrganize
					<if test="orderCol.secondOrganize!= null">
						${orderCol.secondOrganize}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('paramKey')">
					a.paramKey
					<if test="orderCol.paramKey!= null">
						${orderCol.paramKey}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('paramValue')">
					a.paramValue
					<if test="orderCol.paramValue!= null">
						${orderCol.paramValue}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('validStatus')">
					a.validStatus
					<if test="orderCol.validStatus!= null">
						${orderCol.validStatus}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('modStatus')">
					a.modStatus
					<if test="orderCol.modStatus!= null">
						${orderCol.modStatus}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('displayType')">
					a.displayType
					<if test="orderCol.displayType!= null">
						${orderCol.displayType}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('remark')">
					a.remark
					<if test="orderCol.remark!= null">
						${orderCol.remark}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('createTime')">
					a.createTime
					<if test="orderCol.createTime!= null">
						${orderCol.createTime}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('createUserId')">
					a.createUserId
					<if test="orderCol.createUserId!= null">
						${orderCol.createUserId}
					</if>
					,
				</if>
				<if test="orderCol.containsKey('createUserName')">
					a.createUserName
					<if test="orderCol.createUserName!= null">
						${orderCol.createUserName}
					</if>
					,
				</if>
			</trim>
		</if>
	</sql>
	<sql id="_group_by_">
		<if test="groupList != null and !groupList.isEmpty()">
			GROUP BY
			<trim suffixOverrides=","  suffix="">
				<foreach collection="groupList" open="" close="" index="index" item="item" separator=",">
						${item}
				</foreach>
			</trim>
		</if>
	</sql>
</mapper>