<?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="ink.wgink.login.base.dao.login.ILoginFormDao">

    <cache flushInterval="3600000"/>

    <resultMap id="loginFormDTO" type="ink.wgink.login.base.pojo.dtos.login.LoginFormDTO">
        <result column="loginform_id" property="loginFormId"/>
        <result column="name" property="name"/>
        <result column="summary" property="summary"/>
        <result column="is_active" property="isActive"/>
        <result column="preview" property="preview"/>
        <result column="resource_imgs" property="resourceImgs"/>
        <result column="form_html" property="formHtml"/>
        <result column="form_css" property="formCss"/>
        <result column="form_left_css" property="formLeftCss"/>
        <result column="form_center_css" property="formCenterCss"/>
        <result column="form_right_css" property="formRightCss"/>
        <result column="gmt_create" property="gmtCreat"/>
    </resultMap>

    <!-- 建表 -->
    <update id="createTable">
        CREATE TABLE IF NOT EXISTS `sys_login_form` (
            `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
            `loginform_id` char(36) NOT NULL COMMENT '主键',
            `name` varchar(255) NOT NULL COMMENT '名称',
            `summary` varchar(255) DEFAULT NULL COMMENT '说明',
            `is_active` int(1) DEFAULT '1' COMMENT '是否激活',
            `preview` char(36) DEFAULT NULL COMMENT '预览',
            `resource_imgs` text COMMENT '资源图片',
            `form_html` longtext COMMENT 'form代码',
            `form_css` longtext COMMENT 'form样式',
            `form_left_css` text COMMENT 'form左样式',
            `form_center_css` text COMMENT 'form中样式',
            `form_right_css` text COMMENT 'form右样式',
            `gmt_create` datetime DEFAULT NULL,
            `creator` char(36) DEFAULT NULL,
            `gmt_modified` datetime DEFAULT NULL,
            `modifier` char(36) DEFAULT NULL,
            `is_delete` int(1) DEFAULT '1',
            PRIMARY KEY (`id`,`loginform_id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    </update>

    <!-- 新增登录form表单 -->
    <insert id="save" parameterType="map" flushCache="true">
        INSERT INTO sys_login_form(
            loginform_id,
            name,
            summary,
            is_active,
            preview,
            resource_imgs,
            form_html,
            form_css,
            form_left_css,
            form_center_css,
            form_right_css,
            gmt_create,
            creator,
            gmt_modified,
            modifier,
            is_delete
        ) VALUES(
            #{loginFormId},
            #{name},
            #{summary},
            #{isActive},
            #{preview},
            #{resourceImgs},
            #{formHtml},
            #{formCss},
            #{formLeftCss},
            #{formCenterCss},
            #{formRightCss},
            #{gmtCreate},
            #{creator},
            #{gmtModified},
            #{modifier},
            #{isDelete}
        )
    </insert>

    <!-- 删除登录form表单 -->
    <update id="remove" parameterType="map" flushCache="true">
        UPDATE
            sys_login_form
        SET
            is_delete = 1,
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            loginform_id IN
        <foreach collection="loginFormIds" index="index" open="(" separator="," close=")">
            #{loginFormIds[${index}]}
        </foreach>
    </update>

    <!-- 修改登录form表单 -->
    <update id="update" parameterType="map" flushCache="true">
        UPDATE
            sys_login_form
        SET
        <if test="name != null and name != ''">
            name = #{name},
        </if>
        <if test="summary != null and summary != ''">
            summary = #{summary},
        </if>
        <if test="isActive != null">
            is_active = #{isActive},
        </if>
        <if test="preview != null and preview != ''">
            preview = #{preview},
        </if>
        <if test="resourceImgs != null and resourceImgs != ''">
            resource_imgs = #{resourceImgs},
        </if>
        <if test="formHtml != null and formHtml != ''">
            form_html = #{formHtml},
        </if>
        <if test="formCss != null and formCss != ''">
            form_css = #{formCss},
        </if>
        <if test="formLeftCss != null and formLeftCss != ''">
            form_left_css = #{formLeftCss},
        </if>
        <if test="formCenterCss != null and formCenterCss != ''">
            form_center_css = #{formCenterCss},
        </if>
        <if test="formRightCss != null and formRightCss != ''">
            form_right_css = #{formRightCss},
        </if>
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            loginform_id = #{loginFormId}
    </update>

    <!-- 修改激活状态 -->
    <update id="updateActive" parameterType="map" flushCache="true">
        UPDATE
            sys_login_form
        SET
            is_active = #{isActive}
        <where>
            <if test="loginFormId != null and loginFormId != ''">
            loginform_id = #{loginFormId}
            </if>
        </where>
    </update>

    <!-- 登录form表单列表 -->
    <select id="list" parameterType="map" resultMap="loginFormDTO" useCache="true">
        SELECT
            loginform_id,
            name,
            summary,
            is_active,
            preview,
            gmt_create
        FROM
            sys_login_form
    </select>

    <!-- 登录form表单详情 -->
    <select id="get" parameterType="map" resultMap="loginFormDTO" useCache="true">
        SELECT
            loginform_id,
            name,
            summary,
            is_active,
            preview,
            resource_imgs,
            form_html,
            form_css,
            form_left_css,
            form_center_css,
            form_right_css,
            gmt_create
        FROM
            sys_login_form
        WHERE
        <if test="loginFormId != null and loginFormId != ''">
            loginform_id = #{loginFormId}
        </if>
        <if test="isActive != null">
            is_active = #{isActive}
        </if>
    </select>

</mapper>