<?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.dcsoft.system.mapper.SysEmpowerRecordMapper">

    <resultMap type="SysEmpowerRecord" id="SysEmpowerRecordResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="peopleId"    column="people_id"    />
        <result property="infoDown"    column="info_down"    />
        <result property="empower"    column="empower"    />
        <result property="equipmentId"    column="equipment_id"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <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="ruleId"    column="rule_id"    />
        <result property="entryExitType"    column="entry_exit_type"    />
        <association property="equipment"    column="equipment_id" javaType="SysEquipment" resultMap="equipmentResult" />
        <association property="people"    column="people_id" javaType="SysPeople" resultMap="peopleResult" />
    </resultMap>

    <resultMap id="equipmentResult" type="SysEquipment">
        <id     property="id"    column="equipment_id"     />
        <result property="name"  column="equipmentName"   />
    </resultMap>

    <resultMap id="peopleResult" type="SysPeople">
        <id     property="id"    column="people_id"     />
        <result property="name"  column="peopleName"   />
        <result property="avatar"  column="peopleAvatar"   />
    </resultMap>

    <sql id="selectSysEmpowerRecordVo">
        select ser.id, ser.name, ser.people_id, ser.info_down, ser.empower, ser.equipment_id, ser.status, ser.remark, ser.create_by,
               ser.create_time, ser.update_by, ser.update_time, ser.rule_id, p.name peopleName,p.avatar peopleAvatar,e.name equipmentName,
               e.entry_exit_type
        from sys_empower_record ser
            left join sys_people p on ser.people_id=p.id
            left join sys_equipment e on ser.equipment_id=e.id
    </sql>

    <select id="selectSysEmpowerRecordList" parameterType="SysEmpowerRecord" resultMap="SysEmpowerRecordResult">
        <include refid="selectSysEmpowerRecordVo"/>
        <where>
            <if test="name != null  and name != ''"> and ser.name like concat('%', #{name}, '%')</if>
            <if test="peopleId != null"> and ser.people_id = #{peopleId}</if>
            <if test="peopleName != null  and peopleName != ''"> and p.name like concat('%', #{peopleName}, '%')</if>
            <if test="infoDown != null  and infoDown != ''"> and ser.info_down = #{infoDown}</if>
            <if test="empower != null  and empower != ''"> and ser.empower = #{empower}</if>
            <if test="equipmentId != null "> and ser.equipment_id = #{equipmentId}</if>
            <if test="status != null  and status != ''"> and ser.status = #{status}</if>
            <if test="ruleId != null "> and ser.rule_id = #{ruleId}</if>
            <if test="gh != null "> and p.gh = #{gh}</if>
        </where>
    </select>

    <select id="selectSysEmpowerRecordById" parameterType="Long" resultMap="SysEmpowerRecordResult">
        <include refid="selectSysEmpowerRecordVo"/>
        where ser.id = #{id}
    </select>

    <insert id="insertSysEmpowerRecord" parameterType="SysEmpowerRecord" useGeneratedKeys="true" keyProperty="id">
        insert into sys_empower_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="peopleId != null">people_id,</if>
            <if test="infoDown != null">info_down,</if>
            <if test="empower != null">empower,</if>
            <if test="equipmentId != null">equipment_id,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</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="ruleId != null">rule_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="peopleId != null">#{peopleId},</if>
            <if test="infoDown != null">#{infoDown},</if>
            <if test="empower != null">#{empower},</if>
            <if test="equipmentId != null">#{equipmentId},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</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="ruleId != null">#{ruleId},</if>
         </trim>
    </insert>

    <update id="updateSysEmpowerRecord" parameterType="SysEmpowerRecord">
        update sys_empower_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="peopleId != null">people_id = #{peopleId},</if>
            <if test="infoDown != null">info_down = #{infoDown},</if>
            <if test="empower != null">empower = #{empower},</if>
            <if test="equipmentId != null">equipment_id = #{equipmentId},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</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="ruleId != null">rule_id = #{ruleId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysEmpowerRecordById" parameterType="Long">
        delete from sys_empower_record where id = #{id}
    </delete>

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

    <delete id="deleteSysEmpowerRecordByPeopleId" parameterType="Long">
        delete from sys_empower_record where people_id = #{peopleId}
    </delete>
</mapper>
