Browse Source

1.新增年维度和季维度

master
wxz 5 years ago
parent
commit
8796f34f80
  1. 18
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java
  2. 21
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java
  3. 3
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimYearService.java
  4. 44
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimDateServiceImpl.java
  5. 58
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java
  6. 27
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimQuarterServiceImpl.java
  7. 73
      epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimYearServiceImpl.java

18
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/DimController.java

@ -3,10 +3,7 @@ package com.epmet.controller;
import com.epmet.commons.tools.utils.Result; import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.AgencySubTreeDto; import com.epmet.dto.AgencySubTreeDto;
import com.epmet.service.StatsDimService; import com.epmet.service.StatsDimService;
import com.epmet.service.stats.DimAgencyService; import com.epmet.service.stats.*;
import com.epmet.service.stats.DimDateService;
import com.epmet.service.stats.DimMonthService;
import com.epmet.service.stats.DimQuarterService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -28,6 +25,9 @@ public class DimController {
@Autowired @Autowired
private DimQuarterService quarterService; private DimQuarterService quarterService;
@Autowired
private DimYearService dimYearService;
@Autowired @Autowired
private StatsDimService statsDimService; private StatsDimService statsDimService;
@ -104,6 +104,16 @@ public class DimController {
return new Result(); return new Result();
} }
/**
* 年度维度
* @return
*/
@PostMapping("/year/init")
public Result initYearDim() {
dimYearService.initYearDim();
return new Result();
}
/** /**
* @Description 所有机构 * @Description 所有机构
* @param * @param

21
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/impl/StatsDimServiceImpl.java

@ -16,6 +16,7 @@ import com.epmet.service.org.CustomerGridService;
import com.epmet.service.stats.*; import com.epmet.service.stats.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -53,6 +54,11 @@ public class StatsDimServiceImpl implements StatsDimService {
@Override @Override
public void initGridDim() { public void initGridDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_GRID);
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_GRID);
}
DimGridEntity lastCreatedGridDim = dimGridService.getLastCreatedGridDim(); DimGridEntity lastCreatedGridDim = dimGridService.getLastCreatedGridDim();
List<CustomerGridEntity> grids; List<CustomerGridEntity> grids;
if (lastCreatedGridDim == null) { if (lastCreatedGridDim == null) {
@ -68,7 +74,11 @@ public class StatsDimServiceImpl implements StatsDimService {
} }
List<DimGridEntity> gridDims = convertCustomerGrid2GridDim(grids); List<DimGridEntity> gridDims = convertCustomerGrid2GridDim(grids);
if (!CollectionUtils.isEmpty(gridDims)) {
dimGridService.addGridDims(gridDims); dimGridService.addGridDims(gridDims);
lastExecRecord.setExecTime(new Date());
lastExecRecordService.updateById(lastExecRecord);
}
} }
/** /**
@ -112,12 +122,14 @@ public class StatsDimServiceImpl implements StatsDimService {
} }
List<CustomerAgencyEntity> agencies = customerAgencyService.listAgenciesByCreateTime(statsStartTime, statsEndTime); List<CustomerAgencyEntity> agencies = customerAgencyService.listAgenciesByCreateTime(statsStartTime, statsEndTime);
if (!CollectionUtils.isEmpty(agencies)) {
dimAgencyService.addAgencyDims(agencies); dimAgencyService.addAgencyDims(agencies);
lastExecRecord.setExecTime(new Date()); lastExecRecord.setExecTime(new Date());
// 记录最后一次统计时间 // 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord); lastExecRecordService.updateById(lastExecRecord);
} }
}
/** /**
* 初始化网格维度 * 初始化网格维度
@ -136,6 +148,7 @@ public class StatsDimServiceImpl implements StatsDimService {
} }
List<CustomerEntity> customers = customerService.listValidCustomersByCreateTime(statsStartTime, statsEndTime); List<CustomerEntity> customers = customerService.listValidCustomersByCreateTime(statsStartTime, statsEndTime);
if (!CollectionUtils.isEmpty(customers)) {
dimCustomerService.addCustomerDims(customers); dimCustomerService.addCustomerDims(customers);
lastExecRecord.setExecTime(new Date()); lastExecRecord.setExecTime(new Date());
@ -143,6 +156,7 @@ public class StatsDimServiceImpl implements StatsDimService {
// 记录最后一次统计时间 // 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord); lastExecRecordService.updateById(lastExecRecord);
} }
}
@Override @Override
public void initDepartmentDim() { public void initDepartmentDim() {
@ -158,14 +172,11 @@ public class StatsDimServiceImpl implements StatsDimService {
} }
List<CustomerDepartmentEntity> departments = departmentService.listDepartmentsByCreatedTime(statsStartTime, statsEndTime); List<CustomerDepartmentEntity> departments = departmentService.listDepartmentsByCreatedTime(statsStartTime, statsEndTime);
if (!CollectionUtils.isEmpty(departments)) {
dimDepartmentService.addDepartmentDims(departments); dimDepartmentService.addDepartmentDims(departments);
lastExecRecord.setExecTime(new Date()); lastExecRecord.setExecTime(new Date());
// 记录最后一次统计时间 // 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord); lastExecRecordService.updateById(lastExecRecord);
} }
}
} }

3
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/DimYearService.java

@ -92,4 +92,7 @@ public interface DimYearService extends BaseService<DimYearEntity> {
* @date 2020-06-16 * @date 2020-06-16
*/ */
void delete(String[] ids); void delete(String[] ids);
void initYearDim();
} }

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

@ -24,12 +24,17 @@ import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.utils.DateUtils; import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.StatsSubject;
import com.epmet.dao.stats.DimDateDao; import com.epmet.dao.stats.DimDateDao;
import com.epmet.dto.stats.DimDateDTO; import com.epmet.dto.stats.DimDateDTO;
import com.epmet.entity.stats.DimDateEntity; import com.epmet.entity.stats.DimDateEntity;
import com.epmet.entity.stats.LastExecRecordEntity;
import com.epmet.service.stats.DimDateService; import com.epmet.service.stats.DimDateService;
import com.epmet.service.stats.LastExecRecordService;
import com.epmet.util.DimIdGenerator; import com.epmet.util.DimIdGenerator;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -44,6 +49,9 @@ import java.util.*;
@Service @Service
public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntity> implements DimDateService { public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntity> implements DimDateService {
@Autowired
private LastExecRecordService lastExecRecordService;
@Override @Override
public PageData<DimDateDTO> page(Map<String, Object> params) { public PageData<DimDateDTO> page(Map<String, Object> params) {
IPage<DimDateEntity> page = baseDao.selectPage( IPage<DimDateEntity> page = baseDao.selectPage(
@ -109,32 +117,44 @@ public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntit
@Override @Override
public void initDimDate() { public void initDimDate() {
DimDateDTO latestDimDateDto = baseDao.getLatestDimDate(); LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_DATE);
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_DATE);
}
Date now = new Date();
Date targetDate = DateUtils.addDateDays(DateUtils.parse( Date targetDate = DateUtils.addDateDays(DateUtils.parse(
DateUtils.format(new Date(), DateUtils.DATE_PATTERN_YYYYMMDD), DateUtils.format(now, DateUtils.DATE_PATTERN_YYYYMMDD),
DateUtils.DATE_PATTERN_YYYYMMDD), -1); DateUtils.DATE_PATTERN_YYYYMMDD), -1);
Date lastDimDate; Date lastDimDate = null;
if (latestDimDateDto == null) { if ((lastDimDate = lastExecRecord.getExecTime()) == null) {
// 没有维度数据 // 首次初始化按日维度
initDimDate(targetDate); initDimDate(targetDate);
} else if(targetDate.after(lastDimDate = DateUtils.parse(latestDimDateDto.getId(), DateUtils.DATE_PATTERN_YYYYMMDD))) { lastExecRecord.setExecTime(now);
// 有维度数据,并且当前日期大于最大按日维度数据的id,需要连续生成至少一天的维度数据(补缺) lastExecRecordService.updateById(lastExecRecord);
} else {
if (targetDate.equals(lastDimDate) || targetDate.after(lastDimDate)) {
initDimDate(lastDimDate, targetDate); initDimDate(lastDimDate, targetDate);
lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
}
} }
} }
/** /**
* 连续初始化 * 连续初始化
* @param lastDimDate * @param startDate
* @param targetDate * @param targetDate
*/ */
private void initDimDate(Date lastDimDate, Date targetDate) { private void initDimDate(Date startDate, Date targetDate) {
while (lastDimDate.before(targetDate)) { LocalDate localStartDate = new LocalDate(startDate);
lastDimDate = DateUtils.addDateDays(lastDimDate, 1); LocalDate localTargetDate = new LocalDate(targetDate);
initDimDate(lastDimDate); while (localTargetDate.isEqual(localStartDate) || localTargetDate.isAfter(localStartDate)) {
initDimDate(localStartDate.toDate());
localStartDate = localStartDate.plusDays(1);
} }
} }

58
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimMonthServiceImpl.java

@ -34,6 +34,7 @@ import com.epmet.service.stats.LastExecRecordService;
import com.epmet.util.DimIdGenerator; import com.epmet.util.DimIdGenerator;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -116,52 +117,55 @@ public class DimMonthServiceImpl extends BaseServiceImpl<DimMonthDao, DimMonthEn
} }
Date now = new Date(); Date now = new Date();
String startTime; Date startMonth;
String endTime = DateUtils.format(now, DateUtils.DATE_PATTERN_YYYYMM); Date targetMonth = DateUtils.addDateMonths(DateUtils.integrate(now, DateUtils.DATE_PATTERN_YYYYMM), -1);
if (lastExecRecord.getExecTime() == null) { if (lastExecRecord.getExecTime() == null) {
Date targetDate = new LocalDate(now).minusMonths(1).toDate(); initMonthDim(targetMonth);
initMonthDim(DateUtils.format(targetDate, DateUtils.DATE_PATTERN_YYYYMM)); lastExecRecord.setExecTime(now);
lastExecRecordService.updateById(lastExecRecord);
} else { } else {
startTime = DateUtils.format(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMM); startMonth = DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMM);
initMonthDims(startTime, endTime); if (targetMonth.equals(startMonth) || targetMonth.after(startMonth)) {
} initMonthDims(startMonth, targetMonth);
lastExecRecord.setExecTime(now);
lastExecRecord.setExecTime(new Date());
// 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord); lastExecRecordService.updateById(lastExecRecord);
}
}
} }
public void initMonthDims(String startMonthStr, String endMonthStr) { /**
Integer startMonthInt = Integer.valueOf(startMonthStr); * 按月维度连续生成
Integer endMonthInt = Integer.valueOf(endMonthStr); * @param startMonth
while(startMonthInt < endMonthInt) { * @param targetMonth
initMonthDim(startMonthInt + ""); */
++ startMonthInt; public void initMonthDims(Date startMonth, Date targetMonth) {
LocalDate localstartMonth = new LocalDate(startMonth);
LocalDate localTargetMonth = new LocalDate(targetMonth);
while(localTargetMonth.isEqual(localstartMonth) || localTargetMonth.isAfter(localstartMonth)) {
initMonthDim(localstartMonth.toDate());
localstartMonth = localstartMonth.plusMonths(1);
} }
} }
public void initMonthDim(String startMonthStr) { public void initMonthDim(Date targetMonth) {
Date now = new Date(); Date now = new Date();
Date startDate = DateUtils.stringToDate( startMonthStr, DateUtils.DATE_PATTERN_YYYYMM); Date endDate = DateUtils.addDateDays(DateUtils.addDateMonths(targetMonth, 1), -1);
Date endDate = DateUtils.addDateDays(DateUtils.addDateMonths(startDate, 1), -1); LocalDate localDate = new LocalDate(targetMonth);
LocalDate localDate = new LocalDate(startDate);
DimMonthEntity dim = new DimMonthEntity(); DimMonthEntity dim = new DimMonthEntity();
dim.setStartDate(startDate); dim.setStartDate(targetMonth);
dim.setEndDate(endDate); dim.setEndDate(endDate);
dim.setMonthName(DateUtils.format(startDate, DateUtils.MONTH_NAME_PATTERN)); dim.setMonthName(DateUtils.format(targetMonth, DateUtils.MONTH_NAME_PATTERN));
dim.setMonthOrder(DateUtils.getMonthOfYear(startDate)); dim.setMonthOrder(DateUtils.getMonthOfYear(targetMonth));
dim.setQuarterId(localDate.getYear() + "Q" + DateUtils.getQuarterIndex(startDate)); dim.setQuarterId(localDate.getYear() + "Q" + DateUtils.getQuarterIndex(targetMonth));
dim.setYearId(localDate.getYear() + ""); dim.setYearId(localDate.getYear() + "");
dim.setCreatedBy("APP_USER"); dim.setCreatedBy("APP_USER");
dim.setUpdatedBy("APP_USER"); dim.setUpdatedBy("APP_USER");
dim.setCreatedTime(now); dim.setCreatedTime(now);
dim.setUpdatedTime(now); dim.setUpdatedTime(now);
dim.setDelFlag("0"); dim.setDelFlag("0");
dim.setId(DimIdGenerator.getMonthDimId(startDate)); dim.setId(DimIdGenerator.getMonthDimId(targetMonth));
baseDao.insert(dim); baseDao.insert(dim);
} }

27
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimQuarterServiceImpl.java

@ -32,6 +32,7 @@ import com.epmet.entity.stats.LastExecRecordEntity;
import com.epmet.service.stats.DimQuarterService; import com.epmet.service.stats.DimQuarterService;
import com.epmet.service.stats.LastExecRecordService; import com.epmet.service.stats.LastExecRecordService;
import com.epmet.util.DimIdGenerator; import com.epmet.util.DimIdGenerator;
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -121,39 +122,43 @@ public class DimQuarterServiceImpl extends BaseServiceImpl<DimQuarterDao, DimQua
//Date now = new Date(); //Date now = new Date();
Date now = DateUtils.parse("20210430", DateUtils.DATE_PATTERN_YYYYMMDD); Date now = DateUtils.parse("20210430", DateUtils.DATE_PATTERN_YYYYMMDD);
Date targetQday; Date targetQuarter;
Date startQday; Date startQuarter;
targetQday = DateUtils.integrate(DateUtils.addDateMonths(now, -3), DateUtils.DATE_PATTERN_YYYYMM); targetQuarter = DateUtils.integrate(DateUtils.addDateMonths(now, -3), DateUtils.DATE_PATTERN_YYYYMM);
if (lastExecRecord.getExecTime() == null) { if (lastExecRecord.getExecTime() == null) {
// 初始化上一个季度 // 初始化上一个季度
initQuarterDim(targetQday); initQuarterDim(targetQuarter);
lastExecRecord.setExecTime(new Date());
lastExecRecordService.updateById(lastExecRecord);
} else { } else {
// 连续初始化多个季度 // 连续初始化多个季度
startQday = DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMM); startQuarter = DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMM);
initQuarterDim(startQday, targetQday); if (initQuarterDim(startQuarter, targetQuarter)) {
}
lastExecRecord.setExecTime(new Date()); lastExecRecord.setExecTime(new Date());
// 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord); lastExecRecordService.updateById(lastExecRecord);
} }
}
}
/** /**
* 连续初始化多个季度维度数据 * 连续初始化多个季度维度数据
* @param startQday * @param startQday
* @param targetQday * @param targetQday
* @return 是否产生新数据
*/ */
public void initQuarterDim(Date startQday, Date targetQday) { public boolean initQuarterDim(Date startQday, Date targetQday) {
Boolean execed = false;
Integer startQuarterIdx; Integer startQuarterIdx;
Integer targetQuarterIdx; Integer targetQuarterIdx;
while ((startQuarterIdx = Integer.valueOf(DateUtils.format(startQday, DateUtils.DATE_PATTERN_YYYY) + DateUtils.getQuarterIndex(startQday))) while ((startQuarterIdx = Integer.valueOf(DateUtils.format(startQday, DateUtils.DATE_PATTERN_YYYY) + DateUtils.getQuarterIndex(startQday)))
<= (targetQuarterIdx = Integer.valueOf(DateUtils.format(targetQday, DateUtils.DATE_PATTERN_YYYY) + DateUtils.getQuarterIndex(targetQday)))) { <= (targetQuarterIdx = Integer.valueOf(DateUtils.format(targetQday, DateUtils.DATE_PATTERN_YYYY) + DateUtils.getQuarterIndex(targetQday)))) {
initQuarterDim(startQday); initQuarterDim(startQday);
startQday = DateUtils.addDateMonths(startQday, 3); startQday = DateUtils.addDateMonths(startQday, 3);
execed = true;
} }
return execed;
} }
/** /**
* 初始化指定月份维度数据 * 初始化指定月份维度数据

73
epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/stats/impl/DimYearServiceImpl.java

@ -23,16 +23,22 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils; import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.constant.FieldConstant; import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.utils.DateUtils;
import com.epmet.constant.StatsSubject;
import com.epmet.dao.stats.DimYearDao; import com.epmet.dao.stats.DimYearDao;
import com.epmet.dto.stats.DimYearDTO; import com.epmet.dto.stats.DimYearDTO;
import com.epmet.entity.stats.DimYearEntity; import com.epmet.entity.stats.DimYearEntity;
import com.epmet.entity.stats.LastExecRecordEntity;
import com.epmet.service.stats.DimYearService; import com.epmet.service.stats.DimYearService;
import com.epmet.service.stats.LastExecRecordService;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.joda.time.LocalDate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -45,6 +51,9 @@ import java.util.Map;
@Service @Service
public class DimYearServiceImpl extends BaseServiceImpl<DimYearDao, DimYearEntity> implements DimYearService { public class DimYearServiceImpl extends BaseServiceImpl<DimYearDao, DimYearEntity> implements DimYearService {
@Autowired
private LastExecRecordService lastExecRecordService;
@Override @Override
public PageData<DimYearDTO> page(Map<String, Object> params) { public PageData<DimYearDTO> page(Map<String, Object> params) {
IPage<DimYearEntity> page = baseDao.selectPage( IPage<DimYearEntity> page = baseDao.selectPage(
@ -97,4 +106,68 @@ public class DimYearServiceImpl extends BaseServiceImpl<DimYearDao, DimYearEntit
baseDao.deleteBatchIds(Arrays.asList(ids)); baseDao.deleteBatchIds(Arrays.asList(ids));
} }
@Override
public void initYearDim() {
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_YEAR);
if (lastExecRecord == null) {
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_YEAR);
}
Date now = new Date();
Date startYear;
Date targetYear;
targetYear = DateUtils.integrate(DateUtils.addDateYears(now, -1), DateUtils.DATE_PATTERN_YYYY);
if (lastExecRecord.getExecTime() == null) {
// 第一次执行统计
initYearDim(targetYear);
lastExecRecord.setExecTime(now);
// 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord);
} else {
startYear = DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYY);
if (targetYear.equals(startYear) || targetYear.after(startYear)) {
initYearDims(startYear, targetYear);
lastExecRecord.setExecTime(now);
// 记录最后一次统计时间
lastExecRecordService.updateById(lastExecRecord);
}
}
}
/**
* 按年连续初始化
* @param startYear
* @param targetYear
*/
private void initYearDims(Date startYear, Date targetYear) {
LocalDate localStartYear = new LocalDate(startYear);
LocalDate localTargetYear = new LocalDate(targetYear);
while (localStartYear.getYear() <= localTargetYear.getYear()) {
initYearDim(localStartYear.toDate());
localStartYear = localStartYear.plusYears(1);
}
}
/**
* 俺年单次统计
* @param targetYear
*/
public void initYearDim(Date targetYear) {
String yyyy = DateUtils.format(targetYear, DateUtils.DATE_PATTERN_YYYY);
Date now = new Date();
DimYearEntity dim = new DimYearEntity();
dim.setId(yyyy);
dim.setYearName(yyyy.concat("年"));
//dim.setUpdatedTime(now);
//dim.setUpdatedBy("APP_USER");
//dim.setCreatedTime(now);
//dim.setCreatedBy("APP_USER");
//dim.setRevision(0);
//dim.setDelFlag("0");
baseDao.insert(dim);
}
} }
Loading…
Cancel
Save