This commit is contained in:
wells
2026-08-08 10:20:00 +08:00
parent 98e6aaa159
commit dc33b8008c
4 changed files with 47 additions and 53 deletions
@@ -25,14 +25,11 @@ public class OpsController {
*/ */
@PostMapping("/points/add") @PostMapping("/points/add")
public R<Void> addPoints(@RequestBody PointsDTO dto) { public R<Void> addPoints(@RequestBody PointsDTO dto) {
try { Long operatorId = UserContext.getUserId();
Long operatorId = UserContext.getUserId(); pointsService.addPoints(dto.getUserId(), dto.getAmount(),
pointsService.addPoints(dto.getUserId(), dto.getAmount(), IPointsService.TYPE_OPS_ADD, null, operatorId, dto.getRemark());
IPointsService.TYPE_OPS_ADD, null, operatorId, dto.getRemark()); return R.ok();
return R.ok();
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
} }
/** /**
@@ -40,17 +37,14 @@ public class OpsController {
*/ */
@PostMapping("/points/sub") @PostMapping("/points/sub")
public R<Void> subPoints(@RequestBody PointsDTO dto) { public R<Void> subPoints(@RequestBody PointsDTO dto) {
try { Long operatorId = UserContext.getUserId();
Long operatorId = UserContext.getUserId(); boolean success = pointsService.subPoints(dto.getUserId(), dto.getAmount(),
boolean success = pointsService.subPoints(dto.getUserId(), dto.getAmount(), IPointsService.TYPE_OPS_SUB, null, operatorId, dto.getRemark());
IPointsService.TYPE_OPS_SUB, null, operatorId, dto.getRemark()); if (success) {
if (success) { return R.ok();
return R.ok();
}
return R.fail("余额不足或用户不存在");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
} }
return R.fail("余额不足或用户不存在");
} }
/** /**
@@ -58,12 +52,9 @@ public class OpsController {
*/ */
@PostMapping("/group/pull") @PostMapping("/group/pull")
public R<Void> pullGroup(@RequestBody PullGroupDTO dto) { public R<Void> pullGroup(@RequestBody PullGroupDTO dto) {
try { Long operatorId = UserContext.getUserId();
Long operatorId = UserContext.getUserId(); groupService.pullUser(dto.getGroupId(), dto.getUserId(), operatorId);
groupService.pullUser(dto.getGroupId(), dto.getUserId(), operatorId); return R.ok();
return R.ok();
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
} }
} }
@@ -26,12 +26,9 @@ public class UserController {
*/ */
@PostMapping("/register") @PostMapping("/register")
public R<Void> register(@RequestBody RegisterDTO dto) { public R<Void> register(@RequestBody RegisterDTO dto) {
try { userService.register(dto.getUsername(), dto.getPassword());
userService.register(dto.getUsername(), dto.getPassword()); return R.ok();
return R.ok();
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
} }
/** /**
@@ -39,14 +36,11 @@ public class UserController {
*/ */
@PostMapping("/login") @PostMapping("/login")
public R<LoginVo> login(@RequestBody LoginDTO dto) { public R<LoginVo> login(@RequestBody LoginDTO dto) {
try { String token = userService.login(dto.getUsername(), dto.getPassword());
String token = userService.login(dto.getUsername(), dto.getPassword()); LoginVo vo = new LoginVo();
LoginVo vo = new LoginVo(); vo.setToken(token);
vo.setToken(token); return R.ok("登录成功", vo);
return R.ok("登录成功", vo);
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
} }
/** /**
@@ -63,13 +57,10 @@ public class UserController {
*/ */
@PutMapping("/update") @PutMapping("/update")
public R<Void> update(@RequestBody UpdateUserDTO dto) { public R<Void> update(@RequestBody UpdateUserDTO dto) {
try { Long userId = UserContext.getUserId();
Long userId = UserContext.getUserId(); userService.updateUserInfo(userId, dto);
userService.updateUserInfo(userId, dto); return R.ok();
return R.ok();
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
} }
/** /**
@@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tailbet.model.entity.User; import com.tailbet.model.entity.User;
import com.tailbet.mapper.UserMapper; import com.tailbet.mapper.UserMapper;
import com.tailbet.model.dto.UpdateUserDTO; import com.tailbet.model.dto.UpdateUserDTO;
import com.tailbet.openim.OpenIMClient;
import com.tailbet.service.IUserService; import com.tailbet.service.IUserService;
import com.tailbet.util.JwtUtil; import com.tailbet.util.JwtUtil;
import com.tailbet.util.PasswordUtil; import com.tailbet.util.PasswordUtil;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
@@ -20,11 +22,12 @@ import java.util.List;
@Slf4j @Slf4j
@RequiredArgsConstructor @RequiredArgsConstructor
@Service @Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUserService { public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
private final UserMapper userMapper; private final UserMapper userMapper;
private final PasswordUtil passwordUtil; private final PasswordUtil passwordUtil;
private final JwtUtil jwtUtil; private final JwtUtil jwtUtil;
private final OpenIMClient openIMClient;
/** /**
@@ -40,6 +43,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUs
* 注册用户 * 注册用户
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class)
public User register(String username, String password) { public User register(String username, String password) {
// 检查用户名是否已存在 // 检查用户名是否已存在
if (getByUsername(username) != null) { if (getByUsername(username) != null) {
@@ -54,6 +58,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUs
user.setStatus(1); user.setStatus(1);
userMapper.insert(user); userMapper.insert(user);
// 在OpenIM创建用户
boolean openIMResult = openIMClient.createUser(String.valueOf(user.getId()), user.getNickname());
if (!openIMResult) {
log.warn("OpenIM用户创建失败: userId={}, username={}", user.getId(), username);
throw new RuntimeException("OpenIM用户创建失败,请稍后再试!");
}
// 分配运营(按最少绑定+优先在线算法) // 分配运营(按最少绑定+优先在线算法)
assignOps(user); assignOps(user);
@@ -79,7 +90,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUs
} }
/** /**
* 更新用户信息 * 更新用户信息
*/ */
+7 -5
View File
@@ -10,9 +10,10 @@ spring:
password: ${DB_PASSWORD:123456} password: ${DB_PASSWORD:123456}
data: data:
redis: redis:
host: ${REDIS_HOST:localhost} host: ${REDIS_HOST:127.0.0.1}
port: ${REDIS_PORT:6379} port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:123456} password: ${REDIS_PASSWORD:123456}
# password: ${REDIS_PASSWORD:ejgheyg2@eHSY2!.}
database: ${REDIS_DB:0} database: ${REDIS_DB:0}
timeout: 5000ms timeout: 5000ms
lettuce: lettuce:
@@ -39,10 +40,11 @@ mybatis-plus:
logic-not-delete-value: 0 logic-not-delete-value: 0
openim: openim:
api-url: ${OPENIM_API_URL:http://localhost:10010} # api-url: ${OPENIM_API_URL:http://172.31.5.16:10002}
ws-url: ${OPENIM_WS_URL:ws://localhost:10010} api-url: ${OPENIM_API_URL:https://openim.xiu6688.com}
admin-user: ${OPENIM_ADMIN_USER:admin} ws-url: ${OPENIM_WS_URL:wss://im.xiu6688.com}
admin-token: ${OPENIM_ADMIN_TOKEN:} admin-user: ${OPENIM_ADMIN_USER:imAdmin}
admin-token: ${OPENIM_ADMIN_TOKEN:d71c0861267DM23adg}
jwt: jwt:
secret: ${JWT_SECRET:your-256-bit-secret-key-for-jwt-token-generation} secret: ${JWT_SECRET:your-256-bit-secret-key-for-jwt-token-generation}