| | |
| | | |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.UserPoint; |
| | | import com.ruoyi.account.service.AppUserService; |
| | | import com.ruoyi.account.service.UserPointService; |
| | | import com.ruoyi.account.service.VipSettingService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.other.api.domain.VipSetting; |
| | | import com.ruoyi.other.api.feignClient.RemoteVipSettingClient; |
| | | import com.ruoyi.other.api.feignClient.VipSettingClient; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class VipSettingServiceImpl implements VipSettingService { |
| | |
| | | private RemoteVipSettingClient remoteVipSettingClient; |
| | | @Resource |
| | | private AppUserClient appUserClient; |
| | | @Resource |
| | | private AppUserService appUserService; |
| | | @Resource |
| | | private VipSettingClient vipSettingClient; |
| | | @Resource |
| | | private UserPointService userPointService; |
| | | @Autowired |
| | | private PointSettingServiceImpl pointSettingServiceImpl; |
| | | |
| | | |
| | | @Override |
| | |
| | | } |
| | | return getVipSettingById(appUser.getVipId()); |
| | | } |
| | | |
| | | @Override |
| | | public void downUsers() { |
| | | //查出可能需要降级的人员 |
| | | List<Integer> vipIds = new ArrayList<>(); |
| | | vipIds.add(5); |
| | | vipIds.add(6); |
| | | vipIds.add(7); |
| | | List<AppUser> list = appUserService.lambdaQuery().in(AppUser::getVipId, vipIds).list(); |
| | | VipSetting vipSetting5 = vipSettingClient.getVipSetting(5).getData(); |
| | | VipSetting vipSetting6 = vipSettingClient.getVipSetting(6).getData(); |
| | | VipSetting vipSetting7 = vipSettingClient.getVipSetting(7).getData(); |
| | | LocalDate now = LocalDate.now(); |
| | | //循环判断是否要展示 |
| | | if (list.size()>0){ |
| | | for (AppUser appUser : list){ |
| | | boolean danger = false; |
| | | if (appUser.getVipId()==5){ |
| | | extracted(vipSetting5, now,danger); |
| | | } |
| | | if (appUser.getVipId()==6){ |
| | | extracted(vipSetting6, now,danger); |
| | | } |
| | | if (appUser.getVipId()==7){ |
| | | extracted(vipSetting7, now,danger); |
| | | } |
| | | if (danger){ |
| | | appUser.setIsDanger(1); |
| | | }else { |
| | | appUser.setIsDanger(0); |
| | | } |
| | | } |
| | | appUserService.updateBatchById(list); |
| | | } |
| | | } |
| | | |
| | | private void extracted(VipSetting vipSetting5, LocalDate now,boolean danger) { |
| | | |
| | | if (vipSetting5.getKeepBuyPoint()!=null){ |
| | | //如果消费不为空,查找对应天数的消费积分 |
| | | List<UserPoint> list1 = userPointService.lambdaQuery().eq(UserPoint::getType,1).ge(UserPoint::getCreateTime, now.minusDays(vipSetting5.getKeepBuyDay())).list(); |
| | | //如果消费积分小于保级积分,设置用户降级标志并将降级信息 |
| | | Integer point = 0; |
| | | for (UserPoint userPoint : list1) { |
| | | point = point+userPoint.getVariablePoint(); |
| | | } |
| | | if (point<= vipSetting5.getKeepBuyPoint()){ |
| | | danger = true; |
| | | } |
| | | } |
| | | if (vipSetting5.getKeepSharePoint()!=null){ |
| | | //如果消费不为空,查找对应天数的消费积分 |
| | | List<UserPoint> list1 = userPointService.lambdaQuery().eq(UserPoint::getType,2).ge(UserPoint::getCreateTime, now.minusDays(vipSetting5.getKeepBuyDay())).list(); |
| | | //如果消费积分小于保级积分,设置用户降级标志并将降级信息 |
| | | Integer point = 0; |
| | | for (UserPoint userPoint : list1) { |
| | | point = point+userPoint.getVariablePoint(); |
| | | } |
| | | if (point<= vipSetting5.getKeepBuyPoint()){ |
| | | danger = true; |
| | | } |
| | | } |
| | | if (vipSetting5.getKeepShopPoint()!=null){ |
| | | //如果消费不为空,查找对应天数的消费积分 |
| | | List<UserPoint> list1 = userPointService.lambdaQuery().eq(UserPoint::getType,5).ge(UserPoint::getCreateTime, now.minusDays(vipSetting5.getKeepBuyDay())).list(); |
| | | //如果消费积分小于保级积分,设置用户降级标志并将降级信息 |
| | | Integer point = 0; |
| | | for (UserPoint userPoint : list1) { |
| | | point = point+userPoint.getVariablePoint(); |
| | | } |
| | | if (point<= vipSetting5.getKeepBuyPoint()){ |
| | | danger = true; |
| | | } |
| | | } |
| | | } |
| | | } |