<?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.gic.haoban.manage.service.dao.mapper.licence.TabHaobanLicenceOrderProgressMapper">
    <resultMap type="com.gic.haoban.manage.service.entity.licence.TabHaobanLicenceOrderProgress" id="BaseResultMap">
        <result column="id" property="id"/>
        <result column="enterprise_id" property="enterpriseId"/>
        <result column="wx_enterprise_id" property="wxEnterpriseId"/>
        <result column="order_id" property="orderId"/>
        <result column="order_status" property="orderStatus"/>
        <result column="type" property="type"/>
        <result column="voucher" property="voucher"/>
        <result column="reason" property="reason"/>
        <result column="delete_flag" property="deleteFlag"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="creator_name" property="creatorName"/>
    </resultMap>
    <sql id="Base_Column_List">
      id,
      enterprise_id,
	  wx_enterprise_id,
	  order_id,
	  order_status,
	  type,
	  voucher,
	  reason,
	  delete_flag,
	  create_time,
	  update_time,
	  creator_name
    </sql>
    <!-- ===================== 新增 ======================== -->
    <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.licence.TabHaobanLicenceOrderProgress"
            useGeneratedKeys="true" keyProperty="id">
        INSERT INTO tab_haoban_licence_order_progress(id,
                                                      enterprise_id,
                                                      wx_enterprise_id,
                                                      order_id,
                                                      order_status,
                                                      type,
                                                      voucher,
                                                      reason,
                                                      delete_flag,
                                                      create_time,
                                                      update_time,
                                                      creator_name)
        VALUES (#{id,jdbcType=BIGINT},
                #{enterpriseId,jdbcType=VARCHAR},
                #{wxEnterpriseId,jdbcType=VARCHAR},
                #{orderId,jdbcType=BIGINT},
                #{orderStatus,jdbcType=VARCHAR},
                #{type,jdbcType=INTEGER},
                #{voucher,jdbcType=VARCHAR},
                #{reason,jdbcType=VARCHAR},
                0,
                now(),
                now(),
                #{creatorName,jdbcType=VARCHAR})
    </insert>

    <!-- =====================删除==================== -->
    <update id="deleteByPrimaryKey" parameterType="long">
        UPDATE tab_haoban_licence_order_progress
        SET delete_flag = 1
        WHERE id = #{id}
    </update>


    <!-- ==================更新 ========== -->
    <update id="updateByPrimaryKey"
            parameterType="com.gic.haoban.manage.service.entity.licence.TabHaobanLicenceOrderProgress">
        UPDATE tab_haoban_licence_order_progress
        SET id=#{id,jdbcType=BIGINT},
            enterprise_id=#{enterpriseId,jdbcType=VARCHAR},
            wx_enterprise_id=#{wxEnterpriseId,jdbcType=VARCHAR},
            order_id=#{orderId,jdbcType=BIGINT},
            order_status=#{orderStatus,jdbcType=VARCHAR},
            type=#{type,jdbcType=INTEGER},
            voucher=#{voucher,jdbcType=VARCHAR},
            reason=#{reason,jdbcType=VARCHAR},
            delete_flag=#{deleteFlag,jdbcType=INTEGER},
            create_time=#{createTime,jdbcType=TIMESTAMP},
            update_time=#{updateTime,jdbcType=TIMESTAMP},
            creator_name=#{creatorName,jdbcType=VARCHAR}
        where id = #{id}
    </update>

    <!-- ============ 查询=============-->
    <select id="selectById" parameterType="long" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM tab_haoban_licence_order_progress WHERE id = #{id} and delete_flag=0
    </select>


    <select id="getListByOrderId" parameterType="long" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM tab_haoban_licence_order_progress WHERE order_id = #{orderId}
        <if test="type != null">
            and type=#{type}
        </if>
        and delete_flag=0 order by create_time desc
    </select>

    <update id="deleteByOrderId" parameterType="long">
        UPDATE tab_haoban_licence_order_progress
        SET delete_flag = 1
        WHERE order_id = #{orderId}
    </update>

    <update id="uploadLicenceOrderVoucher" >
        UPDATE tab_haoban_licence_order_progress
        SET voucher = #{voucher}
        WHERE order_id = #{orderId} and delete_flag = 0
    </update>

</mapper> 