From fe74fb7d72fd9283249ed2753b9baec523915c92 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Tue, 20 Aug 2019 22:48:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=83=A8=E9=97=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=92=8C=E4=BA=BA=E5=91=98=E6=9F=A5=E8=AF=A2=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=8E=A5=E5=8F=A3=E6=9C=BA=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8B=E8=BD=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/plugin/IApiConsts.java | 5 ++ .../department/IDepartmentService.java | 11 +++ .../impl/DepartmentServiceImpl.java | 13 ++++ .../service/file/impl/FileServiceImpl.java | 73 ++++++++++++++++++- 4 files changed, 99 insertions(+), 3 deletions(-) diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java index c42f166..7806ef3 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/IApiConsts.java @@ -19,6 +19,11 @@ public interface IApiConsts { */ String LIST_DEPARTMENT = "%s/resource/department/listdepartments/%s"; + /** + * 父ID获取全部部门 + */ + String LIST_ALL_DEPARTMENT = "%s/resource/department/listalldepartments/%s"; + /** * 组织部门用户列表 */ diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/IDepartmentService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/IDepartmentService.java index f3b1368..efb18f4 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/IDepartmentService.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/IDepartmentService.java @@ -23,8 +23,19 @@ public interface IDepartmentService { * * @param params * @return + * @throws AccessTokenException + * @throws AccessTokenException * @throws SearchException */ JSONArray listDepartments(Map params) throws AccessTokenException, AccessTokenException, SearchException; + /** + * 组织部门列表 + * + * @param parentId + * @return + * @throws AccessTokenException + * @throws SearchException + */ + JSONArray listDepartmentsAllByParentId(String parentId) throws AccessTokenException, SearchException; } diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/impl/DepartmentServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/impl/DepartmentServiceImpl.java index 3205d6d..f4e243f 100644 --- a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/impl/DepartmentServiceImpl.java +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/department/impl/DepartmentServiceImpl.java @@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.HashMap; import java.util.Map; /** @@ -43,4 +44,16 @@ public class DepartmentServiceImpl extends AbstractService implements IDepartmen } return JSONArray.parseArray(result); } + + @Override + public JSONArray listDepartmentsAllByParentId(String parentId) throws AccessTokenException, SearchException { + String result = restTemplateUtil.doPostForm(String.format(IApiConsts.LIST_ALL_DEPARTMENT, apiPathProperties.getUserCenter(), parentId), new HashMap<>(0)); + if(result == null) { + throw new AccessTokenException("认证失败"); + } + if(result.isEmpty()) { + throw new SearchException("获取组织部门列表失败"); + } + return JSONArray.parseArray(result); + } } diff --git a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/file/impl/FileServiceImpl.java b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/file/impl/FileServiceImpl.java index 0a4089a..97934db 100644 --- a/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/file/impl/FileServiceImpl.java +++ b/cloud-common-plugin/src/main/java/com/cm/common/plugin/service/file/impl/FileServiceImpl.java @@ -128,10 +128,11 @@ public class FileServiceImpl extends AbstractService implements IFileService { if (null == filePO) { throw new SearchException("文件获取失败"); } - if (Boolean.valueOf(params.get("isOpen").toString())) { - response.setContentType("application/force-download"); + response.setContentType(getContentType(filePO.getFileType())); + response.addHeader("Content-Length", filePO.getFileSize()); + if (!Boolean.valueOf(params.get("isOpen").toString())) { + response.addHeader("Content-Disposition", "attachment;fileName=" + filePO.getFileName()); } - response.addHeader("Content-Disposition", "attachment;fileName=" + filePO.getFileName()); outputStream = response.getOutputStream(); fileInputStream = new FileInputStream(new File(filePO.getFilePath())); for (byte[] buf = new byte[INPUT_STREAM_SIZE]; fileInputStream.read(buf) > -1; ) { @@ -417,4 +418,70 @@ public class FileServiceImpl extends AbstractService implements IFileService { return true; } + /** + * 获取ContentType + * + * @param fileType + * @return + */ + private String getContentType(String fileType) { + String contentType; + switch (fileType) { + case "png": + contentType = "image/png"; + break; + case "jpg": + contentType = "image/jpeg"; + break; + case "jpeg": + contentType = "image/jpeg"; + break; + case "gif": + contentType = "image/gif"; + break; + case "mp4": + contentType = "video/mpeg4"; + break; + case "rmvb": + contentType = "application/vnd.rn-realmedia-vbr"; + break; + case "mp3": + contentType = "audio/mp3"; + break; + case "wmv": + contentType = "video/x-ms-wmv"; + break; + case "wav": + contentType = "audio/wav"; + break; + case "doc": + contentType = "application/msword"; + break; + case "docx": + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; + break; + case "xls": + contentType = "application/vnd.ms-excel"; + break; + case "xlsx": + contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + break; + case "ppt": + contentType = "application/vnd.ms-powerpoint"; + break; + case "pptx": + contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; + break; + case "txt": + contentType = "text/plain"; + break; + case "apk": + contentType = "application/vnd.android.package-archive"; + break; + default: + contentType = "application/octet-stream"; + } + return contentType; + } + }