浏览代码

导入带图像

suntianwu 3 年之前
父节点
当前提交
fc6cae9821
共有 1 个文件被更改,包括 7 次插入6 次删除
  1. 7 6
      src/main/java/com/iden/bms/service/PersonService.java

+ 7 - 6
src/main/java/com/iden/bms/service/PersonService.java

@@ -272,9 +272,10 @@ public class PersonService {
     public List<Long> importWithExcel(MultipartFile file) throws BDException {
         List<Long> personIdList = new ArrayList<>();
             try {
-                System.out.println("file.getName()==" + file.getName());
-                System.out.println("file.getName()2==" + file.getName().substring(file.getName().length() - 4));
-                if (!file.getName().substring(file.getName().length() - 4).equals("xlsx")) {
+                String excelFileName = file.getOriginalFilename();
+                System.out.println("file.getName()==" + excelFileName);
+                System.out.println("file.getName()2==" + excelFileName.substring(excelFileName.length() - 4));
+                if (!excelFileName.substring(excelFileName.length() - 4).equals("xlsx")) {
                     throw new BDException("导入Excel只支持xlsx格式");
                 }
 
@@ -455,11 +456,11 @@ public class PersonService {
                         PictureData picData = picMap.get(i);
                         if(picData != null){
                             //保存的文件名
-                            String fileName = DateUtils.getCurrYyyyMMddHHmmssDate() + "_" + UUID.randomUUID().toString()   + ".jpg";
-                            String savePath = idenRoot + "data/final/person/image/" + idenCommunity.getCode() + "/" + fileName;
+                            String saveFileName = DateUtils.getCurrYyyyMMddHHmmssDate() + "_" + UUID.randomUUID().toString()   + ".jpg";
+                            String savePath = idenRoot + "data/final/person/image/" + idenCommunity.getCode() + "/" + saveFileName;
                             // 保存图片
                             savePic(picData,savePath);
-                            personVO.setImage(fileUrl + "person/image/" + idenCommunity.getCode() +"/" + fileName);
+                            personVO.setImage(fileUrl + "person/image/" + idenCommunity.getCode() +"/" + saveFileName);
                         }
 
                     }