point-user-mapper.xml 2.15 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">

<!-- @author tongxiaochuan -->
<mapper namespace="com.cjs.cms.dao.user.point.PointUserDao">

	<sql id="point_rule_field">
		id, user_id, otc_code,otc_name,point_amount 
	</sql>
	
	<sql id="searchCondition">
	    where 1=1
		<if test="userId != null and userId != ''"> and user_id=#{userId} </if>
		<if test="otcCode != null and otcCode != ''"> and otc_code=#{otcCode} </if>
	</sql>

	<insert id="insert" parameterType="PointUserInfo" useGeneratedKeys="true" keyProperty="id">
		insert into point_user(user_id, point_amount) 
		values(#{userId}, #{pointAmount})
	</insert>
	
	<update id="update" parameterType="PointUserInfo">
		update point_user set point_amount = #{pointAmount} 
		where user_id = #{userId}
	</update>
	
	<!-- 增加积分 -->
	<update id="addPoint">
		update point_user set point_amount = point_amount + #{occurPoint}
		where user_id = #{userId}
		<if test="otcCode != null and otcCode != ''"> and otc_code=#{otcCode} </if>
	</update>

	<select id="queryByUserId" parameterType="string" resultType="PointUserInfo">
		select <include refid="point_rule_field" /> from point_user 
		where user_id = #{userId} 
	</select>
	
	<select id="queryByUserIdAndCode" parameterType="string" resultType="PointUserInfo">
		select <include refid="point_rule_field" /> from point_user 
		where user_id = #{userId} and otc_code=#{otcCode}
	</select>

	<select id="search" parameterType="map" resultType="PointUserInfo">
		select <include refid="point_rule_field" />
		from point_user
		<include refid="searchCondition" />
		<if test="orderBy == 0 "> 
		order by point_amount asc
		</if>
		<if test="orderBy == 1 "> 
		order by point_amount desc
		</if>
		<include refid="common.pageLimit" />
	</select>
	<select id="searchTotal" parameterType="map" resultType="int">
		select count(*)
		from point_user
		<include refid="searchCondition" />
	</select>
	
	<select id="searchPointAmount" parameterType="map" resultType="double">
	    select IFNULL(sum(point_amount),0)
	    from point_user
		<include refid="searchCondition" />
	</select>
	
</mapper>