|
|
@ -23,18 +23,23 @@ import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.constant.StatsSubject; |
|
|
|
import com.epmet.dao.stats.DimQuarterDao; |
|
|
|
import com.epmet.dto.stats.DimQuarterDTO; |
|
|
|
import com.epmet.entity.stats.DimQuarterEntity; |
|
|
|
import com.epmet.entity.stats.LastExecRecordEntity; |
|
|
|
import com.epmet.service.stats.DimQuarterService; |
|
|
|
import com.epmet.service.stats.LastExecRecordService; |
|
|
|
import com.epmet.util.DimIdGenerator; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
/** |
|
|
|
* 季度维度表 |
|
|
@ -45,6 +50,14 @@ import java.util.Map; |
|
|
|
@Service |
|
|
|
public class DimQuarterServiceImpl extends BaseServiceImpl<DimQuarterDao, DimQuarterEntity> implements DimQuarterService { |
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private LastExecRecordService lastExecRecordService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private DimQuarterDao dimQuarterDao; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<DimQuarterDTO> page(Map<String, Object> params) { |
|
|
|
IPage<DimQuarterEntity> page = baseDao.selectPage( |
|
|
@ -97,4 +110,100 @@ public class DimQuarterServiceImpl extends BaseServiceImpl<DimQuarterDao, DimQua |
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional |
|
|
|
@Override |
|
|
|
public void initQuarterDim() { |
|
|
|
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_QUARTER); |
|
|
|
if (lastExecRecord == null) { |
|
|
|
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_QUARTER); |
|
|
|
} |
|
|
|
|
|
|
|
//Date now = new Date();
|
|
|
|
Date now = DateUtils.parse("20210430", DateUtils.DATE_PATTERN_YYYYMMDD); |
|
|
|
|
|
|
|
Date targetQday; |
|
|
|
Date startQday; |
|
|
|
|
|
|
|
targetQday = DateUtils.integrate(DateUtils.addDateMonths(now, -3), DateUtils.DATE_PATTERN_YYYYMM); |
|
|
|
|
|
|
|
if (lastExecRecord.getExecTime() == null) { |
|
|
|
// 初始化上一个季度
|
|
|
|
initQuarterDim(targetQday); |
|
|
|
} else { |
|
|
|
// 连续初始化多个季度
|
|
|
|
startQday = DateUtils.integrate(lastExecRecord.getExecTime(), DateUtils.DATE_PATTERN_YYYYMM); |
|
|
|
initQuarterDim(startQday, targetQday); |
|
|
|
} |
|
|
|
|
|
|
|
lastExecRecord.setExecTime(new Date()); |
|
|
|
|
|
|
|
// 记录最后一次统计时间
|
|
|
|
lastExecRecordService.updateById(lastExecRecord); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 连续初始化多个季度维度数据 |
|
|
|
* @param startQday |
|
|
|
* @param targetQday |
|
|
|
*/ |
|
|
|
public void initQuarterDim(Date startQday, Date targetQday) { |
|
|
|
Integer startQuarterIdx; |
|
|
|
Integer targetQuarterIdx; |
|
|
|
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)))) { |
|
|
|
initQuarterDim(startQday); |
|
|
|
startQday = DateUtils.addDateMonths(startQday, 3); |
|
|
|
} |
|
|
|
} |
|
|
|
/** |
|
|
|
* 初始化指定月份维度数据 |
|
|
|
*/ |
|
|
|
public void initQuarterDim(Date targetQday) { |
|
|
|
Date now = new Date(); |
|
|
|
DimQuarterEntity dim = new DimQuarterEntity(); |
|
|
|
String quarterDimId = DimIdGenerator.getQuarterDimId(targetQday); |
|
|
|
dim.setId(quarterDimId); |
|
|
|
dim.setQuarterName(getQuarterName(targetQday)); |
|
|
|
|
|
|
|
String yyyy = DateUtils.format(targetQday, DateUtils.DATE_PATTERN_YYYY); |
|
|
|
int quarter = DateUtils.getQuarterIndex(targetQday); |
|
|
|
dim.setStartDate(DateUtils.getQuarterStartDate(yyyy, quarter)); |
|
|
|
dim.setEndDate(DateUtils.getQuarterEndDate(yyyy, quarter)); |
|
|
|
dim.setQuarterOrder(quarter); |
|
|
|
dim.setYearId(yyyy); |
|
|
|
dim.setDelFlag("0"); |
|
|
|
dim.setRevision(0); |
|
|
|
dim.setCreatedBy("APP_USER"); |
|
|
|
dim.setCreatedTime(now); |
|
|
|
dim.setUpdatedBy("APP_USER"); |
|
|
|
dim.setUpdatedTime(now); |
|
|
|
dimQuarterDao.insert(dim); |
|
|
|
logger.info("初始化季度数据,基于日期:" + targetQday + ",生成的DimId:" + quarterDimId); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 季度名称 |
|
|
|
* @param targetQday |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private String getQuarterName(Date targetQday) { |
|
|
|
String yyyy = DateUtils.format(targetQday, DateUtils.DATE_PATTERN_YYYY); |
|
|
|
int quarterIndex = DateUtils.getQuarterIndex(targetQday); |
|
|
|
String quarterName; |
|
|
|
switch (quarterIndex) { |
|
|
|
case 1: |
|
|
|
quarterName = "第一季度"; |
|
|
|
break; |
|
|
|
case 2: |
|
|
|
quarterName = "第二季度"; |
|
|
|
break; |
|
|
|
case 3: |
|
|
|
quarterName = "第三季度"; |
|
|
|
break; |
|
|
|
default: |
|
|
|
quarterName = "第四季度"; |
|
|
|
} |
|
|
|
return yyyy.concat("年").concat(quarterName); |
|
|
|
} |
|
|
|
|
|
|
|
} |