<?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.business.mapper.TEbsRecordMapper">

    <resultMap type="TEbsRecord" id="TEbsRecordResult">
        <result property="recordId"    column="record_id"    />
        <result property="methodName"    column="method_name"    />
        <result property="apiId"    column="api_id"    />
        <result property="apiUrl"    column="api_url"    />
        <result property="apiParam"    column="api_param"    />
        <result property="result"    column="result"    />
        <result property="status"    column="status"    />
        <result property="description"    column="description"    />
        <result property="operateTime"    column="operate_time"    />
        <result property="goodsId"    column="goods_id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="lotId"    column="lot_id"    />
        <result property="quantity"    column="quantity"    />
    </resultMap>

    <sql id="selectTEbsRecordVo">
        select record_id, method_name, api_id, api_url, api_param, result, status, description, operate_time, goods_id, goods_name, lot_id, quantity from t_ebs_record
    </sql>

    <select id="selectTEbsRecordList" parameterType="TEbsRecord" resultMap="TEbsRecordResult">
        <include refid="selectTEbsRecordVo"/>
        <where>  
            <if test="methodName != null  and methodName != ''"> and method_name like concat('%', #{methodName}, '%')</if>
            <if test="apiId != null and apiId != 0"> and api_id = #{apiId}</if>
            <if test="apiUrl != null  and apiUrl != ''"> and api_url = #{apiUrl}</if>
            <if test="apiParam != null  and apiParam != ''"> and api_param = #{apiParam}</if>
            <if test="result != null  and result != ''"> and result = #{result}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="description != null  and description != ''"> and description like concat('%', #{description}, '%')</if>
            <if test="operateTime != null"> and operate_time = #{operateTime}</if>
            <if test="goodsId != null  and goodsId != ''"> and goods_id like concat('%', #{goodsId}, '%')</if>
            <if test="goodsName != null  and goodsName != ''"> and goods_name like concat('%', #{goodsName}, '%')</if>
            <if test="lotId != null  and lotId != ''"> and lot_id like concat('%', #{lotId}, '%')</if>
            <if test="quantity != null"> and quantity = #{quantity}</if>
        </where>
        order by operate_time desc
    </select>
    
    <select id="selectTEbsRecordByRecordId" parameterType="Long" resultMap="TEbsRecordResult">
        <include refid="selectTEbsRecordVo"/>
        where record_id = #{recordId}
    </select>
        
    <insert id="insertTEbsRecord" parameterType="TEbsRecord" useGeneratedKeys="true" keyProperty="recordId">
        insert into t_ebs_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="methodName != null">method_name,</if>
            <if test="apiId != null">api_id,</if>
            <if test="apiUrl != null">api_url,</if>
            <if test="apiParam != null">api_param,</if>
            <if test="result != null">result,</if>
            <if test="status != null">status,</if>
            <if test="description != null">description,</if>
            <if test="goodsId != null">goods_id,</if>
            <if test="goodsName != null">goods_name,</if>
            <if test="lotId != null">lot_id,</if>
            <if test="quantity != null">quantity,</if>
            operate_time,
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="methodName != null">#{methodName},</if>
            <if test="apiId != null">#{apiId},</if>
            <if test="apiUrl != null">#{apiUrl},</if>
            <if test="apiParam != null">#{apiParam},</if>
            <if test="result != null">#{result},</if>
            <if test="status != null">#{status},</if>
            <if test="description != null">#{description},</if>
            <if test="goodsId != null">#{goodsId},</if>
            <if test="goodsName != null">#{goodsName},</if>
            <if test="lotId != null">#{lotId},</if>
            <if test="quantity != null">#{quantity},</if>
            now()
         </trim>
    </insert>

    <update id="updateTEbsRecord" parameterType="TEbsRecord">
        update t_ebs_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="methodName != null">method_name = #{methodName},</if>
            <if test="apiId != null">api_id = #{apiId},</if>
            <if test="apiUrl != null">api_url = #{apiUrl},</if>
            <if test="apiParam != null">api_param = #{apiParam},</if>
            <if test="result != null">result = #{result},</if>
            <if test="status != null">status = #{status},</if>
            <if test="description != null">description = #{description},</if>
            <if test="goodsId != null">goods_id = #{goodsId},</if>
            <if test="goodsName != null">goods_name = #{goodsName},</if>
            <if test="lotId != null">lot_id = #{lotId},</if>
            <if test="quantity != null">quantity = #{quantity},</if>
            operate_time = now(),
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteTEbsRecordByRecordId" parameterType="Long">
        delete from t_ebs_record where record_id = #{recordId}
    </delete>

    <delete id="deleteTEbsRecordByRecordIds" parameterType="String">
        delete from t_ebs_record where record_id in 
        <foreach item="recordId" collection="array" open="(" separator="," close=")">
            #{recordId}
        </foreach>
    </delete>

</mapper>