<?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.warehouse.mapper.WmsBatchJobMapper">
    <resultMap type="WmsBatchJob" id="WmsBatchJobResult">
        <id property="id" column="id"/>
        <result property="jobNo" column="job_no"/>
        <result property="sourceType" column="source_type"/>
        <result property="bizType" column="biz_type"/>
        <result property="fileName" column="file_name"/>
        <result property="filePath" column="file_path"/>
        <result property="status" column="status"/>
        <result property="progress" column="progress"/>
        <result property="totalCount" column="total_count"/>
        <result property="successCount" column="success_count"/>
        <result property="failCount" column="fail_count"/>
        <result property="errorMsg" column="error_msg"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectWmsBatchJobVo">
        select id, job_no, source_type, biz_type, file_name, file_path, status, progress,
               total_count, success_count, fail_count, error_msg, create_by, create_time, update_time
        from wms_batch_job
    </sql>

    <select id="selectWmsBatchJobList" parameterType="WmsBatchJob" resultMap="WmsBatchJobResult">
        <include refid="selectWmsBatchJobVo"/>
        <where>
            <if test="jobNo != null and jobNo != ''">and job_no like concat('%', #{jobNo}, '%')</if>
            <if test="sourceType != null and sourceType != ''">and source_type = #{sourceType}</if>
            <if test="bizType != null and bizType != ''">and biz_type = #{bizType}</if>
            <if test="status != null">and status = #{status}</if>
        </where>
        order by id desc
    </select>

    <select id="selectWmsBatchJobById" parameterType="Long" resultMap="WmsBatchJobResult">
        <include refid="selectWmsBatchJobVo"/> where id = #{id}
    </select>

    <insert id="insertWmsBatchJob" parameterType="WmsBatchJob" useGeneratedKeys="true" keyProperty="id">
        insert into wms_batch_job(job_no, source_type, biz_type, file_name, file_path, status, progress,
                                  total_count, success_count, fail_count, error_msg, create_by, create_time)
        values(#{jobNo}, #{sourceType}, #{bizType}, #{fileName}, #{filePath}, #{status}, #{progress},
               #{totalCount}, #{successCount}, #{failCount}, #{errorMsg}, #{createBy}, sysdate())
    </insert>

    <update id="updateWmsBatchJob" parameterType="WmsBatchJob">
        update wms_batch_job
        <set>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="bizType != null">biz_type = #{bizType},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="filePath != null">file_path = #{filePath},</if>
            <if test="status != null">status = #{status},</if>
            <if test="progress != null">progress = #{progress},</if>
            <if test="totalCount != null">total_count = #{totalCount},</if>
            <if test="successCount != null">success_count = #{successCount},</if>
            <if test="failCount != null">fail_count = #{failCount},</if>
            error_msg = #{errorMsg},
            update_time = sysdate()
        </set>
        where id = #{id}
    </update>
</mapper>
