<?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.jkcredit.invoice.mapper.customer.CustomerOperMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.jkcredit.invoice.model.entity.customer.CustomerOper">
        <id column="id" property="id"/>
        <result column="customerName" property="customerName"/>
        <result column="customerPhone" property="customerPhone"/>
        <result column="company" property="company"/>
        <result column="createTime" property="createTime"/>
        <result column="batchNumber" property="batchNumber"/>
        <result column="operType" property="operType"/>
        <result column="batchStatus" property="batchStatus"/>
    </resultMap>

    <sql id="baseSql">
        id,
        customerName,
        customerPhone,
        company,
        createTime,
        batchNumber,
        operType,
        batchStatus
    </sql>
    <select id="selectAllByPage" resultMap="BaseResultMap">
        select
        <include refid="baseSql" />
        from t_cusomerOper
        <where>
            <if test="customerOper.customerName != null and customerOper.customerName != ''">
                AND  customerName = BINARY #{customerOper.customerName}
            </if>
            <if test="customerOper.company != null and customerOper.company != ''">
                AND  company LIKE BINARY CONCAT('%',#{customerOper.company},'%')
            </if>
            <if test="customerOper.batchNumber != null and customerOper.batchNumber != ''">
                AND  batchNumber LIKE CONCAT('%',#{customerOper.batchNumber},'%')
            </if>
            <if test="customerOper.operType != null and customerOper.operType != ''">
                AND   operType = #{customerOper.operType}
            </if>
        </where>
         order by batchNumber desc
    </select>
    <insert id="insert" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerOper" >
        insert into t_cusomerOper (
            customerName,
            customerPhone,
            company,
            createTime,
            batchNumber,
            operType,
            batchStatus
        )
        values ( #{customerName,jdbcType=VARCHAR}, #{customerPhone,jdbcType=VARCHAR},
            #{company,jdbcType=VARCHAR},#{createTime,jdbcType=VARCHAR}, #{batchNumber,jdbcType=INTEGER},
            #{operType,jdbcType=INTEGER},#{batchStatus,jdbcType=INTEGER}
        )
    </insert>
    <resultMap id="notfinishCont" type="java.lang.Integer">
        <result column="notfinishCont" property="notfinishCont"/>
    </resultMap>
    <select id="countHasNotFinish" parameterType="java.lang.String" resultMap="notfinishCont">
        select count(1) notfinishCont from t_cusomerOper where customerName = #{customerName,jdbcType=VARCHAR} and batchStatus=1 and operType=1
    </select>
    <update id="updateStatus" parameterType="java.util.Map">
        UPDATE t_cusomerOper SET batchStatus = #{batchStatus,jdbcType=INTEGER} where batchNumber =  #{batchNumber,jdbcType=VARCHAR}
    </update>
</mapper>
