|  |  | @ -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; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
	
		
			
				
					|  |  | 
 |