|
@@ -2,6 +2,7 @@ package com.gis.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.gis.common.constant.CmdConstant;
|
|
import com.gis.common.constant.CmdConstant;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.constant.ConfigConstant;
|
|
import com.gis.common.constant.MsgCode;
|
|
import com.gis.common.constant.MsgCode;
|
|
@@ -37,6 +38,7 @@ public class UploadServiceImpl implements UploadService {
|
|
String originalFilename = file.getOriginalFilename();
|
|
String originalFilename = file.getOriginalFilename();
|
|
String suffix = StringUtils.substringAfterLast(originalFilename, ".");
|
|
String suffix = StringUtils.substringAfterLast(originalFilename, ".");
|
|
String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
|
|
String time = DateUtil.format(new Date(), "yyyyMMdd_HHmmssSSS");
|
|
|
|
+ // 目录位置
|
|
String basePath = configConstant.serverBasePath + time;
|
|
String basePath = configConstant.serverBasePath + time;
|
|
String filePath = basePath + "/face." + suffix;
|
|
String filePath = basePath + "/face." + suffix;
|
|
log.info("filePath: " + filePath);
|
|
log.info("filePath: " + filePath);
|
|
@@ -48,7 +50,7 @@ public class UploadServiceImpl implements UploadService {
|
|
log.info("文件写入完成");
|
|
log.info("文件写入完成");
|
|
|
|
|
|
// 换装并上传
|
|
// 换装并上传
|
|
- ossUrl = cmdReloadAndUploadOss(filePath, faceSwapName, type);
|
|
|
|
|
|
+ ossUrl = cmdReloadAndUploadOss(filePath, basePath, type, time);
|
|
return Result.success(ossUrl);
|
|
return Result.success(ossUrl);
|
|
//发消息到mq
|
|
//发消息到mq
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -58,20 +60,47 @@ public class UploadServiceImpl implements UploadService {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private String cmdReloadAndUploadOss(String input, String faceSwapName, String type) throws Exception {
|
|
|
|
- String output = configConstant.serverBasePath + faceSwapName;
|
|
|
|
- log.info("output: " + output);
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param input 输入文件地址
|
|
|
|
+ * @param basePath 输出目录
|
|
|
|
+ * @param type 合成图片类型
|
|
|
|
+ * @param dir 目录名称
|
|
|
|
+ * @return
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ private String cmdReloadAndUploadOss(String input, String basePath, String type, String dir) throws Exception {
|
|
|
|
+ log.info("输出目录: " + basePath);
|
|
String cmd = CmdConstant.FACE_SWAP;
|
|
String cmd = CmdConstant.FACE_SWAP;
|
|
cmd = cmd.replace("@input", input);
|
|
cmd = cmd.replace("@input", input);
|
|
- cmd = cmd.replace("@output", output);
|
|
|
|
|
|
+ cmd = cmd.replace("@output", basePath);
|
|
cmd = cmd.replace("@type", type);
|
|
cmd = cmd.replace("@type", type);
|
|
log.info("cmd: {}", cmd);
|
|
log.info("cmd: {}", cmd);
|
|
CmdUtils.callLine(cmd);
|
|
CmdUtils.callLine(cmd);
|
|
- log.info("换装完成: {}", output);
|
|
|
|
|
|
+ log.info("换装完成: {}", basePath);
|
|
|
|
|
|
- String ossKey = configConstant.ossBasePath + faceSwapName;
|
|
|
|
- aliyunOssUtil.upload(output, ossKey);
|
|
|
|
- String ossUrl = configConstant.ossDomain + ossKey;
|
|
|
|
|
|
+ // 检查算法是否生成upload.json
|
|
|
|
+ String uploadJsonPath = basePath + "/upload.json";
|
|
|
|
+ if (!FileUtil.exist(uploadJsonPath)) {
|
|
|
|
+ log.error("算法合成失败,upload.json不存在");
|
|
|
|
+ throw new BaseRuntimeException(MsgCode.e5005, "算法合成失败,upload.json不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String str = FileUtil.readUtf8String(uploadJsonPath);
|
|
|
|
+ JSONObject uploadJson = JSONObject.parseObject(str);
|
|
|
|
+ log.info("uploadJson返回值: {}", uploadJson);
|
|
|
|
+ Integer status = uploadJson.getInteger("status");
|
|
|
|
+ // status=0 正常, 其他异常
|
|
|
|
+ if (status != 0) {
|
|
|
|
+ String msg = uploadJson.getString("msg");
|
|
|
|
+ log.error("算法合成失败: " + msg);
|
|
|
|
+ throw new BaseRuntimeException(MsgCode.e5005, "算法合成失败: " + msg);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 合成图片上传oss
|
|
|
|
+ String ossDir = configConstant.ossBasePath + dir;
|
|
|
|
+ aliyunOssUtil.uploadDir(basePath, ossDir);
|
|
|
|
+ String ossUrl = configConstant.ossDomain + ossDir;
|
|
log.info("oss上传完成: {}", ossUrl);
|
|
log.info("oss上传完成: {}", ossUrl);
|
|
return ossUrl;
|
|
return ossUrl;
|
|
|
|
|