Browse Source

dimPartyMember信息统计添加指定时间区间

master
zxc 5 years ago
parent
commit
f2428906e9
  1. 5
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/form/CustomerIdAndDateIdFormDTO.java
  2. 1
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java
  3. 63
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimCustomerPartymemberServiceImpl.java
  4. 16
      epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/impl/DimPartyMemberServiceImpl.java

5
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/stats/form/CustomerIdAndDateIdFormDTO.java

@ -19,6 +19,9 @@ public class CustomerIdAndDateIdFormDTO implements Serializable {
private String customerId;
@NotBlank(message = "日期Id不能为空",groups = CustomerIdAndDateId.class)
private String dateId;
private String startDate;
private String endDate;
}

1
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java

@ -263,7 +263,6 @@ public class DimController {
*/
@PostMapping("statsparty")
public Result getPartyInfo(@RequestBody CustomerIdAndDateIdFormDTO customerIdAndDateIdFormDTO) {
ValidatorUtils.validateEntity(customerIdAndDateIdFormDTO, CustomerIdAndDateIdFormDTO.CustomerIdAndDateId.class);
return new Result().ok(partyMemberService.statsPartyMember(customerIdAndDateIdFormDTO));
}

63
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimCustomerPartymemberServiceImpl.java

@ -41,6 +41,7 @@ import com.epmet.service.partymember.PartyMemberService;
import com.epmet.service.stats.DimCustomerPartymemberService;
import com.epmet.service.stats.DimCustomerService;
import com.epmet.service.stats.DimGridService;
import com.epmet.util.DimIdGenerator;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
@ -49,10 +50,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -134,32 +132,45 @@ public class DimCustomerPartymemberServiceImpl extends BaseServiceImpl<DimCustom
*/
@Override
public Boolean statsPartyMember(CustomerIdAndDateIdFormDTO customerIdAndDateIdFormDTO) {
List<String> allCustomerId = dimCustomerService.getAllCustomerId();
if (CollectionUtils.isEmpty(allCustomerId)){
String customerIdOne = customerIdAndDateIdFormDTO.getCustomerId();
List<String> customerIds = new ArrayList<>();
List<String> dateIds = new ArrayList<>();
if (StringUtils.isNotBlank(customerIdOne)){
customerIds.add(customerIdOne);
}else {
customerIds = dimCustomerService.getAllCustomerId();
}
if (CollectionUtils.isEmpty(customerIds)){
throw new RenException(StatsConstant.CUSTOMER_INFO_NULL);
}
allCustomerId.forEach(customerId -> {
String dateId = customerIdAndDateIdFormDTO.getDateId();
List<DimCustomerPartyMemberFormDTO> partyMemberList = partyMemberService.selectPartyMemberInfo(customerId, dateId);
if (CollectionUtils.isEmpty(partyMemberList)){
log.warn(String.format(StatsConstant.PARTY_INFO_LIST,customerId));
return;
}
List<String> gridIds = partyMemberList.stream().map(party -> party.getGridId()).distinct().collect(Collectors.toList());
List<GridBelongAgencyResultDTO> agencyInfos = dimGridService.selectGridBelongAgencyInfo(gridIds);
TimeListResultDTO timeList = DateUtils.getTimeList(dateId);
partyMemberList.forEach(party -> {
BeanUtils.copyProperties(timeList,party);
agencyInfos.forEach(agency -> {
if (party.getGridId().equals(agency.getGridId())){
party.setAgencyId(agency.getAgencyId());
party.setParentId(agency.getParentId());
party.setPids(agency.getPids());
}
if ((StringUtils.isBlank(customerIdAndDateIdFormDTO.getStartDate()) && StringUtils.isBlank(customerIdAndDateIdFormDTO.getEndDate()))){
dateIds.add(DimIdGenerator.getDateDimId(DateUtils.addDateDays(new Date(), -1)));
}else {
dateIds = DateUtils.getDaysBetween(customerIdAndDateIdFormDTO.getStartDate(), customerIdAndDateIdFormDTO.getEndDate());
}
List<String> finalDateIds = dateIds;
customerIds.forEach(customerId -> {
finalDateIds.forEach(dateId -> {
List<DimCustomerPartyMemberFormDTO> partyMemberList = partyMemberService.selectPartyMemberInfo(customerId, dateId);
if (CollectionUtils.isEmpty(partyMemberList)){
log.warn(String.format(StatsConstant.PARTY_INFO_LIST,customerId));
return;
}
List<String> gridIds = partyMemberList.stream().map(party -> party.getGridId()).distinct().collect(Collectors.toList());
List<GridBelongAgencyResultDTO> agencyInfos = dimGridService.selectGridBelongAgencyInfo(gridIds);
TimeListResultDTO timeList = DateUtils.getTimeList(dateId);
partyMemberList.forEach(party -> {
BeanUtils.copyProperties(timeList,party);
agencyInfos.forEach(agency -> {
if (party.getGridId().equals(agency.getGridId())){
party.setAgencyId(agency.getAgencyId());
party.setParentId(agency.getParentId());
party.setPids(agency.getPids());
}
});
});
delAndInsertParty(partyMemberList,customerId,dateId);
});
delAndInsertParty(partyMemberList,customerId,dateId);
});
return true;
}

16
epmet-module/epmet-job/epmet-job-server/src/main/java/com/epmet/service/impl/DimPartyMemberServiceImpl.java

@ -1,7 +1,6 @@
package com.epmet.service.impl;
import com.alibaba.druid.util.StringUtils;
import com.epmet.commons.tools.constant.NumConstant;
import com.alibaba.fastjson.JSON;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.stats.form.CustomerIdAndDateIdFormDTO;
import com.epmet.feign.DataStatisticalOpenFeignClient;
@ -23,15 +22,8 @@ public class DimPartyMemberServiceImpl implements DimPartyMemberService {
@Override
public Result getPartyInfo(String dateId) {
CustomerIdAndDateIdFormDTO c = new CustomerIdAndDateIdFormDTO();
if (!StringUtils.isEmpty(dateId)) {
c.setDateId(dateId);
}else {
String now = LocalDate.now().minusDays(NumConstant.ONE).toString();
String concat = now.substring(NumConstant.ZERO, NumConstant.FOUR).concat(now.substring(NumConstant.FIVE, NumConstant.SEVEN)).concat(now.substring(NumConstant.EIGHT, NumConstant.TEN));
c.setDateId(concat);
}
return statsFeignClient.getPartyInfo(c);
public Result getPartyInfo(String form) {
CustomerIdAndDateIdFormDTO customerIdAndDateIdFormDTO = JSON.parseObject(form, CustomerIdAndDateIdFormDTO.class);
return statsFeignClient.getPartyInfo(customerIdAndDateIdFormDTO);
}
}

Loading…
Cancel
Save