附件上传

pull/14/head
dearlin 2023-12-18 16:14:27 +08:00
parent b4c3061e84
commit 062f77fa00
8 changed files with 203 additions and 58 deletions

View File

@ -64,8 +64,7 @@ public class AppEightWorkCfdController extends BaseController {
public Object list(Page page) throws Exception{ public Object list(Page page) throws Exception{
Map<String,Object> map = new HashMap<String,Object>(); Map<String,Object> map = new HashMap<String,Object>();
String errInfo = "success"; String errInfo = "success";
PageData pd = new PageData(); PageData pd = this.getPageData();
pd = this.getPageData();
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件 String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
if(Tools.notEmpty(KEYWORDS))pd.put("KEYWORDS", KEYWORDS.trim()); if(Tools.notEmpty(KEYWORDS))pd.put("KEYWORDS", KEYWORDS.trim());
// pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); // pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());

View File

@ -1,5 +1,6 @@
package com.zcloud.controller.filemanager; package com.zcloud.controller.filemanager;
import com.zcloud.aspect.DockAnnotation;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import java.io.Console; import java.io.Console;
@ -34,18 +35,18 @@ import com.zcloud.util.Tools;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
/** /**
* *
* zCloud * zCloud
* *
*/ */
@Controller @Controller
@RequestMapping("/mfolder") @RequestMapping("/mfolder")
public class MfolderController extends BaseController { public class MfolderController extends BaseController {
@Autowired @Autowired
private MfolderService mfolderService; private MfolderService mfolderService;
/** /**
* @param * @param
* @throws Exception * @throws Exception
@ -53,6 +54,7 @@ public class MfolderController extends BaseController {
@RequestMapping(value="/add") @RequestMapping(value="/add")
@RequiresPermissions("mfolder:add") @RequiresPermissions("mfolder:add")
@ResponseBody @ResponseBody
@DockAnnotation(isAdd = true)
public Object add() throws Exception{ public Object add() throws Exception{
Map<String,Object> map = new HashMap<String,Object>(); Map<String,Object> map = new HashMap<String,Object>();
String errInfo = "success"; String errInfo = "success";
@ -64,13 +66,14 @@ public class MfolderController extends BaseController {
pd.put("UNAME", Jurisdiction.getName()); //上传者 pd.put("UNAME", Jurisdiction.getName()); //上传者
pd.put("MASTER", Jurisdiction.getUsername()); //所属人 pd.put("MASTER", Jurisdiction.getUsername()); //所属人
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业 pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业
pd.put("FILESIZE", ""); pd.put("FILESIZE", "");
pd.put("SHARE", "no"); pd.put("SHARE", "no");
mfolderService.save(pd); mfolderService.save(pd);
map.put("result", errInfo); map.put("result", errInfo);
map.put("pd", pd);
return map; return map;
} }
/** /**
* @param * @param
* @throws Exception * @throws Exception
@ -120,11 +123,11 @@ public class MfolderController extends BaseController {
map.put("result", errInfo); //返回结果 map.put("result", errInfo); //返回结果
return map; return map;
} }
/** /**
* *
* *
* @param * @param
* @throws Exception * @throws Exception
*/ */
@ -186,7 +189,7 @@ public class MfolderController extends BaseController {
map.put("result", errInfo); // 返回结果 map.put("result", errInfo); // 返回结果
return map; return map;
} }
/** /**
* @param * @param
* @throws Exception * @throws Exception
@ -212,7 +215,7 @@ public class MfolderController extends BaseController {
// String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile; //文件上传路径 // String filePath = PathUtil.getProjectpath() + Const.FILEPATHFILE + ffile; //文件上传路径
// fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //执行上传 // fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //执行上传
fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); fileName = this.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
Smb.sshSftp(file, fileName,Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile); Smb.sshSftp(file, fileName,Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile);
pd.put("FILEPATH", Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName); //文件路径 pd.put("FILEPATH", Const.FILEPATHFILE + Jurisdiction.getCORPINFO_ID() + "/" + ffile + "/" + fileName); //文件路径
String realName = file.getOriginalFilename(); String realName = file.getOriginalFilename();
String[] fileFullNames = realName.split("\\.");//上传文件全名 String[] fileFullNames = realName.split("\\.");//上传文件全名
@ -235,7 +238,7 @@ public class MfolderController extends BaseController {
map.put("result", errInfo); //返回结果 map.put("result", errInfo); //返回结果
return map; return map;
} }
/** /**
* @param out * @param out
* @throws Exception * @throws Exception
@ -263,7 +266,7 @@ public class MfolderController extends BaseController {
map.put("result", errInfo); //返回结果 map.put("result", errInfo); //返回结果
return map; return map;
} }
/** /**
* @param * @param
* @throws Exception * @throws Exception
@ -280,7 +283,7 @@ public class MfolderController extends BaseController {
map.put("result", errInfo); map.put("result", errInfo);
return map; return map;
} }
/** /**
* @param page * @param page
* @throws Exception * @throws Exception
@ -300,7 +303,7 @@ public class MfolderController extends BaseController {
MFOLDER_ID = null == pd.get("MFOLDER_ID")?"":pd.get("MFOLDER_ID").toString(); MFOLDER_ID = null == pd.get("MFOLDER_ID")?"":pd.get("MFOLDER_ID").toString();
pd.put("MFOLDER_ID", MFOLDER_ID); //当作上级ID pd.put("MFOLDER_ID", MFOLDER_ID); //当作上级ID
} }
// if(Tools.notEmpty(SHARE) && "yes".equals(SHARE)) { // if(Tools.notEmpty(SHARE) && "yes".equals(SHARE)) {
// pd.put("SHARE", "yes"); // pd.put("SHARE", "yes");
// }else { // }else {
@ -351,7 +354,7 @@ public class MfolderController extends BaseController {
fileType = "video"; //视频文件类型 fileType = "video"; //视频文件类型
} }
varList.get(i).put("extension_name", extension_name); //文件拓展名 varList.get(i).put("extension_name", extension_name); //文件拓展名
varList.get(i).put("fileType", fileType); //用于文件图标 varList.get(i).put("fileType", fileType); //用于文件图标
} }
map.put("varList", varList); map.put("varList", varList);
map.put("page", page); map.put("page", page);
@ -385,9 +388,9 @@ public class MfolderController extends BaseController {
map.put("result", errInfo); map.put("result", errInfo);
return map; return map;
} }
/**txt,java,php, /**txt,java,php,
* @return * @return
*/ */
@RequestMapping(value="/viewTxt") @RequestMapping(value="/viewTxt")
@ResponseBody @ResponseBody
@ -403,7 +406,7 @@ public class MfolderController extends BaseController {
map.put("result", errInfo); map.put("result", errInfo);
return map; return map;
} }
/** /**
* @param * @param
* @throws Exception * @throws Exception
@ -414,7 +417,7 @@ public class MfolderController extends BaseController {
public Object deleteAll() throws Exception{ public Object deleteAll() throws Exception{
Map<String,Object> map = new HashMap<String,Object>(); Map<String,Object> map = new HashMap<String,Object>();
String errInfo = "success"; String errInfo = "success";
PageData pd = new PageData(); PageData pd = new PageData();
pd = this.getPageData(); pd = this.getPageData();
String DATA_IDS = pd.getString("DATA_IDS"); String DATA_IDS = pd.getString("DATA_IDS");
if(Tools.notEmpty(DATA_IDS)){ if(Tools.notEmpty(DATA_IDS)){
@ -428,7 +431,7 @@ public class MfolderController extends BaseController {
map.put("result", errInfo); //返回结果 map.put("result", errInfo); //返回结果
return map; return map;
} }
/** /**
* @param response * @param response
* @throws Exception * @throws Exception
@ -447,11 +450,11 @@ public class MfolderController extends BaseController {
throw new NofileException("=========要下载的文件已经没有了========="); throw new NofileException("=========要下载的文件已经没有了=========");
} }
} }
/** /**
* *
* *
* @throws Exception * @throws Exception
*/ */
public void initialize () throws Exception { public void initialize () throws Exception {
PageData pData = new PageData(); PageData pData = new PageData();
@ -469,12 +472,12 @@ public class MfolderController extends BaseController {
pd.put("UNAME", "init"); //上传者 pd.put("UNAME", "init"); //上传者
pd.put("MASTER", Jurisdiction.getUsername()); //所属人 pd.put("MASTER", Jurisdiction.getUsername()); //所属人
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业 pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业
pd.put("FILESIZE", ""); pd.put("FILESIZE", "");
pd.put("SHARE", "no"); pd.put("SHARE", "no");
mfolderService.save(pd); mfolderService.save(pd);
} }
} }
} }
/* /*
@ -483,7 +486,7 @@ public class MfolderController extends BaseController {
class NofileException extends Exception { class NofileException extends Exception {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public NofileException() { public NofileException() {
super(); super();
} }
@ -499,5 +502,5 @@ class NofileException extends Exception {
public NofileException(Throwable cause) { public NofileException(Throwable cause) {
super(cause); super(cause);
} }
} }

View File

@ -13,9 +13,7 @@ import org.springframework.stereotype.Component;
* www.zcloudchina.com * www.zcloudchina.com
*/ */
@Component @Component
@RocketMQMessageListener(consumerGroup = "${mq.group.info}", @RocketMQMessageListener(consumerGroup = "${mq.group.info}", topic = "${mq.topic.info}", selectorType = SelectorType.TAG)
topic = "${mq.topic.info}",
selectorType = SelectorType.TAG)
public class MqListener implements RocketMQListener<String> { public class MqListener implements RocketMQListener<String> {
@Override @Override

View File

@ -32,10 +32,10 @@ import com.zcloud.util.Tools;
@Controller @Controller
@RequestMapping("/photo") @RequestMapping("/photo")
public class PhotoController extends BaseController { public class PhotoController extends BaseController {
@Autowired @Autowired
private PhotoService photoService; private PhotoService photoService;
/** /**
* @param * @param
* @throws Exception * @throws Exception
@ -85,7 +85,7 @@ public class PhotoController extends BaseController {
map.put("result", errInfo); map.put("result", errInfo);
return map; return map;
} }
/** /**
* @param * @param
* @throws Exception * @throws Exception
@ -98,7 +98,7 @@ public class PhotoController extends BaseController {
PageData pd = new PageData(); PageData pd = new PageData();
pd = this.getPageData(); pd = this.getPageData();
pd.put("USERNAME", Jurisdiction.getUsername()); //用户名 pd.put("USERNAME", Jurisdiction.getUsername()); //用户名
if (null != file && !file.isEmpty()) { if (null != file && !file.isEmpty()) {
String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1).toLowerCase(); String suffixName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1).toLowerCase();
if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName) && !"mp4".equals(suffixName)) { if (!"pdf".equals(suffixName) && !"jpg".equals(suffixName) && !"jpeg".equals(suffixName) && !"png".equals(suffixName) && !"mp4".equals(suffixName)) {
@ -137,7 +137,7 @@ public class PhotoController extends BaseController {
map.put("result", errInfo); map.put("result", errInfo);
return map; return map;
} }
/**() /**()
* @param * @param
* @throws Exception * @throws Exception
@ -150,11 +150,11 @@ public class PhotoController extends BaseController {
PageData pd = new PageData(); PageData pd = new PageData();
pd = this.getPageData(); pd = this.getPageData();
String USERNAME = Jurisdiction.getUsername();//用户名 String USERNAME = Jurisdiction.getUsername();//用户名
String userphoto = "uploadFiles/photo/"+USERNAME+"_photo.jpg"; String userphoto = "/uploadFiles/photo/"+USERNAME+"_photo.jpg";
String imgData = pd.getString("PHOTODATA").replace("data:image/jpeg;base64,", ""); String imgData = pd.getString("PHOTODATA").replace("data:image/jpeg;base64,", "");
String pathimg = PathUtil.getProjectpath()+userphoto; String pathimg = PathUtil.getProjectpath()+userphoto;
ImageAnd64Binary.generateImage(imgData, pathimg); ImageAnd64Binary.generateImage(imgData, pathimg);
pd.put("USERNAME", USERNAME); pd.put("USERNAME", USERNAME);
pd.put("PHOTO0", ""); //原图 pd.put("PHOTO0", ""); //原图
pd.put("PHOTO1", userphoto); //头像1 pd.put("PHOTO1", userphoto); //头像1
pd.put("PHOTO2", userphoto); //头像2 pd.put("PHOTO2", userphoto); //头像2

View File

@ -23,15 +23,15 @@ public class Const {
public static final String SHOWCOUNT = "showCount"; //每页条数 public static final String SHOWCOUNT = "showCount"; //每页条数
public static final String basePath = "/mnt/qask/file/"; public static final String basePath = "/mnt/qask/file/";
public static final String FILEPATHFILE = "/uploadFiles/file/"; //文件上传路径 public static final String FILEPATHFILE = "/uploadFiles/czks/file/"; //文件上传路径
public static final String FILEPATHHEADPHONE = "/uploadFiles/headPhone/"; //用户头像 public static final String FILEPATHHEADPHONE = "/uploadFiles/czks/headPhone/"; //用户头像
public static final String BIFILEPATHFILE = "/uploadFiles/Bfile/"; //文件上传路径 public static final String BIFILEPATHFILE = "/uploadFiles/czks/Bfile/"; //文件上传路径
public static final String FILEPATHIMG = "/uploadFiles/imgs/"; //图片上传路径 public static final String FILEPATHIMG = "/uploadFiles/czks/imgs/"; //图片上传路径
public static final String FILEPATHDZJM = "/uploadFiles/dzjm/"; //图片上传路径 public static final String FILEPATHDZJM = "/uploadFiles/czks/dzjm/"; //图片上传路径
public static final String FILEPATHYHTP = "/uploadFiles/yhtp/"; //图片上传路径 public static final String FILEPATHYHTP = "/uploadFiles/czks/yhtp/"; //图片上传路径
public static final String FILEPATHAITP = "/uploadFiles/aitp/"; //图片上传路径 public static final String FILEPATHAITP = "/uploadFiles/czks/aitp/"; //图片上传路径
public static final String FILEPATHFXSST = "/uploadFiles/fxsst/"; //图片上传路径 风险四色图 public static final String FILEPATHFXSST = "/uploadFiles/czks/fxsst/"; //图片上传路径 风险四色图
public static final String FILEPATHSTUDYVIDEO = "/uploadFiles/studyVideo/"; //学习园地-学习视频文件 public static final String FILEPATHSTUDYVIDEO = "/uploadFiles/czks/studyVideo/"; //学习园地-学习视频文件
public static final String FILEACTIVITI = "/uploadFiles/activitiFile/"; //工作流生成XML和PNG目录 public static final String FILEACTIVITI = "/uploadFiles/activitiFile/"; //工作流生成XML和PNG目录

View File

@ -4,6 +4,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Vector; import java.util.Vector;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Configurable; import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -17,6 +18,8 @@ import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpATTRS; import com.jcraft.jsch.SftpATTRS;
import com.jcraft.jsch.SftpException; import com.jcraft.jsch.SftpException;
import javax.annotation.Resource;
@Configuration @Configuration
public class Smb { public class Smb {
@ -27,24 +30,30 @@ public class Smb {
public static String password; public static String password;
public static String basePath; public static String basePath;
@Resource
private RocketMQTemplate rocketMQTemplate;
@Value("${smb.host}") @Value("${smb.host}")
public void setHostPath(String hostProperties){ public void setHostPath(String hostProperties) {
host = hostProperties; host = hostProperties;
} }
@Value("${smb.port}") @Value("${smb.port}")
public void setPortPath(Integer portProperties){ public void setPortPath(Integer portProperties) {
port = portProperties; port = portProperties;
} }
@Value("${smb.user}") @Value("${smb.user}")
public void setUserPath(String userProperties){ public void setUserPath(String userProperties) {
user = userProperties; user = userProperties;
} }
@Value("${smb.password}") @Value("${smb.password}")
public void setPasswordPath(String passwordProperties){ public void setPasswordPath(String passwordProperties) {
password = passwordProperties; password = passwordProperties;
} }
@Value("${smb.basePath}") @Value("${smb.basePath}")
public void setBasePath(String basePathProperties){ public void setBasePath(String basePathProperties) {
basePath = basePathProperties; basePath = basePathProperties;
} }
@ -132,6 +141,141 @@ public class Smb {
} }
} }
} }
/*
* bus_imgfiles
* IMGFILES_IDFOREIGN_KEYTYPE
* Smb.sshSftp
* */
public static void sshSftp(MultipartFile file, String fileName, String path,String IMGFILES_ID,String FOREIGN_KEY,String TYPE) throws Exception {
Session session = null;
Channel channel = null;
JSch jsch = new JSch();
if (port <= 0) {
// 连接服务器,采用默认端口
session = jsch.getSession(user, host);
} else {
// 采用指定的端口连接服务器
session = jsch.getSession(user, host, port);
}
// 如果服务器连接不上,则抛出异常
if (session == null) {
throw new Exception("session is null");
}
// 设置登陆主机的密码
session.setPassword(password);
// 设置第一次登陆的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
// 设置登陆超时时间
session.connect(30000);
OutputStream outstream = null;
try {
// 创建sftp通信通道
channel = (Channel) session.openChannel("sftp");
channel.connect(1000);
ChannelSftp sftp = (ChannelSftp) channel;
// 进入服务器指定的文件夹
// File dir = new File(basePath+"/"+path);
// dir.setWritable(true, false);
// if(!dir.exists()){
// dir.mkdirs();
// }
createDir(basePath + path, sftp);
sftp.cd(basePath + path);
// 列出服务器指定的文件列表
// Vector v = sftp.ls("*");
// for(int i=0;i<v.size();i++){
// System.out.println(v.get(i));
// }
// 以下代码实现从本地上传一个文件到服务器,如果要实现下载,对换以下流就可以了
sftp.put(file.getInputStream(), fileName);
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关流操作
if (outstream != null) {
outstream.flush();
outstream.close();
}
if (session != null) {
session.disconnect();
}
if (channel != null) {
channel.disconnect();
}
}
}
/*
* bus_imgfiles
* IMGFILES_IDFOREIGN_KEYTYPE
* Smb.sshSftp
* */
public static void sshSftpForInput(InputStream fileI, String fileName, String path,String IMGFILES_ID,String FOREIGN_KEY,String TYPE) throws Exception {
Session session = null;
Channel channel = null;
JSch jsch = new JSch();
if (port <= 0) {
// 连接服务器,采用默认端口
session = jsch.getSession(user, host);
} else {
// 采用指定的端口连接服务器
session = jsch.getSession(user, host, port);
}
// 如果服务器连接不上,则抛出异常
if (session == null) {
throw new Exception("session is null");
}
// 设置登陆主机的密码
session.setPassword(password);
// 设置第一次登陆的时候提示,可选值:(ask | yes | no)
session.setConfig("StrictHostKeyChecking", "no");
// 设置登陆超时时间
session.connect(30000);
OutputStream outstream = null;
try {
// 创建sftp通信通道
channel = (Channel) session.openChannel("sftp");
channel.connect(1000);
ChannelSftp sftp = (ChannelSftp) channel;
// 进入服务器指定的文件夹
// File dir = new File(basePath+"/"+path);
// dir.setWritable(true, false);
// if(!dir.exists()){
// dir.mkdirs();
// }
createDir(basePath + path, sftp);
sftp.cd(basePath + path);
// 列出服务器指定的文件列表
// Vector v = sftp.ls("*");
// for(int i=0;i<v.size();i++){
// System.out.println(v.get(i));
// }
// 以下代码实现从本地上传一个文件到服务器,如果要实现下载,对换以下流就可以了
sftp.put(fileI, fileName);
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关流操作
if (outstream != null) {
outstream.flush();
outstream.close();
}
if (session != null) {
session.disconnect();
}
if (channel != null) {
channel.disconnect();
}
}
}
public static void sshSftpForInput(InputStream fileI, String fileName, String path) throws Exception { public static void sshSftpForInput(InputStream fileI, String fileName, String path) throws Exception {
Session session = null; Session session = null;
@ -196,6 +340,7 @@ public class Smb {
} }
} }
public static void createDir(String createpath, ChannelSftp sftp) { public static void createDir(String createpath, ChannelSftp sftp) {
try { try {
if (isDirExist(createpath, sftp)) { if (isDirExist(createpath, sftp)) {
@ -278,7 +423,7 @@ public class Smb {
System.out.println("4、" + directoryFile + " 删除的文件....."); System.out.println("4、" + directoryFile + " 删除的文件.....");
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e);
} }
// 切断远程连接 // 切断远程连接
channelSftp.exit(); channelSftp.exit();

View File

@ -60,7 +60,7 @@ gwj-baseimgpath=https://qgqy.qhdsafety.com/file/
gwj-backendaddr=http://192.168.0.31:8991/qa-prevention-gwj/ gwj-backendaddr=http://192.168.0.31:8991/qa-prevention-gwj/
#mq ??????????? #mq ???????????
rocketmq.name-server=192.168.0.31:9876 rocketmq.name-server=192.168.0.79:9876
rocketmq.producer.group=libmiddle rocketmq.producer.group=libmiddle
rocketmq.producer.send-message-timeout=3000 rocketmq.producer.send-message-timeout=3000
rocketmq.producer.compress-message-body-threshold=4096 rocketmq.producer.compress-message-body-threshold=4096

View File

@ -1,4 +1,4 @@
spring.application.name=qa-prevention-gwj spring.application.name=qa-prevention-czks
server.port=8191 server.port=8191
#?? #??