From b003bdfa558b901d5de79010b6781e36e2808828 Mon Sep 17 00:00:00 2001 From: lip Date: Fri, 5 Aug 2022 17:14:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smtweb-framework/bpm/pom.xml | 6 +++ .../bpm/spring/controller/AttachController.java | 60 +++++++++++----------- .../bpm/spring/file/attach/AttachHelper.java | 2 +- .../system/bpm/spring/file/attach/AttachUtil.java | 9 ++-- .../bpm/src/main/resources/config/application.yaml | 16 +++--- smtweb-framework/core/pom.xml | 2 +- .../framework/core/db/dao/AbstractEntityDao.java | 2 +- 7 files changed, 52 insertions(+), 45 deletions(-) diff --git a/smtweb-framework/bpm/pom.xml b/smtweb-framework/bpm/pom.xml index 85d8450..1f9e93c 100644 --- a/smtweb-framework/bpm/pom.xml +++ b/smtweb-framework/bpm/pom.xml @@ -161,6 +161,12 @@ httpclient 4.5.7 + + cc.smtweb + core + 3.1.0-SNAPSHOT + compile + diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java index be43c7c..7acb3eb 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java @@ -18,6 +18,7 @@ import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -36,6 +37,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; /** @@ -275,19 +277,18 @@ public class AttachController { //保存处理附件 private void localSaveAttach(final AttachInfo attach, final File upload) throws Exception { try { - //一般附件,上传到服务器,并记录附件 - //传到ftp服务器上 - attachUtil.saveAttach(attach, upload.getPath(), false); - //写入数据库 - dbEngine.insertEntity(attach); -// String sql="insert into "+AttachInfo.ENTITY_NAME+" (attach_id,attach_name,attach_suffix,attach_owner_id,attach_path,attach_type,attach_size,attach_is_temp,attach_party_id,attach_time,attach_user_id,attach_count,attach_ref_id)" + //一般附件,上传到服务器,并记录附件 + //传到ftp服务器上 + attachUtil.saveAttach(attach, upload.getPath(), false); + //写入数据库 + dbEngine.insertEntity(attach); } finally { UtilFile.delFile(upload.getAbsolutePath()); } } - //将附件上传到ftp服务器上 + //附件下载 @RequestMapping(value = "/download", method = {RequestMethod.GET, RequestMethod.POST}) public R down(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "attachId", required = false) Long attachId) throws Exception { AttachInfo attach = dbEngine.queryEntity(AttachInfo.class,attachId); @@ -311,29 +312,22 @@ public class AttachController { } //图片附件显示路径 - @RequestMapping(value = "/showImg", method = {RequestMethod.GET, RequestMethod.POST}) - public R showImg(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "attachId", required = false) Long attachId) throws Exception { + @GetMapping(value = "/showImg") + public R showImg(HttpServletResponse response, @RequestParam(value = "attachId", required = false) Long attachId) throws Exception { AttachInfo attach = dbEngine.queryEntity(AttachInfo.class,attachId); if (null == attach) { return R.error("附件不存在"); } - final String remoteFileName = attach.getName(); - final String fileName = attach.getName(); - final String remotePath = attach.getPath(); - try { - attachUtil.downloadAttach(remotePath, remoteFileName, fileName, response); - } catch (Exception e) { - logger.error("附件下载失败",e); - R.error("附件下载失败"); - } +// attachUtil.showImg(attach.getPath(),attach.getName(),response); + attachUtil.downloadAttach(attach.getPath(),attach.getName(),attach.getName(),response); return null; } //图片附件显示路径 @RequestMapping(value = "/showImgThumb", method = {RequestMethod.GET, RequestMethod.POST}) - public R showImgThumb(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "attachId", required = false) Long attachId, - @RequestParam(value = "width", required = false,defaultValue = "100") String width, - @RequestParam(value = "heigh", required = false,defaultValue = "100") String heigh) throws Exception { + public R showImgThumb(HttpServletResponse response, @RequestParam(value = "attachId", required = false) Long attachId, + @RequestParam(value = "width", required = false,defaultValue = "200") String width, + @RequestParam(value = "height", required = false,defaultValue = "120") String height) throws Exception { AttachInfo attach = dbEngine.queryEntity(AttachInfo.class,attachId); if (null == attach) { return R.error("附件不存在"); @@ -346,7 +340,7 @@ public class AttachController { String lfd = tempPath + "/thumb_" + attach.getId() + attach.getSuffix(); attachUtil.downloadAttach(remotePath, remoteFileName, tempPath); int w=Integer.valueOf(width); - int h=Integer.valueOf(heigh); + int h=Integer.valueOf(height); if (w <= 0) w = 100; if (h <= 0) h = 100; getImgThumb(lfo, lfd, w, h); @@ -396,18 +390,16 @@ public class AttachController { } //删除附件 - @PostMapping({"/delete"}) - public R del(HttpServletRequest request, @RequestParam(value = "attachId", required = false) Long attachId) throws Exception { + @GetMapping({"/delete"}) + public R del(@RequestParam(value = "attachIds") String attachIds) { try { - AttachInfo attach = dbEngine.queryEntity(AttachInfo.class,attachId); - if (null == attach) { - return R.error("附件不存在"); - } - attachHelper.deleteOneAttach(attach); + List attaches = dbEngine.queryWhere(AttachInfo.class, "attach_id in (" + attachIds + ")"); + Assert.isTrue(attaches != null && !attaches.isEmpty(), "附件不存在"); + attaches.forEach(a -> attachHelper.deleteOneAttach(a)); return R.success("附件删除成功"); } catch (Exception e) { logger.error("删除附件失败", e); - return R.error("删除附件失败"); + return R.error(e.getMessage()); } } @@ -424,4 +416,10 @@ public class AttachController { } -} \ No newline at end of file + //图片附件显示路径 + @GetMapping(value = "/loadAttachBean") + public R loadAttachBean(@RequestParam(value = "attachIds") String attachIds) throws Exception { + List beans = dbEngine.queryWhere(AttachInfo.class, "attach_id in ("+attachIds+")"); + return R.success(beans); + } +} diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java index 926c8ce..387cb9d 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java @@ -55,7 +55,7 @@ public final class AttachHelper { } //删除ftp服务器的文件 - public boolean deleteOneAttach(AttachInfo bean) throws Exception { + public boolean deleteOneAttach(AttachInfo bean) { boolean deleteSuccess = deleteAttachInFtpServer(bean.getPath(), bean.getName()); if (deleteSuccess) { dbEngine.deleteEntity(bean); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java index b722dd0..6ae570f 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java @@ -59,6 +59,7 @@ public final class AttachUtil { folder.setFolderAttachPath(attach.getPath()); folder.setFolderPeriod(period); folder.setFolderMaxSeq(1); + folder.setFolderFileCount(0L); entity.setPath(attach.getPath()); entity.setPeriod(period); @@ -76,17 +77,15 @@ public final class AttachUtil { entity.setId(folder.getFolderId()); //检查并确定远程目录 if (isNew) { -// dbEngine.update("insert into "+AttachFolderEntity.ENTITY_NAME+" (folder_id,attach_path,folder_period,max_seq,file_count)values(?,?,?,?,?)",entity.getFolderId(),entity.getAttachPath(),entity.getFolderPeriod(),entity.getMaxSeq(),entity.getFileCount()); dbEngine.insertEntity(entity, "folder_id,folder_path,folder_period,folder_max_seq,folder_file_count"); } else { -// dbEngine.update("update "+AttachFolderEntity.ENTITY_NAME+" set max_seq=?,file_count=? where folder_id=?",new Object[]{entity.getMaxSeq(),entity.getFileCount(),entity.getFolderId()}); dbEngine.updateEntity(entity, "folder_max_seq,folder_file_count"); } attach.setPath(attach.getPath() + "/" + period + "/" + folder.getFolderMaxSeq()); attachFolderEntityBuffer.putOneData(folder); } - public void saveAttach(final AttachInfo attach, String localAttach, boolean isDelLocal) throws Exception { + public void saveAttach(final AttachInfo attach, String localAttach, boolean isDelLocal) throws Exception { synchronized (attach.getPath()) { checkAttachFolder(attach); saveAttach(attach.getName(), attach.getPath(), localAttach, false); @@ -132,4 +131,8 @@ public final class AttachUtil { public Path getAttachPath(String remotePath, String remoteName) throws Exception { return worker.getAttachPath(remotePath, remoteName); } + + public void showImg(String remotePath, String remoteName, HttpServletResponse response) throws Exception { + worker.showAttachImg(remotePath, remoteName, response); + } } diff --git a/smtweb-framework/bpm/src/main/resources/config/application.yaml b/smtweb-framework/bpm/src/main/resources/config/application.yaml index 5c15030..00e13f7 100644 --- a/smtweb-framework/bpm/src/main/resources/config/application.yaml +++ b/smtweb-framework/bpm/src/main/resources/config/application.yaml @@ -6,13 +6,13 @@ smtweb: #访问路径,需/结尾 attach-http-path: 'http://bjjt.jujiatech.cn/files/' #此配置原则上可以和local-path一致,可本机路径可ftp附件路径,需/结尾 - attach-path: /jjkj/attach/ + attach-path: /jjkj/attach/files/persistent/ #临时文件路径,需/结尾 - attach-temp-path: /jujia/tomcat_api/webapps/files/tempFile/ + attach-temp-path: /jjkj/attach/files/temp/ #附件上传方式 sftp/ftp/local - attach-type: sftp + attach-type: local #ftp IP地址 - attach-ftp-ip: 172.26.60.191 + attach-ftp-ip: 127.0.0.1 #ftp 端口 attach-ftp-port: 22 #ftp 用户名 @@ -21,10 +21,7 @@ smtweb: attach-ftp-pwd: Bjjt@2021 bpm: debug: true -# 有.idea或pom.xml文件的目录 - code-java-path: 'd:/work/smtweb2/smtweb-framework' -# 读取模式 1-读取pom.xml,要求module名同目录 2-读取.idea/modules.xml - mode: 2 + code-java-path: 'D:\Git\dfpDepository\smtweb2\smtweb-framework' db: type: mysql default: @@ -49,6 +46,9 @@ spring: url: jdbc:mysql://139.9.38.43:6032/smt?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false username: root password: Ncmz@2022_jjkj +# url: jdbc:mysql://127.0.0.1:3306/smt_asp?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false +# username: root +# password: 123456 servlet: multipart: max-file-size: 104857600000 diff --git a/smtweb-framework/core/pom.xml b/smtweb-framework/core/pom.xml index f277f76..3394cc6 100644 --- a/smtweb-framework/core/pom.xml +++ b/smtweb-framework/core/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> cc.smtweb - sw-framework-core + core 3.1.0-SNAPSHOT diff --git a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java index 79f15cb..1833a1b 100644 --- a/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java +++ b/smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java @@ -309,7 +309,7 @@ public abstract class AbstractEntityDao { protected Object[] handleDelete(T obj, StringBuilder sql) { EntityColumn idColumn = findIdColumn(); - sql.append("DELETE FROM ").append(modelTable.getSchemaTableName()).append(" WHERE ").append(idColumn.getField()).append("=?"); + sql.append("DELETE FROM ").append(modelTable.getSchemaTableName()).append(" WHERE ").append(idColumn.getField().getName()).append("=?"); return new Object[]{idColumn.readValue(obj)}; }