<?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.fs.company.mapper.CompanyRedPackageLogsMapper">
    
    <resultMap type="CompanyRedPackageLogs" id="CompanyRedPackageLogsResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="operateType"    column="operate_type"    />
        <result property="type"    column="type"    />
        <result property="upMoney"    column="up_money"    />
        <result property="handlMoney"    column="handl_money"    />
        <result property="handlPri"    column="handl_pri"    />
        <result property="money"    column="money"    />
        <result property="status"    column="status"    />
        <result property="images"    column="images"    />
        <result property="rejectMemo"    column="reject_memo"    />
        <result property="rejectImages"    column="reject_images"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanyRedPackageLogsVo">
        select id, company_id, operate_type, type, up_money, handl_money, handl_pri, money, status, images, reject_memo, reject_images, create_time, create_by, update_by, update_time, remark from company_red_package_logs
    </sql>

    <select id="selectCompanyRedPackageLogsList" parameterType="CompanyRedPackageLogs" resultType="CompanyRedPackageLogs">
        select a.*,b.company_name from company_red_package_logs a inner join company b on a.company_id = b.company_id
        <where>  
            <if test="companyId != null "> and a.company_id = #{companyId}</if>
            <if test="operateType != null "> and a.operate_type = #{operateType}</if>
            <if test="type != null "> and a.type = #{type}</if>
            <if test="upMoney != null "> and a.up_money = #{upMoney}</if>
            <if test="handlMoney != null "> and a.handl_money = #{handlMoney}</if>
            <if test="handlPri != null "> and a.handl_pri = #{handlPri}</if>
            <if test="money != null "> and a.money = #{money}</if>
            <if test="status != null "> and a.status = #{status}</if>
            <if test="images != null  and images != ''"> and a.images = #{images}</if>
            <if test="rejectMemo != null  and rejectMemo != ''"> and a.reject_memo = #{rejectMemo}</if>
            <if test="rejectImages != null  and rejectImages != ''"> and a.reject_images = #{rejectImages}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectCompanyRedPackageLogsById" parameterType="Long" resultMap="CompanyRedPackageLogsResult">
        <include refid="selectCompanyRedPackageLogsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCompanyRedPackageLogs" parameterType="CompanyRedPackageLogs" useGeneratedKeys="true" keyProperty="id">
        insert into company_red_package_logs
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="operateType != null">operate_type,</if>
            <if test="type != null">type,</if>
            <if test="upMoney != null">up_money,</if>
            <if test="handlMoney != null">handl_money,</if>
            <if test="handlPri != null">handl_pri,</if>
            <if test="money != null">money,</if>
            <if test="status != null">status,</if>
            <if test="images != null">images,</if>
            <if test="rejectMemo != null">reject_memo,</if>
            <if test="rejectImages != null">reject_images,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="operateType != null">#{operateType},</if>
            <if test="type != null">#{type},</if>
            <if test="upMoney != null">#{upMoney},</if>
            <if test="handlMoney != null">#{handlMoney},</if>
            <if test="handlPri != null">#{handlPri},</if>
            <if test="money != null">#{money},</if>
            <if test="status != null">#{status},</if>
            <if test="images != null">#{images},</if>
            <if test="rejectMemo != null">#{rejectMemo},</if>
            <if test="rejectImages != null">#{rejectImages},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCompanyRedPackageLogs" parameterType="CompanyRedPackageLogs">
        update company_red_package_logs
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="operateType != null">operate_type = #{operateType},</if>
            <if test="type != null">type = #{type},</if>
            <if test="upMoney != null">up_money = #{upMoney},</if>
            <if test="handlMoney != null">handl_money = #{handlMoney},</if>
            <if test="handlPri != null">handl_pri = #{handlPri},</if>
            <if test="money != null">money = #{money},</if>
            <if test="status != null">status = #{status},</if>
            <if test="images != null">images = #{images},</if>
            <if test="rejectMemo != null">reject_memo = #{rejectMemo},</if>
            <if test="rejectImages != null">reject_images = #{rejectImages},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanyRedPackageLogsById" parameterType="Long">
        delete from company_red_package_logs where id = #{id}
    </delete>

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