bug修改

This commit is contained in:
hejiayang
2025-10-28 17:25:21 +08:00
parent 5b17317fd9
commit ac6bfdf437
2 changed files with 13 additions and 21 deletions
@@ -8,10 +8,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.jeecg.payment.entity.StClientMemberLevelDeductRule;
import org.jeecg.payment.entity.StClientMemberLevelDemotionTime;
import org.jeecg.payment.vo.StClientMemberLevelDeductRuleVo;
import org.jeecg.payment.vo.StClientMemberLevelDemotionTimeVO;
import java.util.Date;
import java.util.List;
/**
@@ -25,5 +25,5 @@ public interface StClientMemberLevelDeductRuleMapper extends BaseMapper<StClient
*/
List<StClientMemberLevelDeductRuleVo> selectStClientMemberLevelDeductRulePage(Page<StClientMemberLevelDeductRuleVo> page, @Param("vo") StClientMemberLevelDemotionTimeVO stClientMemberLevelDeductRule);
DateTime getMaxTimeByUserId(@Param("userId") String userId);
Date getMaxTimeByUserId(@Param("userId") String userId);
}
@@ -311,12 +311,11 @@ public class StClientMemberLevelDeductRuleServiceImpl extends JeecgServiceImpl<S
}
//去重
voListAll = filterDuplicateTimestamp(voListAll);
//过滤时间小于1分钟的记录
voListAll = filterRecentThanOneMinute(voListAll,System.currentTimeMillis());
Map<String, List<StRfidVo>> userListMaps = voListAll.stream().collect(Collectors.groupingBy(StRfidVo::getUserId));
for (Map.Entry<String, List<StRfidVo>> userListMap : userListMaps.entrySet()) {
String userId = userListMap.getKey();
List<StRfidVo> value = userListMap.getValue();
// 尝试获取锁,超时时间1分钟
String lockValue = redisLockUtil.tryLock(userId);
if (lockValue == null) {
@@ -324,24 +323,26 @@ public class StClientMemberLevelDeductRuleServiceImpl extends JeecgServiceImpl<S
}
try {
//根据用户获取之后一次扣费时间
DateTime maxTime = baseMapper.getMaxTimeByUserId(userId);
if(CollectionUtils.isEmpty(voListAll)){
Date maxTime = baseMapper.getMaxTimeByUserId(userId);
if(CollectionUtils.isEmpty(value)){
return Result.error("扣费信息不能为空");
}
//扣费规则(扣费类型(1:固定扣费,2:固定+补贴扣费,3:按量扣费,4:自定义金额))
StClientMemberLevelDeductRuleVo levelDeductRuleVo = this.getDeductRuleByCanteenId(restId);
if(voListAll.size() > 1){//离线扣费
value = filterRecentThanOneMinute(value,maxTime.getTime());
if(value.size() > 1){//离线扣费
//加异步处理
List<StRfidVo> finalVoListAll = voListAll;
List<StRfidVo> finalVoListAll = value;
//过滤时间小于1分钟的记录
CompletableFuture.runAsync(() -> {
unifiedDeductionInterface(finalVoListAll,restId,deviceCode,levelDeductRuleVo,false,maxTime);
unifiedDeductionInterface(finalVoListAll,restId,deviceCode,levelDeductRuleVo,false);
});
} else {//在线扣费
return unifiedDeductionInterface(voListAll,restId,deviceCode,levelDeductRuleVo,true,maxTime);
return unifiedDeductionInterface(value,restId,deviceCode,levelDeductRuleVo,true);
}
} catch (Exception e) {
e.printStackTrace();
return Result.error("扣费失败");
} finally {
//释放锁
redisLockUtil.releaseLock(userId, lockValue);
@@ -360,7 +361,7 @@ public class StClientMemberLevelDeductRuleServiceImpl extends JeecgServiceImpl<S
* @return
*/
private Result<StClientMemberSpendVO> unifiedDeductionInterface(List<StRfidVo> voListAll, String restId, String deviceCode,
StClientMemberLevelDeductRuleVo levelDeductRuleVo, Boolean online,DateTime maxTime) {
StClientMemberLevelDeductRuleVo levelDeductRuleVo, Boolean online) {
long start = System.currentTimeMillis();
//声明在线扣费余额信息
StClientMemberSpendVO stClientMemberSpendVO = new StClientMemberSpendVO();
@@ -369,15 +370,6 @@ public class StClientMemberLevelDeductRuleServiceImpl extends JeecgServiceImpl<S
// 存储错误信息
String errorMessages = null;
//用户最后一次扣费时间
if(maxTime != null){
//转毫秒级时间戳
long timestampMs = maxTime.getTime();
voListAll = voListAll.stream().filter(vo -> Long.parseLong(vo.getDateTime()) - timestampMs > 6000)
.sorted(Comparator.comparing(a -> Long.parseLong(a.getDateTime()), Comparator.nullsLast(Comparator.naturalOrder())))
.collect(Collectors.toList());
}
// 将扣费信息按照餐次分组
Map<String, List<StRfidVo>> stringListMap = groupByMeal(voListAll, restId);
StMiniMineBalanceVo stMiniMineBalanceVoOnline = new StMiniMineBalanceVo();