rentaiming
2024-07-20 ed4f07531b9cb0794e976a14cee3b591dec8d4f6
ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/MemberServiceImpl.java
@@ -37,7 +37,6 @@
import com.ruoyi.member.service.IMemberService;
import com.ruoyi.member.util.HttpUtils;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.constants.SecurityConstant;
import com.ruoyi.system.api.domain.AppMiniLoginVO;
import com.ruoyi.system.api.domain.Member;
import com.ruoyi.system.api.domain.MemberPoints;
@@ -54,7 +53,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
@@ -66,6 +64,8 @@
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
 * <p>
@@ -243,7 +243,6 @@
                Member member1=this.getOne(wrapper1);
                if (member1==null){
                        //创建新用户
                        String memberId = IdUtils.simpleUUID();
                        sysUser = new SysUser();
@@ -528,6 +527,7 @@
    }
    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void updMembeOne(updMembeOneDTO dMembeOneDTO) {
        Member byId = this.getById(dMembeOneDTO.getMemberId());
        if (dMembeOneDTO.getMoney()!=null){
@@ -550,32 +550,32 @@
        this.updateById(byId);
        LambdaQueryWrapper<MemberLevel> wrapper= Wrappers.lambdaQuery();
        List<MemberLevel> list = memberLevelMapper.selectList(wrapper);
        for (int i=0;i<list.size();i++){
            if (i==0){
                int ia = byId.getMoney().compareTo(list.get(0).getCumulativeConsumption());
                if (ia<0){
                    byId.setLevel(0);
                    break;
                }
            }
            if (i==list.size()-1){
                BigDecimal cumulative = list.get(i - 1).getCumulativeConsumption();
                BigDecimal cumulative1 = list.get(i).getCumulativeConsumption();
                if (cumulative.compareTo(byId.getMoney()) <= 0 && cumulative1.compareTo(byId.getMoney()) >= 0) {
                    byId.setLevel(list.get(i).getLevel());
                }else{
                    byId.setLevel(list.get(i).getLevel());
                }
            }else {
                BigDecimal cumulative = list.get(i - 1).getCumulativeConsumption();
                BigDecimal cumulative1 = list.get(i).getCumulativeConsumption();
                if (cumulative.compareTo(byId.getMoney()) <= 0 && cumulative1.compareTo(byId.getMoney()) >= 0) {
                    byId.setLevel(list.get(i).getLevel());
                }
        int appropriateLevel = findAppropriateLevel(list, byId.getMoney());
        byId.setLevel(appropriateLevel);
        this.updateById(byId);
    }
    private static int findAppropriateLevel(List<MemberLevel> memberLevels, BigDecimal money) {
        // 对于最开始的level,设置为0(假设0是最低等级)
        int level = 0;
        for (int i = 0; i < memberLevels.size(); i++) {
            MemberLevel currentLevel = memberLevels.get(i);
            BigDecimal currentCumulativeConsumption = currentLevel.getCumulativeConsumption();
            // 如果当前成员的消费额小于等于当前等级的累积消费额
            if (money.compareTo(currentCumulativeConsumption) < 0) {
                return level;
            }
            // 更新level为当前等级,准备下一次比较
            level = currentLevel.getLevel();
        }
        // 如果遍历完成后还没有返回,说明该成员的消费额高于所有已定义等级的累积消费额
        level = memberLevels.get(memberLevels.size() - 1).getLevel();
        return level;
    }
    /**
@@ -628,6 +628,8 @@
                .orderByDesc(Member::getLevel)
                .list();
    }
}