Browse Source

Merge branch 'test' of jishutao/jitao-server into prod

liliang4869 7 years ago
parent
commit
bee57f985a

+ 26 - 19
src/main/java/com/goafanti/admin/controller/AdminVideoApiController.java

@@ -61,6 +61,8 @@ public class AdminVideoApiController extends CertifyApiController {
 	private String ffprobePath = null;
 	@Value(value = "${video.path}")
 	private String videoPath = null;
+	@Value(value = "${video.temppath}")
+	private String videoTemppath = null;
 	
 	
 
@@ -72,7 +74,8 @@ public class AdminVideoApiController extends CertifyApiController {
 		AttachmentType attachmentType = AttachmentType.getField(sign);
 		if (attachmentType == AttachmentType.VIDEO) {
 			// 先将视频存在本地文件中
-			String filename = handleVideoFiles(res, req, videoPath);
+			String dir =  videoTemppath + "/convert_before";
+			String filename = handleVideoFiles(res, req, dir);
 			res.setData(filename);
 		} else if (attachmentType == AttachmentType.VIDEO_COVER) {
 			String picturebase = req.getParameter("picturebase");
@@ -146,6 +149,7 @@ public class AdminVideoApiController extends CertifyApiController {
 		
 		// 生成保存到数据库的url
 		String output = System.nanoTime() + ".mp4";
+
 		video.setUrl(createFileName(videoPath) + "/" + output);
 		
 		video.setTranscoding(1);
@@ -153,7 +157,8 @@ public class AdminVideoApiController extends CertifyApiController {
 		result.setData(adminVideoService.insertVideo(video));
 
 		// 压缩视频并将视频
-		videoChange(filename, output, video.getUrl());
+		//output = videoTemppath + "/convert_after";
+		videoChange(filename, output, video.getUrl(), videoTemppath + "/convert_after");
 		
 		return result;
 	}
@@ -200,7 +205,7 @@ public class AdminVideoApiController extends CertifyApiController {
 			String filename = video.getUrl();
 			String output = System.nanoTime() + ".mp4";
 			video.setUrl(createFileName(videoPath) + "/" + output);
-			videoChange(filename, output, video.getUrl());
+			videoChange(filename, output, video.getUrl(), videoTemppath + "/convert_after");
 			
 			//删除原来远程的视频
 			deleteFtpVideo(oldVideo.getUrl());
@@ -220,7 +225,7 @@ public class AdminVideoApiController extends CertifyApiController {
 	}
 
 	// 将文件转码
-	private String videoChange(String input, String output, String url) throws IOException,
+	private String videoChange(String input, String output, String url,String outputdir) throws IOException,
 			InterruptedException, ExecutionException {
 
 		FFmpeg ffmpeg = new FFmpeg(ffmpegPath);
@@ -231,7 +236,7 @@ public class AdminVideoApiController extends CertifyApiController {
 		FFmpegBuilder builder = new FFmpegBuilder();
 		builder.setInput(in) // 输入文件
 				.overrideOutputFiles(true) // 覆盖重复文件
-				.addOutput(output) // 输出文件
+				.addOutput(outputdir+"/"+output) // 输出文件
 				.setFormat("mp4") // 设置格式
 				.setTargetSize(250_000) // 目标大小
 				.disableSubtitle() // 没有子标题
@@ -247,7 +252,7 @@ public class AdminVideoApiController extends CertifyApiController {
 		FFmpegExecutor executor = new FFmpegExecutor(ffmpeg, ffprobe);
 		ExecutorService service = Executors.newCachedThreadPool();
 		// 3.直接new一个FutureTask
-		SubTask subTask = new SubTask(executor, builder, in, url, input, output);
+		SubTask subTask = new SubTask(executor, builder, in, url, input, output, outputdir+"/"+output);
 		FutureTask<Boolean> result = new FutureTask<Boolean>(subTask);
 		// 4.提交任务
 		service.submit(result);
@@ -259,30 +264,30 @@ public class AdminVideoApiController extends CertifyApiController {
 		return "SUCESS";
 	}
 
-	private void updateSql(String url, String filename) {
+	private void updateSql(String url, String tempdir, String filename) {
 		// 修改数据
-		File file = new File(filename);
+		File file = new File(tempdir);
 		JtVideo video = new JtVideo();
 		video.setMd5(FileMD5(file));
 		video.setTranscoding(2);
 		video.setUrl(url);
-		int c = adminVideoService.updateByUrl(video);
-		if (c > 0){
-			url = url.substring(0,url.lastIndexOf("/"));
-			videoChange(url, filename);// 上传到远程
-		}
+		url = url.substring(0,url.lastIndexOf("/"));
+		if(videoChange(url, tempdir, filename)){
+			adminVideoService.updateByUrl(video);//修改状态
+		}// 上传到远程
 	}
 
-	private void videoChange(String url, String filename) {
-		
-		File f2 = new File(filename);// 临时压缩后的文件
+	private boolean videoChange(String url, String tempdir, String filename) {
+		boolean t =false;
+		File f2 = new File(tempdir);// 临时压缩后的文件
 		if (f2.exists()) {
 			// 传到远程服务器
 			FtpUtils ftp = new FtpUtils();
-			ftp.uploadFile(url, filename, filename);
+			t = ftp.uploadFile(url, filename, tempdir);
 			// 删除视频
 			f2.delete();
 		}
+		return t;
 	}
 
 	// 获得文件md5
@@ -315,16 +320,18 @@ public class AdminVideoApiController extends CertifyApiController {
 		private String url;
 		private String input;
 		private String output;
+		private String tempdir;
 
 		public SubTask(FFmpegExecutor executor, FFmpegBuilder builder,
 				FFmpegProbeResult probeResult, String url, String input,
-				String output) {
+				String output, String tempdir) {
 			this.executor = executor;
 			this.builder = builder;
 			this.probeResult = probeResult;
 			this.url = url;
 			this.input = input;
 			this.output = output;
+			this.tempdir = tempdir;
 		}
 
 		public FFmpegExecutor getExecutor() {
@@ -379,7 +386,7 @@ public class AdminVideoApiController extends CertifyApiController {
 				// System.out.println("设置 sate");
 				// latch.wait();
 				state = true;
-				updateSql(url, output);
+				updateSql(url, tempdir,output);
 				// 删除未压缩的视频
 				File f1 = new File(input);
 				f1.delete();

+ 15 - 0
src/main/java/com/goafanti/business/controller/UserJtBusinessController.java

@@ -1,5 +1,6 @@
 package com.goafanti.business.controller;
 
+import java.util.Base64;
 import java.util.Date;
 
 import javax.annotation.Resource;
@@ -21,6 +22,7 @@ import com.goafanti.common.model.JtBusinessCategory;
 import com.goafanti.common.model.JtBusinessProject;
 import com.goafanti.common.model.JtTag;
 import com.goafanti.common.utils.StringUtils;
+import com.goafanti.core.shiro.token.TokenManager;
 
 @RestController
 @RequestMapping(value = "/api/user/jtBusiness")
@@ -154,6 +156,19 @@ public class UserJtBusinessController extends CertifyApiController{
 		}
 		return res;
 	}
+	@RequestMapping(value = "/project/uploadPicture64", method = RequestMethod.POST)
+	public Result uploadProjectPicture64(String picturebase, String filename,String sign) {
+		Result res = new Result();
+ 		byte[] bs=Base64.getDecoder().decode(picturebase);
+		AttachmentType attachmentType = AttachmentType.getField(sign);
+		if (attachmentType == AttachmentType.JT_PROJECT_PICTURE) {
+			//res.setData(handleFiles(res, "/jtProjects/", false, req, sign, ""));
+			res.setData(handleBaseFiles(res, "/jtProjects/", false,bs, sign, TokenManager.getUserId(),filename));
+		} else {
+			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
+		}
+		return res;
+	}
 	
 	/*
 	 * 查询品类

+ 0 - 1
src/main/java/com/goafanti/common/utils/FileUtils.java

@@ -16,7 +16,6 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.multipart.MultipartFile;
 
-import com.goafanti.common.enums.AttachmentType;
 
 public class FileUtils {
 	@Value(value = "${upload.private.path}")

+ 0 - 4
src/main/java/com/goafanti/user/controller/UserRegisterController.java

@@ -2,7 +2,6 @@ package com.goafanti.user.controller;
 
 import java.util.Calendar;
 import java.util.Date;
-import java.util.List;
 import java.util.UUID;
 import javax.annotation.Resource;
 import javax.validation.Valid;
@@ -18,12 +17,9 @@ import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.AFTConstants;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.BaseController;
-import com.goafanti.common.dao.UserMapper;
 import com.goafanti.common.enums.UserAuthentication;
 import com.goafanti.common.enums.UserFields;
 import com.goafanti.common.enums.UserLevel;
-import com.goafanti.common.enums.VoucherSourceType;
-import com.goafanti.common.model.JtVoucherDetail;
 import com.goafanti.common.model.User;
 import com.goafanti.common.utils.InvitationCodeUtils;
 import com.goafanti.common.utils.PasswordUtil;

+ 1 - 0
src/main/resources/props/config_local.properties

@@ -86,5 +86,6 @@ ffmpeg.path=E\:\\mytools\\ffmpeg-20181028-bdfd2e3-win64-static\\bin\\ffmpeg.exe
 ffprobe.path=E\:\\mytools\\ffmpeg-20181028-bdfd2e3-win64-static\\bin\\ffprobe.exe
 
 video.path=local
+video.temppath=F:/data/local/video
 
 collect_flag=true

+ 1 - 0
src/main/resources/props/config_test.properties

@@ -85,5 +85,6 @@ ffmpeg.path=/usr/bin/ffmpeg
 ffprobe.path=/usr/bin/ffprobe
 
 video.path=test
+video.temppath=/data/statics/video
 
 collect_flag=true