<?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.hdkj.lt.bf.mapper.SystemThemeMapper">
    <insert id="addThemeColor">
        INSERT INTO `USER_SYS_COLOR`(USER_ID,SYSTEM_COLOR) VALUES (#{themeColorVo.userId},#{themeColorVo.themeColor})
    </insert>
    <update id="updateColor">
        UPDATE USER_SYS_COLOR usc
        SET usc.SYSTEM_COLOR =
            (SELECT
                 sdd.dict_value
            FROM sys_dict_type sdt
            LEFT JOIN sys_dict_data sdd ON sdt.dict_type = sdd.dict_type
            WHERE sdt.dict_type = 'system_color' AND sdd.dict_sort = #{param})
        WHERE usc.USER_ID = #{userId}
    </update>

    <select id="getThemeColor" resultType="com.hdkj.lt.bf.entity.vo.ThemeColorVo">
        SELECT usc.USER_ID AS userId, usc.SYSTEM_COLOR AS themeColor FROM USER_SYS_COLOR usc WHERE usc.USER_ID = #{userId}
    </select>
    <select id="getThemeColorSort" resultType="java.lang.Integer">
        SELECT
            sdd.dict_sort
        FROM
            sys_dict_type sdt
        LEFT JOIN
            sys_dict_data sdd ON sdt.dict_type = sdd.dict_type
        INNER JOIN
            USER_SYS_COLOR usc ON usc.SYSTEM_COLOR =sdd.dict_value
        WHERE sdt.dict_type = 'system_color' AND usc.USER_ID = #{userId}
    </select>

    <select id="getAllSort" resultType="java.lang.Integer">
        SELECT
            COUNT(1)
        FROM sys_dict_type sdt
        LEFT JOIN
            sys_dict_data sdd on sdt.dict_type = sdd.dict_type
        WHERE sdt.dict_type = 'system_color'
    </select>
</mapper>