diff --git a/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PubCluePoolMapper.java b/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PubCluePoolMapper.java index 71224bf..eda3a82 100644 --- a/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PubCluePoolMapper.java +++ b/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PubCluePoolMapper.java @@ -2,6 +2,8 @@ package cn.fw.valhalla.dao.mapper; import cn.fw.valhalla.domain.db.pub.PubCluePool; import cn.fw.valhalla.domain.dto.FollowPoolDTO; +import cn.fw.valhalla.domain.dto.PubCluePoolReportDTO; +import cn.fw.valhalla.domain.dto.PubCluePoolReportQueryDTO; import cn.fw.valhalla.domain.query.FollowPoolQueryVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; @@ -37,4 +39,11 @@ public interface PubCluePoolMapper extends BaseMapper { * @return */ Long followListCount(@Param("condition") FollowPoolQueryVO queryVO); + + /** + * 查询站岗分配 + * @param dto + * @return + */ + List countPubCluePoolList(PubCluePoolReportQueryDTO dto); } diff --git a/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PublicPoolMapper.java b/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PublicPoolMapper.java index 071eab2..e80051f 100644 --- a/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PublicPoolMapper.java +++ b/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PublicPoolMapper.java @@ -2,6 +2,8 @@ package cn.fw.valhalla.dao.mapper; import cn.fw.valhalla.domain.db.pool.PublicPool; import cn.fw.valhalla.domain.dto.PublicPoolDTO; +import cn.fw.valhalla.domain.dto.PublicPoolReportDTO; +import cn.fw.valhalla.domain.dto.PublicPoolReportQueryDTO; import cn.fw.valhalla.domain.query.PublicPoolQueryVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; @@ -41,4 +43,11 @@ public interface PublicPoolMapper extends BaseMapper { * @return */ List queryIdListByShops(@Param("shopIds") List shopIds); + + /** + * 查询公共池来源统计 + * @param dto + * @return + */ + List countPublicPoolList(PublicPoolReportQueryDTO dto); } diff --git a/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PublicReportDataMapper.java b/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PublicReportDataMapper.java new file mode 100644 index 0000000..309e00d --- /dev/null +++ b/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/PublicReportDataMapper.java @@ -0,0 +1,16 @@ +package cn.fw.valhalla.dao.mapper; + +import cn.fw.valhalla.domain.db.PublicReportData; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.springframework.stereotype.Repository; + +/** + * @author : kurisu + * @className : SecretReportHistoryMapper + * @description : 公共池报表数据(初次抽取)mapper + * @date: 2021-02-21 14:54 + */ +@Repository +public interface PublicReportDataMapper extends BaseMapper { + +} diff --git a/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/StammkundePoolMapper.java b/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/StammkundePoolMapper.java index 124abc1..b759ba4 100644 --- a/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/StammkundePoolMapper.java +++ b/fw-valhalla-dao/src/main/java/cn/fw/valhalla/dao/mapper/StammkundePoolMapper.java @@ -2,6 +2,8 @@ package cn.fw.valhalla.dao.mapper; import cn.fw.valhalla.domain.db.pool.StammkundePool; import cn.fw.valhalla.domain.dto.StammkundePoolDTO; +import cn.fw.valhalla.domain.dto.StammkundePoolReportDTO; +import cn.fw.valhalla.domain.dto.StammkundePoolReportQueryDTO; import cn.fw.valhalla.domain.query.StammkundePoolQueryVO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; @@ -32,4 +34,13 @@ public interface StammkundePoolMapper extends BaseMapper { * @return */ Long stammkundeListCount(@Param("condition") StammkundePoolQueryVO queryVO); + + + + /** + * 查询渠道到店统计 + * @param dto + * @return + */ + List countStammkundePoolList(StammkundePoolReportQueryDTO dto); } diff --git a/fw-valhalla-dao/src/main/resources/mapper/PubCluePoolMapper.xml b/fw-valhalla-dao/src/main/resources/mapper/PubCluePoolMapper.xml index d820fc5..2d2f9b2 100644 --- a/fw-valhalla-dao/src/main/resources/mapper/PubCluePoolMapper.xml +++ b/fw-valhalla-dao/src/main/resources/mapper/PubCluePoolMapper.xml @@ -180,4 +180,36 @@ + + + + + diff --git a/fw-valhalla-dao/src/main/resources/mapper/PublicPoolMapper.xml b/fw-valhalla-dao/src/main/resources/mapper/PublicPoolMapper.xml index e96d25a..0609d59 100644 --- a/fw-valhalla-dao/src/main/resources/mapper/PublicPoolMapper.xml +++ b/fw-valhalla-dao/src/main/resources/mapper/PublicPoolMapper.xml @@ -165,4 +165,27 @@ + + + + + diff --git a/fw-valhalla-dao/src/main/resources/mapper/PublicReportDataMapper.xml b/fw-valhalla-dao/src/main/resources/mapper/PublicReportDataMapper.xml new file mode 100644 index 0000000..7fb2628 --- /dev/null +++ b/fw-valhalla-dao/src/main/resources/mapper/PublicReportDataMapper.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/fw-valhalla-dao/src/main/resources/mapper/StammkundePoolMapper.xml b/fw-valhalla-dao/src/main/resources/mapper/StammkundePoolMapper.xml index a0110ff..430b33e 100644 --- a/fw-valhalla-dao/src/main/resources/mapper/StammkundePoolMapper.xml +++ b/fw-valhalla-dao/src/main/resources/mapper/StammkundePoolMapper.xml @@ -245,4 +245,38 @@ + + + + + diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/db/PublicReportData.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/db/PublicReportData.java new file mode 100644 index 0000000..b9ff12a --- /dev/null +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/db/PublicReportData.java @@ -0,0 +1,88 @@ +package cn.fw.valhalla.domain.db; + +import cn.fw.common.data.entity.BaseAuditableTimeEntity; +import lombok.Data; + +import java.time.LocalDate; + +/** + * 公共池报表数据(初次抽取)(PublicReportData)实体类 + * @author makejava + * @since 2023-05-12 16:09:45 + */ +@Data +public class PublicReportData extends BaseAuditableTimeEntity { + /** + * 数据日期 + */ + private LocalDate dataDate; + /** + * 数据维度: 10门店,20人员,99来源 + */ + private String reportDimension; + /** + * 来源类型 1:首保 2:流失 3:主动放弃 (店,来源) + */ + private Integer type; + /** + * 用户id + */ + private Long userId; + /** + * 用户名称 + */ + private String userName; + /** + * 门店id + */ + private Long shopId; + /** + * 门店名称 + */ + private String shopName; + /** + * 月初始数(店,来源) + */ + private Integer monthInitial; + /** + * 日新增(店,来源) + */ + private Integer dayIncrease; + /** + * 月新增(店,来源) + */ + private Integer monthIncrease; + /** + * 截止当前(店,来源) + */ + private Integer currentQuantity; + /** + * 日站岗分配(店,人) + */ + private Integer dayStandQuantity; + /** + * 月站岗分配(店,人) + */ + private Integer monthStandQuantity; + /** + * 日自然到店成交((店,人)) + */ + private Integer dayNaturalQuantity; + /** + * 月自然到店成交((店,人)) + */ + private Integer monthNaturalQuantity; + /** + * 集团id + */ + private Long groupId; + + public PublicReportData() { + } + + public PublicReportData(String reportDimension, Long groupId) { + this.reportDimension = reportDimension; + this.groupId = groupId; + } +} + diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/db/pool/StammkundePool.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/db/pool/StammkundePool.java index b42f80c..9e16909 100644 --- a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/db/pool/StammkundePool.java +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/db/pool/StammkundePool.java @@ -77,4 +77,8 @@ public class StammkundePool extends BaseAuditableTimeEntity sourceTypes; + + private Long groupId; + + public PubCluePoolReportQueryDTO() { + } + + public PubCluePoolReportQueryDTO(Long groupId) { + this.groupId = groupId; + } +} diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/PublicPoolReportDTO.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/PublicPoolReportDTO.java new file mode 100644 index 0000000..60d36ea --- /dev/null +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/PublicPoolReportDTO.java @@ -0,0 +1,33 @@ +package cn.fw.valhalla.domain.dto; + +import lombok.Data; + +/** + * @author : kurisu + * @className : FollowClueDTO + * @description : 查询分配聚合 + * @date: 2020-11-20 15:27 + */ +@Data +public class PublicPoolReportDTO { + + /** + * 类型 1:首保 2:流失 3:主动放弃 + */ + private Integer type; + + /** + * 门店id + */ + private Long shopId; + + /** + * 门店名称 + */ + private String shopName; + + /** + * 统计值 + */ + private Long total; +} diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/PublicPoolReportQueryDTO.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/PublicPoolReportQueryDTO.java new file mode 100644 index 0000000..af526b4 --- /dev/null +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/PublicPoolReportQueryDTO.java @@ -0,0 +1,28 @@ +package cn.fw.valhalla.domain.dto; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * @author : kurisu + * @className : FollowClueDTO + * @description : 查询分配聚合 + * @date: 2020-11-20 15:27 + */ +@Data +public class PublicPoolReportQueryDTO { + + private LocalDateTime startDate; + + private LocalDateTime endDate; + + private Long groupId; + + public PublicPoolReportQueryDTO() { + } + + public PublicPoolReportQueryDTO(Long groupId) { + this.groupId = groupId; + } +} diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/StammkundePoolReportDTO.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/StammkundePoolReportDTO.java new file mode 100644 index 0000000..17ff0ef --- /dev/null +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/StammkundePoolReportDTO.java @@ -0,0 +1,33 @@ +package cn.fw.valhalla.domain.dto; + +import lombok.Data; + +/** + * @author : kurisu + * @className : FollowClueDTO + * @description : 查询分配聚合 + * @date: 2020-11-20 15:27 + */ +@Data +public class StammkundePoolReportDTO { + + /** + * 门店id + */ + private Long shopId; + + /** + * 顾问id + */ + private Long adviserId; + + /** + * 顾问名称 + */ + private String adviserName; + + /** + * 统计值 + */ + private Long total; +} diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/StammkundePoolReportQueryDTO.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/StammkundePoolReportQueryDTO.java new file mode 100644 index 0000000..67959aa --- /dev/null +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/dto/StammkundePoolReportQueryDTO.java @@ -0,0 +1,36 @@ +package cn.fw.valhalla.domain.dto; + +import lombok.Data; + +import java.time.LocalDateTime; +import java.util.Set; + +/** + * @author : kurisu + * @className : FollowClueDTO + * @description : 查询分配聚合 + * @date: 2020-11-20 15:27 + */ +@Data +public class StammkundePoolReportQueryDTO { + + private LocalDateTime startDate; + + private LocalDateTime endDate; + + private Set sourceSets; + + /** + * 公共池来源【针对自然进店的标识】 + */ + private Boolean fromPublic; + + private Long groupId; + + public StammkundePoolReportQueryDTO() { + } + + public StammkundePoolReportQueryDTO(Long groupId) { + this.groupId = groupId; + } +} diff --git a/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/enums/ValhallaReportDimension.java b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/enums/ValhallaReportDimension.java new file mode 100644 index 0000000..5d392f8 --- /dev/null +++ b/fw-valhalla-domain/src/main/java/cn/fw/valhalla/domain/enums/ValhallaReportDimension.java @@ -0,0 +1,45 @@ +package cn.fw.valhalla.domain.enums; + +import com.fasterxml.jackson.annotation.JsonCreator; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 维度 + *

+ * create at 2020-07-14 + * + * @author zhangjj + */ +@AllArgsConstructor +public enum ValhallaReportDimension { + /** + * 门店 + */ + D10("10"), + /** + * 人员 + */ + D20("20"), + /** + * 来源 + */ + D60("60"), + ; + + /** + * 值 + */ + @Getter + private final String value; + + @JsonCreator + public static ValhallaReportDimension ofValue(final String value) { + for (final ValhallaReportDimension instance : ValhallaReportDimension.values()) { + if (instance.getValue().equals(value)) { + return instance; + } + } + return null; + } +} diff --git a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/debug/DebugController.java b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/debug/DebugController.java new file mode 100644 index 0000000..486b015 --- /dev/null +++ b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/debug/DebugController.java @@ -0,0 +1,54 @@ +package cn.fw.valhalla.controller.debug; + +import cn.fw.common.web.annotation.ControllerMethod; +import cn.fw.data.base.domain.common.Message; +import cn.fw.security.auth.client.annotation.Authorization; +import cn.fw.security.auth.client.annotation.IgnoreAuth; +import cn.fw.security.auth.client.enums.AuthType; +import cn.fw.valhalla.common.utils.DateUtil; +import cn.fw.valhalla.service.report.PublicReportBizService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDate; +import java.util.Date; +import java.util.Objects; + +import static cn.fw.common.web.util.ResultBuilder.success; + +/** + * @author : kurisu + * @className : DebugController + * @description : 调试接口 + * @date: 2020-10-22 11:06 + */ +@Slf4j +@RestController +@RequiredArgsConstructor +@IgnoreAuth +@Authorization(AuthType.APP) +@Validated +@RequestMapping("/valhalla/debug") +public class DebugController { + private final PublicReportBizService publicReportBizService; + + @GetMapping("/run/publicReportData") + @ControllerMethod("公共池报表数据准备") + public Message publicReportData(@RequestParam(required = false) Long groupId, + @RequestParam(required = false)Date date) { + if (Objects.isNull(groupId)) { + groupId = 2L; + } + if (Objects.isNull(date)) { + publicReportBizService.extracting(LocalDate.now().minusDays(1),groupId); + } else { + publicReportBizService.extracting(DateUtil.date2LocalDate(date),groupId); + } + return success(); + } +} diff --git a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java index 9403ce2..a15b71a 100644 --- a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java +++ b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/task/ReportPrepareTask.java @@ -31,20 +31,18 @@ public class ReportPrepareTask { /** * 保持率进站率报表数据准备 */ - @Scheduled(cron = "0 0 0 ? * * ") + @Scheduled(cron = "30 0 0 ? * * ") public void extractingData() { -// CompletableFuture.runAsync(() -> retentionRatioBizService.extracting(DateUtil.startDate(new Date())), ThreadPoolUtil.getInstance().getExecutor()); retentionRatioBizService.extracting(DateUtil.startDate(new Date())); } /** - * 公共池报表数据准备 + * 公共池报表数据准备,0点30分抽取 */ @Scheduled(cron = "0 30 0 ? * * ") public void extractingPublicData() { final List groupList = oopService.allGroup(); - final LocalDate now = LocalDate.now(); - + final LocalDate now = LocalDate.now().minusDays(1); for (GroupDTO group : groupList) { try { publicReportBizService.extracting(now, group.getId()); diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/component/producer/CustomerChangeProducer.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/component/producer/CustomerChangeProducer.java index 3d93669..54e7e19 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/component/producer/CustomerChangeProducer.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/component/producer/CustomerChangeProducer.java @@ -1,12 +1,17 @@ package cn.fw.valhalla.component.producer; +import cn.fw.valhalla.domain.vo.customer.CustomerDetailVO; import cn.fw.valhalla.sdk.result.CustomerInfoDto; +import cn.fw.valhalla.service.bus.cust.CustomerBizService; import lombok.extern.slf4j.Slf4j; import org.apache.rocketmq.spring.core.RocketMQTemplate; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMapping; +import java.util.Objects; + /** * @author kurisu */ @@ -15,11 +20,19 @@ import org.springframework.web.bind.annotation.RequestMapping; public class CustomerChangeProducer { @Autowired private RocketMQTemplate rocketMQTemplate; + @Autowired + private CustomerBizService customerBizService; @RequestMapping(value = "send") public void send(CustomerInfoDto customerInfoDto) { try { log.info("售后保有客信息变更mq: body:[{}]", customerInfoDto); + if (Objects.isNull(customerInfoDto.getGroupId())) { + log.warn("售后保有客信息变更mq集团id为空"); + return; + } + CustomerDetailVO detailByVin = customerBizService.getDetailByVin(customerInfoDto.getFrameNo(), customerInfoDto.getGroupId()); + BeanUtils.copyProperties(detailByVin, customerInfoDto); rocketMQTemplate.syncSend(CustomerInfoDto.TOPIC + ":*", customerInfoDto); } catch (Exception e) { e.printStackTrace(); diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/component/producer/RenewalSwitchProducer.kt b/fw-valhalla-service/src/main/java/cn/fw/valhalla/component/producer/RenewalSwitchProducer.kt index bfafab3..5b6f656 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/component/producer/RenewalSwitchProducer.kt +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/component/producer/RenewalSwitchProducer.kt @@ -4,7 +4,6 @@ import cn.fw.valhalla.common.utils.DateUtil import cn.fw.valhalla.domain.enums.FollowTypeEnum import cn.fw.valhalla.domain.enums.SettingTypeEnum import cn.fw.valhalla.domain.vo.setting.SettingVO -import cn.fw.valhalla.sdk.result.CustomerDistributedMQ import cn.fw.valhalla.sdk.result.RenewalSwitchMQ import cn.fw.valhalla.service.bus.setting.SettingBizService import cn.fw.valhalla.service.bus.setting.strategy.SettingStrategy @@ -51,7 +50,7 @@ class RenewalSwitchProducer( log.info("发送续保跟进切换mq消息。vin:{}", vin) try { val mq = RenewalSwitchMQ(FollowTypeEnum.IR.value, vin, DateUtil.localDate2Date(deadline), groupId) - rocketMQTemplate.syncSend(CustomerDistributedMQ.TOPIC + ":*", mq) + rocketMQTemplate.syncSend(RenewalSwitchMQ.TOPIC + ":*", mq) } catch (e: Exception) { log.info("发送保有客分配结束mq消息失败!", e) } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/CustomerChangeBizService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/CustomerChangeBizService.java index 215f892..f78a1e9 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/CustomerChangeBizService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/cust/CustomerChangeBizService.java @@ -54,6 +54,7 @@ import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import static cn.fw.common.businessvalidator.Validator.BV; @@ -397,9 +398,8 @@ public class CustomerChangeBizService extends AbstractCustomerService { if (Objects.isNull(customer.getAdviserId()) && Objects.isNull(customer.getShopId())) { publicPoolService.removeByCustomerId(customer.getId(), customer.getGroupId()); - create(customer, adviserId, shopId); + create(customer, adviserId, shopId, r -> r.setFromPublic(Boolean.TRUE)); } - return updated; } @@ -421,6 +421,10 @@ public class CustomerChangeBizService extends AbstractCustomerService { private void create(Customer customer, Long adviserId, Long shopId) { + create(customer, adviserId, shopId, null); + } + + private void create(Customer customer, Long adviserId, Long shopId, Consumer cs) { StammkundePool stammkundePool = createSimpleInfo(customer, adviserId); stammkundePool.setSources(StammkundeSourcesEnum.NATURAL); stammkundePool.setShopId(shopId); @@ -428,6 +432,9 @@ public class CustomerChangeBizService extends AbstractCustomerService { stammkundePool.setAktiv(Boolean.TRUE); stammkundePool.setActivationTime(new Date()); stammkundePool.setCreateTime(new Date()); + if (cs != null) { + cs.accept(stammkundePool); + } stammkundePoolService.save(stammkundePool); } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PubCluePoolService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PubCluePoolService.java index 71a172b..1d4d465 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PubCluePoolService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PubCluePoolService.java @@ -2,6 +2,8 @@ package cn.fw.valhalla.service.data; import cn.fw.valhalla.domain.db.pub.PubCluePool; import cn.fw.valhalla.domain.dto.FollowPoolDTO; +import cn.fw.valhalla.domain.dto.PubCluePoolReportDTO; +import cn.fw.valhalla.domain.dto.PubCluePoolReportQueryDTO; import cn.fw.valhalla.domain.query.FollowPoolQueryVO; import com.baomidou.mybatisplus.extension.service.IService; @@ -20,4 +22,11 @@ public interface PubCluePoolService extends IService { List followList(FollowPoolQueryVO queryVO); long followListCount(FollowPoolQueryVO queryVO); + + /** + * 查询站岗分配 + * @param dto + * @return + */ + List countPubCluePoolList(PubCluePoolReportQueryDTO dto); } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PublicPoolService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PublicPoolService.java index 5d7727f..f52cfa6 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PublicPoolService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PublicPoolService.java @@ -2,6 +2,8 @@ package cn.fw.valhalla.service.data; import cn.fw.valhalla.domain.db.pool.PublicPool; import cn.fw.valhalla.domain.dto.PublicPoolDTO; +import cn.fw.valhalla.domain.dto.PublicPoolReportDTO; +import cn.fw.valhalla.domain.dto.PublicPoolReportQueryDTO; import cn.fw.valhalla.domain.query.PublicPoolQueryVO; import com.baomidou.mybatisplus.extension.service.IService; import org.springframework.transaction.annotation.Transactional; @@ -74,4 +76,11 @@ public interface PublicPoolService extends IService { * @return */ List queryIdListByShops(List shopIds); + + /** + * 查询公共池来源统计 + * @param dto + * @return + */ + List countPublicPoolList(PublicPoolReportQueryDTO dto); } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PublicReportDataService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PublicReportDataService.java new file mode 100644 index 0000000..90b60c1 --- /dev/null +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/PublicReportDataService.java @@ -0,0 +1,14 @@ +package cn.fw.valhalla.service.data; + +import cn.fw.valhalla.domain.db.PublicReportData; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + * @author : kurisu + * @className : PublicReportDataService + * @description : 公共池报表数据(初次抽取) + * @date: 2021-02-21 14:58 + */ +public interface PublicReportDataService extends IService { + +} diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/StammkundePoolService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/StammkundePoolService.java index 682dccc..f78442d 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/StammkundePoolService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/StammkundePoolService.java @@ -3,6 +3,8 @@ package cn.fw.valhalla.service.data; import cn.fw.valhalla.domain.db.pool.StammkundePool; import cn.fw.valhalla.domain.dto.StammkundeDto; import cn.fw.valhalla.domain.dto.StammkundePoolDTO; +import cn.fw.valhalla.domain.dto.StammkundePoolReportDTO; +import cn.fw.valhalla.domain.dto.StammkundePoolReportQueryDTO; import cn.fw.valhalla.domain.enums.DefeatReasonEnum; import cn.fw.valhalla.domain.query.StammkundePoolQueryVO; import com.baomidou.mybatisplus.extension.service.IService; @@ -96,4 +98,11 @@ public interface StammkundePoolService extends IService { * @param groupId */ void removeByCustomerId(@NonNull Long customerId, @NonNull Long groupId); + + /** + * 查询渠道到店统计 + * @param dto + * @return + */ + List countStammkundePoolList(StammkundePoolReportQueryDTO dto); } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PubCluePoolServiceImpl.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PubCluePoolServiceImpl.java index 70d3693..35a7a0c 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PubCluePoolServiceImpl.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PubCluePoolServiceImpl.java @@ -3,6 +3,8 @@ package cn.fw.valhalla.service.data.impl; import cn.fw.valhalla.dao.mapper.PubCluePoolMapper; import cn.fw.valhalla.domain.db.pub.PubCluePool; import cn.fw.valhalla.domain.dto.FollowPoolDTO; +import cn.fw.valhalla.domain.dto.PubCluePoolReportDTO; +import cn.fw.valhalla.domain.dto.PubCluePoolReportQueryDTO; import cn.fw.valhalla.domain.query.FollowPoolQueryVO; import cn.fw.valhalla.service.data.PubCluePoolService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -10,6 +12,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -37,4 +40,14 @@ public class PubCluePoolServiceImpl extends ServiceImpl countPubCluePoolList(PubCluePoolReportQueryDTO dto){ + return Optional.ofNullable(getBaseMapper().countPubCluePoolList(dto)).orElse(Collections.emptyList()); + } } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PublicPoolServiceImpl.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PublicPoolServiceImpl.java index b9b27e2..bc304e0 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PublicPoolServiceImpl.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PublicPoolServiceImpl.java @@ -3,6 +3,8 @@ package cn.fw.valhalla.service.data.impl; import cn.fw.valhalla.dao.mapper.PublicPoolMapper; import cn.fw.valhalla.domain.db.pool.PublicPool; import cn.fw.valhalla.domain.dto.PublicPoolDTO; +import cn.fw.valhalla.domain.dto.PublicPoolReportDTO; +import cn.fw.valhalla.domain.dto.PublicPoolReportQueryDTO; import cn.fw.valhalla.domain.query.PublicPoolQueryVO; import cn.fw.valhalla.service.data.PublicPoolService; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -87,4 +89,9 @@ public class PublicPoolServiceImpl extends ServiceImpl countPublicPoolList(PublicPoolReportQueryDTO dto) { + return Optional.ofNullable(this.getBaseMapper().countPublicPoolList(dto)).orElse(Collections.emptyList()); + } } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PublicReportDataServiceImpl.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PublicReportDataServiceImpl.java new file mode 100644 index 0000000..8bb2c79 --- /dev/null +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/PublicReportDataServiceImpl.java @@ -0,0 +1,20 @@ +package cn.fw.valhalla.service.data.impl; + +import cn.fw.valhalla.dao.mapper.PublicReportDataMapper; +import cn.fw.valhalla.domain.db.PublicReportData; +import cn.fw.valhalla.service.data.PublicReportDataService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * @author : kurisu + * @className : PublicReportDataServiceImpl + * @description : 公共池报表数据(初次抽取) + * @date: 2021-02-21 14:58 + */ +@Slf4j +@Service +public class PublicReportDataServiceImpl extends ServiceImpl implements PublicReportDataService { + +} diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/StammkundePoolServiceImpl.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/StammkundePoolServiceImpl.java index 99b130d..e69e428 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/StammkundePoolServiceImpl.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/data/impl/StammkundePoolServiceImpl.java @@ -4,6 +4,8 @@ import cn.fw.valhalla.dao.mapper.StammkundePoolMapper; import cn.fw.valhalla.domain.db.pool.StammkundePool; import cn.fw.valhalla.domain.dto.StammkundeDto; import cn.fw.valhalla.domain.dto.StammkundePoolDTO; +import cn.fw.valhalla.domain.dto.StammkundePoolReportDTO; +import cn.fw.valhalla.domain.dto.StammkundePoolReportQueryDTO; import cn.fw.valhalla.domain.enums.DefeatReasonEnum; import cn.fw.valhalla.domain.enums.StammkundeStatusEnum; import cn.fw.valhalla.domain.query.StammkundePoolQueryVO; @@ -123,4 +125,13 @@ public class StammkundePoolServiceImpl extends ServiceImpl countStammkundePoolList(StammkundePoolReportQueryDTO dto){ + return Optional.ofNullable(getBaseMapper().countStammkundePoolList(dto)).orElse(Collections.emptyList()); + } } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java index 3e493fc..f048d8d 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java @@ -1,11 +1,33 @@ 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; /** * 公共池报表数据服务 @@ -20,6 +42,15 @@ import java.time.LocalDate; @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; /** * 抽取集团公共池数据 @@ -28,8 +59,529 @@ public class PublicReportBizService { * @param groupId 集团id */ @Transactional(rollbackFor = Exception.class) - public void extracting(LocalDate nowDate, Long groupId) { + public void extracting(final LocalDate nowDate, final Long groupId) { log.info("开始抽取公共池报表数据,日期:{} 集团:{}", nowDate, groupId); - // TODO: 2023/5/4 完成方法 + final String lockKey = generateKey(groupId); + RLock lock = (RLock) distributedLocker.lock(lockKey); + if (lock == null || !lock.isLocked()) { + return; + } + try { + /** + * 1.准备数据 + */ + HashSet sourceTypes = Sets.newHashSet(PubStandType.PUB.getValue(), PubStandType.ACTIVITY.getValue()); + HashSet 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 cluePoolDayList = getCluePoolTimeList(groupId, sourceTypes, startDayDateTime, endDayDateTime); + /** + * 1.2 查询月站岗分配(人) + */ + List cluePoolMonList = getCluePoolTimeList(groupId, sourceTypes,startMonDateTime, endDayDateTime); + /** + * 1.3 查询日自然到店成交(人) + */ + List stammkundePoolReportDayList = getStammkundePoolReportTimeList(groupId, startDayDateTime, endDayDateTime, sourceSets); + /** + * 1.4 查询月自然到店成交(人) + */ + List stammkundePoolReportMonList = getStammkundePoolReportTimeList(groupId, startMonDateTime,endDayDateTime, sourceSets); + /** + * 1.5 查询日新增(来源) + */ + List poolReportDayDTOList = getPoolReportList(groupId, startDayDateTime, endDayDateTime); + /** + * 1.6 查询月新增(来源) + */ + List poolReportMonDTOList = getPoolReportList(groupId, startMonDateTime, endDayDateTime); + /** + * 1.7 截止当前(来源) + */ + List poolReportCutDTOList = getPoolReportList(groupId,null, endDayDateTime); + + /** + * 1.8 月初始数(来源) + */ + List poolReportMonFirstDTOList = getPoolReportMonFirstDTOList(nowDate,startMonDate, groupId, startMonDateTimeOver); + /** + * 2.处理数据 + */ + /** + * 2.1 人员维度 + */ + List publicReportDataD20List = extractedD20(nowDate, groupId, cluePoolDayList, cluePoolMonList, stammkundePoolReportDayList, stammkundePoolReportMonList); + /** + * 2.2 来源维度 + */ + List publicReportDataD99List = extractedD99(nowDate, groupId, poolReportDayDTOList, poolReportMonDTOList, poolReportCutDTOList, poolReportMonFirstDTOList); + /** + * 2.3 门店维度 = 来源 + 人员 + */ + List 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 getPoolReportMonFirstDTOList(LocalDate nowDate,LocalDate startMonDate, Long groupId, LocalDateTime startMonDateTimeOver) { + List poolReportMonFirstDTOList = new ArrayList<>(); + if (nowDate.equals(startMonDate)) { + //如果是月初一就去查询小于月初一的数据统计 + poolReportMonFirstDTOList = getPoolReportList(groupId,null, startMonDateTimeOver); + }else { + //不是1号的数据直接从上次抽取的数据中查询月初一的数据 + List reportDataList = publicReportDataService.list(Wrappers.lambdaQuery() + .eq(PublicReportData::getReportDimension, ValhallaReportDimension.D60.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 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 getStammkundePoolReportTimeList(Long groupId, LocalDateTime startDayDateTime, LocalDateTime endDayDateTime, HashSet 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 getCluePoolTimeList(Long groupId, HashSet 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.lambdaUpdate() + .eq(PublicReportData::getDataDate, nowDate) + ); + } + + /** + * 3.2 存储新数据 + * @param publicReportDataD20List 人员的 + * @param publicReportDataD99List 来源的 + * @param publicReportDataD10List 店的 + */ + private void save(List publicReportDataD20List, List publicReportDataD99List, List 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 extractedD10(LocalDate nowDate, Long groupId, List publicReportDataD20List, List publicReportDataD99List) { + List publicReportData10List = new ArrayList<>(); + if (!CollectionUtils.isEmpty(publicReportDataD20List)){ + Map> 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> 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 extractedD99(LocalDate nowDate, Long groupId, + List poolReportDayDTOList, + List poolReportMonDTOList, + List poolReportCutDTOList, + List poolReportMonFirstDTOList) { + List 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 extractedD20(LocalDate nowDate, Long groupId, + List cluePoolDayList, + List cluePoolMonList, + List stammkundePoolReportDayDTOS, + List stammkundePoolReportMonDTOS) { + List 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 publicReportData20List,PubCluePoolReportDTO pubCluePoolReportDTO,Long groupId){ + if (CollectionUtils.isEmpty(publicReportData20List)){ + return new PublicReportData(ValhallaReportDimension.D20.getValue(),groupId); + } + Optional 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 publicReportData20List,StammkundePoolReportDTO stammkundePoolReportMonDTO,Long groupId){ + if (CollectionUtils.isEmpty(publicReportData20List)){ + return new PublicReportData(ValhallaReportDimension.D20.getValue(),groupId); + } + Optional 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 publicReportData20List,PublicPoolReportDTO publicPoolReportDTO,Long groupId){ + if (CollectionUtils.isEmpty(publicReportData20List)){ + return new PublicReportData(ValhallaReportDimension.D60.getValue(),groupId); + } + Optional 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.D60.getValue(),groupId); + } + + private PublicReportData getPublicReportDataD10(List publicReportData20List,Long shopId,Long groupId){ + if (CollectionUtils.isEmpty(publicReportData20List)){ + return new PublicReportData(ValhallaReportDimension.D10.getValue(),groupId); + } + Optional 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); } }