<?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.zehong.system.mapper.TDetectorUserErrorMapper">
    
    <resultMap type="TDetectorUserError" id="TDetectorUserErrorResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="userType"    column="user_type"    />
        <result property="gasType"    column="gas_type"    />
        <result property="villageName"    column="village_name"    />
        <result property="address"    column="address"    />
        <result property="linkman"    column="linkman"    />
        <result property="phone"    column="phone"    />
        <result property="remarks"    column="remarks"    />
        <result property="errorMsg"    column="error_msg"    />
    </resultMap>

    <sql id="selectTDetectorUserErrorVo">
        select user_id, nick_name, beyond_enterprise_name, beyond_enterprise_id,user_type, gas_type, village_name, address, linkman, phone, remarks, error_msg from t_detector_user_error
    </sql>

    <select id="selectTDetectorUserErrorList" parameterType="TDetectorUserError" resultMap="TDetectorUserErrorResult">
        <include refid="selectTDetectorUserErrorVo"/>
        <where>  
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="beyondEnterpriseName != null  and beyondEnterpriseName != ''"> and beyond_enterprise_name like concat('%', #{beyondEnterpriseName}, '%')</if>
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != '' and beyondEnterpriseId != '-2'"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="userType != null  and userType != ''"> and user_type = #{userType}</if>
            <if test="gasType != null  and gasType != ''"> and gas_type = #{gasType}</if>
            <if test="villageName != null  and villageName != ''"> and village_name like concat('%', #{villageName}, '%')</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="linkman != null  and linkman != ''"> and linkman = #{linkman}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="errorMsg != null  and errorMsg != ''"> and error_msg = #{errorMsg}</if>
        </where>
    </select>
    
    <select id="selectTDetectorUserErrorById" parameterType="Long" resultMap="TDetectorUserErrorResult">
        <include refid="selectTDetectorUserErrorVo"/>
        where user_id = #{userId}
    </select>
        
    <insert id="insertTDetectorUserError" parameterType="TDetectorUserError" useGeneratedKeys="true" keyProperty="userId">
        insert into t_detector_user_error
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nickName != null">nick_name,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="userType != null">user_type,</if>
            <if test="gasType != null">gas_type,</if>
            <if test="villageName != null">village_name,</if>
            <if test="address != null">address,</if>
            <if test="linkman != null">linkman,</if>
            <if test="phone != null">phone,</if>
            <if test="remarks != null">remarks,</if>
            <if test="errorMsg != null">error_msg,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nickName != null">#{nickName},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="userType != null">#{userType},</if>
            <if test="gasType != null">#{gasType},</if>
            <if test="villageName != null">#{villageName},</if>
            <if test="address != null">#{address},</if>
            <if test="linkman != null">#{linkman},</if>
            <if test="phone != null">#{phone},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="errorMsg != null">#{errorMsg},</if>
         </trim>
    </insert>
    <insert id="insertBatch" parameterType="list">
        insert into t_detector_user_error (nick_name, beyond_enterprise_name, user_type, gas_type, village_name,
                                           address, linkman, phone, remarks, error_msg)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.nickName,jdbcType=VARCHAR}, #{item.beyondEnterpriseName,jdbcType=VARCHAR},
            #{item.userType,jdbcType=VARCHAR}, #{item.gasType,jdbcType=VARCHAR}, #{item.villageName,jdbcType=VARCHAR},
            #{item.address,jdbcType=DECIMAL}, #{item.linkman,jdbcType=DECIMAL}, #{item.phone,jdbcType=VARCHAR},
            #{item.remarks,jdbcType=VARCHAR}, #{item.errorMsg,jdbcType=TIMESTAMP}
            )
        </foreach>
    </insert>

    <update id="updateTDetectorUserError" parameterType="TDetectorUserError">
        update t_detector_user_error
        <trim prefix="SET" suffixOverrides=",">
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="gasType != null">gas_type = #{gasType},</if>
            <if test="villageName != null">village_name = #{villageName},</if>
            <if test="address != null">address = #{address},</if>
            <if test="linkman != null">linkman = #{linkman},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="errorMsg != null">error_msg = #{errorMsg},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteTDetectorUserErrorById" parameterType="Long">
        delete from t_detector_user_error where user_id = #{userId}
    </delete>

    <delete id="deleteTDetectorUserErrorByIds" parameterType="String">
        delete from t_detector_user_error where user_id in 
        <foreach item="userId" collection="array" open="(" separator="," close=")">
            #{userId}
        </foreach>
    </delete>
    <select id="countByBeyondEnterpriseId" parameterType="String" resultType="int">
        select count(*) from t_detector_user_error
        <where>
            <if test="beyondEnterpriseId != null and beyondEnterpriseId != '' and beyondEnterpriseId != '-2'">
                beyond_enterprise_id = #{beyondEnterpriseId}
            </if>
        </where>
    </select>
    <delete id="clearByBeyondEnterpriseId" parameterType="String">
        delete from t_detector_user_error
        <where>
            <if test="beyondEnterpriseId != null and beyondEnterpriseId != '' and beyondEnterpriseId != '-2'">
                beyond_enterprise_id = #{beyondEnterpriseId}
            </if>
        </where>
    </delete>
</mapper>