<?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="cn.iocoder.yudao.module.contract.mapper.ContractHistoryMapper">

    <resultMap type="cn.iocoder.yudao.module.contract.entity.ContractHistory" id="ContractHistoryResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="contractId"    column="contract_id"    />
        <result property="signContract"    column="sign_contract"    />
        <result property="createTime"    column="create_time"    />
        <result property="creator"    column="creator"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updater"    column="updater"    />
    </resultMap>

    <sql id="selectContractHistoryVo">
        select id, user_id, contract_id, sign_contract, create_time, creator, update_time, updater from contract_history
    </sql>

    <select id="selectContractHistoryList" parameterType="cn.iocoder.yudao.module.contract.entity.ContractHistory" resultType="cn.iocoder.yudao.module.contract.entity.ContractHistory">
        SELECT
        history.id,
        history.user_id,
        history.contract_id,
        history.sign_contract,
        history.create_time,
        history.creator as creator,
        history.update_time,
        history.updater as updater,
        su.real_name,
        su.phonenumber as phoneNum
        FROM
        contract_history history
        LEFT JOIN sys_user su  on 	su.user_id = history.user_id
        <where>
            <if test="phoneNum != null "> and su.phonenumber like concat('%',#{phoneNum},'%') </if>
            <if test="realName != null "> and su.real_name = #{realName}</if>
        </where>
    </select>

    <select id="selectContractHistoryById" parameterType="Long" resultMap="ContractHistoryResult">
        <include refid="selectContractHistoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertContractHistory" parameterType="cn.iocoder.yudao.module.contract.entity.ContractHistory">
        insert into contract_history
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="contractId != null">contract_id,</if>
            <if test="signContract != null">sign_contract,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creator != null">creator,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updater != null">updater,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="contractId != null">#{contractId},</if>
            <if test="signContract != null">#{signContract},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creator != null">#{creator},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updater != null">#{updater},</if>
         </trim>
    </insert>

    <update id="updateContractHistory" parameterType="cn.iocoder.yudao.module.contract.entity.ContractHistory">
        update contract_history
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="contractId != null">contract_id = #{contractId},</if>
            <if test="signContract != null">sign_contract = #{signContract},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updater != null">updater = #{updater},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteContractHistoryById" parameterType="Long">
        delete from contract_history where id = #{id}
    </delete>

    <delete id="deleteContractHistoryByIds" parameterType="String">
        delete from contract_history where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="partnerGetWtList" resultType="cn.iocoder.yudao.module.contract.entity.InspectionContract">
        SELECT
            *
        FROM
            `inspection_contract`
        WHERE 1=1
          <if test="bren !=null and bren!=''">
              and bren like CONCAT('%',#{bren},'%')
          </if>
        <if test="brphone !=null and brphone!=''">
            and brphone like CONCAT('%',#{brphone},'%')
        </if>

        <if test="wtr !=null and wtr!=''">
            and wtr like CONCAT('%',#{wtr},'%')
        </if>
        <if test="wtrphone !=null and wtrphone!=''">
            and wtrphone like CONCAT('%',#{wtrphone},'%')
        </if>
        <if test="carnum !=null and carnum!=''">
            and carnum like CONCAT('%',#{carnum},'%')
        </if>

    </select>
</mapper>
