<?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.chinaitop.depot.intelligent.grainsituation.mapper.TTestdataMapper" >
  <resultMap id="BaseResultMap" type="com.chinaitop.depot.intelligent.grainsituation.model.TTestdata" >
    <result column="id" property="id" jdbcType="VARCHAR" />
    <result column="org_id" property="orgId" jdbcType="VARCHAR" />
    <result column="storehouse" property="storehouse" jdbcType="VARCHAR" />
    <result column="house" property="house" jdbcType="VARCHAR" />
    <result column="time" property="time" jdbcType="TIMESTAMP" />
    <result column="inTemp" property="intemp" jdbcType="DECIMAL" />
    <result column="inH" property="inh" jdbcType="DECIMAL" />
    <result column="outTemp" property="outtemp" jdbcType="DECIMAL" />
    <result column="outH" property="outh" jdbcType="DECIMAL" />
    <result column="max" property="max" jdbcType="DECIMAL" />
    <result column="min" property="min" jdbcType="DECIMAL" />
    <result column="avg" property="avg" jdbcType="DECIMAL" />
    <result column="data_source" property="dataSource" jdbcType="VARCHAR" />
    <result column="updatetime" property="updatetime" jdbcType="TIMESTAMP" />
    <result column="iLq_yq" property="ilqYq" jdbcType="VARCHAR" />
  </resultMap>
  <resultMap id="ResultMapWithBLOBs" type="com.chinaitop.depot.intelligent.grainsituation.model.TTestdata" extends="BaseResultMap" >
    <result column="t_points" property="tPoints" jdbcType="LONGVARCHAR" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    id, org_id, storehouse, house, time, inTemp, inH, outTemp, outH, max, min, avg, data_source, 
    updatetime, iLq_yq
  </sql>
  <sql id="Blob_Column_List" >
    t_points
  </sql>
  <select id="selectByExampleWithBLOBs" resultMap="ResultMapWithBLOBs" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TTestdataExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from t_testdata
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TTestdataExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_testdata
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <delete id="deleteByExample" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TTestdataExample" >
    delete from t_testdata
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TTestdata" >
    insert into t_testdata (id, org_id, storehouse, 
      house, time, inTemp, 
      inH, outTemp, outH, 
      max, min, avg, data_source, 
      updatetime, iLq_yq, t_points
      )
    values (#{id,jdbcType=VARCHAR}, #{orgId,jdbcType=VARCHAR}, #{storehouse,jdbcType=VARCHAR}, 
      #{house,jdbcType=VARCHAR}, #{time,jdbcType=TIMESTAMP}, #{intemp,jdbcType=DECIMAL}, 
      #{inh,jdbcType=DECIMAL}, #{outtemp,jdbcType=DECIMAL}, #{outh,jdbcType=DECIMAL}, 
      #{max,jdbcType=DECIMAL}, #{min,jdbcType=DECIMAL}, #{avg,jdbcType=DECIMAL}, #{dataSource,jdbcType=VARCHAR}, 
      #{updatetime,jdbcType=TIMESTAMP}, #{ilqYq,jdbcType=VARCHAR}, #{tPoints,jdbcType=LONGVARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TTestdata" >
    insert into t_testdata
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="orgId != null" >
        org_id,
      </if>
      <if test="storehouse != null" >
        storehouse,
      </if>
      <if test="house != null" >
        house,
      </if>
      <if test="time != null" >
        time,
      </if>
      <if test="intemp != null" >
        inTemp,
      </if>
      <if test="inh != null" >
        inH,
      </if>
      <if test="outtemp != null" >
        outTemp,
      </if>
      <if test="outh != null" >
        outH,
      </if>
      <if test="max != null" >
        max,
      </if>
      <if test="min != null" >
        min,
      </if>
      <if test="avg != null" >
        avg,
      </if>
      <if test="dataSource != null" >
        data_source,
      </if>
      <if test="updatetime != null" >
        updatetime,
      </if>
      <if test="ilqYq != null" >
        iLq_yq,
      </if>
      <if test="tPoints != null" >
        t_points,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="orgId != null" >
        #{orgId,jdbcType=VARCHAR},
      </if>
      <if test="storehouse != null" >
        #{storehouse,jdbcType=VARCHAR},
      </if>
      <if test="house != null" >
        #{house,jdbcType=VARCHAR},
      </if>
      <if test="time != null" >
        #{time,jdbcType=TIMESTAMP},
      </if>
      <if test="intemp != null" >
        #{intemp,jdbcType=DECIMAL},
      </if>
      <if test="inh != null" >
        #{inh,jdbcType=DECIMAL},
      </if>
      <if test="outtemp != null" >
        #{outtemp,jdbcType=DECIMAL},
      </if>
      <if test="outh != null" >
        #{outh,jdbcType=DECIMAL},
      </if>
      <if test="max != null" >
        #{max,jdbcType=DECIMAL},
      </if>
      <if test="min != null" >
        #{min,jdbcType=DECIMAL},
      </if>
      <if test="avg != null" >
        #{avg,jdbcType=DECIMAL},
      </if>
      <if test="dataSource != null" >
        #{dataSource,jdbcType=VARCHAR},
      </if>
      <if test="updatetime != null" >
        #{updatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="ilqYq != null" >
        #{ilqYq,jdbcType=VARCHAR},
      </if>
      <if test="tPoints != null" >
        #{tPoints,jdbcType=LONGVARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TTestdataExample" resultType="java.lang.Integer" >
    select count(*) from t_testdata
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update t_testdata
    <set >
      <if test="record.id != null" >
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.orgId != null" >
        org_id = #{record.orgId,jdbcType=VARCHAR},
      </if>
      <if test="record.storehouse != null" >
        storehouse = #{record.storehouse,jdbcType=VARCHAR},
      </if>
      <if test="record.house != null" >
        house = #{record.house,jdbcType=VARCHAR},
      </if>
      <if test="record.time != null" >
        time = #{record.time,jdbcType=TIMESTAMP},
      </if>
      <if test="record.intemp != null" >
        inTemp = #{record.intemp,jdbcType=DECIMAL},
      </if>
      <if test="record.inh != null" >
        inH = #{record.inh,jdbcType=DECIMAL},
      </if>
      <if test="record.outtemp != null" >
        outTemp = #{record.outtemp,jdbcType=DECIMAL},
      </if>
      <if test="record.outh != null" >
        outH = #{record.outh,jdbcType=DECIMAL},
      </if>
      <if test="record.max != null" >
        max = #{record.max,jdbcType=DECIMAL},
      </if>
      <if test="record.min != null" >
        min = #{record.min,jdbcType=DECIMAL},
      </if>
      <if test="record.avg != null" >
        avg = #{record.avg,jdbcType=DECIMAL},
      </if>
      <if test="record.dataSource != null" >
        data_source = #{record.dataSource,jdbcType=VARCHAR},
      </if>
      <if test="record.updatetime != null" >
        updatetime = #{record.updatetime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.ilqYq != null" >
        iLq_yq = #{record.ilqYq,jdbcType=VARCHAR},
      </if>
      <if test="record.tPoints != null" >
        t_points = #{record.tPoints,jdbcType=LONGVARCHAR},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map" >
    update t_testdata
    set id = #{record.id,jdbcType=VARCHAR},
      org_id = #{record.orgId,jdbcType=VARCHAR},
      storehouse = #{record.storehouse,jdbcType=VARCHAR},
      house = #{record.house,jdbcType=VARCHAR},
      time = #{record.time,jdbcType=TIMESTAMP},
      inTemp = #{record.intemp,jdbcType=DECIMAL},
      inH = #{record.inh,jdbcType=DECIMAL},
      outTemp = #{record.outtemp,jdbcType=DECIMAL},
      outH = #{record.outh,jdbcType=DECIMAL},
      max = #{record.max,jdbcType=DECIMAL},
      min = #{record.min,jdbcType=DECIMAL},
      avg = #{record.avg,jdbcType=DECIMAL},
      data_source = #{record.dataSource,jdbcType=VARCHAR},
      updatetime = #{record.updatetime,jdbcType=TIMESTAMP},
      iLq_yq = #{record.ilqYq,jdbcType=VARCHAR},
      t_points = #{record.tPoints,jdbcType=LONGVARCHAR}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update t_testdata
    set id = #{record.id,jdbcType=VARCHAR},
      org_id = #{record.orgId,jdbcType=VARCHAR},
      storehouse = #{record.storehouse,jdbcType=VARCHAR},
      house = #{record.house,jdbcType=VARCHAR},
      time = #{record.time,jdbcType=TIMESTAMP},
      inTemp = #{record.intemp,jdbcType=DECIMAL},
      inH = #{record.inh,jdbcType=DECIMAL},
      outTemp = #{record.outtemp,jdbcType=DECIMAL},
      outH = #{record.outh,jdbcType=DECIMAL},
      max = #{record.max,jdbcType=DECIMAL},
      min = #{record.min,jdbcType=DECIMAL},
      avg = #{record.avg,jdbcType=DECIMAL},
      data_source = #{record.dataSource,jdbcType=VARCHAR},
      updatetime = #{record.updatetime,jdbcType=TIMESTAMP},
      iLq_yq = #{record.ilqYq,jdbcType=VARCHAR}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>

  <insert id="insertBatch" parameterType="java.util.List">
    insert into t_testdata (id, org_id, storehouse,
    house, time, inTemp,
    inH, outTemp, outH,
    max, min, avg, data_source,
    updatetime, iLq_yq, t_points
    )
    values
    <foreach collection="list" item="testData" index="index" separator=",">
      (#{testData.id,jdbcType=VARCHAR}, #{testData.orgId,jdbcType=VARCHAR}, #{testData.storehouse,jdbcType=VARCHAR},
      #{testData.house,jdbcType=VARCHAR}, #{testData.time,jdbcType=TIMESTAMP}, #{testData.intemp,jdbcType=DECIMAL},
      #{testData.inh,jdbcType=DECIMAL}, #{testData.outtemp,jdbcType=DECIMAL}, #{testData.outh,jdbcType=DECIMAL},
      #{testData.max,jdbcType=DECIMAL}, #{testData.min,jdbcType=DECIMAL}, #{testData.avg,jdbcType=DECIMAL}, #{testData.dataSource,jdbcType=VARCHAR},
      #{testData.updatetime,jdbcType=TIMESTAMP}, #{testData.ilqYq,jdbcType=VARCHAR}, #{testData.tPoints,jdbcType=LONGVARCHAR}
      )
    </foreach>
  </insert>

  <select id="getList" parameterType="Map" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from t_testdata
    <where>
      <if test="vDatatime != null and vDatatime != ''">
        time like #{vDatatime}
      </if>
      <if test="vCfCode != null and vCfCode != ''">
        and house = #{vCfCode}
      </if>
    </where>
    order by time desc
  </select>

  <select id="getByCfCdoes" parameterType="Map" resultMap="BaseResultMap">
    SELECT
    a.*
    FROM
    (
    SELECT
    <include refid="Base_Column_List"/>
    FROM
    t_testdata
    ORDER BY
    time DESC
    ) a
    WHERE 1=1
    <if test="orgId != null">
      AND a.orgId = #{orgId}
    </if>
    GROUP BY
    a.storehouse
  </select>
  <select id="getNewest" resultMap="BaseResultMap" parameterType="java.util.Map">
    SELECT
    <include refid="Base_Column_List"/>
    FROM
    (
    SELECT
    <include refid="Base_Column_List"/>
    FROM
    t_testdata
    ORDER BY
    time DESC limit 10000000000
    ) a
    GROUP BY
    a.storehouse
  </select>

    <select id="getById" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String">
       SELECT * FROM t_testdata WHERE id = #{id}
    </select>

  <select id="getOrgId" resultType="java.lang.String" parameterType="java.lang.String">
    SELECT
    org_id
    FROM
    basic_storehouse
    <if test="cfCode != null">
      WHERE storehouse_code = #{cfCode}
    </if>
    LIMIT 0,1
  </select>

  <select id="getGrainPointAll" resultType="java.util.Map" parameterType="java.util.Map">
    SELECT
    *
    FROM
    t_testdata
    <where>
      <if test="tHouse != null">
        storehouse = #{tHouse}
      </if>
      <if test="startTime != null and endTime != null">
        AND time BETWEEN #{startTime} AND #{endTime}
      </if>
      <if test="lqIds != null">
        AND id IN
        <foreach item="lqId" index="index" collection="lqIds" open="(" separator="," close=")">
          #{lqId}
        </foreach>
      </if>
    </where>
  </select>
</mapper>