<?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.fs.qw.mapper.QwAccountMapper">

    <resultMap type="QwAccount" id="QwAccountResult">
        <result property="id"    column="id"    />
        <result property="account"    column="account"    />
        <result property="userId"    column="user_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="availableDevice"    column="available_device"    />
        <result property="deptId"    column="dept_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="isAudit"    column="is_audit"    />
        <result property="authCheck"    column="auth_check"    />
        <result property="onlineTime"    column="online_time"    />
        <result property="offlineTime"    column="offline_time"    />
        <result property="offlineType"    column="offline_type"    />
        <result property="remark"    column="remark"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectQwAccountVo">
        select id,online_time,offline_time,offline_type, account, user_id, company_id, device_id, available_device,auth_check, dept_id, company_user_id, is_audit, remark, create_time, update_time from qw_account
    </sql>

    <select id="selectQwAccountList" parameterType="QwAccount" resultMap="QwAccountResult">
        <include refid="selectQwAccountVo"/>
        <where>
            <if test="account != null  and account != ''"> and account = #{account}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="deviceId != null  and deviceId != ''"> and device_id = #{deviceId}</if>
            <if test="availableDevice != null "> and available_device = #{availableDevice}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="isAudit != null "> and is_audit = #{isAudit}</if>
        </where>
    </select>

    <select id="selectQwAccountById" parameterType="Long" resultMap="QwAccountResult">
        <include refid="selectQwAccountVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwAccount" parameterType="QwAccount" useGeneratedKeys="true" keyProperty="id">
        insert into qw_account
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="account != null">account,</if>
            <if test="userId != null">user_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="availableDevice != null">available_device,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="isAudit != null">is_audit,</if>
            <if test="authCheck != null">auth_check,</if>
            <if test="remark != null">remark,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="account != null">#{account},</if>
            <if test="userId != null">#{userId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="availableDevice != null">#{availableDevice},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="isAudit != null">#{isAudit},</if>
            <if test="authCheck != null">#{authCheck},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateQwAccount" parameterType="QwAccount">
        update qw_account
        <trim prefix="SET" suffixOverrides=",">
            <if test="account != null">account = #{account},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="availableDevice != null">available_device = #{availableDevice},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="isAudit != null">is_audit = #{isAudit},</if>
            <if test="onlineTime != null">online_time = #{onlineTime},</if>
            <if test="offlineTime != null">offline_time = #{offlineTime},</if>
            <if test="offlineType != null">offline_type = #{offlineType},</if>
            <if test="authCheck != null">auth_check = #{authCheck},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwAccountById" parameterType="Long">
        delete from qw_account where id = #{id}
    </delete>

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

</mapper>
