|
@@ -8,6 +8,9 @@ import com.bowintek.practice.util.multipdb.DBTypeEnum;
|
|
|
import com.bowintek.practice.util.multipdb.SwitchDataSource;
|
|
|
import com.bowintek.practice.vo.EsQueryLogVo;
|
|
|
import com.bowintek.practice.vo.FactWell.FactWellGroupList;
|
|
|
+import com.bowintek.practice.vo.FactWell.FactWellResult;
|
|
|
+import com.bowintek.practice.vo.FactWell.FactWellTime;
|
|
|
+import com.bowintek.practice.vo.FactWell.FactWellTimeResult;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import org.apache.commons.lang3.SystemUtils;
|
|
@@ -26,18 +29,24 @@ public class FactWellServiceImpl implements FactWellService {
|
|
|
|
|
|
@Override
|
|
|
@SwitchDataSource(DBTypeEnum.POSTGRE)
|
|
|
- public List<FactWellGroupList> getFactWellList(String wellId, String timeType){
|
|
|
+ public FactWellResult getFactWellList(String wellId, String timeType){
|
|
|
+ if(wellId==null) return FactWellResult.gen(new ArrayList<>(), null);
|
|
|
//当前只有月份计算方式
|
|
|
- return getMonthShowInList(wellId);
|
|
|
+ return getMonthShowInList(wellId, null, null);
|
|
|
}
|
|
|
|
|
|
- public List<FactWellGroupList> getMonthShowInList(String wellId){
|
|
|
+ public FactWellTimeResult getMonthTimeLimit(String wellId){
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(getToDay());
|
|
|
|
|
|
+ //根据SQL查询最后一天有数据的日期
|
|
|
+ List<FactWellTime> dayList = factWellCQuery.getDayTime(wellId);
|
|
|
+ if(dayList.size()>0) calendar.setTime(dayList.get(0).getDayTime());
|
|
|
+
|
|
|
+ //取当月最后一天
|
|
|
+ calendar.add(Calendar.MONTH, 1);
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
- //上月最后
|
|
|
Date endTime = calendar.getTime();
|
|
|
|
|
|
//11月前的1号
|
|
@@ -45,16 +54,19 @@ public class FactWellServiceImpl implements FactWellService {
|
|
|
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
Date startTime = calendar.getTime();
|
|
|
|
|
|
- return getMonthShowInList(wellId, startTime, endTime);
|
|
|
+ return FactWellTimeResult.gen("day", startTime, endTime);
|
|
|
}
|
|
|
- public List<FactWellGroupList> getMonthShowInList(String wellId, Date startTime, Date endTime){
|
|
|
+ public FactWellResult getMonthShowInList(String wellId, Date startTime, Date endTime){
|
|
|
+ FactWellTimeResult timeResult = getMonthTimeLimit(wellId);
|
|
|
//重新计算当前12月
|
|
|
- if(startTime==null || endTime==null) return getMonthGroupList(wellId);
|
|
|
+ if(startTime==null || endTime==null) {
|
|
|
+ startTime = timeResult.getStartTime();
|
|
|
+ endTime = timeResult.getEndTime();
|
|
|
+ }
|
|
|
|
|
|
System.out.println("getMonthGroupList startTime:"+dateToDayString(startTime)
|
|
|
+" endTime:"+dateToDayString(endTime)
|
|
|
+" wellId:"+wellId);
|
|
|
- if(StringUtils.IsNullEmpty(wellId)) return new ArrayList<>();
|
|
|
|
|
|
List<FactWellGroupList> rtnList = factWellCQuery
|
|
|
.getMonthShowInList(wellId, dateToDayString(startTime), dateToDayString(endTime));
|
|
@@ -70,37 +82,31 @@ public class FactWellServiceImpl implements FactWellService {
|
|
|
time = calendarTime.getTime();
|
|
|
}
|
|
|
|
|
|
- rtnList = supplementList(wellId, monthList, rtnList);
|
|
|
- return rtnList;
|
|
|
+ return FactWellResult.gen(supplementList(wellId, monthList, rtnList),
|
|
|
+ Arrays.stream((new FactWellTimeResult[]{timeResult})).toList());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@SwitchDataSource(DBTypeEnum.POSTGRE)
|
|
|
- public List<FactWellGroupList> getFactWellListByTime(String wellId, String timeType, Date startTime, Date endTime){
|
|
|
+ public FactWellResult getFactWellListByTime(String wellId, String timeType, Date startTime, Date endTime){
|
|
|
if(timeType.equals("day")) return getDayGroupList(wellId, startTime, endTime);
|
|
|
if(timeType.equals("month")) return getMonthGroupList(wellId, startTime, endTime);
|
|
|
else return getYearGroupList(wellId, startTime, endTime);
|
|
|
}
|
|
|
|
|
|
- public List<FactWellGroupList> getDayGroupList(String wellId){
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(getToDay()); // 设置当前天日期
|
|
|
- //上月最后一天
|
|
|
- Date endTime = calendar.getTime();
|
|
|
+ public FactWellResult getDayGroupList(String wellId, Date startTime, Date endTime){
|
|
|
+ List<FactWellTimeResult> timeList = getTimeLimitList(wellId);
|
|
|
+ FactWellTimeResult timeResult = getTimeResult(timeList, "day");
|
|
|
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, -29);
|
|
|
- Date startTime = calendar.getTime();
|
|
|
- return getDayGroupList(wellId, startTime, endTime);
|
|
|
- }
|
|
|
-
|
|
|
- public List<FactWellGroupList> getDayGroupList(String wellId, Date startTime, Date endTime){
|
|
|
//重新计算当前30天日期
|
|
|
- if(startTime==null || endTime==null) return getDayGroupList(wellId);
|
|
|
+ if(startTime==null || endTime==null) {
|
|
|
+ startTime = timeResult.getStartTime();
|
|
|
+ endTime = timeResult.getEndTime();
|
|
|
+ }
|
|
|
|
|
|
System.out.println("getMonthGroupList startTime:"+dateToDayString(startTime)
|
|
|
+" endTime:"+dateToDayString(endTime)
|
|
|
+" wellId:"+wellId);
|
|
|
- if(StringUtils.IsNullEmpty(wellId)) return new ArrayList<>();
|
|
|
|
|
|
List<FactWellGroupList> rtnList = factWellCQuery
|
|
|
.getDayGroupList(wellId, dateToDayString(startTime), dateToDayString(endTime));
|
|
@@ -115,44 +121,23 @@ public class FactWellServiceImpl implements FactWellService {
|
|
|
calendarTime.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
time = calendarTime.getTime();
|
|
|
}
|
|
|
- rtnList = supplementList(wellId, dayList, rtnList);
|
|
|
- return rtnList;
|
|
|
- }
|
|
|
|
|
|
- public Date getToDay(){
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
- return calendar.getTime();
|
|
|
+ return FactWellResult.gen(supplementList(wellId, dayList, rtnList), timeList);
|
|
|
}
|
|
|
|
|
|
- public List<FactWellGroupList> getMonthGroupList(String wellId){
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(getToDay());
|
|
|
-
|
|
|
- calendar.add(Calendar.MONTH, 1);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
- //当前月最后一天
|
|
|
- Date endTime = calendar.getTime();
|
|
|
-
|
|
|
- //11月前的1号
|
|
|
- calendar.add(Calendar.MONTH, -11);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- Date startTime = calendar.getTime();
|
|
|
+ public FactWellResult getMonthGroupList(String wellId, Date startTime, Date endTime){
|
|
|
+ List<FactWellTimeResult> timeList = getTimeLimitList(wellId);
|
|
|
+ FactWellTimeResult timeResult = getTimeResult(timeList, "month");
|
|
|
|
|
|
- return getMonthGroupList(wellId, startTime, endTime);
|
|
|
- }
|
|
|
- public List<FactWellGroupList> getMonthGroupList(String wellId, Date startTime, Date endTime){
|
|
|
//重新计算当前12月
|
|
|
- if(startTime==null || endTime==null) return getMonthGroupList(wellId);
|
|
|
+ if(startTime==null || endTime==null) {
|
|
|
+ startTime = timeResult.getStartTime();
|
|
|
+ endTime = timeResult.getEndTime();
|
|
|
+ }
|
|
|
|
|
|
System.out.println("getMonthGroupList startTime:"+dateToDayString(startTime)
|
|
|
+" endTime:"+dateToDayString(endTime)
|
|
|
+" wellId:"+wellId);
|
|
|
- if(StringUtils.IsNullEmpty(wellId)) return new ArrayList<>();
|
|
|
|
|
|
List<FactWellGroupList> rtnList = factWellCQuery
|
|
|
.getMonthGroupList(wellId, dateToDayString(startTime), dateToDayString(endTime));
|
|
@@ -168,36 +153,22 @@ public class FactWellServiceImpl implements FactWellService {
|
|
|
time = calendarTime.getTime();
|
|
|
}
|
|
|
|
|
|
- rtnList = supplementList(wellId, monthList, rtnList);
|
|
|
- return rtnList;
|
|
|
+ return FactWellResult.gen(supplementList(wellId, monthList, rtnList), timeList);
|
|
|
}
|
|
|
|
|
|
- public List<FactWellGroupList> getYearGroupList(String wellId){
|
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
- calendar.setTime(getToDay());
|
|
|
- calendar.set(Calendar.MONTH, 12);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- calendar.add(Calendar.MONTH, 1);
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
- //当年最后一天
|
|
|
- Date endTime = calendar.getTime();
|
|
|
- //5年前1月1日
|
|
|
- calendar.add(Calendar.YEAR, -4);
|
|
|
- calendar.set(Calendar.MONTH, 1);
|
|
|
- calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
- Date startTime = calendar.getTime();
|
|
|
-
|
|
|
- return getYearGroupList(wellId, startTime, endTime);
|
|
|
- }
|
|
|
+ public FactWellResult getYearGroupList(String wellId, Date startTime, Date endTime){
|
|
|
+ List<FactWellTimeResult> timeList = getTimeLimitList(wellId);
|
|
|
+ FactWellTimeResult timeResult = getTimeResult(timeList, "year");
|
|
|
|
|
|
- public List<FactWellGroupList> getYearGroupList(String wellId, Date startTime, Date endTime){
|
|
|
//重新计算5年时间
|
|
|
- if(startTime==null || endTime==null) return getYearGroupList(wellId);
|
|
|
+ if(startTime==null || endTime==null) {
|
|
|
+ startTime = timeResult.getStartTime();
|
|
|
+ endTime = timeResult.getEndTime();
|
|
|
+ }
|
|
|
|
|
|
System.out.println("getMonthGroupList startTime:"+dateToDayString(startTime)
|
|
|
+" endTime:"+dateToDayString(endTime)
|
|
|
+" wellId:"+wellId);
|
|
|
- if(StringUtils.IsNullEmpty(wellId)) return new ArrayList<>();
|
|
|
|
|
|
List<FactWellGroupList> rtnList = factWellCQuery
|
|
|
.getYearGroupList(wellId, dateToDayString(startTime), dateToDayString(endTime));
|
|
@@ -213,10 +184,89 @@ public class FactWellServiceImpl implements FactWellService {
|
|
|
time = calendarTime.getTime();
|
|
|
}
|
|
|
|
|
|
- rtnList = supplementList(wellId, monthList, rtnList);
|
|
|
+ return FactWellResult.gen(supplementList(wellId, monthList, rtnList), timeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<FactWellTimeResult> getTimeLimitList(String wellId){
|
|
|
+ //根据SQL查询最后一天有数据的日期
|
|
|
+ List<FactWellTime> dayList = factWellCQuery.getDayTime(wellId);
|
|
|
+ List<FactWellTime> monthList = factWellCQuery.getMonthTime(wellId);
|
|
|
+ Date day = getToDay(), month = getToDay();
|
|
|
+ if(dayList.size()>0) day = dayList.get(0).getDayTime();
|
|
|
+ if(monthList.size()>0) month = monthList.get(0).getDayTime();
|
|
|
+
|
|
|
+ List<FactWellTimeResult> rtnList = new ArrayList<>();
|
|
|
+ rtnList.add(getDayTimeLimit(day));
|
|
|
+ rtnList.add(getMonthTimeLimit(month));
|
|
|
+ rtnList.add(getYearTimeLimit(month));
|
|
|
+
|
|
|
return rtnList;
|
|
|
}
|
|
|
|
|
|
+ public FactWellTimeResult getTimeResult(List<FactWellTimeResult> timeList, String timeType){
|
|
|
+ return timeList.stream().filter(r->r.getTimeType().equals(timeType))
|
|
|
+ .collect(Collectors.toList()).get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public FactWellTimeResult getDayTimeLimit(Date toDay){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(toDay);
|
|
|
+
|
|
|
+ //有数据当天的日期
|
|
|
+ Date endTime = calendar.getTime();
|
|
|
+ //向前推30天后的日期
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -29);
|
|
|
+ Date startTime = calendar.getTime();
|
|
|
+ return FactWellTimeResult.gen("day", startTime, endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ public FactWellTimeResult getMonthTimeLimit(Date toDay){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(toDay);
|
|
|
+
|
|
|
+ //当前月最后一天
|
|
|
+ calendar.add(Calendar.MONTH, 1);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
+ Date endTime = calendar.getTime();
|
|
|
+
|
|
|
+ //11月前的1号
|
|
|
+ calendar.add(Calendar.MONTH, -11);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ Date startTime = calendar.getTime();
|
|
|
+
|
|
|
+ return FactWellTimeResult.gen("month", startTime, endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ public FactWellTimeResult getYearTimeLimit(Date toDay){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(toDay);
|
|
|
+
|
|
|
+ //当年12月最后一天
|
|
|
+ calendar.set(Calendar.MONTH, 11);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ calendar.add(Calendar.MONTH, 1);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
+ Date endTime = calendar.getTime();
|
|
|
+
|
|
|
+ //5年前1月1日
|
|
|
+ calendar.add(Calendar.YEAR, -4);
|
|
|
+ calendar.set(Calendar.MONTH, 0);
|
|
|
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ Date startTime = calendar.getTime();
|
|
|
+
|
|
|
+ return FactWellTimeResult.gen("year", startTime, endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Date getToDay(){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ return calendar.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
public List<FactWellGroupList> supplementList(String wellId, List<String> timeList, List<FactWellGroupList> source){
|
|
|
//if(source.stream().filter(r->r.getTime_str().equals()))
|
|
|
for(int i=0;i<timeList.size();i++){
|