| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package com.fdkankan.scene.service.impl;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.io.FileUtil;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.fdkankan.common.util.CmdUtils;
- import com.fdkankan.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.model.constants.ConstantFilePath;
- import com.fdkankan.model.constants.UploadFilePath;
- import com.fdkankan.scene.entity.ScenePlus;
- import com.fdkankan.scene.httpclient.HaixinClient;
- import com.fdkankan.scene.service.IHaixinService;
- import com.fdkankan.scene.service.IScenePlusService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- @Slf4j
- @Service
- public class HaixinServiceImpl implements IHaixinService {
- private static final String API_FDFS_UPLOAD = "/fdfs/api/file/upload";
- private static final String API_SUBMIT_FLOORPLAN = "/ecs/api/panoramicImageService/submitFloorPlan";
- @Value("${haixin.host}")
- private String haixinHost;
- @Resource
- private FYunFileServiceInterface fileServiceInterface;
- @Resource
- private HaixinClient haixinClient;
- @Autowired
- private IScenePlusService scenePlusService;
- @Override
- public void sendCadImgToHaixin(String num) throws Exception {
- log.info("进入场景平面图推送方法");
- ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
- String userViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
- List<String> userKeyS = fileServiceInterface.listRemoteFiles(userViewPath);
- if(CollUtil.isEmpty(userKeyS)){
- return;
- }
- log.info("user列表文件:{}", JSON.toJSONString(userKeyS));
- List<String> cadImgKeys = userKeyS.stream().filter(v->v.contains("cad-style-3-")).collect(Collectors.toList());
- if(CollUtil.isEmpty(cadImgKeys)){
- return;
- }
- log.info("平面图列表文件:{}", JSON.toJSONString(userKeyS));
- String currentTimeMillis = String.valueOf(System.currentTimeMillis());
- String tmpPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + currentTimeMillis + "/";
- cadImgKeys.stream().forEach(key->{
- fileServiceInterface.downloadFile(key, tmpPath + FileUtil.getName(key));
- });
- String floorPlanPath = String.format(UploadFilePath.USER_VIEW_PATH, num) + "floorplan.json";
- String floorPlanStr = fileServiceInterface.getFileContent(floorPlanPath);
- JSONObject floorPlanJson = JSON.parseObject(floorPlanStr);
- JSONArray floors = floorPlanJson.getJSONArray("floors");
- List<Map<String, String>> readme = floors.stream().map(f -> {
- JSONObject item = (JSONObject) f;
- Integer subgroup = item.getInteger("subgroup");
- String floor_name = item.getString("name");
- Map<String, String> map = new HashMap<>();
- map.put("floor_name", floor_name);
- map.put("img_name", "cad-style-3-" + subgroup + ".jpg");
- return map;
- }).collect(Collectors.toList());
- log.info("readme.json:{}", JSON.toJSONString(readme));
- FileUtil.writeUtf8String(JSON.toJSONString(readme), tmpPath + "readme.json");
- String zipPath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + currentTimeMillis + ".zip";
- //打压缩包
- this.zip(tmpPath, zipPath);
- //上传到fastdf
- String url = haixinHost.concat(API_FDFS_UPLOAD);
- JSONObject jsonObject = haixinClient.uploadToFdfs(url, zipPath);
- JSONObject data = jsonObject.getJSONObject("data");
- //通知计算结果
- this.sendResult(scenePlus.getTaskId(), data.getString("fileNameRemote"));
- }
- private void zip(String sourcePath, String zipPath) throws Exception {
- FileUtil.mkParentDirs(zipPath);
- String cmd = "cd " + sourcePath + " && zip -r " + zipPath + " *";
- CmdUtils.callLineSh(cmd, 200);
- }
- @Override
- public void sendResult(String taskId, String packetPath){
- String url = haixinHost.concat(API_SUBMIT_FLOORPLAN);
- Map<String, String> params = new HashMap<>();
- params.put("vendor","A0BF");
- params.put("projectId", taskId);
- params.put("packetPath", packetPath);
- haixinClient.postJson(url, params);
- }
- }
|