<?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="cn.hellohao.dao.KeysMapper">


    <!-- 查询对象存储key-->
    <select id="selectKeys" parameterType="integer" resultType="cn.hellohao.pojo.Keys">
        SELECT
            *
        FROM
            `keys`
        WHERE
            id = #{id}
    </select>
    <!-- 查询添加的所有对象存储-->
    <select id="getStorageName"  resultType="cn.hellohao.pojo.Keys">
        select id,keyname,storageType from `keys`
    </select>

    <!-- 查询对象存储有多少种-->
    <select id="getStorage"  resultType="cn.hellohao.pojo.Keys">
        SELECT id,storageType,
               CASE WHEN storageType=1 THEN '网易云'
                    WHEN storageType=2 THEN '阿里云'
                    WHEN storageType=3 THEN '又拍云'
                    WHEN storageType=4 THEN '七牛云'
                    WHEN storageType=5 THEN '本地'
                    WHEN storageType=6 THEN '腾讯云'
                    WHEN storageType=7 THEN 'FTP'
                    WHEN storageType=8 THEN 'UFile'
                    ELSE  '未知' END AS storageName,
               keyname
        FROM `keys`  GROUP BY storageType

    </select>

    <!-- 查询对象存储key-->
    <select id="getKeys" parameterType="integer" resultType="cn.hellohao.pojo.Keys">
        SELECT
            *
        FROM
            `keys`
    </select>

    <update id="updateKey" parameterType="cn.hellohao.pojo.Keys">
        UPDATE `keys`
        SET AccessKey = #{AccessKey},
        AccessSecret = #{AccessSecret},
        Endpoint = #{Endpoint},
        Bucketname = #{Bucketname},
        RequestAddress = #{RequestAddress},
        keyname = #{keyname}
        WHERE
            storageType = #{storageType}
    </update>
</mapper>