소스 검색

Merge remote-tracking branch 'origin/master'

Joburgess 4 년 전
부모
커밋
3fbbd662af

+ 4 - 2
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/OrganizationServiceImpl.java

@@ -26,6 +26,7 @@ import com.keao.edu.util.iniFile.IniFileEntity;
 import com.keao.edu.util.iniFile.IniFileUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -36,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.beans.IntrospectionException;
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.InputStream;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -357,8 +359,8 @@ public class OrganizationServiceImpl extends BaseServiceImpl<Integer, Organizati
 
         Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(file.getInputStream(), 2, file.getOriginalFilename());
 
-        File columnFile = ResourceUtils.getFile("classpath:" + "columnMapper.ini");
-        List<IniFileEntity> organizationColumns = IniFileUtil.readIniFile(columnFile).get("organization");
+        InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
+        List<IniFileEntity> organizationColumns = IniFileUtil.readIniFile(inputStream).get("organization");
 
         List<SysRole> organRoles = sysUserDao.getOrganRole(Integer.parseInt(tenantId));
         List<Organization> organizations = new ArrayList<>();

+ 3 - 3
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/TeacherServiceImpl.java

@@ -26,6 +26,7 @@ import com.keao.edu.util.iniFile.IniFileEntity;
 import com.keao.edu.util.iniFile.IniFileUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -183,9 +184,8 @@ public class TeacherServiceImpl extends BaseServiceImpl<Integer, Teacher> implem
     @Transactional(rollbackFor = Exception.class)
     public List<Teacher> importTeacher(MultipartFile file, String tenantId, Integer organId) throws Exception {
         Map<String, List<Map<String, Object>>> sheetsListMap = POIUtil.importExcel(file.getInputStream(), 2, file.getOriginalFilename());
-
-        File columnFile = ResourceUtils.getFile("classpath:" + "columnMapper.ini");
-        List<IniFileEntity> columns = IniFileUtil.readIniFile(columnFile).get("teacher");
+        InputStream inputStream = new ClassPathResource("columnMapper.ini").getInputStream();
+        List<IniFileEntity> columns = IniFileUtil.readIniFile(inputStream).get("teacher");
         List<Subject> subSubjects = subjectDao.findSubSubjects();
         List<Teacher> teachers = new ArrayList<>();
         sheetsListMap.keySet().forEach(e -> {

+ 1 - 1
edu-user/edu-user-server/src/main/resources/columnMapper.ini

@@ -1,4 +1,4 @@
-[test]
+[examSong]
 曲目名称=songName
 曲目作者=songAuthor
 曲目专业=subjectList

+ 85 - 41
edu-util/src/main/java/com/keao/edu/util/iniFile/IniFileUtil.java

@@ -2,6 +2,7 @@ package com.keao.edu.util.iniFile;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -17,45 +18,88 @@ import com.keao.edu.util.exception.UtilException;
 
 public class IniFileUtil {
 
-	/**
-	 * 读取Ini文件
-	 * @param iniFile 文件绝对路径(文件编码须UTF-8)
-	 * @return 返回所有section以及下面的key/value
-	 * @throws InvalidFileFormatException
-	 * @throws IOException
-	 */
-	public static Map<String, List<IniFileEntity>> readIniFile(File iniFile) throws InvalidFileFormatException, IOException {
-		if (!iniFile.exists()) {
-			throw new UtilException("文件[" + iniFile.getAbsolutePath() + "]不存在");
-		}
-		Ini ini = new Ini();
-		ini.load(iniFile);
-
-		Map<String, List<IniFileEntity>> result = new HashMap<String, List<IniFileEntity>>();
-		IniFileEntity entity = null;
-
-		Collection<Section> sections = ini.values();
-		for (Section section : sections) {
-			List<IniFileEntity> entryList = result.get(section.getName());
-			if (entryList == null) {
-				entryList = new ArrayList<IniFileEntity>();
-			}
-			for (Entry<String, String> entry : section.entrySet()) {
-				entity = new IniFileEntity();
-				entity.setSection(section.getName());
-				entity.setKey(entry.getKey());
-				entity.setValue(entry.getValue());
-
-				entryList.add(entity);
-			}
-			result.put(section.getName(), entryList);
-		}
-
-		return result;
-	}
-	
-	public static void main(String[] args) throws InvalidFileFormatException, IOException {
-		File file = new File("e:/test.ini");
-		System.out.println(IniFileUtil.readIniFile(file));
-	}
+    /**
+     * 读取Ini文件
+     *
+     * @param iniFile 文件绝对路径(文件编码须UTF-8)
+     * @return 返回所有section以及下面的key/value
+     * @throws InvalidFileFormatException
+     * @throws IOException
+     */
+    public static Map<String, List<IniFileEntity>> readIniFile(File iniFile) throws InvalidFileFormatException, IOException {
+        if (!iniFile.exists()) {
+            throw new UtilException("文件[" + iniFile.getAbsolutePath() + "]不存在");
+        }
+        Ini ini = new Ini();
+        ini.load(iniFile);
+
+        Map<String, List<IniFileEntity>> result = new HashMap<String, List<IniFileEntity>>();
+        IniFileEntity entity = null;
+
+        Collection<Section> sections = ini.values();
+        for (Section section : sections) {
+            List<IniFileEntity> entryList = result.get(section.getName());
+            if (entryList == null) {
+                entryList = new ArrayList<IniFileEntity>();
+            }
+            for (Entry<String, String> entry : section.entrySet()) {
+                entity = new IniFileEntity();
+                entity.setSection(section.getName());
+                entity.setKey(entry.getKey());
+                entity.setValue(entry.getValue());
+
+                entryList.add(entity);
+            }
+            result.put(section.getName(), entryList);
+        }
+
+        return result;
+    }
+
+
+    /**
+     * 读取Ini文件
+     *
+     * @param inputStream
+     * @return 返回所有section以及下面的key/value
+     * @throws InvalidFileFormatException
+     * @throws IOException
+     */
+    public static Map<String, List<IniFileEntity>> readIniFile(InputStream inputStream) throws InvalidFileFormatException, IOException {
+        Ini ini = new Ini();
+        try {
+            ini.load(inputStream);
+        } catch (Exception e) {
+            throw new UtilException(e.getMessage());
+        } finally {
+            inputStream.close();
+        }
+
+        Map<String, List<IniFileEntity>> result = new HashMap<String, List<IniFileEntity>>();
+        IniFileEntity entity = null;
+
+        Collection<Section> sections = ini.values();
+        for (Section section : sections) {
+            List<IniFileEntity> entryList = result.get(section.getName());
+            if (entryList == null) {
+                entryList = new ArrayList<IniFileEntity>();
+            }
+            for (Entry<String, String> entry : section.entrySet()) {
+                entity = new IniFileEntity();
+                entity.setSection(section.getName());
+                entity.setKey(entry.getKey());
+                entity.setValue(entry.getValue());
+
+                entryList.add(entity);
+            }
+            result.put(section.getName(), entryList);
+        }
+
+        return result;
+    }
+
+    public static void main(String[] args) throws InvalidFileFormatException, IOException {
+        File file = new File("e:/test.ini");
+        System.out.println(IniFileUtil.readIniFile(file));
+    }
 }