From 60c455b39a7080c83b54c02205dadf3467d97298 Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Fri, 10 Dec 2021 15:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=20=E5=BF=97?= =?UTF-8?q?=E6=84=BF=E8=80=85=E6=8E=AA=E6=96=BD=E6=B8=85=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../result/DemandServiceCountResultDTO.java | 15 ++ .../epmet/controller/DemandController.java | 38 ++++ .../dao/heart/IcUserDemandServiceDao.java | 44 +++++ .../com/epmet/dao/heart/VolunteerInfoDao.java | 33 ++++ .../stats/FactVolunteerServiceDailyDao.java | 42 ++++ .../main/java/com/epmet/dao/user/UserDao.java | 2 + .../heart/IcUserDemandServiceEntity.java | 75 +++++++ .../entity/heart/VolunteerInfoEntity.java | 71 +++++++ .../FactVolunteerServiceDailyEntity.java | 86 ++++++++ .../java/com/epmet/service/DemandService.java | 20 ++ .../service/heart/HeartDemandService.java | 15 ++ .../service/heart/HeartVolunteerService.java | 15 ++ .../heart/impl/HeartDemandServiceImpl.java | 40 ++++ .../heart/impl/HeartVolunteerServiceImpl.java | 40 ++++ .../epmet/service/impl/DemandServiceImpl.java | 184 ++++++++++++++++++ .../service/stats/DemandStatsService.java | 18 ++ .../stats/impl/DemandStatsServiceImpl.java | 36 ++++ .../com/epmet/service/user/UserService.java | 2 + .../service/user/impl/UserServiceImpl.java | 4 + ...0.0.26__create_volunteer_service_daily.sql | 21 ++ .../mapper/heart/IcUserDemandServiceDao.xml | 33 ++++ .../mapper/heart/VolunteerInfoDao.xml | 23 +++ .../stats/FactVolunteerServiceDailyDao.xml | 37 ++++ .../main/resources/mapper/user/UserDao.xml | 13 ++ 24 files changed, 907 insertions(+) create mode 100644 epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/heart/result/DemandServiceCountResultDTO.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemandController.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/heart/IcUserDemandServiceDao.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/heart/VolunteerInfoDao.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactVolunteerServiceDailyDao.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/heart/IcUserDemandServiceEntity.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/heart/VolunteerInfoEntity.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/FactVolunteerServiceDailyEntity.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/DemandService.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartDemandService.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartVolunteerService.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartDemandServiceImpl.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DemandServiceImpl.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DemandStatsService.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DemandStatsServiceImpl.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.26__create_volunteer_service_daily.sql create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/heart/IcUserDemandServiceDao.xml create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/heart/VolunteerInfoDao.xml create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactVolunteerServiceDailyDao.xml diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/heart/result/DemandServiceCountResultDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/heart/result/DemandServiceCountResultDTO.java new file mode 100644 index 0000000000..57cc894ae4 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/heart/result/DemandServiceCountResultDTO.java @@ -0,0 +1,15 @@ +package com.epmet.dto.heart.result; + +import lombok.Data; + +/** + * @Description 描述 + * @Author wangxianzhang + * @Date 2021/12/8 4:39 下午 + * @Version 1.0 + */ +@Data +public class DemandServiceCountResultDTO { + private String serverId; + private String serviceType; +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemandController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemandController.java new file mode 100644 index 0000000000..cd77d2b25a --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemandController.java @@ -0,0 +1,38 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.utils.Result; +import com.epmet.service.DemandService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * @Description 描述 + * @Author wangxianzhang + * @Date 2021/12/8 10:44 上午 + * @Version 1.0 + */ +@RestController +@RequestMapping("demand") +public class DemandController { + + @Autowired + private DemandService demandStatsService; + + /** + * wangxianzhang + * + * 计算客户下志愿者服务相关数据 + * + * @param customerId 客户ID,可以为空,为空则计算所有客户 + * @return + */ + @PostMapping("volunteer/daily") + public Result statsVolunteerDemandServicesDaily(@RequestParam(value = "customer-id", required = false) String customerId) { + + demandStatsService.statsVolunteerDemandServicesDaily(customerId); + + return new Result(); + } + + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/heart/IcUserDemandServiceDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/heart/IcUserDemandServiceDao.java new file mode 100644 index 0000000000..602c04da5e --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/heart/IcUserDemandServiceDao.java @@ -0,0 +1,44 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.heart; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.dto.heart.result.DemandServiceCountResultDTO; +import com.epmet.entity.heart.IcUserDemandServiceEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; + +/** + * 居民需求服务记录表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-11-19 + */ +@Mapper +public interface IcUserDemandServiceDao extends BaseDao { + + /** + * 需求服务次数查询 + * @param customerId 客户id + * @param serviceType 服务者类型 + */ + List listDemandServiceCountPage(@Param("customerId") String customerId, @Param("endTime") Date endTime, @Param("serviceType") String serviceType); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/heart/VolunteerInfoDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/heart/VolunteerInfoDao.java new file mode 100644 index 0000000000..11b5aad534 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/heart/VolunteerInfoDao.java @@ -0,0 +1,33 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.heart; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.heart.VolunteerInfoEntity; +import org.apache.ibatis.annotations.Mapper; + +/** + * 志愿者信息 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-12-08 + */ +@Mapper +public interface VolunteerInfoDao extends BaseDao { + +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactVolunteerServiceDailyDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactVolunteerServiceDailyDao.java new file mode 100644 index 0000000000..605364c820 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactVolunteerServiceDailyDao.java @@ -0,0 +1,42 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.dao.stats; + +import com.epmet.commons.mybatis.dao.BaseDao; +import com.epmet.entity.stats.FactVolunteerServiceDailyEntity; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 志愿者服务情况统计 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-12-08 + */ +@Mapper +public interface FactVolunteerServiceDailyDao extends BaseDao { + + /** + * 删除指定客户,指定dateId的志愿者服务统计记录 + * @param customerIds + * @param dateDimId + */ + void clearVolunteerDemandServiceDailyStats(@Param("customerIds") List customerIds, @Param("dateDimId") String dateDimId); +} \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/UserDao.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/UserDao.java index 2c8f46ea9b..584bfdf64c 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/UserDao.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/user/UserDao.java @@ -264,5 +264,7 @@ public interface UserDao { List getPatrolRecordList(MidPatrolFormDTO formDTO); List getPatrolDetailList(MidPatrolFormDTO formDTO); + + List filterUserIds(@Param("userIds") List userIds, @Param("roleKey") String roleKey); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/heart/IcUserDemandServiceEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/heart/IcUserDemandServiceEntity.java new file mode 100644 index 0000000000..002b1db875 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/heart/IcUserDemandServiceEntity.java @@ -0,0 +1,75 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.heart; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 居民需求服务记录表 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-11-19 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("ic_user_demand_service") +public class IcUserDemandServiceEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * 需求id + */ + private String demandRecId; + + /** + * 服务方类型:志愿者:volunteer;社会组织:social_org;社区自组织:community_org;区域党建单位:party_unit; + */ + private String serviceType; + + /** + * 志愿者:居民端爱心互助的志愿者userId; + */ + private String serverId; + + /** + * 实际服务开始时间 + */ + private Date serviceStartTime; + + /** + * 实际服务结束时间 + */ + private Date serviceEndTime; + + /** + * 完成情况 + */ + private String finishDesc; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/heart/VolunteerInfoEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/heart/VolunteerInfoEntity.java new file mode 100644 index 0000000000..60f41bd0fa --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/heart/VolunteerInfoEntity.java @@ -0,0 +1,71 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.heart; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 志愿者信息 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-12-08 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("volunteer_info") +public class VolunteerInfoEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 用户id + */ + private String userId; + + /** + * 客户id + */ + private String customerId; + + /** + * 志愿者自我介绍 + */ + private String volunteerIntroduce; + + /** + * 志愿者签名 + */ + private String volunteerSignature; + + /** + * 网格id + */ + private String gridId; + + /** + * 网格名称 + */ + private String gridName; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/FactVolunteerServiceDailyEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/FactVolunteerServiceDailyEntity.java new file mode 100644 index 0000000000..f2b473bfe9 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/FactVolunteerServiceDailyEntity.java @@ -0,0 +1,86 @@ +/** + * Copyright 2018 人人开源 https://www.renren.io + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + *

+ * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.epmet.entity.stats; + +import com.baomidou.mybatisplus.annotation.TableName; + +import com.epmet.commons.mybatis.entity.BaseEpmetEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.Date; + +/** + * 志愿者服务情况统计 + * + * @author generator generator@elink-cn.com + * @since v1.0.0 2021-12-08 + */ +@Data +@EqualsAndHashCode(callSuper=false) +@TableName("fact_volunteer_service_daily") +public class FactVolunteerServiceDailyEntity extends BaseEpmetEntity { + + private static final long serialVersionUID = 1L; + + /** + * 客户id + */ + private String customerId; + + /** + * yyyyMMdd + */ + private String dateId; + + /** + * yyyyMM + */ + private String monthId; + + /** + * 截止到当前dateId,当前客户下,共有多少个爱心互助的志愿者 + */ + private Integer volunteerTotal; + + /** + * 截止到当前dateId,当前客户下,XX个爱心互助志愿者中,党员有多少个 + */ + private Integer partyTotal; + + /** + * 截止到当前dateId,当前客户下,XX个爱心互助志愿者中,居民有多少个 + */ + private Integer resiTotal; + + /** + * 服务总次数 + */ + private Integer serviceTotal; + + /** + * 党员服务总次数 + */ + private Integer partyServiceTotal; + + /** + * 居民服务总次数 + */ + private Integer resiServiceTotal; + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/DemandService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/DemandService.java new file mode 100644 index 0000000000..a5baf1a613 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/DemandService.java @@ -0,0 +1,20 @@ +package com.epmet.service; + +/** + * @Description 需求service + * @Author wangxianzhang + * @Date 2021/12/8 12:14 下午 + * @Version 1.0 + */ +public interface DemandService { + + /** + * wangxianzhang + * + * 按日统计 + * + * @param customerId 客户ID,可为空,为空计算所有 + */ + void statsVolunteerDemandServicesDaily(String customerId); + +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartDemandService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartDemandService.java new file mode 100644 index 0000000000..1a106fa881 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartDemandService.java @@ -0,0 +1,15 @@ +package com.epmet.service.heart; + +import com.epmet.dto.heart.result.DemandServiceCountResultDTO; + +import java.util.Date; +import java.util.List; + +/** + *@Description 爱心互助,需求service + *@Author wangxianzhang + *@Date 2021/12/8 + */ +public interface HeartDemandService { + List listDemandServiceCountPage(String customerId, Date endTime, int serviceCountPageNo, int serviceCountPageSize); +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartVolunteerService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartVolunteerService.java new file mode 100644 index 0000000000..abccaae1e6 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/HeartVolunteerService.java @@ -0,0 +1,15 @@ +package com.epmet.service.heart; + +import com.epmet.entity.heart.VolunteerInfoEntity; + +import java.util.Date; +import java.util.List; + +/** + *@Description heart 志愿者service + *@Author wangxianzhang + *@Date 2021/12/8 + */ +public interface HeartVolunteerService { + List listVolunteersPage(String customerId, Date endCreateTime, Integer pageNum, Integer pageSize); +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartDemandServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartDemandServiceImpl.java new file mode 100644 index 0000000000..a4192fcd30 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartDemandServiceImpl.java @@ -0,0 +1,40 @@ +package com.epmet.service.heart.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.epmet.commons.dynamic.datasource.annotation.DataSource; +import com.epmet.constant.DataSourceConstant; +import com.epmet.dao.heart.IcUserDemandServiceDao; +import com.epmet.dto.heart.result.DemandServiceCountResultDTO; +import com.epmet.service.heart.HeartDemandService; +import com.github.pagehelper.ISelect; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * @Description 爱心互助,需求service + * @Author wangxianzhang + * @Date 2021/12/8 12:33 下午 + * @Version 1.0 + */ +@Service +@DataSource(DataSourceConstant.EPMET_HEART) +public class HeartDemandServiceImpl implements HeartDemandService { + + @Autowired + private IcUserDemandServiceDao demandServiceDao; + + @Override + public List listDemandServiceCountPage(String customerId, Date endTime, int serviceCountPageNo, int serviceCountPageSize) { + return PageHelper.startPage(serviceCountPageNo, serviceCountPageSize).doSelectPage(new ISelect() { + @Override + public void doSelect() { + demandServiceDao.listDemandServiceCountPage(customerId, endTime, "volunteer"); + } + }); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java new file mode 100644 index 0000000000..c95fd094fe --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/heart/impl/HeartVolunteerServiceImpl.java @@ -0,0 +1,40 @@ +package com.epmet.service.heart.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.epmet.commons.dynamic.datasource.annotation.DataSource; +import com.epmet.constant.DataSourceConstant; +import com.epmet.dao.heart.VolunteerInfoDao; +import com.epmet.entity.heart.VolunteerInfoEntity; +import com.epmet.service.heart.HeartVolunteerService; +import com.github.pagehelper.ISelect; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * @Description 描述 + * @Author wangxianzhang + * @Date 2021/12/8 1:35 下午 + * @Version 1.0 + */ +@Service +@DataSource(DataSourceConstant.EPMET_HEART) +public class HeartVolunteerServiceImpl implements HeartVolunteerService { + + @Autowired + private VolunteerInfoDao volunteerInfoDao; + + @Override + public List listVolunteersPage(String customerId, Date endCreateTime, Integer pageNum, Integer pageSize) { + return PageHelper.startPage(pageNum, pageSize).doSelectPage(() -> { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(VolunteerInfoEntity::getCustomerId, customerId); + query.lt(VolunteerInfoEntity::getCreatedTime, endCreateTime); + volunteerInfoDao.selectList(query); + }); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DemandServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DemandServiceImpl.java new file mode 100644 index 0000000000..7782226923 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/DemandServiceImpl.java @@ -0,0 +1,184 @@ +package com.epmet.service.impl; + +import com.epmet.commons.tools.constant.EpmetRoleKeyConstant; +import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.dto.heart.result.DemandServiceCountResultDTO; +import com.epmet.entity.crm.CustomerEntity; +import com.epmet.entity.heart.VolunteerInfoEntity; +import com.epmet.entity.stats.FactVolunteerServiceDailyEntity; +import com.epmet.service.DemandService; +import com.epmet.service.crm.CustomerService; +import com.epmet.service.heart.HeartDemandService; +import com.epmet.service.heart.HeartVolunteerService; +import com.epmet.service.stats.DemandStatsService; +import com.epmet.service.user.UserService; +import com.epmet.util.DimIdGenerator; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @Description 需求service + * @Author wangxianzhang + * @Date 2021/12/8 12:14 下午 + * @Version 1.0 + */ +@Service +public class DemandServiceImpl implements DemandService { + + @Autowired + private HeartDemandService heartDemandService; + + @Autowired + private HeartVolunteerService heartVolunteerService; + + @Autowired + private UserService userService; + + @Autowired + private DemandStatsService demandStatsService; + + @Autowired + private CustomerService customerService; + + @Override + public void statsVolunteerDemandServicesDaily(String customerId) { + + Date now = new Date(); + Date today = DateUtils.integrate(now, "yyyy-MM-dd"); + Date yestoday = DateUtils.addDateDays(today, -1); + + if (StringUtils.isNotBlank(customerId)) { + // 只计算单个客户 + clearOldDatas(Arrays.asList(customerId), yestoday); + statsVolunteerDemandServicesDaily4Customer(customerId, today, yestoday); + } else { + // 查询所有客户ID + List customerIds = customerService.listValidCustomersByCreateTime(null, null).stream().map(c -> c.getId()).collect(Collectors.toList()); + clearOldDatas(customerIds, yestoday); + customerIds.stream().forEach(cId -> { + statsVolunteerDemandServicesDaily4Customer(cId, today, yestoday); + }); + } + } + + /** + * 清理旧数据 + * @param yestoday + */ + private void clearOldDatas(List customerIds, Date yestoday) { + + String dateDimId = DimIdGenerator.getDateDimId(yestoday); + + demandStatsService.clearVolunteerDemandServiceDailyStats(customerIds, dateDimId); + + } + + /** + * 统计单个客户的志愿者服务情况 + * @param customerId 客户ID + * @param endTime 统计截止时间( partymemberVolunteerUserIds = new ArrayList<>(16); + + int pageNum = 1; + int volunteerPageSize = 5; + + while (true) { + + int shardingStartIndex = 0; + int shardingSize = 2; + + List volunteersPage = heartVolunteerService.listVolunteersPage(customerId, endTime, pageNum, volunteerPageSize); + + // 如果查询结果为0,说明没有更多的志愿者了 + if (volunteersPage.size() == 0) { + break; + } + + volunteerTotalCount += volunteersPage.size(); + + // 分片去确定党员身份 + while (true) { + int realShardingSize = Math.min(shardingSize, volunteersPage.size() - shardingStartIndex); + + if (realShardingSize == 0) { + break; + } + + int shardingEndIndex = shardingStartIndex + realShardingSize; + List volunteerUserIds = volunteersPage.subList(shardingStartIndex, shardingEndIndex) + .stream() + .map((volunteerInfoEntity) -> volunteerInfoEntity.getUserId()) + .collect(Collectors.toList()); + + List tempPartymemberUserIds = userService.filterUserIds(volunteerUserIds, EpmetRoleKeyConstant.PARTYMEMBER); + + partymemberVolunteerUserIds.addAll(tempPartymemberUserIds); + + shardingStartIndex = shardingEndIndex; + } + + pageNum++; + } + + partymemberVolunteerCount += partymemberVolunteerUserIds.size(); + resiVolunteerCount = volunteerTotalCount - partymemberVolunteerCount; + + //2. 查询志愿者服务次数 + + // 总服务次数 + int totalDemandServiceCount = 0; + // 党员服务次数 + int partymemberDemandServiceCount = 0; + // 居民服务次数 + int resiDemandServiceCount = 0; + + int serviceCountPageNo = 0; + int serviceCountPageSize = 1000; + while (true) { + + List damendServiceCounts = heartDemandService.listDemandServiceCountPage(customerId, endTime, serviceCountPageNo, serviceCountPageSize); + + for (DemandServiceCountResultDTO damendServiceCount : damendServiceCounts) { + String serverId = damendServiceCount.getServerId(); + if (partymemberVolunteerUserIds.contains(serverId)) { + partymemberDemandServiceCount++; + } else { + resiDemandServiceCount++; + } + } + + totalDemandServiceCount += damendServiceCounts.size(); + + if (damendServiceCounts.size() <= serviceCountPageSize) { + break; + } + } + + // 3.持久化 + FactVolunteerServiceDailyEntity insert = new FactVolunteerServiceDailyEntity(); + insert.setDateId(DimIdGenerator.getDateDimId(belongTime)); + insert.setCustomerId(customerId); + insert.setMonthId(DimIdGenerator.getMonthDimId(belongTime)); + insert.setPartyServiceTotal(partymemberDemandServiceCount); + insert.setServiceTotal(totalDemandServiceCount); + insert.setPartyTotal(partymemberVolunteerCount); + insert.setResiServiceTotal(resiDemandServiceCount); + insert.setResiTotal(resiVolunteerCount); + insert.setVolunteerTotal(volunteerTotalCount); + + demandStatsService.addVolunteerServiceDaily(insert); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DemandStatsService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DemandStatsService.java new file mode 100644 index 0000000000..dec4ed26ef --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DemandStatsService.java @@ -0,0 +1,18 @@ +package com.epmet.service.stats; + +import com.epmet.entity.stats.FactVolunteerServiceDailyEntity; + +import java.util.List; + +/** + *@Description 统计客户下的志愿者需求服务数据 + *@Author wangxianzhang + *@Date 2021/12/8 + */ +public interface DemandStatsService { + + + void addVolunteerServiceDaily(FactVolunteerServiceDailyEntity entity); + + void clearVolunteerDemandServiceDailyStats(List customerIds, String dateDimId); +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DemandStatsServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DemandStatsServiceImpl.java new file mode 100644 index 0000000000..54a8525877 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DemandStatsServiceImpl.java @@ -0,0 +1,36 @@ +package com.epmet.service.stats.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.epmet.commons.dynamic.datasource.annotation.DataSource; +import com.epmet.constant.DataSourceConstant; +import com.epmet.dao.stats.FactVolunteerServiceDailyDao; +import com.epmet.entity.stats.FactVolunteerServiceDailyEntity; +import com.epmet.service.stats.DemandStatsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @Description 描述 + * @Author wangxianzhang + * @Date 2021/12/8 10:54 上午 + * @Version 1.0 + */ +@Service +@DataSource(DataSourceConstant.STATS) +public class DemandStatsServiceImpl implements DemandStatsService { + + @Autowired + private FactVolunteerServiceDailyDao factVolunteerServiceDailyDao; + + @Override + public void addVolunteerServiceDaily(FactVolunteerServiceDailyEntity entity) { + factVolunteerServiceDailyDao.insert(entity); + } + + @Override + public void clearVolunteerDemandServiceDailyStats(List customerIds, String dateDimId) { + factVolunteerServiceDailyDao.clearVolunteerDemandServiceDailyStats(customerIds, dateDimId); + } +} diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/UserService.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/UserService.java index ffa464d4fa..1d0a500b0a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/UserService.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/UserService.java @@ -146,4 +146,6 @@ public interface UserService { List getPatrolRecordList(MidPatrolFormDTO formDTO); List getPatrolDetailList(MidPatrolFormDTO formDTO); + + List filterUserIds(List userIds, String roleKey); } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java index a8bf95d7f0..a2d56125a6 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/user/impl/UserServiceImpl.java @@ -1109,4 +1109,8 @@ public class UserServiceImpl implements UserService { return userDao.getPatrolDetailList(formDTO); } + @Override + public List filterUserIds(List userIds, String roleKey) { + return userDao.filterUserIds(userIds, roleKey); + } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.26__create_volunteer_service_daily.sql b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.26__create_volunteer_service_daily.sql new file mode 100644 index 0000000000..7eade2a679 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.26__create_volunteer_service_daily.sql @@ -0,0 +1,21 @@ +CREATE TABLE epmet_data_statistical.`fact_volunteer_service_daily` +( + `ID` varchar(64) NOT NULL COMMENT '主键', + `CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', + `DATE_ID` varchar(8) NOT NULL COMMENT 'yyyyMMdd', + `MONTH_ID` varchar(6) NOT NULL COMMENT 'yyyyMM', + `VOLUNTEER_TOTAL` int(11) NOT NULL COMMENT '截止到当前dateId,当前客户下,共有多少个爱心互助的志愿者', + `PARTY_TOTAL` int(11) NOT NULL COMMENT '截止到当前dateId,当前客户下,XX个爱心互助志愿者中,党员有多少个', + `RESI_TOTAL` int(11) NOT NULL COMMENT '截止到当前dateId,当前客户下,XX个爱心互助志愿者中,居民有多少个', + `SERVICE_TOTAL` int(11) NOT NULL COMMENT '服务总次数', + `PARTY_SERVICE_TOTAL` int(11) NOT NULL COMMENT '党员服务总次数', + `RESI_SERVICE_TOTAL` int(11) NOT NULL COMMENT '居民服务总次数', + `DEL_FLAG` int(11) NOT NULL COMMENT '删除标识:0.未删除 1.已删除', + `REVISION` int(11) NOT NULL COMMENT '乐观锁', + `CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', + `CREATED_TIME` datetime NOT NULL COMMENT '创建时间', + `UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', + `UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', + PRIMARY KEY (`ID`), + UNIQUE KEY `uni_vsd` (`CUSTOMER_ID`,`DATE_ID`,`DEL_FLAG`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='志愿者服务情况统计' \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/heart/IcUserDemandServiceDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/heart/IcUserDemandServiceDao.xml new file mode 100644 index 0000000000..1c13f56e87 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/heart/IcUserDemandServiceDao.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/heart/VolunteerInfoDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/heart/VolunteerInfoDao.xml new file mode 100644 index 0000000000..a426712a22 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/heart/VolunteerInfoDao.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactVolunteerServiceDailyDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactVolunteerServiceDailyDao.xml new file mode 100644 index 0000000000..59dfd96c12 --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactVolunteerServiceDailyDao.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + delete + from fact_volunteer_service_daily + where DATE_ID=#{dateDimId} + and CUSTOMER_ID in + + #{customerId} + + + + + + \ No newline at end of file diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml index 4715f23c2a..6542440fb8 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/user/UserDao.xml @@ -1052,5 +1052,18 @@ order by created_time LIMIT #{offset},#{pageSize} + + +