<?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.cftech.mp.fans.dao.FanssgroupMapper">

	<resultMap id="resultMap" type="com.cftech.mp.fans.model.Fanssgroup">
		<id column="id" property="id"/>
		<result column="name" property="name"/>
		<result column="groupid" property="groupid"/>
		<result column="accountsid" property="accountsid"/>
		<result column="delflag" property="delflag"/>
		<result column="updatetime" property="updatetime"/>
		<result column="updateby" property="updateby"/>
		<result column="createtime" property="createtime"/>
		<result column="createby" property="createby"/>
	</resultMap>

	<sql id="sqlWhere">
		<if test="conds!=null">
			<trim prefix="WHERE" prefixOverrides="AND|OR">
				<foreach collection="conds.conds" index="index" item="cond">
					${cond.linkType}
					<if test="cond.condType == 'EQUAL'">${cond.param} = #{cond.value}</if>
					<if test="cond.condType == 'NOTEQUAL'">${cond.param} &lt;&gt; #{cond.value}</if>
					<if test="cond.condType == 'GREATEQUAL'">${cond.param} &gt;= #{cond.value}</if>
					<if test="cond.condType == 'GREATTHAN'">${cond.param} &gt; #{cond.value}</if>
					<if test="cond.condType == 'LESSEQUAL'">${cond.param} &lt;= #{cond.value}</if>
					<if test="cond.condType == 'LESSTHAN'">${cond.param} &lt; #{cond.value}</if>
					<if test="cond.condType == 'BETWEEN'">${cond.param} BETWEEN #{cond.startValue} AND #{cond.endValue}</if>
					<if test="cond.condType == 'ISNULL'">${cond.param} IS NULL</if>
					<if test="cond.condType == 'NOTNULL'">${cond.param} IS NOT NULL</if>
					<if test="cond.condType == 'LIKE'">${cond.param} LIKE #{cond.value}</if>
					<if test="cond.condType == 'IN'">${cond.param} IN
						<foreach item="item" index="index" collection="cond.value" open="(" separator="," close=")">
							#{item}
						</foreach>
					</if>
				</foreach>
			</trim>
		</if>
	</sql>

	<sql id="sqlColumns">
		id, name, groupid, accountsid, delflag, updatetime, updateby, createtime, createby
	</sql>

	<insert id="save" parameterType="com.cftech.mp.fans.model.Fanssgroup"  keyProperty="id">
		insert into wx_mp_fanssgroup
		(
		id, name, groupid, accountsid, delflag, updatetime, updateby, createtime, createby
		)
		values
		(
		#{id, jdbcType=BIGINT},  #{name, jdbcType=VARCHAR},  #{groupid, jdbcType=BIGINT},  #{accountsid, jdbcType=BIGINT},  
		#{delflag, jdbcType=CHAR},  now(),  #{updateby, jdbcType=BIGINT},  now(),#{createby, jdbcType=BIGINT}
		)
	</insert>

	<select id="fetchById" parameterType="java.lang.Long" resultMap="resultMap">
		SELECT <include refid="sqlColumns" /> FROM wx_mp_fanssgroup t
		WHERE t.id=#{id}
	</select>

	<select id="count" parameterType="java.util.Map" resultType="java.lang.Integer">
		SELECT COUNT(1)  FROM wx_mp_fanssgroup<include refid="sqlWhere" />
	</select>

	<select id="fetchSearchByPage" parameterType="java.util.Map" resultMap="resultMap">
		SELECT <include refid="sqlColumns" /> 
		FROM wx_mp_fanssgroup t
		<include refid="sqlWhere" />
		<if test="sort!=null">ORDER BY ${sort.param} ${sort.type}</if>
		<if test="limit>0">limit #{offset},#{limit}</if>
	</select>

	<update id="update" parameterType="com.cftech.mp.fans.model.Fanssgroup">
		update wx_mp_fanssgroup
		<set>
			<if test="id != null">
				id = #{id, jdbcType=BIGINT},
			</if>
			<if test="name != null">
				name = #{name, jdbcType=VARCHAR},
			</if>
			<if test="groupid != null">
				groupid = #{groupid, jdbcType=BIGINT},
			</if>
			<if test="accountsid != null">
				accountsid = #{accountsid, jdbcType=BIGINT},
			</if>
			<if test="delflag != null">
				delflag = #{delflag, jdbcType=CHAR},
			</if>
			<if test="updatetime != null">
				updatetime=now(),
			</if>
			<if test="updateby != null">
				updateby = #{updateby, jdbcType=BIGINT},
			</if>
			<if test="createtime != null">
				createtime = #{createtime, jdbcType=TIMESTAMP},
			</if>
			<if test="createby != null">
				createby = #{createby, jdbcType=BIGINT},
			</if>
		</set>
		where id=#{id,jdbcType=BIGINT}
	</update>

	<update id="delete" parameterType="java.lang.Long">
		update wx_mp_fanssgroup set delflag=1 where id=#{id,jdbcType=BIGINT}
	</update>

</mapper>