Commit 3896dacb authored by m1991's avatar m1991

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

parent 6d6ecb9f
...@@ -21,10 +21,13 @@ import java.nio.file.Files; ...@@ -21,10 +21,13 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import cn.wisenergy.service.app.UploadService; import cn.wisenergy.service.app.UploadService;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import cn.wisenergy.mapper.ShopZxMapper; import cn.wisenergy.mapper.ShopZxMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -48,32 +51,32 @@ public class UploadServiceImpl implements UploadService { ...@@ -48,32 +51,32 @@ public class UploadServiceImpl implements UploadService {
@Autowired @Autowired
private userLikesMapper LikesMapper; private userLikesMapper LikesMapper;
// @Value("${file.upload.path:#{null}}") // @Value("${file.upload.path:#{null}}")
private String path; private String path;
/** /**
* 视频文件上传 * 视频文件上传
*/ */
@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 {
Map<String, Object> resultMap=new HashMap<String, Object>(); Map<String, Object> resultMap = new HashMap<String, Object>();
/** /**
* http://路径 request.getScheme() + "://" + request.getServerName() * http://路径 request.getScheme() + "://" + request.getServerName()
* + ":" + request.getServerPort()+/upload/";" * + ":" + request.getServerPort()+/upload/";"
*/ */
String basePath ="/upload/"; String basePath = "/upload/";
Long time = System.currentTimeMillis(); Long time = System.currentTimeMillis();
String fileName = file.getOriginalFilename();//文件原始名称 String fileName = file.getOriginalFilename();//文件原始名称
String suffixName = fileName.substring(fileName.lastIndexOf("."));//从最后一个.开始截取。截取fileName的后缀名 String suffixName = fileName.substring(fileName.lastIndexOf("."));//从最后一个.开始截取。截取fileName的后缀名
String newFileName = time+suffixName; //文件新名称 String newFileName = time + suffixName; //文件新名称
//设置文件存储路径,可以存放在你想要指定的路径里面 //设置文件存储路径,可以存放在你想要指定的路径里面
String rootPath="/opt/upload/video/"; //上传视频存放位置 String rootPath = "/opt/upload/video/"; //上传视频存放位置
String filePath = rootPath+newFileName; String filePath = rootPath + newFileName;
File newFile = new File(filePath); File newFile = new File(filePath);
//判断目标文件所在目录是否存在 //判断目标文件所在目录是否存在
if(!newFile.getParentFile().exists()){ if (!newFile.getParentFile().exists()) {
//如果目标文件所在的目录不存在,则创建父目录 //如果目标文件所在的目录不存在,则创建父目录
newFile.getParentFile().mkdirs(); newFile.getParentFile().mkdirs();
} }
...@@ -84,71 +87,72 @@ public class UploadServiceImpl implements UploadService { ...@@ -84,71 +87,72 @@ public class UploadServiceImpl implements UploadService {
String videoUrl = basePath + newFileName; String videoUrl = basePath + newFileName;
//视频封面图处理 //视频封面图处理
String newImgName = time+".jpg"; String newImgName = time + ".jpg";
String framefile = rootPath + newImgName; String framefile = rootPath + newImgName;
String imgUrlSave = basePath+newImgName;//图片最终位置路径 String imgUrlSave = basePath + newImgName;//图片最终位置路径
//视频截取封面图 //视频截取封面图
String imgUrl=FrameGrabberKit.getVedioImg(videoUrl, framefile, imgUrlSave); String imgUrl = FrameGrabberKit.getVedioImg(videoUrl, framefile, imgUrlSave);
resultMap.put("videoUrl", videoUrl); resultMap.put("videoUrl", videoUrl);
resultMap.put("imgUrl", imgUrl); resultMap.put("imgUrl", imgUrl);
resultMap.put("code", 0); resultMap.put("code", 0);
resultMap.put("msg","视频上传成功"); resultMap.put("msg", "视频上传成功");
String zxUrl=videoUrl; String zxUrl = videoUrl;
//System.out.println("上传的文件名为:"+fileName+",后缀名为:"+newFileName); //System.out.println("上传的文件名为:"+fileName+",后缀名为:"+newFileName);
/** /**
* 生成当前时间戳 * 生成当前时间戳
*/ */
Long zxDate= System.currentTimeMillis(); Long zxDate = System.currentTimeMillis();
shopZxMapper.zxadd(zxUrl,zxField,inviteCode, zxDate); shopZxMapper.zxadd(zxUrl, zxField, inviteCode, zxDate);
return resultMap; return resultMap;
} }
/**
* 图片文件上传
*/
@Override
public Map<String, Object> uploadImage(MultipartFile file, String inviteCode) throws Exception {
Map<String, Object> resultMap = new HashMap<String, Object>();
/** /**
* 图片文件上传 * 生成当前时间戳
*/ */
@Override Long zxDate = System.currentTimeMillis();
public Map<String, Object> uploadImage(MultipartFile file,String inviteCode) throws Exception {
Map<String, Object> resultMap=new HashMap<String, Object>();
/**
* 生成当前时间戳
*/
Long zxDate= System.currentTimeMillis();
String basePath = "/upload/"; String basePath = "/upload/";
Long time = System.currentTimeMillis(); Long time = System.currentTimeMillis();
String zxName = file.getOriginalFilename();//文件原始名称 String zxName = file.getOriginalFilename();//文件原始名称
assert zxName != null; assert zxName != null;
String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名 String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名
String newzxName = time+suffixName; //文件新名称 String newzxName = time + suffixName; //文件新名称
//设置文件存储路径,可以存放在你想要指定的路径里面 //设置文件存储路径,可以存放在你想要指定的路径里面
String rootPath="/opt/upload/video/"; //上传图片存放位置 String rootPath = "/opt/upload/video/"; //上传图片存放位置
String filePath = rootPath+newzxName; String filePath = rootPath + newzxName;
File newFile = new File(filePath); File newFile = new File(filePath);
//判断目标文件所在目录是否存在 //判断目标文件所在目录是否存在
if(!newFile.getParentFile().exists()){ if (!newFile.getParentFile().exists()) {
//如果目标文件所在的目录不存在,则创建父目录 //如果目标文件所在的目录不存在,则创建父目录
newFile.getParentFile().mkdirs(); newFile.getParentFile().mkdirs();
}
User user=usersMapper.InvitedCode2(inviteCode);
String userId=user.getUserId();
//将内存中的数据写入磁盘
file.transferTo(newFile);
//图片上传保存url
String zxUrl = basePath + newzxName;
resultMap.put("zxUrl", zxUrl);
resultMap.put("code", 0);
resultMap.put("msg","头像上传成功!!!");
// shopZxMapper.zxadd1(zxUrl,userId);
return resultMap;
} }
User user = usersMapper.InvitedCode2(inviteCode);
String userId = user.getUserId();
//将内存中的数据写入磁盘
file.transferTo(newFile);
//图片上传保存url
String zxUrl = basePath + newzxName;
resultMap.put("zxUrl", zxUrl);
resultMap.put("code", 0);
resultMap.put("msg", "头像上传成功!!!");
// shopZxMapper.zxadd1(zxUrl,userId);
return resultMap;
}
/** /**
* 多图片 * 多图片
*
* @param files * @param files
* @param zxField * @param zxField
* @param inviteCode * @param inviteCode
...@@ -156,33 +160,38 @@ public class UploadServiceImpl implements UploadService { ...@@ -156,33 +160,38 @@ 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) {
if(null==inviteCode||"".equals(inviteCode)){ if (null == inviteCode || "".equals(inviteCode)) {
inviteCode="0"; inviteCode = "0";
} }
HashMap map = new HashMap(); HashMap map = new HashMap();
//正则去除特殊符号 //正则去除特殊符号
//String a = inviteCode.replaceAll("\"(\\b[^\"]+|\\s+)?\"(\\b[^\"]+\\b)?\"([^\"]+\\b|\\s+)?\"","\"$1$2$3\""); //String a = inviteCode.replaceAll("\"(\\b[^\"]+|\\s+)?\"(\\b[^\"]+\\b)?\"([^\"]+\\b|\\s+)?\"","\"$1$2$3\"");
//过滤传入的邀请码带有“”的符号 //过滤传入的邀请码带有“”的符号
inviteCode = inviteCode.replace("\"", "").replace("\"", ""); inviteCode = inviteCode.replace("\"", "").replace("\"", "");
//上传图片不为空时 //获取上传图片数量,打印在控制台
if (null != files && 0 != files.length) { System.out.println("上传图片数量" + files.length);
//获取上传图片数量,打印在控制台 String zxUrl = new String();
System.out.println("上传图片数量" + files.length); //创建集合
String zxUrl = new String(); List<Map<String, Object>> root = new ArrayList<Map<String, Object>>();
//创建集合 String fileName1 = null;
List<Map<String, Object>> root = new ArrayList<Map<String, Object>>(); // 要上传的目标文件存放的绝对路径
String fileName1 = null;
// 要上传的目标文件存放的绝对路径
// final String localPath = path; // final String localPath = path;
Long time = System.currentTimeMillis(); Long time = System.currentTimeMillis();
String localPath = "/upload/"; 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;
for (MultipartFile file : files) {
sa =file.getSize();
}
if (sa > 0) {
//遍历图片数据 //遍历图片数据
for (MultipartFile file : files) { for (MultipartFile file : files) {
//判断上传文件格式 //判断上传文件格式
String fileType = file.getContentType(); String fileType = file.getContentType();
if (fileType.equals("image/jpeg") || fileType.equals("image/png") || fileType.equals("image/gif") || fileType.equals("image/jpg") || fileType.equals("image/bmp") || fileType.equals("application/octet-stream")) { log.error(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)) {
//上传后保存的文件名(需要防止图片重名导致的文件覆盖) //上传后保存的文件名(需要防止图片重名导致的文件覆盖)
//获取文件名 //获取文件名
fileName1 = file.getOriginalFilename(); fileName1 = file.getOriginalFilename();
...@@ -220,28 +229,28 @@ public class UploadServiceImpl implements UploadService { ...@@ -220,28 +229,28 @@ public class UploadServiceImpl implements UploadService {
* 生成当前时间戳 * 生成当前时间戳
*/ */
Long zxDate = Long.valueOf(System.currentTimeMillis()); Long zxDate = Long.valueOf(System.currentTimeMillis());
zxUrl=null;
shopZxMapper.zxadd(zxUrl, zxField, inviteCode, zxDate); shopZxMapper.zxadd(zxUrl, zxField, inviteCode, zxDate);
return result; return result;
//用户只上传文字时 //用户只上传文字时
} else if (null != zxField&&files==null) { } else if (null != zxField&&sa == 0) {
/** /**
* 生成当前时间戳 * 生成当前时间戳
*/ */
Long zxDate = Long.valueOf(System.currentTimeMillis()); Long zxDate = Long.valueOf(System.currentTimeMillis());
// zxUrl="0";
String zxUrl="0";
shopZxMapper.zxadd(zxUrl, zxField, inviteCode, zxDate); shopZxMapper.zxadd(zxUrl, zxField, inviteCode, zxDate);
//图片与文字都为null的时候,给前端返回提示! //图片与文字都为null的时候,给前端返回提示!
}else { } else {
if (null==files&&null==zxField) { if (null == files && null == zxField) {
map.put("code", 1); map.put("code", 1);
map.put("msg", "上传资讯不能为空,请重新上传!"); map.put("msg", "上传资讯不能为空,请重新上传!");
return map; return map;
} }
} }
map.put("code", 0); map.put("code", 0);
map.put("msg", "资讯上传成功!"); map.put("msg", "资讯上传成功!");
return map; return map;
} }
/** /**
...@@ -262,6 +271,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -262,6 +271,7 @@ public class UploadServiceImpl implements UploadService {
/** /**
* 存储文件到系统 * 存储文件到系统
*
* @param file 文件 * @param file 文件
* @return 文件名 * @return 文件名
*/ */
...@@ -271,7 +281,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -271,7 +281,7 @@ public class UploadServiceImpl implements UploadService {
String fileName = StringUtils.cleanPath(file.getOriginalFilename()); String fileName = StringUtils.cleanPath(file.getOriginalFilename());
try { try {
// Check if the file's name contains invalid characters // Check if the file's name contains invalid characters
if(fileName.contains("..")) { if (fileName.contains("..")) {
throw new FileException("Sorry! Filename contains invalid path sequence " + fileName); throw new FileException("Sorry! Filename contains invalid path sequence " + fileName);
} }
// Copy file to the target location (Replacing existing file with the same name) // Copy file to the target location (Replacing existing file with the same name)
...@@ -288,50 +298,50 @@ public class UploadServiceImpl implements UploadService { ...@@ -288,50 +298,50 @@ public class UploadServiceImpl implements UploadService {
try { try {
Path filePath = this.fileStorageLocation.resolve(fileName).normalize(); Path filePath = this.fileStorageLocation.resolve(fileName).normalize();
Resource resource = new UrlResource(filePath.toUri()); Resource resource = new UrlResource(filePath.toUri());
if(resource.exists()) { if (resource.exists()) {
return resource; return resource;
} else { } else {
throw new FileException("File not found " + fileName); throw new FileException("File not found " + fileName);
} }
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
throw new FileException("File not found " + fileName, ex); throw new FileException("File not found " + fileName, ex);
} }
} }
/** /**
* 资讯文件展示 * 资讯文件展示
*/ */
@Override @Override
public Map selectPage(Integer pageNum, Integer pageSize,String inviteCode) { public Map selectPage(Integer pageNum, Integer pageSize, String inviteCode) {
Map map = new HashMap(); Map map = new HashMap();
pageNum=pageNum-1; pageNum = pageNum - 1;
List<zxUserDto> shopZxList = shopZxMapper.selectPage(pageNum,pageSize); List<zxUserDto> shopZxList = shopZxMapper.selectPage(pageNum, pageSize);
for (zxUserDto shopZx : shopZxList) { for (zxUserDto shopZx : shopZxList) {
String[] zxUrl = shopZx.getZxUrl().split(","); String[] zxUrl = shopZx.getZxUrl().split(",");
ArrayList list =new ArrayList(); ArrayList list = new ArrayList();
if (null != zxUrl){ if (null != zxUrl) {
for (String split:zxUrl) { for (String split : zxUrl) {
boolean arrayList=Collections.addAll(list,split); boolean arrayList = Collections.addAll(list, split);
shopZx.setAskImgList(list); shopZx.setAskImgList(list);
} }
} }
int likedId =shopZx.getZxid(); int likedId = shopZx.getZxid();
if(shopZx.getUserId()==null&&""!=shopZx.getUserId()){ if (shopZx.getUserId() == null && "" != shopZx.getUserId()) {
map.put("code",1); map.put("code", 1);
map.put("msg","用户不存在!请重新开始!"); map.put("msg", "用户不存在!请重新开始!");
return map; return map;
} }
shopZx.setUserId(shopZx.getUserId().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2")); shopZx.setUserId(shopZx.getUserId().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));
if(null!=inviteCode&&""!=inviteCode) { if (null != inviteCode && "" != inviteCode) {
//用户个人邀请码查询用户数据 //用户个人邀请码查询用户数据
User user=usersMapper.InvitedCode2(inviteCode); User user = usersMapper.InvitedCode2(inviteCode);
String userLikeId=user.getUserId(); String userLikeId = user.getUserId();
if(null==userLikeId){ if (null == userLikeId) {
map.put("code",1); map.put("code", 1);
map.put("msg","用户不存在,请重新登陆!"); map.put("msg", "用户不存在,请重新登陆!");
return map; return map;
} }
userLikes d = LikesMapper.selectlikes(userLikeId, likedId); userLikes d = LikesMapper.selectlikes(userLikeId, likedId);
...@@ -342,12 +352,13 @@ public class UploadServiceImpl implements UploadService { ...@@ -342,12 +352,13 @@ public class UploadServiceImpl implements UploadService {
} }
} }
} }
map.put("data",shopZxList); map.put("data", shopZxList);
return map; return map;
} }
/** /**
* 资讯点赞实现 * 资讯点赞实现
*
* @param * @param
* @return * @return
*/ */
...@@ -355,39 +366,42 @@ public class UploadServiceImpl implements UploadService { ...@@ -355,39 +366,42 @@ public class UploadServiceImpl implements UploadService {
public Map Ilike(Integer zxid, String inviteCode) { public Map Ilike(Integer zxid, String inviteCode) {
Map map = new HashMap(); Map map = new HashMap();
//用户个人邀请码查询用户数据 //用户个人邀请码查询用户数据
User user=usersMapper.InvitedCode2(inviteCode); User user = usersMapper.InvitedCode2(inviteCode);
//用户等于null //用户等于null
if(null == user || "".equals(user)){ if (null == user || "".equals(user)) {
map.put("code",1); map.put("code", 1);
map.put("msg","用户信息不存在,请先注册!"); map.put("msg", "用户信息不存在,请先注册!");
return map; return map;
//用户存在 //用户存在
}else { } else {
//判断该用户是否点过赞,如果点过赞,就返回信息告知前端, //判断该用户是否点过赞,如果点过赞,就返回信息告知前端,
String userLikeId=user.getUserId(); String userLikeId = user.getUserId();
int likedId= zxid; int likedId = zxid;
userLikes b= LikesMapper.selectlikes(userLikeId, likedId); userLikes b = LikesMapper.selectlikes(userLikeId, likedId);
if(b==null){ if (b == null) {
// 没有点过的话,就进行插入点赞记录表,更新点赞数 // 没有点过的话,就进行插入点赞记录表,更新点赞数
Integer likedType=0;//点赞类型为扩展类型,暂时默认0 Integer likedType = 0;//点赞类型为扩展类型,暂时默认0
Integer likedStaus=1; //更新点赞状态 Integer likedStaus = 1; //更新点赞状态
LikesMapper.addlikes(userLikeId,likedId,likedStaus,likedType); LikesMapper.addlikes(userLikeId, likedId, likedStaus, likedType);
shopZx shopZx = shopZxMapper.selectByzxid(zxid); shopZx shopZx = shopZxMapper.selectByzxid(zxid);
int a = shopZx.getZxLikes(); int a = shopZx.getZxLikes();
Integer zxLikes=shopZx.setZxLikes(a + 1); Integer zxLikes = shopZx.setZxLikes(a + 1);
shopZxMapper.updateByzxid(zxid,zxLikes); shopZxMapper.updateByzxid(zxid, zxLikes);
map.put("LikedStatus",likedStaus); map.put("LikedStatus", likedStaus);
map.put("code",0); map.put("code", 0);
map.put("msg","点赞成功!"); map.put("msg", "点赞成功!");
}else { } else {
map.put("code",1); map.put("code", 1);
map.put("msg","点赞失败!"); map.put("msg", "点赞失败!");
}; }
;
} }
return map; return map;
} }
/** /**
* 资讯审核 * 资讯审核
*
* @param zxid * @param zxid
* @return * @return
*/ */
...@@ -396,16 +410,17 @@ public class UploadServiceImpl implements UploadService { ...@@ -396,16 +410,17 @@ public class UploadServiceImpl implements UploadService {
Map map = new HashMap(); Map map = new HashMap();
try { try {
shopZx shopZx = shopZxMapper.selectByzxid(zxid); shopZx shopZx = shopZxMapper.selectByzxid(zxid);
if(null!=shopZx){ if (null != shopZx) {
Integer ZxToExamine=shopZx.setZxToExamine(1); Integer ZxToExamine = shopZx.setZxToExamine(1);
shopZxMapper.updateZxToExaminezxid(zxid,ZxToExamine); shopZxMapper.updateZxToExaminezxid(zxid, ZxToExamine);
} }
map.put("code",0); map.put("code", 0);
map.put("msg","审核通过!"); map.put("msg", "审核通过!");
}catch ( BaseException e){ } catch (BaseException e) {
map.put("code",1); map.put("code", 1);
map.put("msg","审核失败!"); map.put("msg", "审核失败!");
}; }
;
return map; return map;
} }
} }
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