<?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.inspect.metadata.bdconfig.mapper.BasedataBdConfigMainSystemMapper">

    <resultMap type="BasedataBdConfigMainSystem" id="BasedataBdConfigMainSystemResult">
        <result property="mainSystemId" column="main_system_id"/>
        <result property="mainSystemCode" column="main_system_code"/>
        <result property="mainSystemName" column="main_system_name"/>
        <result property="manufacturerCode" column="manufacturer_code"/>
        <result property="systemType" column="system_type"/>
        <result property="manufacturerName" column="manufacturer_name"/>
        <result property="startUseTime" column="start_use_time"/>
        <result property="convertFlag" column="convert_flag"/>
        <result property="ipAddr" column="ip_addr"/>
        <result property="port" column="port"/>
        <result property="username" column="username"/>
        <result property="password" column="password"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="algConvertFlag" column="alg_convert_flag"/>
    </resultMap>

    <sql id="selectBasedataBdConfigMainSystemVo">
        select main_system_id,
               main_system_code,
               main_system_name,
               manufacturer_code,
               system_type,
               manufacturer_name,
               start_use_time,
               convert_flag,
               ip_addr,
               port,
               username,
               password,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               alg_convert_flag
        from basedata_bdconfig_mainsystem
    </sql>

    <select id="selectBasedataBdConfigMainSystemList" parameterType="BasedataBdConfigMainSystem"
            resultMap="BasedataBdConfigMainSystemResult">
        <include refid="selectBasedataBdConfigMainSystemVo"/>
        <where>
            <if test="mainSystemCode != null  and mainSystemCode != ''">and main_system_code = #{mainSystemCode}</if>
            <if test="mainSystemName != null  and mainSystemName != ''">and main_system_name like concat('%',
                #{mainSystemName}, '%')
            </if>
            <if test="manufacturerCode != null  and manufacturerCode != ''">and manufacturer_code =
                #{manufacturerCode}
            </if>
            <if test="systemType != null  and systemType != ''">and system_type = #{systemType}</if>
            <if test="manufacturerName != null  and manufacturerName != ''">and manufacturer_name like concat('%',
                #{manufacturerName}, '%')
            </if>
            <if test="startUseTime != null ">and start_use_time = #{startUseTime}</if>
            <if test="convertFlag != null  and convertFlag != ''">and convert_flag = #{convertFlag}</if>
            <if test="ipAddr != null  and ipAddr != ''">and ip_addr = #{ipAddr}</if>
            <if test="port != null  and port != ''">and port = #{port}</if>
            <if test="username != null  and username != ''">and username like concat('%', #{username}, '%')</if>
            <if test="password != null  and password != ''">and password = #{password}</if>
            <if test="algConvertFlag != null  and algConvertFlag != ''">and alg_convert_flag = #{algConvertFlag}</if>
        </where>
    </select>

    <select id="selectBasedataBdConfigMainSystemByMainSystemId" parameterType="Long"
            resultMap="BasedataBdConfigMainSystemResult">
        <include refid="selectBasedataBdConfigMainSystemVo"/>
        where main_system_id = #{mainSystemId}
    </select>

    <insert id="insertBasedataBdConfigMainSystem" parameterType="BasedataBdConfigMainSystem" useGeneratedKeys="true"
            keyProperty="mainSystemId">
        insert into basedata_bdconfig_mainsystem
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mainSystemCode != null and mainSystemCode != ''">main_system_code,</if>
            <if test="mainSystemName != null">main_system_name,</if>
            <if test="manufacturerCode != null and manufacturerCode != ''">manufacturer_code,</if>
            <if test="systemType != null and systemType != ''">system_type,</if>
            <if test="manufacturerName != null and manufacturerName != ''">manufacturer_name,</if>
            <if test="startUseTime != null">start_use_time,</if>
            <if test="convertFlag != null">convert_flag,</if>
            <if test="ipAddr != null">ip_addr,</if>
            <if test="port != null">port,</if>
            <if test="username != null">username,</if>
            <if test="password != null">password,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="algConvertFlag != null">alg_convert_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mainSystemCode != null and mainSystemCode != ''">#{mainSystemCode},</if>
            <if test="mainSystemName != null">#{mainSystemName},</if>
            <if test="manufacturerCode != null and manufacturerCode != ''">#{manufacturerCode},</if>
            <if test="systemType != null and systemType != ''">#{systemType},</if>
            <if test="manufacturerName != null and manufacturerName != ''">#{manufacturerName},</if>
            <if test="startUseTime != null">#{startUseTime},</if>
            <if test="convertFlag != null">#{convertFlag},</if>
            <if test="ipAddr != null">#{ipAddr},</if>
            <if test="port != null">#{port},</if>
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="algConvertFlag != null">#{algConvertFlag},</if>
        </trim>
    </insert>

    <update id="updateBasedataBdConfigMainSystem" parameterType="BasedataBdConfigMainSystem">
        update basedata_bdconfig_mainsystem
        <trim prefix="SET" suffixOverrides=",">
            <if test="mainSystemCode != null and mainSystemCode != ''">main_system_code = #{mainSystemCode},</if>
            <if test="mainSystemName != null">main_system_name = #{mainSystemName},</if>
            <if test="manufacturerCode != null and manufacturerCode != ''">manufacturer_code = #{manufacturerCode},</if>
            <if test="systemType != null and systemType != ''">system_type = #{systemType},</if>
            <if test="manufacturerName != null and manufacturerName != ''">manufacturer_name = #{manufacturerName},</if>
            <if test="startUseTime != null">start_use_time = #{startUseTime},</if>
            <if test="convertFlag != null">convert_flag = #{convertFlag},</if>
            <if test="ipAddr != null">ip_addr = #{ipAddr},</if>
            <if test="port != null">port = #{port},</if>
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="algConvertFlag != null">alg_convert_flag = #{algConvertFlag},</if>
        </trim>
        where main_system_id = #{mainSystemId}
    </update>

    <delete id="deleteBasedataBdConfigMainSystemByMainSystemId" parameterType="Long">
        delete
        from basedata_bdconfig_mainsystem
        where main_system_id = #{mainSystemId}
    </delete>

    <delete id="deleteBasedataBdConfigMainSystemByMainSystemIds" parameterType="String">
        delete from basedata_bdconfig_mainsystem where main_system_id in
        <foreach item="mainSystemId" collection="array" open="(" separator="," close=")">
            #{mainSystemId}
        </foreach>
    </delete>

    <select id="selectBasedataBdConfigMainSystemByMainSystemCode" parameterType="String"
            resultMap="BasedataBdConfigMainSystemResult">
        <include refid="selectBasedataBdConfigMainSystemVo"/>
        where main_system_code = #{mainSystemCode} limit 1
    </select>
</mapper>
