Commit a4c5661e authored by m1991's avatar m1991

资讯模块——邀请码过滤特殊字符功能功能修复

parent 9887c6c4
......@@ -83,5 +83,4 @@ public class FileUtil {
}
return inputStream;
}
}
\ No newline at end of file
......@@ -104,6 +104,12 @@
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg-platform</artifactId>
</dependency>
<!--图片压缩处理-->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
</dependencies>
<!-- MAVEN构建 -->
......
package cn.wisenergy.service.app.impl;
import cn.hutool.core.img.Img;
import cn.wisenergy.common.expection.BaseException;
import cn.wisenergy.common.utils.*;
......@@ -12,6 +14,9 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.nio.file.Files;
......@@ -21,8 +26,10 @@ import java.nio.file.StandardCopyOption;
import cn.wisenergy.service.app.UploadService;
import java.io.File;
import java.util.*;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import cn.wisenergy.mapper.ShopZxMapper;
......@@ -31,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
/**
* Created by m1991 on 2021/2/24 13:42
*/
......@@ -52,7 +60,7 @@ public class UploadServiceImpl implements UploadService {
private String path;
/**
* 视频文件上传
* TODO 视频文件上传
*/
@Override
public Map<String, Object> uploadVideo(MultipartFile file, HttpServletRequest request, String zxField, String inviteCode) throws Exception {
......@@ -105,7 +113,7 @@ public class UploadServiceImpl implements UploadService {
}
/**
* 图片文件上传
* TODO 图片文件上传
*/
@Override
public Map<String, Object> uploadImage(MultipartFile file, String inviteCode) throws Exception {
......@@ -148,7 +156,7 @@ public class UploadServiceImpl implements UploadService {
}
/**
* 多图片
* TODO 多图片
*
* @param files
* @param zxField
......@@ -158,6 +166,7 @@ public class UploadServiceImpl implements UploadService {
@Override
public Map imageUpload(MultipartFile[] files, String zxField, String inviteCode) {
String zxUrl = new String();
String xxurl=new String();
if (null == inviteCode || "".equals(inviteCode)) {
inviteCode = "0";
}
......@@ -171,20 +180,20 @@ public class UploadServiceImpl implements UploadService {
//创建集合
List<Map<String, Object>> root = new ArrayList<Map<String, Object>>();
String fileName1 = null;
// 要上传的目标文件存放的绝对路径
// final String localPath = path;
Long time = System.currentTimeMillis();
String localPath = "/upload/";
Map<String, Object> result = new HashMap<String, Object>();//一个文件上传的结果
String msg = "";//上传结果信息
//上传图片不为空时
long sa = 0;
for (MultipartFile file : files) {
sa =file.getSize();
sa = file.getSize();
}
if (sa > 0) {
//遍历图片数据
for (MultipartFile file : files) {
//判断上传文件格式
String fileType = file.getContentType();
log.info(file.getSize() + "");
......@@ -205,14 +214,22 @@ public class UploadServiceImpl implements UploadService {
fileName = "1" + UUID.randomUUID() + fileName1 + ".jpg";//文件新名称
}
//设置文件存储路径,可以存放在你想要指定的路径里面
String Path = "/opt/upload/video/"; //上传图片存放位置
zxUrl += localPath + fileName + ",";
String Path = "/upload/";
String Path1 = "/opt/upload/video/"; //上传图片存放位置
zxUrl += Path1 + fileName + ",";
String UrlzxPath ="/opt/upload/video/";
xxurl=UrlzxPath+ fileName;
if (FileUtils.upload(file, Path, fileName)) {
//文件存放的相对路径(一般存放在数据库用于img标签的src)
String relativePath = "用于判断是否图片上传成功,返回值有:" + fileName;
result.put("relativePath", relativePath);//前端根据是否存在该字段来判断上传是否成功
msg = "图片上传成功";
result.put("zxUrl", zxUrl);
FileOutputStream fouts = null;
Img.from(cn.hutool.core.io.FileUtil.file(xxurl))
.setQuality(0.8)//压缩比率
.write(cn.hutool.core.io.FileUtil.file(xxurl));
} else {
msg = "图片上传失败";
}
......@@ -230,7 +247,7 @@ public class UploadServiceImpl implements UploadService {
shopZxMapper.zxadd(zxUrl, zxField, inviteCode, zxDate);
return result;
//用户只上传文字时
} else if (null != zxField&&sa == 0) {
} else if (null != zxField && sa == 0) {
/**
* 生成当前时间戳
*/
......@@ -251,7 +268,7 @@ public class UploadServiceImpl implements UploadService {
}
/**
* 多文件上传 TODO
* TODO 多文件上传
*/
private Path fileStorageLocation; // 文件在本地存储的地址
......@@ -356,7 +373,7 @@ public class UploadServiceImpl implements UploadService {
@Override
public List<zxUserVo> selectAll(Integer pageNum, Integer pageSize) {
return shopZxMapper.selectAll(pageNum,pageSize);
return shopZxMapper.selectAll(pageNum, pageSize);
}
/**
......
......@@ -58,6 +58,12 @@
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!--图片压缩处理-->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
</dependencies>
<!-- MAVEN构建 -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment