Files
sb-backend/src/main/resources/mapper/MemberMapper.xml
T

136 lines
6.1 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sb.web.auth.mapper.MemberMapper">
<resultMap id="memberResultMap" type="com.sb.web.auth.domain.Member">
<id property="id" column="id"/>
<result property="loginId" column="login_id"/>
<result property="password" column="password"/>
<result property="name" column="name"/>
<result property="email" column="email"/>
<result property="provider" column="provider"/>
<result property="providerId" column="provider_id"/>
<result property="googleId" column="google_id"/>
<result property="googlePicture" column="google_picture"/>
<result property="profileImage" column="profile_image"/>
<result property="role" column="role"/>
<result property="plan" column="plan"/>
<result property="planExpiresAt" column="plan_expires_at"/>
<result property="planProduct" column="plan_product"/>
<result property="planAutoRenew" column="plan_auto_renew"/>
<result property="points" column="points"/>
<result property="status" column="status"/>
<result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/>
</resultMap>
<sql id="columns">
id, login_id, password, name, email, provider, provider_id, google_id, google_picture, profile_image, role, plan, plan_expires_at, plan_product, plan_auto_renew, points, status, created_at, updated_at
</sql>
<select id="findById" parameterType="long" resultMap="memberResultMap">
SELECT <include refid="columns"/> FROM member WHERE id = #{id}
</select>
<!-- 관리자 목록: 무거운 profile_image(MEDIUMTEXT)·password 는 제외하고 가볍게 조회 -->
<select id="findAll" resultMap="memberResultMap">
SELECT id, login_id, name, email, provider, provider_id, google_id, role, plan, points, status, created_at, updated_at
FROM member ORDER BY id
</select>
<select id="findByLoginId" parameterType="string" resultMap="memberResultMap">
SELECT <include refid="columns"/> FROM member WHERE login_id = #{loginId}
</select>
<select id="findByProvider" resultMap="memberResultMap">
SELECT <include refid="columns"/>
FROM member
WHERE provider = #{provider} AND provider_id = #{providerId}
</select>
<!-- 구글 sub 로 회원 조회 (연결된 LOCAL 계정 + 순수 구글 계정 모두 google_id 로 찾음) -->
<select id="findByGoogleId" parameterType="string" resultMap="memberResultMap">
SELECT <include refid="columns"/> FROM member WHERE google_id = #{googleId}
</select>
<!-- 구글 로그인 시 같은 이메일의 기존 계정 1건(연결 대상). LOCAL 계정 우선. -->
<select id="findByEmailForLink" parameterType="string" resultMap="memberResultMap">
SELECT <include refid="columns"/>
FROM member
WHERE email = #{email} AND status = 'ACTIVE' AND google_id IS NULL
ORDER BY (provider = 'LOCAL') DESC, id ASC
LIMIT 1
</select>
<!-- 기존 계정에 구글 연결 (provider 는 그대로 유지) -->
<update id="linkGoogle">
UPDATE member SET google_id = #{googleId}, updated_at = NOW() WHERE id = #{id}
</update>
<select id="countByLoginId" parameterType="string" resultType="int">
SELECT COUNT(*) FROM member WHERE login_id = #{loginId}
</select>
<insert id="insert" parameterType="com.sb.web.auth.domain.Member"
useGeneratedKeys="true" keyProperty="id">
INSERT INTO member (login_id, password, name, email, provider, provider_id, google_id, google_picture, role, status, created_at, updated_at)
VALUES (#{loginId}, #{password}, #{name}, #{email},
#{provider}, #{providerId}, #{googleId}, #{googlePicture}, #{role}, #{status}, NOW(), NOW())
</insert>
<update id="updatePassword">
UPDATE member SET password = #{password}, updated_at = NOW() WHERE id = #{id}
</update>
<update id="updateProfile">
UPDATE member SET name = #{name}, email = #{email}, updated_at = NOW() WHERE id = #{id}
</update>
<update id="updateGooglePicture">
UPDATE member SET google_picture = #{googlePicture}, updated_at = NOW() WHERE id = #{id}
</update>
<update id="updateProfileImage">
UPDATE member SET profile_image = #{profileImage}, updated_at = NOW() WHERE id = #{id}
</update>
<update id="updateRole">
UPDATE member SET role = #{role}, updated_at = NOW() WHERE id = #{id}
</update>
<!-- 관리자 수동 변경: 만료일/구독정보 없이(영구) 설정/해제 -->
<update id="updatePlan">
UPDATE member SET plan = #{plan}, plan_expires_at = NULL, plan_product = NULL, plan_auto_renew = 0,
updated_at = NOW() WHERE id = #{id}
</update>
<!-- 결제로 멤버십 부여/갱신: plan + 만료일 + 구독상품 + 자동갱신 -->
<update id="updateMembership">
UPDATE member SET plan = #{plan}, plan_expires_at = #{expiresAt},
plan_product = #{product}, plan_auto_renew = #{autoRenew}, updated_at = NOW()
WHERE id = #{id}
</update>
<!-- 구독 해지/재개: 자동 갱신 플래그만 변경 (이용은 만료일까지 유지) -->
<update id="updateAutoRenew">
UPDATE member SET plan_auto_renew = #{autoRenew}, updated_at = NOW() WHERE id = #{id}
</update>
<!-- 만료된 '해지(자동갱신 off)' 유료회원만 강등 (자동갱신 건은 마켓 갱신/RTDN 이 관리) -->
<update id="downgradeExpired">
UPDATE member SET plan = 'FREE', plan_product = NULL, plan_auto_renew = 0, updated_at = NOW()
WHERE plan = 'PREMIUM' AND plan_auto_renew = 0
AND plan_expires_at IS NOT NULL AND plan_expires_at &lt; NOW()
</update>
<update id="updateStatus">
UPDATE member SET status = #{status}, updated_at = NOW() WHERE id = #{id}
</update>
<delete id="deleteById">
DELETE FROM member WHERE id = #{id}
</delete>
</mapper>