<?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.scm.contract.dao.cancel.TagCancelDao">

    <sql id="columns">
        a.`id` AS "id",
		a.`tag_type_id` AS "tagTypeId",
		a.`number` AS "number",
		a.`status` AS "status",
		a.`operator_id` AS "operatorId",
		a.`operator_name` AS "operatorName",
		a.`reprint_code_id` AS "reprintCodeId",
		a.`create_time` AS "cTime",
		a.`update_time` AS "updateTime"
    </sql>

    <sql id="joins">
    </sql>

    <insert id="save">
        INSERT INTO
        tag_cancel_record
        (
        `id`,
        `tag_type_id`,
        `number`,
        `status`,
        `operator_id`,
        `operator_name`,
        `reprint_code_id`
        )
        VALUES
            (
            #{id},
            #{tagTypeId},
            #{number},
            #{status},
            #{operatorId},
            #{operatorName},
            #{reprintCodeId}
            )
    </insert>

    <update id="updateNumber">
        UPDATE `tag_cancel_record` SET `number` = #{number} WHERE `reprint_code_id` = #{reprintCodeId}
    </update>

    <delete id="deleteByReprintCodeId">
        DELETE FROM tag_cancel_record WHERE `reprint_code_id` = #{reprintCodeId}
    </delete>

    <select id="findList" resultType="com.scm.contract.model.cancel.TagCancel">
        SELECT
        <include refid="columns"/>
        FROM tag_cancel_record a
        <include refid="joins"/>
        <where>
            <if test="id != null and id != ''">
                AND a.id = #{id}
            </if>
            <if test="beginTime != null and endTime != null ">
                AND a.create_time BETWEEN #{beginTime} AND #{endTime}
            </if>
            <if test="tagTypeId != null and tagTypeId != ''">
                AND a.tag_type_id = #{tagTypeId}
            </if>
            <if test="operatorId != null and operatorId != ''">
                AND a.operator_id = #{operatorId}
            </if>
            <if test="operatorName != null and operatorName != ''">
                AND a.`operator_name` LIKE '%' #{operatorName} '%'
            </if>
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
        </choose>
    </select>
</mapper>
