<?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="t_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="t_max" property="max" jdbcType="DECIMAL" />
    <result column="t_min" property="min" jdbcType="DECIMAL" />
    <result column="t_avg" property="avg" jdbcType="DECIMAL" />
    <result column="data_source" property="dataSource" jdbcType="VARCHAR" />
    <result column="iLq_yq" property="ilqYq" jdbcType="VARCHAR" />
    <result column="t_points" property="tPoints" jdbcType="VARCHAR" />
  </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, t_time, inTemp, inH, outTemp, outH, t_max, t_min, 
    t_avg, data_source, iLq_yq, t_points
  </sql>
  <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, t_time, inTemp, 
      inH, outTemp, outH, 
      t_max, t_min, t_avg, data_source, 
      iLq_yq, t_points)
    values (#{id,jdbcType=VARCHAR}, #{orgId,jdbcType=VARCHAR}, #{storehouse,jdbcType=VARCHAR}, 
      #{house,jdbcType=VARCHAR}, #{tTime,jdbcType=TIMESTAMP}, #{intemp,jdbcType=DECIMAL}, 
      #{inh,jdbcType=DECIMAL}, #{outtemp,jdbcType=DECIMAL}, #{outh,jdbcType=DECIMAL}, 
      #{tMax,jdbcType=DECIMAL}, #{tMin,jdbcType=DECIMAL}, #{tAvg,jdbcType=DECIMAL}, #{dataSource,jdbcType=VARCHAR}, 
      #{ilqYq,jdbcType=VARCHAR}, #{tPoints,jdbcType=VARCHAR})
  </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="tTime != null" >
        t_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="tMax != null" >
        t_max,
      </if>
      <if test="tMin != null" >
        t_min,
      </if>
      <if test="tAvg != null" >
        t_avg,
      </if>
      <if test="dataSource != null" >
        data_source,
      </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="tTime != null" >
        #{tTime,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="tMax != null" >
        #{tMax,jdbcType=DECIMAL},
      </if>
      <if test="tMin != null" >
        #{tMin,jdbcType=DECIMAL},
      </if>
      <if test="tAvg != null" >
        #{tAvg,jdbcType=DECIMAL},
      </if>
      <if test="dataSource != null" >
        #{dataSource,jdbcType=VARCHAR},
      </if>
      <if test="ilqYq != null" >
        #{ilqYq,jdbcType=VARCHAR},
      </if>
      <if test="tPoints != null" >
        #{tPoints,jdbcType=VARCHAR},
      </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.tTime != null" >
        t_time = #{record.tTime,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.tMax != null" >
        t_max = #{record.tMax,jdbcType=DECIMAL},
      </if>
      <if test="record.tMin != null" >
        t_min = #{record.tMin,jdbcType=DECIMAL},
      </if>
      <if test="record.tAvg != null" >
        t_avg = #{record.tAvg,jdbcType=DECIMAL},
      </if>
      <if test="record.dataSource != null" >
        data_source = #{record.dataSource,jdbcType=VARCHAR},
      </if>
      <if test="record.ilqYq != null" >
        iLq_yq = #{record.ilqYq,jdbcType=VARCHAR},
      </if>
      <if test="record.tPoints != null" >
        t_points = #{record.tPoints,jdbcType=VARCHAR},
      </if>
    </set>
    <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},
      t_time = #{record.tTime,jdbcType=TIMESTAMP},
      inTemp = #{record.intemp,jdbcType=DECIMAL},
      inH = #{record.inh,jdbcType=DECIMAL},
      outTemp = #{record.outtemp,jdbcType=DECIMAL},
      outH = #{record.outh,jdbcType=DECIMAL},
      t_max = #{record.tMax,jdbcType=DECIMAL},
      t_min = #{record.tMin,jdbcType=DECIMAL},
      t_avg = #{record.tAvg,jdbcType=DECIMAL},
      data_source = #{record.dataSource,jdbcType=VARCHAR},
      iLq_yq = #{record.ilqYq,jdbcType=VARCHAR},
      t_points = #{record.tPoints,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, t_time, inTemp,
        inH, outTemp, outH,
        t_max, t_min, t_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 t
        <where>
            <if test="vDatatime != null and vDatatime != ''">
                t_time like #{vDatatime}
            </if>
            <if test="vCfCode != null and vCfCode != ''">
                and house = #{vCfCode}
            </if>
        </where>
        order by t.t_time desc
    </select>

    <select id="getByCfCdoes" parameterType="Map" resultMap="BaseResultMap">
     SELECT
	*
FROM
	t_testdata t
WHERE
	t.org_id = #{orgId}
AND (
	t.storehouse IN (
		SELECT
			t.storehouse
		FROM
			t_testdata t
		WHERE
			org_id = #{orgId}
		GROUP BY
			t.storehouse
	)
)
AND t.t_time IN (
	SELECT
		max(t.t_time) timemax
	FROM
		t_testdata t
	WHERE
		org_id = #{orgId}
	GROUP BY
		t.storehouse
)
ORDER BY
	t.t_time DESC
  </select>
    <select id="getNewest" resultMap="BaseResultMap" parameterType="java.util.Map">
    SELECT
	*
FROM
	t_testdata t
WHERE
	t.org_id = #{orgId}
AND (
	t.storehouse IN (
		SELECT
			t.storehouse
		FROM
			t_testdata t
		WHERE
			org_id = #{orgId}
		GROUP BY
			t.storehouse
	)
)
AND t.t_time IN (
	SELECT
		max(t.t_time) timemax
	FROM
		t_testdata t
	WHERE
		org_id = #{orgId}
	GROUP BY
		t.storehouse
)
ORDER BY
	t.t_time DESC
  </select>

    <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.String">
       SELECT * FROM t_testdata t 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 t
        <where>
            <if test="tHouse != null">
                storehouse = #{tHouse}
            </if>
            <if test="startTime != null and endTime != null">
                AND t.t_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>
    <select id="findByTempTable" resultMap="BaseResultMap" parameterType="java.lang.String">
      SELECT
          org_id, t_points
      FROM
          t_testdata
      <where>
        <if test="id != null">
          id = #{id}
        </if>
      </where>
    </select>
</mapper>