|
|
@ -1,14 +1,26 @@ |
|
|
|
package com.epmet.datareport.service.screen.impl; |
|
|
|
|
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.datareport.dao.screen.ScreenCpcBaseDataDao; |
|
|
|
import com.epmet.datareport.dao.screen.ScreenPartyBranchDataDao; |
|
|
|
import com.epmet.datareport.dao.screen.ScreenUserTotalDataDao; |
|
|
|
import com.epmet.screen.dto.form.BranchBuildTrendFormDTO; |
|
|
|
import com.epmet.screen.dto.form.ParymemberFormDTO; |
|
|
|
import com.epmet.screen.dto.result.PartymemberPercentResultDTO; |
|
|
|
import com.epmet.screen.dto.result.*; |
|
|
|
import com.epmet.datareport.service.screen.GrassrootsPartyDevService; |
|
|
|
import com.google.common.collect.Maps; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 基层党建相关各指标查询 |
|
|
|
* |
|
|
@ -22,6 +34,11 @@ public class GrassrootsPartyDevServiceImpl implements GrassrootsPartyDevService |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ScreenUserTotalDataDao screenUserTotalDataDao; |
|
|
|
@Autowired |
|
|
|
private ScreenCpcBaseDataDao screenCpcBaseDataDao; |
|
|
|
@Autowired |
|
|
|
private ScreenPartyBranchDataDao screenPartyBranchDataDao; |
|
|
|
private List<String> issueGroup; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 1、党员基本情况-饼状图概况 |
|
|
@ -35,7 +52,203 @@ public class GrassrootsPartyDevServiceImpl implements GrassrootsPartyDevService |
|
|
|
public PartymemberPercentResultDTO partymemberBaseInfo(ParymemberFormDTO param) { |
|
|
|
|
|
|
|
PartymemberPercentResultDTO result = screenUserTotalDataDao.selectAgencyPartymemberPercent(param.getAgencyId()); |
|
|
|
if(null == result){ |
|
|
|
logger.warn("com.epmet.datareport.service.screen.impl.GrassrootsPartyDevServiceImpl.partymemberBaseInfo:未查询出指定agencyId下的党员基础信息数据,agencyId :: {}",param.getAgencyId()); |
|
|
|
result.setPercentInPlatForm(convertPercentStr(BigDecimal.ZERO)); |
|
|
|
return result; |
|
|
|
} |
|
|
|
//partymember / platform
|
|
|
|
if(null == result.getPlatFormTotal() || NumConstant.ZERO == result.getPlatFormTotal()){ |
|
|
|
result.setPercentInPlatForm(convertPercentStr(BigDecimal.ZERO)); |
|
|
|
}else{ |
|
|
|
result.setPercentInPlatForm(convertPercentStr(new BigDecimal(result.getPartyMemberTotal()/result.getPlatFormTotal()))); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 2、党员基本情况-年龄分布 |
|
|
|
* @NEI https://nei.netease.com/interface/detail/req/?pid=57068&id=321980
|
|
|
|
* @param param |
|
|
|
* @return |
|
|
|
* @author wangc |
|
|
|
* @date 2020.08.18 17:54 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public PartymemberAgeDistributionResultDTO partymemberAgeDistribution(ParymemberFormDTO param) { |
|
|
|
PartymemberAgePercentResultDTO percent = screenCpcBaseDataDao.selectPartymemberAgeDistribution(param.getAgencyId()); |
|
|
|
PartymemberAgeDistributionResultDTO result = new PartymemberAgeDistributionResultDTO(); |
|
|
|
|
|
|
|
if(null == percent.getUnder30Ratio()) percent.setUnder30Ratio(new BigDecimal(NumConstant.ZERO)); |
|
|
|
result.setUnder30Ratio(convertPercentStr(percent.getUnder30Ratio())); |
|
|
|
|
|
|
|
if(null == percent.getBetween31And50Ratio()) percent.setBetween31And50Ratio(new BigDecimal(NumConstant.ZERO)); |
|
|
|
result.setBetween31And50Ratio(convertPercentStr(percent.getBetween31And50Ratio())); |
|
|
|
|
|
|
|
if(null == percent.getBetween51And60Ratio()) percent.setBetween51And60Ratio(new BigDecimal(NumConstant.ZERO)); |
|
|
|
result.setBetween51And60Ratio(convertPercentStr(percent.getBetween51And60Ratio())); |
|
|
|
|
|
|
|
if(null == percent.getAbove61()) percent.setAbove61(new BigDecimal(NumConstant.ZERO)); |
|
|
|
result.setAbove61(convertPercentStr(percent.getAbove61())); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 3、支部建设情况|联建共建情况-折线图 |
|
|
|
* @NEI https://nei.netease.com/interface/detail/req/?pid=57068&id=321981
|
|
|
|
* @param param |
|
|
|
* @return BranchBuildTrendResultDTO |
|
|
|
* @author wangc |
|
|
|
* @date 2020.08.19 11:02 |
|
|
|
**/ |
|
|
|
@Override |
|
|
|
public BranchBuildTrendResultDTO branchBuildTrend(BranchBuildTrendFormDTO param) { |
|
|
|
if(StringUtils.equals("ljgj",param.getCategory())){ |
|
|
|
//联建共建情况
|
|
|
|
param.setCategory("union"); |
|
|
|
}else if(StringUtils.equals("ljdyzy",param.getCategory())){ |
|
|
|
//联建党员志愿服务情况
|
|
|
|
param.setCategory("voluntaryservice"); |
|
|
|
}else{ |
|
|
|
//默认支部建设
|
|
|
|
param.setCategory("party"); |
|
|
|
} |
|
|
|
BranchBuildTrendResultDTO result = new BranchBuildTrendResultDTO(); |
|
|
|
//生成近十二个月的横坐标数组
|
|
|
|
Map<String,String> monthMap = getX(); |
|
|
|
result.setXAxis(monthMap.values().stream().collect(Collectors.toList())); |
|
|
|
|
|
|
|
List<BranchTrendSeriesDataResultDTO> dataArray = new LinkedList<>(); |
|
|
|
List<BranchIssueDataResultDTO> yearlyDataList = |
|
|
|
screenPartyBranchDataDao.selectBranchDataByTypeAndTimeZone(param.getAgencyId(),param.getType(),param.getCategory(),monthMap.keySet().iterator().next()); |
|
|
|
|
|
|
|
|
|
|
|
if(null != yearlyDataList && !yearlyDataList.isEmpty()){ |
|
|
|
|
|
|
|
Map<String,List<BranchIssueDataResultDTO>> dataMapByIssue = |
|
|
|
yearlyDataList.stream().collect(Collectors.groupingBy(BranchIssueDataResultDTO::getIssue)); |
|
|
|
|
|
|
|
|
|
|
|
result.setLegend(new LinkedList<>(dataMapByIssue.keySet())); |
|
|
|
|
|
|
|
dataMapByIssue.forEach((issue,val) ->{ |
|
|
|
List<BranchIssueDataResultDTO> issueYearlyDataList = val; |
|
|
|
List<Integer> numArray = new LinkedList<>(); |
|
|
|
BranchTrendSeriesDataResultDTO data = new BranchTrendSeriesDataResultDTO(); |
|
|
|
data.setName(issue); |
|
|
|
if(null != issueYearlyDataList && issueYearlyDataList.isEmpty()){ |
|
|
|
monthMap.keySet().forEach( monthId ->{ |
|
|
|
Optional<BranchIssueDataResultDTO> optional |
|
|
|
= issueYearlyDataList.stream().filter(yearly -> StringUtils.equals(monthId,yearly.getMonthId())).findAny(); |
|
|
|
if(optional.isPresent()){ |
|
|
|
numArray.add(optional.get().getData()); |
|
|
|
}else{ |
|
|
|
numArray.add(NumConstant.ZERO); |
|
|
|
} |
|
|
|
}); |
|
|
|
}else{ |
|
|
|
for(int i = NumConstant.ZERO ; i < NumConstant.TWELVE ; i++){ |
|
|
|
numArray.add(NumConstant.ZERO); |
|
|
|
} |
|
|
|
} |
|
|
|
dataArray.add(data); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
result.setSeriesData(dataArray); |
|
|
|
result.setLegend(null == result.getLegend() ? new ArrayList<>() : result.getLegend()); |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String convertPercentStr(BigDecimal percent){ |
|
|
|
if(null == percent || BigDecimal.ZERO == percent) return "0.00%"; |
|
|
|
String percentStr = percent.setScale(NumConstant.TWO, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString(); |
|
|
|
return percentStr.concat("%"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 返回当前月以及前十一个月,升序 |
|
|
|
* @param |
|
|
|
* @return Map<String,String> key:202001 value:1月 |
|
|
|
* @author wangc |
|
|
|
* @date 2020.08.19 12:46 |
|
|
|
**/ |
|
|
|
private Map<String,String> getX(){ |
|
|
|
SimpleDateFormat format = new SimpleDateFormat("YYYYmm"); |
|
|
|
Calendar calendar = Calendar.getInstance(); |
|
|
|
calendar.setTime(new Date()); // 设置为当前时间
|
|
|
|
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
|
|
|
|
String currentMonth = format.format(calendar.getTime()); |
|
|
|
Integer monthCounter = Integer.parseInt(currentMonth); |
|
|
|
Map<String,String> monthMap = new HashMap<>(); |
|
|
|
int i = NumConstant.ONE; |
|
|
|
while(i <= NumConstant.TWELVE){ |
|
|
|
|
|
|
|
if(monthCounter.toString().endsWith("00")){ |
|
|
|
monthCounter -= NumConstant.EIGHTY_EIGHT; |
|
|
|
} |
|
|
|
|
|
|
|
String abscissa = monthCounter.toString().substring(monthCounter.toString().length() - NumConstant.TWO); |
|
|
|
if(abscissa.startsWith("0")) { |
|
|
|
abscissa = abscissa.replace("0","").concat("月"); |
|
|
|
}else{ |
|
|
|
abscissa = abscissa.concat("月"); |
|
|
|
} |
|
|
|
monthMap.put(monthCounter.toString(),abscissa); |
|
|
|
monthCounter-- ; |
|
|
|
i++; |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, String> result = Maps.newLinkedHashMap(); |
|
|
|
monthMap.entrySet().stream().sorted(Map.Entry.comparingByKey()) |
|
|
|
.forEachOrdered((e -> result.put(e.getKey(),e.getValue()))); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMM"); |
|
|
|
String currentMonth = format.format(new Date()); |
|
|
|
Integer monthCounter = Integer.parseInt(currentMonth); |
|
|
|
Map<String,String> monthMap = new HashMap<>(); |
|
|
|
int i = NumConstant.ONE; |
|
|
|
while(i <= NumConstant.TWELVE){ |
|
|
|
|
|
|
|
if(monthCounter.toString().endsWith("00")){ |
|
|
|
monthCounter -= NumConstant.EIGHTY_EIGHT; |
|
|
|
} |
|
|
|
|
|
|
|
String abscissa = monthCounter.toString().substring(monthCounter.toString().length() - NumConstant.TWO); |
|
|
|
if(abscissa.startsWith("0")) { |
|
|
|
abscissa = abscissa.replace("0","").concat("月"); |
|
|
|
}else{ |
|
|
|
abscissa = abscissa.concat("月"); |
|
|
|
} |
|
|
|
monthMap.put(monthCounter.toString(),abscissa); |
|
|
|
monthCounter-- ; |
|
|
|
i++; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> result = Maps.newLinkedHashMap(); |
|
|
|
monthMap.entrySet().stream().sorted(Map.Entry.<String,String>comparingByKey()) |
|
|
|
.forEachOrdered((e -> result.put(e.getKey(),e.getValue()))); |
|
|
|
result.forEach((k,v) -> { |
|
|
|
System.out.print(k); |
|
|
|
System.out.print(" -> "); |
|
|
|
System.out.print(v); |
|
|
|
System.out.println(); |
|
|
|
}); |
|
|
|
|
|
|
|
List<String> xLine = result.values().stream().collect(Collectors.toList()); |
|
|
|
xLine.forEach(x -> { |
|
|
|
System.out.println(x); |
|
|
|
}); |
|
|
|
|
|
|
|
result.keySet().forEach(key -> System.out.println(key)); |
|
|
|
} |
|
|
|
} |
|
|
|