|
@@ -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 = "")
|