-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from adorabled4/refactor-count
重构接口调用信息统计逻辑
- Loading branch information
Showing
45 changed files
with
929 additions
and
780 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
api-common/src/main/java/com/dhx/apicommon/constant/MQConstant.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
api-core/src/main/java/com/dhx/apicore/controller/DailyCheckInController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.dhx.apicore.controller; | ||
|
||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
import com.dhx.apicommon.common.BaseResponse; | ||
import com.dhx.apicommon.common.exception.BusinessException; | ||
import com.dhx.apicommon.common.exception.ErrorCode; | ||
import com.dhx.apicommon.util.ResultUtil; | ||
import com.dhx.apicore.manager.RedisLockManager; | ||
import com.dhx.apicore.model.DO.DailyCheckIn; | ||
import com.dhx.apicore.model.vo.UserVo; | ||
import com.dhx.apicore.service.DailyCheckInService; | ||
import com.dhx.apicore.service.UserService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.annotation.Resource; | ||
|
||
/** | ||
* @Author: QiMu | ||
* @Date: 2023/08/31 11:51:14 | ||
* @Version: 1.0 | ||
* @Description: 签到接口 | ||
*/ | ||
@RestController | ||
@RequestMapping("/dailyCheckIn") | ||
@Slf4j | ||
public class DailyCheckInController { | ||
|
||
@Resource | ||
private DailyCheckInService dailyCheckInService; | ||
|
||
@Resource | ||
private UserService userService; | ||
@Resource | ||
private RedisLockManager redisLockManager; | ||
|
||
public static final Long LOGIN_ADD_COIN = 10L; | ||
|
||
|
||
/** | ||
* 签到 | ||
* | ||
* @return {@link BaseResponse}<{@link Boolean}> | ||
*/ | ||
@PostMapping("/doCheckIn") | ||
@Transactional(rollbackFor = Exception.class) | ||
public BaseResponse<Boolean> doDailyCheckIn() { | ||
UserVo loginUser = userService.getCurrentUser(); | ||
String redissonLock = ("doDailyCheckIn_" + loginUser.getUserAccount()).intern(); | ||
return redisLockManager.redissonDistributedLocks(redissonLock, () -> { | ||
LambdaQueryWrapper<DailyCheckIn> dailyCheckInLambdaQueryWrapper = new LambdaQueryWrapper<>(); | ||
dailyCheckInLambdaQueryWrapper.eq(DailyCheckIn::getUserId, loginUser.getUserId()); | ||
DailyCheckIn dailyCheckIn = dailyCheckInService.getOne(dailyCheckInLambdaQueryWrapper); | ||
if (ObjectUtils.isNotEmpty(dailyCheckIn)) { | ||
throw new BusinessException(ErrorCode.OPERATION_ERROR, "签到失败,今日已签到"); | ||
} | ||
dailyCheckIn = new DailyCheckIn(); | ||
dailyCheckIn.setUserId(loginUser.getUserId()); | ||
dailyCheckIn.setAddCoins(LOGIN_ADD_COIN); | ||
boolean dailyCheckInResult = dailyCheckInService.save(dailyCheckIn); | ||
userService.addLeftCoin(loginUser.getUserId(), dailyCheckIn.getAddCoins()); | ||
if (!dailyCheckInResult) { | ||
throw new BusinessException(ErrorCode.OPERATION_ERROR); | ||
} | ||
return ResultUtil.success(true); | ||
}, "签到失败"); | ||
} | ||
} |
67 changes: 0 additions & 67 deletions
67
api-core/src/main/java/com/dhx/apicore/listener/CallResultListener.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.