|
@ -23,16 +23,23 @@ 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.RobotConstant; |
|
|
|
|
|
import com.epmet.constant.StatsSubject; |
|
|
import com.epmet.dao.stats.DimWeekDao; |
|
|
import com.epmet.dao.stats.DimWeekDao; |
|
|
import com.epmet.dto.stats.DimWeekDTO; |
|
|
import com.epmet.dto.stats.DimWeekDTO; |
|
|
import com.epmet.entity.stats.DimWeekEntity; |
|
|
import com.epmet.entity.stats.DimWeekEntity; |
|
|
|
|
|
import com.epmet.entity.stats.LastExecRecordEntity; |
|
|
import com.epmet.service.stats.DimWeekService; |
|
|
import com.epmet.service.stats.DimWeekService; |
|
|
|
|
|
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 +52,9 @@ import java.util.Map; |
|
|
@Service |
|
|
@Service |
|
|
public class DimWeekServiceImpl extends BaseServiceImpl<DimWeekDao, DimWeekEntity> implements DimWeekService { |
|
|
public class DimWeekServiceImpl extends BaseServiceImpl<DimWeekDao, DimWeekEntity> implements DimWeekService { |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private LastExecRecordService lastExecRecordService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public PageData<DimWeekDTO> page(Map<String, Object> params) { |
|
|
public PageData<DimWeekDTO> page(Map<String, Object> params) { |
|
|
IPage<DimWeekEntity> page = baseDao.selectPage( |
|
|
IPage<DimWeekEntity> page = baseDao.selectPage( |
|
@ -97,4 +107,71 @@ public class DimWeekServiceImpl extends BaseServiceImpl<DimWeekDao, DimWeekEntit |
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
@Override |
|
|
|
|
|
public void initWeekDim() { |
|
|
|
|
|
LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_WEEK); |
|
|
|
|
|
if (lastExecRecord == null) { |
|
|
|
|
|
lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_WEEK); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
|
|
Date startWeekDay; |
|
|
|
|
|
Date targetWeekDay = DateUtils.getWeekStartAndEnd(DateUtils.addDateDays(now, -7))[0]; |
|
|
|
|
|
|
|
|
|
|
|
if (lastExecRecord.getExecTime() == null) { |
|
|
|
|
|
// 首次执行
|
|
|
|
|
|
initWeekDim(targetWeekDay); |
|
|
|
|
|
lastExecRecord.setExecTime(now); |
|
|
|
|
|
lastExecRecordService.updateById(lastExecRecord); |
|
|
|
|
|
} else { |
|
|
|
|
|
startWeekDay = DateUtils.getWeekStartAndEnd(lastExecRecord.getExecTime())[0]; |
|
|
|
|
|
if (targetWeekDay.equals(startWeekDay) || targetWeekDay.after(startWeekDay)) { |
|
|
|
|
|
initWeekDim(startWeekDay, targetWeekDay); |
|
|
|
|
|
lastExecRecord.setExecTime(now); |
|
|
|
|
|
lastExecRecordService.updateById(lastExecRecord); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 按周维度连续初始化 |
|
|
|
|
|
* @param startWeekDay |
|
|
|
|
|
* @param targetWeekDay |
|
|
|
|
|
*/ |
|
|
|
|
|
private void initWeekDim(Date startWeekDay, Date targetWeekDay) { |
|
|
|
|
|
LocalDate localStartWeekDay = new LocalDate(startWeekDay); |
|
|
|
|
|
LocalDate localTargetWeekDay = new LocalDate(targetWeekDay); |
|
|
|
|
|
|
|
|
|
|
|
while (localTargetWeekDay.isEqual(localStartWeekDay) |
|
|
|
|
|
|| localTargetWeekDay.isAfter(localStartWeekDay)) { |
|
|
|
|
|
|
|
|
|
|
|
initWeekDim(localStartWeekDay.toDate()); |
|
|
|
|
|
localStartWeekDay = localStartWeekDay.plusDays(7); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 单周初始化 |
|
|
|
|
|
* @param targetWeekDay |
|
|
|
|
|
*/ |
|
|
|
|
|
private void initWeekDim(Date targetWeekDay) { |
|
|
|
|
|
Date[] weekBorders = DateUtils.getWeekStartAndEnd(targetWeekDay); |
|
|
|
|
|
String yyyy = DateUtils.format(targetWeekDay, DateUtils.DATE_PATTERN_YYYY); |
|
|
|
|
|
int weekOfYear = DateUtils.getWeekOfYear(targetWeekDay); |
|
|
|
|
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
|
|
DimWeekEntity dim = new DimWeekEntity(); |
|
|
|
|
|
dim.setEndDate(weekBorders[1]); |
|
|
|
|
|
dim.setStartDate(weekBorders[0]); |
|
|
|
|
|
dim.setWeekName(yyyy + "年第" + weekOfYear + "周"); |
|
|
|
|
|
dim.setWeekOrder(weekOfYear); |
|
|
|
|
|
dim.setYearId(yyyy); |
|
|
|
|
|
dim.setId(yyyy.concat("W").concat(String.format("%02d", weekOfYear))); |
|
|
|
|
|
dim.setCreatedBy(RobotConstant.DIMENSION_ROBOT); |
|
|
|
|
|
dim.setUpdatedBy(RobotConstant.DIMENSION_ROBOT); |
|
|
|
|
|
|
|
|
|
|
|
baseDao.insert(dim); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |