Raod 4 years ago
parent 29bb62d309
commit 07ed946a91

@ -28,9 +28,7 @@ import org.springframework.beans.BeanUtils;
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 java.util.ArrayList; import java.util.*;
import java.util.LinkedList;
import java.util.List;
/** /**
* TODO * TODO
@ -127,11 +125,12 @@ public class ReportExcelServiceImpl implements ReportExcelService {
private String analysisReportData(ReportExcelDto reportExcelDto) { private String analysisReportData(ReportExcelDto reportExcelDto) {
String jsonStr = reportExcelDto.getJsonStr(); String jsonStr = reportExcelDto.getJsonStr();
String setParam = reportExcelDto.getSetParam();
List<JSONObject> dbObjectList = (List<JSONObject>) JSON.parse(jsonStr); List<JSONObject> dbObjectList = (List<JSONObject>) JSON.parse(jsonStr);
if (dbObjectList != null && dbObjectList.size() > 0) { if (dbObjectList != null && dbObjectList.size() > 0) {
for (int x = 0; x < dbObjectList.size(); x++) { for (int x = 0; x < dbObjectList.size(); x++) {
analysisSheetCellData(dbObjectList.get(x)); analysisSheetCellData(dbObjectList.get(x), setParam);
} }
} }
//fastjson $ref 循环引用 //fastjson $ref 循环引用
@ -143,7 +142,7 @@ public class ReportExcelServiceImpl implements ReportExcelService {
* *
* @param dbObject * @param dbObject
*/ */
private void analysisSheet(JSONObject dbObject) { private void analysisSheet(JSONObject dbObject, String setParma) {
//data是一个二维数组 //data是一个二维数组
if (dbObject.containsKey("data") && null != dbObject.get("data")) { if (dbObject.containsKey("data") && null != dbObject.get("data")) {
List<JSONArray> data = (List<JSONArray>) dbObject.get("data"); List<JSONArray> data = (List<JSONArray>) dbObject.get("data");
@ -158,7 +157,7 @@ public class ReportExcelServiceImpl implements ReportExcelService {
JSONObject cell = jsonArray.getJSONObject(c); JSONObject cell = jsonArray.getJSONObject(c);
if (null != cell && cell.containsKey("v") && StringUtils.isNotBlank(cell.getString("v"))) { if (null != cell && cell.containsKey("v") && StringUtils.isNotBlank(cell.getString("v"))) {
String v = cell.getString("v"); String v = cell.getString("v");
DataSetDto dataSet = getDataSet(v); DataSetDto dataSet = getDataSet(v, setParma);
if (null != dataSet) { if (null != dataSet) {
OriginalDataDto originalDataDto = dataSetService.getData(dataSet); OriginalDataDto originalDataDto = dataSetService.getData(dataSet);
if (null != originalDataDto.getData()) { if (null != originalDataDto.getData()) {
@ -204,7 +203,7 @@ public class ReportExcelServiceImpl implements ReportExcelService {
* *
* @param dbObject * @param dbObject
*/ */
private void analysisSheetCellData(JSONObject dbObject) { private void analysisSheetCellData(JSONObject dbObject, String setParam) {
//清空data值 //清空data值
dbObject.remove("data"); dbObject.remove("data");
//celldata是一个一维数组 //celldata是一个一维数组
@ -225,7 +224,7 @@ public class ReportExcelServiceImpl implements ReportExcelService {
JSONObject cell = cellObj.getJSONObject("v"); JSONObject cell = cellObj.getJSONObject("v");
if (null != cell && cell.containsKey("v") && StringUtils.isNotBlank(cell.getString("v"))) { if (null != cell && cell.containsKey("v") && StringUtils.isNotBlank(cell.getString("v"))) {
String v = cell.getString("v"); String v = cell.getString("v");
DataSetDto dataSet = getDataSet(v); DataSetDto dataSet = getDataSet(v, setParam);
if (null != dataSet) { if (null != dataSet) {
OriginalDataDto originalDataDto = dataSetService.getData(dataSet); OriginalDataDto originalDataDto = dataSetService.getData(dataSet);
if (null != originalDataDto.getData()) { if (null != originalDataDto.getData()) {
@ -267,10 +266,6 @@ public class ReportExcelServiceImpl implements ReportExcelService {
} }
} }
System.out.println("aaaa");
} }
@ -282,7 +277,8 @@ public class ReportExcelServiceImpl implements ReportExcelService {
* @param v * @param v
* @return * @return
*/ */
private DataSetDto getDataSet(String v) { private DataSetDto getDataSet(String v, String setParam) {
DataSetDto dto = new DataSetDto(); DataSetDto dto = new DataSetDto();
if (v.contains("#{") && v.contains("}")) { if (v.contains("#{") && v.contains("}")) {
int start = v.indexOf("#{") + 2; int start = v.indexOf("#{") + 2;
@ -293,6 +289,7 @@ public class ReportExcelServiceImpl implements ReportExcelService {
String[] split = substring.split("\\."); String[] split = substring.split("\\.");
dto.setSetCode( split[0]); dto.setSetCode( split[0]);
dto.setFieldLabel(split[1]); dto.setFieldLabel(split[1]);
getContextData(setParam, dto);
return dto; return dto;
} }
} }
@ -300,4 +297,22 @@ public class ReportExcelServiceImpl implements ReportExcelService {
return null; return null;
} }
/**
*
* @param setParam
* @param dto
*/
private void getContextData(String setParam, DataSetDto dto) {
if (StringUtils.isNotBlank(setParam)) {
JSONObject setParamJson = JSONObject.parseObject(setParam);
Map<String, Object> map = new HashMap<>();
// 查询条件
if (setParamJson.containsKey(dto.getSetCode())) {
JSONObject paramCondition = setParamJson.getJSONObject(dto.getSetCode());
paramCondition.forEach(map::put);
}
dto.setContextData(map);
}
}
} }

@ -454,6 +454,11 @@ export default {
// console.log(luckysheet.toJson()) // console.log(luckysheet.toJson())
// console.log(luckysheet.getAllSheets()) // console.log(luckysheet.getAllSheets())
// console.log(luckysheet.getSheetData(0)) // console.log(luckysheet.getSheetData(0))
const jsonData = luckysheet.getAllSheets()
for (let i = 0; i < jsonData.length; i++) {
//datacelldata
jsonData[i]['data'] = []
}
this.reportExcelDto.jsonStr = JSON.stringify(luckysheet.getAllSheets()) this.reportExcelDto.jsonStr = JSON.stringify(luckysheet.getAllSheets())
var setCodeList = [] var setCodeList = []

@ -87,8 +87,8 @@ export default {
async searchPreview () { async searchPreview () {
const arr = this.toObject(this.tableData2) const arr = this.toObject(this.tableData2)
this.params.setParam = JSON.stringify(arr) this.params.setParam = JSON.stringify(arr)
const { code, data } = await preview(this.params) //
if (code !== '200') return this.preview()
}, },
async preview () { async preview () {
this.excelData = {} this.excelData = {}
@ -111,8 +111,8 @@ export default {
this.excelData = data.jsonStr this.excelData = data.jsonStr
this.sheetData = (data == null ? [{}] : JSON.parse(data.jsonStr)) this.sheetData = (data == null ? [{}] : JSON.parse(data.jsonStr))
console.log(this.excelData) // console.log(this.excelData)
console.log(this.sheetData) // console.log(this.sheetData)
this.createSheet(); this.createSheet();
}, },
download (val) { download (val) {
@ -191,7 +191,7 @@ export default {
] ]
}; };
options.data = this.sheetData; options.data = this.sheetData;
console.log(this.sheetData)
$(function () { $(function () {
luckysheet.create(options); luckysheet.create(options);
}); });

Loading…
Cancel
Save