|
@ -0,0 +1,883 @@
|
|
|
package com.yihu.jw.hospital.module.upload.controller;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.yihu.fastdfs.FastDFSUtil;
|
|
|
import com.yihu.jw.hospital.utils.CommonUtil;
|
|
|
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping(value = "/upload", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
|
|
@Api(description = "文件上传")
|
|
|
public class FileUploadController extends EnvelopRestEndpoint {
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(FileUploadController.class);
|
|
|
@ApiParam
|
|
|
FastDFSUtil fastDFSUtil;
|
|
|
@Autowired
|
|
|
private CommonUtil CommonUtil;
|
|
|
|
|
|
@Value("${fastDFS.fastdfs_file_url}")
|
|
|
private String fastdfs_file_url;
|
|
|
|
|
|
@Value("${neiwang.enable}")
|
|
|
private Boolean isneiwang = false; //如果不是内网项目要转到到内网wlyy在上传
|
|
|
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
// @Autowired
|
|
|
// private CustomerService customerService;
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "commonUpload", method = RequestMethod.POST)
|
|
|
@ResponseBody
|
|
|
@ApiOperation("公共的文件上传")
|
|
|
public String commonUpload(HttpServletRequest request) {
|
|
|
try {
|
|
|
String paths = request.getParameter("filePaths");
|
|
|
String fileUrls = "";
|
|
|
if (StringUtils.isBlank(paths)) {
|
|
|
//为空是文件上传
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// 文件保存的临时路径
|
|
|
FastDFSUtil fastDFSUtil = new FastDFSUtil();
|
|
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
String fileName = null;
|
|
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// 上传文件
|
|
|
MultipartFile mf = entity.getValue();
|
|
|
fileName = mf.getOriginalFilename();
|
|
|
InputStream in = mf.getInputStream();
|
|
|
ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
|
|
|
in.close();
|
|
|
if (result != null) {
|
|
|
fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",")
|
|
|
+ result.get("groupName").toString().replaceAll("\"", "") + "/"
|
|
|
+ result.get("remoteFileName").toString().replaceAll("\"", "");
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
String[] pathArr = paths.split(",");
|
|
|
for (String path : pathArr) {
|
|
|
//传路径自己去路径上传
|
|
|
File file = new File(path);
|
|
|
String fileName = null;
|
|
|
if (file.exists()) {
|
|
|
fileName = file.getName();
|
|
|
InputStream in = new FileInputStream(file);
|
|
|
ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
|
|
|
in.close();
|
|
|
if (result != null) {
|
|
|
fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",")
|
|
|
+ result.get("groupName").toString().replaceAll("\"", "") + "/"
|
|
|
+ result.get("remoteFileName").toString().replaceAll("\"", "");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return fileUrls;
|
|
|
} catch (Exception e) {
|
|
|
return e.getMessage();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// /**
|
|
|
// * 患者头像上传
|
|
|
// *
|
|
|
// * @return
|
|
|
// * @throws IOException
|
|
|
// * @throws IllegalStateException
|
|
|
// */
|
|
|
// @RequestMapping(value = "patientPhoto", method = RequestMethod.POST/* , headers = "Accept=image/png" */)
|
|
|
// @ResponseBody
|
|
|
// public String patientPhoto(HttpServletRequest request, HttpServletResponse response, String photo) {
|
|
|
// if (isneiwang) {
|
|
|
// try {
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// String fileName = null;
|
|
|
// String firstPhoto = null;
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// fileName = mf.getOriginalFilename();
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// // 重命名文件
|
|
|
// firstPhoto = photo.substring(0, photo.lastIndexOf(".")) + "_small." + fileExt;
|
|
|
// File uploadFile = new File(SystemConf.getInstance().getTempPath() + File.separator + firstPhoto);
|
|
|
// // 拷贝文件流到指定文件路径
|
|
|
// FileCopyUtils.copy(mf.getBytes(), uploadFile);
|
|
|
// }
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// // 图片标识对象的HTTP链接
|
|
|
// json.put("urls", String.join(",", firstPhoto));
|
|
|
// logger.info("图片上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// /**
|
|
|
// * 图片上传
|
|
|
// *
|
|
|
// * @return
|
|
|
// * @throws IOException
|
|
|
// * @throws IllegalStateException
|
|
|
// * 备注:图片先保存到本地服务器,后续保存图片到fastDFS
|
|
|
// */
|
|
|
// @RequestMapping(value = "image", method = RequestMethod.POST /*,headers = "Accept=image/png"*/ )
|
|
|
// @ResponseBody
|
|
|
// public String image(HttpServletRequest request, HttpServletResponse response) {
|
|
|
// if (isneiwang) {
|
|
|
// // 圖片列表
|
|
|
// List<File> images = new ArrayList<File>();
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// // 文件保存的临时路径
|
|
|
// String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
|
|
|
// // 拼接年月日路径
|
|
|
// String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
|
|
|
// try {
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// // 创建文件夹
|
|
|
// File file = new File(tempPath + datePath);
|
|
|
// if (!file.exists()) {
|
|
|
// file.mkdirs();
|
|
|
// }
|
|
|
// String fileName = null;
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// fileName = mf.getOriginalFilename();
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// // 重命名文件
|
|
|
// SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
// String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
|
|
|
// File uploadFile = new File(tempPath + datePath + newFileName);
|
|
|
// // 拷贝文件流到指定文件路径
|
|
|
// FileCopyUtils.copy(mf.getBytes(), uploadFile);
|
|
|
// // 生成缩略图
|
|
|
// ImageCompress.compress(uploadFile.getAbsolutePath(), uploadFile.getAbsolutePath() + "_small", 300, 300);
|
|
|
// // 添加到上传成功数组中
|
|
|
// images.add(uploadFile);
|
|
|
// tempPaths.add(datePath + newFileName);
|
|
|
// }
|
|
|
// String urls = "";
|
|
|
// for (String image : tempPaths) {
|
|
|
// if (urls.length() == 0) {
|
|
|
// urls = image;
|
|
|
// } else {
|
|
|
// urls += "," + image;
|
|
|
// }
|
|
|
// }
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// // 图片标识对象的HTTP链接
|
|
|
// json.put("urls", urls);
|
|
|
// json.put("tempPath", tempPath);
|
|
|
// logger.info("图片上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// try {
|
|
|
// // 清除垃圾图片
|
|
|
// for (File file : images) {
|
|
|
// FileUtils.forceDelete(file);
|
|
|
// }
|
|
|
// } catch (Exception e2) {
|
|
|
// error(e2);
|
|
|
// }
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// /**
|
|
|
// * 聊天附件上传
|
|
|
// *
|
|
|
// * @return
|
|
|
// * @throws IOException
|
|
|
// * @throws IllegalStateException
|
|
|
// */
|
|
|
// @RequestMapping(value = "chat", method = RequestMethod.POST)
|
|
|
// @ResponseBody
|
|
|
// public String chatFile(HttpServletRequest request, HttpServletResponse response) {
|
|
|
// if (isneiwang) {
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// try {
|
|
|
// String fastUrl = fastdfs_file_url;
|
|
|
// String type = request.getParameter("type");
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// String fileName = null;
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
//
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// fileName = mf.getOriginalFilename();
|
|
|
//
|
|
|
// if ("3".equals(type)) {
|
|
|
// String tempPath = CommonUtil.saveVoiceToDisk(mf.getInputStream(), fileName);
|
|
|
// String map3Path = tempPath.substring(0, tempPath.lastIndexOf("."));
|
|
|
// CommonUtil.changeToMp3(tempPath, map3Path);
|
|
|
// File tempFile = new File(tempPath);
|
|
|
// File mp3File = new File(map3Path);
|
|
|
// ObjectNode objectNode = fastDFSUtil.upload(new FileInputStream(mp3File), "mp3", "");
|
|
|
// //1.3.7 去掉前缀,返回相对路径
|
|
|
//// tempPaths.add(fastUrl + objectNode.get("groupName").toString().replaceAll("\"","")
|
|
|
//// + "/" + objectNode.get("remoteFileName").toString().replaceAll("\"",""));
|
|
|
// tempPaths.add(objectNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + objectNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// if (tempFile != null) {
|
|
|
// tempFile.delete();
|
|
|
// }
|
|
|
// if (mp3File != null) {
|
|
|
// mp3File.delete();
|
|
|
// }
|
|
|
// } else if ("4".equals(type)) {
|
|
|
// String tempPath = CommonUtil.saveVoiceToDisk(mf.getInputStream(), fileName);
|
|
|
// String pngPath = tempPath.substring(0, tempPath.lastIndexOf(".")) + ".png";
|
|
|
// File tempFile = new File(tempPath);
|
|
|
// File pngFile = new File(pngPath);
|
|
|
// long times = CommonUtil.getVideoTimeAndImg(tempPath, pngPath);
|
|
|
// if (times < 1000) {
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", -1);
|
|
|
// json.put("success", true);
|
|
|
// json.put("msg", "视频录制时间太短!");
|
|
|
// json.put("times", times);
|
|
|
// return json.toString();
|
|
|
// }
|
|
|
// ObjectNode imgNode = fastDFSUtil.upload(new FileInputStream(pngPath), "png", "");
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// ObjectNode videoNode = fastDFSUtil.upload(new FileInputStream(tempPath), fileExt, "");
|
|
|
//
|
|
|
// tempPaths.add(imgNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// tempPaths.add(videoNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + videoNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// tempPaths.add(times + "");
|
|
|
// if (tempFile != null) {
|
|
|
// tempFile.delete();
|
|
|
// }
|
|
|
// if (pngFile != null) {
|
|
|
// pngFile.delete();
|
|
|
// }
|
|
|
// } else {
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// ObjectNode objectNode = fastDFSUtil.upload(mf.getInputStream(), fileExt, "");
|
|
|
// tempPaths.add(objectNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + objectNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// }
|
|
|
// }
|
|
|
// String urls = String.join(",", tempPaths);
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("success", true);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// // 图片标识对象的HTTP链接
|
|
|
// json.put("urls", urls);
|
|
|
// logger.info("附件上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 文件上传指定上传路径
|
|
|
*
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
* @throws IllegalStateException
|
|
|
*/
|
|
|
// @RequestMapping(value = "chatByStorage", method = RequestMethod.POST)
|
|
|
// @ResponseBody
|
|
|
// public String chatByStorage(HttpServletRequest request, HttpServletResponse response) {
|
|
|
// if (isneiwang) {
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// try {
|
|
|
// String fastUrl = fastdfs_file_url;
|
|
|
// String type = request.getParameter("type");
|
|
|
// Integer storePath = Integer.valueOf(request.getParameter("storePath"));
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// String fileName = null;
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
//
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// fileName = mf.getOriginalFilename();
|
|
|
//
|
|
|
// if ("3".equals(type)) {
|
|
|
// String tempPath = CommonUtil.saveVoiceToDisk(mf.getInputStream(), fileName);
|
|
|
// String map3Path = tempPath.substring(0, tempPath.lastIndexOf("."));
|
|
|
// CommonUtil.changeToMp3(tempPath, map3Path);
|
|
|
// File tempFile = new File(tempPath);
|
|
|
// File mp3File = new File(map3Path);
|
|
|
// ObjectNode objectNode = fastDFSUtil.uploadByStorage(new FileInputStream(mp3File), "mp3", "",storePath);
|
|
|
// //1.3.7 去掉前缀,返回相对路径
|
|
|
//// tempPaths.add(fastUrl + objectNode.get("groupName").toString().replaceAll("\"","")
|
|
|
//// + "/" + objectNode.get("remoteFileName").toString().replaceAll("\"",""));
|
|
|
// tempPaths.add(objectNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + objectNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// if (tempFile != null) {
|
|
|
// tempFile.delete();
|
|
|
// }
|
|
|
// if (mp3File != null) {
|
|
|
// mp3File.delete();
|
|
|
// }
|
|
|
// } else if ("4".equals(type)) {
|
|
|
// String tempPath = CommonUtil.saveVoiceToDisk(mf.getInputStream(), fileName);
|
|
|
// String pngPath = tempPath.substring(0, tempPath.lastIndexOf(".")) + ".png";
|
|
|
// File tempFile = new File(tempPath);
|
|
|
// File pngFile = new File(pngPath);
|
|
|
// long times = CommonUtil.getVideoTimeAndImg(tempPath, pngPath);
|
|
|
// if (times < 1000) {
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", -1);
|
|
|
// json.put("success", true);
|
|
|
// json.put("msg", "视频录制时间太短!");
|
|
|
// json.put("times", times);
|
|
|
// return json.toString();
|
|
|
// }
|
|
|
// ObjectNode imgNode = fastDFSUtil.uploadByStorage(new FileInputStream(pngPath), "png", "",storePath);
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// ObjectNode videoNode = fastDFSUtil.uploadByStorage(new FileInputStream(tempPath), fileExt, "",storePath);
|
|
|
//
|
|
|
// tempPaths.add(imgNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// tempPaths.add(videoNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + videoNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// tempPaths.add(times + "");
|
|
|
// if (tempFile != null) {
|
|
|
// tempFile.delete();
|
|
|
// }
|
|
|
// if (pngFile != null) {
|
|
|
// pngFile.delete();
|
|
|
// }
|
|
|
// } else {
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// ObjectNode objectNode = fastDFSUtil.uploadByStorage(mf.getInputStream(), fileExt, "",storePath);
|
|
|
// tempPaths.add(objectNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + objectNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// }
|
|
|
// }
|
|
|
// String urls = String.join(",", tempPaths);
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("success", true);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// // 图片标识对象的HTTP链接
|
|
|
// json.put("urls", urls);
|
|
|
// logger.info("附件上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWangByStorage(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 语音上传
|
|
|
*
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @return
|
|
|
*/
|
|
|
// @RequestMapping(value = "voice", method = RequestMethod.POST)
|
|
|
// @ResponseBody
|
|
|
// public String voice(HttpServletRequest request, HttpServletResponse response) {
|
|
|
// if (isneiwang) {
|
|
|
// // 圖片列表
|
|
|
// List<File> voices = new ArrayList<File>();
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// // 文件保存的临时路径
|
|
|
// String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
|
|
|
// // 拼接年月日路径
|
|
|
// String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
|
|
|
// try {
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// // 创建文件夹
|
|
|
// File file = new File(tempPath + datePath);
|
|
|
// if (!file.exists()) {
|
|
|
// file.mkdirs();
|
|
|
// }
|
|
|
// String fileName = null;
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// fileName = mf.getOriginalFilename();
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// // 重命名文件
|
|
|
// SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
// String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
|
|
|
// File uploadFile = new File(tempPath + datePath + newFileName);
|
|
|
// // 拷贝文件流到指定文件路径
|
|
|
// FileCopyUtils.copy(mf.getBytes(), uploadFile);
|
|
|
// // 添加到上传成功数组中
|
|
|
// voices.add(uploadFile);
|
|
|
// tempPaths.add(datePath + newFileName);
|
|
|
// }
|
|
|
// String urls = "";
|
|
|
// for (String voice : tempPaths) {
|
|
|
// if (urls.length() == 0) {
|
|
|
// urls = voice;
|
|
|
// } else {
|
|
|
// urls += "," + voice;
|
|
|
// }
|
|
|
// }
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// // 图片标识对象的HTTP链接
|
|
|
// json.put("urls", urls);
|
|
|
// logger.info("语音上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// try {
|
|
|
// // 清除垃圾图片
|
|
|
// for (File file : voices) {
|
|
|
// FileUtils.forceDelete(file);
|
|
|
// }
|
|
|
// } catch (Exception e2) {
|
|
|
// error(e2);
|
|
|
// }
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 语音上传
|
|
|
*
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @return
|
|
|
*/
|
|
|
// @RequestMapping(value = "src/main/test", method = RequestMethod.POST)
|
|
|
// @ResponseBody
|
|
|
// public String test(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
// if (isneiwang) {
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// String fastUrl = fastdfs_file_url;
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// String fileName = mf.getOriginalFilename();
|
|
|
// String tempPath = CommonUtil.saveVoiceToDisk(mf.getInputStream(), fileName);
|
|
|
// String pngPath = tempPath.substring(0, tempPath.lastIndexOf(".")) + ".png";
|
|
|
// File tempFile = new File(tempPath);
|
|
|
// File pngFile = new File(pngPath);
|
|
|
// long times = CommonUtil.getVideoTimeAndImg(tempPath, pngPath);
|
|
|
// ObjectNode imgNode = fastDFSUtil.upload(new FileInputStream(pngPath), "png", "");
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// ObjectNode videoNode = fastDFSUtil.upload(new FileInputStream(tempPath), fileExt, "");
|
|
|
// tempPaths.add(fastUrl + imgNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// tempPaths.add(fastUrl + videoNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + videoNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// tempPaths.add(times + "");
|
|
|
// if (tempFile != null) {
|
|
|
// tempFile.delete();
|
|
|
// }
|
|
|
// if (pngFile != null) {
|
|
|
// pngFile.delete();
|
|
|
// }
|
|
|
// }
|
|
|
// String urls = String.join(",", tempPaths);
|
|
|
// return urls;
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// @RequestMapping(value = "fastDFSImag", method = RequestMethod.POST)
|
|
|
// @ApiOperation("编辑文章上传图片")
|
|
|
// @ResponseBody
|
|
|
// public String pushArticleList(@ApiParam(name = "file", value = "文件", required = true)
|
|
|
// @RequestParam(value = "file", required = true) MultipartFile file,
|
|
|
// HttpServletRequest request, HttpServletResponse response){
|
|
|
// if (isneiwang) {
|
|
|
// // 圖片列表
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// try {
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// InputStream inputStream = mf.getInputStream();
|
|
|
// String fileName = mf.getOriginalFilename().substring(0,mf.getOriginalFilename().lastIndexOf("."));
|
|
|
// ObjectNode imgNode = FastDFSUtil.upload(inputStream,"png",fileName);
|
|
|
// com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(imgNode.toString());
|
|
|
// tempPaths.add(json.getString("fid"));
|
|
|
// }
|
|
|
// String urls = "";
|
|
|
// for (String image : tempPaths) {
|
|
|
// if (urls.length() == 0) {
|
|
|
// urls = image;
|
|
|
// } else {
|
|
|
// urls += "," + image;
|
|
|
// }
|
|
|
// }
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// json.put("data", urls);
|
|
|
// logger.info("图片上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
//// String result = CommonUtil.toNeiWang(request, response);
|
|
|
//// logger.info("fastDFSImag reslt :" + result);
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
* 图片上传
|
|
|
*
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
* @throws IllegalStateException
|
|
|
*/
|
|
|
// @RequestMapping(value = "pcimage", method = RequestMethod.POST /*,headers = "Accept=image/png"*/ )
|
|
|
// @ResponseBody
|
|
|
// public String pcimage(HttpServletRequest request, HttpServletResponse response) {
|
|
|
// if (isneiwang) {
|
|
|
// // 圖片列表
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// try {
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// InputStream inputStream = mf.getInputStream();
|
|
|
// String fileName = mf.getOriginalFilename().substring(0,mf.getOriginalFilename().lastIndexOf("."));
|
|
|
// ObjectNode imgNode = FastDFSUtil.upload(inputStream,"png",fileName);
|
|
|
// com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(imgNode.toString());
|
|
|
// tempPaths.add(json.getString("fid"));
|
|
|
// }
|
|
|
// String urls = "";
|
|
|
// for (String image : tempPaths) {
|
|
|
// if (urls.length() == 0) {
|
|
|
// urls = image;
|
|
|
// } else {
|
|
|
// urls += "," + image;
|
|
|
// }
|
|
|
// }
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// json.put("urls", urls);
|
|
|
//
|
|
|
// logger.info("图片上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
// @RequestMapping(value = "deleteFile", method = RequestMethod.POST /*,headers = "Accept=image/png"*/ )
|
|
|
// @ResponseBody
|
|
|
// public String deleteFile(@ApiParam(name="storagePath",value="文件的全部路径 如:group1/M00/00/00/wKgRsVjtwpSAXGwkAAAweEAzRjw471.jpg",required = true)
|
|
|
// @RequestParam(required = true)String storagePath,HttpServletRequest request, HttpServletResponse response){
|
|
|
// try {
|
|
|
// if (isneiwang) {
|
|
|
//
|
|
|
// fastDFSUtil.delete(storagePath);
|
|
|
// }else{
|
|
|
// CommonUtil.deleteFile(storagePath,request,response);
|
|
|
// }
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "删除成功");
|
|
|
// return json.toString();
|
|
|
// }catch (Exception e){
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
// @RequestMapping(value = "uploadChatFile", method = RequestMethod.POST)
|
|
|
// @ResponseBody
|
|
|
// public String uploadChatFile(@RequestBody String jsonString) {
|
|
|
// InputStream inputStream = null;
|
|
|
// String fileName = "";
|
|
|
// try {
|
|
|
// Map map = objectMapper.readValue(jsonString, Map.class);
|
|
|
// if (null == map.get("fileByte")) {
|
|
|
// return error(-1, "上传失败");
|
|
|
// }
|
|
|
// String fileByte = String.valueOf(map.get("fileByte"));
|
|
|
// fileName = null == map.get("fileName") ? fileName : String.valueOf(map.get("fileName"));
|
|
|
// byte[] imgByte = org.apache.commons.codec.binary.Base64.decodeBase64(fileByte);
|
|
|
// inputStream = new ByteArrayInputStream(imgByte);
|
|
|
// } catch (Exception e) {
|
|
|
// error(e);
|
|
|
// return error(-1, "上传失败");
|
|
|
// }
|
|
|
// if (isneiwang) {
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// try {
|
|
|
// String tempPath = CommonUtil.saveVoiceToDisk(inputStream, fileName);
|
|
|
// String pngPath = tempPath.substring(0, tempPath.lastIndexOf(".")) + ".png";
|
|
|
// File tempFile = new File(tempPath);
|
|
|
// File pngFile = new File(pngPath);
|
|
|
// ObjectNode imgNode = fastDFSUtil.upload(new FileInputStream(pngPath), "png", "");
|
|
|
// String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// ObjectNode videoNode = fastDFSUtil.upload(new FileInputStream(tempPath), fileExt, "");
|
|
|
//
|
|
|
// tempPaths.add(imgNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + imgNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// tempPaths.add(videoNode.get("groupName").toString().replaceAll("\"", "")
|
|
|
// + "/" + videoNode.get("remoteFileName").toString().replaceAll("\"", ""));
|
|
|
// if (tempFile != null) {
|
|
|
// tempFile.delete();
|
|
|
// }
|
|
|
// if (pngFile != null) {
|
|
|
// pngFile.delete();
|
|
|
// }
|
|
|
// String urls = String.join(",", tempPaths);
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("success", true);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// // 图片标识对象的HTTP链接
|
|
|
// json.put("urls", urls);
|
|
|
// logger.info("附件上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// request.setAttribute("type", "4");
|
|
|
// return CommonUtil.toNeiWang(request, inputStream, fileName);
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
|
|
|
// @RequestMapping(value = "/uploadWxMedia", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
|
|
|
// @ResponseBody
|
|
|
// @ApiOperation("多张上传图片")
|
|
|
// public String uploadWxMedia(@ApiParam(name = "mediaIds", value = "微信媒体id标识", defaultValue = "wL1vfE9g1fiRCl5xd-Xotl1XycWQ9mwigDLUv-S0Kmde-pXNrlySKbf5RM5SwwFl")
|
|
|
// @RequestParam(value = "mediaIds", required = true) String mediaIds) {
|
|
|
// try {
|
|
|
// String url = "";
|
|
|
// FastDFSUtil fastDFSUtil = new FastDFSConfig().fastDFSUtil();
|
|
|
// for(String mediaId:mediaIds.split(",")){
|
|
|
// InputStream wxImg = getInputStream(mediaId);
|
|
|
// ObjectNode result = fastDFSUtil.upload(wxImg, "jpg", "");
|
|
|
// wxImg.close();
|
|
|
// String serverUrl = fastdfs_file_url;
|
|
|
// if (result != null) {
|
|
|
// url += ","+serverUrl
|
|
|
// + result.get("groupName").toString().replaceAll("\"", "") + "/"
|
|
|
// + result.get("remoteFileName").toString().replaceAll("\"", "");
|
|
|
// } else {
|
|
|
// return write(-1, "图片上传失败!");
|
|
|
// }
|
|
|
// }
|
|
|
// if(StringUtils.isNotBlank(url)){
|
|
|
// url = url.substring(1,url.length());
|
|
|
// }
|
|
|
// return write(200, "图片上传成功!", "url", url);
|
|
|
// } catch (Exception e) {
|
|
|
// return invalidUserException(e, -1, "图片上传失败!");
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
//
|
|
|
// @RequestMapping(value = "fastDFSVoice", method = RequestMethod.POST)
|
|
|
// @ApiOperation("上传音频")
|
|
|
// @ResponseBody
|
|
|
// public String fastDFSVoice(@ApiParam(name = "file", value = "文件", required = true)
|
|
|
// @RequestParam(value = "file", required = true) MultipartFile file,
|
|
|
// HttpServletRequest request, HttpServletResponse response){
|
|
|
// if (isneiwang) {
|
|
|
// // 音频列表
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// try {
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// InputStream inputStream = mf.getInputStream();
|
|
|
// String fileName = mf.getOriginalFilename().substring(0,mf.getOriginalFilename().lastIndexOf("."));
|
|
|
// ObjectNode imgNode = FastDFSUtil.upload(inputStream,"mp3",fileName);
|
|
|
// com.alibaba.fastjson.JSONObject json = com.alibaba.fastjson.JSONObject.parseObject(imgNode.toString());
|
|
|
// tempPaths.add(json.getString("fid"));
|
|
|
// }
|
|
|
// String urls = "";
|
|
|
// for (String voice: tempPaths) {
|
|
|
// if (urls.length() == 0) {
|
|
|
// urls = voice;
|
|
|
// } else {
|
|
|
// urls += "," + voice;
|
|
|
// }
|
|
|
// }
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// json.put("data", urls);
|
|
|
// logger.info("音频上传:" + json.toString());
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// @RequestMapping(value = "ftpVoiceUpload", method = RequestMethod.POST)
|
|
|
// @ApiOperation("上传音频")
|
|
|
// @ResponseBody
|
|
|
// public String ftpVoiceUpload(@ApiParam(name = "bytes", value = "文件流", required = true)
|
|
|
// @RequestParam(value = "bytes", required = true)String bytes,
|
|
|
// @ApiParam(name = "name", value = "文件流", required = true)
|
|
|
// @RequestParam(value = "name", required = true) String name){
|
|
|
// try {
|
|
|
// //根据文件名判断是否已经上传,已上传返回true,否则返回false
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// if(!customerService.findByFileName(name)){
|
|
|
// byte[] byteres = Base64Utils.decode(bytes);
|
|
|
// InputStream inputStream = new ByteArrayInputStream(byteres);
|
|
|
// String fileName = name.substring(0, name.lastIndexOf("."));
|
|
|
// ObjectNode imgNode = FastDFSUtil.upload(inputStream, "mp3", fileName);
|
|
|
// com.alibaba.fastjson.JSONObject json1 = com.alibaba.fastjson.JSONObject.parseObject(imgNode.toString());
|
|
|
// json.put("data", json1.getString("fid"));
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// logger.info(name + "音频上传:" + json.toString());
|
|
|
// //保存录音路径
|
|
|
// customerService.saveManageCallRecordVideoDo(name,json1.getString("fid"));
|
|
|
// }else {
|
|
|
// json.put("status", 200);
|
|
|
// json.put("data", "");
|
|
|
// json.put("msg", "音频已上传过");
|
|
|
// logger.info(name + "音频已上传过:" + json.toString());
|
|
|
// }
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// logger.error(name + "音频上传失败:" + e.getMessage());
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// @RequestMapping(value = "fastDFSVoiceByRequest", method = RequestMethod.POST)
|
|
|
// @ApiOperation("上传音频")
|
|
|
// @ResponseBody
|
|
|
// public String fastDFSVoiceTest(HttpServletRequest request, HttpServletResponse response) {
|
|
|
// if (isneiwang) {
|
|
|
// JSONObject json = new JSONObject();
|
|
|
// List<String> tempPaths = new ArrayList<String>();
|
|
|
// try {
|
|
|
// MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
// Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// // 上传文件
|
|
|
// MultipartFile mf = entity.getValue();
|
|
|
// InputStream inputStream = mf.getInputStream();
|
|
|
// String fileName = mf.getOriginalFilename().substring(0, mf.getOriginalFilename().lastIndexOf("."));
|
|
|
// //判断是否上传过
|
|
|
// if (!customerService.findByFileName(fileName)) {
|
|
|
// ObjectNode imgNode = FastDFSUtil.upload(inputStream, "mp3", fileName);
|
|
|
// com.alibaba.fastjson.JSONObject json1 = com.alibaba.fastjson.JSONObject.parseObject(imgNode.toString());
|
|
|
// tempPaths.add(json1.getString("fid"));
|
|
|
// json.put("data", json1.getString("fid"));
|
|
|
// json.put("status", 200);
|
|
|
// json.put("msg", "上传成功");
|
|
|
// logger.info(fileName + "音频上传:" + json.toString());
|
|
|
// //保存录音路径
|
|
|
// customerService.saveManageCallRecordVideoDo(fileName, json1.getString("fid"));
|
|
|
// } else {
|
|
|
// json.put("status", 200);
|
|
|
// json.put("data", "");
|
|
|
// json.put("msg", fileName + "音频已上传过");
|
|
|
// logger.info(fileName + "音频已上传过:" + json.toString());
|
|
|
// }
|
|
|
// }
|
|
|
// return json.toString();
|
|
|
// } catch (Exception e) {
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// } else {
|
|
|
// return CommonUtil.toNeiWang(request, response);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
//
|
|
|
// @Autowired
|
|
|
// private ExcelUtilService excelUtilService;
|
|
|
//
|
|
|
// @PostMapping("/abcabc")
|
|
|
// @ApiOperation("ExcelUtils处理")
|
|
|
// @ResponseBody
|
|
|
// public String importUser(@RequestParam("file")MultipartFile file,
|
|
|
// @RequestParam(value = "type", required = true)String type) {
|
|
|
// try {
|
|
|
// excelUtilService.excelHpvOrCyto(file,type);
|
|
|
// return success("成功");
|
|
|
// } catch (Exception e) {
|
|
|
// e.printStackTrace();
|
|
|
// return errorResult(e);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
|
|
|
}
|