|
|
@ -1,12 +1,29 @@ |
|
|
|
package com.epmet.service.evaluationindex.extract.toscreen.impl; |
|
|
|
|
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.dto.extract.form.PartyBaseInfoFormDTO; |
|
|
|
import com.epmet.dto.extract.result.CustomerAgencyInfoResultDTO; |
|
|
|
import com.epmet.dto.extract.result.PartyMemberInfoResultDTO; |
|
|
|
import com.epmet.dto.extract.result.UserCountResultDTO; |
|
|
|
import com.epmet.service.evaluationindex.extract.toscreen.PartyBaseInfoService; |
|
|
|
import com.epmet.service.evaluationindex.screen.ScreenCpcBaseDataService; |
|
|
|
import com.epmet.service.evaluationindex.screen.ScreenCustomerAgencyService; |
|
|
|
import com.epmet.service.stats.DimCustomerPartymemberService; |
|
|
|
import com.epmet.service.stats.user.FactParticipationUserAgencyDailyService; |
|
|
|
import com.epmet.service.stats.user.FactParticipationUserGridDailyService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import com.epmet.constant.ScreenConstant; |
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Desciption 党员基本情况 |
|
|
@ -19,6 +36,14 @@ public class PartyBaseInfoServiceImpl implements PartyBaseInfoService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ScreenCustomerAgencyService agencyService; |
|
|
|
@Autowired |
|
|
|
private DimCustomerPartymemberService partyMemberService; |
|
|
|
@Autowired |
|
|
|
private FactParticipationUserGridDailyService userGridDailyService; |
|
|
|
@Autowired |
|
|
|
private FactParticipationUserAgencyDailyService userAgencyDailyService; |
|
|
|
@Autowired |
|
|
|
private ScreenCpcBaseDataService cpcBaseDataService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 统计基层党建-党员基本情况 |
|
|
@ -29,9 +54,187 @@ public class PartyBaseInfoServiceImpl implements PartyBaseInfoService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Boolean statsPartyMemberBaseInfoToScreen(String customerId, String dateId) { |
|
|
|
String agencyId = "cyagstrbee8711eaa1fac03fd56f7847"; |
|
|
|
Map<String, Object> stringObjectMap = agencyService.selectAllSubAgencyId(agencyId, customerId); |
|
|
|
System.out.println(stringObjectMap); |
|
|
|
return null; |
|
|
|
List<CustomerAgencyInfoResultDTO> agencyIdList = agencyService.selectAllAgencyId(customerId); |
|
|
|
if (!CollectionUtils.isEmpty(agencyIdList)){ |
|
|
|
Map<String, List<CustomerAgencyInfoResultDTO>> groupByLevel = agencyIdList.stream().collect(Collectors.groupingBy(CustomerAgencyInfoResultDTO::getLevel)); |
|
|
|
if (groupByLevel.containsKey(ScreenConstant.COMMUNITY)){ |
|
|
|
List<CustomerAgencyInfoResultDTO> customerGridInfoList = groupByLevel.get(ScreenConstant.COMMUNITY); |
|
|
|
disPose(customerGridInfoList,true,customerId,dateId); |
|
|
|
}else if (groupByLevel.containsKey(ScreenConstant.STREET)){ |
|
|
|
List<CustomerAgencyInfoResultDTO> customerGridInfoList = groupByLevel.get(ScreenConstant.STREET); |
|
|
|
disPose(customerGridInfoList,false,customerId,dateId); |
|
|
|
}else if (groupByLevel.containsKey(ScreenConstant.DISTRICT)){ |
|
|
|
List<CustomerAgencyInfoResultDTO> customerGridInfoList = groupByLevel.get(ScreenConstant.DISTRICT); |
|
|
|
disPose(customerGridInfoList,false,customerId,dateId); |
|
|
|
}else if (groupByLevel.containsKey(ScreenConstant.CITY)){ |
|
|
|
List<CustomerAgencyInfoResultDTO> customerGridInfoList = groupByLevel.get(ScreenConstant.CITY); |
|
|
|
disPose(customerGridInfoList,false,customerId,dateId); |
|
|
|
}else if (groupByLevel.containsKey(ScreenConstant.PROVINCE)){ |
|
|
|
List<CustomerAgencyInfoResultDTO> customerGridInfoList = groupByLevel.get(ScreenConstant.PROVINCE); |
|
|
|
disPose(customerGridInfoList,false,customerId,dateId); |
|
|
|
}else { |
|
|
|
// TODO 干啥
|
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description |
|
|
|
* @param isGrid true:level = community |
|
|
|
* @author zxc |
|
|
|
* @date 2020/9/22 4:48 下午 |
|
|
|
*/ |
|
|
|
public void disPose(List<CustomerAgencyInfoResultDTO> agencyIdList, Boolean isGrid, String customerId, String dateId){ |
|
|
|
if (!CollectionUtils.isEmpty(agencyIdList)){ |
|
|
|
List<PartyBaseInfoFormDTO> result = new ArrayList<>(); |
|
|
|
if (isGrid == true){ |
|
|
|
List<UserCountResultDTO> userCountList = userGridDailyService.selectUserCount(customerId, dateId); |
|
|
|
agencyIdList.forEach(agency -> { |
|
|
|
// 1. 处理社区下的所有网格中的党员信息
|
|
|
|
String agencyId = agency.getAgencyId(); |
|
|
|
Map<String, Object> agencyMap = agencyService.selectAllSubAgencyId(agencyId, customerId); |
|
|
|
List<String> gridIds = (List<String>) agencyMap.get(agencyId); |
|
|
|
List<PartyMemberInfoResultDTO> partyMemberInfoList = partyMemberService.selectPartyMemberInfo(customerId, gridIds); |
|
|
|
if (!CollectionUtils.isEmpty(partyMemberInfoList)){ |
|
|
|
partyMemberInfoList.forEach(party -> { |
|
|
|
party.setAge(getAge(party.getBirthday())); |
|
|
|
}); |
|
|
|
Map<String, List<PartyMemberInfoResultDTO>> groupByGridId = partyMemberInfoList.stream().collect(Collectors.groupingBy(PartyMemberInfoResultDTO::getGridId)); |
|
|
|
groupByGridId.forEach((gridId,partyInfos) -> { |
|
|
|
PartyBaseInfoFormDTO form = new PartyBaseInfoFormDTO(); |
|
|
|
form.setOrgType(ScreenConstant.GRID); |
|
|
|
form.setOrgId(gridId); |
|
|
|
form.setOrgName(partyInfos.get(NumConstant.ZERO).getGridName()); |
|
|
|
form.setAgeLevel1(disposeAge(partyInfos,NumConstant.TWENTY,false)); |
|
|
|
form.setAgeLevel2(disposeAgeArea(partyInfos,NumConstant.TWENTY,NumConstant.THIRTY)); |
|
|
|
form.setAgeLevel3(disposeAgeArea(partyInfos,NumConstant.THIRTY_ONE,NumConstant.FORTY)); |
|
|
|
form.setAgeLevel4(disposeAgeArea(partyInfos,NumConstant.FORTY_ONE,NumConstant.FIFTY)); |
|
|
|
form.setAgeLevel5(disposeAgeArea(partyInfos,NumConstant.FIFTY_ONE,NumConstant.SIXTY)); |
|
|
|
form.setAgeLevel6(disposeAge(partyInfos,NumConstant.SIXTY,true)); |
|
|
|
form.setCustomerId(customerId); |
|
|
|
form.setDataEndTime(dateId); |
|
|
|
form.setParentId(partyInfos.get(NumConstant.ZERO).getAgencyId()); |
|
|
|
if (!CollectionUtils.isEmpty(userCountList)){ |
|
|
|
userCountList.forEach(user -> { |
|
|
|
if (gridId.equals(user.getOrgId())){ |
|
|
|
form.setResiTotal(user.getResiTotal()); |
|
|
|
form.setRegisterUserCount(user.getRegisterUserCount()); |
|
|
|
form.setPartyMemberCount(user.getPartyMemberCount()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
result.add(form); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
// 2. 处理社区级别的党员信息
|
|
|
|
Map<String, List<PartyBaseInfoFormDTO>> groupByAgency = result.stream().collect(Collectors.groupingBy(PartyBaseInfoFormDTO::getParentId)); |
|
|
|
groupByAgency.forEach((commAgencyId,party) -> { |
|
|
|
PartyBaseInfoFormDTO form = new PartyBaseInfoFormDTO(); |
|
|
|
form.setOrgName(party.get(NumConstant.ZERO).getOrgName()); |
|
|
|
form.setOrgId(commAgencyId); |
|
|
|
form.setOrgType(ScreenConstant.AGENCY); |
|
|
|
form.setParentId(party.get(NumConstant.ZERO).getParentId()); |
|
|
|
form.setAgeLevel1(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getAgeLevel1))); |
|
|
|
form.setAgeLevel2(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getAgeLevel2))); |
|
|
|
form.setAgeLevel3(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getAgeLevel3))); |
|
|
|
form.setAgeLevel4(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getAgeLevel4))); |
|
|
|
form.setAgeLevel5(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getAgeLevel5))); |
|
|
|
form.setAgeLevel6(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getAgeLevel6))); |
|
|
|
form.setPartyMemberCount(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getPartyMemberCount))); |
|
|
|
form.setResiTotal(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getResiTotal))); |
|
|
|
form.setRegisterUserCount(party.stream().collect(Collectors.summingInt(PartyBaseInfoFormDTO::getRegisterUserCount))); |
|
|
|
result.add(form); |
|
|
|
}); |
|
|
|
delAndInsert(result,customerId,dateId); |
|
|
|
}else { |
|
|
|
List<UserCountResultDTO> userCountRList = userAgencyDailyService.selectUserCount(customerId, dateId); |
|
|
|
agencyIdList.forEach(agency -> { |
|
|
|
String agencyId = agency.getAgencyId(); |
|
|
|
Map<String, Object> agencyMap = agencyService.selectAllSubAgencyId(agencyId, customerId); |
|
|
|
List<String> agencyIds = (List<String>) agencyMap.get(agencyId); |
|
|
|
// todo
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 根据生日计算年龄 |
|
|
|
* @param birthday |
|
|
|
* @author zxc |
|
|
|
* @date 2020/9/22 5:34 下午 |
|
|
|
*/ |
|
|
|
public Integer getAge(Date birthday){ |
|
|
|
LocalDate now = LocalDate.now(); |
|
|
|
int nowYear = now.getYear(); |
|
|
|
int nowMonth = now.getMonthValue(); |
|
|
|
int nowDayOfMonth = now.getDayOfMonth(); |
|
|
|
LocalDate birth = birthday.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); |
|
|
|
int birthDayYear = birth.getYear(); |
|
|
|
int birthDayMonth = birth.getMonthValue(); |
|
|
|
int birthDayOfMonth = birth.getDayOfMonth(); |
|
|
|
int age = nowYear - birthDayYear; |
|
|
|
if (nowMonth < birthDayMonth || (nowMonth == birthDayMonth && nowDayOfMonth < birthDayOfMonth)) { |
|
|
|
age--; |
|
|
|
} |
|
|
|
return age; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 处理年龄段之间的人数 |
|
|
|
* @param partyMemberInfoList |
|
|
|
* @param startAge |
|
|
|
* @param endAge |
|
|
|
* @author zxc |
|
|
|
* @date 2020/9/22 5:45 下午 |
|
|
|
*/ |
|
|
|
public Integer disposeAgeArea(List<PartyMemberInfoResultDTO> partyMemberInfoList, Integer startAge,Integer endAge ){ |
|
|
|
if (!CollectionUtils.isEmpty(partyMemberInfoList)){ |
|
|
|
List<PartyMemberInfoResultDTO> collect = partyMemberInfoList.stream().filter(p -> p.getAge() >= startAge).filter(p -> p.getAge() <= endAge).collect(Collectors.toList()); |
|
|
|
return collect.size(); |
|
|
|
} |
|
|
|
return NumConstant.ZERO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 计算 大于/小于 年龄的人数 |
|
|
|
* @param partyMemberInfoList |
|
|
|
* @param age |
|
|
|
* @param isGreater 是否是 大于 |
|
|
|
* @author zxc |
|
|
|
* @date 2020/9/22 5:49 下午 |
|
|
|
*/ |
|
|
|
public Integer disposeAge(List<PartyMemberInfoResultDTO> partyMemberInfoList, Integer age , Boolean isGreater){ |
|
|
|
if (!CollectionUtils.isEmpty(partyMemberInfoList)){ |
|
|
|
List<PartyMemberInfoResultDTO> collect = new ArrayList<>(); |
|
|
|
if (isGreater == true){ |
|
|
|
collect = partyMemberInfoList.stream().filter(p -> p.getAge() > age).collect(Collectors.toList()); |
|
|
|
}else { |
|
|
|
collect = partyMemberInfoList.stream().filter(p -> p.getAge() < age).collect(Collectors.toList()); |
|
|
|
} |
|
|
|
return collect.size(); |
|
|
|
} |
|
|
|
return NumConstant.ZERO; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description |
|
|
|
* @param result |
|
|
|
* @param customerId |
|
|
|
* @param dateId |
|
|
|
* @author zxc |
|
|
|
* @date 2020/9/23 10:13 上午 |
|
|
|
*/ |
|
|
|
public void delAndInsert(List<PartyBaseInfoFormDTO> result, String customerId, String dateId){ |
|
|
|
if (!CollectionUtils.isEmpty(result)){ |
|
|
|
List<String> orgIds = result.stream().map(m -> m.getOrgId()).collect(Collectors.toList()); |
|
|
|
Integer delNum; |
|
|
|
do { |
|
|
|
delNum = cpcBaseDataService.deleteOldPartyBaseInfo(customerId, dateId, orgIds); |
|
|
|
}while (delNum > NumConstant.ZERO); |
|
|
|
cpcBaseDataService.insertPartyBaseInfo(result); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|