<?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.api.manage.dao.butlerService.SysSecurityManagementDao">

    <select id="list" parameterType="com.api.model.butlerService.SearchSecurityManagement" resultType="com.api.vo.butlerService.VoSecurityManagement">
        select sem.*,su.actual_name as create_name
        from sys_security_management as sem,sys_user as su
        <where>
            sem.create_id = su.id
            <if test="name != null and name != ''">
                and sem.name like concat('%',#{name},'%')
            </if>
            <if test="type != null">
                and sem.type = #{type}
            </if>
            <if test="createId != null">
                and sem.create_id = #{createId}
            </if>
            <if test="happenDateStart != null">
                and sem.happen_date <![CDATA[ >= ]]> #{happenDateStart}
            </if>
            <if test="happenDateEnd != null">
                and sem.happen_date <![CDATA[ <= ]]> #{happenDateEnd}
            </if>
        </where>
        order by sem.create_date desc
    </select>

    <insert id="insert" parameterType="com.api.model.butlerService.SecurityManagement">
        insert into sys_security_management(
            code,
            name,
            type,
            details,
            happen_date,
            create_id,
            create_date
        )value (
            #{code},
            #{name},
            #{type},
            #{details},
            #{happenDate},
            #{createId},
            #{createDate}
        )
        <selectKey keyProperty="id" resultType="java.lang.Integer">
            select LAST_INSERT_ID() AS id
        </selectKey>
    </insert>

    <select id="findAllCreateName" resultType="com.api.vo.basicArchives.VoFindAll">
        select sem.create_id as value,su.actual_name as label
        from sys_security_management as sem,sys_user as su
        where sem.create_id = su.id
    </select>

    <select id="findById" parameterType="java.lang.Integer" resultType="com.api.vo.butlerService.VoFBISecurityManagement">
        select * from sys_security_management where id = #{id}
    </select>

    <update id="update" parameterType="com.api.model.butlerService.SecurityManagement">
        update sys_security_management
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="type != null">
                type = #{type},
            </if>
            <if test="details != null and details != ''">
                details = #{details},
            </if>
            <if test="happenDate != null">
                happen_date = #{happenDate},
            </if>
            modify_id = #{modifyId},
            modify_date = #{modifyDate}
        </set>
        where id = #{id}
    </update>

    <delete id="delete" parameterType="java.lang.Integer">
        delete from sys_security_management where id = #{id}
    </delete>


</mapper>