Browse Source

数据-项目-机关月统计-部分代码提交

master
sunyuchao 5 years ago
parent
commit
c6489e4d08
  1. 37
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/project/form/MonthProjectListFormDTO.java
  2. 0
      epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/project/result/.gitkeep
  3. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimDateDao.java
  4. 18
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactAgencyProjectDailyDao.java
  5. 9
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactAgencyProjectMonthlyDao.java
  6. 176
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsProjectServiceImpl.java
  7. 8
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimDateService.java
  8. 16
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactAgencyProjectDailyService.java
  9. 7
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactAgencyProjectMonthlyService.java
  10. 11
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java
  11. 22
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactAgencyProjectDailyServiceImpl.java
  12. 11
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactAgencyProjectMonthlyServiceImpl.java
  13. 13
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimDateDao.xml
  14. 24
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactAgencyProjectDailyDao.xml
  15. 9
      epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactAgencyProjectMonthlyDao.xml

37
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/project/form/MonthProjectListFormDTO.java

@ -0,0 +1,37 @@
package com.epmet.dto.project.form;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @Author sun
* 查询项目机关过去一个月的日统计数据
*/
@Data
public class MonthProjectListFormDTO implements Serializable {
private static final long serialVersionUID = -3634745091993094743L;
/**
* 客户Id
*/
private String customerId;
/**
* 机关Id
*/
private String agencyId;
/**
* 起始时间
*/
private Date startTime;
/**
* 结束时间
*/
private Date endTime;
}

0
epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/dto/project/result/.gitkeep

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/DimDateDao.java

@ -35,14 +35,6 @@ import java.util.List;
@Mapper
public interface DimDateDao extends BaseDao<DimDateEntity> {
/**
* @param dto
* @return
* @Author sun
* @Description 根据创建时间查询日维度信息
**/
List<DimDateDTO> selectDimDate(DimDateDTO dto);
/**
* 最新的按日维度
*/

18
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactAgencyProjectDailyDao.java

@ -18,9 +18,12 @@
package com.epmet.dao.stats;
import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.project.form.MonthProjectListFormDTO;
import com.epmet.entity.stats.FactAgencyProjectDailyEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 机关下日项目数据统计 存放机关下截止到当前日期的各项总数据以及昨日新增各项数据
*
@ -29,5 +32,18 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface FactAgencyProjectDailyDao extends BaseDao<FactAgencyProjectDailyEntity> {
/**
* @param formDTO
* @Author sun
* @Description 查询上一月机关日统计数据按时间倒序
**/
List<FactAgencyProjectDailyEntity> selectMonthProjectList(MonthProjectListFormDTO formDTO);
/**
* @param delEntity
* @Author sun
* @Description 根据客户Id日维度Id批量物理删除一下可能存在的历史数据
**/
void delDateProject(FactAgencyProjectDailyEntity delEntity);
}

9
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/dao/stats/FactAgencyProjectMonthlyDao.java

@ -29,5 +29,12 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface FactAgencyProjectMonthlyDao extends BaseDao<FactAgencyProjectMonthlyEntity> {
/**
* @param delEntity
* @return
* @Author sun
* @Description 根据客户Id月份Id批量物理删除可能存在的历史数据
**/
void delMonthProject(FactAgencyProjectMonthlyEntity delEntity);
}

176
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsProjectServiceImpl.java

@ -2,16 +2,20 @@ package com.epmet.service.impl;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.constant.ProjectConstant;
import com.epmet.dto.project.form.MonthProjectListFormDTO;
import com.epmet.dto.stats.DimAgencyDTO;
import com.epmet.dto.stats.DimDateDTO;
import com.epmet.entity.project.ProjectEntity;
import com.epmet.entity.project.ProjectProcessEntity;
import com.epmet.entity.stats.DimDateEntity;
import com.epmet.entity.stats.FactAgencyProjectDailyEntity;
import com.epmet.entity.stats.FactAgencyProjectMonthlyEntity;
import com.epmet.service.StatsProjectService;
import com.epmet.service.project.ProjectProcessService;
import com.epmet.service.project.ProjectService;
import com.epmet.service.stats.*;
import com.epmet.util.DimIdGenerator;
import oracle.sql.NUMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -63,13 +67,20 @@ public class StatsProjectServiceImpl implements StatsProjectService {
**/
@Override
public void statsAgencyProject(String customerId) {
//1:执行机关日数据统计
agencyDateProjectStats(customerId);
//2:执行机关月数据统计
if (Calendar.getInstance().get(Calendar.DATE) == 1) {
agencyMonthProjectStats(customerId);
}
//1:根据客户Id查询机关维度表数据
DimAgencyDTO dimAgencyDTO = new DimAgencyDTO();
dimAgencyDTO.setCustomerId(customerId);
List<DimAgencyDTO> dimAgencyList = dimAgencyService.getDimAgencyList(dimAgencyDTO);
if (null != dimAgencyList && dimAgencyList.size() > NumConstant.ZERO) {
//2:执行机关日数据统计
agencyDateProjectStats(customerId, dimAgencyList);
//3:执行机关月数据统计
if (Calendar.getInstance().get(Calendar.DATE) == 1) {
agencyMonthProjectStats(customerId, dimAgencyList);
}
}
}
/**
@ -77,28 +88,18 @@ public class StatsProjectServiceImpl implements StatsProjectService {
* @Author sun
* @Description 数据-项目-机关日统计
**/
private String agencyDateProjectStats(String customerId) {
private String agencyDateProjectStats(String customerId, List<DimAgencyDTO> dimAgencyList) {
Date date = yesterDay();
//1:查询各维度表Id,方便使用 //TODO
DimDateDTO dimDateDTO = new DimDateDTO();
dimDateDTO.setCreatedTime(date);
dimDateDTO = dimDateService.getDimDate(dimDateDTO).get(0);
//2:根据客户Id查询机关维度表数据
DimAgencyDTO dimAgencyDTO = new DimAgencyDTO();
dimAgencyDTO.setCustomerId(customerId);
List<DimAgencyDTO> dimAgencyList = dimAgencyService.getDimAgencyList(dimAgencyDTO);
if (null == dimAgencyList || dimAgencyList.size() < NumConstant.ONE) {
return null;
}
//1:查询各维度表Id,方便使用
DimIdGenerator.DimIdBean dimId = DimIdGenerator.getDimIdBean(yesterDay());
//3:根据客户Id查询项目业务表数据
//2:根据客户Id查询项目业务表数据
List<ProjectEntity> projectList = projectService.getProjectList(customerId);
//4:查询项目处理进展表中是创建项目和结案两种进展的有效数据(创建日期截取yyyy-mm-dd格式字段值)
//3:查询项目处理进展表中是创建项目和结案两种进展的有效数据(创建日期截取yyyy-mm-dd格式字段值)
List<ProjectProcessEntity> processList = projectProcessService.getProcessList(customerId);
//5:遍历统计每个机关各项指标数
//4:遍历统计每个机关各项指标数
//批量机关日统计新增对象
List<FactAgencyProjectDailyEntity> dimDateEntityList = new ArrayList<>();
//计算百分比使用,保留小数点后两位
@ -172,11 +173,10 @@ public class StatsProjectServiceImpl implements StatsProjectService {
agencyDailyEntity.setCustomerId(customerId);
agencyDailyEntity.setAgencyId(agency.getId());
agencyDailyEntity.setParentId(agency.getPid());
//TODO
agencyDailyEntity.setDateId("");
agencyDailyEntity.setWeekId("");
agencyDailyEntity.setMonthId("");
agencyDailyEntity.setYearId("");
agencyDailyEntity.setDateId(dimId.getDateId());
agencyDailyEntity.setWeekId(dimId.getWeekId());
agencyDailyEntity.setMonthId(dimId.getMonthId());
agencyDailyEntity.setYearId(dimId.getYearId());
agencyDailyEntity.setProjectTotal(projectTotal.intValue());
agencyDailyEntity.setPendingTotal(pendingTotal.intValue());
agencyDailyEntity.setClosedTotal(closedTotal.intValue());
@ -199,8 +199,15 @@ public class StatsProjectServiceImpl implements StatsProjectService {
dimDateEntityList.add(agencyDailyEntity);
}
//6:批量保存机关日统计数据
//先删后增
if (null != dimDateEntityList && dimDateEntityList.size() > NumConstant.ZERO) {
//5:根据客户Id、日维度Id批量物理删除一下可能存在的历史数据
FactAgencyProjectDailyEntity delEntity = new FactAgencyProjectDailyEntity();
delEntity.setCustomerId(customerId);
delEntity.setDateId(dimId.getDateId());
factAgencyProjectDailyService.delDateProject(delEntity);
//6:批量保存机关日统计数据
factAgencyProjectDailyService.insertBatch(dimDateEntityList);
}
return null;
@ -211,8 +218,76 @@ public class StatsProjectServiceImpl implements StatsProjectService {
* @Author sun
* @Description 数据-项目-机关月统计
**/
private void agencyMonthProjectStats(String customerId) {
private String agencyMonthProjectStats(String customerId, List<DimAgencyDTO> dimAgencyList) {
//1:获取个维度Id方便使用
DimIdGenerator.DimIdBean dimId = DimIdGenerator.getDimIdBean(yesterDay());
//2:获取昨天日期所在月份的起始日期和结束日期
MonthProjectListFormDTO formDTO = new MonthProjectListFormDTO();
formDTO.setCustomerId(customerId);
formDTO.setStartTime(getMonthBegin(yesterDay()));
formDTO.setEndTime(getMonthEnd(yesterDay()));
//批量月数据新增对象
List<FactAgencyProjectMonthlyEntity> monthlyEntityList = new ArrayList<>();
//3:遍历机关维度数据,分别统计每个组织月数据
for (DimAgencyDTO agency : dimAgencyList) {
//4:查询上一月机关日统计数据,按时间倒序
formDTO.setAgencyId(agency.getId());
List<FactAgencyProjectDailyEntity> projectDailyList = factAgencyProjectDailyService.getMonthProjectList(formDTO);
//5:汇总统计上一月机关月统计数据
//月增量中项目总数、处理中总数、已结案总数、已结案已解决总数、已结案未解决总数
int pendingIncr = 0;
int closedIncr = 0;
int resolvedIncr = 0;
int unResolvedIncr = 0;
for (FactAgencyProjectDailyEntity date : projectDailyList) {
pendingIncr += date.getPendingIncr();
closedIncr += date.getClosedIncr();
resolvedIncr += date.getResolvedIncr();
unResolvedIncr += date.getUnresolvedIncr();
}
//6:实体字段属性赋值
FactAgencyProjectMonthlyEntity monthlyEntity = new FactAgencyProjectMonthlyEntity();
monthlyEntity.setCustomerId(customerId);
monthlyEntity.setAgencyId(agency.getId());
monthlyEntity.setParentId(agency.getPid());
monthlyEntity.setMonthId(dimId.getMonthId());
monthlyEntity.setQuarterId(dimId.getQuarterId());
monthlyEntity.setYearId(dimId.getYearId());
if (null != projectDailyList && projectDailyList.size() > NumConstant.ZERO) {
FactAgencyProjectDailyEntity entity = projectDailyList.get(0);
monthlyEntity.setProjectTotal(entity.getProjectTotal());
monthlyEntity.setPendingTotal(entity.getPendingTotal());
monthlyEntity.setPendingRatio(entity.getPendingRatio());
monthlyEntity.setClosedTotal(entity.getClosedTotal());
monthlyEntity.setClosedRatio(entity.getClosedRatio());
monthlyEntity.setResolvedTotal(entity.getResolvedTotal());
monthlyEntity.setResolvedRatio(entity.getResolvedRatio());
monthlyEntity.setUnresolvedTotal(entity.getUnresolvedTotal());
monthlyEntity.setUnresolvedRatio(entity.getUnresolvedRatio());
monthlyEntity.setProjectIncr(pendingIncr + closedIncr);
monthlyEntity.setPendingIncr(pendingIncr);
monthlyEntity.setClosedIncr(closedIncr);
monthlyEntity.setResolvedIncr(resolvedIncr);
monthlyEntity.setUnresolvedIncr(unResolvedIncr);
}
monthlyEntityList.add(monthlyEntity);
}
if (null != monthlyEntityList && monthlyEntityList.size() > NumConstant.ZERO) {
//7:根据客户Id、月份Id批量删除一下可能存在的历史数据
FactAgencyProjectMonthlyEntity delEntity = new FactAgencyProjectMonthlyEntity();
delEntity.setCustomerId(customerId);
delEntity.setMonthId(dimId.getMonthId());
factAgencyProjectMonthlyService.delMonthProject(delEntity);
//8:批量保存机关月统计数据
factAgencyProjectMonthlyService.insertBatch(monthlyEntityList);
}
return null;
}
/**
@ -251,4 +326,47 @@ public class StatsProjectServiceImpl implements StatsProjectService {
return date;
}
/**
* @Author sun
* @Description 获取指定日期所在月份开始的时间
**/
public Date getMonthBegin(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
//设置为1号,当前日期既为本月第一天
c.set(Calendar.DAY_OF_MONTH, 1);
//将小时至0
c.set(Calendar.HOUR_OF_DAY, 0);
//将分钟至0
c.set(Calendar.MINUTE, 0);
//将秒至0
c.set(Calendar.SECOND, 0);
//将毫秒至0
c.set(Calendar.MILLISECOND, 0);
//获取本月第一天的时间
return c.getTime();
}
/**
* @Author sun
* @Description 获取指定日期所在月份结束的时间
**/
public Date getMonthEnd(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
//设置为当月最后一天
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
//将小时至23
c.set(Calendar.HOUR_OF_DAY, 23);
//将分钟至59
c.set(Calendar.MINUTE, 59);
//将秒至59
c.set(Calendar.SECOND, 59);
//将毫秒至999
c.set(Calendar.MILLISECOND, 999);
//获取本月最后一天的时间
System.out.println(c.getTime());
System.out.println(c);
return c.getTime();
}
}

8
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimDateService.java

@ -93,14 +93,6 @@ public interface DimDateService extends BaseService<DimDateEntity> {
*/
void delete(String[] ids);
/**
* @param dto
* @return
* @Author sun
* @Description 根据创建时间查询日维度信息
**/
List<DimDateDTO> getDimDate(DimDateDTO dto);
void initDimDate();
}

16
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactAgencyProjectDailyService.java

@ -18,8 +18,11 @@
package com.epmet.service.stats;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.dto.project.form.MonthProjectListFormDTO;
import com.epmet.entity.stats.FactAgencyProjectDailyEntity;
import java.util.List;
/**
* 机关下日项目数据统计 存放机关下截止到当前日期的各项总数据以及昨日新增各项数据
*
@ -28,4 +31,17 @@ import com.epmet.entity.stats.FactAgencyProjectDailyEntity;
*/
public interface FactAgencyProjectDailyService extends BaseService<FactAgencyProjectDailyEntity> {
/**
* @param formDTO
* @Author sun
* @Description 查询上一月机关日统计数据按时间倒序
**/
List<FactAgencyProjectDailyEntity> getMonthProjectList(MonthProjectListFormDTO formDTO);
/**
* @param delEntity
* @Author sun
* @Description 根据客户Id日维度Id批量物理删除一下可能存在的历史数据
**/
void delDateProject(FactAgencyProjectDailyEntity delEntity);
}

7
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/FactAgencyProjectMonthlyService.java

@ -28,4 +28,11 @@ import com.epmet.entity.stats.FactAgencyProjectMonthlyEntity;
*/
public interface FactAgencyProjectMonthlyService extends BaseService<FactAgencyProjectMonthlyEntity> {
/**
* @param delEntity
* @return
* @Author sun
* @Description 根据客户Id月份Id批量物理删除可能存在的历史数据
**/
void delMonthProject(FactAgencyProjectMonthlyEntity delEntity);
}

11
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java

@ -95,17 +95,6 @@ public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntit
baseDao.deleteBatchIds(Arrays.asList(ids));
}
/**
* @param dto
* @return
* @Author sun
* @Description 根据创建时间查询日维度信息
**/
@Override
public List<DimDateDTO> getDimDate(DimDateDTO dto) {
return baseDao.selectDimDate(dto);
}
@Override
public void initDimDate() {
DimDateDTO latestDimDateDto = baseDao.getLatestDimDate();

22
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactAgencyProjectDailyServiceImpl.java

@ -19,10 +19,13 @@ package com.epmet.service.stats.impl;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.dao.stats.FactAgencyProjectDailyDao;
import com.epmet.dto.project.form.MonthProjectListFormDTO;
import com.epmet.entity.stats.FactAgencyProjectDailyEntity;
import com.epmet.service.stats.FactAgencyProjectDailyService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 机关下日项目数据统计 存放机关下截止到当前日期的各项总数据以及昨日新增各项数据
*
@ -33,4 +36,23 @@ import org.springframework.stereotype.Service;
public class FactAgencyProjectDailyServiceImpl extends BaseServiceImpl<FactAgencyProjectDailyDao, FactAgencyProjectDailyEntity> implements FactAgencyProjectDailyService {
/**
* @param formDTO
* @Author sun
* @Description 查询上一月机关日统计数据按时间倒序
**/
@Override
public List<FactAgencyProjectDailyEntity> getMonthProjectList(MonthProjectListFormDTO formDTO) {
return baseDao.selectMonthProjectList(formDTO);
}
/**
* @param delEntity
* @Author sun
* @Description 根据客户Id日维度Id批量物理删除一下可能存在的历史数据
**/
@Override
public void delDateProject(FactAgencyProjectDailyEntity delEntity) {
baseDao.delDateProject(delEntity);
}
}

11
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/FactAgencyProjectMonthlyServiceImpl.java

@ -32,5 +32,14 @@ import org.springframework.stereotype.Service;
@Service
public class FactAgencyProjectMonthlyServiceImpl extends BaseServiceImpl<FactAgencyProjectMonthlyDao, FactAgencyProjectMonthlyEntity> implements FactAgencyProjectMonthlyService {
/**
* @param delEntity
* @return
* @Author sun
* @Description 根据客户Id月份Id批量物理删除可能存在的历史数据
**/
@Override
public void delMonthProject(FactAgencyProjectMonthlyEntity delEntity) {
baseDao.delMonthProject(delEntity);
}
}

13
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/DimDateDao.xml

@ -3,19 +3,6 @@
<mapper namespace="com.epmet.dao.stats.DimDateDao">
<select id="selectDimDate" resultType="com.epmet.dto.stats.DimDateDTO">
SELECT
*
FROM
`dim_date`
WHERE
del_flag = '0'
<if test="createdTime != null and createdTime.trim() != ''">
AND DATE_FORMAT(created_time, "%Y-%m-%d") = DATE_FORMAT(#{createdTime}, "%Y-%m-%d")
</if>
ORDER BY created_time DESC
</select>
<!--最新的按日维度-->
<select id="getLatestDimDate" resultType="com.epmet.dto.stats.DimDateDTO">
SELECT *

24
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactAgencyProjectDailyDao.xml

@ -3,6 +3,30 @@
<mapper namespace="com.epmet.dao.stats.FactAgencyProjectDailyDao">
<select id="selectMonthProjectList" resultType="com.epmet.entity.stats.FactAgencyProjectDailyEntity">
SELECT
*
FROM
fact_agency_project_daily
WHERE
del_flag = '0'
AND customer_id = #{customerId}
AND agency_id = #{agencyId}
AND (
DATE_FORMAT(created_time, "%Y-%m-%d")
BETWEEN DATE_FORMAT(#{startTime}, "%Y-%m-%d")
AND DATE_FORMAT(#{endTime}, "%Y-%m-%d")
)
ORDER BY created_time DESC,project_total DESC
</select>
<delete id="delDateProject">
DELETE
FROM
fact_agency_project_daily
WHERE
customer_id = #{customerId}
AND date_id = #{dateId}
</delete>
</mapper>

9
epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/stats/FactAgencyProjectMonthlyDao.xml

@ -3,6 +3,13 @@
<mapper namespace="com.epmet.dao.stats.FactAgencyProjectMonthlyDao">
<delete id="delMonthProject">
DELETE
FROM
fact_agency_project_monthly
WHERE
customer_id = #{customerId}
AND month_id = #{monthId}
</delete>
</mapper>
Loading…
Cancel
Save