Commit a4c5661e authored by m1991's avatar m1991

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

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