|
@@ -1,18 +1,21 @@
|
|
|
package org.jeecg.modules.oa.controller;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.net.URLDecoder;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.jeecg.common.exception.JeecgBootException;
|
|
|
import org.jeecg.common.system.vo.LoginUser;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.oa.vo.SyCarryPage;
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
|
@@ -22,7 +25,6 @@ import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
|
|
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
-import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.oa.entity.SyCarryB;
|
|
|
import org.jeecg.modules.oa.entity.SyCarry;
|
|
|
import org.jeecg.modules.oa.service.ISyCarryService;
|
|
@@ -37,7 +39,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
/**
|
|
|
* @Description: 搬运装卸费用-搬运工对账单-主表
|
|
@@ -202,17 +203,13 @@ public class SyCarryController {
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
- MultipartFile file = entity.getValue();// 获取上传文件对象
|
|
|
- ImportParams params = new ImportParams();
|
|
|
- params.setTitleRows(2);
|
|
|
- params.setHeadRows(1);
|
|
|
- params.setNeedSave(true);
|
|
|
+ MultipartFile file = entity.getValue();// 获取上传文件对象
|
|
|
try {
|
|
|
- List<SyCarryPage> list = ExcelImportUtil.importExcel(file.getInputStream(), SyCarryPage.class, params);
|
|
|
- Result<List<SyCarryPage>> result = new Result<>();
|
|
|
- result.setMessage("文件导入成功!数据行数:" + list.size());
|
|
|
- result.setResult(list);
|
|
|
- return result;
|
|
|
+ InputStream inputStream=file.getInputStream();
|
|
|
+ Workbook workbook=new XSSFWorkbook(inputStream);
|
|
|
+
|
|
|
+ SyCarryPage syCarryPage = refreshSheet2(workbook);
|
|
|
+ return Result.ok(syCarryPage);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(),e);
|
|
|
return Result.error("文件导入失败:"+e.getMessage());
|
|
@@ -227,6 +224,87 @@ public class SyCarryController {
|
|
|
return Result.ok("文件导入失败!");
|
|
|
}
|
|
|
|
|
|
+ public SyCarryPage refreshSheet2(Workbook workbook1) throws ParseException {
|
|
|
+ Sheet sheet = workbook1.getSheet("Sheet1");
|
|
|
+ SyCarryPage syCarryPage = new SyCarryPage();
|
|
|
+ List<SyCarryB> syCarryBList = new ArrayList<>();
|
|
|
+ //末尾坐标
|
|
|
+ int endX = 0;
|
|
|
+ //给表体数据赋值
|
|
|
+ for (int x=0;x<=sheet.getLastRowNum();x++){
|
|
|
+ Row row=sheet.getRow(x);
|
|
|
+ SyCarryB syCarryB = new SyCarryB();
|
|
|
+ if(x>=3){
|
|
|
+ if(row==null || row.getCell(0)==null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(row.getCell(0).toString().equals("合计:")){
|
|
|
+ endX=x;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ syCarryB.setOrderDate(row.getCell(0).getDateCellValue());
|
|
|
+ syCarryB.setAllNum(row.getCell(1).getNumericCellValue());
|
|
|
+ syCarryB.setDetailedNum(row.getCell(2).getNumericCellValue());
|
|
|
+ syCarryB.setCoatHanger(row.getCell(3)==null?0:row.getCell(3).getNumericCellValue());
|
|
|
+ syCarryB.setContainerNo(row.getCell(4).getStringCellValue());
|
|
|
+ syCarryB.setInvoiceNo(row.getCell(5).getStringCellValue());
|
|
|
+ syCarryB.setPrice(row.getCell(6).getNumericCellValue());
|
|
|
+ syCarryB.setJhyByData(row.getCell(7).getStringCellValue());
|
|
|
+ syCarryB.setJhyNameData(row.getCell(8)==null?"":row.getCell(8).getStringCellValue());
|
|
|
+ syCarryB.setDemo(row.getCell(9)==null?"":row.getCell(9).getStringCellValue());
|
|
|
+ syCarryBList.add(syCarryB);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //给表头赋值
|
|
|
+ syCarryPage.setSyCarryBList(syCarryBList);
|
|
|
+ String demo = sheet.getRow(endX+1).getCell(0).getStringCellValue()+" || "+
|
|
|
+ sheet.getRow(endX+2).getCell(0).getStringCellValue()+" || "+
|
|
|
+ sheet.getRow(endX+3).getCell(0).getStringCellValue()+" || "+
|
|
|
+ sheet.getRow(endX+4).getCell(0).getStringCellValue();
|
|
|
+ syCarryPage.setDemo(demo);
|
|
|
+ syCarryPage.setTotalNum(sheet.getRow(endX).getCell(3).getNumericCellValue());
|
|
|
+ return syCarryPage;
|
|
|
+ }
|
|
|
+// if(x<2) {
|
|
|
+// mainStrs.add(row.getCell(4)==null?"":row.getCell(4).toString());
|
|
|
+// mainStrs.add(row.getCell(8)==null?"":row.getCell(8).toString());
|
|
|
+// mainStrs.add(row.getCell(12)==null?"":row.getCell(12).toString());
|
|
|
+// mainStrs.add(row.getCell(16)==null?"":row.getCell(16).toString());
|
|
|
+// mainStrs.add(row.getCell(20)==null?"":row.getCell(16).toString());
|
|
|
+// }else if(x==2){
|
|
|
+// main =new SyPackingListFabric(mainStrs.toArray(new String[mainStrs.size()]));
|
|
|
+// }else if(x>3){
|
|
|
+// if(oConvertUtils.isEmpty(row.getCell(1))||row.getCell(1).toString().length()<10){//如果这一列为空就退出
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// List<String> itemStrs=new ArrayList<>();
|
|
|
+// for (int i=0;i<row.getLastCellNum();i++){
|
|
|
+// Cell cell=row.getCell(i);
|
|
|
+// if(i<18&&i>14){
|
|
|
+// if(cell==null||cell.equals("")||cell.toString().length()<1){
|
|
|
+// throw new JeecgBootException("请填写第"+(x+1)+"行里的"+sheet.getRow(3).getCell(i));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// cell.setCellType(CellType.STRING);//获取的都转换成String
|
|
|
+// FormulaEvaluator formulaEvaluator = new XSSFFormulaEvaluator((XSSFWorkbook) workbook1);
|
|
|
+// //获取单元格内容的类型
|
|
|
+// CellType cellType = cell.getCellType();
|
|
|
+// //判断是否存储的为公式,此处本可以不加判断
|
|
|
+// if (cellType.equals(CellType.FORMULA)){
|
|
|
+// //获取公式,可以理解为已String类型获取cell的值输出
|
|
|
+// String cellFormula = cell.getCellFormula();
|
|
|
+// //System.out.println(cellFormula);
|
|
|
+// //执行公式,此处cell的值就是公式
|
|
|
+// CellValue evaluate = formulaEvaluator.evaluate(cell);
|
|
|
+// //System.out.println(evaluate.formatAsString());
|
|
|
+// itemStrs.add(evaluate.formatAsString());
|
|
|
+// }else{
|
|
|
+// itemStrs.add(cell.toString());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// SyPackingListFabricItem syPackingListFabricItem=new SyPackingListFabricItem(itemStrs.toArray(new String[itemStrs.size()]));
|
|
|
+// items.add(syPackingListFabricItem);
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 通过excel导入数据
|