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")
public R<Void> addPoints(@RequestBody PointsDTO dto) {
try {
Long operatorId = UserContext.getUserId();
pointsService.addPoints(dto.getUserId(), dto.getAmount(),
IPointsService.TYPE_OPS_ADD, null, operatorId, dto.getRemark());
return R.ok();
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
Long operatorId = UserContext.getUserId();
pointsService.addPoints(dto.getUserId(), dto.getAmount(),
IPointsService.TYPE_OPS_ADD, null, operatorId, dto.getRemark());
return R.ok();
}
/**
@@ -40,17 +37,14 @@ public class OpsController {
*/
@PostMapping("/points/sub")
public R<Void> subPoints(@RequestBody PointsDTO dto) {
try {
Long operatorId = UserContext.getUserId();
boolean success = pointsService.subPoints(dto.getUserId(), dto.getAmount(),
IPointsService.TYPE_OPS_SUB, null, operatorId, dto.getRemark());
if (success) {
return R.ok();
}
return R.fail("余额不足或用户不存在");
} catch (RuntimeException e) {
return R.fail(e.getMessage());
Long operatorId = UserContext.getUserId();
boolean success = pointsService.subPoints(dto.getUserId(), dto.getAmount(),
IPointsService.TYPE_OPS_SUB, null, operatorId, dto.getRemark());
if (success) {
return R.ok();
}
return R.fail("余额不足或用户不存在");
}
/**
@@ -58,12 +52,9 @@ public class OpsController {
*/
@PostMapping("/group/pull")
public R<Void> pullGroup(@RequestBody PullGroupDTO dto) {
try {
Long operatorId = UserContext.getUserId();
groupService.pullUser(dto.getGroupId(), dto.getUserId(), operatorId);
return R.ok();
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
Long operatorId = UserContext.getUserId();
groupService.pullUser(dto.getGroupId(), dto.getUserId(), operatorId);
return R.ok();
}
}
@@ -26,12 +26,9 @@ public class UserController {
*/
@PostMapping("/register")
public R<Void> register(@RequestBody RegisterDTO dto) {
try {
userService.register(dto.getUsername(), dto.getPassword());
return R.ok();
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
userService.register(dto.getUsername(), dto.getPassword());
return R.ok();
}
/**
@@ -39,14 +36,11 @@ public class UserController {
*/
@PostMapping("/login")
public R<LoginVo> login(@RequestBody LoginDTO dto) {
try {
String token = userService.login(dto.getUsername(), dto.getPassword());
LoginVo vo = new LoginVo();
vo.setToken(token);
return R.ok("登录成功", vo);
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
String token = userService.login(dto.getUsername(), dto.getPassword());
LoginVo vo = new LoginVo();
vo.setToken(token);
return R.ok("登录成功", vo);
}
/**
@@ -63,13 +57,10 @@ public class UserController {
*/
@PutMapping("/update")
public R<Void> update(@RequestBody UpdateUserDTO dto) {
try {
Long userId = UserContext.getUserId();
userService.updateUserInfo(userId, dto);
return R.ok();
} catch (RuntimeException e) {
return R.fail(e.getMessage());
}
Long userId = UserContext.getUserId();
userService.updateUserInfo(userId, dto);
return R.ok();
}
/**
@@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tailbet.model.entity.User;
import com.tailbet.mapper.UserMapper;
import com.tailbet.model.dto.UpdateUserDTO;
import com.tailbet.openim.OpenIMClient;
import com.tailbet.service.IUserService;
import com.tailbet.util.JwtUtil;
import com.tailbet.util.PasswordUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@@ -20,11 +22,12 @@ import java.util.List;
@Slf4j
@RequiredArgsConstructor
@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 PasswordUtil passwordUtil;
private final JwtUtil jwtUtil;
private final OpenIMClient openIMClient;
/**
@@ -40,6 +43,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUs
* 注册用户
*/
@Override
@Transactional(rollbackFor = Exception.class)
public User register(String username, String password) {
// 检查用户名是否已存在
if (getByUsername(username) != null) {
@@ -54,6 +58,13 @@ public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUs
user.setStatus(1);
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);
@@ -79,7 +90,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUs
}
/**
* 更新用户信息
*/