<?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.zehong.system.mapper.TCashOperateMapper">
    
    <resultMap type="TCashOperate" id="TCashOperateResult">
        <result property="operateId"    column="operate_id"    />
        <result property="operateDeptId"    column="operate_dept_id"    />
        <result property="operateType"    column="operate_type"    />
        <result property="operateAmount"    column="operate_amount"    />
        <result property="relationDoc"    column="relation_doc"    />
        <result property="operateTime"    column="operate_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remark"    column="remark"    />
        <result property="operateDeptName" column="operate_dept_name"/>
        <result property="documentType" column="document_type"/>

    </resultMap>

    <sql id="selectTCashOperateVo">
        select operate_id, operate_dept_id, operate_type, operate_amount, relation_doc, operate_time, create_time, update_time, is_del, remark,document_type,(SELECT dept_name FROM sys_dept WHERE dept_id = operate_dept_id)AS operate_dept_name from t_cash_operate
    </sql>

    <select id="selectTCashOperateList" parameterType="TCashOperate" resultMap="TCashOperateResult">
        <include refid="selectTCashOperateVo"/>
        <where>  
            <if test="operateDeptId != null "> and operate_dept_id = #{operateDeptId}</if>
            <if test="operateType != null  and operateType != ''"> and operate_type = #{operateType}</if>
            <if test="operateAmount != null "> and operate_amount = #{operateAmount}</if>
            <if test="relationDoc != null  and relationDoc != ''"> and relation_doc = #{relationDoc}</if>
            <if test="operateTime != null "> and operate_time = #{operateTime}</if>
            <if test="beginOperatorTime != null and endOperatorTime != null"> and operate_time BETWEEN #{beginOperatorTime} AND #{endOperatorTime}</if>
            <if test="isDel != null  and isDel != ''"> and is_del = #{isDel}</if>
        </where>
        ORDER BY operate_time DESC
    </select>
    
    <select id="selectTCashOperateById" parameterType="Long" resultMap="TCashOperateResult">
        <include refid="selectTCashOperateVo"/>
        where operate_id = #{operateId}
    </select>
        
    <insert id="insertTCashOperate" parameterType="TCashOperate" useGeneratedKeys="true" keyProperty="operateId">
        insert into t_cash_operate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="operateDeptId != null">operate_dept_id,</if>
            <if test="operateType != null">operate_type,</if>
            <if test="operateAmount != null">operate_amount,</if>
            <if test="relationDoc != null">relation_doc,</if>
            <if test="operateTime != null">operate_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remark != null">remark,</if>
            <if test="documentType != null">document_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="operateDeptId != null">#{operateDeptId},</if>
            <if test="operateType != null">#{operateType},</if>
            <if test="operateAmount != null">#{operateAmount},</if>
            <if test="relationDoc != null">#{relationDoc},</if>
            <if test="operateTime != null">#{operateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remark != null">#{remark},</if>
            <if test="documentType != null">#{documentType}</if>
         </trim>
    </insert>

    <update id="updateTCashOperate" parameterType="TCashOperate">
        update t_cash_operate
        <trim prefix="SET" suffixOverrides=",">
            <if test="operateDeptId != null">operate_dept_id = #{operateDeptId},</if>
            <if test="operateType != null">operate_type = #{operateType},</if>
            <if test="operateAmount != null">operate_amount = #{operateAmount},</if>
            <if test="relationDoc != null">relation_doc = #{relationDoc},</if>
            <if test="operateTime != null">operate_time = #{operateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where operate_id = #{operateId}
    </update>

    <delete id="deleteTCashOperateById" parameterType="Long">
        delete from t_cash_operate where operate_id = #{operateId}
    </delete>

    <delete id="deleteTCashOperateByIds" parameterType="String">
        delete from t_cash_operate where operate_id in 
        <foreach item="operateId" collection="array" open="(" separator="," close=")">
            #{operateId}
        </foreach>
    </delete>
</mapper>