<?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.reptileclient.jlifeapp.dao.jz.DyLaikeShopThreeRateMapper">
  <resultMap id="BaseResultMap" type="com.reptileclient.jlifeapp.entity.jz.DyLaikeShopThreeRate">
    <!--@mbg.generated-->
    <!--@Table dy_laike_shop_three_rate-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="batch_id" jdbcType="INTEGER" property="batchId" />
    <result column="shop_poi_id" jdbcType="VARCHAR" property="shopPoiId" />
    <result column="city_id" jdbcType="INTEGER" property="cityId" />
    <result column="city_name" jdbcType="VARCHAR" property="cityName" />
    <result column="start_date" jdbcType="VARCHAR" property="startDate" />
    <result column="end_date" jdbcType="VARCHAR" property="endDate" />
    <result column="fra_id" jdbcType="INTEGER" property="fraId" />
    <result column="fra_name" jdbcType="VARCHAR" property="fraName" />
    <result column="shop_name" jdbcType="VARCHAR" property="shopName" />
    <result column="bad_rate" jdbcType="DECIMAL" property="badRate" />
    <result column="complaint_rate" jdbcType="DECIMAL" property="complaintRate" />
    <result column="refund_rate" jdbcType="DECIMAL" property="refundRate" />
    <result column="eva_update_time" jdbcType="TIMESTAMP" property="evaUpdateTime" />
    <result column="etl_time" jdbcType="TIMESTAMP" property="etlTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, batch_id, shop_poi_id, city_id, city_name, start_date, end_date, fra_id, fra_name,
    shop_name, bad_rate, complaint_rate, refund_rate, eva_update_time, etl_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select
    <include refid="Base_Column_List" />
    from dy_laike_shop_three_rate
    where id = #{id,jdbcType=INTEGER}
  </select>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.reptileclient.jlifeapp.entity.jz.DyLaikeShopThreeRate" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into jlife_reports.dy_laike_shop_three_rate
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="batchId != null">
        batch_id,
      </if>
      <if test="shopPoiId != null and shopPoiId != ''">
        shop_poi_id,
      </if>
      <if test="cityId != null">
        city_id,
      </if>
      <if test="cityName != null and cityName != ''">
        city_name,
      </if>
      <if test="startDate != null and startDate != ''">
        start_date,
      </if>
      <if test="endDate != null and endDate != ''">
        end_date,
      </if>
      <if test="fraId != null">
        fra_id,
      </if>
      <if test="fraName != null and fraName != ''">
        fra_name,
      </if>
      <if test="shopName != null and shopName != ''">
        shop_name,
      </if>
      <if test="badRate != null">
        bad_rate,
      </if>
      <if test="complaintRate != null">
        complaint_rate,
      </if>
      <if test="refundRate != null">
        refund_rate,
      </if>
      <if test="evaUpdateTime != null">
        eva_update_time,
      </if>
      <if test="etlTime != null">
        etl_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="batchId != null">
        #{batchId,jdbcType=INTEGER},
      </if>
      <if test="shopPoiId != null and shopPoiId != ''">
        #{shopPoiId,jdbcType=VARCHAR},
      </if>
      <if test="cityId != null">
        #{cityId,jdbcType=INTEGER},
      </if>
      <if test="cityName != null and cityName != ''">
        #{cityName,jdbcType=VARCHAR},
      </if>
      <if test="startDate != null and startDate != ''">
        #{startDate,jdbcType=VARCHAR},
      </if>
      <if test="endDate != null and endDate != ''">
        #{endDate,jdbcType=VARCHAR},
      </if>
      <if test="fraId != null">
        #{fraId,jdbcType=INTEGER},
      </if>
      <if test="fraName != null and fraName != ''">
        #{fraName,jdbcType=VARCHAR},
      </if>
      <if test="shopName != null and shopName != ''">
        #{shopName,jdbcType=VARCHAR},
      </if>
      <if test="badRate != null">
        #{badRate,jdbcType=DECIMAL},
      </if>
      <if test="complaintRate != null">
        #{complaintRate,jdbcType=DECIMAL},
      </if>
      <if test="refundRate != null">
        #{refundRate,jdbcType=DECIMAL},
      </if>
      <if test="evaUpdateTime != null">
        #{evaUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="etlTime != null">
        #{etlTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

  <select id="getLastBatch" resultType="java.lang.Integer">
    select IFNULL(max(batch_id) + 1, 1)
    from jlife_reports.dy_laike_shop_three_rate
    </select>

  <update id="updateLastBatch">
      update jlife_reports.dy_laike_shop_three_rate a join jlife_nurse.jz_shop b on a.shop_poi_id = b.poi_id
      set a.fra_id    =b.fra_id,
          a.fra_name  = b.fra_name,
          a.city_id   = b.shop_city,
          a.city_name = b.shop_city_name
      where a.batch_id = #{batchId,jdbcType=INTEGER}
  </update>
</mapper>
