|
@ -159,6 +159,15 @@ public class ExcelController { |
|
|
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) { |
|
|
|
|
|
schdLineDate = schdLineDate.replace("-", "/"); |
|
|
|
|
|
} |
|
|
|
|
|
if(schdLineDateDl != null) { |
|
|
|
|
|
schdLineDateDl = schdLineDateDl.replace("-", "/"); |
|
|
|
|
|
} |
|
|
|
|
|
if(schdLineDateTh != null) { |
|
|
|
|
|
schdLineDateTh = schdLineDateTh.replace("-", "/"); |
|
|
|
|
|
} |
|
|
if (schdLineDate != null) { |
|
|
if (schdLineDate != null) { |
|
|
if ("F".equals(schdLineFcQual)) { |
|
|
if ("F".equals(schdLineFcQual)) { |
|
|
JSONObject firm = firmMap.get(schdLineDate); |
|
|
JSONObject firm = firmMap.get(schdLineDate); |
|
@ -247,7 +256,9 @@ public class ExcelController { |
|
|
if("changchun".equals(type)) {//长春模板
|
|
|
if("changchun".equals(type)) {//长春模板
|
|
|
fileNames.add(fillChangchun(orderNo, jsonObjectHeader, firmOrderArray, 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, firmOrderArray, firmArray, forecastArray)); |
|
|
fileNames.add(fillFoshan(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); |
|
|
|
|
|
} else if("qingdao".equals(type)) { |
|
|
|
|
|
fileNames.add(fillQingdao(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); |
|
|
} else if("guowai1".equals(type)) { |
|
|
} else if("guowai1".equals(type)) { |
|
|
fileNames.add(fillGuowai1(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); |
|
|
fileNames.add(fillGuowai1(orderNo, jsonObjectHeader, firmOrderArray, firmArray, forecastArray)); |
|
|
} else if("guowai2".equals(type)) { |
|
|
} else if("guowai2".equals(type)) { |
|
@ -419,7 +430,177 @@ public class ExcelController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 横财佛山青岛格式excel |
|
|
* 横财佛山格式excel |
|
|
|
|
|
* @param orderNo 订单号 |
|
|
|
|
|
* @param jsonObjectHeader 头部信息 |
|
|
|
|
|
* @param orderArray 订单数据 |
|
|
|
|
|
* @param firmArray firm数据 |
|
|
|
|
|
* @param forecastArray forecast数据 |
|
|
|
|
|
* @return 生成文件的路径 |
|
|
|
|
|
* @throws IOException io异常 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String fillFoshan(String orderNo, JSONObject jsonObjectHeader, JSONArray orderArray, JSONArray firmArray, JSONArray forecastArray) throws IOException { |
|
|
|
|
|
ClassPathResource templateFile = new ClassPathResource("foshan.xls"); |
|
|
|
|
|
String filePath = WinConfig.getUploadPath(); |
|
|
|
|
|
String fileName = orderNo + ".xls"; |
|
|
|
|
|
File file = new File(filePath); |
|
|
|
|
|
if (!file.exists()) { |
|
|
|
|
|
file.mkdirs(); |
|
|
|
|
|
} |
|
|
|
|
|
file = new File(filePath + "/" + fileName); |
|
|
|
|
|
if (file.exists()) { |
|
|
|
|
|
file.delete(); |
|
|
|
|
|
} |
|
|
|
|
|
final ExcelWriter excelWriter = EasyExcelFactory.write(filePath + "/" + fileName).excelType(ExcelTypeEnum.XLS).withTemplate(templateFile.getInputStream()).build(); |
|
|
|
|
|
try { |
|
|
|
|
|
final WriteSheet writeSheet = EasyExcelFactory.writerSheet().build(); |
|
|
|
|
|
//默认纵向添加数据
|
|
|
|
|
|
FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build(); |
|
|
|
|
|
//基础数据
|
|
|
|
|
|
excelWriter.fill(jsonObjectHeader, writeSheet); |
|
|
|
|
|
//order数据
|
|
|
|
|
|
excelWriter.fill(new FillWrapper("order", orderArray), fillConfig, writeSheet); |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (excelWriter != null) { |
|
|
|
|
|
excelWriter.finish(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
FileInputStream inputStream = new FileInputStream(filePath + "/" + fileName); |
|
|
|
|
|
Workbook workbook = new HSSFWorkbook(inputStream); |
|
|
|
|
|
Sheet sheet = workbook.getSheetAt(0); // 获取第一个工作表
|
|
|
|
|
|
CellStyle cellStyle1 = getCellStyle(sheet, 14, 8);//Firm订标题样式
|
|
|
|
|
|
CellStyle cellStyle2 = getCellStyle(sheet, 14, 9);//Pick Up Date提货时间
|
|
|
|
|
|
CellStyle cellStyle3 = getCellStyle(sheet, 14, 10);//forecast标题
|
|
|
|
|
|
CellStyle cellStyle4 = getCellStyle(sheet, 15, 8);//Firm日期样式
|
|
|
|
|
|
CellStyle cellStyle5 = getCellStyle(sheet, 15, 10);//Forecast日期样式
|
|
|
|
|
|
CellStyle cellStyle6 = getCellStyle(sheet, 16, 8);//Firm数据样式
|
|
|
|
|
|
CellStyle cellStyle7 = getCellStyle(sheet, 16, 10);//Forecast数据样式
|
|
|
|
|
|
Row row14 = sheet.getRow(14); |
|
|
|
|
|
Row row15 = sheet.getRow(15); |
|
|
|
|
|
for (int i = 0; i < firmArray.size(); i++) { |
|
|
|
|
|
int cellIndex = 8 + i; |
|
|
|
|
|
JSONObject firm = firmArray.getJSONObject(i); |
|
|
|
|
|
//设置firm标题
|
|
|
|
|
|
Cell firmCell = row14.getCell(cellIndex); |
|
|
|
|
|
if (firmCell == null) { |
|
|
|
|
|
firmCell = row14.createCell(cellIndex); |
|
|
|
|
|
} |
|
|
|
|
|
firmCell.setCellValue("Firm订单"); |
|
|
|
|
|
firmCell.setCellStyle(cellStyle1); |
|
|
|
|
|
//设置firm日期
|
|
|
|
|
|
Cell firmDateCell = row15.getCell(cellIndex); |
|
|
|
|
|
if (firmDateCell == null) { |
|
|
|
|
|
firmDateCell = row15.createCell(cellIndex); |
|
|
|
|
|
} |
|
|
|
|
|
firmDateCell.setCellValue(firm.getString("schd_line_date")); |
|
|
|
|
|
firmDateCell.setCellStyle(cellStyle4); |
|
|
|
|
|
//设置每个firm订单数据
|
|
|
|
|
|
for (int count = 0; count < orderArray.size(); count++) { |
|
|
|
|
|
int cellValue = 0; |
|
|
|
|
|
JSONObject object = orderArray.getJSONObject(count); |
|
|
|
|
|
JSONObject order = firm.getJSONObject(object.getString("schd_line_line")); |
|
|
|
|
|
Row nextRow = sheet.getRow(16 + count); |
|
|
|
|
|
Cell nextCell = nextRow.getCell(cellIndex); |
|
|
|
|
|
if (nextCell == null) { |
|
|
|
|
|
nextCell = nextRow.createCell(cellIndex); |
|
|
|
|
|
} |
|
|
|
|
|
if (order != null) { |
|
|
|
|
|
cellValue = order.getIntValue("schd_line_qty"); |
|
|
|
|
|
} |
|
|
|
|
|
if (cellValue != 0) { |
|
|
|
|
|
nextCell.setCellValue(cellValue); |
|
|
|
|
|
} else { |
|
|
|
|
|
nextCell.setCellValue(""); |
|
|
|
|
|
} |
|
|
|
|
|
nextCell.setCellStyle(cellStyle6); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//设置firm前的Pick Up Date 提货日期列
|
|
|
|
|
|
for (int count = 0; count < orderArray.size(); count++) { |
|
|
|
|
|
Row beforeRow = sheet.getRow(16 + count); |
|
|
|
|
|
Cell beforeCell = beforeRow.getCell(7); |
|
|
|
|
|
if (beforeCell == null) { |
|
|
|
|
|
beforeCell = beforeRow.createCell(7); |
|
|
|
|
|
} |
|
|
|
|
|
beforeCell.setCellValue(""); |
|
|
|
|
|
beforeCell.setCellStyle(cellStyle1); |
|
|
|
|
|
} |
|
|
|
|
|
//设置forecast前的Pick Up Date 提货日期列
|
|
|
|
|
|
for (int count = 0; count < orderArray.size() + 2; count++) { |
|
|
|
|
|
int cellIndex = 8 + firmArray.size(); |
|
|
|
|
|
Row nextRow = sheet.getRow(14 + count); |
|
|
|
|
|
Cell nextCell = nextRow.getCell(cellIndex); |
|
|
|
|
|
if (nextCell == null) { |
|
|
|
|
|
nextCell = nextRow.createCell(cellIndex); |
|
|
|
|
|
} |
|
|
|
|
|
nextCell.setCellValue(""); |
|
|
|
|
|
nextCell.setCellStyle(cellStyle2); |
|
|
|
|
|
if (count == 0) { |
|
|
|
|
|
nextCell.setCellValue("Pick Up Date 提货日期"); |
|
|
|
|
|
nextCell.setCellStyle(cellStyle2); |
|
|
|
|
|
} else if (count == 1) { |
|
|
|
|
|
nextCell.setCellValue("ETA " + jsonObjectHeader.getString("schm_header_arrive_us") + "\n到达" + jsonObjectHeader.getString("schm_header_arrive_ch") + "时间"); |
|
|
|
|
|
} else { |
|
|
|
|
|
nextCell.setCellValue(""); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
for (int i = 0; i < forecastArray.size(); i++) { |
|
|
|
|
|
int cellIndex = 9 + firmArray.size() + i; |
|
|
|
|
|
//设置forecast标题
|
|
|
|
|
|
Cell forecastCell = row14.getCell(cellIndex); |
|
|
|
|
|
if (forecastCell == null) { |
|
|
|
|
|
forecastCell = row14.createCell(cellIndex); |
|
|
|
|
|
} |
|
|
|
|
|
if (i == 0) { |
|
|
|
|
|
forecastCell.setCellValue("forecast 预测"); |
|
|
|
|
|
} else { |
|
|
|
|
|
forecastCell.setCellValue(""); |
|
|
|
|
|
} |
|
|
|
|
|
forecastCell.setCellStyle(cellStyle3); |
|
|
|
|
|
//设置forecast日期
|
|
|
|
|
|
JSONObject forecast = forecastArray.getJSONObject(i); |
|
|
|
|
|
Cell forecastDateCell = row15.getCell(cellIndex); |
|
|
|
|
|
if (forecastDateCell == null) { |
|
|
|
|
|
forecastDateCell = row15.createCell(cellIndex); |
|
|
|
|
|
} |
|
|
|
|
|
forecastDateCell.setCellValue(forecast.getString("schd_line_date")); |
|
|
|
|
|
forecastDateCell.setCellStyle(cellStyle5); |
|
|
|
|
|
//设置forecast每个订单数据
|
|
|
|
|
|
for (int count = 0; count < orderArray.size(); count++) { |
|
|
|
|
|
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.getIntValue("schd_line_qty"); |
|
|
|
|
|
} |
|
|
|
|
|
Cell nextCell = nextRow.getCell(cellIndex); |
|
|
|
|
|
if (nextCell == null) { |
|
|
|
|
|
nextCell = nextRow.createCell(cellIndex); |
|
|
|
|
|
} |
|
|
|
|
|
if (cellValue != 0) { |
|
|
|
|
|
nextCell.setCellValue(cellValue); |
|
|
|
|
|
} else { |
|
|
|
|
|
nextCell.setCellValue(""); |
|
|
|
|
|
} |
|
|
|
|
|
nextCell.setCellStyle(cellStyle7); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (!forecastArray.isEmpty() && forecastArray.size() > 1) { |
|
|
|
|
|
// 合并单元格
|
|
|
|
|
|
CellRangeAddress cellRangeAddress3 = new CellRangeAddress(14, 14, firmArray.size() + 9, firmArray.size() + forecastArray.size() + 8); |
|
|
|
|
|
sheet.addMergedRegion(cellRangeAddress3); |
|
|
|
|
|
} |
|
|
|
|
|
inputStream.close(); |
|
|
|
|
|
FileOutputStream outputStream = new FileOutputStream(filePath + "/" + fileName); |
|
|
|
|
|
workbook.write(outputStream); |
|
|
|
|
|
workbook.close(); |
|
|
|
|
|
outputStream.close(); |
|
|
|
|
|
return fileName; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 横财青岛格式excel |
|
|
* @param orderNo 订单号 |
|
|
* @param orderNo 订单号 |
|
|
* @param jsonObjectHeader 头部信息 |
|
|
* @param jsonObjectHeader 头部信息 |
|
|
* @param orderArray 订单数据 |
|
|
* @param orderArray 订单数据 |
|
@ -428,8 +609,8 @@ public class ExcelController { |
|
|
* @return 生成文件的路径 |
|
|
* @return 生成文件的路径 |
|
|
* @throws IOException io异常 |
|
|
* @throws IOException io异常 |
|
|
*/ |
|
|
*/ |
|
|
private String fillFoshanQingdao(String orderNo, JSONObject jsonObjectHeader, JSONArray orderArray, JSONArray firmArray, JSONArray forecastArray) throws IOException { |
|
|
private String fillQingdao(String orderNo, JSONObject jsonObjectHeader, JSONArray orderArray, JSONArray firmArray, JSONArray forecastArray) throws IOException { |
|
|
ClassPathResource templateFile = new ClassPathResource("foshan_qingdao.xls"); |
|
|
ClassPathResource templateFile = new ClassPathResource("qingdao.xls"); |
|
|
String filePath = WinConfig.getUploadPath(); |
|
|
String filePath = WinConfig.getUploadPath(); |
|
|
String fileName = orderNo + ".xls"; |
|
|
String fileName = orderNo + ".xls"; |
|
|
File file = new File(filePath); |
|
|
File file = new File(filePath); |
|
|