From fdb7bac7f6bc4f92b204d571a5a49f8bbf8318d4 Mon Sep 17 00:00:00 2001 From: wangxuanran <3055088966@qq.com> Date: Wed, 7 Dec 2022 15:08:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=BD=E7=BD=97=E5=BE=B7=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/Util.java | 2 +- .../CusCreateWorkFlowController.java | 2 +- .../controller/DownLoadFileController.java | 61 +++++++++++++++++++ .../mapper/DownLoadFileMapper.java | 33 ++++++++++ .../service/DownLoadFileService.java | 56 +++++++++++++++++ .../xuanran/wang/common/util/CommonUtil.java | 9 ++- .../PushSealTaskSealValue.java | 13 ++-- .../download_file/DownLoadFileTest.java | 45 ++++++++++++++ 常用信息.md | 2 +- 9 files changed, 210 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/api/xuanran/wang/schroeder/download_file/controller/DownLoadFileController.java create mode 100644 src/main/java/com/api/xuanran/wang/schroeder/download_file/mapper/DownLoadFileMapper.java create mode 100644 src/main/java/com/api/xuanran/wang/schroeder/download_file/service/DownLoadFileService.java create mode 100644 src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index e4891bc..1cf328d 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -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); diff --git a/src/main/java/com/api/xuanran/wang/saic_travel/model_create_workflow/controller/CusCreateWorkFlowController.java b/src/main/java/com/api/xuanran/wang/saic_travel/model_create_workflow/controller/CusCreateWorkFlowController.java index 30a73c8..3abb495 100644 --- a/src/main/java/com/api/xuanran/wang/saic_travel/model_create_workflow/controller/CusCreateWorkFlowController.java +++ b/src/main/java/com/api/xuanran/wang/saic_travel/model_create_workflow/controller/CusCreateWorkFlowController.java @@ -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,"请先登录!"); diff --git a/src/main/java/com/api/xuanran/wang/schroeder/download_file/controller/DownLoadFileController.java b/src/main/java/com/api/xuanran/wang/schroeder/download_file/controller/DownLoadFileController.java new file mode 100644 index 0000000..1d09cfc --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/schroeder/download_file/controller/DownLoadFileController.java @@ -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; + +/** + *

+ * 施罗德下载文件接口/wxr/schroeder/downLoadFile?docId=1212 + *

+ * + * @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 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(); + } + } + +} diff --git a/src/main/java/com/api/xuanran/wang/schroeder/download_file/mapper/DownLoadFileMapper.java b/src/main/java/com/api/xuanran/wang/schroeder/download_file/mapper/DownLoadFileMapper.java new file mode 100644 index 0000000..6223c91 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/schroeder/download_file/mapper/DownLoadFileMapper.java @@ -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; + +/** + *

文件下载mapper

+ * + * @Author xuanran.wang + * @Date 2022/12/7 10:58 + */ +@SqlMapper +public interface DownLoadFileMapper { + + /** + *

根据docId查询附件信息

+ * @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 selectDocInfoByDocId(@ParamMapper("docId") String docId); +} diff --git a/src/main/java/com/api/xuanran/wang/schroeder/download_file/service/DownLoadFileService.java b/src/main/java/com/api/xuanran/wang/schroeder/download_file/service/DownLoadFileService.java new file mode 100644 index 0000000..b2dd097 --- /dev/null +++ b/src/main/java/com/api/xuanran/wang/schroeder/download_file/service/DownLoadFileService.java @@ -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; + +/** + *

下载文件业务方法

+ * + * @Author xuanran.wang + * @Date 2022/12/7 10:51 + */ +public class DownLoadFileService { + /** + *

文件记录表

+ **/ + private static final String DOC_LOG_TABLE_NAME = "doc_log"; + /** + *

查询文件记录sql

+ **/ + 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); + + /** + *

根据docId获取文件信息

+ * @author xuanran.wang + * @dateTime 2022/12/7 11:24 + * @param docId docId + **/ + public Map 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 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; + } + + +} diff --git a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java index dea7401..f1c9c82 100644 --- a/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java +++ b/src/main/java/weaver/xuanran/wang/common/util/CommonUtil.java @@ -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 { /** *

日志对象

**/ - private static final Logger logger = Util.getLogger(CommonUtil.class.getName()); + private static final Logger logger = Util.getLogger(); /** *

sql用in的时候分割集合大小

**/ @@ -55,6 +59,9 @@ public class CommonUtil { **/ private static final CommonMapper commonMapper = Util.getMapper(CommonMapper.class); + public CommonUtil(){ + } + /** *

将文件解压至指定文件夹中

* @author xuanran.wang diff --git a/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java b/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java index 671e490..1ccb5d0 100644 --- a/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java +++ b/src/main/java/weaver/xuanran/wang/schroeder/cus_field_value/PushSealTaskSealValue.java @@ -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> 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),""); diff --git a/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java b/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java new file mode 100644 index 0000000..70fe195 --- /dev/null +++ b/src/test/java/xuanran/wang/schroeder/download_file/DownLoadFileTest.java @@ -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; + +/** + *

+ * + * @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 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("============="); + } +} diff --git a/常用信息.md b/常用信息.md index d34e1dd..e04590c 100644 --- a/常用信息.md +++ b/常用信息.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常用视图**