|
|
|
@ -1,17 +1,24 @@
|
|
|
|
|
package com.anjiplus.template.gaea.business.modules.reportexcel.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.anji.plus.gaea.constant.BaseOperationEnum;
|
|
|
|
|
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
|
|
|
|
|
import com.anji.plus.gaea.exception.BusinessException;
|
|
|
|
|
import com.anji.plus.gaea.utils.GaeaAssert;
|
|
|
|
|
import com.anji.plus.gaea.utils.GaeaBeanUtils;
|
|
|
|
|
import com.anjiplus.template.gaea.business.code.ResponseCode;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.DataSetDto;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.dataset.controller.dto.OriginalDataDto;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.dataset.service.DataSetService;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.report.dao.ReportMapper;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.reportexcel.controller.dto.ReportExcelDto;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.reportexcel.dao.ReportExcelMapper;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.reportexcel.dao.entity.ReportExcel;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.reportexcel.service.ReportExcelService;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.reportexcel.util.XlsSheetUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
@ -20,6 +27,8 @@ import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* TODO
|
|
|
|
|
*
|
|
|
|
@ -34,6 +43,9 @@ public class ReportExcelServiceImpl implements ReportExcelService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ReportExcelMapper reportExcelMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DataSetService dataSetService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ReportMapper reportMapper;
|
|
|
|
@ -93,9 +105,9 @@ public class ReportExcelServiceImpl implements ReportExcelService {
|
|
|
|
|
reportExcelDto.setSetParam(setParam);
|
|
|
|
|
}
|
|
|
|
|
reportExcelDto.setReportName(report.getReportName());
|
|
|
|
|
// TODO 数据集解析,待扩展
|
|
|
|
|
// JSONObject jsonObject = reportUtil.reportParse(reportExcelDto);
|
|
|
|
|
// reportExcelDto.setJsonStr(JSONObject.toJSONString(jsonObject));
|
|
|
|
|
// 数据集解析
|
|
|
|
|
String jsonStr = analysisReportData(reportExcelDto);
|
|
|
|
|
reportExcelDto.setJsonStr(jsonStr);
|
|
|
|
|
// reportExcelDto.setTotal(jsonObject.getJSONObject("rows").size());
|
|
|
|
|
return reportExcelDto;
|
|
|
|
|
}
|
|
|
|
@ -106,4 +118,106 @@ public class ReportExcelServiceImpl implements ReportExcelService {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解析报表数据,动态插入列表数据和对象数据
|
|
|
|
|
*/
|
|
|
|
|
private String analysisReportData(ReportExcelDto reportExcelDto) {
|
|
|
|
|
|
|
|
|
|
String jsonStr = reportExcelDto.getJsonStr();
|
|
|
|
|
List<JSONObject> dbObjectList = (List<JSONObject>) JSON.parse(jsonStr);
|
|
|
|
|
|
|
|
|
|
if (dbObjectList != null && dbObjectList.size() > 0) {
|
|
|
|
|
for (int x = 0; x < dbObjectList.size(); x++) {
|
|
|
|
|
analysisSheet(dbObjectList.get(x));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JSONObject.toJSONString(dbObjectList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解析单sheet
|
|
|
|
|
*
|
|
|
|
|
* @param dbObject
|
|
|
|
|
*/
|
|
|
|
|
private void analysisSheet(JSONObject dbObject) {
|
|
|
|
|
//data是一个二维数组
|
|
|
|
|
if (dbObject.containsKey("data") && null != dbObject.get("data")) {
|
|
|
|
|
List<JSONArray> data = (List<JSONArray>) dbObject.get("data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//行
|
|
|
|
|
for (int r = 0; r < data.size(); r++) {
|
|
|
|
|
JSONArray jsonArray = data.get(r);
|
|
|
|
|
//列
|
|
|
|
|
for (int c = 0; c < jsonArray.size(); c++) {
|
|
|
|
|
//单元格
|
|
|
|
|
JSONObject cell = jsonArray.getJSONObject(c);
|
|
|
|
|
if (null != cell && cell.containsKey("v") && StringUtils.isNotBlank(cell.getString("v"))) {
|
|
|
|
|
String v = cell.getString("v");
|
|
|
|
|
DataSetDto dataSet = getDataSet(v);
|
|
|
|
|
if (null != dataSet) {
|
|
|
|
|
OriginalDataDto originalDataDto = dataSetService.getData(dataSet);
|
|
|
|
|
if (null != originalDataDto.getData()) {
|
|
|
|
|
if (originalDataDto.getData().size() == 1) {
|
|
|
|
|
//对象
|
|
|
|
|
JSONObject jsonObject = originalDataDto.getData().get(0);
|
|
|
|
|
String fieldLabel = jsonObject.getString(dataSet.getFieldLabel());
|
|
|
|
|
|
|
|
|
|
String replace = v.replace("#{".concat(dataSet.getSetCode()).concat(".").concat(dataSet.getFieldLabel()).concat("}"), fieldLabel);
|
|
|
|
|
dbObject.getJSONArray("data").getJSONArray(r).getJSONObject(c).put("v", replace);
|
|
|
|
|
dbObject.getJSONArray("data").getJSONArray(r).getJSONObject(c).put("m", replace);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
//集合
|
|
|
|
|
JSONObject jsonObject = originalDataDto.getData().get(0);
|
|
|
|
|
String fieldLabel = jsonObject.getString(dataSet.getFieldLabel());
|
|
|
|
|
|
|
|
|
|
String replace = v.replace("#{".concat(dataSet.getSetCode()).concat(".").concat(dataSet.getFieldLabel()).concat("}"), fieldLabel);
|
|
|
|
|
dbObject.getJSONArray("data").getJSONArray(r).getJSONObject(c).put("v", replace);
|
|
|
|
|
dbObject.getJSONArray("data").getJSONArray(r).getJSONObject(c).put("m", replace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println("aaaa");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解析 #{xxxx.xxxxx} 数据
|
|
|
|
|
* @param v
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private DataSetDto getDataSet(String v) {
|
|
|
|
|
DataSetDto dto = new DataSetDto();
|
|
|
|
|
if (v.contains("#{") && v.contains("}")) {
|
|
|
|
|
int start = v.indexOf("#{") + 2;
|
|
|
|
|
int end = v.indexOf("}");
|
|
|
|
|
if (start < end) {
|
|
|
|
|
String substring = v.substring(start, end);
|
|
|
|
|
if (substring.contains(".")) {
|
|
|
|
|
String[] split = substring.split("\\.");
|
|
|
|
|
dto.setSetCode( split[0]);
|
|
|
|
|
dto.setFieldLabel(split[1]);
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|