刘嘉昕 | 88d3f7d | 2025-06-04 11:54:09 +0800 | [diff] [blame^] | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 3 | <mapper namespace="com.pt5.pthouduan.mapper.UserMapper"> |
| 4 | |
| 5 | <!-- 通用查询映射结果 --> |
| 6 | <resultMap id="BaseResultMap" type="com.pt5.pthouduan.entity.User"> |
| 7 | <id column="userid" property="userid" /> |
| 8 | <result column="username" property="username" /> |
| 9 | <result column="password" property="password" /> |
| 10 | <result column="user_upload" property="userUpload" /> |
| 11 | <result column="user_download" property="userDownload" /> |
| 12 | <result column="credit" property="credit" /> |
| 13 | <result column="image" property="image" /> |
| 14 | <result column="sex" property="sex" /> |
| 15 | <result column="grade_id" property="gradeId" /> |
| 16 | <result column="passkey" property="passkey" /> |
| 17 | <result column="user_created_time" property="userCreatedTime" /> |
| 18 | <result column="ratio" property="ratio" /> |
| 19 | <result column="age" property="age" /> |
| 20 | <result column="privacy" property="privacy" /> |
| 21 | </resultMap> |
| 22 | |
| 23 | <!-- 通用查询结果列 --> |
| 24 | <sql id="Base_Column_List"> |
| 25 | username, password, user_upload, user_download, credit, image, sex, userid, grade_id, passkey, user_created_time, ratio, age, privacy |
| 26 | </sql> |
| 27 | <!-- 根据 passkey 查询用户名 --> |
| 28 | <select id="getUsernameByPasskey" parameterType="java.lang.String" resultType="java.lang.String"> |
| 29 | SELECT username |
| 30 | FROM user |
| 31 | WHERE passkey = #{passkey} |
| 32 | </select> |
| 33 | |
| 34 | <select id="findSeedersByInfoHash" resultType="com.pt5.pthouduan.entity.PeerInfo"> |
| 35 | SELECT |
| 36 | ps.ip, |
| 37 | ps.port, |
| 38 | ps.peer_id, |
| 39 | ps.uploaded, |
| 40 | ps.upload_speed, |
| 41 | ps.downloaded, |
| 42 | ps.download_speed, |
| 43 | ps.last_event, |
| 44 | ps.last_updated, |
| 45 | ps.created_at, |
| 46 | ps.client, |
| 47 | ps.username, |
| 48 | ps.created_at, |
| 49 | ps.completed_time, |
| 50 | ps.port |
| 51 | FROM peer_stats ps |
| 52 | WHERE ps.info_hash = #{infoHash} |
| 53 | </select> |
| 54 | |
| 55 | |
| 56 | |
| 57 | <!-- 根据 passkey 检查用户是否存在 --> |
| 58 | <select id="existsByPasskey" resultType="boolean"> |
| 59 | SELECT COUNT(*) > 0 |
| 60 | FROM user |
| 61 | WHERE passkey = #{passkey} |
| 62 | </select> |
| 63 | |
| 64 | <!-- <update id="incrementUserTraffic">--> |
| 65 | <!-- UPDATE user--> |
| 66 | <!-- SET user_upload = user_upload + #{user_upload},--> |
| 67 | <!-- user_download = user_download + #{user_download}--> |
| 68 | <!-- WHERE passkey = #{passkey}--> |
| 69 | <!-- </update>--> |
| 70 | <update id="incrementUserTraffic"> |
| 71 | UPDATE user u |
| 72 | JOIN torrent t ON t.info_hash = #{info_hash} AND u.passkey = #{passkey} |
| 73 | SET |
| 74 | u.user_upload = u.user_upload + ( |
| 75 | CASE |
| 76 | WHEN t.promotionid = 1 THEN #{user_upload} * 2 -- 上传加倍 |
| 77 | ELSE #{user_upload} |
| 78 | END |
| 79 | ), |
| 80 | u.user_download = u.user_download + ( |
| 81 | CASE |
| 82 | WHEN t.promotionid = 2 THEN #{user_download} / 2 -- 下载减半 |
| 83 | WHEN t.promotionid = 3 THEN 0 -- 免费下载 |
| 84 | ELSE #{user_download} |
| 85 | END |
| 86 | ) |
| 87 | </update> |
| 88 | |
| 89 | |
| 90 | |
| 91 | </mapper> |