WANG 6 lat temu
rodzic
commit
5eab761d9c

+ 90 - 25
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/OrgController.java

@@ -3,6 +3,7 @@ package cn.com.qmth.examcloud.core.basic.api.controller;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -14,6 +15,8 @@ import javax.persistence.criteria.Predicate;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.disk.DiskFileItem;
@@ -44,13 +47,13 @@ import com.google.common.collect.Maps;
 
 import cn.com.qmth.examcloud.api.commons.exchange.PageInfo;
 import cn.com.qmth.examcloud.api.commons.security.bean.User;
+import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.helpers.DynamicEnum;
 import cn.com.qmth.examcloud.commons.helpers.DynamicEnumManager;
 import cn.com.qmth.examcloud.commons.util.PathUtil;
 import cn.com.qmth.examcloud.commons.util.RegExpUtil;
 import cn.com.qmth.examcloud.core.basic.api.controller.bean.OrgDomain;
-import cn.com.qmth.examcloud.core.basic.base.constants.PropKeys;
 import cn.com.qmth.examcloud.core.basic.dao.OrgPropertyRepo;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
@@ -58,7 +61,7 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.OrgPropertyEntity;
 import cn.com.qmth.examcloud.core.basic.dao.enums.OrgProperty;
 import cn.com.qmth.examcloud.core.basic.service.bean.OrgInfo;
 import cn.com.qmth.examcloud.core.basic.service.impl.OrgServiceImpl;
-import cn.com.qmth.examcloud.web.bootstrap.PropertyHolder;
+import cn.com.qmth.examcloud.web.config.SystemConfig;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.web.support.Naked;
@@ -81,6 +84,9 @@ public class OrgController extends ControllerSupport {
 	@Autowired
 	OrgPropertyRepo orgPropertyRepo;
 
+	@Autowired
+	SystemConfig systemConfig;
+
 	@ApiOperation(value = "分页查询所有机构")
 	@GetMapping("fullOrgPage/{curPage}/{pageSize}")
 	public PageInfo<OrgDomain> getFullOrgPage(@PathVariable Integer curPage,
@@ -853,16 +859,59 @@ public class OrgController extends ControllerSupport {
 			throw new StatusException("140002", "orgEntity is null");
 		}
 
+		Long orgId = org.getId();
+
 		DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
-		DynamicEnum de = manager.getByName("LOGO_PATH");
 
-		OrgPropertyEntity entity = orgPropertyRepo.findByOrgIdAndKeyId(org.getId(), de.getId());
-		if (null != entity) {
-			IOUtils.copy(new FileInputStream(entity.getValue()), response.getOutputStream());
-			response.flushBuffer();
-		} else {
+		DynamicEnum logoFileSuffix = manager.getByName("LOGO_FILE_SUFFIX");
+
+		OrgPropertyEntity fileSuffixEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
+				logoFileSuffix.getId());
+
+		if (null == fileSuffixEntity) {
 			throw new StatusException("140003", "no logo");
 		}
+
+		String path = systemConfig.getTempDataDir() + "/logo/" + orgId + fileSuffixEntity;
+
+		File file = new File(path);
+
+		if (file.exists()) {
+			FileInputStream in = null;
+			try {
+				in = new FileInputStream(file);
+				IOUtils.copy(in, response.getOutputStream());
+				response.flushBuffer();
+			} finally {
+				IOUtils.closeQuietly(in);
+			}
+			return;
+		}
+
+		DynamicEnum logoFile = manager.getByName("LOGO_FILE");
+		OrgPropertyEntity fileEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId, logoFile.getId());
+
+		byte[] decodeHex = null;;
+		try {
+			decodeHex = Hex.decodeHex(fileEntity.getValue());
+		} catch (DecoderException e) {
+			throw new ExamCloudRuntimeException(e);
+		}
+
+		FileUtils.writeByteArrayToFile(new File(path), decodeHex);
+
+		if (file.exists()) {
+			FileInputStream in = null;
+			try {
+				in = new FileInputStream(file);
+				IOUtils.copy(in, response.getOutputStream());
+				response.flushBuffer();
+			} finally {
+				IOUtils.closeQuietly(in);
+			}
+			return;
+		}
+
 	}
 
 	/**
@@ -886,36 +935,52 @@ public class OrgController extends ControllerSupport {
 
 		validateRootOrgIsolation(orgEntity.getRootId());
 
-		String schoolLogoPath = PropertyHolder.getString(PropKeys.SCHOOL_LOGO_PATH);
-		if (StringUtils.isBlank(schoolLogoPath)) {
-			FileUtils.forceMkdir(new File(schoolLogoPath));
-		}
 		FileItem fileItem = file.getFileItem();
 		String name = fileItem.getName();
-		String filePath = null;
+		String fileSuffix = null;
 		if (name.endsWith(".jpg")) {
-			filePath = schoolLogoPath + "/" + orgId + ".jpg";
+			fileSuffix = ".jpg";
 		} else if (name.endsWith(".gif")) {
-			filePath = schoolLogoPath + "/" + orgId + ".gif";
+			fileSuffix = ".gif";
 		} else if (name.endsWith(".png")) {
-			filePath = schoolLogoPath + "/" + orgId + ".png";
+			fileSuffix = ".png";
 		} else {
 			throw new StatusException("101001", "文件格式错误");
 		}
 
-		FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
+		byte[] byteArray = null;
+		InputStream inputStream = file.getInputStream();
+		try {
+			byteArray = IOUtils.toByteArray(inputStream);
+		} finally {
+			IOUtils.closeQuietly(inputStream);
+		}
+
+		String hexString = Hex.encodeHexString(byteArray);
 
 		DynamicEnumManager manager = OrgProperty.getDynamicEnumManager();
-		DynamicEnum de = manager.getByName("LOGO_PATH");
+		DynamicEnum logoFile = manager.getByName("LOGO_FILE");
+		DynamicEnum logoFileSuffix = manager.getByName("LOGO_FILE_SUFFIX");
+
+		OrgPropertyEntity fileEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId, logoFile.getId());
+		if (null == fileEntity) {
+			fileEntity = new OrgPropertyEntity();
+			fileEntity.setKeyId(logoFile.getId());
+			fileEntity.setOrgId(orgId);
+		}
+		fileEntity.setValue(hexString);
 
-		OrgPropertyEntity entity = orgPropertyRepo.findByOrgIdAndKeyId(orgId, de.getId());
-		if (null == entity) {
-			entity = new OrgPropertyEntity();
-			entity.setKeyId(de.getId());
-			entity.setOrgId(orgId);
+		OrgPropertyEntity fileSuffixEntity = orgPropertyRepo.findByOrgIdAndKeyId(orgId,
+				logoFileSuffix.getId());
+		if (null == fileSuffixEntity) {
+			fileSuffixEntity = new OrgPropertyEntity();
+			fileSuffixEntity.setKeyId(logoFileSuffix.getId());
+			fileSuffixEntity.setOrgId(orgId);
 		}
-		entity.setValue(filePath);
-		orgPropertyRepo.save(entity);
+		fileSuffixEntity.setValue(fileSuffix);
+
+		orgPropertyRepo.save(fileEntity);
+
 	}
 
 	@ApiOperation(value = "删除子机构", notes = "")

+ 41 - 46
examcloud-core-basic-base/src/main/java/cn/com/qmth/examcloud/core/basic/base/constants/PropKeys.java

@@ -1,46 +1,41 @@
-package cn.com.qmth.examcloud.core.basic.base.constants;
-
-/**
- * 自定义属性
- *
- * @author WANGWEI
- * @date 2018年6月21日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public interface PropKeys {
-
-	/**
-	 * 学校logo路径
-	 */
-	String SCHOOL_LOGO_PATH = "$croe.basic.resource.schoolLogoPath";
-
-	/**
-	 * session过期时长
-	 */
-	String SESSION_TIMEOUT = "$core.basic.sessionTimeout";
-
-	/**
-	 * 又拍云学生底照路径
-	 */
-	String STUDENT_PHOTO_URL_PREFIX = "$studentPhoto.url.prefix";
-
-	/**
-	 * 短信验证码签名
-	 */
-	String SEND_VERIFICATION_CODE_SIGN = "$sendVerificationCode.sign";
-
-	/**
-	 * 短信验证码模板
-	 */
-	String SEND_VERIFICATION_CODE_TEMPLATE_CODE = "$sendVerificationCode.templatecode";
-
-	/**
-	 * 短信验证码有效期/秒
-	 */
-	String SEND_VERIFICATION_CODE_EFFECTIVE_TIME = "$sendVerificationCode.effectivetime";
-
-	/**
-	 * 短信验证码 发送间隔时间/秒
-	 */
-	String SEND_VERIFICATION_CODE_INTERVAL_SECONDS = "$sendVerificationCode.intervalseconds";
-}
+package cn.com.qmth.examcloud.core.basic.base.constants;
+
+/**
+ * 自定义属性
+ *
+ * @author WANGWEI
+ * @date 2018年6月21日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface PropKeys {
+
+	/**
+	 * session过期时长
+	 */
+	String SESSION_TIMEOUT = "$core.basic.sessionTimeout";
+
+	/**
+	 * 又拍云学生底照路径
+	 */
+	String STUDENT_PHOTO_URL_PREFIX = "$studentPhoto.url.prefix";
+
+	/**
+	 * 短信验证码签名
+	 */
+	String SEND_VERIFICATION_CODE_SIGN = "$sendVerificationCode.sign";
+
+	/**
+	 * 短信验证码模板
+	 */
+	String SEND_VERIFICATION_CODE_TEMPLATE_CODE = "$sendVerificationCode.templatecode";
+
+	/**
+	 * 短信验证码有效期/秒
+	 */
+	String SEND_VERIFICATION_CODE_EFFECTIVE_TIME = "$sendVerificationCode.effectivetime";
+
+	/**
+	 * 短信验证码 发送间隔时间/秒
+	 */
+	String SEND_VERIFICATION_CODE_INTERVAL_SECONDS = "$sendVerificationCode.intervalseconds";
+}

+ 8 - 2
examcloud-core-basic-starter/src/main/resources/org-properties.xml

@@ -2,8 +2,8 @@
 <enums>
 	<enum>
 		<id>1</id>
-		<name>LOGO_PATH</name>
-		<desc>机构图标路径</desc>
+		<name>LOGO_FILE</name>
+		<desc>机构图标文件(文件转字符串存储)</desc>
 		<pattern>.*</pattern>
 	</enum>
 	<enum>
@@ -12,5 +12,11 @@
 		<desc>网考学生端系统名称</desc>
 		<pattern>.*</pattern>
 	</enum>
+	<enum>
+		<id>3</id>
+		<name>LOGO_FILE_SUFFIX</name>
+		<desc>机构图标文件后缀</desc>
+		<pattern>.*</pattern>
+	</enum>
 
 </enums>