PointsAccountMapper.xml 10.9 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="cn.runsa.crmapp.points.mapper.PointsAccountMapper">
  <resultMap id="BaseResultMap" type="cn.runsa.crmapp.points.entity.PointsAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="PNT_ID" jdbcType="BIGINT" property="pntId" />
    <result column="ACT_ID" jdbcType="BIGINT" property="actId" />
    <result column="PNT_TYPE" jdbcType="VARCHAR" property="pntType" />
    <result column="PNT_NAME" jdbcType="VARCHAR" property="pntName" />
    <result column="CST_ID" jdbcType="BIGINT" property="cstId" />
    <result column="PNT_VAL" jdbcType="DOUBLE" property="pntVal" />
    <result column="TOTAL_ALL" jdbcType="DOUBLE" property="totalAll" />
    <result column="TOTAL_THIS" jdbcType="DOUBLE" property="totalThis" />
    <result column="S_TIME" jdbcType="TIMESTAMP" property="sTime" />
    <result column="E_TIME" jdbcType="TIMESTAMP" property="eTime" />
    <result column="PNT_UNIT" jdbcType="VARCHAR" property="pntUnit" />
    <result column="PNT_U_V" jdbcType="DECIMAL" property="pntUV" />
    <result column="REC_TIME" jdbcType="TIMESTAMP" property="recTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    `PNT_ID`, `ACT_ID`, `PNT_TYPE`, `CST_ID`, `PNT_VAL`, `TOTAL_ALL`, `TOTAL_THIS`, `S_TIME`, 
    `E_TIME`, `REC_TIME`
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from crm_points_account
    where `PNT_ID` = #{pntId,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from crm_points_account
    where `PNT_ID` = #{pntId,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="cn.runsa.crmapp.points.entity.PointsAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <selectKey keyProperty="pntId" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into crm_points_account (`PNT_ID`, `ACT_ID`, `PNT_TYPE`, 
      `CST_ID`, `PNT_VAL`, `TOTAL_ALL`, 
      `TOTAL_THIS`, `S_TIME`, `E_TIME`, 
      `REC_TIME`)
    values (#{pntId,jdbcType=BIGINT}, #{actId,jdbcType=BIGINT}, #{pntType,jdbcType=VARCHAR}, 
      #{cstId,jdbcType=BIGINT}, #{pntVal,jdbcType=DOUBLE}, #{totalAll,jdbcType=DOUBLE}, 
      #{totalThis,jdbcType=DOUBLE}, #{sTime,jdbcType=TIMESTAMP}, #{eTime,jdbcType=TIMESTAMP}, 
      #{recTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="cn.runsa.crmapp.points.entity.PointsAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <selectKey keyProperty="pntId" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into crm_points_account
    <trim prefix="(" suffix=")" suffixOverrides=",">
      `PNT_ID`,
      <if test="actId != null">
        `ACT_ID`,
      </if>
      <if test="pntType != null">
        `PNT_TYPE`,
      </if>
      <if test="cstId != null">
        `CST_ID`,
      </if>
      <if test="pntVal != null">
        `PNT_VAL`,
      </if>
      <if test="totalAll != null">
        `TOTAL_ALL`,
      </if>
      <if test="totalThis != null">
        `TOTAL_THIS`,
      </if>
      <if test="sTime != null">
        `S_TIME`,
      </if>
      <if test="eTime != null">
        `E_TIME`,
      </if>
      <if test="recTime != null">
        `REC_TIME`,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      #{pntId,jdbcType=BIGINT},
      <if test="actId != null">
        #{actId,jdbcType=BIGINT},
      </if>
      <if test="pntType != null">
        #{pntType,jdbcType=VARCHAR},
      </if>
      <if test="cstId != null">
        #{cstId,jdbcType=BIGINT},
      </if>
      <if test="pntVal != null">
        #{pntVal,jdbcType=DOUBLE},
      </if>
      <if test="totalAll != null">
        #{totalAll,jdbcType=DOUBLE},
      </if>
      <if test="totalThis != null">
        #{totalThis,jdbcType=DOUBLE},
      </if>
      <if test="sTime != null">
        #{sTime,jdbcType=TIMESTAMP},
      </if>
      <if test="eTime != null">
        #{eTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recTime != null">
        #{recTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="cn.runsa.crmapp.points.entity.PointsAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_points_account
    <set>
      <if test="actId != null">
        `ACT_ID` = #{actId,jdbcType=BIGINT},
      </if>
      <if test="pntType != null">
        `PNT_TYPE` = #{pntType,jdbcType=VARCHAR},
      </if>
      <if test="cstId != null">
        `CST_ID` = #{cstId,jdbcType=BIGINT},
      </if>
      <if test="pntVal != null">
        `PNT_VAL` = #{pntVal,jdbcType=DOUBLE},
      </if>
      <if test="totalAll != null">
        `TOTAL_ALL` = #{totalAll,jdbcType=DOUBLE},
      </if>
      <if test="totalThis != null">
        `TOTAL_THIS` = #{totalThis,jdbcType=DOUBLE},
      </if>
      <if test="sTime != null">
        `S_TIME` = #{sTime,jdbcType=TIMESTAMP},
      </if>
      <if test="eTime != null">
        `E_TIME` = #{eTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recTime != null">
        `REC_TIME` = #{recTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where `PNT_ID` = #{pntId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.runsa.crmapp.points.entity.PointsAccount">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_points_account
    set `ACT_ID` = #{actId,jdbcType=BIGINT},
      `PNT_TYPE` = #{pntType,jdbcType=VARCHAR},
      `CST_ID` = #{cstId,jdbcType=BIGINT},
      `PNT_VAL` = #{pntVal,jdbcType=DOUBLE},
      `TOTAL_ALL` = #{totalAll,jdbcType=DOUBLE},
      `TOTAL_THIS` = #{totalThis,jdbcType=DOUBLE},
      `S_TIME` = #{sTime,jdbcType=TIMESTAMP},
      `E_TIME` = #{eTime,jdbcType=TIMESTAMP},
      `REC_TIME` = #{recTime,jdbcType=TIMESTAMP}
    where `PNT_ID` = #{pntId,jdbcType=BIGINT}
  </update>
  
  <update id="updatePointsValue" parameterType="map">
	  update crm_points_account
      set `PNT_VAL` = `PNT_VAL` + #{account.pntVal,jdbcType=DOUBLE}
      <if test="updateTotal == true">
      ,`TOTAL_ALL` = `TOTAL_ALL`+ #{account.pntVal,jdbcType=DOUBLE}
      </if>
      where `PNT_ID` = #{account.pntId,jdbcType=BIGINT}
  </update>
  <select id="selectPointsAccount" parameterType="map" resultMap="BaseResultMap">
  	SELECT 
  	<include refid="Base_Column_List" />
  	FROM crm_points_account 
  	WHERE CST_ID = #{cstId} 
  	AND ACT_ID = #{actId} 
  	AND PNT_TYPE = #{pntType}
  </select>
  <select id="selectPoints" parameterType="map" resultMap="BaseResultMap">
  	SELECT a.`PNT_ID`,a.`ACT_ID`,a.`PNT_TYPE`,a.`PNT_VAL`,s.`PNT_SET_NAME` AS PNT_NAME,s.`PNT_UNIT`,s.`PNT_U_V`
	FROM crm_points_account a 
	RIGHT JOIN crm_points_set s  
	ON a.`ACT_ID`=s.`ACT_ID` 
	AND a.`PNT_TYPE` = s.`PNT_TYPE`
	WHERE a.`CST_ID`= #{cstId}
	<if test="sets !=null">
	AND a.`ACT_ID` IN
	<foreach collection="sets" open="(" close=")" item="it" separator=",">
	#{it}
	</foreach>
	</if>
	<if test="types !=null">
	AND a.`PNT_TYPE` IN
	<foreach collection="types" open="(" close=")" item="it" separator=",">
	#{it}
	</foreach>
	</if>
  </select>
  <select id="selectPointsAvaliable" parameterType="map" resultMap="BaseResultMap">
  	SELECT a.`PNT_ID`,a.`ACT_ID`,a.`PNT_TYPE`,SUM(i.`PNT_VAL`) AS PNT_VAL,s.`PNT_SET_NAME` AS PNT_NAME ,s.`PNT_UNIT`,s.`PNT_U_V`
  	FROM crm_points_account a 
  	LEFT JOIN crm_points_set s 
  	ON a.`ACT_ID` = s.`ACT_ID` 
  	AND a.`PNT_TYPE` = s.`PNT_TYPE` 
  	LEFT JOIN crm_points_item i 
  	ON a.`PNT_ID`=i.`PNT_ID` 
  	WHERE a.`CST_ID`= #{cstId}
	<if test="sets !=null">
	AND a.`ACT_ID` IN
	<foreach collection="sets" open="(" close=")" item="it" separator=",">
	#{it}
	</foreach>
	</if>
	<if test="types !=null">
	AND a.`PNT_TYPE` IN
	<foreach collection="types" open="(" close=")" item="it" separator=",">
	#{it}
	</foreach>
	</if>
	AND i.`E_TIME` > NOW() 
	AND i.`S_TIME` &lt; NOW()
	GROUP BY a.`PNT_ID`
  </select>
  <select id="selectPointsExpiring" parameterType="map" resultMap="BaseResultMap">
  	SELECT a.`PNT_ID`,a.`ACT_ID`,a.`PNT_TYPE`,SUM(i.`PNT_VAL`) AS PNT_VAL,s.`PNT_SET_NAME` AS PNT_NAME ,s.`PNT_UNIT`,s.`PNT_U_V`
  	FROM crm_points_account a 
  	LEFT JOIN crm_points_set s 
  	ON a.`ACT_ID` = s.`ACT_ID` 
  	AND a.`PNT_TYPE` = s.`PNT_TYPE` 
  	LEFT JOIN crm_points_item i 
  	ON a.`PNT_ID`=i.`PNT_ID` 
  	WHERE a.`CST_ID`= #{cstId}
	<if test="sets !=null">
	AND a.`ACT_ID` IN
	<foreach collection="sets" open="(" close=")" item="it" separator=",">
	#{it}
	</foreach>
	</if>
	<if test="types !=null">
	AND a.`PNT_TYPE` IN
	<foreach collection="types" open="(" close=")" item="it" separator=",">
	#{it}
	</foreach>
	</if>
	AND i.`E_TIME` BETWEEN #{fDate} AND #{tDate}
	GROUP BY a.`PNT_ID`
  </select>
  <select id="selectTotalPointsByDate" parameterType="map" resultType="map">
  	SELECT a.`CST_ID` AS cstId,SUM(c.`PNT_VAL`) AS val 
	FROM crm_points_change c 
	INNER JOIN crm_points_account a 
	ON c.`PNT_ID` = a.`PNT_ID`
	WHERE a.`ACT_ID` = #{actId} 
	AND a.`CST_ID` IN
	<foreach collection="csts" open="(" close=")" separator="," item="it">
	 #{it}
	 </foreach>
	AND a.`PNT_TYPE` = #{type,jdbcType=VARCHAR}
	AND c.`PNT_VAL` > 0
	AND c.`REC_TIME` BETWEEN #{fDate,jdbcType=TIMESTAMP} AND #{tDate,jdbcType=TIMESTAMP}
	GROUP BY a.`CST_ID`
  </select>
  <select id="selectSharedPoints" parameterType="java.lang.Long" resultMap="BaseResultMap">
  	SELECT a.`PNT_ID`, a.`ACT_ID`, a.`PNT_TYPE`, a.`CST_ID`, a.`PNT_VAL`,s.`PNT_SET_NAME` AS PNT_NAME,s.`PNT_UNIT`,s.`PNT_U_V`
    FROM crm_points_account a 
    INNER JOIN crm_points_set s 
    ON (a.`ACT_ID` = s.`ACT_ID` AND a.`PNT_TYPE` = s.`PNT_TYPE`) 
    WHERE CST_ID = #{cstId} AND s.`EXCHANGE` = 1 
  </select>
  
  <select id="selectSharedPointsAvaliable" parameterType="java.lang.Long" resultType="map">
  	SELECT i.`ITM_ID`,s.`PNT_U_V` FROM crm_points_account a 
  	INNER JOIN crm_points_set s ON (a.`ACT_ID` = s.`ACT_ID` AND a.`PNT_TYPE` = s.`PNT_TYPE`) 
  	INNER JOIN crm_points_item i ON a.`PNT_ID` = i.`PNT_ID` 
  	WHERE a.`CST_ID` = #{cstId} AND s.`EXCHANGE` = 1
  	AND i.`E_TIME` > NOW() 
	AND i.`S_TIME` &lt; NOW()
  </select>
</mapper>