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

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

Binary file not shown.
Loading…
Cancel
Save