<?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.ruoyi.system.mapper.WorkerMoneyLogMapper">
    
    <resultMap type="WorkerMoneyLog" id="WorkerMoneyLogResult">
        <result property="id"    column="id"    />
        <result property="workerId"    column="worker_id"    />
        <result property="oid"    column="oid"    />
        <result property="orderId"    column="order_id"    />
        <result property="price"    column="price"    />
        <result property="type"    column="type"    />
        <result property="servicePrice"    column="service_price"    />
        <result property="reductionPrice"    column="reduction_price"    />
        <result property="cr"    column="cr"    />
        <result property="mergin"    column="mergin"    />
        <result property="doorPrice"    column="door_price"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectWorkerMoneyLogVo">
        select id, worker_id, oid, order_id, price, type, service_price, reduction_price, cr, mergin, door_price, created_at, updated_at from worker_money_log
    </sql>

    <select id="selectWorkerMoneyLogList" parameterType="WorkerMoneyLog" resultMap="WorkerMoneyLogResult">
        <include refid="selectWorkerMoneyLogVo"/>
        <where>  
            <if test="workerId != null "> and worker_id = #{workerId}</if>
            <if test="oid != null "> and oid = #{oid}</if>
            <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
            <if test="price != null "> and price = #{price}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="servicePrice != null "> and service_price = #{servicePrice}</if>
            <if test="reductionPrice != null "> and reduction_price = #{reductionPrice}</if>
            <if test="cr != null "> and cr = #{cr}</if>
            <if test="mergin != null "> and mergin = #{mergin}</if>
            <if test="doorPrice != null "> and door_price = #{doorPrice}</if>
        </where>
    </select>
    
    <select id="selectWorkerMoneyLogById" parameterType="Integer" resultMap="WorkerMoneyLogResult">
        <include refid="selectWorkerMoneyLogVo"/>
        where id = #{id}
    </select>

    <insert id="insertWorkerMoneyLog" parameterType="WorkerMoneyLog" useGeneratedKeys="true" keyProperty="id">
        insert into worker_money_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workerId != null">worker_id,</if>
            <if test="oid != null">oid,</if>
            <if test="orderId != null">order_id,</if>
            <if test="price != null">price,</if>
            <if test="type != null">type,</if>
            <if test="servicePrice != null">service_price,</if>
            <if test="reductionPrice != null">reduction_price,</if>
            <if test="cr != null">cr,</if>
            <if test="mergin != null">mergin,</if>
            <if test="doorPrice != null">door_price,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workerId != null">#{workerId},</if>
            <if test="oid != null">#{oid},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="price != null">#{price},</if>
            <if test="type != null">#{type},</if>
            <if test="servicePrice != null">#{servicePrice},</if>
            <if test="reductionPrice != null">#{reductionPrice},</if>
            <if test="cr != null">#{cr},</if>
            <if test="mergin != null">#{mergin},</if>
            <if test="doorPrice != null">#{doorPrice},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateWorkerMoneyLog" parameterType="WorkerMoneyLog">
        update worker_money_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="workerId != null">worker_id = #{workerId},</if>
            <if test="oid != null">oid = #{oid},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="price != null">price = #{price},</if>
            <if test="type != null">type = #{type},</if>
            <if test="servicePrice != null">service_price = #{servicePrice},</if>
            <if test="reductionPrice != null">reduction_price = #{reductionPrice},</if>
            <if test="cr != null">cr = #{cr},</if>
            <if test="mergin != null">mergin = #{mergin},</if>
            <if test="doorPrice != null">door_price = #{doorPrice},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWorkerMoneyLogById" parameterType="Integer">
        delete from worker_money_log where id = #{id}
    </delete>

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