|
@@ -0,0 +1,328 @@
|
|
|
+package com.fdkankan.scene.service.impl;
|
|
|
+
|
|
|
+import static com.fdkankan.push.PushMessageConfig.ANDROID_KEY;
|
|
|
+import static com.fdkankan.push.PushMessageConfig.ANDROID_KEY_Z;
|
|
|
+import static com.fdkankan.push.PushMessageConfig.ANDROID_SECRET;
|
|
|
+import static com.fdkankan.push.PushMessageConfig.ANDROID_SECRET_Z;
|
|
|
+import static com.fdkankan.push.PushMessageConfig.IOS_KEY;
|
|
|
+import static com.fdkankan.push.PushMessageConfig.IOS_KEY_Z;
|
|
|
+import static com.fdkankan.push.PushMessageConfig.IOS_SECRET;
|
|
|
+import static com.fdkankan.push.PushMessageConfig.IOS_SECRET_Z;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
+import com.fdkankan.common.constant.UploadFilePath;
|
|
|
+import com.fdkankan.common.util.CreateObjUtil;
|
|
|
+import com.fdkankan.common.util.FileUtil;
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
+import com.fdkankan.dingtalk.DingTalkSendUtils;
|
|
|
+import com.fdkankan.fyun.constant.StorageType;
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.fdkankan.mq.message.BuildSceneMqMessage;
|
|
|
+import com.fdkankan.push.PushMessageConfig;
|
|
|
+import com.fdkankan.push.PushMsgUtil;
|
|
|
+import com.fdkankan.scene.service.IBuildScenePreService;
|
|
|
+import com.taobao.api.ApiException;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.security.InvalidKeyException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Map.Entry;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * TODO
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author dengsixing
|
|
|
+ * @since 2022/3/1
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class BuildScenePreServiceImpl implements IBuildScenePreService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UploadToOssUtil uploadToOssUtil;
|
|
|
+ @Value("${upload.type}")
|
|
|
+ private String ossType;
|
|
|
+ @Autowired
|
|
|
+ private DingTalkSendUtils dingTalkSendUtils;
|
|
|
+ @Value("${environment:dev}")
|
|
|
+ private String environment;
|
|
|
+
|
|
|
+ public static String hostName;
|
|
|
+
|
|
|
+ public static final String DINGTALK_MSG_PATTERN = "**环境**: %s\n\n" +
|
|
|
+ "**服务器名称**: %s\n\n" +
|
|
|
+ "**失败原因**: %s\n\n" +
|
|
|
+ "**num**: %s\n\n" +
|
|
|
+ "**server-path**: %s\n\n";
|
|
|
+// "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
|
|
|
+
|
|
|
+ public static final String contentExt = "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
|
|
|
+
|
|
|
+ @Value("${hostName.filePath:/opt/hosts/hosts.txt}")
|
|
|
+ public void setHostName(String filePath){
|
|
|
+ try {
|
|
|
+ this.hostName = FileUtils.readFile(filePath);
|
|
|
+ log.error("从文件({})中获取服务器名称:{}", filePath,hostName);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("从文件中获取服务器名称失败,文件路径{}", filePath);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, String> getTypeString(String cameraType, String algorithm, String resolution,
|
|
|
+ JSONObject dataJson) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getPath(BuildSceneMqMessage buildSceneMqMessage) throws Exception{
|
|
|
+ String path = buildSceneMqMessage.getPath();
|
|
|
+ String cameraName = buildSceneMqMessage.getCameraName();
|
|
|
+ String fileId = buildSceneMqMessage.getFileId();
|
|
|
+ int cameraType = Integer.parseInt(buildSceneMqMessage.getCameraType());
|
|
|
+ String unicode = buildSceneMqMessage.getUnicode();
|
|
|
+ if(cameraType < 3){
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+ String localPath = cameraName.replace("4DKKPRO_", "")
|
|
|
+ .replace("-fdage", "").toLowerCase() +
|
|
|
+ File.separator + fileId + File.separator + unicode;
|
|
|
+
|
|
|
+ if(cameraType == 5 || cameraType == 6){
|
|
|
+ path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
|
|
|
+ }else if(cameraType == 14) {
|
|
|
+ path = ConstantFilePath.BUILD_MODEL_LASER_PATH + localPath;
|
|
|
+ } else{
|
|
|
+ path = ConstantFilePath.BUILD_MODEL_PATH + localPath;
|
|
|
+ }
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void downLoadSource(BuildSceneMqMessage buildSceneMqMessage,String path) throws Exception{
|
|
|
+ String cameraName = buildSceneMqMessage.getCameraName();
|
|
|
+ String fileId = buildSceneMqMessage.getFileId();
|
|
|
+ String unicode = buildSceneMqMessage.getUnicode();
|
|
|
+ int cameraType = Integer.parseInt(buildSceneMqMessage.getCameraType());
|
|
|
+ String prefix = buildSceneMqMessage.getPrefix();
|
|
|
+ String imgsName = buildSceneMqMessage.getImgsName();
|
|
|
+ if(cameraType < 3){
|
|
|
+ for(int i = 0;i<5;++i){
|
|
|
+ try{
|
|
|
+ FileUtils.downLoadFromUrl(prefix+imgsName+"?m="+new Date().getTime(), imgsName,
|
|
|
+ path + File.separator + "capture");
|
|
|
+ FileUtils.decompress(path + File.separator + "capture" +File.separator+imgsName,
|
|
|
+ path + File.separator + "capture") ;
|
|
|
+ break;
|
|
|
+ }catch(Exception e){
|
|
|
+ log.error(String.format("第%d次下载并解压资源失败", i+1), e);
|
|
|
+ if(i<4)
|
|
|
+ {
|
|
|
+ FileUtils.deleteFile(path + File.separator + "capture" +File.separator+imgsName);
|
|
|
+ FileUtils.delFolder(path + File.separator + "capture" +File.separator+"images");
|
|
|
+ }
|
|
|
+ Thread.sleep(10000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ FileUtils.deleteFile(path + File.separator + "capture" +File.separator+"zip.Zip");
|
|
|
+ }else{
|
|
|
+ String ossPath = ConstantFilePath.OSS_PREFIX + cameraName.replace("4DKKPRO_", "")
|
|
|
+ .replace("-fdage", "").toLowerCase() + File.separator + fileId + File.separator
|
|
|
+ + unicode + File.separator;
|
|
|
+ if(cameraType == 5 || cameraType == 6){
|
|
|
+ path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
|
|
|
+ //下载zip包
|
|
|
+ FileUtils.downLoadFromUrl(prefix + "/" + imgsName + "?m=" + System.currentTimeMillis(), imgsName, path + File.separator + "capture");
|
|
|
+ //解压
|
|
|
+ FileUtils.decompress(path + File.separator + "capture" + File.separator + imgsName,
|
|
|
+ path + File.separator + "capture") ;
|
|
|
+ //删除压缩包
|
|
|
+ FileUtil.delFile(path + File.separator + "capture" + File.separator + imgsName);
|
|
|
+ }else if(cameraType == 14) {
|
|
|
+ CreateObjUtil.ossUtilCp(ossPath,path + File.separator + "capture");
|
|
|
+ } else{
|
|
|
+ CreateObjUtil.ossUtilCp(ossPath,path + File.separator + "capture");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void uploadFileMapHandler(String num, int cameraType, Map<String, String> map) {
|
|
|
+
|
|
|
+ String dataPath = String.format("data/data%s/", num);
|
|
|
+ String imagePath = String.format("images/images%s/", num);
|
|
|
+ String videoPath = String.format("video/video%s/", num);
|
|
|
+
|
|
|
+ String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
|
+ String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
|
|
|
+ String videosViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
|
|
|
+
|
|
|
+ map.entrySet().parallelStream().forEach(entry -> {
|
|
|
+
|
|
|
+ String key = entry.getKey();
|
|
|
+ String value = entry.getValue();
|
|
|
+ if(value.contains(dataPath)){
|
|
|
+ map.put(key, value.replace(dataPath, dataViewPath));
|
|
|
+ }
|
|
|
+ if(value.contains(imagePath)){
|
|
|
+ map.put(key, value.replace(imagePath, imgViewPath));
|
|
|
+ }
|
|
|
+ if(value.contains(videoPath)){
|
|
|
+ map.put(key, value.replace(videoPath, videosViewPath));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void uploadCaches(String num, Map<String,String> map, String path){
|
|
|
+
|
|
|
+ String sceneNumPAth = String.format("scene/%s", num);
|
|
|
+
|
|
|
+ List<String> imagesList = FileUtil.getFileList(path + "/caches/images");
|
|
|
+ log.info("caches/images_path:{}", path + "/caches/images");
|
|
|
+ if(CollUtil.isNotEmpty(imagesList)){
|
|
|
+ log.info("上传的caches/images文件列表:{}", imagesList.toString());
|
|
|
+ imagesList.stream().forEach(str -> map.put(str, str.replace(path, sceneNumPAth)));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> videosList = FileUtil.getFileList(path + "/caches/videos");
|
|
|
+ if(CollUtil.isNotEmpty(videosList)){
|
|
|
+ log.info("上传的caches/videos文件列表:{}", videosList.toString());
|
|
|
+ videosList.stream().forEach(str -> map.put(str, str.replace(path, sceneNumPAth)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void copyToEditDir(String num) throws IOException {
|
|
|
+
|
|
|
+ String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
|
|
|
+ String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
|
|
|
+
|
|
|
+ String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
|
|
|
+ String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
|
|
|
+ map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
|
|
|
+ map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
|
|
|
+
|
|
|
+ for (Entry<String, String> entry : map.entrySet()) {
|
|
|
+ uploadToOssUtil.copyFiles(entry.getValue(), entry.getKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void sendSms(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
|
|
|
+ log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
|
|
|
+ if(Objects.isNull(pushChannel) && StrUtil.isBlank(pushToken))
|
|
|
+ return;
|
|
|
+
|
|
|
+ try{
|
|
|
+ if(StorageType.AWS.code().equals(ossType)){
|
|
|
+ PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
|
|
|
+ sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ PushMessageConfig demo = null;
|
|
|
+ if(pushChannel == 0){
|
|
|
+ if(cameraType == 10 || cameraType == 13){
|
|
|
+ //ios
|
|
|
+ log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY_Z, IOS_SECRET_Z);
|
|
|
+ demo = new PushMessageConfig(IOS_KEY_Z, IOS_SECRET_Z);
|
|
|
+ demo.sendIOSUnicast(pushToken, "四维看看Minion",
|
|
|
+ sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
|
|
|
+ }else {
|
|
|
+ //ios
|
|
|
+ log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY, IOS_SECRET);
|
|
|
+ demo = new PushMessageConfig(IOS_KEY, IOS_SECRET);
|
|
|
+ demo.sendIOSUnicast(pushToken, "四维看看Pro",
|
|
|
+ sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if(cameraType == 10 || cameraType == 13){
|
|
|
+ //ios
|
|
|
+ //安卓
|
|
|
+ log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY_Z, ANDROID_SECRET_Z);
|
|
|
+ demo = new PushMessageConfig(ANDROID_KEY_Z, ANDROID_SECRET_Z);
|
|
|
+ demo.sendAndroidUnicast2(pushToken, "四维看看Minion",
|
|
|
+ sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
|
|
|
+ }else {
|
|
|
+ //安卓
|
|
|
+ log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY, ANDROID_SECRET);
|
|
|
+ demo = new PushMessageConfig(ANDROID_KEY, ANDROID_SECRET);
|
|
|
+ demo.sendAndroidUnicast(pushToken, "四维看看Pro",
|
|
|
+ sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("消息推送结束!");
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("推送消息失败:", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handFail(String reason, String serverPath, String num, String hostName, String contentExt) {
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ String contentFormat = StrUtil.isBlank(contentExt) ? this.DINGTALK_MSG_PATTERN : this.DINGTALK_MSG_PATTERN + contentExt;
|
|
|
+ String content = String.format(contentFormat, this.environment, hostName, reason, num, serverPath, num, num);
|
|
|
+ log.error("发送钉钉消息,content:{}", content);
|
|
|
+ dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
|
|
|
+ } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
|
|
|
+ log.error("发送钉钉消息失败", apiException);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long calUseSpace(Map<String, String> uploadFile) {
|
|
|
+ File spaceFile = null;
|
|
|
+ long space = 0L;
|
|
|
+ for (String key : uploadFile.keySet()) {
|
|
|
+ spaceFile = new File(key);
|
|
|
+ if(spaceFile.exists()){
|
|
|
+ space += spaceFile.length();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return space;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void uploadLogFile(String num, String dataSource) {
|
|
|
+ String dataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
|
|
|
+
|
|
|
+ //todo 待删除old_path
|
|
|
+ uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+num+File.separator+"status.json",
|
|
|
+ "data/data"+num+File.separator+"status.json");
|
|
|
+
|
|
|
+ uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+num+File.separator+"status.json",
|
|
|
+ dataPath+"status.json");
|
|
|
+
|
|
|
+ //上送日志 //todo 待删除old_path
|
|
|
+ uploadToOssUtil.upload(dataSource+File.separator+"console.log",
|
|
|
+ "build_log/"+num+File.separator+"console.log");
|
|
|
+
|
|
|
+ //上送日志
|
|
|
+ uploadToOssUtil.upload(dataSource+File.separator+"console.log",
|
|
|
+ dataPath+"console.log");
|
|
|
+ }
|
|
|
+}
|