<?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.TCcvalueMapper" >
  <resultMap id="BaseResultMap" type="com.chinaitop.depot.intelligent.grainsituation.model.TCcvalue" >
    <result column="id" property="id" jdbcType="VARCHAR" />
    <result column="org_id" property="orgId" jdbcType="VARCHAR" />
    <result column="v_cc_code" property="vCcCode" jdbcType="VARCHAR" />
    <result column="z_zd_code" property="zZdCode" jdbcType="VARCHAR" />
    <result column="v_cf_code" property="vCfCode" jdbcType="VARCHAR" />
    <result column="v_max" property="vMax" jdbcType="INTEGER" />
    <result column="v_min" property="vMin" jdbcType="INTEGER" />
    <result column="v_avg" property="vAvg" jdbcType="DECIMAL" />
    <result column="v_update_time" property="vUpdateTime" jdbcType="TIMESTAMP" />
    <result column="data_source" property="dataSource" 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, v_cc_code, z_zd_code, v_cf_code, v_max, v_min, v_avg, v_update_time, 
    data_source
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TCcvalueExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from t_ccvalue
    <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.TCcvalueExample" >
    delete from t_ccvalue
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TCcvalue" >
    insert into t_ccvalue (id, org_id, v_cc_code, 
      z_zd_code, v_cf_code, v_max, 
      v_min, v_avg, v_update_time, 
      data_source,hcjcdh)
    values (#{id,jdbcType=VARCHAR}, #{orgId,jdbcType=VARCHAR}, #{vCcCode,jdbcType=VARCHAR}, 
      #{zZdCode,jdbcType=VARCHAR}, #{vCfCode,jdbcType=VARCHAR}, #{vMax,jdbcType=INTEGER}, 
      #{vMin,jdbcType=INTEGER}, #{vAvg,jdbcType=DECIMAL}, #{vUpdateTime,jdbcType=TIMESTAMP}, 
      #{dataSource,jdbcType=VARCHAR}, #{hcjcdh,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TCcvalue" >
    insert into t_ccvalue
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="orgId != null" >
        org_id,
      </if>
      <if test="vCcCode != null" >
        v_cc_code,
      </if>
      <if test="zZdCode != null" >
        z_zd_code,
      </if>
      <if test="vCfCode != null" >
        v_cf_code,
      </if>
      <if test="vMax != null" >
        v_max,
      </if>
      <if test="vMin != null" >
        v_min,
      </if>
      <if test="vAvg != null" >
        v_avg,
      </if>
      <if test="vUpdateTime != null" >
        v_update_time,
      </if>
      <if test="dataSource != null" >
        data_source,
      </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="vCcCode != null" >
        #{vCcCode,jdbcType=VARCHAR},
      </if>
      <if test="zZdCode != null" >
        #{zZdCode,jdbcType=VARCHAR},
      </if>
      <if test="vCfCode != null" >
        #{vCfCode,jdbcType=VARCHAR},
      </if>
      <if test="vMax != null" >
        #{vMax,jdbcType=INTEGER},
      </if>
      <if test="vMin != null" >
        #{vMin,jdbcType=INTEGER},
      </if>
      <if test="vAvg != null" >
        #{vAvg,jdbcType=DECIMAL},
      </if>
      <if test="vUpdateTime != null" >
        #{vUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="dataSource != null" >
        #{dataSource,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.chinaitop.depot.intelligent.grainsituation.model.TCcvalueExample" resultType="java.lang.Integer" >
    select count(*) from t_ccvalue
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update t_ccvalue
    <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.vCcCode != null" >
        v_cc_code = #{record.vCcCode,jdbcType=VARCHAR},
      </if>
      <if test="record.zZdCode != null" >
        z_zd_code = #{record.zZdCode,jdbcType=VARCHAR},
      </if>
      <if test="record.vCfCode != null" >
        v_cf_code = #{record.vCfCode,jdbcType=VARCHAR},
      </if>
      <if test="record.vMax != null" >
        v_max = #{record.vMax,jdbcType=INTEGER},
      </if>
      <if test="record.vMin != null" >
        v_min = #{record.vMin,jdbcType=INTEGER},
      </if>
      <if test="record.vAvg != null" >
        v_avg = #{record.vAvg,jdbcType=DECIMAL},
      </if>
      <if test="record.vUpdateTime != null" >
        v_update_time = #{record.vUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.dataSource != null" >
        data_source = #{record.dataSource,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update t_ccvalue
    set id = #{record.id,jdbcType=VARCHAR},
      org_id = #{record.orgId,jdbcType=VARCHAR},
      v_cc_code = #{record.vCcCode,jdbcType=VARCHAR},
      z_zd_code = #{record.zZdCode,jdbcType=VARCHAR},
      v_cf_code = #{record.vCfCode,jdbcType=VARCHAR},
      v_max = #{record.vMax,jdbcType=INTEGER},
      v_min = #{record.vMin,jdbcType=INTEGER},
      v_avg = #{record.vAvg,jdbcType=DECIMAL},
      v_update_time = #{record.vUpdateTime,jdbcType=TIMESTAMP},
      data_source = #{record.dataSource,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_ccvalue (id, org_id, v_cc_code,
    z_zd_code, v_cf_code, v_max,
    v_min, v_avg, v_update_time,
    data_source,hcjcdh)
    values
    <foreach collection="list" item="cc" index="index" separator=",">
      (#{cc.id,jdbcType=VARCHAR}, #{cc.orgId,jdbcType=VARCHAR}, #{cc.vCcCode,jdbcType=VARCHAR},
      #{cc.zZdCode,jdbcType=VARCHAR}, #{cc.vCfCode,jdbcType=VARCHAR}, #{cc.vMax,jdbcType=INTEGER},
      #{cc.vMin,jdbcType=INTEGER}, #{cc.vAvg,jdbcType=DECIMAL}, #{cc.vUpdateTime,jdbcType=TIMESTAMP},
      #{cc.dataSource,jdbcType=VARCHAR}, #{cc.hcjcdh,jdbcType=VARCHAR})
    </foreach>
  </insert>

  <select id="getByCfCode" resultType="java.util.Map" parameterType="java.util.Map">
    SELECT
    v_cf_code AS vCfCode,
    v_max AS max,
    v_min AS min,
    v_avg AS avg,
    v_update_time AS vUpdateTime
    FROM
    t_ccvalue
    <where>
      <if test="vCfCode != null">
        v_cf_code = #{vCfCode}
      </if>
      <if test="searchStartDate != null and test=searchEndDate != null">
        AND v_update_time BETWEEN #{searchStartDate} AND #{searchEndDate}
      </if>
    </where>
    GROUP BY vUpdateTime
    ORDER BY vUpdateTime asc
  </select>

  <select id="getByCfCodes" parameterType="java.util.Map" resultType="java.util.Map">
    SELECT
    a.*
    FROM
    (
    SELECT
    v_cf_code AS vCfCode,
    v_max AS max,
    v_min AS min,
    v_avg AS avg,
    v_update_time AS vUpdateTime
    FROM
    t_ccvalue
    ORDER BY
    vUpdateTime DESC
    ) a
    WHERE 1=1
    <if test="orgId != null">
      AND a.orgId = #{orgId}
    </if>
    GROUP BY
    a.vCfCode;
  </select>

  <select id="getOneByCfCode" resultMap="BaseResultMap" parameterType="java.util.Map">
    SELECT
    *
    FROM
    t_ccvalue
    <where>
      <if test="orgId != null">
        org_id = #{orgId} and
      </if>
      <if test="vCfCode != null">
        v_cf_code = #{vCfCode}
      </if>
    </where>
    GROUP BY v_update_time
    ORDER BY v_update_time DESC LIMIT 0,1
  </select>
  
  <select id="getJcd" parameterType="java.util.Map" resultType="java.util.Map">
    select concat(hwdm, to_char(sysdate,'yyyymmddhh24mi')) jcd from basic_warehouse
    <where>
      <if test="warehouseId != null">
        warehouse_id = #{warehouseId}
      </if>
    </where>
  </select>
  
</mapper>