Browse Source

群组数统计代码调整

master
sunyuchao 4 years ago
parent
commit
1d0f29b3fa
  1. 18
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java
  2. 4
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/group/form/GroupTotalFormDTO.java
  3. 6
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/extract/FactOriginGroupMainDailyDao.java
  4. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/group/GroupDataDao.java
  5. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/extract/FactOriginGroupMainDailyEntity.java
  6. 2
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsGroupService.java
  7. 6
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/todata/FactOriginGroupMainDailyService.java
  8. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/todata/impl/FactOriginGroupMainDailyServiceImpl.java
  9. 5
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/group/GroupDataService.java
  10. 11
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/group/impl/GroupDataServiceImpl.java
  11. 69
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsGroupServiceImpl.java
  12. 11
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/extract/FactOriginGroupMainDailyDao.xml
  13. 10
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/group/GroupDataDao.xml

18
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/utils/DateUtils.java

@ -800,4 +800,22 @@ public class DateUtils {
}
return date;
}
/**
* 格式化日期
* @param dateStr String 字符型日期
* @param format String 格式
* @return Date 日期
*/
public static Date parseDate(String dateStr, String format) {
Date date = null;
try {
DateFormat dateFormat = new SimpleDateFormat(format);
date = dateFormat.parse(dateStr);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
}

4
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/group/form/GroupTotalFormDTO.java

@ -18,7 +18,7 @@ public class GroupTotalFormDTO implements Serializable {
*/
private String customerId = "";
/**
* 需要执行的日期格式yyyy-MM-dd2020-01-01
* 需要执行的日期格式yyyyMMdd
*/
private String date = "";
private String dateId = "";
}

6
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/evaluationindex/extract/FactOriginGroupMainDailyDao.java

@ -199,4 +199,10 @@ public interface FactOriginGroupMainDailyDao extends BaseDao<FactOriginGroupMain
*/
List<OrgStatisticsResultDTO> selectOrgGroupCount(@Param("customerId") String customerId, @Param("monthId") String monthId,
@Param("level") String level);
/**
* @Author sun
* @Description 查询客户小组维度下有效群组列表
**/
List<FactOriginGroupMainDailyEntity> selectCustomerGroupList(@Param("customerId") String customerId, @Param("dateId") String dateId);
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/group/GroupDataDao.java

@ -92,9 +92,4 @@ public interface GroupDataDao {
**/
List<FactOriginGroupMainDailyDTO> groupExtracting(@Param("customerId")String customerId,@Param("dateId") String dateId);
/**
* @Author sun
* @Description 查询客户下有效群组列表
**/
List<ResiGroupEntity> selectCustomerGroupList(@Param("customerId")String customerId);
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/entity/evaluationindex/extract/FactOriginGroupMainDailyEntity.java

@ -116,4 +116,9 @@ Ps: 如果一个小组被拒绝,当前小组的状态将永久停留在“审
*/
private Integer isOwnerParty;
/**
* 小组类型(ordinary:楼院小组 branch:支部小组)
*/
private String groupType;
}

2
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/StatsGroupService.java

@ -3,6 +3,8 @@ package com.epmet.service;
import com.epmet.dto.group.form.GroupStatsFormDTO;
import com.epmet.dto.group.form.GroupTotalFormDTO;
import java.text.ParseException;
/**
* @Author zxc
* @CreateTime 2020/6/16 14:14

6
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/todata/FactOriginGroupMainDailyService.java

@ -105,4 +105,10 @@ public interface FactOriginGroupMainDailyService extends BaseService<FactOriginG
* @return java.util.List<com.epmet.dto.extract.result.OrgStatisticsResultDTO>
*/
List<OrgStatisticsResultDTO> getOrgGroupCount(String customerId, String monthId, String level);
/**
* @Author sun
* @Description 查询客户小组维度下有效群组列表
**/
List<FactOriginGroupMainDailyEntity> getGroupListByCustomerId(String customerId, String dateId);
}

9
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/extract/todata/impl/FactOriginGroupMainDailyServiceImpl.java

@ -136,4 +136,13 @@ public class FactOriginGroupMainDailyServiceImpl extends BaseServiceImpl<FactOri
return baseDao.selectOrgGroupCount(customerId, monthId, level);
}
/**
* @Author sun
* @Description 查询客户小组维度下有效群组列表
**/
@Override
public List<FactOriginGroupMainDailyEntity> getGroupListByCustomerId(String customerId, String dateId) {
return baseDao.selectCustomerGroupList(customerId, dateId);
}
}

5
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/group/GroupDataService.java

@ -67,9 +67,4 @@ public interface GroupDataService {
**/
List<FactOriginGroupMainDailyDTO> extractGroupData(Boolean isFirst,String customerId,String dateId);
/**
* @Author sun
* @Description 查询客户下有效群组列表
**/
List<ResiGroupEntity> getGroupListByCustomerId(String customerId);
}

11
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/group/impl/GroupDataServiceImpl.java

@ -211,15 +211,4 @@ public class GroupDataServiceImpl implements GroupDataService {
return groupDataDao.groupExtracting(customerId,isFirst?null:dateId);
}
/**
* @Author sun
* @Description 查询客户下有效群组列表
**/
@Override
public List<ResiGroupEntity> getGroupListByCustomerId(String customerId) {
return groupDataDao.selectCustomerGroupList(customerId);
}
}

69
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsGroupServiceImpl.java

@ -1,6 +1,7 @@
package com.epmet.service.impl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.convert.DateConverter;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.GroupConstant;
import com.epmet.dto.AgencySubTreeDto;
@ -9,24 +10,29 @@ import com.epmet.dto.group.form.GroupStatsFormDTO;
import com.epmet.dto.group.form.GroupTotalFormDTO;
import com.epmet.dto.group.result.*;
import com.epmet.dto.stats.DimAgencyDTO;
import com.epmet.entity.evaluationindex.extract.FactOriginGroupMainDailyEntity;
import com.epmet.entity.group.ResiGroupEntity;
import com.epmet.entity.stats.DimAgencyEntity;
import com.epmet.entity.stats.DimGridEntity;
import com.epmet.entity.stats.FactGroupTotalAgencyDailyEntity;
import com.epmet.entity.stats.FactGroupTotalGridDailyEntity;
import com.epmet.service.StatsGroupService;
import com.epmet.service.evaluationindex.extract.todata.FactOriginGroupMainDailyService;
import com.epmet.service.group.GroupDataService;
import com.epmet.service.org.CustomerGridService;
import com.epmet.service.stats.*;
import com.epmet.util.DimIdGenerator;
import com.epmet.util.ModuleConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
@ -63,6 +69,8 @@ public class StatsGroupServiceImpl implements StatsGroupService {
private FactGroupTotalGridDailyService factGroupTotalGridDailyService;
@Autowired
private FactGroupTotalAgencyDailyService factGroupTotalAgencyDailyService;
@Autowired
private FactOriginGroupMainDailyService factOriginGroupMainDailyService;
/**
* @param
@ -352,15 +360,16 @@ public class StatsGroupServiceImpl implements StatsGroupService {
**/
@Override
public void gridGroupTotal(GroupTotalFormDTO formDTO) {
Date date = DateUtils.yesterDay();
//入参有日期的则按具体时间执行,没有的则按当前时间前一天执行
if (null != formDTO && StringUtils.isNotBlank(formDTO.getDate())) {
date = DateUtils.parse(formDTO.getDate(), DateUtils.DATE_PATTERN);
if (StringUtils.isBlank(formDTO.getDateId())) {
Date yesterday = DateUtils.addDateDays(new Date(), -1);
SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_PATTERN_YYYYMMDD);
formDTO.setDateId(format.format(yesterday));
}
//入参有客户Id的则按客户Id执行,没有的则全部客户都执行
if (null != formDTO && StringUtils.isNotBlank(formDTO.getCustomerId())) {
log.info("单独统计客户网格-小组总数日统计数据,当前统计的客户Id:" + formDTO.getCustomerId());
gridGroupStats(formDTO.getCustomerId(), date);
gridGroupStats(formDTO.getCustomerId(), formDTO.getDateId());
} else {
int pageNo = 1;
int pageSize = 100;
@ -373,7 +382,7 @@ public class StatsGroupServiceImpl implements StatsGroupService {
try {
log.info("for循环统计网格-小组总数日统计数据,当前统计的客户Id:" + customerId);
//遍历统计每一个客户数据
gridGroupStats(customerId, date);
gridGroupStats(customerId, formDTO.getDateId());
} catch (Exception e) {
log.error("小组总数-网格日统计-程序错误,对应客户Id:" + customerId, e);
log.error("Error creating model JSON", e);
@ -389,8 +398,9 @@ public class StatsGroupServiceImpl implements StatsGroupService {
* @Author sun
* @Description 小组总数-网格日统计数据
**/
private void gridGroupStats(String customerId, Date date) {
private void gridGroupStats(String customerId, String dateId) {
//1:查询各维度表Id,方便使用
Date date = DateUtils.parseDate(dateId,DateUtils.DATE_PATTERN_YYYYMMDD);
DimIdGenerator.DimIdBean dimId = DimIdGenerator.getDimIdBean(date);
//2:根据客户Id查询网格维度表数据
@ -399,18 +409,18 @@ public class StatsGroupServiceImpl implements StatsGroupService {
//3.根据客户Id查询客户下有效的群组列表数据
log.info("StatsGroupServiceImpl.customerGridStats-根据客户Id查询客户下有效的群组列表数据,对应客户Id:" + customerId);
List<ResiGroupEntity> groupList = groupDataService.getGroupListByCustomerId(customerId);
List<FactOriginGroupMainDailyEntity> groupList = factOriginGroupMainDailyService.getGroupListByCustomerId(customerId, dateId);
//4.分别计算每个网格下审核通过的小组数据
List<FactGroupTotalGridDailyEntity> list = new ArrayList<>();
DimIdGenerator.DimIdBean finalDimId = dimId;
dimGridList.forEach(grid -> {
FactGroupTotalGridDailyEntity entity = new FactGroupTotalGridDailyEntity();
AtomicInteger total = new AtomicInteger(0);
AtomicInteger ordinary = new AtomicInteger(0);
AtomicInteger branch = new AtomicInteger(0);
groupList.forEach(group -> {
if (grid.getId().equals(group.getGridId()) && "approved".equals(group.getState())) {
if (grid.getId().equals(group.getGridId()) && "approved".equals(group.getGroupState())) {
total.addAndGet(1);
if ("ordinary".equals(group.getGroupType())) {
ordinary.addAndGet(1);
@ -424,11 +434,11 @@ public class StatsGroupServiceImpl implements StatsGroupService {
entity.setCustomerId(grid.getCustomerId());
entity.setAgencyId(grid.getAgencyId());
entity.setGridId(grid.getId());
entity.setDateId(dimId.getDateId());
entity.setWeekId(dimId.getWeekId());
entity.setMonthId(dimId.getMonthId());
entity.setQuarterId(dimId.getQuarterId());
entity.setYearId(dimId.getYearId());
entity.setDateId(finalDimId.getDateId());
entity.setWeekId(finalDimId.getWeekId());
entity.setMonthId(finalDimId.getMonthId());
entity.setQuarterId(finalDimId.getQuarterId());
entity.setYearId(finalDimId.getYearId());
entity.setGroupTotal(total.get());
entity.setOrdinaryTotal(ordinary.get());
entity.setBranchTotal(branch.get());
@ -457,15 +467,16 @@ public class StatsGroupServiceImpl implements StatsGroupService {
**/
@Override
public void agencyGroupTotal(GroupTotalFormDTO formDTO) {
Date date = DateUtils.yesterDay();
//入参有时间的则按具体时间执行,没有的则按当前时间前一天执行
if (null != formDTO && StringUtils.isNotBlank(formDTO.getDate())) {
date = DateUtils.parse(formDTO.getDate(), DateUtils.DATE_PATTERN);
//入参有日期的则按具体时间执行,没有的则按当前时间前一天执行
if (StringUtils.isBlank(formDTO.getDateId())) {
Date yesterday = DateUtils.addDateDays(new Date(), -1);
SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_PATTERN_YYYYMMDD);
formDTO.setDateId(format.format(yesterday));
}
//入参有客户Id的则按客户Id执行,没有的则全部客户都执行
if (null != formDTO && StringUtils.isNotBlank(formDTO.getCustomerId())) {
log.info("单独统计客户组织下-小组总数日统计数据,当前统计的客户Id:" + formDTO.getCustomerId());
agencyGroupStats(formDTO.getCustomerId(), date);
agencyGroupStats(formDTO.getCustomerId(), formDTO.getDateId());
} else {
int pageNo = 1;
int pageSize = 100;
@ -477,7 +488,7 @@ public class StatsGroupServiceImpl implements StatsGroupService {
try {
log.info("for循环统计机关-小组总数日统计数据,当前统计的客户Id:" + customerId);
//遍历统计每一个客户数据
agencyGroupStats(customerId, date);
agencyGroupStats(customerId, formDTO.getDateId());
} catch (Exception e) {
log.error("小组总数-机关日统计程序错误,对应客户Id:" + customerId, e);
log.error("Error creating model JSON", e);
@ -493,8 +504,9 @@ public class StatsGroupServiceImpl implements StatsGroupService {
* @Author sun
* @Description 小组总数-机关日统计数据
**/
private void agencyGroupStats(String customerId, Date date) {
private void agencyGroupStats(String customerId, String dateId) {
//1:查询各维度表Id,方便使用
Date date = DateUtils.parseDate(dateId,DateUtils.DATE_PATTERN_YYYYMMDD);
DimIdGenerator.DimIdBean dimId = DimIdGenerator.getDimIdBean(date);
//2:根据客户Id查询机关维度表数据
@ -508,10 +520,11 @@ public class StatsGroupServiceImpl implements StatsGroupService {
//4.根据客户Id查询客户下有效的群组列表数据
log.info("StatsGroupServiceImpl.agencyGroupStats-根据客户Id查询客户下有效的群组列表数据,对应客户Id:" + customerId);
List<ResiGroupEntity> groupList = groupDataService.getGroupListByCustomerId(customerId);
List<FactOriginGroupMainDailyEntity> groupList = factOriginGroupMainDailyService.getGroupListByCustomerId(customerId, dateId);
List<FactGroupTotalAgencyDailyEntity> list = new ArrayList<>();
//5.遍历组织维度数据分别计算每个组织下群组数据
DimIdGenerator.DimIdBean finalDimId = dimId;
agencyList.forEach(agency->{
FactGroupTotalAgencyDailyEntity entity = new FactGroupTotalAgencyDailyEntity();
//5-1.汇总组织及所有下级组织列表
@ -538,7 +551,7 @@ public class StatsGroupServiceImpl implements StatsGroupService {
//5-3.根据汇总的网格列表统计对应的群组数据
agencyGridList.forEach(gridId -> {
groupList.forEach(group -> {
if (gridId.equals(group.getGridId()) && "approved".equals(group.getState())) {
if (gridId.equals(group.getGridId()) && "approved".equals(group.getGroupState())) {
total.addAndGet(1);
if ("ordinary".equals(group.getGroupType())) {
ordinary.addAndGet(1);
@ -553,11 +566,11 @@ public class StatsGroupServiceImpl implements StatsGroupService {
entity.setCustomerId(agency.getCustomerId());
entity.setAgencyId(agency.getId());
entity.setPid(agency.getPid());
entity.setDateId(dimId.getDateId());
entity.setWeekId(dimId.getWeekId());
entity.setMonthId(dimId.getMonthId());
entity.setQuarterId(dimId.getQuarterId());
entity.setYearId(dimId.getYearId());
entity.setDateId(finalDimId.getDateId());
entity.setWeekId(finalDimId.getWeekId());
entity.setMonthId(finalDimId.getMonthId());
entity.setQuarterId(finalDimId.getQuarterId());
entity.setYearId(finalDimId.getYearId());
entity.setGroupTotal(total.get());
entity.setOrdinaryTotal(ordinary.get());
entity.setBranchTotal(branch.get());

11
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/evaluationindex/extract/FactOriginGroupMainDailyDao.xml

@ -340,4 +340,15 @@
AND f.GROUP_STATE = 'approved'
GROUP BY f.AGENCY_ID
</select>
<select id="selectCustomerGroupList" resultType="com.epmet.entity.evaluationindex.extract.FactOriginGroupMainDailyEntity">
SELECT
*
FROM fact_origin_group_main_daily
WHERE
del_flag = '0'
AND customer_id = #{customerId}
<![CDATA[AND DATE_ID <= #{dateId}]]>
</select>
</mapper>

10
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/group/GroupDataDao.xml

@ -228,14 +228,4 @@
</select>
<select id="selectCustomerGroupList" resultType="com.epmet.entity.group.ResiGroupEntity">
SELECT
*
FROM
resi_group
WHERE
del_flag = '0'
AND customer_id = #{customerId}
</select>
</mapper>
Loading…
Cancel
Save