Browse Source

修改导出模板

master
liuchen864 6 months ago
parent
commit
aca5214e55
  1. 138
      win-admin/src/main/java/com/win/web/controller/base/ExcelController.java

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

@ -35,7 +35,6 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
@ -96,9 +95,17 @@ public class ExcelController {
UUID traceid = UUID.randomUUID(); UUID traceid = UUID.randomUUID();
AjaxResult ajaxResult = linuxAccessService.executeCommand(linuxAccess, qadAccess, traceid.toString(), json, domain); AjaxResult ajaxResult = linuxAccessService.executeCommand(linuxAccess, qadAccess, traceid.toString(), json, domain);
jsonObject = JSONObject.parseObject(ajaxResult.get("msg").toString()); jsonObject = JSONObject.parseObject(ajaxResult.get("msg").toString());
jsonObject = JSONObject.parseObject(jsonObject.getString("dssupplierrs")); // BufferedReader reader = new BufferedReader(new FileReader("E:\\download\\response.json"));
JSONArray headerJsonArray = JSONArray.parse(jsonObject.getString("ttsupplierrsheader")); // StringBuilder str = new StringBuilder();
JSONArray lineJsonArray = JSONArray.parse(jsonObject.getString("ttsupplierrsline")); // String line;
// while ((line = reader.readLine()) != null) {
// str.append(line);
// }
// reader.close();
// jsonObject = JSONObject.parseObject(str.toString());
jsonObject = jsonObject.getJSONObject("dssupplierrs");
JSONArray headerJsonArray = jsonObject.getJSONArray("ttsupplierrsheader");
JSONArray lineJsonArray = jsonObject.getJSONArray("ttsupplierrsline");
List<String> fileNames = new ArrayList<>(); List<String> fileNames = new ArrayList<>();
if(headerJsonArray == null) { if(headerJsonArray == null) {
return AjaxResult.error(HttpStatus.TTSUPPLIERRSHEADER_FAIL, "数据不存在ttsupplierrsheader"); return AjaxResult.error(HttpStatus.TTSUPPLIERRSHEADER_FAIL, "数据不存在ttsupplierrsheader");
@ -121,11 +128,15 @@ public class ExcelController {
String schdLineFcQual = jsonObjectLine.getString("schd_line_fc_qual"); String schdLineFcQual = jsonObjectLine.getString("schd_line_fc_qual");
if(schmHeaderOrder.equals(schdLineOrder)) { if(schmHeaderOrder.equals(schdLineOrder)) {
JSONObject order; JSONObject order;
if(!"guowai2".equals(type)) {
order = firmOrderMap.get(schdLineLine);
} else {
if ("F".equals(schdLineFcQual)) { if ("F".equals(schdLineFcQual)) {
order = firmOrderMap.get(schdLineLine); order = firmOrderMap.get(schdLineLine);
} else { } else {
order = forecastOrderMap.get(schdLineLine); order = forecastOrderMap.get(schdLineLine);
} }
}
if (order == null) { if (order == null) {
order = new JSONObject(); order = new JSONObject();
order.put("schd_line_line", schdLineLine); order.put("schd_line_line", schdLineLine);
@ -136,11 +147,15 @@ public class ExcelController {
order.put("schd_line_cum_qty", jsonObjectLine.getIntValue("schd_line_cum_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")); order.put("schd_line_pcr_qty", jsonObjectLine.getIntValue("schd_line_pcr_qty"));
} }
if(!"guowai2".equals(type)) {
firmOrderMap.put(schdLineLine, order);
} else {
if ("F".equals(schdLineFcQual)) { if ("F".equals(schdLineFcQual)) {
firmOrderMap.put(schdLineLine, order); firmOrderMap.put(schdLineLine, order);
} else { } else {
forecastOrderMap.put(schdLineLine, order); forecastOrderMap.put(schdLineLine, order);
} }
}
String schdLineDate = jsonObjectLine.getString("schd_line_date"); String schdLineDate = jsonObjectLine.getString("schd_line_date");
String schdLineDateDl = jsonObjectLine.getString("schd_line_date_dl"); String schdLineDateDl = jsonObjectLine.getString("schd_line_date_dl");
String schdLineDateTh = jsonObjectLine.getString("schd_line_date_th"); String schdLineDateTh = jsonObjectLine.getString("schd_line_date_th");
@ -181,16 +196,15 @@ public class ExcelController {
} }
for(String firmKey : firmMap.keySet()) { for(String firmKey : firmMap.keySet()) {
JSONObject firm = firmMap.get(firmKey); JSONObject firm = firmMap.get(firmKey);
JSONObject forecast = forecastMap.get(firmKey);
boolean isAllZero = false; boolean isAllZero = false;
for(int count = 0; count < firmOrderArray.size(); count++) { for(int count = 0; count < firmOrderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = firmOrderArray.getJSONObject(count); JSONObject object = firmOrderArray.getJSONObject(count);
JSONObject order = firm.getJSONObject(object.getString("schd_line_line")); JSONObject order = firm.getJSONObject(object.getString("schd_line_line"));
if(order != null) { if(order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
} }
if(!cellValue.isEmpty() && !cellValue.equals("0")) { if(cellValue != 0) {
isAllZero = true; isAllZero = true;
} }
} }
@ -201,17 +215,31 @@ public class ExcelController {
for(String forecastKey : forecastMap.keySet()) { for(String forecastKey : forecastMap.keySet()) {
JSONObject forecast = forecastMap.get(forecastKey); JSONObject forecast = forecastMap.get(forecastKey);
boolean isAllZero = false; boolean isAllZero = false;
if(!"guowai2".equals(type)) {
for(int count = 0; count < firmOrderArray.size(); count++) {
int cellValue = 0;
JSONObject object = firmOrderArray.getJSONObject(count);
JSONObject order = forecast.getJSONObject(object.getString("schd_line_line"));
if(order != null) {
cellValue = order.getIntValue("schd_line_qty");
}
if(cellValue != 0) {
isAllZero = true;
}
}
} else {
for (int count = 0; count < forecastOrderArray.size(); count++) { for (int count = 0; count < forecastOrderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = forecastOrderArray.getJSONObject(count); JSONObject object = forecastOrderArray.getJSONObject(count);
JSONObject order = forecast.getJSONObject(object.getString("schd_line_line")); JSONObject order = forecast.getJSONObject(object.getString("schd_line_line"));
if (order != null) { if (order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
} }
if(!cellValue.isEmpty() && !cellValue.equals("0")) { if(cellValue != 0) {
isAllZero = true; isAllZero = true;
} }
} }
}
if(isAllZero) { if(isAllZero) {
forecastArray.add(forecastMap.get(forecastKey)); forecastArray.add(forecastMap.get(forecastKey));
} }
@ -297,7 +325,7 @@ public class ExcelController {
firmDateCell.setCellStyle(cellStyle4); firmDateCell.setCellStyle(cellStyle4);
//设置每个firm订单数据 //设置每个firm订单数据
for(int count = 0; count < orderArray.size(); count++) { for(int count = 0; count < orderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = orderArray.getJSONObject(count); JSONObject object = orderArray.getJSONObject(count);
JSONObject order = firm.getJSONObject(object.getString("schd_line_line")); JSONObject order = firm.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheet.getRow(16 + count); Row nextRow = sheet.getRow(16 + count);
@ -306,13 +334,10 @@ public class ExcelController {
nextCell = nextRow.createCell(cellIndex); nextCell = nextRow.createCell(cellIndex);
} }
if(order != null) { if(order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
}
if(cellValue.equals("0")) {
cellValue = "";
} }
if(!cellValue.isEmpty()) { if(cellValue != 0) {
nextCell.setCellValue(new BigDecimal(cellValue).intValue()); nextCell.setCellValue(cellValue);
} else { } else {
nextCell.setCellValue(""); nextCell.setCellValue("");
} }
@ -361,22 +386,19 @@ public class ExcelController {
forecastDateCell.setCellStyle(cellStyle5); forecastDateCell.setCellStyle(cellStyle5);
//设置forecast每个订单数据 //设置forecast每个订单数据
for(int count = 0; count < orderArray.size(); count++) { for(int count = 0; count < orderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = orderArray.getJSONObject(count); JSONObject object = orderArray.getJSONObject(count);
JSONObject order = forecast.getJSONObject(object.getString("schd_line_line")); JSONObject order = forecast.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheet.getRow(16 + count); Row nextRow = sheet.getRow(16 + count);
if(order != null) { if(order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
}
if(cellValue.equals("0")) {
cellValue = "";
} }
Cell nextCell = nextRow.getCell(cellIndex); Cell nextCell = nextRow.getCell(cellIndex);
if (nextCell == null) { if (nextCell == null) {
nextCell = nextRow.createCell(cellIndex); nextCell = nextRow.createCell(cellIndex);
} }
if(!cellValue.isEmpty()) { if(cellValue != 0) {
nextCell.setCellValue(new BigDecimal(cellValue).intValue()); nextCell.setCellValue(cellValue);
} else { } else {
nextCell.setCellValue(""); nextCell.setCellValue("");
} }
@ -463,7 +485,7 @@ public class ExcelController {
firmDateCell.setCellStyle(cellStyle4); firmDateCell.setCellStyle(cellStyle4);
//设置每个firm订单数据 //设置每个firm订单数据
for (int count = 0; count < orderArray.size(); count++) { for (int count = 0; count < orderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = orderArray.getJSONObject(count); JSONObject object = orderArray.getJSONObject(count);
JSONObject order = firm.getJSONObject(object.getString("schd_line_line")); JSONObject order = firm.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheet.getRow(16 + count); Row nextRow = sheet.getRow(16 + count);
@ -472,13 +494,10 @@ public class ExcelController {
nextCell = nextRow.createCell(cellIndex); nextCell = nextRow.createCell(cellIndex);
} }
if (order != null) { if (order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
} }
if (cellValue.equals("0")) { if (cellValue != 0) {
cellValue = ""; nextCell.setCellValue(cellValue);
}
if (!cellValue.isEmpty()) {
nextCell.setCellValue(new BigDecimal(cellValue).intValue());
} else { } else {
nextCell.setCellValue(""); nextCell.setCellValue("");
} }
@ -537,22 +556,19 @@ public class ExcelController {
forecastDateCell.setCellStyle(cellStyle5); forecastDateCell.setCellStyle(cellStyle5);
//设置forecast每个订单数据 //设置forecast每个订单数据
for (int count = 0; count < orderArray.size(); count++) { for (int count = 0; count < orderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = orderArray.getJSONObject(count); JSONObject object = orderArray.getJSONObject(count);
JSONObject order = forecast.getJSONObject(object.getString("schd_line_line")); JSONObject order = forecast.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheet.getRow(16 + count); Row nextRow = sheet.getRow(16 + count);
if (order != null) { if (order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
}
if (cellValue.equals("0")) {
cellValue = "";
} }
Cell nextCell = nextRow.getCell(cellIndex); Cell nextCell = nextRow.getCell(cellIndex);
if (nextCell == null) { if (nextCell == null) {
nextCell = nextRow.createCell(cellIndex); nextCell = nextRow.createCell(cellIndex);
} }
if (!cellValue.isEmpty()) { if (cellValue != 0) {
nextCell.setCellValue(new BigDecimal(cellValue).intValue()); nextCell.setCellValue(cellValue);
} else { } else {
nextCell.setCellValue(""); nextCell.setCellValue("");
} }
@ -644,7 +660,7 @@ public class ExcelController {
firmCell.setCellStyle(cellStyle3); firmCell.setCellStyle(cellStyle3);
//设置每个firm订单数据 //设置每个firm订单数据
for(int count = 0; count < orderArray.size(); count++) { for(int count = 0; count < orderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = orderArray.getJSONObject(count); JSONObject object = orderArray.getJSONObject(count);
JSONObject order = firm.getJSONObject(object.getString("schd_line_line")); JSONObject order = firm.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheet.getRow(17 + count); Row nextRow = sheet.getRow(17 + count);
@ -653,13 +669,10 @@ public class ExcelController {
nextCell = nextRow.createCell(cellIndex); nextCell = nextRow.createCell(cellIndex);
} }
if(order != null) { if(order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
}
if(cellValue.equals("0")) {
cellValue = "";
} }
if(!cellValue.isEmpty()) { if (cellValue != 0) {
nextCell.setCellValue(new BigDecimal(cellValue).intValue()); nextCell.setCellValue(cellValue);
} else { } else {
nextCell.setCellValue(""); nextCell.setCellValue("");
} }
@ -707,22 +720,19 @@ public class ExcelController {
forecstCell.setCellStyle(cellStyle3); forecstCell.setCellStyle(cellStyle3);
//设置forecast每个订单数据 //设置forecast每个订单数据
for(int count = 0; count < orderArray.size(); count++) { for(int count = 0; count < orderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = orderArray.getJSONObject(count); JSONObject object = orderArray.getJSONObject(count);
JSONObject order = forecast.getJSONObject(object.getString("schd_line_line")); JSONObject order = forecast.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheet.getRow(17 + count); Row nextRow = sheet.getRow(17 + count);
if(order != null) { if(order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
}
if(cellValue.equals("0")) {
cellValue = "";
} }
Cell nextCell = nextRow.getCell(cellIndex); Cell nextCell = nextRow.getCell(cellIndex);
if (nextCell == null) { if (nextCell == null) {
nextCell = nextRow.createCell(cellIndex); nextCell = nextRow.createCell(cellIndex);
} }
if(!cellValue.isEmpty()) { if (cellValue != 0) {
nextCell.setCellValue(new BigDecimal(cellValue).intValue()); nextCell.setCellValue(cellValue);
} else { } else {
nextCell.setCellValue(""); nextCell.setCellValue("");
} }
@ -823,7 +833,7 @@ public class ExcelController {
firmCell.setCellStyle(cellStyle2); firmCell.setCellStyle(cellStyle2);
//设置每个firm订单数据 //设置每个firm订单数据
for(int count = 0; count < firmOrderArray.size(); count++) { for(int count = 0; count < firmOrderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = firmOrderArray.getJSONObject(count); JSONObject object = firmOrderArray.getJSONObject(count);
JSONObject order = firm.getJSONObject(object.getString("schd_line_line")); JSONObject order = firm.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheet.getRow(19 + count); Row nextRow = sheet.getRow(19 + count);
@ -832,13 +842,10 @@ public class ExcelController {
nextCell = nextRow.createCell(cellIndex); nextCell = nextRow.createCell(cellIndex);
} }
if(order != null) { if(order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
}
if(cellValue.equals("0")) {
cellValue = "";
} }
if(!cellValue.isEmpty()) { if (cellValue != 0) {
nextCell.setCellValue(new BigDecimal(cellValue).intValue()); nextCell.setCellValue(cellValue);
} else { } else {
nextCell.setCellValue(""); nextCell.setCellValue("");
} }
@ -887,22 +894,19 @@ public class ExcelController {
forecastCell.setCellStyle(cellStyleForecast2); forecastCell.setCellStyle(cellStyleForecast2);
//设置forecast每个订单数据 //设置forecast每个订单数据
for(int count = 0; count < forecastOrderArray.size(); count++) { for(int count = 0; count < forecastOrderArray.size(); count++) {
String cellValue = ""; int cellValue = 0;
JSONObject object = forecastOrderArray.getJSONObject(count); JSONObject object = forecastOrderArray.getJSONObject(count);
JSONObject order = forecast.getJSONObject(object.getString("schd_line_line")); JSONObject order = forecast.getJSONObject(object.getString("schd_line_line"));
Row nextRow = sheetForecast.getRow(18 + count); Row nextRow = sheetForecast.getRow(18 + count);
if(order != null) { if(order != null) {
cellValue = order.getString("schd_line_qty"); cellValue = order.getIntValue("schd_line_qty");
}
if(cellValue.equals("0")) {
cellValue = "";
} }
Cell nextCell = nextRow.getCell(cellIndex); Cell nextCell = nextRow.getCell(cellIndex);
if (nextCell == null) { if (nextCell == null) {
nextCell = nextRow.createCell(cellIndex); nextCell = nextRow.createCell(cellIndex);
} }
if(!cellValue.isEmpty()) { if (cellValue != 0) {
nextCell.setCellValue(new BigDecimal(cellValue).intValue()); nextCell.setCellValue(cellValue);
} else { } else {
nextCell.setCellValue(""); nextCell.setCellValue("");
} }

Loading…
Cancel
Save