<?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.TInspectionAccidentMapper">

    <resultMap type="com.zehong.system.domain.TInspectionAccident" id="TInspectionAccidentResult">
        <result property="id"    column="id"    />
        <result property="accidentName"    column="accident_name"    />
        <result property="happenDate"    column="happen_date"    />
        <result property="accidentLocation"    column="accident_location"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="accidentDescription"    column="accident_description"    />
        <result property="accidentReason"    column="accident_reason"    />
        <result property="obligationPerson"    column="obligation_person"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTInspectionAccidentVo">
        select id, accident_name, happen_date, accident_location, longitude, latitude, accident_description, accident_reason, obligation_person, beyond_enterprise_id, beyond_enterprise_name, create_time, remark from t_inspection_accident
    </sql>

    <select id="selectTInspectionAccidentList" parameterType="com.zehong.system.domain.TInspectionAccident" resultMap="TInspectionAccidentResult">
        <include refid="selectTInspectionAccidentVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="accidentName != null  and accidentName != ''"> and accident_name like concat('%', #{accidentName}, '%')</if>
            <if test="happenDate != null  and happenDate != ''"> and happen_date = #{happenDate}</if>
            <if test="obligationPerson != null  and obligationPerson != ''"> and obligation_person = #{obligationPerson}</if>
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="beyondEnterpriseName != null  and beyondEnterpriseName != ''"> and beyond_enterprise_name like concat('%', #{beyondEnterpriseName}, '%')</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
        </where>
    </select>

    <select id="selectTInspectionAccidentById" parameterType="Long" resultMap="TInspectionAccidentResult">
        <include refid="selectTInspectionAccidentVo"/>
        where id = #{id}
    </select>

    <insert id="insertTInspectionAccident" parameterType="com.zehong.system.domain.TInspectionAccident" useGeneratedKeys="true" keyProperty="id">
        insert into t_inspection_accident
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="accidentName != null">accident_name,</if>
            <if test="happenDate != null">happen_date,</if>
            <if test="accidentLocation != null">accident_location,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="accidentDescription != null">accident_description,</if>
            <if test="accidentReason != null">accident_reason,</if>
            <if test="obligationPerson != null">obligation_person,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="accidentName != null">#{accidentName},</if>
            <if test="happenDate != null">#{happenDate},</if>
            <if test="accidentLocation != null">#{accidentLocation},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="accidentDescription != null">#{accidentDescription},</if>
            <if test="accidentReason != null">#{accidentReason},</if>
            <if test="obligationPerson != null">#{obligationPerson},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTInspectionAccident" parameterType="com.zehong.system.domain.TInspectionAccident">
        update t_inspection_accident
        <trim prefix="SET" suffixOverrides=",">
            <if test="accidentName != null">accident_name = #{accidentName},</if>
            <if test="happenDate != null">happen_date = #{happenDate},</if>
            <if test="accidentLocation != null">accident_location = #{accidentLocation},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="accidentDescription != null">accident_description = #{accidentDescription},</if>
            <if test="accidentReason != null">accident_reason = #{accidentReason},</if>
            <if test="obligationPerson != null">obligation_person = #{obligationPerson},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTInspectionAccidentById" parameterType="Long">
        delete from t_inspection_accident where id = #{id}
    </delete>

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

    <insert id="insertBatch" parameterType="list">
        insert into t_inspection_accident (accident_name, happen_date, accident_location, longitude, latitude, accident_description,
        accident_reason, obligation_person, beyond_enterprise_id, beyond_enterprise_name, create_time, remark)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.accidentName,jdbcType=VARCHAR}, #{item.happenDate}, #{item.accidentLocation},
            #{item.longitude},#{item.latitude},#{item.accidentDescription}, #{item.accidentReason},
            #{item.obligationPerson},#{item.beyondEnterpriseId},#{item.beyondEnterpriseName},#{item.createTime},#{item.remark}
            )
        </foreach>
    </insert>
</mapper>