1
phpcjl
2024-12-17 f6c948f093a35f20e8fc94b5d0f893c5647c41b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.ruoyi.other.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.other.api.domain.Shop;
import com.ruoyi.other.mapper.ShopPointMapper;
import com.ruoyi.other.api.domain.ShopPoint;
import com.ruoyi.other.service.ShopPointService;
import com.ruoyi.other.service.ShopService;
import com.ruoyi.other.vo.ShopPointStatistics;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-20
 */
@Service
public class ShopPointServiceImpl extends ServiceImpl<ShopPointMapper, ShopPoint> implements ShopPointService {
    @Resource
    private ShopPointMapper shopPointMapper;
    @Resource
    private ShopService shopService;
 
    @Override
    public ShopPointStatistics statistics(IPage<ShopPoint> page, ShopPoint shopPoint) {
 
        String shopName = shopPoint.getShopName();
        String phone = shopPoint.getPhone();
        String shopLeaderName = shopPoint.getShopLeaderName();
        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());
        if (CollectionUtils.isEmpty(shopIds)) {
            return new ShopPointStatistics();
        }
 
        shopPoint.setShopIds(shopIds);
 
 
        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;
            }
        }
        shopPointStatistics.setTotalPoint(shopPointStatistics.getShopPoint() + shopPointStatistics.getShopCommissionPoint() + shopPointStatistics.getSubShopCommissionPoint());
 
 
        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());
        }
        shopPointStatistics.setShopPointIPage(shopPointIPage);
        return shopPointStatistics;
    }
}