PublicReportBizService.java 29.3 KB
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
package cn.fw.valhalla.service.report;

import cn.fw.common.cache.locker.DistributedLocker;
import cn.fw.valhalla.domain.db.PublicReportData;
import cn.fw.valhalla.domain.dto.*;
import cn.fw.valhalla.domain.enums.PubStandType;
import cn.fw.valhalla.domain.enums.StammkundeSourcesEnum;
import cn.fw.valhalla.domain.enums.ValhallaReportDimension;
import cn.fw.valhalla.service.data.PubCluePoolService;
import cn.fw.valhalla.service.data.PublicPoolService;
import cn.fw.valhalla.service.data.PublicReportDataService;
import cn.fw.valhalla.service.data.StammkundePoolService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Sets;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 公共池报表数据服务
 *
 * @author : kurisu
 * @version : 2.0
 * @className : PublicReportBizService
 * @description : 公共池报表数据服务
 * @date : 2023-05-04 15:07
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class PublicReportBizService {
    private final DistributedLocker distributedLocker;
    private final PublicReportDataService publicReportDataService;
    private final PubCluePoolService pubCluePoolService;
    private final StammkundePoolService stammkundePoolService;
    private final PublicPoolService publicPoolService;

    @Value("${spring.cache.custom.global-prefix}:PublicReport:extracting")
    @Getter
    private String keyPrefix;

    /**
     * 抽取集团公共池数据
     *
     * @param nowDate 日期
     * @param groupId 集团id
     */
    @Transactional(rollbackFor = Exception.class)
    public void extracting(final LocalDate nowDate, final Long groupId) {
        log.info("开始抽取公共池报表数据,日期:{} 集团:{}", nowDate, groupId);
        final String lockKey = generateKey(groupId);
        RLock lock = (RLock) distributedLocker.lock(lockKey);
        if (lock == null || !lock.isLocked()) {
            return;
        }
        try {
            /**
             * 1.准备数据
             */
            HashSet<Integer> sourceTypes = Sets.newHashSet(PubStandType.PUB.getValue(), PubStandType.ACTIVITY.getValue());
            HashSet<Integer> sourceSets = Sets.newHashSet(StammkundeSourcesEnum.NATURAL.getValue());
            //开始时间
            LocalDateTime startDayDateTime = nowDate.atTime(0, 0, 0);
            //结束时间
            LocalDateTime endDayDateTime = nowDate.atTime(23, 59, 59);
            //月初日期
            LocalDate startMonDate = nowDate.with(TemporalAdjusters.firstDayOfMonth());
            //月初时间
            LocalDateTime startMonDateTime = startMonDate.atTime(0,0,0);
            //月初的截止结束时间 = 月初的上一天的23:59:59
            LocalDateTime startMonDateTimeOver = startMonDate.minusDays(1).atTime(23, 59, 59);
            /**
             * 1.1 查询日站岗分配(人)
             */
            List<PubCluePoolReportDTO> cluePoolDayList = getCluePoolTimeList(groupId, sourceTypes, startDayDateTime, endDayDateTime);
            /**
             * 1.2 查询月站岗分配(人)
             */
            List<PubCluePoolReportDTO> cluePoolMonList = getCluePoolTimeList(groupId, sourceTypes,startMonDateTime, endDayDateTime);
            /**
             * 1.3 查询日自然到店成交(人)
             */
            List<StammkundePoolReportDTO> stammkundePoolReportDayList = getStammkundePoolReportTimeList(groupId, startDayDateTime, endDayDateTime, sourceSets);
            /**
             * 1.4 查询月自然到店成交(人)
             */
            List<StammkundePoolReportDTO> stammkundePoolReportMonList = getStammkundePoolReportTimeList(groupId, startMonDateTime,endDayDateTime, sourceSets);
            /**
             * 1.5 查询日新增(来源)
             */
            List<PublicPoolReportDTO> poolReportDayDTOList = getPoolReportList(groupId, startDayDateTime, endDayDateTime);
            /**
             * 1.6 查询月新增(来源)
             */
            List<PublicPoolReportDTO> poolReportMonDTOList = getPoolReportList(groupId, startMonDateTime, endDayDateTime);
            /**
             * 1.7 截止当前(来源)
             */
            List<PublicPoolReportDTO> poolReportCutDTOList = getPoolReportList(groupId,null, endDayDateTime);

            /**
             * 1.8 月初始数(来源)
             */
            List<PublicPoolReportDTO> poolReportMonFirstDTOList = getPoolReportMonFirstDTOList(nowDate,startMonDate, groupId, startMonDateTimeOver);
            /**
             * 2.处理数据
             */
            /**
             * 2.1 人员维度
             */
            List<PublicReportData> publicReportDataD20List = extractedD20(nowDate, groupId, cluePoolDayList, cluePoolMonList, stammkundePoolReportDayList, stammkundePoolReportMonList);
            /**
             * 2.2 来源维度
             */
            List<PublicReportData> publicReportDataD99List = extractedD99(nowDate, groupId, poolReportDayDTOList, poolReportMonDTOList, poolReportCutDTOList, poolReportMonFirstDTOList);
            /**
             * 2.3 门店维度 = 来源 + 人员
             */
            List<PublicReportData> publicReportDataD10List = extractedD10(nowDate, groupId, publicReportDataD20List, publicReportDataD99List);

            /**
             * 3.存储数据
             */
            /**
             * 3.1 清理旧数据
             */
            delNowDate(nowDate);
            /**
             * 3.2 存储新数据
             */
            save(publicReportDataD20List, publicReportDataD99List, publicReportDataD10List);
        } finally {
            if (lock.isLocked()) {
                lock.unlock();
            }
        }
    }

    /**
     * 获取月初的数据
     * @param nowDate
     * @param startMonDate
     * @param groupId
     * @param startMonDateTimeOver
     * @return
     */
    private List<PublicPoolReportDTO> getPoolReportMonFirstDTOList(LocalDate nowDate,LocalDate startMonDate, Long groupId, LocalDateTime startMonDateTimeOver) {
        List<PublicPoolReportDTO> poolReportMonFirstDTOList = new ArrayList<>();
        if (nowDate.equals(startMonDate)) {
            //如果是月初一就去查询小于月初一的数据统计
            poolReportMonFirstDTOList = getPoolReportList(groupId,null, startMonDateTimeOver);
        }else {
            //不是1号的数据直接从上次抽取的数据中查询月初一的数据
            List<PublicReportData> reportDataList = publicReportDataService.list(Wrappers.<PublicReportData>lambdaQuery()
                    .eq(PublicReportData::getReportDimension, ValhallaReportDimension.D99.getValue())
                    .eq(PublicReportData::getDataDate, startMonDate)
            );
            if (!CollectionUtils.isEmpty(reportDataList)){
                for (PublicReportData publicReportData : reportDataList) {
                    PublicPoolReportDTO publicPoolReportDTO = new PublicPoolReportDTO();
                    publicPoolReportDTO.setType(publicReportData.getType());
                    publicPoolReportDTO.setShopId(publicReportData.getShopId());
                    publicPoolReportDTO.setShopName(publicReportData.getShopName());
                    if (Objects.nonNull(publicReportData.getMonthInitial())){
                        publicPoolReportDTO.setTotal(publicReportData.getMonthInitial().longValue());
                    }
                    poolReportMonFirstDTOList.add(publicPoolReportDTO);
                }
            }
        }
        return poolReportMonFirstDTOList;
    }

    /**
     * 查询指定时间
     * @param groupId
     * @param startDayDateTime
     * @param endDayDateTime
     * @return
     */
    private List<PublicPoolReportDTO> getPoolReportList(Long groupId,LocalDateTime startDayDateTime,LocalDateTime endDayDateTime){
        PublicPoolReportQueryDTO publicPoolReportQueryDayDTO = new PublicPoolReportQueryDTO(groupId);
        publicPoolReportQueryDayDTO.setStartDate(startDayDateTime);
        publicPoolReportQueryDayDTO.setEndDate(endDayDateTime);
        return publicPoolService.countPublicPoolList(publicPoolReportQueryDayDTO);
    }

    /**
     * 1.3 查询指定时间自然到店成交(人)
     * @param groupId
     * @param startDayDateTime
     * @param endDayDateTime
     * @param sourceSets
     * @return
     */
    private List<StammkundePoolReportDTO> getStammkundePoolReportTimeList(Long groupId, LocalDateTime startDayDateTime, LocalDateTime endDayDateTime, HashSet<Integer> sourceSets) {
        StammkundePoolReportQueryDTO stammkundePoolReportQueryDayDTO = new StammkundePoolReportQueryDTO(groupId);
        stammkundePoolReportQueryDayDTO.setStartDate(startDayDateTime);
        stammkundePoolReportQueryDayDTO.setEndDate(endDayDateTime);
        stammkundePoolReportQueryDayDTO.setSourceSets(sourceSets);
        return stammkundePoolService.countStammkundePoolList(stammkundePoolReportQueryDayDTO);
    }

    /**
     * 1.1 查询指定时间站岗分配(人)
     * @param groupId
     * @param sourceTypes
     * @param startDayDateTime
     * @param endDayDateTime
     * @return
     */
    private List<PubCluePoolReportDTO> getCluePoolTimeList(Long groupId, HashSet<Integer> sourceTypes, LocalDateTime startDayDateTime, LocalDateTime endDayDateTime) {
        PubCluePoolReportQueryDTO reportQueryDayDTO = new PubCluePoolReportQueryDTO(groupId);
        reportQueryDayDTO.setStartDate(startDayDateTime);
        reportQueryDayDTO.setEndDate(endDayDateTime);
        reportQueryDayDTO.setSourceTypes(sourceTypes);
        return pubCluePoolService.countPubCluePoolList(reportQueryDayDTO);
    }

    /**
     * 3.1 清理旧数据
     * @param nowDate
     */
    private void delNowDate(LocalDate nowDate) {
        publicReportDataService.remove(Wrappers.<PublicReportData>lambdaUpdate()
                .eq(PublicReportData::getDataDate, nowDate)
        );
    }

    /**
     * 3.2 存储新数据
     * @param publicReportDataD20List 人员的
     * @param publicReportDataD99List 来源的
     * @param publicReportDataD10List 店的
     */
    private void save(List<PublicReportData> publicReportDataD20List, List<PublicReportData> publicReportDataD99List, List<PublicReportData> publicReportDataD10List) {
        if (!CollectionUtils.isEmpty(publicReportDataD20List)){
            for (PublicReportData reportData : publicReportDataD20List) {
                dealDefaultValueD20(reportData);
            }
            publicReportDataService.saveBatch(publicReportDataD20List);
        }
        if (!CollectionUtils.isEmpty(publicReportDataD99List)){
            for (PublicReportData reportData : publicReportDataD99List) {
                dealDefaultValueD99(reportData);
            }
            publicReportDataService.saveBatch(publicReportDataD99List);
        }
        if (!CollectionUtils.isEmpty(publicReportDataD10List)){
            for (PublicReportData reportData : publicReportDataD10List) {
                //店的默认值处理,共8个 = 人的+店的
                dealDefaultValueD20(reportData);
                dealDefaultValueD99(reportData);
            }
            publicReportDataService.saveBatch(publicReportDataD10List);
        }
    }

    /**
     * 来源的默认值处理,共4个
     * @param reportData
     */
    private static void dealDefaultValueD99(PublicReportData reportData) {
        if (Objects.isNull(reportData.getMonthInitial())){
            reportData.setMonthInitial(0);
        }
        if (Objects.isNull(reportData.getDayIncrease())){
            reportData.setDayIncrease(0);
        }
        if (Objects.isNull(reportData.getMonthIncrease())){
            reportData.setMonthIncrease(0);
        }
        if (Objects.isNull(reportData.getCurrentQuantity())){
            reportData.setCurrentQuantity(0);
        }
    }

    /**
     * 人员的默认值处理,共4个
     * @param reportData
     */
    private static void dealDefaultValueD20(PublicReportData reportData) {
        //人员的默认值处理,共4个
        if (Objects.isNull(reportData.getDayStandQuantity())){
            reportData.setDayStandQuantity(0);
        }
        if (Objects.isNull(reportData.getMonthStandQuantity())){
            reportData.setMonthStandQuantity(0);
        }
        if (Objects.isNull(reportData.getDayNaturalQuantity())){
            reportData.setDayNaturalQuantity(0);
        }
        if (Objects.isNull(reportData.getMonthNaturalQuantity())){
            reportData.setMonthNaturalQuantity(0);
        }
    }


    /**
     * 处理门店维度的数据
     * @param nowDate
     * @param groupId
     * @param publicReportDataD20List
     * @param publicReportDataD99List
     * @return
     */
    private List<PublicReportData>  extractedD10(LocalDate nowDate, Long groupId, List<PublicReportData> publicReportDataD20List, List<PublicReportData> publicReportDataD99List) {
        List<PublicReportData> publicReportData10List = new ArrayList<>();
        if (!CollectionUtils.isEmpty(publicReportDataD20List)){
            Map<Long, List<PublicReportData>> shopIdListMap = publicReportDataD20List.stream().collect(Collectors.groupingBy(PublicReportData::getShopId));
            shopIdListMap.forEach((shopId,shopList) -> {
                PublicReportData publicReportData = getPublicReportDataD10(publicReportData10List, shopId, groupId);
                publicReportData.setDataDate(nowDate);
                publicReportData.setShopId(shopId);
                if (StringUtils.isEmpty(publicReportData.getShopName())){
                    publicReportData.setShopName(Objects.nonNull(shopList.get(0)) ? shopList.get(0).getShopName():null);
                }
                publicReportData.setDayStandQuantity(shopList.stream().filter(e -> Objects.nonNull(e.getDayStandQuantity())).mapToInt(PublicReportData :: getDayStandQuantity).sum());
                publicReportData.setMonthStandQuantity(shopList.stream().filter(e -> Objects.nonNull(e.getMonthStandQuantity())).mapToInt(PublicReportData :: getMonthStandQuantity).sum());
                publicReportData.setDayNaturalQuantity(shopList.stream().filter(e -> Objects.nonNull(e.getDayNaturalQuantity())).mapToInt(PublicReportData :: getDayNaturalQuantity).sum());
                publicReportData.setMonthNaturalQuantity(shopList.stream().filter(e -> Objects.nonNull(e.getMonthNaturalQuantity())).mapToInt(PublicReportData :: getMonthNaturalQuantity).sum());
                publicReportData.setCreateTime(new Date());
                publicReportData.setUpdateTime(publicReportData.getCreateTime());
                if (!publicReportData10List.contains(publicReportData)){
                    publicReportData10List.add(publicReportData);
                }
            });
        }
        if (!CollectionUtils.isEmpty(publicReportDataD99List)){
            Map<Long, List<PublicReportData>> shopIdListMap = publicReportDataD99List.stream().collect(Collectors.groupingBy(PublicReportData::getShopId));
            shopIdListMap.forEach((shopId,shopList) -> {
                PublicReportData publicReportData = getPublicReportDataD10(publicReportData10List, shopId, groupId);
                publicReportData.setDataDate(nowDate);
                publicReportData.setShopId(shopId);
                if (StringUtils.isEmpty(publicReportData.getShopName())){
                    publicReportData.setShopName(Objects.nonNull(shopList.get(0)) ? shopList.get(0).getShopName():null);
                }
                publicReportData.setDayIncrease(shopList.stream().filter(e -> Objects.nonNull(e.getDayIncrease())).mapToInt(PublicReportData :: getDayIncrease).sum());
                publicReportData.setMonthIncrease(shopList.stream().filter(e -> Objects.nonNull(e.getMonthIncrease())).mapToInt(PublicReportData :: getMonthIncrease).sum());
                publicReportData.setCurrentQuantity(shopList.stream().filter(e -> Objects.nonNull(e.getCurrentQuantity())).mapToInt(PublicReportData :: getCurrentQuantity).sum());
                publicReportData.setMonthInitial(shopList.stream().filter(e -> Objects.nonNull(e.getMonthInitial())).mapToInt(PublicReportData :: getMonthInitial).sum());
                publicReportData.setCreateTime(new Date());
                publicReportData.setUpdateTime(publicReportData.getCreateTime());
                if (!publicReportData10List.contains(publicReportData)){
                    publicReportData10List.add(publicReportData);
                }
            });
        }
        return publicReportData10List;
    }


    /**
     * 处理来源维度的数据
     * @param nowDate
     * @param groupId
     * @param poolReportDayDTOList
     * @param poolReportMonDTOList
     * @param poolReportCutDTOList
     * @param poolReportMonFirstDTOList
     */
    private List<PublicReportData> extractedD99(LocalDate nowDate, Long groupId,
                                                List<PublicPoolReportDTO> poolReportDayDTOList,
                                                List<PublicPoolReportDTO> poolReportMonDTOList,
                                                List<PublicPoolReportDTO> poolReportCutDTOList,
                                                List<PublicPoolReportDTO> poolReportMonFirstDTOList) {
        List<PublicReportData> publicReportData99List = new ArrayList<>();
        if (!CollectionUtils.isEmpty(poolReportDayDTOList)){
            for (PublicPoolReportDTO publicPoolReportDTO : poolReportDayDTOList) {
                PublicReportData publicReportData = getPublicReportDataD99Increase(publicReportData99List, publicPoolReportDTO, groupId);
                publicReportData.setDataDate(nowDate);
                publicReportData.setShopId(publicPoolReportDTO.getShopId());
                if (StringUtils.isEmpty(publicReportData.getShopName())){
                    publicReportData.setShopName(publicPoolReportDTO.getShopName());
                }
                publicReportData.setDayIncrease(publicPoolReportDTO.getTotal().intValue());
                publicReportData.setType(publicPoolReportDTO.getType());
                publicReportData.setCreateTime(new Date());
                publicReportData.setUpdateTime(publicReportData.getCreateTime());
                if (!publicReportData99List.contains(publicReportData)){
                    publicReportData99List.add(publicReportData);
                }
            }
        }
        if (!CollectionUtils.isEmpty(poolReportMonDTOList)){
            for (PublicPoolReportDTO publicPoolReportDTO : poolReportMonDTOList) {
                PublicReportData publicReportData = getPublicReportDataD99Increase(publicReportData99List, publicPoolReportDTO, groupId);
                publicReportData.setDataDate(nowDate);
                publicReportData.setShopId(publicPoolReportDTO.getShopId());
                if (StringUtils.isEmpty(publicReportData.getShopName())){
                    publicReportData.setShopName(publicPoolReportDTO.getShopName());
                }
                publicReportData.setMonthIncrease(publicPoolReportDTO.getTotal().intValue());
                publicReportData.setType(publicPoolReportDTO.getType());
                publicReportData.setCreateTime(new Date());
                publicReportData.setUpdateTime(publicReportData.getCreateTime());
                if (!publicReportData99List.contains(publicReportData)){
                    publicReportData99List.add(publicReportData);
                }
            }
        }
        if (!CollectionUtils.isEmpty(poolReportCutDTOList)){
            for (PublicPoolReportDTO publicPoolReportDTO : poolReportCutDTOList) {
                PublicReportData publicReportData = getPublicReportDataD99Increase(publicReportData99List, publicPoolReportDTO, groupId);
                publicReportData.setDataDate(nowDate);
                publicReportData.setShopId(publicPoolReportDTO.getShopId());
                if (StringUtils.isEmpty(publicReportData.getShopName())){
                    publicReportData.setShopName(publicPoolReportDTO.getShopName());
                }
                publicReportData.setCurrentQuantity(publicPoolReportDTO.getTotal().intValue());
                publicReportData.setType(publicPoolReportDTO.getType());
                publicReportData.setCreateTime(new Date());
                publicReportData.setUpdateTime(publicReportData.getCreateTime());
                if (!publicReportData99List.contains(publicReportData)){
                    publicReportData99List.add(publicReportData);
                }
            }
        }
        if (!CollectionUtils.isEmpty(poolReportMonFirstDTOList)){
            for (PublicPoolReportDTO publicPoolReportDTO : poolReportMonFirstDTOList) {
                PublicReportData publicReportData = getPublicReportDataD99Increase(publicReportData99List, publicPoolReportDTO, groupId);
                publicReportData.setDataDate(nowDate);
                publicReportData.setShopId(publicPoolReportDTO.getShopId());
                if (StringUtils.isEmpty(publicReportData.getShopName())){
                    publicReportData.setShopName(publicPoolReportDTO.getShopName());
                }
                publicReportData.setMonthInitial(publicPoolReportDTO.getTotal().intValue());
                publicReportData.setType(publicPoolReportDTO.getType());
                publicReportData.setCreateTime(new Date());
                publicReportData.setUpdateTime(publicReportData.getCreateTime());
                if (!publicReportData99List.contains(publicReportData)){
                    publicReportData99List.add(publicReportData);
                }
            }
        }
        return publicReportData99List;
    }

    /**
     * 处理人员维度的数据
     * @param nowDate
     * @param groupId
     * @param cluePoolDayList
     * @param cluePoolMonList
     * @param stammkundePoolReportDayDTOS
     * @param stammkundePoolReportMonDTOS
     */
    private List<PublicReportData> extractedD20(LocalDate nowDate, Long groupId,
                                                List<PubCluePoolReportDTO> cluePoolDayList,
                                                List<PubCluePoolReportDTO> cluePoolMonList,
                                                List<StammkundePoolReportDTO> stammkundePoolReportDayDTOS,
                                                List<StammkundePoolReportDTO> stammkundePoolReportMonDTOS) {
        List<PublicReportData> publicReportData20List = new ArrayList<>();
        if (!CollectionUtils.isEmpty(cluePoolDayList)){
            for (PubCluePoolReportDTO pubCluePoolReportDTO : cluePoolDayList) {
                PublicReportData data = getPublicReportDataD20Stand(publicReportData20List, pubCluePoolReportDTO, groupId);
                data.setDataDate(nowDate);
                data.setUserId(pubCluePoolReportDTO.getAdviserId());
                data.setUserName(pubCluePoolReportDTO.getAdviserName());
                data.setShopId(pubCluePoolReportDTO.getShopId());
                if (StringUtils.isEmpty(data.getShopName())){
                    data.setShopName(pubCluePoolReportDTO.getShopName());
                }
                data.setDayStandQuantity(pubCluePoolReportDTO.getTotal().intValue());
                data.setCreateTime(new Date());
                data.setUpdateTime(data.getCreateTime());
                if (!publicReportData20List.contains(data)){
                    publicReportData20List.add(data);
                }
            }
        }
        if (!CollectionUtils.isEmpty(cluePoolMonList)){
            for (PubCluePoolReportDTO pubCluePoolReportDTO : cluePoolMonList) {
                PublicReportData data = getPublicReportDataD20Stand(publicReportData20List, pubCluePoolReportDTO, groupId);
                data.setDataDate(nowDate);
                data.setUserId(pubCluePoolReportDTO.getAdviserId());
                data.setUserName(pubCluePoolReportDTO.getAdviserName());
                data.setShopId(pubCluePoolReportDTO.getShopId());
                if (StringUtils.isEmpty(data.getShopName())){
                    data.setShopName(pubCluePoolReportDTO.getShopName());
                }
                data.setMonthStandQuantity((pubCluePoolReportDTO.getTotal().intValue()));
                data.setCreateTime(new Date());
                data.setUpdateTime(data.getCreateTime());
                if (!publicReportData20List.contains(data)){
                    publicReportData20List.add(data);
                }
            }
        }
        if (!CollectionUtils.isEmpty(stammkundePoolReportDayDTOS)){
            for (StammkundePoolReportDTO stammkundePoolReportDTO : stammkundePoolReportDayDTOS) {
                PublicReportData data = getPublicReportDataD20Natural(publicReportData20List, stammkundePoolReportDTO, groupId);
                data.setDataDate(nowDate);
                data.setUserId(stammkundePoolReportDTO.getAdviserId());
                data.setUserName(stammkundePoolReportDTO.getAdviserName());
                data.setShopId(stammkundePoolReportDTO.getShopId());
                data.setDayNaturalQuantity((stammkundePoolReportDTO.getTotal().intValue()));
                data.setCreateTime(new Date());
                data.setUpdateTime(new Date());
                if (!publicReportData20List.contains(data)){
                    publicReportData20List.add(data);
                }
            }
        }
        if (!CollectionUtils.isEmpty(stammkundePoolReportMonDTOS)){
            for (StammkundePoolReportDTO stammkundePoolReportDTO : stammkundePoolReportMonDTOS) {
                PublicReportData data = getPublicReportDataD20Natural(publicReportData20List, stammkundePoolReportDTO, groupId);
                data.setDataDate(nowDate);
                data.setUserId(stammkundePoolReportDTO.getAdviserId());
                data.setUserName(stammkundePoolReportDTO.getAdviserName());
                data.setShopId(stammkundePoolReportDTO.getShopId());
                data.setMonthNaturalQuantity((stammkundePoolReportDTO.getTotal().intValue()));
                data.setCreateTime(new Date());
                data.setUpdateTime(new Date());
                if (!publicReportData20List.contains(data)){
                    publicReportData20List.add(data);
                }
            }
        }
        return publicReportData20List;
    }

    private  PublicReportData  getPublicReportDataD20Stand(List<PublicReportData> publicReportData20List,PubCluePoolReportDTO pubCluePoolReportDTO,Long groupId){
        if (CollectionUtils.isEmpty(publicReportData20List)){
            return new PublicReportData(ValhallaReportDimension.D20.getValue(),groupId);
        }
        Optional<PublicReportData> dataOptional = publicReportData20List.stream().filter(e -> pubCluePoolReportDTO.getAdviserId().equals(e.getUserId()) && pubCluePoolReportDTO.getShopId().equals(e.getShopId())).findFirst();
        if (dataOptional.isPresent()){
            return dataOptional.get();
        }
            return new PublicReportData(ValhallaReportDimension.D20.getValue(),groupId);
    }

    private  PublicReportData  getPublicReportDataD20Natural(List<PublicReportData> publicReportData20List,StammkundePoolReportDTO stammkundePoolReportMonDTO,Long groupId){
        if (CollectionUtils.isEmpty(publicReportData20List)){
            return new PublicReportData(ValhallaReportDimension.D20.getValue(),groupId);
        }
        Optional<PublicReportData> dataOptional = publicReportData20List.stream().filter(e -> stammkundePoolReportMonDTO.getAdviserId().equals(e.getUserId()) && stammkundePoolReportMonDTO.getShopId().equals(e.getShopId())).findFirst();
        if (dataOptional.isPresent()){
            return dataOptional.get();
        }
        return new PublicReportData(ValhallaReportDimension.D20.getValue(),groupId);
    }

    private  PublicReportData  getPublicReportDataD99Increase(List<PublicReportData> publicReportData20List,PublicPoolReportDTO publicPoolReportDTO,Long groupId){
        if (CollectionUtils.isEmpty(publicReportData20List)){
            return new PublicReportData(ValhallaReportDimension.D99.getValue(),groupId);
        }
        Optional<PublicReportData> dataOptional = publicReportData20List.stream().filter(e -> publicPoolReportDTO.getType().equals(e.getType()) && publicPoolReportDTO.getShopId().equals(e.getShopId())).findFirst();
        if (dataOptional.isPresent()){
            return dataOptional.get();
        }
        return new PublicReportData(ValhallaReportDimension.D99.getValue(),groupId);
    }

    private  PublicReportData  getPublicReportDataD10(List<PublicReportData> publicReportData20List,Long shopId,Long groupId){
        if (CollectionUtils.isEmpty(publicReportData20List)){
            return new PublicReportData(ValhallaReportDimension.D10.getValue(),groupId);
        }
        Optional<PublicReportData> dataOptional = publicReportData20List.stream().filter(e -> shopId.equals(e.getShopId())).findFirst();
        if (dataOptional.isPresent()){
            return dataOptional.get();
        }
        return new PublicReportData(ValhallaReportDimension.D10.getValue(),groupId);
    }




    private String generateKey(final Long groupId) {
        Assert.notNull(groupId, "groupId cannot be null");
        return String.format("%s:%s", getKeyPrefix(), groupId);
    }
}