mybatis batchinsert

<?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.xinwei.order.dao.OrderAlarmTblMapper" >
  <resultMap id="BaseResultMap" type="com.xinwei.order.entity.OrderAlarmTbl" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="alarm_id" property="alarmId" jdbcType="VARCHAR" />
    <result column="data_id" property="dataId" jdbcType="VARCHAR" />
    <result column="device_name" property="deviceName" jdbcType="VARCHAR" />
    <result column="device_id" property="deviceId" jdbcType="VARCHAR" />
    <result column="alarm_topic" property="alarmTopic" jdbcType="VARCHAR" />
    <result column="level" property="level" jdbcType="VARCHAR" />
    <result column="order_status" property="orderStatus" jdbcType="VARCHAR" />
    <result column="cost_time" property="costTime" jdbcType="VARCHAR" />
    <result column="proc_inst_id" property="procInstId" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
     <result column="alarm_type" property="alarmType" jdbcType="VARCHAR" />
    <result column="alarm_location" property="alarmLocation" jdbcType="VARCHAR" />
    <result column="ext" property="ext" jdbcType="VARCHAR" />
    <result column="suspend_reason" property="suspendReason" jdbcType="VARCHAR" />
  </resultMap>
 
      <delete id="deleteById" parameterType="java.lang.Long" >
        delete from order_alarm_tbl
        where id = #{id,jdbcType=BIGINT}
      </delete>
      
        <delete id="deleteAll">
        delete from order_alarm_tbl
      </delete>
      
        <delete id="deleteByAlarmId" parameterType="java.lang.String" >
        delete from order_alarm_tbl
        where alarm_id = #{alarmId,jdbcType=VARCHAR}
      </delete>
 
      <insert id="insert" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
        insert into order_alarm_tbl (id, alarm_id, data_id,
          device_name, device_id, alarm_topic, alarm_type, alarm_location,
          level, order_status, cost_time,
          proc_inst_id, create_time, ext,suspend_reason
          )
        values (#{id,jdbcType=BIGINT}, #{alarmId,jdbcType=VARCHAR}, #{dataId,jdbcType=VARCHAR},
          #{deviceName,jdbcType=VARCHAR}, #{deviceId,jdbcType=VARCHAR}, #{alarmTopic,jdbcType=VARCHAR},
          #{alarmType,jdbcType=VARCHAR}, #{alarmLocation,jdbcType=VARCHAR},  
          #{level,jdbcType=VARCHAR}, #{orderStatus,jdbcType=VARCHAR}, #{costTime,jdbcType=VARCHAR},
          #{procInstId,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{ext,jdbcType=VARCHAR}, #{suspendReason,jdbcType=VARCHAR}
          )
      </insert>
 
     <insert id="insertByBatch" parameterType="java.util.List">
        insert into order_alarm_tbl (id,alarm_id, data_id,
      device_name, device_id, alarm_topic, alarm_type, alarm_location,
      level, order_status, cost_time,
      proc_inst_id, create_time, ext,suspend_reason
      )
        values
        <foreach collection="list" item="item" index="index" separator=",">
         ( #{item.id,jdbcType=BIGINT},#{item.alarmId,jdbcType=VARCHAR}, #{item.dataId,jdbcType=VARCHAR},
      #{item.deviceName,jdbcType=VARCHAR}, #{item.deviceId,jdbcType=VARCHAR}, #{item.alarmTopic,jdbcType=VARCHAR},
      #{item.alarmType,jdbcType=VARCHAR}, #{item.alarmLocation,jdbcType=VARCHAR},  
      #{item.level,jdbcType=VARCHAR}, #{item.orderStatus,jdbcType=VARCHAR}, #{item.costTime,jdbcType=VARCHAR},
      #{item.procInstId,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP}, #{item.ext,jdbcType=VARCHAR}, #{item.suspendReason,jdbcType=VARCHAR}
      )
        </foreach>
    </insert>
 
  <update id="updateByPrimaryKey" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
    update order_alarm_tbl
    set alarm_id = #{alarmId,jdbcType=VARCHAR},
    data_id = #{dataId,jdbcType=VARCHAR},
    device_name = #{deviceName,jdbcType=VARCHAR},
    device_id = #{deviceId,jdbcType=VARCHAR},
    alarm_topic = #{alarmTopic,jdbcType=VARCHAR},
    alarm_type = #{alarmType,jdbcType=VARCHAR},
    alarm_location = #{alarmLocation,jdbcType=VARCHAR},
    level = #{level,jdbcType=VARCHAR},
    order_status = #{orderStatus,jdbcType=VARCHAR},
    cost_time = #{costTime,jdbcType=VARCHAR},
    proc_inst_id = #{procInstId,jdbcType=VARCHAR},
    create_time = #{createTime,jdbcType=TIMESTAMP},
    ext = #{ext,jdbcType=VARCHAR},
    suspend_reason = #{suspendReason,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
 
    <update id="updateOrderStatusByDataId" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
    update order_alarm_tbl
    set order_status = #{orderStatus,jdbcType=VARCHAR}
    where data_id = #{dataId,jdbcType=VARCHAR}
  </update>
 
   <update id="updateSuspendReasonByDataId" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
    update order_alarm_tbl
    set suspend_reason = #{suspendReason,jdbcType=VARCHAR}
    where data_id = #{dataId,jdbcType=VARCHAR}
  </update>
 
   <update id="updateSuspendReasonByProcessInstId" parameterType="com.xinwei.order.entity.OrderAlarmTbl" >
    update order_alarm_tbl
    set suspend_reason = #{suspendReason,jdbcType=VARCHAR}
    where proc_inst_id = #{procInstId,jdbcType=VARCHAR}
  </update>
 
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    where id = #{id,jdbcType=BIGINT}
  </select>
 
    <select id="getByDataId" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    where data_id = #{dataId,jdbcType=VARCHAR}
  </select>
 
    <select id="getByAlarmId" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    where alarm_id = #{alarmId,jdbcType=VARCHAR}
  </select>
 
   <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    where id = #{id,jdbcType=BIGINT}
  </select>
 
  <select id="countMyApplyByCondition" resultType="java.lang.Long" >
    select count(1)
   from order_alarm_tbl
    where 1=1 <include refid="queryString" />
  </select>
 
   <select id="selectMyApplyByCondition" resultMap="BaseResultMap" >
 select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location,  level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryString" />
    limit #{startRow},#{pageSize}
  </select>

    <select id="countAll" resultType="java.lang.Long" >
    SELECT COUNT(*)
    from order_alarm_tbl
   </select>

  <select id="getAll" resultMap="BaseResultMap" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic, alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    limit #{startRow},#{pageSize}
  </select>
 
    <select id="selectAll" resultMap="BaseResultMap" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic, alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    order by create_time desc
  </select>
 
   <select id="selectAllAlarmType" resultType="java.lang.String" >
  SELECT DISTINCT alarm_type
    FROM order_alarm_tbl
  </select>
 
  <select id="getSuspendTask" resultMap="BaseResultMap" >
   SELECT * FROM order_alarm_tbl WHERE suspend_reason IS NOT null
    order by create_time desc
  </select>
 
  <select id="countByCondition" resultType="java.lang.Long" >
    SELECT COUNT(*)
      from order_alarm_tbl
      where 1=1
    <include refid="queryString" />
   </select>
   
    <select id="getByCondition" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location,  level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryString" />
    limit #{startRow},#{pageSize}
  </select>
 
     <select id="countExportByCondition" resultType="java.lang.Long" >
    SELECT COUNT(*)
      from order_alarm_tbl
      where 1=1
    <include refid="queryString" />
   </select>
 
    <select id="exportByCondition" resultMap="BaseResultMap" parameterType="java.lang.String" >
     select id, alarm_id, data_id, device_name, device_id, alarm_topic,alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryString" />
  </select>
 
    <select id="selectProcInstIdByCondition" resultType="java.lang.String" >
    select proc_inst_id
    from order_alarm_tbl
    where 1=1 <include refid="queryString" />
  </select>
 
    <select id="countTAToDoListByCondition" resultType="java.lang.Long" >
    SELECT COUNT(*)
      from order_alarm_tbl
      where 1=1
    <include refid="queryTAToDoListByCondition" />
   </select>
   
    <select id="getTAToDoListByCondition" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic, alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryTAToDoListByCondition" />
    limit #{startRow},#{pageSize}
  </select>
 
 
    <select id="getTAToDoListByConditionNoPage" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select id, alarm_id, data_id, device_name, device_id, alarm_topic, alarm_type, alarm_location, level, order_status,
    cost_time, proc_inst_id, create_time, ext,suspend_reason
    from order_alarm_tbl
    WHERE 1=1
    <include refid="queryTAToDoListByCondition" />
  </select>
 
 

  <sql id="queryTAToDoListByCondition">
    
      <if test="alarmType != null and alarmType !=''">
     and alarm_type = #{alarmType,jdbcType=VARCHAR}
    </if>
    
      <if test="alarmLocation != null and alarmLocation !=''">
     and alarm_location = #{alarmLocation,jdbcType=VARCHAR}
    </if>
    
     <if test="level != null and level !=''">
     and level = #{level,jdbcType=VARCHAR}
    </if>
    
     <if test="alarmId != null and alarmId !=''">
     and alarm_id = #{alarmId,jdbcType=VARCHAR}
    </if>
    
    <if test="deviceId != null and deviceId !=''">
     and device_id = #{deviceId,jdbcType=VARCHAR}
    </if>
    
    <if test="alarmTopic != null and alarmTopic !=''">
     and alarm_topic LIKE '%${alarmTopic}%'
    </if>

 </sql>
 
  <sql id="queryString">
     <if test="alarmId != null and alarmId !=''">
     and alarm_id = #{alarmId,jdbcType=VARCHAR}
    </if>
    
    <if test="deviceId != null and deviceId !=''">
     and device_id = #{deviceId,jdbcType=VARCHAR}
    </if>
    
    <if test="alarmTopic != null and alarmTopic !=''">
     and alarm_topic LIKE '%${alarmTopic}%'
    </if>
    
     <if test="startTime != null and endTime != null">
        and DATE_FORMAT(create_time,'%m-%d-%Y')
           between DATE_FORMAT(#{startTime,jdbcType=VARCHAR},'%m-%d-%Y')
           and DATE_FORMAT(#{endTime,jdbcType=VARCHAR},'%m-%d-%Y')
    </if>
 </sql>
</mapper>

posted @ 2017-10-27 10:55  Alamps  阅读(3075)  评论(0编辑  收藏  举报