Commit ce89f588 authored by codezwjava's avatar codezwjava

Merge remote-tracking branch 'origin/master'

parents 927bb2ff 08137cef
......@@ -20,7 +20,7 @@ public interface ShopZxMapper extends BaseMapper<shopZx> {
* @param
* @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 @@
</sql>
<sql id="cols_exclude_id">
zxUrl,zxField,zxAddress,inviteCode
zxUrl,zxField,zxAddress,inviteCode,zxDate
</sql>
<sql id="vals">
#{zxUrl},#{zxField},#{imgUrl},#{zxAddress},#{inviteCode}
#{zxUrl},#{zxField},#{zxAddress},#{inviteCode},#{zxDate}
</sql>
<!--资讯内容插入-->
<insert id="zxadd" parameterType="cn.wisenergy.model.app.shopZx">
......@@ -38,7 +38,7 @@
</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
b.zx_id as zxid,
b.zx_url as zxUrl,
......@@ -49,7 +49,7 @@
b.invite_code as inviteCode,
a.user_id as userId,
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
order by zxid desc limit #{pageNum},#{pageSize}
</select>
......
......@@ -6,6 +6,7 @@ import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
......@@ -20,31 +21,24 @@ public interface UploadService {
* @param request
* @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 图片文件上传
* @param request
* @param userId
* @param zxField
* @param zxAddress
* @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 多文件上传
* @param file
* @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);
Resource loadFileAsResource(String fileName);
......
......@@ -4,8 +4,6 @@ import cn.wisenergy.common.utils.*;
import cn.wisenergy.model.app.shopZx;
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.core.io.Resource;
import org.springframework.core.io.UrlResource;
......@@ -52,7 +50,7 @@ public class UploadServiceImpl implements UploadService {
* 视频文件上传
*/
@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>();
/**
......@@ -84,19 +82,20 @@ public class UploadServiceImpl implements UploadService {
//将内存中的数据写入磁盘
file.transferTo(newFile);
//视频上传保存url
String videoUrl = basePath + newFileName;
String zxUrl = basePath + newFileName;
//视频封面图处理
String newImgName = time+".jpg";
String framefile = rootPath + 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("returnCode", 200);
resultMap.put("returnCode", 0);
//System.out.println("上传的文件名为:"+fileName+",后缀名为:"+newFileName);
shopZxMapper.zxadd(zxUrl,zxField,zxAddress,inviteCode, String.valueOf(zxDate));
return resultMap;
}
......@@ -104,9 +103,14 @@ public class UploadServiceImpl implements UploadService {
* 图片文件上传
*/
@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>();
/**
* 生成当前时间戳
*/
BigInteger zxDate= BigInteger.valueOf(System.currentTimeMillis());
String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort()+"/mimi/upload/images/";
......@@ -116,7 +120,7 @@ public class UploadServiceImpl implements UploadService {
String suffixName = zxName.substring(zxName.lastIndexOf("."));//从最后一个.开始截取。截取zxName的后缀名
String newzxName = time+suffixName; //文件新名称
//设置文件存储路径,可以存放在你想要指定的路径里面
String rootPath="D:/mimi/"+File.separator+"upload/images/"; //上传图片存放位置
String rootPath="/opt/upload/video/"; //上传图片存放位置
String filePath = rootPath+newzxName;
File newFile = new File(filePath);
......@@ -129,77 +133,25 @@ public class UploadServiceImpl implements UploadService {
//将内存中的数据写入磁盘
file.transferTo(newFile);
//图片上传保存url
String imgUrl = basePath + newzxName;
String zxUrl = basePath + newzxName;
resultMap.put("imgUrl", imgUrl);
resultMap.put("zxUrl", zxUrl);
resultMap.put("returnCode", 0);
String zxUrl=null;
shopZxMapper.zxadd(zxUrl,userId,zxName,zxField,imgUrl,zxAddress);
shopZxMapper.zxadd(zxUrl,zxField,zxAddress,inviteCode, String.valueOf(zxDate));
return resultMap;
}
/**
* 项目目录下的图片文件上传
*/
@Override
public Map<String, Object> getImageUrl(HttpServletRequest request) throws Exception {
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
public List imageUpload(MultipartFile[] files, String zxField, String zxAddress,String inviteCode) {
@Override
public List imageUpload(MultipartFile[] files,String userId, String zxField, String zxAddress) {
/**
* 生成当前时间戳
*/
BigInteger zxDate= BigInteger.valueOf(System.currentTimeMillis());
//获取上传图片数量,打印在控制台
System.out.println("上传图片数量" + files.length);
//创建集合
List<Map<String, Object>> root = new ArrayList<Map<String, Object>>();
String imgUrl = "";
String zxName=null;
String fileName=null;
String zxUrl=null;
// 要上传的目标文件存放的绝对路径
......@@ -226,16 +178,14 @@ public class UploadServiceImpl implements UploadService {
//重新生成文件名
fileName = UUID.randomUUID() + suffixName;
zxUrl="";
zxName += fileName+",";
imgUrl+=localPath+fileName+",";
zxUrl+=localPath+fileName+",";
// shopZxMapper.zxadd(zxUrl,userId,zxName,zxField,imgUrl,zxAddress);
if (FileUtils.upload(file, localPath, fileName)) {
//文件存放的相对路径(一般存放在数据库用于img标签的src)
String relativePath = "img/" + fileName;
result.put("relativePath", relativePath);//前端根据是否存在该字段来判断上传是否成功
result_msg = "图片上传成功";
result.put("imgUrl", imgUrl);
result.put("zxUrl", zxUrl);
} else {
result_msg = "图片上传失败";
......@@ -250,9 +200,7 @@ public class UploadServiceImpl implements UploadService {
String root_json = JSON.toJSONString(root);
System.out.println(root_json);
result.put("returnCode", 0);
System.out.println(zxName);
System.out.println(imgUrl);
shopZxMapper.zxadd(zxUrl,userId,zxName,zxField,imgUrl,zxAddress);
shopZxMapper.zxadd(zxUrl,zxField,zxAddress,inviteCode, String.valueOf(zxDate));
return root;
}
......@@ -320,15 +268,13 @@ public class UploadServiceImpl implements UploadService {
public List selectPage(Integer pageNum, Integer pageSize) {
List<shopZx> shopZxList = shopZxMapper.selectPage(pageNum,pageSize);
for (shopZx shopZx : shopZxList) {
String imgUrl = shopZx.getZxUrl();
String[] split = StringUtils.split(imgUrl, ",");
String zxUrl = shopZx.getZxUrl();
String[] split = StringUtils.split(zxUrl, ",");
if (null != split){
List<String> strings = Arrays.asList(split);
shopZx.setAskImgList(strings);
}
// if(null!=shopZx.getImgUrl()){
// shopZx.setAskImgList(Arrays.asList(StringUtils.split(shopZx.getImgUrl(), ",")));
// }
}
return shopZxList;
}
......
......@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigInteger;
@Api(tags = "短信服务测试,邀请码测试")
@RestController
@RequestMapping("/ZX")
......@@ -53,13 +55,32 @@ public class TestController {
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")
......
......@@ -45,7 +45,6 @@ public class UploadController {
*
* @param file
* @param request
* @param userId
* @param zxField
* @param zxAddress
* @return
......@@ -56,39 +55,32 @@ public class UploadController {
@ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "file", value = "视频文件", dataType = "MultipartFile"),
@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)
public Map<String, Object> uploadVideo(@RequestParam(value = "files")MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception {
return uploadService.uploadVideo(file, request, userId, zxField, zxAddress);
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, zxField, zxAddress,inviteCode);
}
/**
* 单图片文件上传
* TODO 单图片文件上传
*
* @param request
* @return
* @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({
@ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "file", value = "单图片", dataType = "MultipartFile"),
@ApiImplicitParam(name = "zxAddress", value = "资讯发布地址", dataType = "String"),
@ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
@ApiImplicitParam(name = "inviteCode", value = "用户本人邀请码(发布人)", required = true, dataType = "String")})
@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 {
return uploadService.uploadImage(file, request, userId, zxField, zxAddress);
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);
}
/**
* 多文件上传
*
* @param files @RequestParam("file") /**
* * 多文件上传接口
* * T0D0 value = "/fileUpload", produces = "application/json;charset=UTF-8
* *
* * TODO 多文件上传接口
* *
* @return
*/
......@@ -99,13 +91,20 @@ public class UploadController {
@ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
@ApiImplicitParam(name = "files", value = "多图片", paramType = "form", allowMultiple=true, dataType = "__file"),
@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")
public List multipleImageUpload(@RequestParam(value = "files") MultipartFile[] files, String userId, String zxField, String zxAddress) {
return uploadService.imageUpload(files, userId, zxField, zxAddress);
public List multipleImageUpload(@RequestParam(value = "files") MultipartFile[] files, String zxField, String zxAddress,String inviteCode) {
return uploadService.imageUpload(files, zxField, zxAddress,inviteCode);
}
/**
* 资讯展示
* @param pageNum
* @param pageSize
* @return
*/
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "从几开始", required = true,dataType = "integer"),
@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