Browse Source

修改导出模板

master
liuchen864 6 months ago
parent
commit
9bf79e1dd9
  1. 98
      win-admin/src/main/java/com/win/web/controller/base/ExcelController.java
  2. BIN
      win-admin/src/main/resources/guowai2.xls

98
win-admin/src/main/java/com/win/web/controller/base/ExcelController.java

@ -82,7 +82,7 @@ public class ExcelController {
qadAccessQueryWrapper.eq("domain",domain);
QadAccess qadAccess = qadAccessService.getOne(qadAccessQueryWrapper);
if(qadAccess == null) {
return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR,"QAD_ACCESS_ERROR");
return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR,"QAD访问控制不存在");
}
JSONArray jsonArray = new JSONArray();
JSONObject ttSearchCondition = new JSONObject();
@ -106,35 +106,46 @@ public class ExcelController {
for(int i = 0; i < headerJsonArray.size(); i++) {
JSONObject jsonObjectHeader = headerJsonArray.getJSONObject(i);
String schmHeaderOrder = jsonObjectHeader.getString("schm_header_order");
TreeMap<Integer, JSONObject> mainMap = new TreeMap<>();
TreeMap<Integer, JSONObject> firmOrderMap = new TreeMap<>();
TreeMap<Integer, JSONObject> forecastOrderMap = new TreeMap<>();
TreeMap<String, JSONObject> firmMap = new TreeMap<>();
TreeMap<String, JSONObject> forecastMap = new TreeMap<>();
JSONArray orderArray = new JSONArray();
JSONArray firmOrderArray = new JSONArray();
JSONArray forecastOrderArray = new JSONArray();
JSONArray firmArray = new JSONArray();
JSONArray forecastArray = new JSONArray();
for(int j = 0; j < lineJsonArray.size(); j++) {
JSONObject jsonObjectLine = lineJsonArray.getJSONObject(j);
String schdLineOrder = jsonObjectLine.getString("schd_line_order");
int schdLineLine = jsonObjectLine.getIntValue("schd_line_line");
String schdLineFcQual = jsonObjectLine.getString("schd_line_fc_qual");
if(schmHeaderOrder.equals(schdLineOrder)) {
JSONObject main = mainMap.get(schdLineLine);
if(main == null) {
main = new JSONObject();
main.put("schd_line_line", schdLineLine);
main.put("schd_line_part", jsonObjectLine.getString("schd_line_part"));
main.put("schd_line_um", jsonObjectLine.getString("schd_line_um"));
main.put("schd_line_part_desc", jsonObjectLine.getString("schd_line_part_desc"));
main.put("schd_line_req_qty", jsonObjectLine.getIntValue("schd_line_req_qty"));
main.put("schd_line_cum_qty", jsonObjectLine.getIntValue("schd_line_cum_qty"));
main.put("schd_line_pcr_qty", jsonObjectLine.getIntValue("schd_line_pcr_qty"));
JSONObject order;
if ("F".equals(schdLineFcQual)) {
order = firmOrderMap.get(schdLineLine);
} else {
order = forecastOrderMap.get(schdLineLine);
}
if (order == null) {
order = new JSONObject();
order.put("schd_line_line", schdLineLine);
order.put("schd_line_part", jsonObjectLine.getString("schd_line_part"));
order.put("schd_line_um", jsonObjectLine.getString("schd_line_um"));
order.put("schd_line_part_desc", jsonObjectLine.getString("schd_line_part_desc"));
order.put("schd_line_req_qty", jsonObjectLine.getIntValue("schd_line_req_qty"));
order.put("schd_line_cum_qty", jsonObjectLine.getIntValue("schd_line_cum_qty"));
order.put("schd_line_pcr_qty", jsonObjectLine.getIntValue("schd_line_pcr_qty"));
}
if ("F".equals(schdLineFcQual)) {
firmOrderMap.put(schdLineLine, order);
} else {
forecastOrderMap.put(schdLineLine, order);
}
mainMap.put(schdLineLine, main);
String schdLineDate = jsonObjectLine.getString("schd_line_date");
String schdLineDateDl = jsonObjectLine.getString("schd_line_date_dl");
String schdLineDateTh = jsonObjectLine.getString("schd_line_date_th");
if(schdLineDate != null) {
String schdLineFcQual = jsonObjectLine.getString("schd_line_fc_qual");
if("F".equals(schdLineFcQual)) {
if (schdLineDate != null) {
if ("F".equals(schdLineFcQual)) {
JSONObject firm = firmMap.get(schdLineDate);
if (firm == null) {
firm = new JSONObject();
@ -142,9 +153,9 @@ public class ExcelController {
firm.put("schd_line_date_dl", schdLineDateDl);
firm.put("schd_line_date_th", schdLineDateTh);
}
JSONObject order = new JSONObject();
order.put("schd_line_qty", jsonObjectLine.getString("schd_line_qty"));
firm.put(String.valueOf(schdLineLine), order);
JSONObject orderJsonObject = new JSONObject();
orderJsonObject.put("schd_line_qty", jsonObjectLine.getString("schd_line_qty"));
firm.put(String.valueOf(schdLineLine), orderJsonObject);
firmMap.put(schdLineDate, firm);
} else {
JSONObject forecast = forecastMap.get(schdLineDate);
@ -154,23 +165,27 @@ public class ExcelController {
forecast.put("schd_line_date_dl", schdLineDateDl);
forecast.put("schd_line_date_th", schdLineDateTh);
}
JSONObject order = new JSONObject();
order.put("schd_line_qty", jsonObjectLine.getString("schd_line_qty"));
forecast.put(String.valueOf(schdLineLine), order);
JSONObject orderJsonObject = new JSONObject();
orderJsonObject.put("schd_line_qty", jsonObjectLine.getString("schd_line_qty"));
forecast.put(String.valueOf(schdLineLine), orderJsonObject);
forecastMap.put(schdLineDate, forecast);
}
}
}
}
for(Integer mainKey : mainMap.keySet()) {
orderArray.add(mainMap.get(mainKey));
for(Integer firmOrderKey : firmOrderMap.keySet()) {
firmOrderArray.add(firmOrderMap.get(firmOrderKey));
}
for(Integer forecastOrderKey : forecastOrderMap.keySet()) {
forecastOrderArray.add(forecastOrderMap.get(forecastOrderKey));
}
for(String firmKey : firmMap.keySet()) {
JSONObject firm = firmMap.get(firmKey);
JSONObject forecast = forecastMap.get(firmKey);
boolean isAllZero = false;
for(int count = 0; count < orderArray.size(); count++) {
for(int count = 0; count < firmOrderArray.size(); count++) {
String cellValue = "";
JSONObject object = orderArray.getJSONObject(count);
JSONObject object = firmOrderArray.getJSONObject(count);
JSONObject order = firm.getJSONObject(object.getString("schd_line_line"));
if(order != null) {
cellValue = order.getString("schd_line_qty");
@ -186,9 +201,9 @@ public class ExcelController {
for(String forecastKey : forecastMap.keySet()) {
JSONObject forecast = forecastMap.get(forecastKey);
boolean isAllZero = false;
for(int count = 0; count < orderArray.size(); count++) {
for(int count = 0; count < forecastOrderArray.size(); count++) {
String cellValue = "";
JSONObject object = orderArray.getJSONObject(count);
JSONObject object = forecastOrderArray.getJSONObject(count);
JSONObject order = forecast.getJSONObject(object.getString("schd_line_line"));
if(order != null) {
cellValue = order.getString("schd_line_qty");
@ -202,13 +217,13 @@ public class ExcelController {
}
}
if("changchun".equals(type)) {//长春模板
fileNames.add(fillChangchun(orderNo, jsonObjectHeader, orderArray, firmArray, forecastArray));
fileNames.add(fillChangchun(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray));
} else if("foshan".equals(type)) {
fileNames.add(fillFoshanQingdao(orderNo, jsonObjectHeader, orderArray, firmArray, forecastArray));
fileNames.add(fillFoshanQingdao(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray));
} else if("guowai1".equals(type)) {
fileNames.add(fillGuowai1(orderNo, jsonObjectHeader, orderArray, firmArray, forecastArray));
fileNames.add(fillGuowai1(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray));
} else if("guowai2".equals(type)) {
fileNames.add(fillGuowai2(orderNo, jsonObjectHeader, orderArray, firmArray, forecastArray));
fileNames.add(fillGuowai2(orderNo, jsonObjectHeader, firmOrderArray, forecastOrderArray, firmArray, forecastArray));
}
}
return AjaxResult.success(fileNames);
@ -726,13 +741,14 @@ public class ExcelController {
* 横财国外格式excel
* @param orderNo 订单号
* @param jsonObjectHeader 头部信息
* @param orderArray 订单数据
* @param firmOrderArray firm订单数据
* @param forecastOrderArray forecast订单数据
* @param firmArray firm数据
* @param forecastArray forecast数据
* @return 生成文件的路径
* @throws IOException io异常
*/
private String fillGuowai2(String orderNo, JSONObject jsonObjectHeader, JSONArray orderArray, JSONArray firmArray, JSONArray forecastArray) throws IOException {
private String fillGuowai2(String orderNo, JSONObject jsonObjectHeader, JSONArray firmOrderArray, JSONArray forecastOrderArray, JSONArray firmArray, JSONArray forecastArray) throws IOException {
ClassPathResource templateFile = new ClassPathResource("guowai2.xls");
String filePath = WinConfig.getUploadPath();
orderNo = orderNo.toUpperCase();
@ -756,9 +772,9 @@ public class ExcelController {
//基础数据
excelWriter.fill(jsonObjectHeader, writeSheet2);
//firmOrder数据
excelWriter.fill(new FillWrapper("order", orderArray), fillConfig, writeSheet1);
excelWriter.fill(new FillWrapper("order", firmOrderArray), fillConfig, writeSheet1);
//forecast
excelWriter.fill(new FillWrapper("order", orderArray), fillConfig, writeSheet2);
excelWriter.fill(new FillWrapper("order", forecastOrderArray), fillConfig, writeSheet2);
} finally {
if (excelWriter != null) {
excelWriter.finish();
@ -806,9 +822,9 @@ public class ExcelController {
firmCell.setCellValue(orderNo);
firmCell.setCellStyle(cellStyle2);
//设置每个firm订单数据
for(int count = 0; count < orderArray.size(); count++) {
for(int count = 0; count < firmOrderArray.size(); count++) {
String cellValue = "";
JSONObject object = orderArray.getJSONObject(count);
JSONObject object = firmOrderArray.getJSONObject(count);
JSONObject order = firm.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheet.getRow(19 + count);
Cell nextCell = nextRow.getCell(cellIndex);
@ -870,9 +886,9 @@ public class ExcelController {
forecastCell.setCellValue("forecast");
forecastCell.setCellStyle(cellStyleForecast2);
//设置forecast每个订单数据
for(int count = 0; count < orderArray.size(); count++) {
for(int count = 0; count < forecastOrderArray.size(); count++) {
String cellValue = "";
JSONObject object = orderArray.getJSONObject(count);
JSONObject object = forecastOrderArray.getJSONObject(count);
JSONObject order = forecast.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheetForecast.getRow(18 + count);
if(order != null) {

BIN
win-admin/src/main/resources/guowai2.xls

Binary file not shown.
Loading…
Cancel
Save