From 15122bad11d7e868bf97dacc56d6c0f514e9f930 Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Wed, 22 Dec 2021 15:45:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=B0screen=5Fproject=5F*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/ScreenCentralZoneDataFormDTO.java | 7 +++--- .../com/epmet/controller/DemoController.java | 23 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/form/ScreenCentralZoneDataFormDTO.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/form/ScreenCentralZoneDataFormDTO.java index 3482e2cab9..d655b8608a 100644 --- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/form/ScreenCentralZoneDataFormDTO.java +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/screen/form/ScreenCentralZoneDataFormDTO.java @@ -1,9 +1,6 @@ package com.epmet.dto.screen.form; -import lombok.AllArgsConstructor; import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; import java.io.Serializable; @@ -26,4 +23,8 @@ public class ScreenCentralZoneDataFormDTO implements Serializable { * 时间维度 不一定是dateId 需要根据其格式进行判断维度的类型 * */ private String dateId; + + private String startDate; + + private String endDate; } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java index ef567e92f1..a1e61b2461 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java @@ -881,10 +881,17 @@ public class DemoController { */ @PostMapping("project-test") public Result project(@RequestBody ScreenCentralZoneDataFormDTO param) { - if(StringUtils.isBlank(param.getDateId())){ - //默认截止到昨天。 - param.setDateId(DateUtils.getBeforeNDay(1)); + List dateIds = new ArrayList<>(); + if ((StringUtils.isBlank(param.getStartDate()) && StringUtils.isBlank(param.getEndDate()))){ + if (StringUtils.isNotBlank(param.getDateId())){ + dateIds.add(param.getDateId()); + }else { + dateIds.add(DimIdGenerator.getDateDimId(DateUtils.addDateDays(new Date(), -1))); + } + }else { + dateIds = DateUtils.getDaysBetween(param.getStartDate(), param.getEndDate()); } + List customerIds = new ArrayList(); if (StringUtils.isNotBlank(param.getCustomerId())) { customerIds.add(param.getCustomerId()); @@ -892,10 +899,12 @@ public class DemoController { customerIds = dimCustomerService.selectCustomerIdPage(1, 100); } for (String customerId : customerIds) { - ScreenCentralZoneDataFormDTO formDTO = new ScreenCentralZoneDataFormDTO(); - formDTO.setCustomerId(customerId); - formDTO.setDateId(param.getDateId()); - screenProjectSettleService.extractScreenData(param); + dateIds.forEach(dateId -> { + ScreenCentralZoneDataFormDTO formDTO = new ScreenCentralZoneDataFormDTO(); + formDTO.setCustomerId(customerId); + formDTO.setDateId(dateId); + screenProjectSettleService.extractScreenData(param); + }); } return new Result(); } From 266d75f719d8f90244bb58c087d26dc9db4b4189 Mon Sep 17 00:00:00 2001 From: zhaoqifeng Date: Wed, 22 Dec 2021 16:52:22 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8A=BD=E5=8F=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=B0screen=5Fproject=5F*?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/epmet/controller/DemoController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java index a1e61b2461..a6de8eb159 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DemoController.java @@ -903,7 +903,7 @@ public class DemoController { ScreenCentralZoneDataFormDTO formDTO = new ScreenCentralZoneDataFormDTO(); formDTO.setCustomerId(customerId); formDTO.setDateId(dateId); - screenProjectSettleService.extractScreenData(param); + screenProjectSettleService.extractScreenData(formDTO); }); } return new Result(); From 742282a2190c82be9345dfe265ff0e9be8dedb3f Mon Sep 17 00:00:00 2001 From: wangxianzhang Date: Wed, 22 Dec 2021 17:16:43 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9A=201.=E5=BF=97?= =?UTF-8?q?=E6=84=BF=E8=80=85=E9=9C=80=E6=B1=82=E6=9C=8D=E5=8A=A1=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E3=80=82=E4=BB=A5=E7=BD=91=E6=A0=BC=E4=B8=BA=E7=BB=B4?= =?UTF-8?q?=E5=BA=A6=E7=BB=9F=E8=AE=A1=E3=80=82=202.=E5=BF=97=E6=84=BF?= =?UTF-8?q?=E8=80=85=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2=E3=80=82=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E7=BA=A7agencyId=E4=B8=BA=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E8=AF=A2=E8=AF=A5agencyId=E4=B8=8Bn=E7=BA=A7?= =?UTF-8?q?=E6=89=80=E6=9C=89=E7=9A=84=E5=BF=97=E6=84=BF=E8=80=85=203.?= =?UTF-8?q?=E5=BF=97=E6=84=BF=E8=80=85=E5=88=86=E5=B8=83=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E3=80=82=E5=A2=9E=E5=8A=A0agencyId=E4=B8=BA=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E8=AF=A2=E8=AF=A5agencyId=E4=B8=8Bn=E7=BA=A7?= =?UTF-8?q?=E6=89=80=E6=9C=89=E7=9A=84=E5=BF=97=E6=84=BF=E8=80=85.=204.?= =?UTF-8?q?=E5=BF=97=E6=84=BF=E8=80=85=E9=9C=80=E6=B1=82=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E7=BB=93=E6=9E=9C=E6=9F=A5=E8=AF=A2=E3=80=82?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0agencyId=E4=B8=BA=E6=9D=A1=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=A5agencyId=E4=B8=8Bn=E7=BA=A7=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E6=9C=8D=E5=8A=A1=E7=BB=9F=E8=AE=A1=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../heart/VolunteerDemandServiceFormDTO.java | 19 +++++ .../DataReportHeartDemandController.java | 12 ++- .../fact/FactVolunteerServiceDailyDao.java | 5 +- .../service/heart/DemandService.java | 2 +- .../service/heart/impl/DemandServiceImpl.java | 44 ++++++++-- .../fact/FactVolunteerServiceDailyDao.xml | 13 ++- .../dao/heart/IcUserDemandServiceDao.java | 2 +- .../FactVolunteerServiceDailyEntity.java | 9 ++ .../service/heart/HeartDemandService.java | 2 +- .../heart/impl/HeartDemandServiceImpl.java | 4 +- .../epmet/service/impl/DemandServiceImpl.java | 83 +++++++++++++++---- ...27__volunteer_service_daily_add_gridid.sql | 14 ++++ .../mapper/heart/IcUserDemandServiceDao.xml | 2 + .../stats/FactVolunteerServiceDailyDao.xml | 2 + .../dto/form/resi/VolunteerCommonFormDTO.java | 12 ++- .../feign/EpmetHeartOpenFeignClient.java | 1 + .../controller/ResiVolunteerController.java | 6 +- .../com/epmet/entity/VolunteerInfoEntity.java | 4 + .../epmet/service/VolunteerInfoService.java | 2 +- .../impl/VolunteerInfoServiceImpl.java | 29 ++++++- .../resources/mapper/VolunteerInfoDao.xml | 2 + .../dto/form/VolunteerCommonFormDTO.java | 3 + .../epmet/controller/VolunteerController.java | 3 +- .../com/epmet/service/VolunteerService.java | 2 +- .../service/impl/VolunteerServiceImpl.java | 7 +- 25 files changed, 234 insertions(+), 50 deletions(-) create mode 100644 epmet-module/data-report/data-report-client/src/main/java/com/epmet/dto/form/heart/VolunteerDemandServiceFormDTO.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.27__volunteer_service_daily_add_gridid.sql diff --git a/epmet-module/data-report/data-report-client/src/main/java/com/epmet/dto/form/heart/VolunteerDemandServiceFormDTO.java b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/dto/form/heart/VolunteerDemandServiceFormDTO.java new file mode 100644 index 0000000000..4a661bebb4 --- /dev/null +++ b/epmet-module/data-report/data-report-client/src/main/java/com/epmet/dto/form/heart/VolunteerDemandServiceFormDTO.java @@ -0,0 +1,19 @@ +package com.epmet.dto.form.heart; + +import lombok.Data; + +/** + * @Description + * @Author wangxianzhang + * @Date 2021/12/22 3:12 下午 + * @Version 1.0 + */ +@Data +public class VolunteerDemandServiceFormDTO { + + /** + * 组织ID + */ + private String agencyId; + +} diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/heart/DataReportHeartDemandController.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/heart/DataReportHeartDemandController.java index 86eabe2b3c..d1de1db852 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/heart/DataReportHeartDemandController.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/controller/heart/DataReportHeartDemandController.java @@ -3,10 +3,13 @@ package com.epmet.datareport.controller.heart; import com.epmet.commons.tools.annotation.LoginUser; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; import com.epmet.datareport.service.heart.DemandService; +import com.epmet.dto.form.heart.VolunteerDemandServiceFormDTO; import com.epmet.dto.result.heart.VolunteerDemandServiceStatsResultDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -29,9 +32,14 @@ public class DataReportHeartDemandController { * @return */ @PostMapping("volunteer/service") - public Result getVolunteerServiceStats(@LoginUser TokenDto loginUser) { + public Result getVolunteerServiceStats(@LoginUser TokenDto loginUser, @RequestBody VolunteerDemandServiceFormDTO input) { + + ValidatorUtils.validateEntity(input); + + String agencyId = input.getAgencyId(); String customerId = loginUser.getCustomerId(); - VolunteerDemandServiceStatsResultDTO r = demandService.getVolunteerServiceStats(customerId); + + VolunteerDemandServiceStatsResultDTO r = demandService.getVolunteerServiceStats(customerId, agencyId); return new Result().ok(r); } diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/fact/FactVolunteerServiceDailyDao.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/fact/FactVolunteerServiceDailyDao.java index fd4d28afb0..6589571c66 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/fact/FactVolunteerServiceDailyDao.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/fact/FactVolunteerServiceDailyDao.java @@ -36,8 +36,9 @@ public interface FactVolunteerServiceDailyDao extends BaseDao - select * + select CUSTOMER_ID CUSTOMER_ID, + DATE_ID DATE_ID, + sum(VOLUNTEER_TOTAL) VOLUNTEER_TOTAL, + sum(PARTY_TOTAL) PARTY_TOTAL, + sum(RESI_TOTAL) RESI_TOTAL, + sum(SERVICE_TOTAL) SERVICE_TOTAL, + sum(PARTY_SERVICE_TOTAL) PARTY_SERVICE_TOTAL, + sum(RESI_SERVICE_TOTAL) RESI_SERVICE_TOTAL from fact_volunteer_service_daily where DEL_FLAG = 0 and CUSTOMER_ID = #{customerId} + and PIDS like CONCAT(#{agencyPids}, "%") + group by CUSTOMER_ID, DATE_ID order by DATE_ID desc - limit 1 + limit 1 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 index 165ae6b91c..02fc225940 100644 --- 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 @@ -40,5 +40,5 @@ public interface IcUserDemandServiceDao extends BaseDao listDemandServeTimes(@Param("customerId") String customerId, @Param("endTime") Date endTime, @Param("serviceType") String serviceType); + List listDemandServeTimes(@Param("customerId") String customerId, @Param("gridId") String gridId, @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/entity/stats/FactVolunteerServiceDailyEntity.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/stats/FactVolunteerServiceDailyEntity.java index f2b473bfe9..82687aeba0 100644 --- 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 @@ -43,6 +43,11 @@ public class FactVolunteerServiceDailyEntity extends BaseEpmetEntity { */ private String customerId; + /** + * 网格ID + */ + private String gridId; + /** * yyyyMMdd */ @@ -82,5 +87,9 @@ public class FactVolunteerServiceDailyEntity extends BaseEpmetEntity { * 居民服务总次数 */ private Integer resiServiceTotal; + + private String pid; + + private String pids; } 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 index baaa29c97b..981fd1fc2f 100644 --- 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 @@ -11,5 +11,5 @@ import java.util.List; *@Date 2021/12/8 */ public interface HeartDemandService { - List listDemandServeTimesPage(String customerId, Date endTime, int serviceCountPageNo, int serviceCountPageSize); + List listDemandServeTimesPage(String customerId, String gridId, Date endTime, int serviceCountPageNo, int serviceCountPageSize); } 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 index c33f426ad5..8969b61d31 100644 --- 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 @@ -29,11 +29,11 @@ public class HeartDemandServiceImpl implements HeartDemandService { private IcUserDemandServiceDao demandServiceDao; @Override - public List listDemandServeTimesPage(String customerId, Date endTime, int serviceCountPageNo, int serviceCountPageSize) { + public List listDemandServeTimesPage(String customerId, String gridId, Date endTime, int serviceCountPageNo, int serviceCountPageSize) { return PageHelper.startPage(serviceCountPageNo, serviceCountPageSize).doSelectPage(new ISelect() { @Override public void doSelect() { - demandServiceDao.listDemandServeTimes(customerId, endTime, "volunteer"); + demandServiceDao.listDemandServeTimes(customerId, gridId, endTime, "volunteer"); } }); } 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 index 66cbf1058d..036718bf0f 100644 --- 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 @@ -1,11 +1,16 @@ package com.epmet.service.impl; import com.epmet.commons.tools.constant.EpmetRoleKeyConstant; +import com.epmet.commons.tools.constant.ServiceConstant; +import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.utils.DateUtils; +import com.epmet.dto.CustomerGridDTO; +import com.epmet.dto.form.CustomerGridFormDTO; 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.feign.GovOrgOpenFeignClient; import com.epmet.service.DemandService; import com.epmet.service.crm.CustomerService; import com.epmet.service.heart.HeartDemandService; @@ -27,7 +32,7 @@ import java.util.stream.Collectors; * @Version 1.0 */ @Service -public class DemandServiceImpl implements DemandService { +public class DemandServiceImpl implements DemandService, ResultDataResolver { @Autowired private HeartDemandService heartDemandService; @@ -37,12 +42,15 @@ public class DemandServiceImpl implements DemandService { @Autowired private UserService userService; - + @Autowired private DemandStatsService demandStatsService; - + @Autowired private CustomerService customerService; + + @Autowired + private GovOrgOpenFeignClient govOrgOpenFeignClient; @Override public void statsVolunteerDemandServicesDaily(String customerId) { @@ -50,7 +58,7 @@ public class DemandServiceImpl implements DemandService { 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); @@ -67,7 +75,8 @@ public class DemandServiceImpl implements DemandService { /** * 清理旧数据 - * @param targetDate 要清理哪天的数据 + * + * @param targetDate 要清理哪天的数据 * @param customerIds 要清理哪些客户的 */ private void clearOldDatas(List customerIds, Date targetDate) { @@ -80,12 +89,44 @@ public class DemandServiceImpl implements DemandService { /** * 统计单个客户的志愿者服务情况 + * * @param customerId 客户ID - * @param endTime 统计截止时间(> gridIdAndVolunteers = new HashMap<>(); + + heartVolunteerService.listVolunteers(customerId, endTime).forEach(v -> { + String volunteerGridId = v.getGridId(); + if (StringUtils.isNotBlank(volunteerGridId)) { + if (!gridIdAndVolunteers.containsKey(volunteerGridId)) { + gridIdAndVolunteers.put(volunteerGridId, new ArrayList<>()); + } + + gridIdAndVolunteers.get(volunteerGridId).add(v); + } + }); + + // 2.按网格分别统计,且持久化 + for (Map.Entry> entry : gridIdAndVolunteers.entrySet()) { + statsVolunteerDemandServicesDaily4Grid(customerId, entry.getKey(), endTime, entry.getValue(), belongTime); + } + } + + /** + * 按日统计网格需求服务数据 + * @param customerId + * @param gridId + * @param endTime 统计截止时间 + * @param volunteers 志愿者volunteerInfo列表 + * @param belongTime 该次统计要归属到哪一天,即createTime + * @return 统计结果entity,以备他用 + */ + private FactVolunteerServiceDailyEntity statsVolunteerDemandServicesDaily4Grid(String customerId, String gridId, Date endTime, List volunteers, Date belongTime) { // 1.志愿者分流为党员志愿者&普通居民志愿者 - Integer volunteerTotalCount = 0; + Integer volunteerTotalCount = volunteers.size(); // 党员志愿者数量 Integer partymemberVolunteerCount = 0; // 居民志愿者数量 @@ -94,15 +135,13 @@ public class DemandServiceImpl implements DemandService { // 党员志愿者用户id列表 List partymemberVolunteerUserIds = new ArrayList<>(16); - List volunteers = heartVolunteerService.listVolunteers(customerId, endTime); - - volunteerTotalCount = volunteers.size(); + //--------------------------------【以上是结果数据变量】------------------------------------------ // 分片开始下标 int shardingStartIndex = 0; // 分片大小(条数) int shardingSize = 100; - + // 分片去确定党员身份,防止in条件过大 while (true) { int realShardingSize = Math.min(shardingSize, volunteerTotalCount - shardingStartIndex); @@ -141,7 +180,7 @@ public class DemandServiceImpl implements DemandService { while (true) { // 取出每一个服务者的服务次数 - List damendServeTimes = heartDemandService.listDemandServeTimesPage(customerId, endTime, serviceCountPageNo, serviceCountPageSize); + List damendServeTimes = heartDemandService.listDemandServeTimesPage(customerId, gridId, endTime, serviceCountPageNo, serviceCountPageSize); for (DemandServiceCountResultDTO damendServiceTimes : damendServeTimes) { String serverId = damendServiceTimes.getServerId(); @@ -158,11 +197,12 @@ public class DemandServiceImpl implements DemandService { } totalDemandServeTimes = partymemberDemandServeTimes + resiDemandServeTimes; - - // 3.持久化 + + // 3.组装entity数据返回,待存储 FactVolunteerServiceDailyEntity insert = new FactVolunteerServiceDailyEntity(); insert.setDateId(DimIdGenerator.getDateDimId(belongTime)); insert.setCustomerId(customerId); + insert.setGridId(gridId); insert.setMonthId(DimIdGenerator.getMonthDimId(belongTime)); insert.setPartyServiceTotal(partymemberDemandServeTimes); insert.setServiceTotal(totalDemandServeTimes); @@ -171,6 +211,19 @@ public class DemandServiceImpl implements DemandService { insert.setResiTotal(resiVolunteerCount); insert.setVolunteerTotal(volunteerTotalCount); + CustomerGridFormDTO gridForm = new CustomerGridFormDTO(); + gridForm.setGridId(gridId); + String errorMsg = "【志愿者服务按日统计】查询网格基本信息失败"; + CustomerGridDTO gridInfo = getResultDataOrThrowsException(govOrgOpenFeignClient.getGridBaseInfoByGridId(gridForm), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); + + Optional.ofNullable(gridInfo).ifPresent(gi -> { + insert.setPid(gi.getPid()); + insert.setPids(gi.getPids()); + }); + + // 持久化 demandStatsService.addVolunteerServiceDaily(insert); + + return insert; } } diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.27__volunteer_service_daily_add_gridid.sql b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.27__volunteer_service_daily_add_gridid.sql new file mode 100644 index 0000000000..de4af15c6f --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/db/migration/V0.0.27__volunteer_service_daily_add_gridid.sql @@ -0,0 +1,14 @@ +-- 发布前执行 +alter table fact_volunteer_service_daily add column GRID_ID varchar(64) not null comment '网格ID' after CUSTOMER_ID; +alter table fact_volunteer_service_daily add column PID varchar(64) default '' comment 'pid网格父级ID' after RESI_SERVICE_TOTAL; +alter table fact_volunteer_service_daily add column PIDS varchar(255) default '' comment 'pid网格父级ID路径,包含PID' after PID; + +-- 发布后执行 + +delete from fact_volunteer_service_daily; + +alter table fact_volunteer_service_daily drop key uni_vsd; + +alter table fact_volunteer_service_daily + add constraint uni_vsd + unique (GRID_ID, DATE_ID, DEL_FLAG); 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 index ddebabef66..ab73afd872 100644 --- 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 @@ -24,11 +24,13 @@ select service.SERVER_ID, SERVICE_TYPE, count(1) as SERVE_TIMES from ic_user_demand_rec damend inner join ic_user_demand_service service on (damend.ID = service.DEMAND_REC_ID and service.DEL_FLAG = 0) + inner join volunteer_info v on (service.SERVER_ID = v.USER_ID and v.DEL_FLAG = 0) where damend.DEL_FLAG = 0 and damend.STATUS = 'finished' and damend.CUSTOMER_ID = #{customerId} and service.SERVICE_END_TIME #{endTime} and service.SERVICE_TYPE = #{serviceType} + and v.GRID_ID = #{gridId} group by service.SERVER_ID, SERVICE_TYPE \ 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 index 59dfd96c12..be083bd93e 100644 --- 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 @@ -14,6 +14,8 @@ + + diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/resi/VolunteerCommonFormDTO.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/resi/VolunteerCommonFormDTO.java index c8893697a8..9a5e2fdc7f 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/resi/VolunteerCommonFormDTO.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/dto/form/resi/VolunteerCommonFormDTO.java @@ -14,12 +14,16 @@ import javax.validation.constraints.NotNull; @Data public class VolunteerCommonFormDTO { - public interface VolunteerPage { - } - - @NotBlank(message = "客户ID不能为空", groups = {VolunteerPage.class}) + /** + * 客户ID + */ private String customerId; + /** + * 上级组织ID,使用PIDS like,查询该组织下所有志愿者,注意,是like 'agencyId:%' + */ + private String superiorAgencyId; + private Integer pageNo = 0; private Integer pageSize = 20; diff --git a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/feign/EpmetHeartOpenFeignClient.java b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/feign/EpmetHeartOpenFeignClient.java index 4bad8f25d7..a21cccb8f3 100644 --- a/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/feign/EpmetHeartOpenFeignClient.java +++ b/epmet-module/epmet-heart/epmet-heart-client/src/main/java/com/epmet/feign/EpmetHeartOpenFeignClient.java @@ -23,6 +23,7 @@ import java.util.List; * @date 2020/6/4 13:25 */ @FeignClient(name = ServiceConstant.EPMET_HEART_SERVER, fallbackFactory = EpmetHeartOpenFeignClientFallbackFactory.class) +//@FeignClient(name = ServiceConstant.EPMET_HEART_SERVER, fallbackFactory = EpmetHeartOpenFeignClientFallbackFactory.class, url = "http://localhost:8111") public interface EpmetHeartOpenFeignClient { /** diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/ResiVolunteerController.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/ResiVolunteerController.java index e1d18e5536..85a9009b44 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/ResiVolunteerController.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/controller/ResiVolunteerController.java @@ -135,13 +135,11 @@ public class ResiVolunteerController { */ @PostMapping("page") public Result> queryVolunteerPage(@RequestBody VolunteerCommonFormDTO input) { - - ValidatorUtils.validateEntity(input, VolunteerCommonFormDTO.VolunteerPage.class); - Integer pageNo = input.getPageNo(); Integer pageSize = input.getPageSize(); String customerId = input.getCustomerId(); - List l = volunteerInfoService.queryVolunteerPage(customerId, pageNo, pageSize); + String superiorAgencyId = input.getSuperiorAgencyId(); + List l = volunteerInfoService.queryVolunteerPage(customerId, pageNo, pageSize, superiorAgencyId); return new Result>().ok(l); } } diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/VolunteerInfoEntity.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/VolunteerInfoEntity.java index fcce38bc75..e49e85d986 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/VolunteerInfoEntity.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/entity/VolunteerInfoEntity.java @@ -67,4 +67,8 @@ public class VolunteerInfoEntity extends BaseEpmetEntity { * 志愿者注册,所在网格名称 */ private String gridName; + + private String pid; + + private String pids; } diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/VolunteerInfoService.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/VolunteerInfoService.java index 6a84fb67a1..1098a61c98 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/VolunteerInfoService.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/VolunteerInfoService.java @@ -96,5 +96,5 @@ public interface VolunteerInfoService extends BaseService { */ List queryListVolunteer(String customerId,String userRealName); - List queryVolunteerPage(String customerId, Integer pageNo, Integer pageSize); + List queryVolunteerPage(String customerId, Integer pageNo, Integer pageSize, String superiorAgencyId); } diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/VolunteerInfoServiceImpl.java b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/VolunteerInfoServiceImpl.java index ac87cc6b4c..ad5f5aa067 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/VolunteerInfoServiceImpl.java +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/java/com/epmet/service/impl/VolunteerInfoServiceImpl.java @@ -22,11 +22,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; import com.epmet.commons.tools.constant.MqConstant; import com.epmet.commons.tools.constant.NumConstant; +import com.epmet.commons.tools.constant.ServiceConstant; import com.epmet.commons.tools.dto.form.mq.MqBaseMsgDTO; import com.epmet.commons.tools.dto.form.mq.eventmsg.BasePointEventMsg; import com.epmet.commons.tools.enums.EventEnum; import com.epmet.commons.tools.exception.EpmetErrorCode; +import com.epmet.commons.tools.exception.EpmetException; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.redis.RedisKeys; import com.epmet.commons.tools.redis.RedisUtils; import com.epmet.commons.tools.security.dto.TokenDto; @@ -35,6 +38,7 @@ import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.SendMqMsgUtils; import com.epmet.constant.SmsTemplateConstant; import com.epmet.dao.VolunteerInfoDao; +import com.epmet.dto.CustomerAgencyDTO; import com.epmet.dto.HeartUserInfoDTO; import com.epmet.dto.VolunteerInfoDTO; import com.epmet.dto.form.CommonCustomerFormDTO; @@ -50,6 +54,7 @@ import com.epmet.dto.result.resi.ResiVolunteerInfoResultDTO; import com.epmet.entity.VolunteerInfoEntity; import com.epmet.feign.EpmetMessageOpenFeignClient; import com.epmet.feign.EpmetUserOpenFeignClient; +import com.epmet.feign.GovOrgOpenFeignClient; import com.epmet.service.HeartUserInfoService; import com.epmet.service.VolunteerInfoService; import com.github.pagehelper.PageHelper; @@ -64,6 +69,7 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -74,7 +80,7 @@ import java.util.stream.Collectors; * @since v1.0.0 2020-07-19 */ @Service -public class VolunteerInfoServiceImpl extends BaseServiceImpl implements VolunteerInfoService { +public class VolunteerInfoServiceImpl extends BaseServiceImpl implements VolunteerInfoService, ResultDataResolver { private Logger logger = LogManager.getLogger(VolunteerInfoServiceImpl.class); private static final String SEND_SMS_CODE_ERROR = "发送短信验证码异常,手机号[%s],code[%s],msg[%s]"; @@ -89,6 +95,9 @@ public class VolunteerInfoServiceImpl extends BaseServiceImpl queryVolunteerPage(String customerId, Integer pageNo, Integer pageSize) { + public List queryVolunteerPage(String customerId, Integer pageNo, Integer pageSize, String superiorAgencyId) { LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.eq(VolunteerInfoEntity::getCustomerId, customerId); + Optional.ofNullable(customerId).ifPresent(cid -> query.eq(VolunteerInfoEntity::getCustomerId, cid)); + Optional.ofNullable(superiorAgencyId).ifPresent(cid -> { + + // 需要查询agency的pids:id,通过这个字符串去匹配志愿者的Pids字段来查询 + String errorMsg = "【分页查询志愿者列表】失败"; + CustomerAgencyDTO agencyInfo = getResultDataOrThrowsException(govOrgOpenFeignClient.getAgencyById(superiorAgencyId), ServiceConstant.GOV_ORG_SERVER, EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); + if (agencyInfo == null) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), errorMsg, errorMsg); + } + + String pidsAndAgencyIdPath = agencyInfo.getPids().concat(":").concat(superiorAgencyId); + if (pidsAndAgencyIdPath.startsWith(":")) pidsAndAgencyIdPath = pidsAndAgencyIdPath.replaceFirst(":", ""); + + query.likeRight(VolunteerInfoEntity::getPids, pidsAndAgencyIdPath); + }); PageHelper.startPage(pageNo, pageSize); List volunteerInfoEntities = baseDao.selectList(query); diff --git a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/VolunteerInfoDao.xml b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/VolunteerInfoDao.xml index 4dc80881f2..a3f67ab27b 100644 --- a/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/VolunteerInfoDao.xml +++ b/epmet-module/epmet-heart/epmet-heart-server/src/main/resources/mapper/VolunteerInfoDao.xml @@ -17,6 +17,8 @@ + +