<?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.dayou.mapper.PostPrivilegeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.PostPrivilege">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="post_id" property="postId" />
        <result column="permission_tree" property="permissionTree" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        created,
        modified,
        post_id, permission_tree
    </sql>

    <insert id="saveOrUpdateById">
        insert into post_privilege(`post_id`, `permission_tree`) values
            (#{postPrivilege.postId},#{postPrivilege.permissionTree})
            on duplicate key update
        <![CDATA[`permission_tree` = case when values(`permission_tree`) <> '' then values(`permission_tree`) else `permission_tree` end

        ]]>
    </insert>

</mapper>
