|
@@ -1,6 +1,7 @@
|
|
|
package com.persagy.dmp.report.service;
|
|
|
|
|
|
import com.persagy.common.criteria.JpaUtils;
|
|
|
+import com.persagy.dmp.config.DmpParameterStorage;
|
|
|
import com.persagy.dmp.report.common.json.JsonMapper;
|
|
|
import com.persagy.dmp.report.entity.*;
|
|
|
import com.persagy.dmp.report.enumeration.DateType;
|
|
@@ -12,7 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author fengyanjie
|
|
@@ -34,216 +38,110 @@ public class DataExecutorService {
|
|
|
|
|
|
@Transactional
|
|
|
public void reportRwdObject(DateType dateType, Date startTime, Date endTime) throws Exception {
|
|
|
+ String groupCode = DmpParameterStorage.getGroupCode();
|
|
|
+ String projectId = DmpParameterStorage.getProjectId();
|
|
|
String tableName = "rwd_object";
|
|
|
String sql = "";
|
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
|
- sqlBuilder.append(" select project_id,obj_type,class_code,'" + dateType + "' as date_type, \n");
|
|
|
+ sqlBuilder.append(" select project_id,group_code,obj_type,class_code,'" + dateType + "' as date_type, \n");
|
|
|
reportUtils.appendSql(sqlBuilder, dateType);
|
|
|
- sqlBuilder.append(" count(0) rwd_object_num from " + tableName + " \n");
|
|
|
+ sqlBuilder.append(" count(0) rwd_object_num from dmp_rwd." + tableName + "_" + groupCode + "_" + projectId + " \n");
|
|
|
sqlBuilder.append(" where create_time >= ? and create_time < ? \n");
|
|
|
- sqlBuilder.append(" group by project_id,obj_type,class_code,date_type,year,month,day,hour,season,date \n");
|
|
|
+ sqlBuilder.append(" and project_id = ? and group_code = ? \n");
|
|
|
+ sqlBuilder.append(" group by project_id,group_code,obj_type,class_code,date_type,year,month,day,hour,season,date \n");
|
|
|
sql = sqlBuilder.toString();
|
|
|
//TODO 返回字段值为null报错
|
|
|
- List<Map<String, Object>> list = jpaUtils.queryList(sql, startTime, endTime);
|
|
|
+ List<Map<String, Object>> list = jpaUtils.queryList(sql, startTime, endTime, projectId, groupCode);
|
|
|
List<BaseEntity> data = new ArrayList<>();
|
|
|
- List<Object> yearList = new ArrayList<>();
|
|
|
- List<Object> monthList = new ArrayList<>();
|
|
|
- List<Object> dayList = new ArrayList<>();
|
|
|
- List<Object> hourList = new ArrayList<>();
|
|
|
- List<Object> seasonList = new ArrayList<>();
|
|
|
- List<Object> createTimeList = new ArrayList<>();
|
|
|
list.forEach(item -> {
|
|
|
ReportRwdObject reportRwdObject = new ReportRwdObject();
|
|
|
+ String year = MapUtils.getString(item, "year");
|
|
|
+ String month = MapUtils.getString(item, "month");
|
|
|
+ String day = MapUtils.getString(item, "day");
|
|
|
+ String hour = MapUtils.getString(item, "hour");
|
|
|
+ String season = MapUtils.getString(item, "season");
|
|
|
+ reportRwdObject.setYear(year.equals("null") ? null : year);
|
|
|
+ reportRwdObject.setDay(day.equals("null") ? null : day);
|
|
|
+ reportRwdObject.setMonth(month.equals("null") ? null : month);
|
|
|
+ reportRwdObject.setHour(hour.equals("null") ? null : hour);
|
|
|
+ reportRwdObject.setSeason(season.equals("null") ? null : season);
|
|
|
reportRwdObject.setProjectId(MapUtils.getString(item, "project_id"));
|
|
|
+ reportRwdObject.setGroupCode(MapUtils.getString(item, "group_code"));
|
|
|
reportRwdObject.setObjType(MapUtils.getString(item, "obj_type"));
|
|
|
reportRwdObject.setClassCode(MapUtils.getString(item, "class_code"));
|
|
|
- if (!MapUtils.getString(item, "year").equals("null")) {
|
|
|
- String year = MapUtils.getString(item, "year");
|
|
|
- if (!yearList.contains(year)) {
|
|
|
- yearList.add(year);
|
|
|
- }
|
|
|
- reportRwdObject.setYear(year);
|
|
|
- }
|
|
|
- if (!MapUtils.getString(item, "day").equals("null")) {
|
|
|
- String day = MapUtils.getString(item, "day");
|
|
|
- if (!dayList.contains(day)) {
|
|
|
- dayList.add(day);
|
|
|
- }
|
|
|
- reportRwdObject.setYear(day);
|
|
|
- }
|
|
|
- if (!MapUtils.getString(item, "month").equals("null")) {
|
|
|
- String month = MapUtils.getString(item, "month");
|
|
|
- if (!monthList.contains(month)) {
|
|
|
- monthList.add(month);
|
|
|
- }
|
|
|
- reportRwdObject.setYear(month);
|
|
|
- }
|
|
|
- if (!MapUtils.getString(item, "hour").equals("null")) {
|
|
|
- String hour = MapUtils.getString(item, "hour");
|
|
|
- if (!hourList.contains(hour)) {
|
|
|
- hourList.add(hour);
|
|
|
- }
|
|
|
- reportRwdObject.setHour(hour);
|
|
|
- }
|
|
|
- if (!MapUtils.getString(item, "season").equals("null")) {
|
|
|
- String season = MapUtils.getString(item, "season");
|
|
|
- if (!seasonList.contains(season)) {
|
|
|
- seasonList.add(season);
|
|
|
- }
|
|
|
- reportRwdObject.setSeason(season);
|
|
|
- }
|
|
|
- String date = MapUtils.getString(item, "date");
|
|
|
- if (!createTimeList.contains(date)) {
|
|
|
- createTimeList.add(date);
|
|
|
- }
|
|
|
- reportRwdObject.setCreateTime(date);
|
|
|
+ reportRwdObject.setCreateTime(MapUtils.getString(item, "date"));
|
|
|
reportRwdObject.setRwdObjectNum(MapUtils.getLong(item, "rwd_object_num"));
|
|
|
reportRwdObject.setDateType(DateType.valueOf(MapUtils.getString(item, "date_type")));
|
|
|
data.add(reportRwdObject);
|
|
|
});
|
|
|
ReportConfig reportConfig = reportUtils.queryReportConfig(tableName);
|
|
|
List<Object> tableGroup = JsonMapper.json2List(JsonMapper.toSimpleJson(reportConfig.getTableGroup()));
|
|
|
- List<ReportConfigGroup> groupList = reportUtils.getGroupList(tableGroup);
|
|
|
-
|
|
|
- List<Object[]> year = new ArrayList<>();
|
|
|
- yearList.forEach(item->year.add(new Object[]{item}));
|
|
|
- List<Object[]> month = new ArrayList<>();
|
|
|
- monthList.forEach(item->month.add(new Object[]{item}));
|
|
|
- List<Object[]> day = new ArrayList<>();
|
|
|
- dayList.forEach(item->day.add(new Object[]{item}));
|
|
|
- List<Object[]> hour = new ArrayList<>();
|
|
|
- hourList.forEach(item->hour.add(new Object[]{item}));
|
|
|
- List<Object[]> season = new ArrayList<>();
|
|
|
- seasonList.forEach(item->season.add(new Object[]{item}));
|
|
|
- List<Object[]> createTime = new ArrayList<>();
|
|
|
- createTimeList.forEach(item->createTime.add(new Object[]{item}));
|
|
|
- groupList.add(new ReportConfigGroup("year", year));
|
|
|
- groupList.add(new ReportConfigGroup("month", month));
|
|
|
- groupList.add(new ReportConfigGroup("day", day));
|
|
|
- groupList.add(new ReportConfigGroup("hour", hour));
|
|
|
- groupList.add(new ReportConfigGroup("season", season));
|
|
|
- groupList.add(new ReportConfigGroup("create_time", createTime));
|
|
|
- groupList.add(new ReportConfigGroup("date_type", Collections.singletonList(new Object[]{dateType})));
|
|
|
+ List<ReportConfigGroup> groupList = reportUtils.getGroupList(tableGroup, dateType, startTime, endTime);
|
|
|
List<BaseEntity> resultList = reportUtils.initData(0, groupList, ReportRwdObject.class, new ArrayList<>());
|
|
|
- reportUtils.addList(data, resultList, reportConfig.getCalculatedColumns());
|
|
|
+ List<BaseEntity> result = reportUtils.addList(data, resultList, reportConfig.getCalculatedColumns());
|
|
|
|
|
|
Map<String, String> map = reportUtils.getDate(dateType, startTime, endTime);
|
|
|
String start = map.get("start");
|
|
|
String end = map.get("end");
|
|
|
- QReportRwdObject qt = QReportRwdObject.reportRwdObject;
|
|
|
- Iterable<ReportRwdObject> all = reportObjectRepository.findAll(qt.dateType.eq(dateType).and(qt.createTime.goe(start)).and(qt.createTime.lt(end)));
|
|
|
- reportObjectRepository.deleteAll(all);
|
|
|
+ reportObjectRepository.deleteDateType(dateType.name(), start, end);
|
|
|
List<ReportRwdObject> save = new ArrayList<>();
|
|
|
- data.forEach(item -> save.add((ReportRwdObject) item));
|
|
|
+ result.forEach(item -> save.add((ReportRwdObject) item));
|
|
|
reportObjectRepository.saveAll(save);
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
public void reportAlarmRecord(DateType dateType, Date startTime, Date endTime) throws Exception {
|
|
|
+ String groupCode = DmpParameterStorage.getGroupCode();
|
|
|
+ String projectId = DmpParameterStorage.getProjectId();
|
|
|
String tableName = "alarm_record";
|
|
|
String sql = "";
|
|
|
StringBuilder sqlBuilder = new StringBuilder();
|
|
|
- sqlBuilder.append(" select item_code,project_id,category,class_code,level,state,'" + dateType + "' as date_type, \n");
|
|
|
+ sqlBuilder.append(" select item_code,project_id,group_code,category,class_code,level,state,'" + dateType + "' as date_type, \n");
|
|
|
reportUtils.appendSql(sqlBuilder, dateType);
|
|
|
- sqlBuilder.append(" count(0) alarm_record_num from " + tableName + " \n");
|
|
|
+ sqlBuilder.append(" count(0) alarm_record_num from dmp_alarm." + tableName + " \n");
|
|
|
sqlBuilder.append(" where create_time >= ? and create_time < ? \n");
|
|
|
- sqlBuilder.append(" group by item_code,project_id,category,class_code,level,state,date_type,year,month,day,hour,season,date \n");
|
|
|
+ sqlBuilder.append(" and project_id = ? and group_code = ? \n");
|
|
|
+ sqlBuilder.append(" group by item_code,project_id,group_code,category,class_code,level,state,date_type,year,month,day,hour,season,date \n");
|
|
|
sql = sqlBuilder.toString();
|
|
|
|
|
|
- List<Map<String, Object>> list = jpaUtils.queryList(sql, startTime, endTime);
|
|
|
+ List<Map<String, Object>> list = jpaUtils.queryList(sql, startTime, endTime, projectId, groupCode);
|
|
|
List<BaseEntity> data = new ArrayList<>();
|
|
|
- List<Object> yearList = new ArrayList<>();
|
|
|
- List<Object> monthList = new ArrayList<>();
|
|
|
- List<Object> dayList = new ArrayList<>();
|
|
|
- List<Object> hourList = new ArrayList<>();
|
|
|
- List<Object> seasonList = new ArrayList<>();
|
|
|
- List<Object> createTimeList = new ArrayList<>();
|
|
|
list.forEach(item -> {
|
|
|
ReportAlarmRecord reportAlarmRecord = new ReportAlarmRecord();
|
|
|
+ String year = MapUtils.getString(item, "year");
|
|
|
+ String month = MapUtils.getString(item, "month");
|
|
|
+ String day = MapUtils.getString(item, "day");
|
|
|
+ String hour = MapUtils.getString(item, "hour");
|
|
|
+ String season = MapUtils.getString(item, "season");
|
|
|
+ reportAlarmRecord.setYear(year.equals("null") ? null : year);
|
|
|
+ reportAlarmRecord.setDay(day.equals("null") ? null : day);
|
|
|
+ reportAlarmRecord.setMonth(month.equals("null") ? null : month);
|
|
|
+ reportAlarmRecord.setHour(hour.equals("null") ? null : hour);
|
|
|
+ reportAlarmRecord.setSeason(season.equals("null") ? null : season);
|
|
|
reportAlarmRecord.setItemCode(MapUtils.getString(item, "item_code"));
|
|
|
reportAlarmRecord.setProjectId(MapUtils.getString(item, "project_id"));
|
|
|
+ reportAlarmRecord.setGroupCode(MapUtils.getString(item, "group_code"));
|
|
|
reportAlarmRecord.setCategory(MapUtils.getString(item, "category"));
|
|
|
reportAlarmRecord.setClassCode(MapUtils.getString(item, "class_code"));
|
|
|
reportAlarmRecord.setLevel(MapUtils.getString(item, "level"));
|
|
|
reportAlarmRecord.setAlarmState(MapUtils.getString(item, "state"));
|
|
|
-
|
|
|
- if (!MapUtils.getString(item, "year").equals("null")) {
|
|
|
- String year = MapUtils.getString(item, "year");
|
|
|
- if (!yearList.contains(year)) {
|
|
|
- yearList.add(year);
|
|
|
- }
|
|
|
- reportAlarmRecord.setYear(year);
|
|
|
- }
|
|
|
- if (!MapUtils.getString(item, "day").equals("null")) {
|
|
|
- String day = MapUtils.getString(item, "day");
|
|
|
- if (!dayList.contains(day)) {
|
|
|
- dayList.add(day);
|
|
|
- }
|
|
|
- reportAlarmRecord.setYear(day);
|
|
|
- }
|
|
|
- if (!MapUtils.getString(item, "month").equals("null")) {
|
|
|
- String month = MapUtils.getString(item, "month");
|
|
|
- if (!monthList.contains(month)) {
|
|
|
- monthList.add(month);
|
|
|
- }
|
|
|
- reportAlarmRecord.setYear(month);
|
|
|
- }
|
|
|
- if (!MapUtils.getString(item, "hour").equals("null")) {
|
|
|
- String hour = MapUtils.getString(item, "hour");
|
|
|
- if (!hourList.contains(hour)) {
|
|
|
- hourList.add(hour);
|
|
|
- }
|
|
|
- reportAlarmRecord.setHour(hour);
|
|
|
- }
|
|
|
- if (!MapUtils.getString(item, "season").equals("null")) {
|
|
|
- String season = MapUtils.getString(item, "season");
|
|
|
- if (!seasonList.contains(season)) {
|
|
|
- seasonList.add(season);
|
|
|
- }
|
|
|
- reportAlarmRecord.setSeason(season);
|
|
|
- }
|
|
|
- String date = MapUtils.getString(item, "date");
|
|
|
- if (!createTimeList.contains(date)) {
|
|
|
- createTimeList.add(date);
|
|
|
- }
|
|
|
- reportAlarmRecord.setCreateTime(date);
|
|
|
+ reportAlarmRecord.setCreateTime(MapUtils.getString(item, "date"));
|
|
|
reportAlarmRecord.setAlarmRecordNum(MapUtils.getLong(item, "alarm_record_num"));
|
|
|
reportAlarmRecord.setDateType(DateType.valueOf(MapUtils.getString(item, "date_type")));
|
|
|
data.add(reportAlarmRecord);
|
|
|
});
|
|
|
ReportConfig reportConfig = reportUtils.queryReportConfig(tableName);
|
|
|
List<Object> tableGroup = JsonMapper.json2List(JsonMapper.toSimpleJson(reportConfig.getTableGroup()));
|
|
|
- List<ReportConfigGroup> groupList = reportUtils.getGroupList(tableGroup);
|
|
|
-
|
|
|
- List<Object[]> year = new ArrayList<>();
|
|
|
- yearList.forEach(item->year.add(new Object[]{item}));
|
|
|
- List<Object[]> month = new ArrayList<>();
|
|
|
- monthList.forEach(item->month.add(new Object[]{item}));
|
|
|
- List<Object[]> day = new ArrayList<>();
|
|
|
- dayList.forEach(item->day.add(new Object[]{item}));
|
|
|
- List<Object[]> hour = new ArrayList<>();
|
|
|
- hourList.forEach(item->hour.add(new Object[]{item}));
|
|
|
- List<Object[]> season = new ArrayList<>();
|
|
|
- seasonList.forEach(item->season.add(new Object[]{item}));
|
|
|
- List<Object[]> createTime = new ArrayList<>();
|
|
|
- createTimeList.forEach(item->createTime.add(new Object[]{item}));
|
|
|
- groupList.add(new ReportConfigGroup("year", year));
|
|
|
- groupList.add(new ReportConfigGroup("month", month));
|
|
|
- groupList.add(new ReportConfigGroup("day", day));
|
|
|
- groupList.add(new ReportConfigGroup("hour", hour));
|
|
|
- groupList.add(new ReportConfigGroup("season", season));
|
|
|
- groupList.add(new ReportConfigGroup("create_time", createTime));
|
|
|
- groupList.add(new ReportConfigGroup("date_type", Collections.singletonList(new Object[]{dateType})));
|
|
|
+ List<ReportConfigGroup> groupList = reportUtils.getGroupList(tableGroup, dateType, startTime, endTime);
|
|
|
List<BaseEntity> resultList = reportUtils.initData(0, groupList, ReportAlarmRecord.class, new ArrayList<>());
|
|
|
- reportUtils.addList(data, resultList, reportConfig.getCalculatedColumns());
|
|
|
+ List<BaseEntity> result = reportUtils.addList(data, resultList, reportConfig.getCalculatedColumns());
|
|
|
+
|
|
|
Map<String, String> map = reportUtils.getDate(dateType, startTime, endTime);
|
|
|
String start = map.get("start");
|
|
|
String end = map.get("end");
|
|
|
- QReportAlarmRecord qt = QReportAlarmRecord.reportAlarmRecord;
|
|
|
- Iterable<ReportAlarmRecord> all = reportAlarmRecordRepository.findAll(qt.dateType.eq(dateType).and(qt.createTime.goe(start)).and(qt.createTime.lt(end)));
|
|
|
- reportAlarmRecordRepository.deleteAll(all);
|
|
|
+ reportAlarmRecordRepository.deleteDateType(dateType.name(), start, end);
|
|
|
List<ReportAlarmRecord> save = new ArrayList<>();
|
|
|
- data.forEach(item -> save.add((ReportAlarmRecord) item));
|
|
|
+ result.forEach(item -> save.add((ReportAlarmRecord) item));
|
|
|
reportAlarmRecordRepository.saveAll(save);
|
|
|
}
|
|
|
}
|