<?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.brilliance.isc.mda.dao.GimOfcMapper">

    <resultMap type="com.brilliance.isc.bo.Gimofc" id="BaseResultMap">
        <result property="inr" column="INR" jdbcType="VARCHAR"/>
        <result property="biccod" column="BICCOD" jdbcType="VARCHAR"/>
        <result property="msgtyp" column="MSGTYP" jdbcType="VARCHAR"/>
        <result property="ctlcod" column="CTLCOD" jdbcType="VARCHAR"/>
        <result property="begdat" column="BEGDAT" jdbcType="TIMESTAMP"/>
        <result property="enddat" column="ENDDAT" jdbcType="TIMESTAMP"/>
        <result property="usr" column="USR" jdbcType="VARCHAR"/>
    </resultMap>

    <select id="selectCountNum" resultType="int">
        SELECT COUNT(1)
        FROM GIMOFC
        WHERE BICCOD = #{bic,jdbcType=VARCHAR}
          AND MSGTYP = #{msgTyp,jdbcType=VARCHAR}
          AND date_format(ENDDAT, '%Y-%m-%d') = '2299-12-31'
          AND CTLCOD = 'S'
    </select>

    <select id="queryById" resultMap="BaseResultMap">
        select inr,biccod,msgtyp,ctlcod,begdat,enddat,usr from gimofc where inr = #{inr}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="BaseResultMap">
        select inr,biccod,msgtyp,ctlcod,begdat,enddat,usr from gimofc
        where 1=1
        <if test="entity.biccod != null and entity.biccod != ''">
            and biccod like concat(#{entity.biccod},'%')
        </if>
        <if test="entity.msgtyp != null and entity.msgtyp != ''">
            and msgtyp = #{entity.msgtyp}
        </if>
        <if test="entity.ctlcod != null and entity.ctlcod != ''">
            and ctlcod = #{entity.ctlcod}
        </if>
        <if test="entity.enddat != null">
            and date_format(enddat,'%Y-%m-%d') = date_format(#{entity.enddat},'%Y-%m-%d')
        </if>
    </select>

    <insert id="insert">
        insert into GIMOFC(INR, BICCOD, MSGTYP, CTLCOD, BEGDAT, ENDDAT, USR)
        values (#{inr}, #{biccod}, #{msgtyp}, #{ctlcod}, now(), str_to_date('2299-12-31 23:59:00','%Y-%m-%d %H:%i:%s'), #{usr})
    </insert>

    <update id="update">
        update GIMOFC
        <set>
            ENDDAT = now(),
        </set>
        where INR= #{inr}
    </update>

    <!--通过主键删除-->
    <update id="delete">
        update GIMOFC
        <set>
            ENDDAT = now(),
        </set>
        where INR= #{inr}
    </update>

    <select id="selofc" resultType="int">
        select count(1) from GIMOFC where BICCOD = #{biccod} and MSGTYP = #{msgtyp} and CTLCOD = #{ctlcod} and date_format(enddat,'%Y-%m-%d %H:%i:%s') = '2299-12-31 23:59:00'
     </select>

    <select id="selofc2" resultType="int">
        select count(1) from GIMOFC where BICCOD = #{biccod} and MSGTYP = #{msgtyp} and date_format(enddat,'%Y-%m-%d %H:%i:%s') = '2299-12-31 23:59:00'
     </select>

</mapper>