<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
</dependency>
@RequestMapping("/extArrangeOrderTemp")
public void extArrangeOrderTemp(HttpServletResponse response) {
try {
String[] title = {"客户", "订单号", "款号", "交货日期", "开款日期", "订单数量", "目标数量", "生产小组", "SAM值/秒"};
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
sheet.setDefaultRowHeight((short) 500);
sheet.setDefaultColumnWidth(10000);
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
row.setHeight((short) 500);
for (int i = 0; i < title.length; i++) {
cell = row.createCell(i);
cell.setCellValue(title[i]);
}
workbook.write(response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
}
@RequestMapping(value = "/batchArrangeOrder")
public BaseResult<?> batchArrangeOrder(HttpServletRequest request, Long adminId) {
try {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
MultipartFile mf = multipartRequest.getFile("file");
assert mf != null;
return mArrangeOrderService.batchArrangeOrder(mf, adminId);
} catch (Exception e) {
e.printStackTrace();
}
return BaseResult.result();
}
public BaseResult<?> batchArrangeOrder(MultipartFile mf, Long adminId) {
try {
Workbook workbook = new HSSFWorkbook(mf.getInputStream());
Sheet sheet = workbook.getSheetAt(0);
int index = 0;
for (Row row : sheet) {
if (index != 0) {
String customer = ProjectUtils.getCellStringValue(row, 0);
String orderCode = ProjectUtils.getCellStringValue(row, 1);
String styleCode = ProjectUtils.getCellStringValue(row, 2);
String deliveryDate = MSDateUtil.formatTime(ProjectUtils.getCellDateValue(row, 3), "yyyy-MM-dd");
String paymentDate = MSDateUtil.formatTime(ProjectUtils.getCellDateValue(row, 4), "yyyy-MM-dd");
Integer orderNum = ProjectUtils.getCellIntValue(row, 5);
Integer targetNum = ProjectUtils.getCellIntValue(row, 6);
String proLine = ProjectUtils.getCellStringValue(row, 7);
Integer stdDur = ProjectUtils.getCellIntValue(row, 8);
if (orderCode == null) continue;
inArrangeOrder(adminId, customer, orderCode, styleCode, deliveryDate, paymentDate, orderNum, targetNum, proLine, stdDur);
}
index++;
}
} catch (Exception ex) {
ex.printStackTrace();
return BaseResult.result().setReturnCode(ReturnCode.CODE_4001);
}
return BaseResult.result();
}
public static String getCellStringValue(Row row, int index) {
Cell cell = row.getCell(index);
if (cell.getCellType() == CellType.STRING) {
return cell.getStringCellValue();
}
if (cell.getCellType() == CellType.NUMERIC) {
return new Double(cell.getNumericCellValue()).longValue() + "";
}
return null;
}
public static Integer getCellIntValue(Row row, int index) {
Cell cell = row.getCell(index);
if (cell.getCellType() == CellType.STRING) {
return Integer.parseInt(cell.getStringCellValue());
}
if (cell.getCellType() == CellType.NUMERIC) {
return new Double(cell.getNumericCellValue()).intValue();
}
return null;
}
public static Float getCellFloatValue(Row row, int index) {
Cell cell = row.getCell(index);
if (cell.getCellType() == CellType.STRING) {
return Float.parseFloat(cell.getStringCellValue());
}
if (cell.getCellType() == CellType.NUMERIC) {
return new Double(cell.getNumericCellValue()).floatValue();
}
return null;
}
public static Date getCellDateValue(Row row, int index) {
Cell cell = row.getCell(index);
return cell.getDateCellValue();
}
|