|
@@ -22,6 +22,10 @@ import com.jeeplus.sys.service.mapstruct.UserProjectWrapper;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
@@ -176,7 +180,7 @@ public class UserProjectController {
|
|
|
@PreAuthorize("hasAnyAuthority('sys:project:import')")
|
|
|
@PostMapping("import")
|
|
|
@ApiOperation(value = "导入项目数据excel")
|
|
|
- public ResponseEntity importFile(MultipartFile file) {
|
|
|
+ public ResponseEntity importFile(MultipartFile file) throws IOException{
|
|
|
|
|
|
this.successNum = 0;
|
|
|
|
|
@@ -184,22 +188,36 @@ public class UserProjectController {
|
|
|
ArrayList<UserProject> arrayList = new ArrayList<>();
|
|
|
HashMap<String,String> hashMap = new HashMap<>();
|
|
|
|
|
|
- //评估项目sheet1
|
|
|
- List<UserProjectDTO> listA = EasyPoiUtil.importSheetExcel(file, 1, 1, 0,1, UserProjectDTO.class);
|
|
|
+ HSSFWorkbook hssfWorkBook=new HSSFWorkbook(file.getInputStream());
|
|
|
|
|
|
- String resultA = importDecide(listA, sdf, arrayList, hashMap, successNum, ProjectTypeEnum.ASSESS.getValue());
|
|
|
- if(StrUtil.isNotEmpty(resultA)){
|
|
|
- return ResponseEntity.badRequest().body (resultA);
|
|
|
+ List<UserProjectDTO> listA = new ArrayList<>();
|
|
|
+ List<UserProjectDTO> listB = new ArrayList<>();
|
|
|
+
|
|
|
+ int sheetIndexAs = hssfWorkBook.getSheetIndex("项目明细表");
|
|
|
+ if(sheetIndexAs != -1){
|
|
|
+ //评估项目sheet
|
|
|
+ listA = EasyPoiUtil.importSheetExcel(file, 1, 1, sheetIndexAs,1, UserProjectDTO.class);
|
|
|
+
|
|
|
+ String resultA = importDecide(listA, sdf, arrayList, hashMap, successNum, ProjectTypeEnum.ASSESS.getValue());
|
|
|
+ if(StrUtil.isNotEmpty(resultA)){
|
|
|
+ return ResponseEntity.badRequest().body (resultA);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- //咨询项目sheet2
|
|
|
- List<UserProjectDTO> listB = EasyPoiUtil.importSheetExcel(file, 1, 1, 1,1, UserProjectDTO.class);
|
|
|
+ int sheetIndexCo = hssfWorkBook.getSheetIndex("咨询报告");
|
|
|
+ if(sheetIndexCo != -1){
|
|
|
+ //咨询项目sheet
|
|
|
+ listB = EasyPoiUtil.importSheetExcel(file, 1, 1, sheetIndexCo,1, UserProjectDTO.class);
|
|
|
|
|
|
- String resultB = importDecide(listB, sdf, arrayList, hashMap, successNum, ProjectTypeEnum.CONSULTATION.getValue());
|
|
|
- if(StrUtil.isNotEmpty(resultB)){
|
|
|
- return ResponseEntity.badRequest().body (resultB);
|
|
|
+ String resultB = importDecide(listB, sdf, arrayList, hashMap, successNum, ProjectTypeEnum.CONSULTATION.getValue());
|
|
|
+ if(StrUtil.isNotEmpty(resultB)){
|
|
|
+ return ResponseEntity.badRequest().body (resultB);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ if(sheetIndexAs == -1 && sheetIndexCo == -1) return ResponseEntity.badRequest().body ("导入文件格式不正确,建议根据模板来进行数据的导入");
|
|
|
+
|
|
|
+
|
|
|
if(hashMap.size() != listA.size() + listB.size()){
|
|
|
return ResponseEntity.badRequest().body ("文件中存在重复的文号或者多个空文号");
|
|
|
}
|