diff --git a/doc/public_report/sql.sql b/doc/public_report/sql.sql new file mode 100644 index 0000000..174093c --- /dev/null +++ b/doc/public_report/sql.sql @@ -0,0 +1,31 @@ +create table public_report_data +( + id bigint auto_increment, + data_date date not null, + user_id bigint not null comment '用户id', + user_name varchar(64) null comment '用户名称', + shop_id bigint not null comment '门店id', + shop_name varchar(256) null comment '门店名称', + month_initial int default 0 null comment '每月初始数', + day_increase int default 0 null comment '日新增', + month_increase int default 0 null comment '月新增', + current_quantity int default 0 null, + day_stand_quantity int default 0 null, + month_stand_quantity int default 0 null, + day_natural_quantity int default 0 null, + month_natural_quantity int default 0 null, + group_id bigint not null comment '集团id', + create_time datetime null comment '创建日期', + update_time datetime null comment '更新日期', + constraint public_report_data_pk + primary key (id) +) + comment '公共池报表数据'; + +create index public_report_data_shop_id_index + on public_report_data (shop_id); + +create index public_report_data_user_id_index + on public_report_data (user_id); + + diff --git a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/CommonController.java b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/CommonController.java index 4a6b06b..239866e 100644 --- a/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/CommonController.java +++ b/fw-valhalla-server/src/main/java/cn/fw/valhalla/controller/app/CommonController.java @@ -9,10 +9,10 @@ import cn.fw.valhalla.common.utils.DateUtil; import cn.fw.valhalla.domain.vo.PostUserVO; import cn.fw.valhalla.service.bus.CommonService; import cn.fw.valhalla.service.bus.CustomerImportBizService; -import cn.fw.valhalla.service.bus.CustomerRetentionRatioBizService; import cn.fw.valhalla.service.bus.LeaveNeedDoBizService; import cn.fw.valhalla.service.bus.follow.FollowBizService; import cn.fw.valhalla.service.bus.pub.PubStandBizService; +import cn.fw.valhalla.service.report.CustomerRetentionRatioBizService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; 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 1d58ae7..9403ce2 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 @@ -1,16 +1,18 @@ package cn.fw.valhalla.controller.task; import cn.fw.valhalla.common.utils.DateUtil; -import cn.fw.valhalla.common.utils.ThreadPoolUtil; -import cn.fw.valhalla.service.bus.CustomerRetentionRatioBizService; +import cn.fw.valhalla.rpc.oop.OopService; +import cn.fw.valhalla.rpc.oop.dto.GroupDTO; +import cn.fw.valhalla.service.report.CustomerRetentionRatioBizService; +import cn.fw.valhalla.service.report.PublicReportBizService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDate; import java.util.Date; -import java.util.concurrent.CompletableFuture; +import java.util.List; /** * @author : kurisu @@ -22,11 +24,33 @@ import java.util.concurrent.CompletableFuture; @Component @Slf4j public class ReportPrepareTask { + private final OopService oopService; private final CustomerRetentionRatioBizService retentionRatioBizService; + private final PublicReportBizService publicReportBizService; + /** + * 保持率进站率报表数据准备 + */ @Scheduled(cron = "0 0 0 ? * * ") - @Transactional(rollbackFor = Exception.class) public void extractingData() { - CompletableFuture.runAsync(() -> retentionRatioBizService.extracting(DateUtil.startDate(new Date())), ThreadPoolUtil.getInstance().getExecutor()); +// CompletableFuture.runAsync(() -> retentionRatioBizService.extracting(DateUtil.startDate(new Date())), ThreadPoolUtil.getInstance().getExecutor()); + retentionRatioBizService.extracting(DateUtil.startDate(new Date())); + } + + /** + * 公共池报表数据准备 + */ + @Scheduled(cron = "0 30 0 ? * * ") + public void extractingPublicData() { + final List groupList = oopService.allGroup(); + final LocalDate now = LocalDate.now(); + + for (GroupDTO group : groupList) { + try { + publicReportBizService.extracting(now, group.getId()); + } catch (Exception e) { + log.warn("准备公共池报表数据失败[groupId: {} data: {}]", group.getId(), now, e); + } + } } } diff --git a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/CustomerRetentionRatioBizService.java b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/CustomerRetentionRatioBizService.java index 2f8da89..0c1e6cf 100644 --- a/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/bus/CustomerRetentionRatioBizService.java +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/CustomerRetentionRatioBizService.java @@ -1,4 +1,4 @@ -package cn.fw.valhalla.service.bus; +package cn.fw.valhalla.service.report; import cn.fw.valhalla.common.constant.RoleCode; import cn.fw.valhalla.common.utils.DateUtil; 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 new file mode 100644 index 0000000..3e493fc --- /dev/null +++ b/fw-valhalla-service/src/main/java/cn/fw/valhalla/service/report/PublicReportBizService.java @@ -0,0 +1,35 @@ +package cn.fw.valhalla.service.report; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDate; + +/** + * 公共池报表数据服务 + * + * @author : kurisu + * @version : 2.0 + * @className : PublicReportBizService + * @description : 公共池报表数据服务 + * @date : 2023-05-04 15:07 + */ +@Service +@Slf4j +@RequiredArgsConstructor +public class PublicReportBizService { + + /** + * 抽取集团公共池数据 + * + * @param nowDate 日期 + * @param groupId 集团id + */ + @Transactional(rollbackFor = Exception.class) + public void extracting(LocalDate nowDate, Long groupId) { + log.info("开始抽取公共池报表数据,日期:{} 集团:{}", nowDate, groupId); + // TODO: 2023/5/4 完成方法 + } +}