You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

102 lines
3.9 KiB

<?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.epmet.dao.AuthorizationInfoDao">
<!-- 插入 授权信息 -->
<insert id="insertAuthorizationInfo" parameterType="com.epmet.dto.form.AuthorizationInfoFormDTO">
INSERT INTO authorization_info ( ID, CUSTOMER_ID, AUTHORIZER_APPID, AUTHORIZER_ACCESS_TOKEN, EXPIRES_IN_TIME, AUTHORIZER_REFRESH_TOKEN, FUNC_INFO, CLIENT_TYPE, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME )
VALUES
(
REPLACE ( UUID(), '-', '' ),
#{customerId},
#{authorizerAppid},
#{authorizerAccessToken},
#{expiresInTime},
#{authorizerRefreshToken},
#{funcInfo},
#{clientType},
#{delFlag},
#{createdBy},
NOW(),
#{updatedBy},
NOW()
)
</insert>
<!-- 逻辑删除授权信息 -->
<update id="updateOldAuthorizationInfo">
update authorization_info set del_flag = 1 where authorizer_appid = #{authAppId}
</update>
<!-- 询即将过期的 authorizer_access_token -->
<select id="checkWillOverDue" resultType="com.epmet.dto.result.WillOverDueResultDTO">
SELECT
authorizer_access_token AS authorizerAccessToken,
authorizer_refresh_token AS authorizerRefreshToken,
authorizer_appid AS authAppId,
customer_id AS customerId,
client_type AS clientType
FROM
authorization_info
WHERE
del_flag = 0
AND (UNIX_TIMESTAMP(expires_in_time) - UNIX_TIMESTAMP(NOW())) <![CDATA[ <= ]]> 900
</select>
<!-- 插入 authorizer_access_token -->
<insert id="insertAuthorizerAccessToken" parameterType="com.epmet.dto.form.AuthorizerAccessTokenFormDTO">
INSERT INTO authorization_info ( ID, AUTHORIZER_ACCESS_TOKEN, EXPIRES_IN_TIME, AUTHORIZER_REFRESH_TOKEN, AUTHORIZER_APPID, CUSTOMER_ID,CLIENT_TYPE, DEL_FLAG, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME )
VALUES
(
REPLACE ( UUID(), '-', '' ),
#{authorizerAccessToken},
#{expiresInTime},
#{authorizerRefreshToken},
#{authAppid},
#{customerId},
#{clientType},
#{delFlag},
#{createdBy},
NOW(),
#{updatedBy},
NOW()
)
</insert>
<!-- 逻辑删 authorizer_access_token -->
<delete id="deleteOldAuthorizerAccessToken">
delete from authorization_info where customer_id = #{customerId} AND client_type = #{clientType}
</delete>
<select id="getAuthInfoByCustomer" resultType="com.epmet.dto.AuthorizationInfoDTO">
SELECT AUTHORIZER_APPID,
AUTHORIZER_ACCESS_TOKEN
FROM authorization_info
WHERE CUSTOMER_ID = #{customerId}
AND CLIENT_TYPE = #{clientType}
AND DEL_FLAG = 0
AND EXPIRES_IN_TIME > NOW()
</select>
<!-- 根据 authAppId 查询客户ID和客户端类型 -->
<select id="selectCustomerIdByAuthAppId" resultType="com.epmet.dto.result.AuthCodeResultDTO">
SELECT
customer_id AS customerId,
client_type AS clientType
FROM
authorization_info
WHERE
del_flag = 0
AND authorizer_appid = #{authAppId}
</select>
<select id="getAuthInfoByCustomerId" resultType="com.epmet.dto.AuthorizationInfoDTO">
SELECT AUTHORIZER_APPID,
AUTHORIZER_ACCESS_TOKEN
FROM authorization_info
WHERE CUSTOMER_ID = #{customerId}
AND DEL_FLAG = 0
AND EXPIRES_IN_TIME > NOW()
</select>
</mapper>