43 lines
1.3 KiB
Java
43 lines
1.3 KiB
Java
package com.designhub.mapper;
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.designhub.entity.UserTitle;
|
|
import org.apache.ibatis.annotations.Mapper;
|
|
import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.annotations.Select;
|
|
import org.apache.ibatis.annotations.Update;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 用户称号Mapper
|
|
*/
|
|
@Mapper
|
|
public interface UserTitleMapper extends BaseMapper<UserTitle> {
|
|
|
|
/**
|
|
* 获取用户的所有称号
|
|
*/
|
|
@Select("SELECT * FROM user_title WHERE user_id = #{userId} ORDER BY is_active DESC, create_time DESC")
|
|
List<UserTitle> selectByUserId(@Param("userId") Long userId);
|
|
|
|
/**
|
|
* 获取用户激活的称号
|
|
*/
|
|
@Select("SELECT * FROM user_title WHERE user_id = #{userId} AND is_active = 1 LIMIT 1")
|
|
UserTitle selectActiveByUserId(@Param("userId") Long userId);
|
|
|
|
/**
|
|
* 检查用户是否拥有某称号
|
|
*/
|
|
@Select("SELECT COUNT(*) FROM user_title WHERE user_id = #{userId} AND title_code = #{titleCode}")
|
|
int countByUserAndTitle(@Param("userId") Long userId, @Param("titleCode") String titleCode);
|
|
|
|
/**
|
|
* 取消用户所有称号的激活状态
|
|
*/
|
|
@Update("UPDATE user_title SET is_active = 0 WHERE user_id = #{userId}")
|
|
int deactivateAllByUserId(@Param("userId") Long userId);
|
|
}
|
|
|