Explorar o código

添加公元上传逻辑

tianboguang %!s(int64=2) %!d(string=hai) anos
pai
achega
6a671e2ea3

+ 5 - 1
4dkankan-common/src/main/java/com/fdkankan/common/jedis/JedisUtil.java

@@ -1,6 +1,7 @@
 package com.fdkankan.common.jedis;
 
 import lombok.extern.log4j.Log4j2;
+import org.springframework.util.ObjectUtils;
 import redis.clients.jedis.*;
 
 import java.io.*;
@@ -73,8 +74,11 @@ public class JedisUtil {
                                 String[] addressInfo = addressArr[i].split(":");
                                 String host = addressInfo[0];
                                 int port = Integer.valueOf(addressInfo[1]);
+                                log.info("初始化连接,host:{},port:{},password:{}", host, port, password);
                                 JedisShardInfo jedisShardInfo = new JedisShardInfo(host, port, 10000);
-                                jedisShardInfo.setPassword(password);
+                                if (!ObjectUtils.isEmpty(password)) {
+                                    jedisShardInfo.setPassword(password);
+                                }
                                 jedisShardInfos.add(jedisShardInfo);
                             }
                             shardedJedisPool = new ShardedJedisPool(config, jedisShardInfos);

+ 23 - 15
4dkankan-modeling/src/main/java/com/fdkankan/modeling/message/BuildSceneReceiver.java

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.base.util.FileUtil;
 import com.fdkankan.common.constant.ConstantFilePath;
 import com.fdkankan.common.constant.ConstantUrl;
-import com.fdkankan.common.jedis.JedisUtil;
 import com.fdkankan.common.jedis.KeyConsts;
 import com.fdkankan.common.push.Demo;
 import com.fdkankan.common.util.FileUtils;
@@ -24,6 +23,7 @@ import com.fdkankan.scene.util.CreateObjUtil;
 import com.fdkankan.user.entity.UserEntity;
 import com.fdkankan.user.service.IUserService;
 import com.fdkankan.utils.DingDingUtils;
+import com.fdkankan.utils.GYUploadToOssUtil;
 import com.rabbitmq.client.Channel;
 import com.taobao.api.ApiException;
 import lombok.extern.log4j.Log4j2;
@@ -57,6 +57,12 @@ public class BuildSceneReceiver {
     @Autowired
     private UploadToOssUtil uploadToOssUtil;
 
+    @Autowired
+    private GYUploadToOssUtil gYUploadToOssUtil;
+
+    @Value("${gy.company.id}")
+    private String gyCompanyId;
+
     @Value("${oss.type}")
     private String ossType;
 
@@ -76,6 +82,7 @@ public class BuildSceneReceiver {
             SysConstants.SYSTEM_BUILDING = false;
             channel.basicNack(deliveryTag, true, true);
             log.error("服务实例:{} 正在关闭,退出构建!", SysConstants.hostName);
+            return;
         }
         if (ObjectUtils.isEmpty(content)) {
             SysConstants.SYSTEM_BUILDING = false;
@@ -129,21 +136,16 @@ public class BuildSceneReceiver {
 
         // 初始化日志参数
         logRecord.setSceneNum(strs[4]);
-        String dataSource = strs[1];
+        String dataSource;
+        if (strs[2].contains("https:")) {
+            dataSource = strs[1];
+        } else {
+            dataSource = strs[1].substring(0, strs[1].lastIndexOf("/") + 1).concat(strs[2]);
+        }
         logRecord.setDataSource(dataSource);
 
-        // 设置缓存锁
-        String key = KeyConsts.SCENE_BUILDING + strs[4];
-        // 获取缓存锁,防止重复消费
-        Long building = JedisUtil.incrBy(key, 1);
         // 记录入库
         modelingLogService.insert(logRecord);
-        if (building.compareTo(1L) != 0) {
-            log.error("服务:{},重复构建:{}",SysConstants.hostName,logRecord.getSceneNum());
-            throw new BuildException(BuildStatusEnum.REPEAT);
-        }else{
-            JedisUtil.expire(key,SysConstants.modelTimeOut);
-        }
     }
 
     private void buildScene(String content, BuildLog logRecord) throws Exception {
@@ -456,8 +458,16 @@ public class BuildSceneReceiver {
             } else {
                 userService.updateUserUsedSpaceBySceneNum(userEntity.getId(), projectNum);
             }
-        }
 
+            // 上传公元数据
+            if (!ObjectUtils.isEmpty(scene.getUserId())) {
+                UserEntity sceneUser = userService.findById(scene.getUserId());
+                if (!ObjectUtils.isEmpty(sceneUser.getCompanyId()) && gyCompanyId.equals(sceneUser.getCompanyId()+"")) {
+                    gYUploadToOssUtil.uploadMulFiles(map);
+                }
+            }
+
+        }
         CreateObjUtil.deleteFile(path.replace(ConstantFilePath.BUILD_MODEL_PATH, "/") + "/capture");
     }
 
@@ -466,8 +476,6 @@ public class BuildSceneReceiver {
             log.info("服务{} 计算结束:{},计算状态:{}", SysConstants.hostName, buildLog.getSceneNum(),buildStatusEnum.getDesc());
             // 释放缓存锁
             if(!buildStatusEnum.equals(BuildStatusEnum.REPEAT)){
-                JedisUtil.del(KeyConsts.SCENE_BUILDING + buildLog.getSceneNum());
-
                 SceneProEntity scene = sceneProService.findBySceneNum(buildLog.getSceneNum());
                 if(scene != null){
                     JSONObject statusJson = new JSONObject();

+ 95 - 0
4dkankan-modeling/src/main/java/com/fdkankan/utils/GYUploadToOssUtil.java

@@ -0,0 +1,95 @@
+package com.fdkankan.utils;
+
+import com.aliyun.oss.OSSClient;
+import com.aliyun.oss.model.ObjectMetadata;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import java.io.File;
+import java.util.Map;
+
+@Slf4j
+@Component
+public class GYUploadToOssUtil {
+
+	@Value("${gy.oss.point:http://oss-cn-shenzhen.aliyuncs.com}")
+	private String point;
+
+	@Value("${gy.oss.key:LTAI64um4wLEwK7q}")
+	private String key;
+
+	@Value("${gy.oss.secrey:jRPX721aKkprhgNIaoYHMG5BXfQ6vw}")
+	private String secrey;
+
+	@Value("${gy.oss.bucket:jiazhuangvr1}")
+	private String bucket;
+
+	@Value("${oss.type}")
+	private String type;
+
+
+	public void upload(String filePath, String key1) {
+		OSSClient ossClient = new OSSClient(point, key, secrey);
+		try {
+			File file = new File(filePath);
+			if (!file.exists()) {
+				log.error("要上传的文件不存在:" + filePath);
+			}
+
+			ObjectMetadata metadata = new ObjectMetadata();
+			if(filePath.contains(".jpg")){
+				metadata.setContentType("image/jpeg");
+			}
+			ossClient.putObject(bucket, key1, new File(filePath), metadata);
+		} catch (Exception e) {
+			log.error(e.toString() + filePath);
+		}
+	}
+
+	public void upload2(String filePath, String key1) {
+		if("oss".equals(type)){
+			OSSClient ossClient = new OSSClient(point, key, secrey);
+			try {
+				ObjectMetadata metadata = new ObjectMetadata();
+				if(filePath.contains(".jpg")){
+					metadata.setContentType("image/jpeg");
+				}
+				if(filePath.contains(".mp4")){
+					metadata.setContentType("video/mp4");
+				}
+				if(filePath.contains(".mp3")){
+					metadata.setContentType("audio/mp3");
+				}
+				ossClient.putObject(bucket, key1, new File(filePath), metadata);
+			} catch (Exception e) {
+				log.error(e.toString() + filePath);
+			}
+		}
+	}
+
+	//上传的数据是文件夹,参数是文件夹路径,key是上传后的文件名
+	public void uploadMulFiles(Map<String, String> filepaths) {
+		if (filepaths == null) {
+			return;
+		}
+//		log.info("开始批量上传到七牛:" + new Date().toString());
+		Long start = System.currentTimeMillis();
+		log.info("开始批量上传到公元阿里云:" + start);
+		if (filepaths.size() > 50) {
+			for (String filePath : filepaths.keySet()) {
+				// log.info("文件:"+key);
+				upload2(filePath, filepaths.get(filePath));
+			}
+		} else {
+			for (String filePath : filepaths.keySet()) {
+//				log.info("文件:" + filePath + "到七牛:" + filepaths.get(filePath));
+				log.info("文件:" + filePath + "到阿里云:" + filepaths.get(filePath));
+				upload(filePath, filepaths.get(filePath));
+			}
+		}
+		log.info("批量上传公元阿里云完毕:" + (System.currentTimeMillis() - start));
+	}
+
+
+}

+ 2 - 0
4dkankan-modeling/src/main/resources/application.properties

@@ -138,4 +138,6 @@ hot.domain.list=https://testopen.4dkankan.com/domainList/hot
 #删除领域中的热点数据
 hot.delete=/deleteHot
 
+gy.company.id=1058
+