diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/screen/ScreenIndexDataMonthlyDao.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/screen/ScreenIndexDataMonthlyDao.java index 028fbf6142..57f0398615 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/screen/ScreenIndexDataMonthlyDao.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/dao/screen/ScreenIndexDataMonthlyDao.java @@ -42,7 +42,7 @@ public interface ScreenIndexDataMonthlyDao{ * @author zxc * @date 2020/8/19 3:43 下午 */ - MonthPieChartResultDTO selectMonthPieChart(@Param("agencyId")String agencyId); + MonthPieChartResultDTO selectMonthPieChart(@Param("agencyId")String agencyId,@Param("monthId")String monthId); /** * @Description 查询近一年的指数值【不包括本月】 diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/GrassRootsGovernServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/GrassRootsGovernServiceImpl.java index f798d5047e..c1ad6a3eca 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/GrassRootsGovernServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/GrassRootsGovernServiceImpl.java @@ -15,6 +15,7 @@ import com.epmet.screen.dto.result.*; import com.github.pagehelper.PageHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.ArrayList; @@ -41,8 +42,6 @@ public class GrassRootsGovernServiceImpl implements GrassRootsGovernService { @Autowired private DateUtils dateUtils; @Autowired - private ScreenUserTotalDataDao screenUserTotalDataDao; - @Autowired private ScreenGovernRankDataDao screenGovernRankDataDao; @Autowired private ScreenPublicPartiTotalDataDao screenPublicPartiTotalDataDao; @@ -106,6 +105,15 @@ public class GrassRootsGovernServiceImpl implements GrassRootsGovernService { String monthId = dateUtils.getCurrentMonthId(); UserJoinIndicatorGrowthRateResultDTO latest = screenUserJoinDao.selectUserJoinData(param.getAgencyId(), monthId); + //保证获取公众参与概率数据的最大可能性 + int time = NumConstant.TWELVE; + while(null == latest && time > NumConstant.ONE) + { + time --; + monthId = dateUtils.getPreviousMonthIdByDest(null,monthId); + latest = screenUserJoinDao.selectUserJoinData(param.getAgencyId(), monthId); + } + if(null == latest) return new PublicPartiProfileResultDTO(); PublicPartiProfileResultDTO result = ConvertUtils.sourceToTarget(latest,PublicPartiProfileResultDTO.class); result.setMonthIncr(convertPercentStr(latest.getMonthIncr(),NumConstant.ZERO)); @@ -153,8 +161,16 @@ public class GrassRootsGovernServiceImpl implements GrassRootsGovernService { if(null == param.getTopNum()) param.setTopNum(NumConstant.FIVE); if(NumConstant.ZERO == param.getTopNum()) param.setTopNum(NumConstant.MAX); PageHelper.startPage(NumConstant.ONE,param.getTopNum()); + String monthId = dateUtils.getCurrentMonthId(); List orderList = - screenGovernRankDataDao.selectGovernCapacityRatio(dateUtils.getCurrentMonthId(),param.getAgencyId()); + screenGovernRankDataDao.selectGovernCapacityRatio(monthId,param.getAgencyId()); + int time = NumConstant.TWELVE; + while(CollectionUtils.isEmpty(orderList) && time > NumConstant.ONE){ + time--; + monthId = dateUtils.getPreviousMonthIdByDest(null ,monthId); + orderList = + screenGovernRankDataDao.selectGovernCapacityRatio(monthId,param.getAgencyId()); + } if(null == orderList || orderList.isEmpty()) return new ArrayList<>(); List result = new LinkedList<>(); orderList.forEach(o -> { diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/GrassrootsPartyDevServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/GrassrootsPartyDevServiceImpl.java index 4fa8a23c20..a4cbbc87da 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/GrassrootsPartyDevServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/GrassrootsPartyDevServiceImpl.java @@ -20,6 +20,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.text.SimpleDateFormat; @@ -112,7 +113,7 @@ public class GrassrootsPartyDevServiceImpl implements GrassrootsPartyDevService } BranchBuildTrendResultDTO result = new BranchBuildTrendResultDTO(); //生成近十二个月的横坐标数组 - Map monthMap = getX(); + Map monthMap = dateUtils.getXpro(); result.setXAxis(monthMap.values().stream().collect(Collectors.toList())); List dataArray = new LinkedList<>(); @@ -155,12 +156,22 @@ public class GrassrootsPartyDevServiceImpl implements GrassrootsPartyDevService result.setSeriesData(dataArray); result.setLegend(null == result.getLegend() ? new ArrayList<>() : result.getLegend()); + List _ymList = monthMap.keySet().stream().collect(Collectors.toList()); //总组织次数 Integer totalOrganizationCount = screenPartyBranchDataDao.selectTotalOrganizationCount(param.getCategory(),ModuleConstant.PARAM_BRANCH_DATA_TYPE_ORGAN,param.getAgencyId(),monthMap.keySet().iterator().next()); + //自旋一次 + totalOrganizationCount = Optional.ofNullable(totalOrganizationCount).orElse( + screenPartyBranchDataDao.selectTotalOrganizationCount(param.getCategory(),ModuleConstant.PARAM_BRANCH_DATA_TYPE_ORGAN,param.getAgencyId(),_ymList.get(NumConstant.ONE)) + ); //总参与人数 Integer totalJoinUserCount = screenPartyBranchDataDao.selectTotalOrganizationCount(param.getCategory(),ModuleConstant.PARAM_BRANCH_DATA_TYPE_JOIN,param.getAgencyId(),monthMap.keySet().iterator().next()); - result.setTotalOrganizationCount(null == totalOrganizationCount ? NumConstant.ZERO : totalOrganizationCount); - result.setTotalJoinUserCount(null == totalJoinUserCount ? NumConstant.ZERO : totalJoinUserCount); + //自旋一次 + totalJoinUserCount = Optional.ofNullable(totalJoinUserCount).orElse( + screenPartyBranchDataDao.selectTotalOrganizationCount(param.getCategory(),ModuleConstant.PARAM_BRANCH_DATA_TYPE_JOIN,param.getAgencyId(),_ymList.get(NumConstant.ONE)) + ); + + result.setTotalOrganizationCount(Optional.ofNullable(totalOrganizationCount).orElse(NumConstant.ZERO)); + result.setTotalJoinUserCount(Optional.ofNullable(totalJoinUserCount).orElse(NumConstant.ZERO)); return result; } @@ -193,6 +204,15 @@ public class GrassrootsPartyDevServiceImpl implements GrassrootsPartyDevService List orderList = screenPartyBranchDataDao.selectBranchDataByTypeOrder(param.getAgencyId(),param.getCategory(),param.getMonthId(),param.getBottomMonthId()); + int time = NumConstant.TWELVE; + while(CollectionUtils.isEmpty(orderList) && time > NumConstant.ONE){ + time --; + param.setMonthId(dateUtils.getPreviousMonthIdByDest(null,param.getMonthId())); + orderList = + screenPartyBranchDataDao.selectBranchDataByTypeOrder(param.getAgencyId(),param.getCategory(),param.getMonthId(),param.getBottomMonthId()); + } + + BranchBuildRankResultDTO result = new BranchBuildRankResultDTO(); result.setJoinData(new LinkedList<>()); result.setOrganizeData(new LinkedList<>()); @@ -212,59 +232,6 @@ public class GrassrootsPartyDevServiceImpl implements GrassrootsPartyDevService return percentStr.concat(ModuleConstant.SYMBOL_PERCENT); } - /** - * @Description 返回当前月以及前十一个月,升序 - * @param - * @return Map key:202001 value:1月 - * @author wangc - * @date 2020.08.19 12:46 - **/ - public Map 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 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 result = Maps.newLinkedHashMap(); - monthMap.entrySet().stream().sorted(Map.Entry.comparingByKey()) - .forEachOrdered((e -> result.put(e.getKey(),e.getValue()))); - return result; - } - - - /** - * @Description 得到上个月的monthId - * @param - * @return - * @author wangc - * @date 2020.08.20 10:19 - **/ - private String getPreviousMonthId(){ - SimpleDateFormat format = new SimpleDateFormat("yyyyMM"); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(new Date()); // 设置为当前时间 - calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月 - return format.format(calendar.getTime()); - } } diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/IndexServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/IndexServiceImpl.java index a747d93c31..fa1e261128 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/IndexServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/IndexServiceImpl.java @@ -7,13 +7,16 @@ import com.epmet.constant.DataSourceConstant; import com.epmet.datareport.dao.screen.ScreenIndexDataMonthlyDao; import com.epmet.datareport.dao.screen.ScreenIndexDataYearlyDao; import com.epmet.datareport.service.screen.IndexService; +import com.epmet.datareport.utils.DateUtils; import com.epmet.screen.dto.form.MonthBarchartFormDTO; import com.epmet.screen.dto.form.MonthPieChartFormDTO; import com.epmet.screen.dto.form.SubAgencyIndexRankFormDTO; import com.epmet.screen.dto.form.YearAverageIndexFormDTO; import com.epmet.screen.dto.result.*; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.time.LocalDate; import java.util.ArrayList; @@ -36,6 +39,8 @@ public class IndexServiceImpl implements IndexService { private ScreenIndexDataMonthlyDao screenIndexDataMonthlyDao; @Autowired private PartyMemberLeadServiceImpl partyMemberLeadServiceImpl; + @Autowired + private DateUtils dateUtils; /** * @Description 1、年度平均指数 @@ -62,7 +67,16 @@ public class IndexServiceImpl implements IndexService { @DataSource(value = DataSourceConstant.STATS,datasourceNameFromArg = true) @Override public MonthPieChartResultDTO monthPieChart(MonthPieChartFormDTO monthPieChartFormDTO) { - MonthPieChartResultDTO monthPieChartResultDTO = screenIndexDataMonthlyDao.selectMonthPieChart(monthPieChartFormDTO.getAgencyId()); + + MonthPieChartResultDTO monthPieChartResultDTO = screenIndexDataMonthlyDao.selectMonthPieChart(monthPieChartFormDTO.getAgencyId(),null); + String monthId = dateUtils.getCurrentMonthId(); + int time = NumConstant.TWELVE; + //保证获取月度指数数据的最大可能性 + while(null == monthPieChartResultDTO && time > NumConstant.ONE){ + time--; + monthId = dateUtils.getPreviousMonthIdByDest(null,monthId); + monthPieChartResultDTO = screenIndexDataMonthlyDao.selectMonthPieChart(monthPieChartFormDTO.getAgencyId(),monthId); + } if (null == monthPieChartResultDTO){ return new MonthPieChartResultDTO(); } @@ -85,7 +99,7 @@ public class IndexServiceImpl implements IndexService { List totalIndexData = new ArrayList<>(); // 1. x轴 result.setXAxis(partyMemberLeadServiceImpl.getXPro()); - // 2. 查询近一年的指数值【不包括本月】 + // 2. 查询近一年的指数值【包括本月】 List monthBarchartResults = screenIndexDataMonthlyDao.selectMonthBarchart(monthBarchartFormDTO.getAgencyId()); if (monthBarchartResults.size() == NumConstant.ZERO){ for (int i = NumConstant.ZERO; i <= NumConstant.TWELVE; i++) { @@ -101,12 +115,48 @@ public class IndexServiceImpl implements IndexService { return result; } List collect = monthBarchartResults.stream().sorted(Comparator.comparing(MonthBarchartResult::getMonthId)).collect(Collectors.toList()); - collect.forEach(month -> { + //升序 当前月份在队尾 + List _ymList = dateUtils.getXpro().keySet().stream().collect(Collectors.toList()); + //针对集合collect的游标 + int cursor = NumConstant.ZERO; + //针对X轴,数据集合不全则进行数据填充 + a:for(int i = NumConstant.ZERO; i < _ymList.size(); i++){ + //这里的collect必须是有序且升序的 + if(cursor >= collect.size()) break a; + //如果存在过期数据,即从数据库中查询出超出横坐标左边界的月份值 + if(Integer.parseInt(collect.get(cursor).getMonthId()) < Integer.parseInt(_ymList.get(NumConstant.ZERO))) { + //控制当前循环重复进行 + i--; + //忽略过期数据 + cursor++; + continue ; + } + if(!StringUtils.equals(collect.get(cursor).getMonthId(),_ymList.get(i))){ + //SET DEFAULT + serviceAbilityData.add(NumConstant.ZERO_DOT_ZERO); + partyDevAbilityData.add(NumConstant.ZERO_DOT_ZERO); + governAbilityData.add(NumConstant.ZERO_DOT_ZERO); + totalIndexData.add(NumConstant.ZERO_DOT_ZERO); + //保持cursor不变 + }else{ + MonthBarchartResult data = collect.get(cursor); + //SET DATA + serviceAbilityData.add(null == data.getServiceAbility() ? NumConstant.ZERO_DOT_ZERO : data.getServiceAbility()); + partyDevAbilityData.add(null == data.getPartyDevAbility() ? NumConstant.ZERO_DOT_ZERO : data.getPartyDevAbility()); + governAbilityData.add(null == data.getGovernAbility() ? NumConstant.ZERO_DOT_ZERO : data.getGovernAbility()); + totalIndexData.add(null == data.getIndexTotal() ? NumConstant.ZERO_DOT_ZERO : data.getIndexTotal()); + //统计日期一致后移动游标 + cursor++; + } + + } + + /*collect.forEach(month -> { serviceAbilityData.add(null == month.getServiceAbility() ? NumConstant.ZERO_DOT_ZERO : month.getServiceAbility()); partyDevAbilityData.add(null == month.getPartyDevAbility() ? NumConstant.ZERO_DOT_ZERO : month.getPartyDevAbility()); governAbilityData.add(null == month.getGovernAbility() ? NumConstant.ZERO_DOT_ZERO : month.getGovernAbility()); totalIndexData.add(null == month.getIndexTotal() ? NumConstant.ZERO_DOT_ZERO : month.getIndexTotal()); - }); + });*/ result.setServiceAbilityData(serviceAbilityData); result.setPartyDevAbilityData(partyDevAbilityData); result.setGovernAbilityData(governAbilityData); @@ -127,7 +177,7 @@ public class IndexServiceImpl implements IndexService { int yearId = now.getYear(); subAgencyIndexRankFormDTO.setYearId(String.valueOf(yearId)); List subAgencyIndexRankResultDTOS = screenIndexDataMonthlyDao.selectSubAgencyIndexRank(subAgencyIndexRankFormDTO); - if (subAgencyIndexRankResultDTOS.size() == NumConstant.ZERO){ + if (CollectionUtils.isEmpty(subAgencyIndexRankResultDTOS)){ return new ArrayList<>(); } return subAgencyIndexRankResultDTOS; diff --git a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/PartyMemberLeadServiceImpl.java b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/PartyMemberLeadServiceImpl.java index b895b49651..8d85e51d8f 100644 --- a/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/PartyMemberLeadServiceImpl.java +++ b/epmet-module/data-report/data-report-server/src/main/java/com/epmet/datareport/service/screen/impl/PartyMemberLeadServiceImpl.java @@ -22,6 +22,7 @@ import com.github.pagehelper.PageHelper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.time.LocalDate; @@ -154,38 +155,35 @@ public class PartyMemberLeadServiceImpl implements PartyMemberLeadService { Optional opt = volunteerServiceResults.stream() .filter(obj -> StringUtils.equals(mm,obj.getMonthId())).findAny(); VolunteerServiceResult find = opt.isPresent() ? opt.get() : defaultObj; - //VolunteerServiceResult find = Optional.ofNullable(opt.isPresent() ? opt.get() : null).orElse(defaultObj); organizeData.add(find.getOrganizeData()); joinData.add(find.getJoinData()); averageJoinUserData.add(find.getAverageJoinUserData()); }); - /* - List collect = volunteerServiceResults.stream().sorted(Comparator.comparing(VolunteerServiceResult::getMonthId)).collect(Collectors.toList()); - collect.forEach(volunteer -> { - organizeData.add(volunteer.getOrganizeData()); - joinData.add(volunteer.getJoinData()); - averageJoinUserData.add(volunteer.getAverageJoinUserData()); - }); - */ - - result.setOrganizeData(organizeData); result.setJoinData(joinData); result.setAverageJoinUserData(averageJoinUserData); String bottomMonthId = yyyyMMList.iterator().next(); //总组织次数 Integer totalOrganizationCount = screenPartyBranchDataDao.selectTotalOrganizationCount(ModuleConstant.KEY_BRANCH_CATEGORY_VOLUNTARY_SERVICE,ModuleConstant.PARAM_BRANCH_DATA_TYPE_ORGAN,volunteerServiceFormDTO.getAgencyId(),bottomMonthId); + //自旋一次 + totalOrganizationCount = Optional.ofNullable(totalOrganizationCount).orElse( + screenPartyBranchDataDao.selectTotalOrganizationCount(ModuleConstant.KEY_BRANCH_CATEGORY_VOLUNTARY_SERVICE,ModuleConstant.PARAM_BRANCH_DATA_TYPE_ORGAN,volunteerServiceFormDTO.getAgencyId(),dateUtils.getPreviousMonthIdByDest(null,bottomMonthId)) + ); //总参与人数 Integer totalJoinUserCount = screenPartyBranchDataDao.selectTotalOrganizationCount(ModuleConstant.KEY_BRANCH_CATEGORY_VOLUNTARY_SERVICE,ModuleConstant.PARAM_BRANCH_DATA_TYPE_JOIN,volunteerServiceFormDTO.getAgencyId(),bottomMonthId); + //自旋一次 + totalJoinUserCount = Optional.ofNullable(totalJoinUserCount).orElse( + screenPartyBranchDataDao.selectTotalOrganizationCount(ModuleConstant.KEY_BRANCH_CATEGORY_VOLUNTARY_SERVICE,ModuleConstant.PARAM_BRANCH_DATA_TYPE_JOIN,volunteerServiceFormDTO.getAgencyId(),dateUtils.getPreviousMonthIdByDest(null,bottomMonthId)) + ); result.setTotalOrganizationCount(null == totalOrganizationCount ? NumConstant.ZERO : totalOrganizationCount); result.setTotalJoinUserCount(null == totalJoinUserCount ? NumConstant.ZERO : totalJoinUserCount); return result; } /** - * @Description 获取之前的12个月份【不包括当前月】 + * @Description 获取之前的12个月份【包括当前月】 * @author zxc * @date 2020/8/21 10:19 上午 */ @@ -200,6 +198,7 @@ public class PartyMemberLeadServiceImpl implements PartyMemberLeadService { return xAxis; } + /** * @Description 4、先进排行榜单-先进支部排行 * @NEI https://nei.netease.com/interface/detail/req/?pid=57068&id=321539 @@ -217,8 +216,15 @@ public class PartyMemberLeadServiceImpl implements PartyMemberLeadService { param.setTopNum(NumConstant.MAX); } PageHelper.startPage(NumConstant.ONE,param.getTopNum()); + String monthId = dateUtils.getCurrentMonthId(); List gridData = - screenOrgRankDataDao.selectGridDataMonthly(param.getAgencyId(),dateUtils.getCurrentMonthId()); + screenOrgRankDataDao.selectGridDataMonthly(param.getAgencyId(),monthId); + int time = NumConstant.TWELVE; + while(CollectionUtils.isEmpty(gridData) && time > NumConstant.ONE){ + time--; + monthId = dateUtils.getPreviousMonthIdByDest(null,monthId); + gridData = screenOrgRankDataDao.selectGridDataMonthly(param.getAgencyId(),monthId); + } List result = new LinkedList<>(); if(null == gridData || gridData.isEmpty()) return result; gridData.forEach( data -> { diff --git a/epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml b/epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml index 3adcde64e8..4122ee8d29 100644 --- a/epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml +++ b/epmet-module/data-report/data-report-server/src/main/resources/mapper/screen/ScreenIndexDataMonthlyDao.xml @@ -15,10 +15,18 @@ del_flag = '0' AND org_type = 'agency' AND org_id = #{agencyId} - AND month_id = DATE_FORMAT(NOW(),'%Y%m') + + + AND month_id = DATE_FORMAT(NOW(),'%Y%m') + + + AND month_id = #{monthId} + + + - + - SELECT org_name AS NAME, index_total AS totalIndex,