root | cd43656 | 2025-05-08 14:09:19 +0000 | [diff] [blame] | 1 | package database; |
| 2 | |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 3 | import java.util.Calendar; |
| 4 | import java.util.UUID; |
| 5 | import java.util.List; |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 6 | import java.util.Map; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 7 | import java.util.Date; |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 8 | import java.util.HashMap; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 9 | |
| 10 | import javax.persistence.EntityManager; |
| 11 | import javax.persistence.EntityManagerFactory; |
| 12 | import javax.persistence.EntityTransaction; |
| 13 | import javax.persistence.Persistence; |
| 14 | |
| 15 | import com.querydsl.jpa.impl.JPAQuery; |
| 16 | import com.querydsl.core.Tuple; |
root | ff0769a | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 17 | import entity.QBegInfo; |
| 18 | import entity.QUserVotes; |
| 19 | import entity.QSubmitSeed; |
| 20 | import entity.QProfile; |
| 21 | import entity.QSeed; |
| 22 | import entity.Seed; |
| 23 | import entity.User; |
| 24 | import entity.UserPT; |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 25 | import entity.config; |
root | ff0769a | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 26 | import entity.Notice; |
| 27 | import entity.BegInfo; |
| 28 | import entity.Post; |
| 29 | import entity.PostReply; |
| 30 | import entity.Profile; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 31 | |
| 32 | import org.slf4j.Logger; |
| 33 | import org.slf4j.LoggerFactory; |
| 34 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 35 | public class Database2 implements DataManagerInterface { |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 36 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 37 | private EntityManagerFactory emf; |
| 38 | private static final Logger logger = LoggerFactory.getLogger(Database2.class); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 39 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 40 | // 构造函数,初始化EntityManagerFactory |
| 41 | public Database2() { |
| 42 | config cfg = new config(); |
| 43 | Map<String, Object> props = new HashMap<>(); |
| 44 | props.put("javax.persistence.jdbc.url", |
| 45 | "jdbc:mysql://" + cfg.SqlURL + "/" + cfg.Database); |
| 46 | props.put("javax.persistence.jdbc.user", cfg.SqlUsername); |
| 47 | props.put("javax.persistence.jdbc.password", cfg.SqlPassword); |
| 48 | this.emf = Persistence.createEntityManagerFactory("myPersistenceUnit", props); |
| 49 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 50 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 51 | public Database2(EntityManagerFactory emf) { |
| 52 | this.emf = emf; |
| 53 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 54 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 55 | @Override |
TRM-coding | cdfe548 | 2025-06-06 17:31:01 +0800 | [diff] [blame] | 56 | public String LoginUser(User userinfo){ |
| 57 | return null; |
| 58 | } |
| 59 | |
| 60 | @Override |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 61 | public int RegisterUser(User userinfo) { |
| 62 | return 0; |
| 63 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 64 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 65 | @Override |
| 66 | public int UpdateInformation(User userinfo) { |
| 67 | return 0; |
| 68 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 69 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 70 | @Override |
| 71 | public User GetInformation(String userid) { |
| 72 | return null; |
| 73 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 74 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 75 | @Override |
| 76 | public UserPT GetInformationPT(String userid) { |
| 77 | return null; |
| 78 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 79 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 80 | @Override |
| 81 | public int UpdateInformationPT(UserPT userinfo) { |
| 82 | return 0; |
| 83 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 84 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 85 | @Override |
| 86 | public int RegisterUserPT(UserPT userinfo) { |
| 87 | return 0; |
| 88 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 89 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 90 | @Override |
| 91 | public Seed GetSeedInformation(String seedid) { |
| 92 | return null; |
| 93 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 94 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 95 | @Override |
| 96 | public int RegisterSeed(Seed seedinfo) { |
| 97 | return 0; |
| 98 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 99 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 100 | @Override |
| 101 | public int UpdateSeed(Seed seedinfo) { |
| 102 | return 0; |
| 103 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 104 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 105 | @Override |
| 106 | public Seed[] SearchSeed(String userQ) { |
| 107 | return new Seed[0]; |
| 108 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 109 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 110 | @Override |
| 111 | public int AddNotice(Notice notice) { |
| 112 | return 0; |
| 113 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 114 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 115 | @Override |
| 116 | public boolean UpdateNotice(Notice notice) { |
| 117 | return false; |
| 118 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 119 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 120 | @Override |
| 121 | public boolean DeleteNotice(String noticeid) { |
| 122 | return false; |
| 123 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 124 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 125 | @Override |
| 126 | public int GetUserAvailableInviteTimes(String userid) { |
| 127 | return 0; |
| 128 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 129 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 130 | @Override |
| 131 | public int InviteUser(String inviterid, String inviteemail) { |
| 132 | return 0; |
| 133 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 134 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 135 | @Override |
Raver | aae0612 | 2025-06-05 08:13:35 +0000 | [diff] [blame] | 136 | public Seed[] GetSeedListByTag(String tag) { |
| 137 | return new Seed[0]; |
| 138 | } |
| 139 | |
| 140 | @Override |
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 141 | public Seed[] GetSeedListByUser(String userid) { |
| 142 | return new Seed[0]; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public int DeleteSeed(String seedid) { |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | @Override |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 151 | public boolean AddCollect(String userid, String postid) { |
| 152 | return false; |
| 153 | } |
root | 33a7d95 | 2025-05-18 17:24:41 +0000 | [diff] [blame] | 154 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 155 | @Override |
| 156 | public boolean DeleteCollect(String userid, String postid) { |
| 157 | return false; |
| 158 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 159 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 160 | @Override |
| 161 | public int AddBegSeed(BegInfo info) { |
| 162 | if (info == null || info.begid == null || info.begid.isEmpty()) { |
| 163 | logger.warn("Invalid parameter: info is null or begid is empty"); |
| 164 | return 2; |
| 165 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 166 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 167 | EntityManager em = null; |
| 168 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 169 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 170 | try { |
| 171 | em = emf.createEntityManager(); |
| 172 | tx = em.getTransaction(); |
| 173 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 174 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 175 | // 检查是否重复 |
| 176 | BegInfo existingBeg = em.find(BegInfo.class, info.begid); |
| 177 | if (existingBeg != null) { |
| 178 | logger.warn("BegSeed with ID {} already exists", info.begid); |
| 179 | return 1; |
| 180 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 181 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 182 | // 设置默认值 |
| 183 | if (info.endtime == null) { |
| 184 | // 设置默认14天截止期 |
| 185 | Calendar calendar = Calendar.getInstance(); |
| 186 | calendar.add(Calendar.DAY_OF_MONTH, 14); |
| 187 | info.endtime = calendar.getTime(); |
| 188 | } |
| 189 | info.hasseed = 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 190 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 191 | // 保存新的求种信息 |
| 192 | em.persist(info); |
| 193 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 194 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 195 | logger.info("Successfully added new BegSeed with ID: {}", info.begid); |
| 196 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 197 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 198 | } catch (Exception e) { |
| 199 | if (tx != null && tx.isActive()) { |
| 200 | tx.rollback(); |
| 201 | } |
| 202 | logger.error("Error adding BegSeed: {}", e.getMessage()); |
| 203 | return 2; |
| 204 | } finally { |
| 205 | if (em != null) { |
| 206 | em.close(); |
| 207 | } |
| 208 | } |
| 209 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 210 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 211 | @Override |
| 212 | public int UpdateBegSeed(BegInfo info) { |
| 213 | if (info == null || info.begid == null || info.begid.isEmpty()) { |
| 214 | logger.warn("Invalid parameter: info is null or begid is empty"); |
| 215 | return 2; |
| 216 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 217 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 218 | EntityManager em = null; |
| 219 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 220 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 221 | try { |
| 222 | em = emf.createEntityManager(); |
| 223 | tx = em.getTransaction(); |
| 224 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 225 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 226 | // 检查是否存在 |
| 227 | BegInfo existingBeg = em.find(BegInfo.class, info.begid); |
| 228 | if (existingBeg == null) { |
| 229 | logger.warn("BegSeed with ID {} does not exist", info.begid); |
| 230 | return 1; |
| 231 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 232 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 233 | // 保持原有值不变的字段 |
| 234 | info.hasseed = existingBeg.hasseed; |
| 235 | if (info.endtime == null) { |
| 236 | info.endtime = existingBeg.endtime; |
| 237 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 238 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 239 | // 更新求种信息 |
| 240 | em.merge(info); |
| 241 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 242 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 243 | logger.info("Successfully updated BegSeed with ID: {}", info.begid); |
| 244 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 245 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 246 | } catch (Exception e) { |
| 247 | if (tx != null && tx.isActive()) { |
| 248 | tx.rollback(); |
| 249 | } |
| 250 | logger.error("Error updating BegSeed: {}", e.getMessage()); |
| 251 | return 2; |
| 252 | } finally { |
| 253 | if (em != null) { |
| 254 | em.close(); |
| 255 | } |
| 256 | } |
| 257 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 258 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 259 | @Override |
| 260 | public int DeleteBegSeed(String begid) { |
| 261 | if (begid == null || begid.isEmpty()) { |
| 262 | logger.warn("Invalid parameter: begid is null or empty"); |
| 263 | return 2; |
| 264 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 265 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 266 | EntityManager em = null; |
| 267 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 268 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 269 | try { |
| 270 | em = emf.createEntityManager(); |
| 271 | tx = em.getTransaction(); |
| 272 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 273 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 274 | // 查找要删除的求种信息 |
| 275 | BegInfo begInfo = em.find(BegInfo.class, begid); |
| 276 | if (begInfo == null) { |
| 277 | logger.warn("BegSeed with ID {} does not exist", begid); |
| 278 | tx.rollback(); |
| 279 | return 1; |
| 280 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 281 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 282 | // 删除求种信息 |
| 283 | em.remove(begInfo); |
| 284 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 285 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 286 | logger.info("Successfully deleted BegSeed with ID: {}", begid); |
| 287 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 288 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 289 | } catch (Exception e) { |
| 290 | if (tx != null && tx.isActive()) { |
| 291 | tx.rollback(); |
| 292 | } |
| 293 | logger.error("Error deleting BegSeed: {}", e.getMessage()); |
| 294 | return 2; |
| 295 | } finally { |
| 296 | if (em != null) { |
| 297 | em.close(); |
| 298 | } |
| 299 | } |
| 300 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 301 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 302 | @Override |
| 303 | public int VoteSeed(String begId, String seedId, String userId) { |
| 304 | if (begId == null || seedId == null || userId == null || |
| 305 | begId.isEmpty() || seedId.isEmpty() || userId.isEmpty()) { |
| 306 | logger.warn("Invalid parameters: begId, seedId or userId is null or empty"); |
| 307 | return 2; |
| 308 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 309 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 310 | EntityManager em = null; |
| 311 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 312 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 313 | try { |
| 314 | em = emf.createEntityManager(); |
| 315 | tx = em.getTransaction(); |
| 316 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 317 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 318 | // 检查求种信息是否存在 |
| 319 | BegInfo begInfo = em.find(BegInfo.class, begId); |
| 320 | if (begInfo == null) { |
| 321 | logger.warn("BegSeed with ID {} does not exist", begId); |
| 322 | return 2; |
| 323 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 324 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 325 | // 检查用户是否已投票 |
| 326 | Long voteCount = new JPAQuery<>(em) |
| 327 | .select(QUserVotes.userVotes.count()) |
| 328 | .from(QUserVotes.userVotes) |
| 329 | .where(QUserVotes.userVotes.id.eq(new entity.UserVotesId(userId, begId, seedId))) |
| 330 | .fetchOne(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 331 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 332 | if (voteCount != null && voteCount > 0) { |
| 333 | logger.warn("User {} has already voted for seed {} in beg {}", userId, seedId, begId); |
| 334 | return 1; |
| 335 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 336 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 337 | // 创建新的投票记录 |
| 338 | em.createNativeQuery("INSERT INTO UserVotes (user_id, beg_id, seed_id, created_at) " + |
| 339 | "VALUES (?, ?, ?, CURRENT_TIMESTAMP)") |
| 340 | .setParameter(1, userId) |
| 341 | .setParameter(2, begId) |
| 342 | .setParameter(3, seedId) |
| 343 | .executeUpdate(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 344 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 345 | // 更新SubmitSeed表中的投票数 |
| 346 | em.createQuery("UPDATE SubmitSeed s SET s.votes = s.votes + 1 " + |
| 347 | "WHERE s.id.begId = :begId AND s.id.seedId = :seedId") |
| 348 | .setParameter("begId", begId) |
| 349 | .setParameter("seedId", seedId) |
| 350 | .executeUpdate(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 351 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 352 | tx.commit(); |
| 353 | logger.info("Successfully added vote from user {} for seed {} in beg {}", userId, seedId, begId); |
| 354 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 355 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 356 | } catch (Exception e) { |
| 357 | if (tx != null && tx.isActive()) { |
| 358 | tx.rollback(); |
| 359 | } |
| 360 | logger.error("Error voting for seed: {}", e.getMessage()); |
| 361 | return 2; |
| 362 | } finally { |
| 363 | if (em != null) { |
| 364 | em.close(); |
| 365 | } |
| 366 | } |
| 367 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 368 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 369 | @Override |
| 370 | public int SubmitSeed(String begid, Seed seed) { |
| 371 | if (begid == null || seed == null || begid.isEmpty() || seed.seedid == null) { |
| 372 | logger.warn("Invalid parameters: begid or seed is null or empty"); |
| 373 | return 2; |
| 374 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 375 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 376 | EntityManager em = null; |
| 377 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 378 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 379 | try { |
| 380 | em = emf.createEntityManager(); |
| 381 | tx = em.getTransaction(); |
| 382 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 383 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 384 | // 检查求种信息是否存在 |
| 385 | BegInfo begInfo = em.find(BegInfo.class, begid); |
| 386 | if (begInfo == null) { |
| 387 | logger.warn("BegSeed with ID {} does not exist", begid); |
| 388 | return 2; |
| 389 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 390 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 391 | // 检查种子是否已提交过 |
| 392 | QSubmitSeed ss = QSubmitSeed.submitSeed; |
| 393 | Long submitCount = new JPAQuery<>(em) |
| 394 | .select(ss.count()) |
| 395 | .from(ss) |
| 396 | .where(ss.begInfo.begid.eq(begid)) |
| 397 | .where(ss.seed.seedid.eq(seed.seedid)) |
| 398 | .fetchOne(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 399 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 400 | if (submitCount > 0) { |
| 401 | logger.warn("Seed {} has already been submitted for beg {}", seed.seedid, |
| 402 | begid); |
| 403 | return 1; |
| 404 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 405 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 406 | // 保存种子信息(如果不存在) |
| 407 | if (em.find(Seed.class, seed.seedid) == null) { |
| 408 | em.persist(seed); |
| 409 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 410 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 411 | // 创建提交记录 |
| 412 | em.createNativeQuery("INSERT INTO SubmitSeed (beg_id, seed_id, votes) VALUES (?, ?, 0)") |
| 413 | .setParameter(1, begid) |
| 414 | .setParameter(2, seed.seedid) |
| 415 | .executeUpdate(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 416 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 417 | tx.commit(); |
| 418 | logger.info("Successfully submitted seed {} for beg {}", seed.seedid, begid); |
| 419 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 420 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 421 | } catch (Exception e) { |
| 422 | if (tx != null && tx.isActive()) { |
| 423 | tx.rollback(); |
| 424 | } |
| 425 | logger.error("Error submitting seed: {}", e.getMessage()); |
| 426 | return 2; |
| 427 | } finally { |
| 428 | if (em != null) { |
| 429 | em.close(); |
| 430 | } |
| 431 | } |
| 432 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 433 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 434 | @Override |
| 435 | public void SettleBeg() { |
| 436 | EntityManager em = null; |
| 437 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 438 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 439 | try { |
| 440 | em = emf.createEntityManager(); |
| 441 | tx = em.getTransaction(); |
| 442 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 443 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 444 | // 1. 获取所有已过期且未完成的求种信息 |
| 445 | QBegInfo b = QBegInfo.begInfo; |
| 446 | List<BegInfo> expiredBegs = new JPAQuery<>(em) |
| 447 | .select(b) |
| 448 | .from(b) |
| 449 | .where(b.endtime.loe(new Date()) |
| 450 | .and(b.hasseed.eq(0))) |
| 451 | .fetch(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 452 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 453 | for (BegInfo beg : expiredBegs) { |
| 454 | // 2. 查找投票最多的提交任务 |
| 455 | QSubmitSeed ss = QSubmitSeed.submitSeed; |
| 456 | Tuple topSubmission = new JPAQuery<>(em) |
| 457 | .select(ss.seed.seedid, ss.votes) |
| 458 | .from(ss) |
| 459 | .where(ss.begInfo.begid.eq(beg.begid)) |
| 460 | .orderBy(ss.votes.desc()) |
| 461 | .limit(1) |
| 462 | .fetchOne(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 463 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 464 | if (topSubmission != null && topSubmission.get(ss.votes) > 0) { |
| 465 | String seedId = topSubmission.get(ss.seed.seedid); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 466 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 467 | // 3. 获取上传者ID |
| 468 | QSeed s = QSeed.seed; |
| 469 | String ownerId = new JPAQuery<>(em) |
| 470 | .select(s.seeduserid) |
| 471 | .from(s) |
| 472 | .where(s.seedid.eq(seedId)) |
| 473 | .fetchOne(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 474 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 475 | // 4. 获取上传者的PT信息并更新魔力值 |
| 476 | UserPT ownerPT = em.find(UserPT.class, ownerId); |
| 477 | if (ownerPT != null) { |
| 478 | // 5. 发放奖励 |
| 479 | ownerPT.magic += beg.magic; |
| 480 | em.merge(ownerPT); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 481 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 482 | // 6. 更新求种状态 |
| 483 | beg.hasseed = 1; |
| 484 | em.merge(beg); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 485 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 486 | logger.info("Reward {} magic points awarded to user {} for beg {}", |
| 487 | beg.magic, ownerId, beg.begid); |
| 488 | } |
| 489 | } |
| 490 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 491 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 492 | tx.commit(); |
| 493 | logger.info("Successfully settled {} expired beg requests", |
| 494 | expiredBegs.size()); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 495 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 496 | } catch (Exception e) { |
| 497 | if (tx != null && tx.isActive()) { |
| 498 | tx.rollback(); |
| 499 | } |
| 500 | logger.error("Error settling beg requests: {}", e.getMessage(), e); |
| 501 | } finally { |
| 502 | if (em != null) { |
| 503 | em.close(); |
| 504 | } |
| 505 | } |
| 506 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 507 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 508 | @Override |
| 509 | public int AddPost(Post post) { |
| 510 | if (post == null || post.postid == null || post.postid.isEmpty()) { |
| 511 | logger.warn("Invalid parameter: post is null or postid is empty"); |
| 512 | return 2; |
| 513 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 514 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 515 | EntityManager em = null; |
| 516 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 517 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 518 | try { |
| 519 | em = emf.createEntityManager(); |
| 520 | tx = em.getTransaction(); |
| 521 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 522 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 523 | // 检查是否重复 |
| 524 | Post existingPost = em.find(Post.class, post.postid); |
| 525 | if (existingPost != null) { |
| 526 | logger.warn("Post with ID {} already exists", post.postid); |
| 527 | return 1; |
| 528 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 529 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 530 | // 检查用户是否存在 |
| 531 | User user = em.find(User.class, post.postuserid); |
| 532 | if (user == null) { |
| 533 | logger.warn("User with ID {} does not exist", post.postuserid); |
| 534 | return 2; |
| 535 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 536 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 537 | // 设置初始值 |
| 538 | if (post.posttime == null) { |
| 539 | post.posttime = new Date(); |
| 540 | } |
| 541 | post.replytime = 0; |
| 542 | post.readtime = 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 543 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 544 | // 保存帖子 |
| 545 | em.persist(post); |
| 546 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 547 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 548 | logger.info("Successfully added new post with ID: {}", post.postid); |
| 549 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 550 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 551 | } catch (Exception e) { |
| 552 | if (tx != null && tx.isActive()) { |
| 553 | tx.rollback(); |
| 554 | } |
| 555 | logger.error("Error adding post: {}", e.getMessage()); |
| 556 | return 2; |
| 557 | } finally { |
| 558 | if (em != null) { |
| 559 | em.close(); |
| 560 | } |
| 561 | } |
| 562 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 563 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 564 | @Override |
| 565 | public int UpdatePost(Post post) { |
| 566 | if (post == null || post.postid == null || post.postid.isEmpty()) { |
| 567 | logger.warn("Invalid parameter: post is null or postid is empty"); |
| 568 | return 2; |
| 569 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 570 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 571 | EntityManager em = null; |
| 572 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 573 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 574 | try { |
| 575 | em = emf.createEntityManager(); |
| 576 | tx = em.getTransaction(); |
| 577 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 578 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 579 | // 检查帖子是否存在 |
| 580 | Post existingPost = em.find(Post.class, post.postid); |
| 581 | if (existingPost == null) { |
| 582 | logger.warn("Post with ID {} does not exist", post.postid); |
| 583 | return 1; |
| 584 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 585 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 586 | // 保持原有不可修改的字段 |
| 587 | post.postuserid = existingPost.postuserid; |
| 588 | post.posttime = existingPost.posttime; |
| 589 | post.replytime = existingPost.replytime; |
| 590 | post.readtime = existingPost.readtime; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 591 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 592 | // 更新帖子 |
| 593 | em.merge(post); |
| 594 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 595 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 596 | logger.info("Successfully updated post with ID: {}", post.postid); |
| 597 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 598 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 599 | } catch (Exception e) { |
| 600 | if (tx != null && tx.isActive()) { |
| 601 | tx.rollback(); |
| 602 | } |
| 603 | logger.error("Error updating post: {}", e.getMessage()); |
| 604 | return 2; |
| 605 | } finally { |
| 606 | if (em != null) { |
| 607 | em.close(); |
| 608 | } |
| 609 | } |
| 610 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 611 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 612 | @Override |
| 613 | public int DeletePost(String postid) { |
| 614 | if (postid == null || postid.isEmpty()) { |
| 615 | logger.warn("Invalid parameter: postid is null or empty"); |
| 616 | return 2; |
| 617 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 618 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 619 | EntityManager em = null; |
| 620 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 621 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 622 | try { |
| 623 | em = emf.createEntityManager(); |
| 624 | tx = em.getTransaction(); |
| 625 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 626 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 627 | // 查找要删除的帖子 |
| 628 | Post post = em.find(Post.class, postid); |
| 629 | if (post == null) { |
| 630 | logger.warn("Post with ID {} does not exist", postid); |
| 631 | tx.rollback(); |
| 632 | return 1; |
| 633 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 634 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 635 | // 删除帖子(由于设置了级联删除,相关的回复会自动删除) |
| 636 | em.remove(post); |
| 637 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 638 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 639 | logger.info("Successfully deleted post with ID: {}", postid); |
| 640 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 641 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 642 | } catch (Exception e) { |
| 643 | if (tx != null && tx.isActive()) { |
| 644 | tx.rollback(); |
| 645 | } |
| 646 | logger.error("Error deleting post: {}", e.getMessage()); |
| 647 | return 2; |
| 648 | } finally { |
| 649 | if (em != null) { |
| 650 | em.close(); |
| 651 | } |
| 652 | } |
| 653 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 654 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 655 | @Override |
| 656 | public int AddComment(String postid, String userid, String comment) { |
| 657 | if (postid == null || postid.isEmpty() || |
| 658 | userid == null || userid.isEmpty() || |
| 659 | comment == null || comment.isEmpty()) { |
| 660 | logger.warn("Invalid parameters: postid, userid or comment is null or empty"); |
| 661 | return 2; |
| 662 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 663 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 664 | EntityManager em = null; |
| 665 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 666 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 667 | try { |
| 668 | em = emf.createEntityManager(); |
| 669 | tx = em.getTransaction(); |
| 670 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 671 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 672 | // 检查帖子是否存在 |
| 673 | Post post = em.find(Post.class, postid); |
| 674 | if (post == null) { |
| 675 | logger.warn("Post with ID {} does not exist", postid); |
| 676 | return 1; |
| 677 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 678 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 679 | // 检查评论用户是否存在 |
| 680 | User user = em.find(User.class, userid); |
| 681 | if (user == null) { |
| 682 | logger.warn("User with ID {} does not exist", userid); |
| 683 | return 1; |
| 684 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 685 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 686 | // 创建新的回复 |
| 687 | PostReply reply = new PostReply(); |
| 688 | reply.replyid = UUID.randomUUID().toString(); |
| 689 | reply.postid = postid; |
| 690 | reply.content = comment; |
| 691 | reply.authorid = userid; |
| 692 | reply.createdAt = new Date(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 693 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 694 | // 保存回复 |
| 695 | em.persist(reply); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 696 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 697 | // 更新帖子的回复数 |
| 698 | post.replytime += 1; |
| 699 | em.merge(post); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 700 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 701 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 702 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 703 | logger.info("Successfully added comment by user {} to post {}, reply ID: {}", |
| 704 | userid, postid, reply.replyid); |
| 705 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 706 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 707 | } catch (Exception e) { |
| 708 | if (tx != null && tx.isActive()) { |
| 709 | tx.rollback(); |
| 710 | } |
| 711 | logger.error("Error adding comment: {}", e.getMessage()); |
| 712 | return 2; |
| 713 | } finally { |
| 714 | if (em != null) { |
| 715 | em.close(); |
| 716 | } |
| 717 | } |
| 718 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 719 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 720 | @Override |
| 721 | public int DeleteComment(String postid, String commentid) { |
| 722 | if (postid == null || postid.isEmpty() || commentid == null || commentid.isEmpty()) { |
| 723 | logger.warn("Invalid parameters: postid or commentid is null or empty"); |
| 724 | return 2; |
| 725 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 726 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 727 | EntityManager em = null; |
| 728 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 729 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 730 | try { |
| 731 | em = emf.createEntityManager(); |
| 732 | tx = em.getTransaction(); |
| 733 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 734 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 735 | // 检查帖子是否存在 |
| 736 | Post post = em.find(Post.class, postid); |
| 737 | if (post == null) { |
| 738 | logger.warn("Post with ID {} does not exist", postid); |
| 739 | return 1; |
| 740 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 741 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 742 | // 检查评论是否存在且属于该帖子 |
| 743 | PostReply reply = em.find(PostReply.class, commentid); |
| 744 | if (reply == null || !reply.postid.equals(postid)) { |
| 745 | logger.warn("Comment {} does not exist or does not belong to post {}", commentid, postid); |
| 746 | return 1; |
| 747 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 748 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 749 | // 删除评论 |
| 750 | em.remove(reply); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 751 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 752 | // 更新帖子的回复数 |
| 753 | post.replytime = Math.max(0, post.replytime - 1); |
| 754 | em.merge(post); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 755 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 756 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 757 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 758 | logger.info("Successfully deleted comment {} from post {}", commentid, postid); |
| 759 | return 0; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 760 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 761 | } catch (Exception e) { |
| 762 | if (tx != null && tx.isActive()) { |
| 763 | tx.rollback(); |
| 764 | } |
| 765 | logger.error("Error deleting comment: {}", e.getMessage()); |
| 766 | return 2; |
| 767 | } finally { |
| 768 | if (em != null) { |
| 769 | em.close(); |
| 770 | } |
| 771 | } |
| 772 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 773 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 774 | @Override |
| 775 | public boolean ExchangeMagicToUpload(String userid, int magic) { |
| 776 | if (userid == null || userid.isEmpty() || magic <= 0) { |
| 777 | logger.warn("参数无效: userid为空或magic <= 0"); |
| 778 | return false; |
| 779 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 780 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 781 | EntityManager em = null; |
| 782 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 783 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 784 | try { |
| 785 | em = emf.createEntityManager(); |
| 786 | tx = em.getTransaction(); |
| 787 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 788 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 789 | UserPT userPT = em.find(UserPT.class, userid); |
| 790 | if (userPT == null) { |
| 791 | logger.warn("未找到用户 {} 的PT信息", userid); |
| 792 | return false; |
| 793 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 794 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 795 | if (userPT.magic < magic) { |
| 796 | logger.warn("用户 {} 的魔力值不足", userid); |
| 797 | return false; |
| 798 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 799 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 800 | // 1:1兑换,直接加上魔力值(假设单位是MB) |
| 801 | userPT.magic -= magic; |
| 802 | userPT.upload += magic; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 803 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 804 | // 更新分享率 |
| 805 | if (userPT.download > 0) { |
| 806 | userPT.share = (double) userPT.upload / userPT.download; |
| 807 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 808 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 809 | em.merge(userPT); |
| 810 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 811 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 812 | logger.info("用户 {} 成功将 {} 点魔力值兑换为 {}MB 上传量", userid, magic, magic); |
| 813 | return true; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 814 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 815 | } catch (Exception e) { |
| 816 | if (tx != null && tx.isActive()) { |
| 817 | tx.rollback(); |
| 818 | } |
| 819 | logger.error("魔力值兑换上传量时发生错误: {}", e.getMessage()); |
| 820 | return false; |
| 821 | } finally { |
| 822 | if (em != null) { |
| 823 | em.close(); |
| 824 | } |
| 825 | } |
| 826 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 827 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 828 | @Override |
| 829 | public boolean ExchangeMagicToDownload(String userid, int magic) { |
| 830 | if (userid == null || userid.isEmpty() || magic <= 0) { |
| 831 | logger.warn("参数无效: userid为空或magic <= 0"); |
| 832 | return false; |
| 833 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 834 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 835 | EntityManager em = null; |
| 836 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 837 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 838 | try { |
| 839 | em = emf.createEntityManager(); |
| 840 | tx = em.getTransaction(); |
| 841 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 842 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 843 | UserPT userPT = em.find(UserPT.class, userid); |
| 844 | if (userPT == null) { |
| 845 | logger.warn("未找到用户 {} 的PT信息", userid); |
| 846 | return false; |
| 847 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 848 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 849 | if (userPT.magic < magic) { |
| 850 | logger.warn("用户 {} 的魔力值不足", userid); |
| 851 | return false; |
| 852 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 853 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 854 | // 1:1兑换,直接减去魔力值对应的下载量(假设单位是MB) |
| 855 | userPT.magic -= magic; |
| 856 | userPT.download = Math.max(0, userPT.download - magic); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 857 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 858 | // 更新分享率 |
| 859 | if (userPT.download > 0) { |
| 860 | userPT.share = (double) userPT.upload / userPT.download; |
| 861 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 862 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 863 | em.merge(userPT); |
| 864 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 865 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 866 | logger.info("用户 {} 成功将 {} 点魔力值兑换为 {}MB 下载量减免", userid, magic, magic); |
| 867 | return true; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 868 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 869 | } catch (Exception e) { |
| 870 | if (tx != null && tx.isActive()) { |
| 871 | tx.rollback(); |
| 872 | } |
| 873 | logger.error("魔力值兑换下载量时发生错误: {}", e.getMessage()); |
| 874 | return false; |
| 875 | } finally { |
| 876 | if (em != null) { |
| 877 | em.close(); |
| 878 | } |
| 879 | } |
| 880 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 881 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 882 | @Override |
| 883 | public boolean ExchangeMagicToVip(String userid, int magic) { |
| 884 | if (userid == null || userid.isEmpty() || magic <= 0) { |
| 885 | logger.warn("参数无效: userid为空或magic <= 0"); |
| 886 | return false; |
| 887 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 888 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 889 | EntityManager em = null; |
| 890 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 891 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 892 | try { |
| 893 | em = emf.createEntityManager(); |
| 894 | tx = em.getTransaction(); |
| 895 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 896 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 897 | UserPT userPT = em.find(UserPT.class, userid); |
| 898 | if (userPT == null) { |
| 899 | logger.warn("未找到用户 {} 的PT信息", userid); |
| 900 | return false; |
| 901 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 902 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 903 | if (userPT.magic < magic) { |
| 904 | logger.warn("用户 {} 的魔力值不足", userid); |
| 905 | return false; |
| 906 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 907 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 908 | // 1:1兑换VIP下载次数 |
| 909 | userPT.magic -= magic; |
| 910 | userPT.viptime += magic; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 911 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 912 | em.merge(userPT); |
| 913 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 914 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 915 | logger.info("用户 {} 成功将 {} 点魔力值兑换为 {} 次VIP下载次数", userid, magic, magic); |
| 916 | return true; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 917 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 918 | } catch (Exception e) { |
| 919 | if (tx != null && tx.isActive()) { |
| 920 | tx.rollback(); |
| 921 | } |
| 922 | logger.error("魔力值兑换VIP下载次数时发生错误: {}", e.getMessage()); |
| 923 | return false; |
| 924 | } finally { |
| 925 | if (em != null) { |
| 926 | em.close(); |
| 927 | } |
| 928 | } |
| 929 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 930 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 931 | @Override |
| 932 | public boolean UploadTransmitProfile(Profile profile) { |
| 933 | if (profile == null || profile.profileurl == null || profile.profileurl.isEmpty() || |
| 934 | profile.userid == null || profile.userid.isEmpty()) { |
| 935 | logger.warn("参数无效: profile为空或必要字段为空"); |
| 936 | return false; |
| 937 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 938 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 939 | EntityManager em = null; |
| 940 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 941 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 942 | try { |
| 943 | em = emf.createEntityManager(); |
| 944 | tx = em.getTransaction(); |
| 945 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 946 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 947 | // 检查用户是否存在 |
| 948 | User user = em.find(User.class, profile.userid); |
| 949 | if (user == null) { |
| 950 | logger.warn("用户 {} 不存在", profile.userid); |
| 951 | return false; |
| 952 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 953 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 954 | // 检查是否已存在相同的迁移申请 |
| 955 | Profile existingProfile = em.find(Profile.class, profile.profileurl); |
| 956 | if (existingProfile != null) { |
| 957 | logger.warn("迁移申请 {} 已存在", profile.profileurl); |
| 958 | return false; |
| 959 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 960 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 961 | // 设置初始值 |
| 962 | profile.exampass = false; |
| 963 | profile.magicgived = "0"; |
| 964 | profile.uploadgived = "0"; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 965 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 966 | // 保存迁移申请 |
| 967 | em.persist(profile); |
| 968 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 969 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 970 | logger.info("成功上传迁移申请 {}", profile.profileurl); |
| 971 | return true; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 972 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 973 | } catch (Exception e) { |
| 974 | if (tx != null && tx.isActive()) { |
| 975 | tx.rollback(); |
| 976 | } |
| 977 | logger.error("上传迁移申请时发生错误: {}", e.getMessage()); |
| 978 | return false; |
| 979 | } finally { |
| 980 | if (em != null) { |
| 981 | em.close(); |
| 982 | } |
| 983 | } |
| 984 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 985 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 986 | @Override |
| 987 | public Profile GetTransmitProfile(String profileid) { |
| 988 | if (profileid == null || profileid.isEmpty()) { |
| 989 | logger.warn("参数无效: profileid为空"); |
| 990 | return null; |
| 991 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 992 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 993 | EntityManager em = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 994 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 995 | try { |
| 996 | em = emf.createEntityManager(); |
| 997 | Profile profile = em.find(Profile.class, profileid); |
| 998 | if (profile == null) { |
| 999 | logger.warn("未找到迁移申请 {}", profileid); |
| 1000 | return null; |
| 1001 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1002 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1003 | logger.info("成功获取迁移申请 {}", profileid); |
| 1004 | return profile; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1005 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1006 | } catch (Exception e) { |
| 1007 | logger.error("获取迁移申请时发生错误: {}", e.getMessage()); |
| 1008 | return null; |
| 1009 | } finally { |
| 1010 | if (em != null) { |
| 1011 | em.close(); |
| 1012 | } |
| 1013 | } |
| 1014 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1015 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1016 | @Override |
| 1017 | public boolean ExamTransmitProfile(String profileid, boolean result) { |
| 1018 | if (profileid == null || profileid.isEmpty()) { |
| 1019 | logger.warn("参数无效: profileid为空"); |
| 1020 | return false; |
| 1021 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1022 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1023 | EntityManager em = null; |
| 1024 | EntityTransaction tx = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1025 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1026 | try { |
| 1027 | em = emf.createEntityManager(); |
| 1028 | tx = em.getTransaction(); |
| 1029 | tx.begin(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1030 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1031 | // 查找迁移申请 |
| 1032 | Profile profile = em.find(Profile.class, profileid); |
| 1033 | if (profile == null) { |
| 1034 | logger.warn("未找到迁移申请 {}", profileid); |
| 1035 | return false; |
| 1036 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1037 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1038 | // 更新审核状态 |
| 1039 | profile.exampass = result; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1040 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1041 | if (result) { |
| 1042 | // 如果审核通过,更新用户的PT信息 |
| 1043 | UserPT userPT = em.find(UserPT.class, profile.userid); |
| 1044 | if (userPT != null) { |
| 1045 | // 发放魔力值 |
| 1046 | int magicToGive = Integer.parseInt(profile.magictogive); |
| 1047 | userPT.magic += magicToGive; |
| 1048 | profile.magicgived = String.valueOf(magicToGive); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1049 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1050 | // 发放上传量 |
| 1051 | long uploadToGive = Long.parseLong(profile.uploadtogive); |
| 1052 | userPT.upload += uploadToGive; |
| 1053 | profile.uploadgived = String.valueOf(uploadToGive); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1054 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1055 | em.merge(userPT); |
| 1056 | } |
| 1057 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1058 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1059 | em.merge(profile); |
| 1060 | tx.commit(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1061 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1062 | logger.info("成功审核迁移申请 {}, 结果: {}", profileid, result); |
| 1063 | return true; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1064 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1065 | } catch (Exception e) { |
| 1066 | if (tx != null && tx.isActive()) { |
| 1067 | tx.rollback(); |
| 1068 | } |
| 1069 | logger.error("审核迁移申请时发生错误: {}", e.getMessage()); |
| 1070 | return false; |
| 1071 | } finally { |
| 1072 | if (em != null) { |
| 1073 | em.close(); |
| 1074 | } |
| 1075 | } |
| 1076 | } |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1077 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1078 | @Override |
| 1079 | public Profile[] GetTransmitProfileList() { |
| 1080 | EntityManager em = null; |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1081 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1082 | try { |
| 1083 | em = emf.createEntityManager(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1084 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1085 | // 获取所有迁移申请 |
| 1086 | QProfile p = QProfile.profile; |
| 1087 | List<Profile> profiles = new JPAQuery<>(em) |
| 1088 | .select(p) |
| 1089 | .from(p) |
| 1090 | .fetch(); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1091 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1092 | logger.info("成功获取所有迁移申请,共 {} 条", profiles.size()); |
| 1093 | return profiles.toArray(new Profile[0]); |
Haotian W | 88568d8 | 2025-05-15 16:15:21 +0000 | [diff] [blame] | 1094 | |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1095 | } catch (Exception e) { |
| 1096 | logger.error("获取迁移申请列表时发生错误: {}", e.getMessage()); |
| 1097 | return new Profile[0]; |
| 1098 | } finally { |
| 1099 | if (em != null) { |
| 1100 | em.close(); |
| 1101 | } |
| 1102 | } |
| 1103 | } |
rhj | 46f62c4 | 2025-06-06 23:24:10 +0800 | [diff] [blame] | 1104 | |
| 1105 | @Override |
| 1106 | public Post[] GetPostList(){ |
| 1107 | return null; |
| 1108 | } |
rhj | 5b69b7e | 2025-06-07 01:28:08 +0800 | [diff] [blame^] | 1109 | |
| 1110 | @Override |
| 1111 | public Post GetPost(String postid) { |
| 1112 | return null; |
| 1113 | } |
| 1114 | |
| 1115 | @Override |
| 1116 | public PostReply[] GetPostReplyList(String postid) { |
| 1117 | return null; |
| 1118 | } |
956303669 | 63296f6 | 2025-06-02 21:16:32 +0800 | [diff] [blame] | 1119 | } |