Browse Source

。。。

wangwei 7 years ago
parent
commit
80521d9757

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

@@ -12,8 +12,10 @@ import java.util.stream.Stream;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -34,11 +36,15 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
+import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
 import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
+import cn.com.qmth.examcloud.commons.web.CommonPropKeys;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
 import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.base.constants.PropKeys;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
 import cn.com.qmth.examcloud.core.basic.service.bean.OrgDto;
@@ -62,9 +68,6 @@ public class OrgController extends ControllerSupport{
     @Autowired
     OrgService orgService;
     
-	@Value("${staticResource.rootPath}")
-	private String rootPath;
-	
 	@Autowired
 	private JdbcTemplate jdbcTemplate;
 
@@ -286,16 +289,25 @@ public class OrgController extends ControllerSupport{
     
 	@ApiOperation(value = "导入logo", notes = "导入logo")
 	@PostMapping("/importLogo/{id}")
-	public ResponseEntity importLogo(@PathVariable Long id, HttpServletRequest request,
-			@RequestParam CommonsMultipartFile file) {
-		try {
-			String filePath = rootPath + "/logo/" + id + ".jpg";
-			FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
-			jdbcTemplate.update("update ecs_core_org t set  t.logo=? where t.id=?", filePath, id);
-			return new ResponseEntity("", HttpStatus.OK);
-		} catch (Exception e) {
-			return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
+	public void importLogo(@PathVariable Long id, HttpServletRequest request,
+			@RequestParam CommonsMultipartFile file) throws IOException {
+		String schoolLogoPath = PropertiesUtil.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;
+		if (name.endsWith(".jpg")) {
+			filePath = schoolLogoPath + "/" + id + ".jpg";
+		} else if (name.endsWith(".gif")) {
+			filePath = schoolLogoPath + "/" + id + ".gif";
+		} else {
+			throw new StatusException("B-101001", "文件格式错误");
 		}
+
+		FileUtils.copyInputStreamToFile(file.getInputStream(), new File(filePath));
+		jdbcTemplate.update("update ecs_core_org t set  t.logo=? where t.id=?", filePath, id);
 	}
 	
 	@ApiOperation(value = "按机构名称模糊查询机构列表", notes = "")

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

@@ -0,0 +1,17 @@
+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 class PropKeys {
+
+	/**
+	 * 学校logo路径
+	 */
+	public static final String SCHOOL_LOGO_PATH = "$croe.basic.resource.schoolLogoPath";
+
+}

+ 1 - 1
examcloud-core-basic-starter/src/main/resources/application-dev.properties

@@ -13,6 +13,6 @@ spring.rabbitmq.username=examcloud
 spring.rabbitmq.password=examcloud
 spring.rabbitmq.listener.acknowledgeMode=MANUAL
 
-staticResource.rootPath=/home/qmth/project/examcloud/static
+$croe.basic.resource.schoolLogoPath=D:/Temp/logo
 
 $core.basic.sessionTimeout=600

+ 1 - 1
examcloud-core-basic-starter/src/main/resources/application-prod.properties

@@ -17,7 +17,7 @@ spring.rabbitmq.listener.acknowledgeMode=MANUAL
 hystrix.command.default.execution.timeout.enabled=false
 hystrix.threadpool.default.coreSize = 500
 
-staticResource.rootPath=/home/qmth/project/examcloud/static
+$croe.basic.resource.schoolLogoPath=/home/qmth/project/examcloud/static/logo
 
 $core.basic.sessionTimeout=3600
 

+ 1 - 1
examcloud-core-basic-starter/src/main/resources/application-test.properties

@@ -15,6 +15,6 @@ spring.rabbitmq.username=examcloud
 spring.rabbitmq.password=examcloud
 spring.rabbitmq.listener.acknowledgeMode=MANUAL
 
-staticResource.rootPath=/home/qmth/project/examcloud/static
+$croe.basic.resource.schoolLogoPath=/home/qmth/project/examcloud/static/logo
 
 $core.basic.sessionTimeout=3600