<?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.iamberry.wechat.service.mapper.IntegralLogMapper">
    <resultMap  id="BaseResultMap" type="IntegralLog" >
        <result    column="inte_log_id"    property="inteLogId" />
        <result    column="user_open_id"    property="userOpenId" />
        <result    column="inte_log_name"    property="inteLogName" />
        <result    column="inte_conf_id"    property="inteConfId" />
        <result    column="inte_log_type"    property="inteLogType" />
        <result    column="inte_log_waiting_date"    property="inteLogWaitingDate" />
        <result    column="inte_log_waiting_order_id"    property="inteLogWaitingOrderId" />
        <result    column="inte_log_use_order_id"    property="inteLogUseOrderId" />
        <result    column="inte_log_old_id"    property="inteLogOldId" />
        <result    column="inte_log_change_num"    property="inteLogChangeNum" />
        <result    column="inte_log_before_num"    property="inteLogBeforeNum" />
        <result    column="inte_log_after_num"    property="inteLogAfterNum" />
        <result    column="inte_log_status"    property="inteLogStatus" />
        <result    column="inte_log_desc"    property="inteLogDesc" />
        <result    column="inte_log_create_time"    property="inteLogCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.inte_log_id,
        t.inte_log_name,
        t.user_open_id,
        t.inte_conf_id,
        t.inte_log_type,
        t.inte_log_waiting_date,
        t.inte_log_waiting_order_id,
        t.inte_log_use_order_id,
        t.inte_log_old_id,
        t.inte_log_change_num,
        t.inte_log_before_num,
        t.inte_log_after_num,
        t.inte_log_status,
        t.inte_log_desc,
        t.inte_log_create_time
    </sql>
    <select id="getIntegralLogList" resultMap="BaseResultMap" parameterType="IntegralLog" >
        select
        <include refid="Base_List" />
        from tb_iamberry_ism_integral_log t
        <where>
            <if test="inteLogId != null ">
                AND t.inte_log_id = #{inteLogId}
            </if >
            <if test="userOpenId != null and userOpenId != ''">
                AND t.user_open_id  like  CONCAT ('%',#{userOpenId},'%')
            </if >
            <if test="inteConfId != null ">
                AND t.inte_conf_id = #{inteConfId}
            </if >
            <if test="inteLogType != null ">
                AND t.inte_log_type = #{inteLogType}
            </if >
            <if test="inteLogWaitingOrderId != null and inteLogWaitingOrderId != ''">
                AND t.inte_log_waiting_order_id = #{inteLogWaitingOrderId}
            </if >
            <if test="inteLogUseOrderId != null and inteLogUseOrderId != ''">
                AND t.inte_log_use_order_id = #{inteLogUseOrderId}
            </if >
            <if test="inteLogOldId != null ">
                AND t.inte_log_old_id = #{inteLogOldId}
            </if >
            <if test="inteLogChangeNum != null ">
                AND t.inte_log_change_num = #{inteLogChangeNum}
            </if >
            <if test="inteLogBeforeNum != null ">
                AND t.inte_log_before_num = #{inteLogBeforeNum}
            </if >
            <if test="inteLogAfterNum != null ">
                AND t.inte_log_after_num = #{inteLogAfterNum}
            </if >
            <if test="inteLogStatus != null ">
                AND t.inte_log_status = #{inteLogStatus}
            </if >
            <if test="inteLogDesc != null and inteLogDesc != ''">
                AND t.inte_log_desc  like  CONCAT ('%',#{inteLogDesc},'%')
            </if >
        </where>
    </select>
    <select id="getIntegralLogListByAccoUser" resultMap="BaseResultMap" parameterType="IntegralLog" >
        select
        <include refid="Base_List" />,
        iio.inte_conf_name
        from tb_iamberry_ism_integral_log t
        LEFT JOIN tb_iamberry_ism_integral_config iio on t.inte_conf_id = iio.inte_conf_id
        <where>
                t.inte_log_type in (1,2)
            AND t.inte_log_status = 1
            AND t.user_open_id  = #{userOpenId}
        </where>
        ORDER BY  t.inte_log_id DESC
    </select>
    <select id="getIntegralLogListByWaitUser" resultMap="BaseResultMap"  >
        select
        <include refid="Base_List" />
        from tb_iamberry_ism_integral_log t
        <where>
                t.inte_log_type = 3
            AND t.inte_log_status = 1
            AND t.inte_log_waiting_date  &lt; now()
        </where>
    </select>
    <select id="getIntegralLogById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_ism_integral_log t
        where t.inte_log_id= #{inteLogId}
    </select>
    <insert id="save" parameterType="IntegralLog" >
        insert into
        tb_iamberry_ism_integral_log
        (
        user_open_id,
        inte_log_name,
        inte_conf_id,
        inte_log_type,
        inte_log_waiting_date,
        inte_log_waiting_order_id,
        inte_log_use_order_id,
        inte_log_old_id,
        inte_log_change_num,
        inte_log_before_num,
        inte_log_after_num,
        inte_log_status,
        inte_log_desc
        )
        values
        (
        #{userOpenId},
        #{inteLogName},
        #{inteConfId},
        #{inteLogType},
        #{inteLogWaitingDate},
        #{inteLogWaitingOrderId},
        #{inteLogUseOrderId},
        #{inteLogOldId},
        #{inteLogChangeNum},
        #{inteLogBeforeNum},
        #{inteLogAfterNum},
        #{inteLogStatus},
        #{inteLogDesc}
        )
    </insert>
    <update id="update" parameterType="IntegralLog" >
        update
          tb_iamberry_ism_integral_log
        <set >
            <if test="userOpenId != null and userOpenId != ''">
                user_open_id = #{userOpenId},
            </if >
            <if test="inteConfId != null ">
                inte_conf_id = #{inteConfId},
            </if >
            <if test="inteLogType != null ">
                inte_log_type = #{inteLogType},
            </if >
            <if test="inteLogWaitingDate != null and inteLogWaitingDate != ''">
                inte_log_waiting_date = #{inteLogWaitingDate},
            </if >
            <if test="inteLogWaitingOrderId != null and inteLogWaitingOrderId != ''">
                inte_log_waiting_order_id = #{inteLogWaitingOrderId},
            </if >
            <if test="inteLogUseOrderId != null and inteLogUseOrderId != ''">
                inte_log_use_order_id = #{inteLogUseOrderId}
            </if >
            <if test="inteLogOldId != null ">
                inte_log_old_id = #{inteLogOldId},
            </if >
            <if test="inteLogChangeNum != null ">
                inte_log_change_num = #{inteLogChangeNum},
            </if >
            <if test="inteLogBeforeNum != null ">
                inte_log_before_num = #{inteLogBeforeNum},
            </if >
            <if test="inteLogAfterNum != null ">
                inte_log_after_num = #{inteLogAfterNum},
            </if >
            <if test="inteLogStatus != null ">
                inte_log_status = #{inteLogStatus},
            </if >
            <if test="inteLogDesc != null and inteLogDesc != ''">
                inte_log_desc = #{inteLogDesc},
            </if >
        </set >
        where inte_log_id= #{inteLogId}
    </update>
    <delete id="delete" parameterType="Integer" >
        delete FROM
            tb_iamberry_ism_integral_log
        where inte_log_id=#{inteLogId}
    </delete>
</mapper>