|
@@ -1,18 +1,24 @@
|
|
package com.project.zcustom.service.unit.impl;
|
|
package com.project.zcustom.service.unit.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.project.common.core.domain.search.PageParamVo;
|
|
|
|
+import com.project.common.utils.StringUtils;
|
|
import com.project.zcustom.domain.addional.LargeProject;
|
|
import com.project.zcustom.domain.addional.LargeProject;
|
|
import com.project.zcustom.mapper.unit.LargeProjectMapper;
|
|
import com.project.zcustom.mapper.unit.LargeProjectMapper;
|
|
import com.project.zcustom.service.unit.ILargeProjectService;
|
|
import com.project.zcustom.service.unit.ILargeProjectService;
|
|
-import com.project.common.core.domain.search.PageParamVo;
|
|
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
-import com.project.common.utils.StringUtils;
|
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -217,4 +223,108 @@ public class LargeProjectServiceImpl extends ServiceImpl<LargeProjectMapper, Lar
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public int upload(MultipartFile file){
|
|
|
|
+ try {
|
|
|
|
+ List<LargeProject> data = parseExcel(file.getInputStream());
|
|
|
|
+ largeProjectMapper.upload(data);
|
|
|
|
+ return 1;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 解析 Excel 文件
|
|
|
|
+ private List<LargeProject> parseExcel(InputStream inputStream) throws IOException {
|
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream);
|
|
|
|
+ Sheet sheet = workbook.getSheetAt(0); // 获取第一个表单
|
|
|
|
+ Iterator<Row> rowIterator = sheet.iterator();
|
|
|
|
+
|
|
|
|
+ List<LargeProject> data = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ // 跳过表头
|
|
|
|
+ if (rowIterator.hasNext()) {
|
|
|
|
+ rowIterator.next();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, String> mapType = new HashMap<>();
|
|
|
|
+ mapType.put("在建", "0");
|
|
|
|
+ mapType.put("施工", "2");
|
|
|
|
+ Map<String, Long> mapSubdivision = new HashMap<>();
|
|
|
|
+ mapSubdivision.put("可研评审", 1L);
|
|
|
|
+ mapSubdivision.put("初设评审", 2L);
|
|
|
|
+ mapSubdivision.put("政府立项备案", 3L);
|
|
|
|
+ mapSubdivision.put("土地手续", 4L);
|
|
|
|
+ mapSubdivision.put("用地规划", 5L);
|
|
|
|
+ mapSubdivision.put("工程规划", 6L);
|
|
|
|
+ mapSubdivision.put("设计招标", 7L);
|
|
|
|
+ mapSubdivision.put("施工招标", 8L);
|
|
|
|
+ mapSubdivision.put("监理招标", 9L);
|
|
|
|
+ mapSubdivision.put("施工许可", 10L);
|
|
|
|
+ mapSubdivision.put("基础施工", 11L);
|
|
|
|
+ mapSubdivision.put("主体工程", 12L);
|
|
|
|
+ mapSubdivision.put("室内外装修", 13L);
|
|
|
|
+ mapSubdivision.put("室外工程", 14L);
|
|
|
|
+
|
|
|
|
+ // 遍历每一行
|
|
|
|
+ while (rowIterator.hasNext()) {
|
|
|
|
+ Row row = rowIterator.next();
|
|
|
|
+ LargeProject a = new LargeProject();
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) {
|
|
|
|
+ Cell cell = row.getCell(i);
|
|
|
|
+
|
|
|
|
+ switch (i) {
|
|
|
|
+ case 0:
|
|
|
|
+ if (cell != null && cell.getCellType() == CellType.STRING) {
|
|
|
|
+ a.setProjectName(cell.getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 1:
|
|
|
|
+ if (cell != null && cell.getCellType() == CellType.STRING) {
|
|
|
|
+ a.setAppOrg(cell.getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ if (cell != null && cell.getCellType() == CellType.STRING) {
|
|
|
|
+ a.setType(mapType.get(cell.getStringCellValue()));
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ if (cell != null && cell.getCellType() == CellType.STRING) {
|
|
|
|
+ a.setSubdivision(mapSubdivision.get(cell.getStringCellValue()));
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 4:
|
|
|
|
+ if (cell != null && cell.getCellType() == CellType.NUMERIC) {
|
|
|
|
+ a.setAbscissa(BigDecimal.valueOf(cell.getNumericCellValue()));
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 5:
|
|
|
|
+ if (cell != null && cell.getCellType() == CellType.NUMERIC) {
|
|
|
|
+ a.setOrdinate(BigDecimal.valueOf(cell.getNumericCellValue()));
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 6:
|
|
|
|
+ if (cell != null && cell.getCellType() == CellType.STRING) {
|
|
|
|
+ a.setSupervisionUnit(cell.getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case 7:
|
|
|
|
+ if (cell != null && cell.getCellType() == CellType.STRING) {
|
|
|
|
+ a.setConstructionUnit(cell.getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ data.add(a);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ workbook.close();
|
|
|
|
+ return data;
|
|
|
|
+ }
|
|
}
|
|
}
|