ソースを参照

附件

master
lip 2年前
コミット
b003bdfa55
7個のファイルの変更52行の追加45行の削除
  1. +6
    -0
      smtweb-framework/bpm/pom.xml
  2. +29
    -31
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/controller/AttachController.java
  3. +1
    -1
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachHelper.java
  4. +6
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/spring/file/attach/AttachUtil.java
  5. +8
    -8
      smtweb-framework/bpm/src/main/resources/config/application.yaml
  6. +1
    -1
      smtweb-framework/core/pom.xml
  7. +1
    -1
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java

+ 6
- 0
smtweb-framework/bpm/pom.xml ファイルの表示

@@ -161,6 +161,12 @@
<artifactId>httpclient</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>cc.smtweb</groupId>
<artifactId>core</artifactId>
<version>3.1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<build>


+ 29
- 31
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<AttachInfo> 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 {
}


}
//图片附件显示路径
@GetMapping(value = "/loadAttachBean")
public R loadAttachBean(@RequestParam(value = "attachIds") String attachIds) throws Exception {
List<AttachInfo> beans = dbEngine.queryWhere(AttachInfo.class, "attach_id in ("+attachIds+")");
return R.success(beans);
}
}

+ 1
- 1
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);


+ 6
- 3
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);
}
}

+ 8
- 8
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


+ 1
- 1
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">
<groupId>cc.smtweb</groupId>
<artifactId>sw-framework-core</artifactId>
<artifactId>core</artifactId>
<version>3.1.0-SNAPSHOT</version>

<parent>


+ 1
- 1
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/db/dao/AbstractEntityDao.java ファイルの表示

@@ -309,7 +309,7 @@ public abstract class AbstractEntityDao<T> {
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)};
}


読み込み中…
キャンセル
保存