1
This commit is contained in:
parent
aa3289abc6
commit
74ab330dd1
@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -100,14 +101,21 @@ public class MemberRightsServiceImpl extends ServiceImpl<MemberRightsMapper, Mem
|
||||
.in(MemberRights::getCardId, cardIds)
|
||||
.eq(MemberRights::getRightsCode, rightsCode);
|
||||
try {
|
||||
MemberRights rights = getOne(lambdaQueryWrapper);
|
||||
if (!("02".equals(rights.getRightsType()) && rights.getRightsValue() == 0)) {
|
||||
int result = rights.getRemaining() - deplete;
|
||||
if (result == 0) {
|
||||
throw new Exception("今日次数已达上限");
|
||||
List<MemberRights> rights = list(lambdaQueryWrapper);
|
||||
//取出最大值
|
||||
if (!rights.isEmpty()) {
|
||||
List<MemberRights> maxRights = getRightsValueZeroOrMax(rights);
|
||||
MemberRights max = maxRights.get(0);
|
||||
if (!("02".equals(max.getRightsType()) && max.getRightsValue() == 0)) {
|
||||
int result = max.getRemaining() - deplete;
|
||||
if (result == 0) {
|
||||
throw new Exception("今日次数已达上限");
|
||||
}
|
||||
max.setRemaining(result);
|
||||
updateById(max);
|
||||
}
|
||||
rights.setRemaining(result);
|
||||
updateById(rights);
|
||||
} else {
|
||||
throw new Exception("未查询到权限");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new Exception(e.getMessage());
|
||||
@ -115,6 +123,35 @@ public class MemberRightsServiceImpl extends ServiceImpl<MemberRightsMapper, Mem
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 取出权益最大值
|
||||
* @author PQZ
|
||||
* @date 18:03 2025/4/24
|
||||
* @param rights {@link MemberRights}
|
||||
* @return java.util.List<com.ruoyi.member.domain.MemberRights>
|
||||
**/
|
||||
private List<MemberRights> getRightsValueZeroOrMax(List<MemberRights> rights) {
|
||||
// 先找 rightsValue==0 的数据
|
||||
List<MemberRights> zeroList = rights.stream()
|
||||
.filter(r -> r.getRightsValue() == 0)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!zeroList.isEmpty()) {
|
||||
// 有 0 的返回所有 0 的数据
|
||||
return zeroList;
|
||||
}
|
||||
|
||||
// 没 0,再找最大值
|
||||
int max = rights.stream()
|
||||
.mapToInt(MemberRights::getRightsValue)
|
||||
.max()
|
||||
.orElse(Integer.MIN_VALUE);
|
||||
|
||||
return rights.stream()
|
||||
.filter(r -> r.getRightsValue() == max)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务重置剩余值
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user