PointsItemMapper.xml 7.05 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.PointsItemMapper">
  <resultMap id="BaseResultMap" type="cn.runsa.crmapp.points.entity.PointsItem">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="ITM_ID" jdbcType="BIGINT" property="itmId" />
    <result column="PNT_ID" jdbcType="BIGINT" property="pntId" />
    <result column="PNT_VAL" jdbcType="DOUBLE" property="pntVal" />
    <result column="BLC_ACT" jdbcType="BIGINT" property="blcAct" />
    <result column="S_TIME" jdbcType="TIMESTAMP" property="sTime" />
    <result column="E_TIME" jdbcType="TIMESTAMP" property="eTime" />
    <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.
    -->
    `ITM_ID`, `PNT_ID`, `PNT_VAL`, `BLC_ACT`, `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_item
    where `ITM_ID` = #{itmId,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_item
    where `ITM_ID` = #{itmId,jdbcType=BIGINT}
  </delete>
  <delete id="deleteListByPrimaryKey">
  	 delete from crm_points_item
     where `ITM_ID` in
     <foreach collection="list" open="(" close=")" separator="," item="it">
     	#{it.itmId}
     </foreach> 
  </delete>
  <insert id="insert" parameterType="cn.runsa.crmapp.points.entity.PointsItem">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <selectKey keyProperty="itmId" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into crm_points_item (`ITM_ID`, `PNT_ID`, `PNT_VAL`, 
      `BLC_ACT`, `S_TIME`, `E_TIME`, 
      `REC_TIME`)
    values (#{itmId,jdbcType=BIGINT}, #{pntId,jdbcType=BIGINT}, #{pntVal,jdbcType=DOUBLE}, 
      #{blcAct,jdbcType=BIGINT}, #{sTime,jdbcType=TIMESTAMP}, #{eTime,jdbcType=TIMESTAMP}, 
      #{recTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="cn.runsa.crmapp.points.entity.PointsItem">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <selectKey keyProperty="itmId" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into crm_points_item
    <trim prefix="(" suffix=")" suffixOverrides=",">
      `ITM_ID`,
      <if test="pntId != null">
        `PNT_ID`,
      </if>
      <if test="pntVal != null">
        `PNT_VAL`,
      </if>
      <if test="blcAct != null">
        `BLC_ACT`,
      </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=",">
      #{itmId,jdbcType=BIGINT},
      <if test="pntId != null">
        #{pntId,jdbcType=BIGINT},
      </if>
      <if test="pntVal != null">
        #{pntVal,jdbcType=DOUBLE},
      </if>
      <if test="blcAct != null">
        #{blcAct,jdbcType=BIGINT},
      </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>
  <insert id="insertOrUpdate" parameterType="map">
    insert into crm_points_item (`PNT_ID`, `PNT_VAL`, `BLC_ACT`, `S_TIME`, `E_TIME`)
    values 
    <foreach collection="list" item="it" separator=",">
    (#{it.pntId,jdbcType=BIGINT}, #{it.pntVal,jdbcType=DOUBLE}, #{it.blcAct,jdbcType=BIGINT}, #{it.sTime,jdbcType=TIMESTAMP}, #{it.eTime,jdbcType=TIMESTAMP})
    </foreach>
    ON DUPLICATE KEY UPDATE 
    <choose>
    <when test="plus == true">
     `PNT_VAL`=`PNT_VAL`+values(`PNT_VAL`)
    </when>
    <otherwise>
    `PNT_VAL`= values(`PNT_VAL`)
    </otherwise>
    </choose>
   
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="cn.runsa.crmapp.points.entity.PointsItem">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_points_item
    <set>
      <if test="pntId != null">
        `PNT_ID` = #{pntId,jdbcType=BIGINT},
      </if>
      <if test="pntVal != null">
        `PNT_VAL` = #{pntVal,jdbcType=DOUBLE},
      </if>
      <if test="blcAct != null">
        `BLC_ACT` = #{blcAct,jdbcType=BIGINT},
      </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 `ITM_ID` = #{itmId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.runsa.crmapp.points.entity.PointsItem">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update crm_points_item
    set `PNT_ID` = #{pntId,jdbcType=BIGINT},
      `PNT_VAL` = #{pntVal,jdbcType=DOUBLE},
      `BLC_ACT` = #{blcAct,jdbcType=BIGINT},
      `S_TIME` = #{sTime,jdbcType=TIMESTAMP},
      `E_TIME` = #{eTime,jdbcType=TIMESTAMP},
      `REC_TIME` = #{recTime,jdbcType=TIMESTAMP}
    where `ITM_ID` = #{itmId,jdbcType=BIGINT}
  </update>
  <select id="countPointsAvaliable" statementType="CALLABLE" parameterType="map" resultType="double">
  	{call crm_pdu_points_total(#{pntId,mode=IN,jdbcType=BIGINT},#{date,mode=IN,jdbcType=TIMESTAMP})}
  </select>
  <select id="countPointsWithNoLocking" parameterType="map" resultType="double">
  	SELECT SUM(PNT_VAL) FROM crm_points_item WHERE PNT_ID = #{pntId} AND `E_TIME` > #{date} AND `S_TIME` &lt; #{date};
  </select>
  <select id="selectAvaliable" parameterType="map" resultMap="BaseResultMap">
  	SELECT * 
  	FROM crm_points_item 
  	WHERE ITM_ID IN 
  	(SELECT ITM_ID 
  	FROM crm_points_item 
  	WHERE PNT_ID = #{pntId}
  	AND `E_TIME` > #{date} 
  	AND `S_TIME` &lt; #{date} ) ORDER BY `E_TIME` ASC
  	LIMIT #{start},#{pageSize}
  </select>
  <select id="selectByItem" resultMap="BaseResultMap">
  	SELECT * 
  	FROM crm_points_item 
  	WHERE ITM_ID IN (
  	<foreach collection="list" item="it" separator=",">
  		#{it}
  	</foreach>
  	)
  	FOR UPDATE
  </select>  
</mapper>