|
@@ -68,60 +68,36 @@ public class ReportTableTask {
|
|
|
log.info("动态报表,{},执行结束,执行时间为{}", reportTable, DateUtil.dateChangeStrYmdhmss(new Date()));
|
|
|
return;
|
|
|
}
|
|
|
- JSONObject jsonObject1 = objects.getJSONObject(0);
|
|
|
- JSONArray objects1 = jsonObject1.getJSONArray("item");
|
|
|
- if (Blank.isNotEmpty(objects1)) {
|
|
|
- for (int i = 0; i < objects1.size(); i++) {
|
|
|
- JSONObject jsonObject2 = objects1.getJSONObject(i);
|
|
|
- Integer itemGroupId = jsonObject2.getInteger("itemGroupId");
|
|
|
- Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
|
|
|
- ItemGroup itemGroup = itemGroupDao.getItemGroupById(itemGroupId);
|
|
|
- String itemName = jsonObject2.getString("itemName");
|
|
|
- if (reportTable.getReportValueFormat() == ConstantStr.EVERY_DAY_ES) {
|
|
|
- String startBelongTime = DateUtil.dateChangeStrYmdhms(DateUtil.getAppointDh(-1, 8)).substring(0, timeFormat.length());
|
|
|
- //获取当前时间,并转为yyyy-MM-dd HH
|
|
|
- String endBelongTime = DateUtil.dateChangeStrYmdhms(DateUtil.getAppointDh(0, 7)).substring(0, timeFormat.length());
|
|
|
- List<RawData> rawDataList = rawDataDao.getTableDataEvery(itemGroupId, remainder, itemGroup.getDataSourceId(), itemName, startBelongTime, endBelongTime);
|
|
|
- if (Blank.isNotEmpty(rawDataList)) {
|
|
|
- String dataType = rawDataList.get(0).getDataType();
|
|
|
- List<String> dataTimeList = new ArrayList();
|
|
|
- if (dataType.equals("boolean")) {
|
|
|
- List<Boolean> booleanList = new ArrayList<>();
|
|
|
- for (int j = 0; j < rawDataList.size(); j++) {
|
|
|
- String dataValue = rawDataList.get(j).getDataValue();
|
|
|
- Boolean[] dataValueList = JSON.parseObject(dataValue, Boolean[].class);
|
|
|
- Boolean avg;
|
|
|
- if (itemGroup.getValueCondition() == ConstantStr.AVERAGE_VALUE) {
|
|
|
- avg = MathUtil.getAvgBoolean(dataValueList);
|
|
|
- } else if (itemGroup.getValueCondition() == ConstantStr.MAX_VALUE) {
|
|
|
- avg = MathUtil.getMaxBoolean(dataValueList);
|
|
|
- } else if (itemGroup.getValueCondition() == ConstantStr.MIN_VALUE) {
|
|
|
- avg = MathUtil.getMinBoolean(dataValueList);
|
|
|
- } else {
|
|
|
- messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
|
|
|
- reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
|
|
|
- "目前还未适配此种类型数据组的取值条件",
|
|
|
- ConstantStr.NO_READ));
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
|
|
|
- }
|
|
|
- booleanList.add(avg);
|
|
|
- String valueBelongTime = rawDataList.get(j).getValueBelongTime();
|
|
|
- dataTimeList.add(valueBelongTime);
|
|
|
- }
|
|
|
- jsonObject2.put("dataList", booleanList);
|
|
|
- } else {
|
|
|
- List<Object> dataList = new ArrayList();
|
|
|
- for (int j = 0; j < rawDataList.size(); j++) {
|
|
|
- String dataValue = rawDataList.get(j).getDataValue();
|
|
|
- try {
|
|
|
- BigDecimal[] dataValueList = JSON.parseObject(dataValue, BigDecimal[].class);
|
|
|
- BigDecimal avg;
|
|
|
+ for (int i = 0; i < objects.size(); i++) {
|
|
|
+ JSONObject jsonObject1 = objects.getJSONObject(i);
|
|
|
+ JSONArray objects1 = jsonObject1.getJSONArray("item");
|
|
|
+ if (Blank.isNotEmpty(objects1)) {
|
|
|
+ for (int j = 0; j < objects1.size(); j++) {
|
|
|
+ JSONObject jsonObject2 = objects1.getJSONObject(j);
|
|
|
+ Integer itemGroupId = jsonObject2.getInteger("itemGroupId");
|
|
|
+ Integer remainder = itemGroupId % ConstantStr.SUB_TABLE_NUM;
|
|
|
+ ItemGroup itemGroup = itemGroupDao.getItemGroupById(itemGroupId);
|
|
|
+ String itemName = jsonObject2.getString("itemName");
|
|
|
+ if (reportTable.getReportValueFormat() == ConstantStr.EVERY_DAY_ES) {
|
|
|
+ String startBelongTime = DateUtil.dateChangeStrYmdhms(DateUtil.getAppointDh(-1, 8)).substring(0, timeFormat.length());
|
|
|
+ //获取当前时间,并转为yyyy-MM-dd HH
|
|
|
+ String endBelongTime = DateUtil.dateChangeStrYmdhms(DateUtil.getAppointDh(0, 7)).substring(0, timeFormat.length());
|
|
|
+ List<RawData> rawDataList = rawDataDao.getTableDataEvery(itemGroupId, remainder, itemGroup.getDataSourceId(), itemName, startBelongTime, endBelongTime);
|
|
|
+ if (Blank.isNotEmpty(rawDataList)) {
|
|
|
+ String dataType = rawDataList.get(0).getDataType();
|
|
|
+ List<String> dataTimeList = new ArrayList();
|
|
|
+ if (dataType.equals("boolean")) {
|
|
|
+ List<Boolean> booleanList = new ArrayList<>();
|
|
|
+ for (int k = 0; k < rawDataList.size(); k++) {
|
|
|
+ String dataValue = rawDataList.get(k).getDataValue();
|
|
|
+ Boolean[] dataValueList = JSON.parseObject(dataValue, Boolean[].class);
|
|
|
+ Boolean avg;
|
|
|
if (itemGroup.getValueCondition() == ConstantStr.AVERAGE_VALUE) {
|
|
|
- avg = MathUtil.getAvg(dataValueList);
|
|
|
+ avg = MathUtil.getAvgBoolean(dataValueList);
|
|
|
} else if (itemGroup.getValueCondition() == ConstantStr.MAX_VALUE) {
|
|
|
- avg = MathUtil.getMax(dataValueList);
|
|
|
+ avg = MathUtil.getMaxBoolean(dataValueList);
|
|
|
} else if (itemGroup.getValueCondition() == ConstantStr.MIN_VALUE) {
|
|
|
- avg = MathUtil.getMin(dataValueList);
|
|
|
+ avg = MathUtil.getMinBoolean(dataValueList);
|
|
|
} else {
|
|
|
messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
|
|
|
reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
|
|
@@ -129,34 +105,60 @@ public class ReportTableTask {
|
|
|
ConstantStr.NO_READ));
|
|
|
throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
|
|
|
}
|
|
|
- dataList.add(avg);
|
|
|
- } catch (Exception e) {
|
|
|
- String[] dataValueList = JSON.parseObject(dataValue, String[].class);
|
|
|
- if (Blank.isNotEmpty(dataValueList)) {
|
|
|
- dataList.add(dataValueList[0]);
|
|
|
- } else {
|
|
|
- dataList.add("");
|
|
|
+ booleanList.add(avg);
|
|
|
+ String valueBelongTime = rawDataList.get(k).getValueBelongTime();
|
|
|
+ dataTimeList.add(valueBelongTime);
|
|
|
+ }
|
|
|
+ jsonObject2.put("dataList", booleanList);
|
|
|
+ } else {
|
|
|
+ List<Object> dataList = new ArrayList();
|
|
|
+ for (int k = 0; k < rawDataList.size(); k++) {
|
|
|
+ String dataValue = rawDataList.get(k).getDataValue();
|
|
|
+ try {
|
|
|
+ BigDecimal[] dataValueList = JSON.parseObject(dataValue, BigDecimal[].class);
|
|
|
+ BigDecimal avg;
|
|
|
+ if (itemGroup.getValueCondition() == ConstantStr.AVERAGE_VALUE) {
|
|
|
+ avg = MathUtil.getAvg(dataValueList);
|
|
|
+ } else if (itemGroup.getValueCondition() == ConstantStr.MAX_VALUE) {
|
|
|
+ avg = MathUtil.getMax(dataValueList);
|
|
|
+ } else if (itemGroup.getValueCondition() == ConstantStr.MIN_VALUE) {
|
|
|
+ avg = MathUtil.getMin(dataValueList);
|
|
|
+ } else {
|
|
|
+ messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
|
|
|
+ reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
|
|
|
+ "目前还未适配此种类型数据组的取值条件",
|
|
|
+ ConstantStr.NO_READ));
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
|
|
|
+ }
|
|
|
+ dataList.add(avg);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String[] dataValueList = JSON.parseObject(dataValue, String[].class);
|
|
|
+ if (Blank.isNotEmpty(dataValueList)) {
|
|
|
+ dataList.add(dataValueList[0]);
|
|
|
+ } else {
|
|
|
+ dataList.add("");
|
|
|
+ }
|
|
|
}
|
|
|
+ String valueBelongTime = rawDataList.get(j).getValueBelongTime();
|
|
|
+ dataTimeList.add(valueBelongTime);
|
|
|
}
|
|
|
- String valueBelongTime = rawDataList.get(i).getValueBelongTime();
|
|
|
- dataTimeList.add(valueBelongTime);
|
|
|
+ jsonObject2.put("dataList", dataList);
|
|
|
}
|
|
|
- jsonObject2.put("dataList", dataList);
|
|
|
+ } else {
|
|
|
+ jsonObject2.put("dataList", new ArrayList<>());
|
|
|
}
|
|
|
} else {
|
|
|
- jsonObject2.put("dataList", new ArrayList<>());
|
|
|
+ messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
|
|
|
+ reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
|
|
|
+ "目前还未适配此种类型数据组的取值条件",
|
|
|
+ ConstantStr.NO_READ));
|
|
|
+ throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
|
|
|
}
|
|
|
- } else {
|
|
|
- messageNoticeDao.addMessageNotice(new MessageNotice(reportTable.getUserId(),
|
|
|
- reportTable.getReportTableName() + DateUtil.dateChangeStrYmdhms(new Date()) + "生成报表失败",
|
|
|
- "目前还未适配此种类型数据组的取值条件",
|
|
|
- ConstantStr.NO_READ));
|
|
|
- throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "目前还未适配此种类型数据组的取值条件");
|
|
|
+ objects1.set(j, jsonObject2);
|
|
|
}
|
|
|
- objects1.set(i, jsonObject2);
|
|
|
}
|
|
|
+ objects.set(i, jsonObject1);
|
|
|
}
|
|
|
- objects.set(0, jsonObject1);
|
|
|
jsonObject.put("tables", objects);
|
|
|
ReportTable reportTable1 = new ReportTable();
|
|
|
reportTable1.setTableTemplateId(reportTable.getTableTemplateId());
|