<?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.xhpc.general.mapper.XhpcAgreementMapper">

    <resultMap id="BaseResultMap" type="com.xhpc.general.domain.XhpcAgreement">
        <result property="agreementId" column="agreement_id"/>
        <result property="title" column="title"/>
        <result property="content" column="content"/>
        <result property="type" column="type"/>
        <result property="status" column="status"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="remark" column="remark"/>
    </resultMap>
    <!-- 通用查询映射结果 -->

    <update id="deleteAgreementItem">

        update xhpc_agreement set del_flag=1 where agreement_id=#{agreementId}
    </update>

    <select id="countSameTypeTitle" resultType="java.lang.Integer">

        select count(agreement_id) from xhpc_agreement where type=#{type} and title=#{title} and del_flag=0
    </select>


    <insert id="insertAgreementItem">

        insert into xhpc_agreement (title,type,content) values(#{title},#{type},#{content})
    </insert>

    <update id="updateAgreementItem">

        update xhpc_agreement set title=#{title},type=#{type},content=#{content} where agreement_id=#{agreementId}
    </update>


    <select id="selectAgreementItems" resultMap="BaseResultMap">
        select *
        from xhpc_agreement
        where del_flag=0
        <if test="title!=null and title!=''">
            and title like concat('%',#{title},'%')
        </if>
        <if test="createBy!=null and createBy!=''">
            and create_by like concat('%',#{createBy},'%')
        </if>
        <if test="type!=null">
            and type=#{type}
        </if>
    </select>


    <select id="selectAgreementItem" resultMap="BaseResultMap">

        select
        agreement_id,
        title,
        cast(content as char) as content,
        type,
        status,
        del_flag,
        create_time,
        create_by,
        update_time,
        update_by,
        remark
        from xhpc_agreement
        where agreement_id=#{agreementId}
    </select>


    <select id="selectContentType" resultMap="BaseResultMap">

        select *
        from xhpc_agreement
        where type=#{type}
        order by update_time desc
        limit 1
    </select>
</mapper>