|  |  |  | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Service | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<MallVipConfig> findConfigList() { | 
|---|
|  |  |  | return this.baseMapper.selectVipConfigList(); | 
|---|
|  |  |  | List<MallVipConfig> configs = this.baseMapper.selectVipConfigList(); | 
|---|
|  |  |  | configs.forEach(item -> { | 
|---|
|  |  |  | List<MallVipBenefits> data = item.getBenefits().stream().filter(benefit -> { | 
|---|
|  |  |  | return benefit.getIsShow() == 1; | 
|---|
|  |  |  | }).peek(benefits -> { | 
|---|
|  |  |  | benefits.setIsJump(CollUtil.isEmpty(benefits.getDetails()) ? 2 : 1); | 
|---|
|  |  |  | }).collect(Collectors.toList()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | item.setBenefits(data); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | return configs; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | public void addVipConfig(MallVipConfig config) { | 
|---|
|  |  |  | List<MallVipConfig> configs = this.baseMapper.selectVipConfigList(); | 
|---|
|  |  |  | boolean b = configs.stream().anyMatch(item -> { | 
|---|
|  |  |  | return (item.getLevel().equals(config.getLevel()) || config.getCode().equals(item.getCode())); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (b) { | 
|---|
|  |  |  | throw new FebsException("会员等级或编码已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | this.baseMapper.insert(config); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallVipConfigBenefits> configBenefitsList = new ArrayList<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void editVipConfig(MallVipConfig config) { | 
|---|
|  |  |  | MallVipConfig oldConfig = this.baseMapper.selectById(config.getId()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<MallVipConfig> configs = this.baseMapper.selectVipConfigList(); | 
|---|
|  |  |  | boolean b = configs.stream().anyMatch(item -> { | 
|---|
|  |  |  | return !item.getId().equals(config.getId()) && (item.getLevel().equals(config.getLevel()) || config.getCode().equals(item.getCode())); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (b) { | 
|---|
|  |  |  | throw new FebsException("会员等级或编码已存在"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (!config.getCode().equals(oldConfig.getCode())) { | 
|---|
|  |  |  | LambdaQueryWrapper<MallMember> memberQuery = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | memberQuery.eq(MallMember::getLevel, oldConfig.getCode()); | 
|---|
|  |  |  | List<MallMember> mallMembers = mallMemberMapper.selectList(memberQuery); | 
|---|
|  |  |  | if (CollUtil.isNotEmpty(mallMembers)) { | 
|---|
|  |  |  | throw new FebsException("会员编码绑定了客户,请调整后修改"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | this.baseMapper.updateById(config); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LambdaQueryWrapper<MallVipConfigBenefits> delQuery = new LambdaQueryWrapper<>(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String today = DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN); | 
|---|
|  |  |  | boolean isBirthday = member.getBirthday().compareTo(DateUtil.parseDate(today)) == 0; | 
|---|
|  |  |  | boolean isBirthday; | 
|---|
|  |  |  | if (member.getBirthday() != null) { | 
|---|
|  |  |  | isBirthday = member.getBirthday().compareTo(DateUtil.parseDate(today)) == 0; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | isBirthday = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<MallVipBenefits> benefits = vipConfig.getBenefits(); | 
|---|
|  |  |  | Optional<MallVipBenefits> max = benefits.stream().filter(item -> { | 
|---|
|  |  |  | if (item.getScoreMultiple() == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (item.getGainType() == 3 && item.getScoreMultiple() != null) { | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 生日权益 | 
|---|
|  |  |  | 
|---|
|  |  |  | return item.getGainType() == 1 && StrUtil.equals(data.getValue(), todayTime); | 
|---|
|  |  |  | }).max(Comparator.comparing(MallVipBenefits::getScoreMultiple)); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return max.orElseGet(max::get); | 
|---|
|  |  |  | return max.orElse(null); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|