改一下这段代码@PostMapping("/addScore") @ApiOperation(value = "添加积分") public R challengeResults(@RequestBody User user){ QueryWrapper<User> queryWrapper = new QueryWrapper(); queryWrapper.eq("user_id",user.getUserId()); System.out.println("user.getUserId============"+user.getUserId()); User u = userServiceImpl.getOne(queryWrapper); //记录历史成绩 userServiceImpl.insertScore(user); BigDecimal score = user.getScore(); if(u!=null){ BigDecimal s = new BigDecimal("0"); if(!ObjectUtils.isEmpty(u.getScore())){ s = u.getScore(); } if(!ObjectUtils.isEmpty(user.getScore())){ s=s.add(user.getScore()); user.setScore(s); } score = s; userServiceImpl.update(user,queryWrapper); }else{ userServiceImpl.save(user); } return R.ok(score);
时间: 2023-12-06 13:41:48 浏览: 89
Spring @Async 的使用与实现的示例代码
@PostMapping("/addScore")
@ApiOperation(value = "添加积分")
public R challengeResults(@RequestBody User user){
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("user_id", user.getUserId());
System.out.println("user.getUserId============" + user.getUserId());
User u = userServiceImpl.getOne(queryWrapper);
//记录历史成绩
userServiceImpl.insertScore(user);
BigDecimal score = user.getScore();
if(u != null){
BigDecimal s = new BigDecimal("0");
if(u.getScore() != null){
s = u.getScore();
}
if(user.getScore() != null){
s = s.add(user.getScore());
user.setScore(s);
}
score = s;
userServiceImpl.update(user, queryWrapper);
} else{
userServiceImpl.save(user);
}
return R.ok().put("score", score);
}
阅读全文