<?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.DyLaikeShopEvaltionMapper">
    <resultMap id="BaseResultMap" type="com.reptileclient.jlifeapp.entity.DyLaikeShopEvaltion">
        <!--@mbg.generated-->
        <!--@Table dy_laike_shop_evaltion-->
        <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="fra_id" jdbcType="INTEGER" property="fraId"/>
        <result column="fra_name" jdbcType="VARCHAR" property="fraName"/>
        <result column="shop_name" jdbcType="VARCHAR" property="shopName"/>
        <result column="score" jdbcType="DECIMAL" property="score"/>
        <result column="eva_count" jdbcType="INTEGER" property="evaCount"/>
        <result column="eva_last_month_count" jdbcType="INTEGER" property="evaLastMonthCount"/>
        <result column="eva_last_goods" jdbcType="INTEGER" property="evaLastGoods"/>
        <result column="eva_last_bad" jdbcType="INTEGER" property="evaLastBad"/>
        <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,
        fra_id,
        fra_name,
        shop_name,
        score,
        eva_count,
        eva_last_month_count,
        eva_last_goods,
        eva_last_bad,
        eva_update_time,
        etl_time
    </sql>
    <insert id="insert" keyColumn="id" keyProperty="id"
            parameterType="com.reptileclient.jlifeapp.entity.DyLaikeShopEvaltion" useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into jlife_reports.dy_laike_shop_evaltion (batch_id, shop_poi_id, fra_id,
                                                          fra_name, shop_name, score,
                                                          eva_count, eva_last_month_count, eva_last_goods,
                                                          eva_last_bad, eva_update_time, etl_time)
        values (#{batchId,jdbcType=INTEGER}, #{shopPoiId,jdbcType=VARCHAR}, #{fraId,jdbcType=INTEGER},
                #{fraName,jdbcType=VARCHAR}, #{shopName,jdbcType=VARCHAR}, #{score,jdbcType=DECIMAL},
                #{evaCount,jdbcType=INTEGER}, #{evaLastMonthCount,jdbcType=INTEGER}, #{evaLastGoods,jdbcType=INTEGER},
                #{evaLastBad,jdbcType=INTEGER}, #{evaUpdateTime,jdbcType=TIMESTAMP}, #{etlTime,jdbcType=TIMESTAMP})
    </insert>


    <select id="selectLastBatch" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from jlife_reports.dy_laike_shop_evaltion
        where batch_id = (select max(batch_id) from dy_laike_shop_evaltion)
    </select>

    <update id="updateLastBatch">
        update jlife_reports.dy_laike_shop_evaltion 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
        where a.batch_id = #{batchId,jdbcType=INTEGER}
    </update>

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