新增部门查询和人员查询资源接口机,修复文件下载问题

This commit is contained in:
wenc000 2019-08-20 22:48:41 +08:00
parent 158d293dca
commit fe74fb7d72
4 changed files with 99 additions and 3 deletions

View File

@ -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";
/**
* 组织部门用户列表
*/

View File

@ -23,8 +23,19 @@ public interface IDepartmentService {
*
* @param params
* @return
* @throws AccessTokenException
* @throws AccessTokenException
* @throws SearchException
*/
JSONArray listDepartments(Map<String, Object> params) throws AccessTokenException, AccessTokenException, SearchException;
/**
* 组织部门列表
*
* @param parentId
* @return
* @throws AccessTokenException
* @throws SearchException
*/
JSONArray listDepartmentsAllByParentId(String parentId) throws AccessTokenException, SearchException;
}

View File

@ -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);
}
}

View File

@ -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;
}
}