Files
game_server/target/classes/mapper/account/UserAccountMapper.xml

89 lines
4.1 KiB
XML

<?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.gameplatform.server.mapper.account.UserAccountMapper">
<resultMap id="UserAccountMap" type="com.gameplatform.server.model.entity.account.UserAccount">
<id property="id" column="id" />
<result property="userType" column="user_type" />
<result property="username" column="username" />
<result property="displayName" column="display_name" />
<result property="passwordHash" column="password_hash" />
<result property="role" column="role" />
<result property="status" column="status" />
<result property="pointsBalance" column="points_balance" />
<result property="createdAt" column="created_at" />
<result property="updatedAt" column="updated_at" />
</resultMap>
<select id="findByUsernameAndType" resultMap="UserAccountMap">
SELECT id, user_type, username, display_name, password_hash, role, status, points_balance, created_at, updated_at
FROM user_account
WHERE username = #{username}
AND user_type = #{userType}
LIMIT 1
</select>
<select id="findByUsername" resultMap="UserAccountMap">
SELECT id, user_type, username, display_name, password_hash, role, status, points_balance, created_at, updated_at
FROM user_account
WHERE username = #{username}
LIMIT 1
</select>
<select id="findById" parameterType="long" resultMap="UserAccountMap">
SELECT id, user_type, username, display_name, password_hash, role, status, points_balance, created_at, updated_at
FROM user_account
WHERE id = #{id}
LIMIT 1
</select>
<insert id="insert" parameterType="com.gameplatform.server.model.entity.account.UserAccount" useGeneratedKeys="true" keyProperty="id">
INSERT INTO user_account (user_type, username, display_name, password_hash, role, status, points_balance)
VALUES (#{userType}, #{username}, #{displayName}, #{passwordHash}, #{role}, #{status}, #{pointsBalance})
</insert>
<update id="update" parameterType="com.gameplatform.server.model.entity.account.UserAccount">
UPDATE user_account
<set>
<if test="displayName != null">display_name = #{displayName},</if>
<if test="role != null">role = #{role},</if>
<if test="status != null">status = #{status},</if>
</set>
WHERE id = #{id}
</update>
<update id="setStatus">
UPDATE user_account SET status = #{status} WHERE id = #{id}
</update>
<update id="updatePassword">
UPDATE user_account SET password_hash = #{passwordHash} WHERE id = #{id}
</update>
<select id="countByFilter" resultType="long">
SELECT COUNT(1) FROM user_account
<where>
<if test="userType != null and userType != ''">AND user_type = #{userType}</if>
<if test="status != null and status != ''">AND status = #{status}</if>
<if test="role != null and role != ''">AND role = #{role}</if>
<if test="keyword != null and keyword != ''">
AND (username LIKE CONCAT('%', #{keyword}, '%') OR display_name LIKE CONCAT('%', #{keyword}, '%'))
</if>
</where>
</select>
<select id="listByFilter" resultMap="UserAccountMap">
SELECT id, user_type, username, display_name, password_hash, role, status, points_balance, created_at, updated_at
FROM user_account
<where>
<if test="userType != null and userType != ''">AND user_type = #{userType}</if>
<if test="status != null and status != ''">AND status = #{status}</if>
<if test="role != null and role != ''">AND role = #{role}</if>
<if test="keyword != null and keyword != ''">
AND (username LIKE CONCAT('%', #{keyword}, '%') OR display_name LIKE CONCAT('%', #{keyword}, '%'))
</if>
</where>
ORDER BY id DESC
LIMIT #{size} OFFSET #{offset}
</select>
</mapper>