Browse Source

修改导出模板

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

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

Loading…
Cancel
Save