<?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.aucma.base.mapper.BaseFactoryMapper">

    <resultMap type="BaseFactory" id="BaseFactoryResult">
            <result property="objId"    column="obj_id"    />
            <result property="companyName"    column="company_name"    />
            <result property="factoryCode"    column="factory_code"    />
            <result property="factoryName"    column="factory_name"    />
            <result property="factoryStatus"    column="factory_status"    />
            <result property="remark"    column="remark"    />
            <result property="createdBy"    column="created_by"    />
            <result property="createdTime"    column="created_time"    />
            <result property="updatedBy"    column="updated_by"    />
            <result property="updatedTime"    column="updated_time"    />
    </resultMap>

    <sql id="selectBaseFactoryVo">
        select obj_id, company_name, factory_code, factory_name, factory_status,
               remark, created_by, created_time, updated_by, updated_time from base_factory
    </sql>

    <select id="selectBaseFactoryList" parameterType="BaseFactory" resultMap="BaseFactoryResult">
        <include refid="selectBaseFactoryVo"/>
        <where>
                        <if test="companyName != null  and companyName != ''"> and company_name like concat(concat('%', #{companyName}), '%')</if>
                        <if test="factoryCode != null  and factoryCode != ''"> and factory_code = #{factoryCode}</if>
                        <if test="factoryName != null  and factoryName != ''"> and factory_name like concat(concat('%', #{factoryName}), '%')</if>
                        <if test="factoryStatus != null  and factoryStatus != ''"> and factory_status = #{factoryStatus}</if>
                        <if test="createdBy != null  and createdBy != ''"> and created_by = #{createdBy}</if>
                        <if test="createdTime != null "> and created_time = #{createdTime}</if>
                        <if test="updatedBy != null  and updatedBy != ''"> and updated_by = #{updatedBy}</if>
                        <if test="updatedTime != null "> and updated_time = #{updatedTime}</if>
        </where>
    </select>

    <select id="selectBaseFactoryByObjId" parameterType="Long" resultMap="BaseFactoryResult">
            <include refid="selectBaseFactoryVo"/>
            where obj_id = #{objId}
    </select>

    <insert id="insertBaseFactory" parameterType="BaseFactory">
            <selectKey keyProperty="objId" resultType="long" order="BEFORE">
                SELECT seq_base_factory.NEXTVAL as objId FROM DUAL
            </selectKey>
        insert into base_factory
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="objId != null">obj_id,</if>
                <if test="companyName != null">company_name,</if>
                <if test="factoryCode != null">factory_code,</if>
                <if test="factoryName != null">factory_name,</if>
                <if test="factoryStatus != null">factory_status,</if>
                <if test="remark != null">remark,</if>
                <if test="createdBy != null">created_by,</if>
                <if test="createdTime != null">created_time,</if>
                <if test="updatedBy != null">updated_by,</if>
                <if test="updatedTime != null">updated_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="objId != null">#{objId},</if>
                <if test="companyName != null">#{companyName},</if>
                <if test="factoryCode != null">#{factoryCode},</if>
                <if test="factoryName != null">#{factoryName},</if>
                <if test="factoryStatus != null">#{factoryStatus},</if>
                <if test="remark != null">#{remark},</if>
                <if test="createdBy != null">#{createdBy},</if>
                <if test="createdTime != null">#{createdTime},</if>
                <if test="updatedBy != null">#{updatedBy},</if>
                <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <update id="updateBaseFactory" parameterType="BaseFactory">
        update base_factory
        <trim prefix="SET" suffixOverrides=",">
                    <if test="companyName != null">company_name = #{companyName},</if>
                    <if test="factoryCode != null">factory_code = #{factoryCode},</if>
                    <if test="factoryName != null">factory_name = #{factoryName},</if>
                    <if test="factoryStatus != null">factory_status = #{factoryStatus},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="createdBy != null">created_by = #{createdBy},</if>
                    <if test="createdTime != null">created_time = #{createdTime},</if>
                    <if test="updatedBy != null">updated_by = #{updatedBy},</if>
                    <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBaseFactoryByObjId" parameterType="Long">
        delete from base_factory where obj_id = #{objId}
    </delete>

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