Commit 7a9e9f07 by 王炜晨

新查询组件导出

parent 6e1319ab
...@@ -3,6 +3,9 @@ package com.xyst.dinas.biz.config; ...@@ -3,6 +3,9 @@ package com.xyst.dinas.biz.config;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.xyst.dinas.biz.init.OrganizationDataInitializer; import com.xyst.dinas.biz.init.OrganizationDataInitializer;
import com.xyst.dinas.biz.internal.service.AdvancedQueryExportServiceImpl;
import com.xyst.dinas.biz.service.AdvancedQueryExportService;
import com.xyst.dinas.biz.web.AdvancedQueryExportController;
import com.xyst.dinas.biz.web.SandAdvancedQueryController; import com.xyst.dinas.biz.web.SandAdvancedQueryController;
import com.xyst.dinas.biz.web.SandSceneController; import com.xyst.dinas.biz.web.SandSceneController;
import com.xyst.dinas.biz.web.WarehouseAdvancedQueryController; import com.xyst.dinas.biz.web.WarehouseAdvancedQueryController;
...@@ -22,6 +25,16 @@ public class BizDataInitializerConfig { ...@@ -22,6 +25,16 @@ public class BizDataInitializerConfig {
return new OrganizationDataInitializer(); return new OrganizationDataInitializer();
} }
@Bean
public AdvancedQueryExportService advancedQueryExportServiceImpl(){
return new AdvancedQueryExportServiceImpl();
}
@Bean
public AdvancedQueryExportController advancedQueryExportController(){
return new AdvancedQueryExportController();
}
@Bean("com.xyst.dinas.biz.web.SandAdvancedQueryController") @Bean("com.xyst.dinas.biz.web.SandAdvancedQueryController")
public SandAdvancedQueryController sandAdvancedQueryController(){ public SandAdvancedQueryController sandAdvancedQueryController(){
return new SandAdvancedQueryController(); return new SandAdvancedQueryController();
......
package com.xyst.dinas.biz.internal.service;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import com.beecode.amino.core.Amino;
import com.beecode.bap.export.excel.GridCell;
import com.beecode.bap.export.excel.GridRow;
import com.beecode.bap.export.excel.Sheet;
import com.beecode.bap.export.excel.service.ExportExcelService;
import com.beecode.bcp.advanced.query.QueryPreprocessor;
import com.beecode.bcp.advanced.query.QueryPreprocessorFactory;
import com.beecode.bcp.advanced.query.bean.QueryParameter;
import com.beecode.bcp.advanced.query.bean.QueryTemplate;
import com.beecode.bcp.advanced.query.bean.QueryView;
import com.beecode.bcp.advanced.query.bean.RowData;
import com.beecode.bcp.advanced.query.service.QueryMetaService;
import com.beecode.bcp.advanced.query.service.QueryService;
import com.fasterxml.jackson.databind.JsonNode;
import com.xyst.dinas.biz.service.AdvancedQueryExportService;
import net.sf.json.JSONObject;
public class AdvancedQueryExportServiceImpl implements AdvancedQueryExportService {
@Autowired
private QueryMetaService metaService;
@Autowired
private QueryService service;
@Autowired
ExportExcelService exportExcelService;
private void createExcel(List<RowData> list, JSONArray columnList, List<Sheet> datas, String fileName) {
List<GridRow> gridRows = new ArrayList<>();
List<GridCell> head = new ArrayList<>();
for (Object columnStr : columnList) {
JSONObject column = JSONObject.fromObject(columnStr.toString());
head.add(new GridCell(column.getString("title")));
}
gridRows.add(0, new GridRow(head));
for (RowData data : list) {
List<GridCell> gridCells = new ArrayList<>();
JsonNode dataJson = data.toJson();
for (Object columnStr : columnList) {
JSONObject column = JSONObject.fromObject(columnStr.toString());
Object str = "";
if (null != dataJson.get(column.getString("key")).asText()
&& !dataJson.get(column.getString("key")).asText().equals("null")) {
str = dataJson.get(column.getString("key")).asText();
}
gridCells.add(new GridCell(str));
}
gridRows.add(new GridRow(gridCells));
}
datas.add(new Sheet(fileName, gridRows));
}
@Override
public void export(QueryParameter queryParameter, JSONArray columnList, String fileName, OutputStream os) {
// TODO Auto-generated method stub
QueryTemplate template = metaService.getQueryTemplate(queryParameter.getDatasource());
QueryPreprocessor preprocessor = QueryPreprocessorFactory.newInstance(queryParameter, template);
List<RowData> rows = service.queryList(preprocessor);
List<Sheet> datas = new ArrayList<>();
createExcel(rows, columnList, datas, fileName);
try {
exportExcelService.exportMoveSheet(os, datas);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package com.xyst.dinas.biz.service;
import java.io.OutputStream;
import org.json.JSONArray;
import com.beecode.bcp.advanced.query.bean.QueryParameter;
public interface AdvancedQueryExportService {
void export(QueryParameter queryParameter, JSONArray columnNameList, String fileName, OutputStream os);
}
package com.xyst.dinas.biz.web;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import com.beecode.bcp.advanced.query.bean.QueryParameter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xyst.dinas.biz.service.AdvancedQueryExportService;
@RestController
public class AdvancedQueryExportController {
@Autowired
private AdvancedQueryExportService advancedQueryExportService;
@PostMapping("/sand/user/query/advance/export")
public void sandUserExport(HttpServletResponse response, HttpServletRequest request) throws IOException {
request.setCharacterEncoding("utf-8");
String exportParamStr = request.getParameter("exportParamStr");
JSONObject list = new JSONObject(exportParamStr);
JSONObject queryParam = list.getJSONObject("queryParam");
QueryParameter queryParameter = new QueryParameter();
String fileName = URLEncoder.encode(list.getString("title"));
try {
ObjectMapper objectMapper = new ObjectMapper();
queryParameter = objectMapper.readValue(queryParam.toString(), QueryParameter.class);
} catch (Exception e) {
e.printStackTrace();
}
OutputStream os = null;
try {
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls");
os = response.getOutputStream();
advancedQueryExportService.export(queryParameter, list.getJSONArray("columnsList"), list.getString("title"), os);
} catch (IOException e) {
throw e;
} finally {
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
throw e;
}
}
}
}
@PostMapping("/query/advance/export")
public void export(HttpServletResponse response, HttpServletRequest request) throws IOException {
request.setCharacterEncoding("utf-8");
String exportParamStr = request.getParameter("exportParamStr");
JSONObject list = new JSONObject(exportParamStr);
JSONObject queryParam = list.getJSONObject("queryParam");
QueryParameter queryParameter = new QueryParameter();
String fileName = URLEncoder.encode(list.getString("title"));
try {
ObjectMapper objectMapper = new ObjectMapper();
queryParameter = objectMapper.readValue(queryParam.toString(), QueryParameter.class);
} catch (Exception e) {
e.printStackTrace();
}
OutputStream os = null;
try {
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls");
os = response.getOutputStream();
advancedQueryExportService.export(queryParameter, list.getJSONArray("columnsList"), list.getString("title"), os);
} catch (IOException e) {
throw e;
} finally {
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
throw e;
}
}
}
}
@PostMapping("/warehouse/api/query/advance/export")
public void warehouseExport(HttpServletResponse response, HttpServletRequest request) throws IOException {
request.setCharacterEncoding("utf-8");
String exportParamStr = request.getParameter("exportParamStr");
JSONObject list = new JSONObject(exportParamStr);
JSONObject queryParam = list.getJSONObject("queryParam");
QueryParameter queryParameter = new QueryParameter();
String fileName = URLEncoder.encode(list.getString("title"));
try {
ObjectMapper objectMapper = new ObjectMapper();
queryParameter = objectMapper.readValue(queryParam.toString(), QueryParameter.class);
} catch (Exception e) {
e.printStackTrace();
}
OutputStream os = null;
try {
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls");
os = response.getOutputStream();
advancedQueryExportService.export(queryParameter, list.getJSONArray("columnsList"), list.getString("title"), os);
} catch (IOException e) {
throw e;
} finally {
if (os != null) {
try {
os.flush();
os.close();
} catch (IOException e) {
throw e;
}
}
}
}
}
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
LEFT JOIN PlanningCycle AS planningCycle ON planningCycle.id = salesPlan.planningCycle LEFT JOIN PlanningCycle AS planningCycle ON planningCycle.id = salesPlan.planningCycle
LEFT JOIN NeedPlan AS needPlan ON needPlan.planningCycle = salesPlan.planningCycle LEFT JOIN NeedPlan AS needPlan ON needPlan.planningCycle = salesPlan.planningCycle
LEFT JOIN ProjectFiled AS projectFiled ON projectFiled.id = needPlan.project LEFT JOIN ProjectFiled AS projectFiled ON projectFiled.id = needPlan.project
WHERE ( salesPlan.DISCARD = FALSE OR salesPlan.DISCARD IS NULL ) UNION WHERE ( salesPlan.DISCARD = FALSE OR salesPlan.DISCARD IS NULL ) UNION ALL
SELECT SELECT
salesPlanTemp.id AS id, salesPlanTemp.id AS id,
xystorganizationrTemp.NAME AS organization, xystorganizationrTemp.NAME AS organization,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment