<?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.supervision.bdglSecret.mapper.SecretAccountMapper">
    
    <resultMap type="SecretAccount" id="SecretAccountResult">
        <result property="id"    column="id"    />
        <result property="unitname"    column="unitName"    />
        <result property="stype"    column="stype"    />
        <result property="brand"    column="brand"    />
        <result property="model"    column="model"    />
        <result property="harddisknumber"    column="hardDiskNumber"    />
        <result property="macaddress"    column="macAddress"    />
        <result property="confidentialitylevel"    column="confidentialityLevel"    />
        <result property="levelnumber"    column="levelNumber"    />
        <result property="persoeliable"    column="persoeLiable"    />
        <result property="remarks"    column="remarks"    />
        <result property="unitid"    column="unitId"    />
    </resultMap>

    <sql id="selectSecretAccountVo">
        select id, unitName, stype, brand, model, hardDiskNumber, macAddress, confidentialityLevel, levelNumber, persoeLiable, remarks, unitId from secret_account
    </sql>

    <select id="selectSecretAccountList" parameterType="SecretAccount" resultMap="SecretAccountResult">
        <include refid="selectSecretAccountVo"/>
        <where>  
            <if test="unitname != null  and unitname != ''"> and unitName like concat('%', #{unitname}, '%')</if>
            <if test="stype != null  and stype != ''"> and stype = #{stype}</if>
            <if test="brand != null  and brand != ''"> and brand = #{brand}</if>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="harddisknumber != null  and harddisknumber != ''"> and hardDiskNumber = #{harddisknumber}</if>
            <if test="macaddress != null  and macaddress != ''"> and macAddress = #{macaddress}</if>
            <if test="confidentialitylevel != null  and confidentialitylevel != ''"> and confidentialityLevel = #{confidentialitylevel}</if>
            <if test="levelnumber != null  and levelnumber != ''"> and levelNumber = #{levelnumber}</if>
            <if test="persoeliable != null  and persoeliable != ''"> and persoeLiable = #{persoeliable}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="unitid != null "> and unitId = #{unitid}</if>
        </where>
    </select>
    
    <select id="selectSecretAccountById" parameterType="Long" resultMap="SecretAccountResult">
        <include refid="selectSecretAccountVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSecretAccount" parameterType="SecretAccount">
        insert into secret_account
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="unitname != null">unitName,</if>
            <if test="stype != null">stype,</if>
            <if test="brand != null">brand,</if>
            <if test="model != null">model,</if>
            <if test="harddisknumber != null">hardDiskNumber,</if>
            <if test="macaddress != null">macAddress,</if>
            <if test="confidentialitylevel != null">confidentialityLevel,</if>
            <if test="levelnumber != null">levelNumber,</if>
            <if test="persoeliable != null">persoeLiable,</if>
            <if test="remarks != null">remarks,</if>
            <if test="unitid != null">unitId,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="unitname != null">#{unitname},</if>
            <if test="stype != null">#{stype},</if>
            <if test="brand != null">#{brand},</if>
            <if test="model != null">#{model},</if>
            <if test="harddisknumber != null">#{harddisknumber},</if>
            <if test="macaddress != null">#{macaddress},</if>
            <if test="confidentialitylevel != null">#{confidentialitylevel},</if>
            <if test="levelnumber != null">#{levelnumber},</if>
            <if test="persoeliable != null">#{persoeliable},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="unitid != null">#{unitid},</if>
         </trim>
    </insert>

    <update id="updateSecretAccount" parameterType="SecretAccount">
        update secret_account
        <trim prefix="SET" suffixOverrides=",">
            <if test="unitname != null">unitName = #{unitname},</if>
            <if test="stype != null">stype = #{stype},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="model != null">model = #{model},</if>
            <if test="harddisknumber != null">hardDiskNumber = #{harddisknumber},</if>
            <if test="macaddress != null">macAddress = #{macaddress},</if>
            <if test="confidentialitylevel != null">confidentialityLevel = #{confidentialitylevel},</if>
            <if test="levelnumber != null">levelNumber = #{levelnumber},</if>
            <if test="persoeliable != null">persoeLiable = #{persoeliable},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="unitid != null">unitId = #{unitid},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSecretAccountById" parameterType="Long">
        delete from secret_account where id = #{id}
    </delete>

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