| | |
| | | package com.webmanage.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.webmanage.common.BusinessException; |
| | | import com.webmanage.common.PageResult; |
| | | import com.webmanage.dto.PointsRuleDTO; |
| | | import com.webmanage.emun.RuleTypeEnum; |
| | | import com.webmanage.entity.Points; |
| | | import com.webmanage.entity.PointsRule; |
| | | import com.webmanage.entity.PointsRuleDetail; |
| | |
| | | import com.webmanage.service.PointsRuleService; |
| | | import com.webmanage.service.PointsService; |
| | | import com.webmanage.service.PointsRuleDetailService; |
| | | import com.webmanage.vo.PointsRuleResultVO; |
| | | import com.webmanage.vo.PointsRuleVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 积分规则Service实现类 |
| | |
| | | private PointsRuleDetailService pointsRuleDetailService; |
| | | |
| | | @Override |
| | | public PageResult<PointsRule> getPointsRulePage(Integer pageNum, Integer pageSize, String ruleName, String ruleType) { |
| | | Page<PointsRule> page = new Page<>(pageNum, pageSize); |
| | | |
| | | public PointsRuleResultVO getPointsRuleList(Long ruleId) { |
| | | |
| | | QueryWrapper<PointsRule> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("deleted", 0); |
| | | |
| | | wrapper.eq("deleted", 0).eq("is_enabled",0); |
| | | |
| | | if (StringUtils.hasText(ruleName)) { |
| | | wrapper.like("rule_name", ruleName); |
| | | if(ruleId != null){ |
| | | wrapper.eq("points_id", ruleId); |
| | | } |
| | | if (StringUtils.hasText(ruleType)) { |
| | | wrapper.eq("rule_type", ruleType); |
| | | |
| | | List<PointsRule> list = list(wrapper); |
| | | PointsRuleResultVO pointsRuleResultVO = new PointsRuleResultVO(); |
| | | if (!CollectionUtil.isEmpty(list)) { |
| | | Map<Long, List<PointsRule>> collect = list.stream().collect(Collectors.groupingBy(PointsRule::getRuleType)); |
| | | |
| | | Map<String, List<PointsRule>> getRules = collect.get(RuleTypeEnum.GET.getCode()).stream().collect(Collectors.groupingBy(PointsRule::getCategory)); |
| | | Map<String, List<PointsRule>> consumeRules = collect.get(RuleTypeEnum.CONSUME.getCode()).stream().collect(Collectors.groupingBy(PointsRule::getCategory)); |
| | | List<PointsRuleVO> getPointsRuleVOList = new ArrayList<>(); |
| | | List<PointsRuleVO> consumePointsRuleVOList = new ArrayList<>(); |
| | | getRules.forEach((k,v)->{ |
| | | PointsRuleVO pointsRuleVO = new PointsRuleVO(); |
| | | pointsRuleVO.setCategory(k); |
| | | pointsRuleVO.setPointsRules(v); |
| | | getPointsRuleVOList.add(pointsRuleVO); |
| | | |
| | | }); |
| | | consumeRules.forEach((k,v)->{ |
| | | PointsRuleVO pointsRuleVO = new PointsRuleVO(); |
| | | pointsRuleVO.setCategory(k); |
| | | pointsRuleVO.setPointsRules(v); |
| | | consumePointsRuleVOList.add(pointsRuleVO); |
| | | |
| | | }); |
| | | pointsRuleResultVO.setGetPointsRuleList(getPointsRuleVOList); |
| | | pointsRuleResultVO.setConsumePointsRuleList(consumePointsRuleVOList); |
| | | } |
| | | |
| | | wrapper.orderByDesc("priority", "created_at"); |
| | | |
| | | IPage<PointsRule> result = page(page, wrapper); |
| | | |
| | | return new PageResult<PointsRule>( |
| | | result.getRecords(), |
| | | result.getTotal(), |
| | | pageNum.longValue(), |
| | | pageSize.longValue(), |
| | | result.getPages() |
| | | ); |
| | | |
| | | return pointsRuleResultVO; |
| | | } |
| | | |
| | | @Override |