施罗德下载文件接口修改
parent
501bddf2f1
commit
fdb7bac7f6
|
@ -850,7 +850,7 @@ public class Util extends weaver.general.Util {
|
|||
} else {
|
||||
try {
|
||||
System.out.println("已存在文件:" + packageName + "." + className + ".java");
|
||||
System.out.print("你想如何处理该文件:替换[r/R] 重命名[w/W] 跳过[n/N] ? ");
|
||||
System.out.print("你想如何处理该文件:替换[r/ApiResult] 重命名[w/W] 跳过[n/N] ? ");
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
String next = scanner.next();
|
||||
System.out.println(next);
|
||||
|
|
|
@ -31,7 +31,7 @@ public class CusCreateWorkFlowController {
|
|||
@Path("cusCreateWorkFlow")
|
||||
@POST
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String getOrgChartTree(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
public String createWorkFlow(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
User logInUser = HrmUserVarify.getUser(request, response);
|
||||
if(logInUser == null){
|
||||
return ApiResult.error(403,"请先登录!");
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
package com.api.xuanran.wang.schroeder.download_file.controller;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import com.api.xuanran.wang.schroeder.download_file.service.DownLoadFileService;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import weaver.file.ImageFileManager;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.StreamingOutput;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>
|
||||
* 施罗德下载文件接口/wxr/schroeder/downLoadFile?docId=1212
|
||||
* </h1>
|
||||
*
|
||||
* @Author xuanran.wang
|
||||
* @Date 2022/12/7 10:18
|
||||
*/
|
||||
@Path("/wxr/schroeder/")
|
||||
public class DownLoadFileController {
|
||||
|
||||
private final DownLoadFileService downLoadFileService = new DownLoadFileService();
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
@Path("downLoadFile")
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
public Response downLoadFile(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
String docId = request.getParameter("docId");
|
||||
try {
|
||||
Map<String, Object> fileInfo = downLoadFileService.getFileInfo(docId);
|
||||
String fileName = Util.null2String(fileInfo.get("fileName"));
|
||||
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfo.get("imageFileId"),""), -1);
|
||||
InputStream is = ImageFileManager.getInputStreamById(imageFileId);
|
||||
byte[] bytes = IOUtils.toByteArray(is);
|
||||
StreamingOutput output = outputStream ->{
|
||||
outputStream.write(bytes);
|
||||
outputStream.close();
|
||||
};
|
||||
Response.ResponseBuilder header = Response.ok(output, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
return header.build();
|
||||
}catch (Exception e){
|
||||
String error = Util.logStr("docId:{}, 下载文件异常:{}", docId, e.getMessage());
|
||||
logger.error(error);
|
||||
return Response.ok(error, MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.api.xuanran.wang.schroeder.download_file.mapper;
|
||||
|
||||
import aiyh.utils.annotation.recordset.ParamMapper;
|
||||
import aiyh.utils.annotation.recordset.Select;
|
||||
import aiyh.utils.annotation.recordset.SqlMapper;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>文件下载mapper</h1>
|
||||
*
|
||||
* @Author xuanran.wang
|
||||
* @Date 2022/12/7 10:58
|
||||
*/
|
||||
@SqlMapper
|
||||
public interface DownLoadFileMapper {
|
||||
|
||||
/**
|
||||
* <h1>根据docId查询附件信息</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2022/12/7 11:01
|
||||
* @param docId docId
|
||||
* @return 文件imageField以及文件名
|
||||
**/
|
||||
@Select("select t3.imagefileid imageFileId,t3.imagefilename fileName,t3.filerealpath filePath " +
|
||||
"from DocDetail t1 " +
|
||||
"left join DocImageFile t2 " +
|
||||
"on t2.docid = t1.id " +
|
||||
"left join ImageFile t3 " +
|
||||
"on t3.imagefileid = t2.imagefileid " +
|
||||
"where t1.id = #{docId}")
|
||||
Map<String, Object> selectDocInfoByDocId(@ParamMapper("docId") String docId);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.api.xuanran.wang.schroeder.download_file.service;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import aiyh.utils.excention.CustomerException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.api.xuanran.wang.schroeder.download_file.mapper.DownLoadFileMapper;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import weaver.conn.RecordSet;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1>下载文件业务方法</h1>
|
||||
*
|
||||
* @Author xuanran.wang
|
||||
* @Date 2022/12/7 10:51
|
||||
*/
|
||||
public class DownLoadFileService {
|
||||
/**
|
||||
* <h2>文件记录表</h2>
|
||||
**/
|
||||
private static final String DOC_LOG_TABLE_NAME = "doc_log";
|
||||
/**
|
||||
* <h2>查询文件记录sql</h2>
|
||||
**/
|
||||
private static final String SELECT_DOC_LOG_SQL = "select 1 from " + DOC_LOG_TABLE_NAME + " where docId = ? and enable = 0";
|
||||
private final DownLoadFileMapper downLoadFileMapper = Util.getMapper(DownLoadFileMapper.class);
|
||||
|
||||
/**
|
||||
* <h1>根据docId获取文件信息</h1>
|
||||
* @author xuanran.wang
|
||||
* @dateTime 2022/12/7 11:24
|
||||
* @param docId docId
|
||||
**/
|
||||
public Map<String, Object> getFileInfo(String docId) {
|
||||
if(StringUtils.isBlank(docId)) {
|
||||
throw new CustomerException(Util.logStr("下载文件失败, 请求路径中不包含指定的docId!当前请求docId:{}", docId));
|
||||
}
|
||||
RecordSet rs = new RecordSet();
|
||||
if (!rs.executeQuery(SELECT_DOC_LOG_SQL, docId) || !rs.next()) {
|
||||
throw new CustomerException("下载文件失败, 请确认文件记录表中是否存在docId = [ " + docId + " ]的文件!");
|
||||
}
|
||||
Map<String, Object> fileInfoMap = downLoadFileMapper.selectDocInfoByDocId(docId);
|
||||
if(MapUtils.isEmpty(fileInfoMap)){
|
||||
throw new CustomerException("执行查询文件信息sql失败!");
|
||||
}
|
||||
String fileName = Util.null2DefaultStr(fileInfoMap.get("fileName"),"");
|
||||
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfoMap.get("imageFileId"),""), -1);
|
||||
if(StringUtils.isBlank(fileName) ||imageFileId < 0){
|
||||
throw new CustomerException(Util.logStr("文件信息部分字段查询为空!当前查询结果map:[{}]", JSONObject.toJSONString(fileInfoMap)));
|
||||
}
|
||||
return fileInfoMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -3,6 +3,7 @@ package weaver.xuanran.wang.common.util;
|
|||
import aiyh.utils.Util;
|
||||
import aiyh.utils.excention.CustomerException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaverboot.tools.logTools.LogTools;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
@ -15,8 +16,11 @@ import weaver.xuanran.wang.common.annocation.CusDateFormat;
|
|||
import weaver.xuanran.wang.common.annocation.ParamNotNull;
|
||||
import weaver.xuanran.wang.common.mapper.CommonMapper;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
@ -37,7 +41,7 @@ public class CommonUtil {
|
|||
/**
|
||||
* <h2>日志对象</h2>
|
||||
**/
|
||||
private static final Logger logger = Util.getLogger(CommonUtil.class.getName());
|
||||
private static final Logger logger = Util.getLogger();
|
||||
/**
|
||||
* <h2>sql用in的时候分割集合大小</h2>
|
||||
**/
|
||||
|
@ -55,6 +59,9 @@ public class CommonUtil {
|
|||
**/
|
||||
private static final CommonMapper commonMapper = Util.getMapper(CommonMapper.class);
|
||||
|
||||
public CommonUtil(){
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>将文件解压至指定文件夹中</h1>
|
||||
* @author xuanran.wang
|
||||
|
|
|
@ -30,30 +30,25 @@ public class PushSealTaskSealValue implements CusInterfaceGetValue {
|
|||
// 接口字段
|
||||
String sealSnField = pathParam.get("sealSnField");
|
||||
String sealNumField = pathParam.get("sealNumField");
|
||||
// 表单字段
|
||||
String workFlowSealNumField = pathParam.get("workFlowSealNumField");
|
||||
String workFlowSealSnField = pathParam.get("workFlowSealSnField");
|
||||
// 自定义sql业务印章类型
|
||||
String sealSnCusSql = pathParam.get("sealSnCusSql");
|
||||
// 使用次数
|
||||
String sealNumCusSql = pathParam.get("sealNumCusSql");
|
||||
// 非空校验
|
||||
if(checkBlank(sealSnField, sealNumField, sealSnCusSql, sealNumCusSql, workFlowSealNumField, workFlowSealSnField)){
|
||||
if(checkBlank(sealSnField, sealNumField, sealSnCusSql, sealNumCusSql)){
|
||||
throw new CustomerException(Util.logStr("自定义类路径中必要参数为空,请检查!当前pathParam : {}", JSONObject.toJSONString(pathParam)));
|
||||
}
|
||||
// 表单印章使用类型值
|
||||
String sealSnVal = Util.null2String(String.valueOf(detailMap.get(sealSnField)),"");
|
||||
logger.info(Util.logStr("当前值 : {}", currentValue));
|
||||
// 如果为空返回空集合
|
||||
if(StringUtils.isBlank(sealSnVal)){
|
||||
if(StringUtils.isBlank(currentValue)){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
ArrayList<Map<String, Object>> list = new ArrayList<>();
|
||||
logger.info(Util.logStr("当前值 : {}", currentValue));
|
||||
int detailId = -1;
|
||||
if(MapUtils.isNotEmpty(detailMap)){
|
||||
detailId = Util.getIntValue(String.valueOf(detailMap.get("id")), -1);
|
||||
}
|
||||
for (String val : sealSnVal.split(",")) {
|
||||
for (String val : currentValue.split(",")) {
|
||||
// 印章类型转换执行自定义sql
|
||||
String inSealVal = Util.null2DefaultStr(toolUtil.getValueByChangeRule(sealSnCusSql, val, String.valueOf(mainMap.get("requestid")), detailId),"");
|
||||
String inSealNumVal = Util.null2DefaultStr(toolUtil.getValueByChangeRule(sealNumCusSql, val, String.valueOf(mainMap.get("requestid")), detailId),"");
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package xuanran.wang.schroeder.download_file;
|
||||
|
||||
import aiyh.utils.Util;
|
||||
import basetest.BaseTest;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.api.xuanran.wang.schroeder.download_file.mapper.DownLoadFileMapper;
|
||||
import org.junit.Test;
|
||||
import weaver.file.ImageFileManager;
|
||||
import weaver.xuanran.wang.common.util.CommonUtil;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <h1></h1>
|
||||
*
|
||||
* @Author xuanran.wang
|
||||
* @Date 2022/12/7 11:58
|
||||
*/
|
||||
public class DownLoadFileTest extends BaseTest {
|
||||
private final DownLoadFileMapper downLoadFileMapper = Util.getMapper(DownLoadFileMapper.class);
|
||||
|
||||
@Test
|
||||
public void testSelectFileInfo() throws IOException {
|
||||
Map<String, Object> fileInfo = downLoadFileMapper.selectDocInfoByDocId("95");
|
||||
log.info("map " + fileInfo);
|
||||
String fileName = Util.null2String(fileInfo.get("fileName"));
|
||||
int imageFileId = Util.getIntValue(Util.null2DefaultStr(fileInfo.get("imageFileId"),""), -1);
|
||||
log.info("imageFileId " + imageFileId);
|
||||
InputStream is = ImageFileManager.getInputStreamById(imageFileId);
|
||||
log.info(null == is);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testImageFileInputSteam(){
|
||||
InputStream inputStreamById = ImageFileManager.getInputStreamById(705);
|
||||
System.out.println("=============");
|
||||
}
|
||||
}
|
2
常用信息.md
2
常用信息.md
|
@ -143,7 +143,7 @@ myComp.setState({test1: test2});
|
|||
> 维护人员: youHong.ai
|
||||
|
||||
```shell
|
||||
mysqldump -uroot -p'passowrd' --single-transaction -R -E --databases ecology_dev> /tmp/ecology_dev_back.sql
|
||||
mysqldump -uroot -p'passowrd' --single-transaction -ApiResult -E --databases ecology_dev> /tmp/ecology_dev_back.sql
|
||||
```
|
||||
|
||||
**mysql常用视图**
|
||||
|
|
Loading…
Reference in New Issue