From 2ed6444f45d227e2acc6de65c3e8b582440fb83a Mon Sep 17 00:00:00 2001 From: luofl <1442745593@qq.com> Date: 星期四, 06 三月 2025 09:20:40 +0800 Subject: [PATCH] 迭代版本:2.28 --- ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopPointServiceImpl.java | 186 ++++++++++++++++++++++++++++++++++----------- 1 files changed, 139 insertions(+), 47 deletions(-) diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopPointServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopPointServiceImpl.java index 9e2354a..31f1e1d 100644 --- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopPointServiceImpl.java +++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/ShopPointServiceImpl.java @@ -1,22 +1,30 @@ package com.ruoyi.other.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ruoyi.account.api.feignClient.AppUserClient; -import com.ruoyi.account.api.model.AppUser; import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.security.service.TokenService; import com.ruoyi.other.api.domain.Shop; -import com.ruoyi.other.mapper.ShopPointMapper; import com.ruoyi.other.api.domain.ShopPoint; +import com.ruoyi.other.api.enums.PointChangeType; +import com.ruoyi.other.mapper.ShopPointMapper; import com.ruoyi.other.service.ShopPointService; import com.ruoyi.other.service.ShopService; import com.ruoyi.other.vo.ShopPointStatistics; +import com.ruoyi.system.api.domain.SysUser; +import com.ruoyi.system.api.feignClient.SysUserClient; +import io.swagger.models.auth.In; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -29,61 +37,145 @@ */ @Service public class ShopPointServiceImpl extends ServiceImpl<ShopPointMapper, ShopPoint> implements ShopPointService { + @Resource - private ShopPointMapper shopPointMapper; + private TokenService tokenService; + @Resource + private SysUserClient sysUserClient; @Resource private ShopService shopService; + + + @Override public ShopPointStatistics statistics(IPage<ShopPoint> page, ShopPoint shopPoint) { + Long userid = tokenService.getLoginUser().getUserid(); + SysUser sysUser = sysUserClient.getSysUser(userid).getData(); + if (sysUser.getRoleType()==1){ - String shopName = shopPoint.getShopName(); - String phone = shopPoint.getPhone(); - String shopLeaderName = shopPoint.getShopLeaderName(); - if (StringUtils.isNotEmpty(shopName) || StringUtils.isNotEmpty(phone) || StringUtils.isNotEmpty(shopLeaderName)) { - List<Integer> shopIds = shopService.listObjs(new LambdaQueryWrapper<Shop>() - .select(Shop::getId) - .like(StringUtils.isNotEmpty(shopName), Shop::getName, shopName) - .like(StringUtils.isNotEmpty(phone), Shop::getPhone, phone) - .like(StringUtils.isNotEmpty(shopLeaderName), Shop::getShopManager, shopLeaderName)) - .stream().map(o -> (Integer) o).collect(Collectors.toList()); - - shopPoint.setShopIds(shopIds); - } + ShopPointStatistics shopPointStatistics = new ShopPointStatistics(); + IPage<ShopPoint> shopPointIPage = this.baseMapper.queryShpointPage(page, shopPoint); + shopPointStatistics.setShopPointIPage(shopPointIPage); - ShopPointStatistics shopPointStatistics = new ShopPointStatistics(); - List<ShopPoint> latestChangeByType = shopPointMapper.findLatestChangeByType(shopPoint); - for (ShopPoint sp : latestChangeByType) { - switch (sp.getType()) { - case 1: - shopPointStatistics.setShopPoint(sp.getVariablePoint()); - break; - case 2: - shopPointStatistics.setShopCommissionPoint(sp.getVariablePoint()); - break; - case 3: - shopPointStatistics.setSubShopCommissionPoint(sp.getVariablePoint()); - break; + List<ShopPoint> shopPointList = list(); + Map<Integer, List<ShopPoint>> shopPointByTypeMap = shopPointList.stream().collect(Collectors.groupingBy(ShopPoint::getType)); + shopPointByTypeMap.forEach((type, shopPoints) -> { + shopPoints.stream().map(ShopPoint::getVariablePoint).reduce(Integer::sum).ifPresent(sum -> { + switch (type) { + case 1: + shopPointStatistics.setShopPoint(sum); + break; + case 2: + shopPointStatistics.setShopCommissionPoint(sum); + break; + case 3: + shopPointStatistics.setSubShopCommissionPoint(sum); + break; + default: + break; + } + }); + }); + + Integer point = shopPointStatistics.getShopPoint() == null ? 0 : shopPointStatistics.getShopPoint(); + Integer shopCommissionPoint = shopPointStatistics.getShopCommissionPoint() == null ? 0 : shopPointStatistics.getShopCommissionPoint(); + Integer setSubShopCommissionPoint = shopPointStatistics.getSubShopCommissionPoint() == null ? 0 : shopPointStatistics.getSubShopCommissionPoint(); + Integer totalPoint = point + shopCommissionPoint + setSubShopCommissionPoint; + shopPointStatistics.setTotalPoint(totalPoint); + + + LocalDateTime startTime = shopPoint.getStartTime(); + LocalDateTime endTime = shopPoint.getEndTime(); + if(null != startTime){ + List<ShopPoint> list = this.list(new LambdaUpdateWrapper<ShopPoint>() + .eq(ShopPoint::getShopId, sysUser.getObjectId()) + .last(" and create_time between '" + startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "' and '" + endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "'")); + List<String> date = new ArrayList<>(); + List<Map<String, Integer>> data = new ArrayList<>(); + String format = "MM.dd"; + while (true){ + if(startTime.isAfter(endTime)){ + break; + } + date.add(startTime.format(DateTimeFormatter.ofPattern(format))); + Map<String, Integer> map = new HashMap<>(); + //返佣积分 + LocalDateTime finalStartTime = startTime; + List<ShopPoint> collect = list.stream().filter(s -> s.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + .equals(finalStartTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) && s.getType() == 2).collect(Collectors.toList()); + map.put("fyjf", collect.stream().mapToInt(ShopPoint::getVariablePoint).sum()); + + //服务积分 + List<ShopPoint> collect1 = list.stream().filter(s -> s.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + .equals(finalStartTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) && s.getType() == 1).collect(Collectors.toList()); + map.put("fwjf", collect1.stream().mapToInt(ShopPoint::getVariablePoint).sum()); + //绑定下级门店返佣积分 + List<ShopPoint> collect2 = list.stream().filter(s -> s.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + .equals(finalStartTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) && s.getType() == 3).collect(Collectors.toList()); + map.put("xjmdfyjf", collect2.stream().mapToInt(ShopPoint::getVariablePoint).sum()); + data.add(map); + startTime = startTime.plusDays(1); + } + Map<String, Object> brokenLine = new HashMap<>(); + brokenLine.put("date", date); + brokenLine.put("data", data); + shopPointStatistics.setBrokenLine(brokenLine); } - } - shopPointStatistics.setTotalPoint(shopPointStatistics.getShopPoint() + shopPointStatistics.getShopCommissionPoint() + shopPointStatistics.getSubShopCommissionPoint()); + return shopPointStatistics; + }else{ + Shop shop = shopService.getById(sysUser.getObjectId()); + Integer serverPoint = shop.getServerPoint(); + Integer sharePoint = shop.getSharePoint(); + Integer lowerLevelSharePoint = shop.getLowerLevelSharePoint(); + ShopPointStatistics shopPointStatistics = new ShopPointStatistics(); + shopPointStatistics.setTotalPoint(serverPoint + sharePoint + lowerLevelSharePoint); + shopPointStatistics.setShopPoint(serverPoint); + shopPointStatistics.setShopCommissionPoint(sharePoint); + shopPointStatistics.setSubShopCommissionPoint(lowerLevelSharePoint); + IPage<ShopPoint> shopPointIPage = this.baseMapper.queryShpointPage(page, shopPoint); + shopPointStatistics.setShopPointIPage(shopPointIPage); - boolean condition = shopPoint.getStartTime() != null && shopPoint.getEndTime() != null; - IPage<ShopPoint> shopPointIPage = page(page, new LambdaQueryWrapper<ShopPoint>() - .in(!CollectionUtils.isEmpty(shopPoint.getShopIds()), ShopPoint::getShopId, shopPoint.getShopIds()) - .eq(shopPoint.getType() != null, ShopPoint::getType, shopPoint.getType()) - .between(condition, ShopPoint::getCreateTime, shopPoint.getStartTime(), shopPoint.getEndTime()) - .orderByDesc(ShopPoint::getCreateTime)); - List<ShopPoint> shopPoints = shopPointIPage.getRecords(); - for (ShopPoint sp : shopPoints) { - Shop shop = shopService.getById(sp.getShopId()); - sp.setShopName(shop.getName()); - sp.setShopLeaderName(shop.getShopManager()); - sp.setPhone(shop.getPhone()); + LocalDateTime startTime = shopPoint.getStartTime(); + LocalDateTime endTime = shopPoint.getEndTime(); + if(null != startTime){ + List<ShopPoint> list = this.list(new LambdaUpdateWrapper<ShopPoint>() + .eq(ShopPoint::getShopId, sysUser.getObjectId()) + .last(" and create_time between '" + startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "' and '" + endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + "'")); + List<String> date = new ArrayList<>(); + List<Map<String, Integer>> data = new ArrayList<>(); + String format = "MM.dd"; + while (true){ + if(startTime.isAfter(endTime)){ + break; + } + date.add(startTime.format(DateTimeFormatter.ofPattern(format))); + Map<String, Integer> map = new HashMap<>(); + //返佣积分 + LocalDateTime finalStartTime = startTime; + List<ShopPoint> collect = list.stream().filter(s -> s.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + .equals(finalStartTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) && s.getType() == 2).collect(Collectors.toList()); + map.put("fyjf", collect.stream().mapToInt(ShopPoint::getVariablePoint).sum()); + + //服务积分 + List<ShopPoint> collect1 = list.stream().filter(s -> s.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + .equals(finalStartTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) && s.getType() == 1).collect(Collectors.toList()); + map.put("fwjf", collect1.stream().mapToInt(ShopPoint::getVariablePoint).sum()); + //绑定下级门店返佣积分 + List<ShopPoint> collect2 = list.stream().filter(s -> s.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + .equals(finalStartTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))) && s.getType() == 3).collect(Collectors.toList()); + map.put("xjmdfyjf", collect2.stream().mapToInt(ShopPoint::getVariablePoint).sum()); + data.add(map); + startTime = startTime.plusDays(1); + } + Map<String, Object> brokenLine = new HashMap<>(); + brokenLine.put("date", date); + brokenLine.put("data", data); + shopPointStatistics.setBrokenLine(brokenLine); + } + return shopPointStatistics; } - shopPointStatistics.setShopPointIPage(shopPointIPage); - return shopPointStatistics; } } -- Gitblit v1.7.1