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