Commit 08137cef authored by m1991's avatar m1991

资讯模块数据——视频功能修复

parent 93ce28f5
...@@ -20,7 +20,7 @@ public interface ShopZxMapper extends BaseMapper<shopZx> { ...@@ -20,7 +20,7 @@ public interface ShopZxMapper extends BaseMapper<shopZx> {
* @param * @param
* @return 1 * @return 1
*/ */
int zxadd(@Param("zxUrl") String zxUrl,@Param("userId") String userId,@Param("zxName") String zxName,@Param("zxField") String zxField,@Param("imgUrl") String imgUrl,@Param("zxAddress") String zxAddress); int zxadd(@Param("zxUrl") String zxUrl,@Param("zxField") String zxField,@Param("zxAddress") String zxAddress,@Param("inviteCode") String inviteCode,@Param("zxDate") String zxDate);
/** /**
* 查询资讯数据 * 查询资讯数据
......
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
</sql> </sql>
<sql id="cols_exclude_id"> <sql id="cols_exclude_id">
zxUrl,zxField,zxAddress,inviteCode zxUrl,zxField,zxAddress,inviteCode,zxDate
</sql> </sql>
<sql id="vals"> <sql id="vals">
#{zxUrl},#{zxField},#{imgUrl},#{zxAddress},#{inviteCode} #{zxUrl},#{zxField},#{zxAddress},#{inviteCode},#{zxDate}
</sql> </sql>
<!--资讯内容插入--> <!--资讯内容插入-->
<insert id="zxadd" parameterType="cn.wisenergy.model.app.shopZx"> <insert id="zxadd" parameterType="cn.wisenergy.model.app.shopZx">
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</insert> </insert>
<!--资讯内容倒叙查询--> <!--资讯内容倒叙查询-->
<select id="findAll" parameterType="java.lang.Integer" resultType="cn.wisenergy.model.app.shopZx"> <select id="selectPage" parameterType="java.lang.Integer" resultType="cn.wisenergy.model.app.shopZx">
select select
b.zx_id as zxid, b.zx_id as zxid,
b.zx_url as zxUrl, b.zx_url as zxUrl,
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
b.invite_code as inviteCode, b.invite_code as inviteCode,
a.user_id as userId, a.user_id as userId,
a.head_image as headImage a.head_image as headImage
from shop_zx b inner join user_info a ON a.invite_code=b.inviteCode from shop_zx b inner join user_info a ON a.invite_code=b.invite_code
WHERE zx_to_examine!=0 WHERE zx_to_examine!=0
order by zxid desc limit #{pageNum},#{pageSize} order by zxid desc limit #{pageNum},#{pageSize}
</select> </select>
......
...@@ -6,6 +6,7 @@ import org.springframework.core.io.Resource; ...@@ -6,6 +6,7 @@ import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -20,31 +21,24 @@ public interface UploadService { ...@@ -20,31 +21,24 @@ public interface UploadService {
* @param request * @param request
* @return * @return
*/ */
Map<String, Object> uploadVideo(MultipartFile file,HttpServletRequest request,String userId,String zxField,String zxAddress) throws Exception; Map<String, Object> uploadVideo(MultipartFile file,HttpServletRequest request,String zxField,String zxAddress,String inviteCode) throws Exception;
/** /**
* TODO 图片文件上传 * TODO 图片文件上传
* @param request * @param request
* @param userId
* @param zxField * @param zxField
* @param zxAddress * @param zxAddress
* @return * @return
*/ */
Map<String, Object> uploadImage(MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception; Map<String, Object> uploadImage(MultipartFile file, HttpServletRequest request, String zxField, String zxAddress,String inviteCode) throws Exception;
/**
* TODO 项目目录下的图片文件上传
* @param request
* @return
*/
Map<String, Object> getImageUrl(HttpServletRequest request) throws Exception;
/** /**
* TODO 多文件上传 * TODO 多文件上传
* @param file * @param file
* @return * @return
*/ */
List imageUpload( MultipartFile[] file,String userId, String zxField, String zxAddress); List imageUpload( MultipartFile[] file, String zxField, String zxAddress,String inviteCode);
String storeFile(MultipartFile file); String storeFile(MultipartFile file);
Resource loadFileAsResource(String fileName); Resource loadFileAsResource(String fileName);
......
...@@ -4,8 +4,6 @@ import cn.wisenergy.common.utils.*; ...@@ -4,8 +4,6 @@ import cn.wisenergy.common.utils.*;
import cn.wisenergy.model.app.shopZx; import cn.wisenergy.model.app.shopZx;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.apache.commons.io.FilenameUtils;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -52,7 +50,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -52,7 +50,7 @@ public class UploadServiceImpl implements UploadService {
* 视频文件上传 * 视频文件上传
*/ */
@Override @Override
public Map<String, Object> uploadVideo(MultipartFile file,HttpServletRequest request,String userId,String zxField, String zxAddress) throws Exception { public Map<String, Object> uploadVideo(MultipartFile file,HttpServletRequest request,String zxField,String zxAddress,String inviteCode) throws Exception {
Map<String, Object> resultMap=new HashMap<String, Object>(); Map<String, Object> resultMap=new HashMap<String, Object>();
/** /**
...@@ -84,19 +82,20 @@ public class UploadServiceImpl implements UploadService { ...@@ -84,19 +82,20 @@ public class UploadServiceImpl implements UploadService {
//将内存中的数据写入磁盘 //将内存中的数据写入磁盘
file.transferTo(newFile); file.transferTo(newFile);
//视频上传保存url //视频上传保存url
String videoUrl = basePath + newFileName; String zxUrl = 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(zxUrl, framefile, imgUrlSave);
resultMap.put("videoUrl", videoUrl); resultMap.put("zxUrl", zxUrl);
resultMap.put("imgUrl", imgUrl); resultMap.put("imgUrl", imgUrl);
resultMap.put("returnCode", 200); resultMap.put("returnCode", 0);
//System.out.println("上传的文件名为:"+fileName+",后缀名为:"+newFileName); //System.out.println("上传的文件名为:"+fileName+",后缀名为:"+newFileName);
shopZxMapper.zxadd(zxUrl,zxField,zxAddress,inviteCode, String.valueOf(zxDate));
return resultMap; return resultMap;
} }
...@@ -104,9 +103,14 @@ public class UploadServiceImpl implements UploadService { ...@@ -104,9 +103,14 @@ public class UploadServiceImpl implements UploadService {
* 图片文件上传 * 图片文件上传
*/ */
@Override @Override
public Map<String, Object> uploadImage(MultipartFile file, HttpServletRequest request,String userId,String zxField, String zxAddress) throws Exception { public Map<String, Object> uploadImage(MultipartFile file, HttpServletRequest request,String zxField, String zxAddress,String inviteCode) throws Exception {
Map<String, Object> resultMap=new HashMap<String, Object>(); Map<String, Object> resultMap=new HashMap<String, Object>();
/**
* 生成当前时间戳
*/
BigInteger zxDate= BigInteger.valueOf(System.currentTimeMillis());
String basePath = request.getScheme() + "://" + request.getServerName() String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort()+"/mimi/upload/images/"; + ":" + request.getServerPort()+"/mimi/upload/images/";
...@@ -116,7 +120,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -116,7 +120,7 @@ public class UploadServiceImpl implements UploadService {
String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名 String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名
String newzxName = time+suffixName; //文件新名称 String newzxName = time+suffixName; //文件新名称
//设置文件存储路径,可以存放在你想要指定的路径里面 //设置文件存储路径,可以存放在你想要指定的路径里面
String rootPath="D:/mimi/"+File.separator+"upload/images/"; //上传图片存放位置 String rootPath="/opt/upload/video/"; //上传图片存放位置
String filePath = rootPath+newzxName; String filePath = rootPath+newzxName;
File newFile = new File(filePath); File newFile = new File(filePath);
...@@ -129,77 +133,25 @@ public class UploadServiceImpl implements UploadService { ...@@ -129,77 +133,25 @@ public class UploadServiceImpl implements UploadService {
//将内存中的数据写入磁盘 //将内存中的数据写入磁盘
file.transferTo(newFile); file.transferTo(newFile);
//图片上传保存url //图片上传保存url
String imgUrl = basePath + newzxName; String zxUrl = basePath + newzxName;
resultMap.put("imgUrl", imgUrl); resultMap.put("zxUrl", zxUrl);
resultMap.put("returnCode", 0); resultMap.put("returnCode", 0);
String zxUrl=null; shopZxMapper.zxadd(zxUrl,zxField,zxAddress,inviteCode, String.valueOf(zxDate));
shopZxMapper.zxadd(zxUrl,userId,zxName,zxField,imgUrl,zxAddress);
return resultMap; return resultMap;
} }
/**
* 项目目录下的图片文件上传
*/
@Override @Override
public Map<String, Object> getImageUrl(HttpServletRequest request) throws Exception { public List imageUpload(MultipartFile[] files, String zxField, String zxAddress,String inviteCode) {
Map<String,Object> result = new HashMap<String,Object>();
//获取图片在项目路径下的地址
String basePath= ClassUtils.getDefaultClassLoader().getResource("").getPath();
String oldPath=basePath+"/static/images/animate.png";
Long res =System.currentTimeMillis();
//设置文件存储路径,可以存放在你想要指定的路径里面
String rootPath="D:/mimi/"+File.separator+"upload/images/";
// 新文件名
String newzxName =res + oldPath.substring(oldPath.lastIndexOf("."));
//新文件
File newFile=new File(rootPath+File.separator+newzxName);
//判断文件目录是否存在
if(!newFile.getParentFile().exists()){
//如果目标文件所在的目录不存在,则创建父目录
newFile.getParentFile().mkdirs();
}
//-------把图片文件写入磁盘 start ----------------
FileOutputStream fos = new FileOutputStream(newFile);
//读取本地文件
File localFile = new File(oldPath);
//获取本地文件输入流
InputStream stream=new FileInputStream(localFile);
//写入目标文件
byte[] buffer=new byte[1024*1024];
int byteRead=0;
//stream.read(buffer) 每次读到的数据存放在 buffer 数组中
while((byteRead=stream.read(buffer))!=-1){
//在 buffer 数组中 取出数据 写到 (输出流)磁盘上
fos.write(buffer, 0, byteRead);
fos.flush();
}
fos.close();
stream.close();
//-------把图片文件写入磁盘 end ----------------
//服务器图片地址
String baseURL = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort()+"/mimi/upload/images/";
String imgUrl=baseURL+newzxName;
result.put("imgUrl", imgUrl);
result.put("returnCode", 0);
return result;
}
//, String userId, String zxField, String zxAddress
@Override /**
public List imageUpload(MultipartFile[] files,String userId, String zxField, String zxAddress) { * 生成当前时间戳
*/
BigInteger zxDate= BigInteger.valueOf(System.currentTimeMillis());
//获取上传图片数量,打印在控制台 //获取上传图片数量,打印在控制台
System.out.println("上传图片数量" + files.length); System.out.println("上传图片数量" + files.length);
//创建集合 //创建集合
List<Map<String, Object>> root = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> root = new ArrayList<Map<String, Object>>();
String imgUrl = "";
String zxName=null;
String fileName=null; String fileName=null;
String zxUrl=null; String zxUrl=null;
// 要上传的目标文件存放的绝对路径 // 要上传的目标文件存放的绝对路径
...@@ -226,16 +178,14 @@ public class UploadServiceImpl implements UploadService { ...@@ -226,16 +178,14 @@ public class UploadServiceImpl implements UploadService {
//重新生成文件名 //重新生成文件名
fileName = UUID.randomUUID() + suffixName; fileName = UUID.randomUUID() + suffixName;
zxUrl=""; zxUrl+=localPath+fileName+",";
zxName += fileName+",";
imgUrl+=localPath+fileName+",";
// shopZxMapper.zxadd(zxUrl,userId,zxName,zxField,imgUrl,zxAddress); // shopZxMapper.zxadd(zxUrl,userId,zxName,zxField,imgUrl,zxAddress);
if (FileUtils.upload(file, localPath, fileName)) { if (FileUtils.upload(file, localPath, fileName)) {
//文件存放的相对路径(一般存放在数据库用于img标签的src) //文件存放的相对路径(一般存放在数据库用于img标签的src)
String relativePath = "img/" + fileName; String relativePath = "img/" + fileName;
result.put("relativePath", relativePath);//前端根据是否存在该字段来判断上传是否成功 result.put("relativePath", relativePath);//前端根据是否存在该字段来判断上传是否成功
result_msg = "图片上传成功"; result_msg = "图片上传成功";
result.put("imgUrl", imgUrl); result.put("zxUrl", zxUrl);
} else { } else {
result_msg = "图片上传失败"; result_msg = "图片上传失败";
...@@ -250,9 +200,7 @@ public class UploadServiceImpl implements UploadService { ...@@ -250,9 +200,7 @@ public class UploadServiceImpl implements UploadService {
String root_json = JSON.toJSONString(root); String root_json = JSON.toJSONString(root);
System.out.println(root_json); System.out.println(root_json);
result.put("returnCode", 0); result.put("returnCode", 0);
System.out.println(zxName); shopZxMapper.zxadd(zxUrl,zxField,zxAddress,inviteCode, String.valueOf(zxDate));
System.out.println(imgUrl);
shopZxMapper.zxadd(zxUrl,userId,zxName,zxField,imgUrl,zxAddress);
return root; return root;
} }
...@@ -320,15 +268,13 @@ public class UploadServiceImpl implements UploadService { ...@@ -320,15 +268,13 @@ public class UploadServiceImpl implements UploadService {
public List selectPage(Integer pageNum, Integer pageSize) { public List selectPage(Integer pageNum, Integer pageSize) {
List<shopZx> shopZxList = shopZxMapper.selectPage(pageNum,pageSize); List<shopZx> shopZxList = shopZxMapper.selectPage(pageNum,pageSize);
for (shopZx shopZx : shopZxList) { for (shopZx shopZx : shopZxList) {
String imgUrl = shopZx.getZxUrl(); String zxUrl = shopZx.getZxUrl();
String[] split = StringUtils.split(imgUrl, ","); String[] split = StringUtils.split(zxUrl, ",");
if (null != split){ if (null != split){
List<String> strings = Arrays.asList(split); List<String> strings = Arrays.asList(split);
shopZx.setAskImgList(strings); shopZx.setAskImgList(strings);
} }
// if(null!=shopZx.getImgUrl()){
// shopZx.setAskImgList(Arrays.asList(StringUtils.split(shopZx.getImgUrl(), ",")));
// }
} }
return shopZxList; return shopZxList;
} }
......
...@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.math.BigInteger;
@Api(tags = "短信服务测试,邀请码测试") @Api(tags = "短信服务测试,邀请码测试")
@RestController @RestController
@RequestMapping("/ZX") @RequestMapping("/ZX")
...@@ -53,13 +55,32 @@ public class TestController { ...@@ -53,13 +55,32 @@ public class TestController {
public static void main(String [] args){ public static void main(String [] args){
String str = "1,2,3,4,5,6,7,8,9"; /**
String repStr = str.replaceAll(",",""); * 隐藏中间四位的方法
*/
String phone = "18501234234";
String hidenPhone = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
String b = ShareCodeUtil.idToCode(1); // /**
String a= ShareCodeUtil.idToCode(1,0+1); // * 生成当前时间戳
// */
// BigInteger zxDate= BigInteger.valueOf(System.currentTimeMillis());
// /**
// * 去,的写法
// */
// String str = "1,2,3,4,5,6,7,8,9";
// String repStr = str.replaceAll(",","");
//
// /**
// * 调用工具类生成六位邀请码
// */
// String b = ShareCodeUtil.idToCode(1);
// String a= ShareCodeUtil.idToCode(1,0+1);
System.out.println(repStr); System.out.println(hidenPhone);
} }
@ApiOperation(value = "测试短信服务,发送手机号", notes = "测试短信服务,发送手机号", httpMethod = "POST", produces = "application/json; charset=UTF-8") @ApiOperation(value = "测试短信服务,发送手机号", notes = "测试短信服务,发送手机号", httpMethod = "POST", produces = "application/json; charset=UTF-8")
......
...@@ -45,7 +45,6 @@ public class UploadController { ...@@ -45,7 +45,6 @@ public class UploadController {
* *
* @param file * @param file
* @param request * @param request
* @param userId
* @param zxField * @param zxField
* @param zxAddress * @param zxAddress
* @return * @return
...@@ -56,39 +55,32 @@ public class UploadController { ...@@ -56,39 +55,32 @@ public class UploadController {
@ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"), @ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "file", value = "视频文件", dataType = "MultipartFile"), @ApiImplicitParam(name = "file", value = "视频文件", dataType = "MultipartFile"),
@ApiImplicitParam(name = "zxAddress", value = "资讯发布地址", dataType = "String"), @ApiImplicitParam(name = "zxAddress", value = "资讯发布地址", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号(发布人)", required = true, dataType = "String")}) @ApiImplicitParam(name = "inviteCode", value = "用户本人邀请码(发布人)", required = true, dataType = "String")})
@RequestMapping(value = "/uploadVideo", method = RequestMethod.POST) @RequestMapping(value = "/uploadVideo", method = RequestMethod.POST)
public Map<String, Object> uploadVideo(@RequestParam(value = "files")MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception { public Map<String, Object> uploadVideo(@RequestParam(value = "files")MultipartFile file, HttpServletRequest request, String zxField, String zxAddress,String inviteCode) throws Exception {
return uploadService.uploadVideo(file, request, userId, zxField, zxAddress); return uploadService.uploadVideo(file, request, zxField, zxAddress,inviteCode);
} }
/** /**
* 单图片文件上传 * TODO 单图片文件上传
* *
* @param request * @param request
* @return * @return
* @throws Exception * @throws Exception
*/ */
@ApiOperation(value = "资讯信息-文字/单图片上传接口", notes = "返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8") @ApiOperation(value = "用户头像上传接口", notes = "返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "file", value = "单图片", dataType = "MultipartFile"), @ApiImplicitParam(name = "file", value = "单图片", dataType = "MultipartFile"),
@ApiImplicitParam(name = "zxAddress", value = "资讯发布地址", dataType = "String"), @ApiImplicitParam(name = "inviteCode", value = "用户本人邀请码(发布人)", required = true, dataType = "String")})
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
@RequestMapping(value = "/uploadImage", method = RequestMethod.POST) @RequestMapping(value = "/uploadImage", method = RequestMethod.POST)
public Map<String, Object> uploadImage(@RequestParam(value = "files")MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception { public Map<String, Object> uploadImage(@RequestParam(value = "files")MultipartFile file, HttpServletRequest request, String zxField, String zxAddress ,String inviteCode) throws Exception {
return uploadService.uploadImage(file,request,zxField,zxAddress,inviteCode);
return uploadService.uploadImage(file, request, userId, zxField, zxAddress);
} }
/** /**
* 多文件上传 * *
* * * TODO 多文件上传接口
* @param files @RequestParam("file") /**
* * 多文件上传接口
* * T0D0 value = "/fileUpload", produces = "application/json;charset=UTF-8
* * * *
* @return * @return
*/ */
...@@ -99,13 +91,20 @@ public class UploadController { ...@@ -99,13 +91,20 @@ public class UploadController {
@ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"), @ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "files", value = "多图片", paramType = "form", allowMultiple=true, dataType = "__file"), @ApiImplicitParam(name = "files", value = "多图片", paramType = "form", allowMultiple=true, dataType = "__file"),
@ApiImplicitParam(name = "zxAddress", value = "发表地址", dataType = "String"), @ApiImplicitParam(name = "zxAddress", value = "发表地址", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")}) @ApiImplicitParam(name = "inviteCode", value = "用户本人邀请码(发布人)", required = true, dataType = "String")})
@RequestMapping(method = RequestMethod.POST, value = "/multipleImageUpload", headers = "content-type=multipart/form-data") @RequestMapping(method = RequestMethod.POST, value = "/multipleImageUpload", headers = "content-type=multipart/form-data")
public List multipleImageUpload(@RequestParam(value = "files") MultipartFile[] files, String userId, String zxField, String zxAddress) { public List multipleImageUpload(@RequestParam(value = "files") MultipartFile[] files, String zxField, String zxAddress,String inviteCode) {
return uploadService.imageUpload(files, userId, zxField, zxAddress); return uploadService.imageUpload(files, zxField, zxAddress,inviteCode);
} }
/**
* 资讯展示
* @param pageNum
* @param pageSize
* @return
*/
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "从几开始", required = true,dataType = "integer"), @ApiImplicitParam(name = "pageNum", value = "从几开始", required = true,dataType = "integer"),
@ApiImplicitParam(name = "pageSize", value = "一页展示数量", required = true, dataType = "Integger")}) @ApiImplicitParam(name = "pageSize", value = "一页展示数量", required = true, dataType = "Integger")})
......
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