JmgaServiceImpl.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. package com.fdkankan.contro.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.io.FileUtil;
  4. import cn.hutool.core.io.file.FileMode;
  5. import cn.hutool.core.lang.UUID;
  6. import cn.hutool.core.util.StrUtil;
  7. import cn.hutool.core.util.ZipUtil;
  8. import cn.hutool.http.HttpUtil;
  9. import cn.hutool.json.JSONUtil;
  10. import com.alibaba.excel.EasyExcel;
  11. import com.alibaba.fastjson.JSON;
  12. import com.alibaba.fastjson.JSONArray;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  15. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  16. import com.fdkankan.common.constant.ErrorCode;
  17. import com.fdkankan.common.constant.PayStatus;
  18. import com.fdkankan.common.constant.RecStatus;
  19. import com.fdkankan.common.constant.SceneStatus;
  20. import com.fdkankan.common.exception.BusinessException;
  21. import com.fdkankan.common.util.DateExtUtil;
  22. import com.fdkankan.common.util.DateUtil;
  23. import com.fdkankan.contro.bean.SendCallAlgorithmDetail;
  24. import com.fdkankan.contro.constant.ModelingControlRespCode;
  25. import com.fdkankan.contro.constant.ZipConstant;
  26. import com.fdkankan.contro.entity.*;
  27. import com.fdkankan.contro.mq.service.IBuildLogService;
  28. import com.fdkankan.contro.service.*;
  29. import com.fdkankan.contro.util.SceneSourceUtil;
  30. import com.fdkankan.contro.vo.SendCallAlgorithmParam;
  31. import com.fdkankan.contro.vo.UploadSceneOrigParamVo;
  32. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  33. import com.fdkankan.model.constants.ConstantFilePath;
  34. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  35. import lombok.extern.slf4j.Slf4j;
  36. import net.lingala.zip4j.exception.ZipException;
  37. import org.springframework.beans.factory.annotation.Autowired;
  38. import org.springframework.beans.factory.annotation.Value;
  39. import org.springframework.stereotype.Service;
  40. import javax.annotation.Resource;
  41. import java.io.File;
  42. import java.io.IOException;
  43. import java.io.RandomAccessFile;
  44. import java.nio.charset.StandardCharsets;
  45. import java.nio.file.Files;
  46. import java.nio.file.Paths;
  47. import java.util.*;
  48. import java.util.stream.Collectors;
  49. import java.util.stream.Stream;
  50. @Slf4j
  51. @Service
  52. public class JmgaServiceImpl implements IJmgaService {
  53. public static final String ipv4Pattern = "\\b(?:[0-9]{1,3}\\.){3}[0-9]{1,3}\\b";
  54. @Value("${jmga.eventNotice:false}")
  55. private boolean eventNotice;
  56. @Value("${scene.pro.new.url}")
  57. private String sceneProNewUrl;
  58. @Autowired
  59. private IOrigFileUploadBatchService origFileUploadBatchService;
  60. @Autowired
  61. private IOrigFileUploadService origFileUploadService;
  62. @Resource
  63. private FYunFileServiceInterface fileServiceInterface;
  64. @Resource
  65. private RabbitMqProducer mqProducer;
  66. @Resource
  67. private FYunFileServiceInterface fYunFileService;
  68. @Autowired
  69. private ISceneFileBuildService sceneFileBuildService;
  70. @Autowired
  71. private IUserService userService;
  72. @Autowired
  73. private IScenePlusService scenePlusService;
  74. @Autowired
  75. private IScenePlusExtService scenePlusExtService;
  76. @Autowired
  77. private ISceneBuildProcessLogService sceneBuildProcessLogService;
  78. @Autowired
  79. private IBuildLogService buildLogService;
  80. @Autowired
  81. private IJyUserService jyUserService;
  82. @Autowired
  83. private IScene3dNumService scene3dNumService;
  84. @Autowired
  85. private ICameraService cameraService;
  86. @Autowired
  87. private ICameraDetailService cameraDetailService;
  88. @Autowired
  89. private ISceneEditInfoService sceneEditInfoService;
  90. @Autowired
  91. private ISceneEditInfoExtService sceneEditInfoExtService;
  92. @Autowired
  93. private ISceneEditControlsService sceneEditControlsService;
  94. @Override
  95. public void checkFileWhole(String uuid, String dataSource, JSONObject fdageData) {
  96. int camType = fdageData.getJSONObject("cam").getIntValue("type");
  97. //从data.fdage中获取需要上传的文件列表
  98. JSONArray points = fdageData.getJSONArray("points");
  99. if(CollUtil.isEmpty(points)){
  100. return;
  101. }
  102. List<String> fileList = new ArrayList<>();
  103. for (Object point : points) {
  104. JSONObject pointJson = (JSONObject) point;
  105. if(camType == 5){//圆周率相机
  106. String name = pointJson.getString("name");
  107. fileList.add(name);
  108. }else{//四维相机
  109. JSONArray imgs = pointJson.getJSONArray("imgs");
  110. if(CollUtil.isEmpty(imgs)){
  111. continue;
  112. }
  113. for (Object img : imgs) {
  114. JSONObject imgJson = (JSONObject) img;
  115. String name = imgJson.getString("name");
  116. fileList.add(name);
  117. }
  118. }
  119. }
  120. //查询当前待通知计算批次文件是否存在
  121. List<OrigFileUploadBatch> batchList = origFileUploadBatchService.list(new LambdaQueryWrapper<OrigFileUploadBatch>().eq(OrigFileUploadBatch::getUuid, uuid));
  122. if(CollUtil.isNotEmpty(batchList)){
  123. Set<String> batchIds = batchList.stream().map(v -> v.getBatchId()).collect(Collectors.toSet());
  124. List<OrigFileUpload> origFileList = origFileUploadService.list(new LambdaQueryWrapper<OrigFileUpload>().in(OrigFileUpload::getBatchId, batchIds));
  125. //过滤出不存在的
  126. fileList = fileList.stream().filter(v -> origFileList.stream().noneMatch(k -> k.getFileName().equals(v))).collect(Collectors.toList());
  127. }
  128. if(CollUtil.isNotEmpty(fileList)){
  129. String args = JSON.toJSONString(fileList);
  130. if(fileList.size() > 5){
  131. args = fileList.size() + "个文件";
  132. }
  133. throw new BusinessException(ErrorCode.FAILURE_CODE_4001, args);
  134. }
  135. }
  136. @Override
  137. public void sendStatus(String num, String eventContent) {
  138. if(!eventNotice){
  139. return;
  140. }
  141. Map<String, Object> param = new HashMap<>();
  142. try {
  143. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  144. JyUser jyUser = new JyUser();
  145. param.put("event_type", "scene");
  146. param.put("event_content", eventContent);
  147. param.put("scene_num", num);
  148. param.put("event_time", new Date());
  149. if(Objects.nonNull(scenePlus)){
  150. param.put("scene_title", scenePlus.getTitle());
  151. jyUser = jyUserService.getByUserId(scenePlus.getUserId());
  152. }
  153. param.put("ryid", jyUser.getRyId());
  154. param.put("ryno", jyUser.getRyNo());
  155. param.put("nick_name", jyUser.getRyNickName());
  156. mqProducer.sendByWorkQueue("jmga-event-notice", param);
  157. }catch (Exception e){
  158. log.info("推送事件失败,param:{}", param);
  159. }
  160. }
  161. @Override
  162. public void checkLackFile(String dataSource) {
  163. String dataFdagePath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("data.fdage");
  164. if(!FileUtil.exist(dataFdagePath)){
  165. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("data.fdage"));
  166. }
  167. JSONObject fdageData = null;
  168. try {
  169. fdageData = JSON.parseObject(FileUtil.readUtf8String(dataFdagePath));
  170. }catch (Exception e){
  171. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("data.fdage"));
  172. }
  173. int camType = fdageData.getJSONObject("cam").getIntValue("type");
  174. if(camType == 1 || camType == 2 || camType == 9 || camType == 10 || camType == 11){
  175. Integer shootCount = fdageData.getJSONArray("points").size();
  176. if(shootCount > 0){//有点位代表架站式
  177. String parametersPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("parameters.json");
  178. if(!FileUtil.exist(parametersPath)){
  179. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("parameters.json"));
  180. }
  181. String sfmDataBinPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("sfm_data.bin");
  182. if(!FileUtil.exist(sfmDataBinPath)){
  183. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("sfm_data.bin"));
  184. }
  185. String upName = camType > 2 ? "Up.txt" : "Up.xml";
  186. String upTxtPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat(upName);
  187. if(!FileUtil.exist(upTxtPath)){
  188. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(upName));
  189. }
  190. }
  191. }
  192. if(camType == 5){
  193. String parametersPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("images/parameters.json");
  194. if(!FileUtil.exist(parametersPath)){
  195. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("parameters.json"));
  196. }
  197. String sfmDataBinPath = dataSource.concat(File.separator).concat("capture").concat(File.separator).concat("result/reconstruction/sfm_data.bin");
  198. if(!FileUtil.exist(sfmDataBinPath)){
  199. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage("sfm_data.bin"));
  200. }
  201. }
  202. //从data.fdage中获取需要上传的文件列表
  203. JSONArray points = fdageData.getJSONArray("points");
  204. if(CollUtil.isEmpty(points)){
  205. return;
  206. }
  207. for (Object point : points) {
  208. JSONObject pointJson = (JSONObject) point;
  209. if(camType == 5){//圆周率相机
  210. String name = pointJson.getString("name");
  211. this.checkFileAvailable(dataSource, name);
  212. }else{//四维相机
  213. JSONArray imgs = pointJson.getJSONArray("imgs");
  214. for (Object img : imgs) {
  215. JSONObject imgJson = (JSONObject) img;
  216. String name = imgJson.getString("name");
  217. this.checkFileAvailable(dataSource, name);
  218. }
  219. }
  220. }
  221. }
  222. private void checkFileAvailable(String dataSource, String fileName){
  223. List<File> fileList = FileUtil.loopFiles(dataSource.concat(File.separator).concat("capture"));
  224. if(CollUtil.isEmpty(fileList)){
  225. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(fileName));
  226. }
  227. for (File file : fileList) {
  228. if(file.getName().equals(fileName) && file.length() > 0){
  229. return;
  230. }
  231. }
  232. throw new BusinessException(ErrorCode.FAILURE_CODE_4001.code(), ErrorCode.FAILURE_CODE_4001.formatMessage(fileName));
  233. }
  234. @Override
  235. public void uploadScene(UploadSceneOrigParamVo param) throws Exception {
  236. User user = userService.getById(param.getUserId());
  237. if(Objects.isNull(user)){
  238. throw new BusinessException(ErrorCode.USER_NOT_EXIST);
  239. }
  240. String uuid = UUID.randomUUID().toString();
  241. String zipName = uuid + ".zip";
  242. String zipDir = "/oss/4dkankan/bd_server/";
  243. fYunFileService.downloadFileByCommand(zipDir + zipName, param.getFilePath());
  244. Camera camera = null;
  245. CameraDetail cameraDetail = null;
  246. String sceneNum = null;
  247. if(param.getSourceType().equals("orig")){//原始资源
  248. String dataFdageStr = com.fdkankan.contro.util.ZipUtil.readUtf8(zipDir + zipName, "data.fdage");
  249. if(StrUtil.isEmpty(dataFdageStr) || !JSONUtil.isJson(dataFdageStr)){
  250. throw new BusinessException(60027, "data.fdage文件数据异常");
  251. }
  252. JSONObject dataFdage = JSON.parseObject(dataFdageStr);
  253. String snCode = dataFdage.getJSONObject("cam").getString("uuid");
  254. String uuidTime = dataFdage.getString("uuidtime");
  255. String uniCode = snCode + "_" + uuidTime;
  256. int camType = dataFdage.getJSONObject("cam").getIntValue("type");
  257. Map<String, Object> instorage = cameraService.instorage(camType, snCode);
  258. cameraDetail = (CameraDetail) instorage.get("cameraDetail");
  259. ScenePlus scenePlus = scenePlusService.getByFileId(uniCode);
  260. if(scenePlus == null){
  261. scenePlus = new ScenePlus();
  262. sceneNum = scene3dNumService.generateSceneNum(cameraDetail.getType());
  263. scenePlus.setNum(sceneNum);
  264. scenePlus.setCameraId(cameraDetail.getCameraId());
  265. scenePlus.setSceneSource(SceneSourceUtil.getSceneSourceByCamType(cameraDetail.getType()));
  266. }else{
  267. if(scenePlus.getSceneStatus() == SceneStatus.wait.code()){
  268. throw new BusinessException(ErrorCode.FAILURE_CODE_5033);
  269. }
  270. sceneNum = scenePlus.getNum();
  271. }
  272. scenePlus.setTitle(dataFdage.getString("name"));
  273. scenePlus.setUserId(user.getId());
  274. scenePlus.setUpdateTime(null);
  275. scenePlus.setSceneStatus(SceneStatus.wait.code());
  276. scenePlusService.saveOrUpdate(scenePlus);
  277. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  278. if(scenePlusExt == null){
  279. scenePlusExt = new ScenePlusExt();
  280. scenePlusExt.setPlusId(scenePlus.getId());
  281. scenePlusExt.setWebSite("/" + sceneProNewUrl + scenePlus.getNum());
  282. String fileId = sceneFileBuildService.getFileId(snCode, uniCode);
  283. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH + snCode + File.separator + fileId + File.separator + uniCode);
  284. scenePlusExtService.save(scenePlusExt);
  285. }
  286. SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
  287. if(sceneEditInfo == null){
  288. sceneEditInfo = new SceneEditInfo();
  289. sceneEditInfo.setScenePlusId(scenePlus.getId());
  290. sceneEditInfoService.save(sceneEditInfo);
  291. }
  292. SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
  293. if(sceneEditInfoExt == null){
  294. sceneEditInfoExt = new SceneEditInfoExt();
  295. sceneEditInfoExt.setScenePlusId(scenePlus.getId());
  296. sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
  297. sceneEditInfoExtService.save(sceneEditInfoExt);
  298. }
  299. SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
  300. if(sceneEditControls == null){
  301. sceneEditControls = new SceneEditControls();
  302. sceneEditControls.setEditInfoId(sceneEditInfo.getId());
  303. sceneEditControlsService.save(sceneEditControls);
  304. }
  305. }else{//离线包
  306. String sceneJsonStr = com.fdkankan.contro.util.ZipUtil.readUtf8(zipDir + zipName, "scene.json");
  307. if(StrUtil.isEmpty(sceneJsonStr) || !JSONUtil.isJson(sceneJsonStr)){
  308. throw new BusinessException(60027, "scene.json文件数据异常");
  309. }
  310. JSONObject sceneJson = JSON.parseObject(sceneJsonStr);
  311. sceneNum = sceneJson.getString("num");
  312. ScenePlus scenePlusDb = scenePlusService.getDeletedByNum(sceneNum);
  313. if(scenePlusDb != null && scenePlusDb.getRecStatus().equalsIgnoreCase(RecStatus.VALID.code())){
  314. throw new BusinessException(ModelingControlRespCode.NUM_EXISTS.code(), ModelingControlRespCode.NUM_EXISTS.message());
  315. }
  316. if(scenePlusDb != null && scenePlusDb.getRecStatus().equalsIgnoreCase(RecStatus.DISABLE.code())){
  317. scenePlusService.updateNumById(scenePlusDb.getId(), scenePlusDb.getNum() + "-" + scenePlusDb.getId());
  318. }
  319. int camType = sceneJson.getInteger("camType");
  320. String snCode = sceneJson.getString("snCode");
  321. Map<String, Object> instorage = cameraService.instorage(camType, snCode);
  322. cameraDetail = (CameraDetail) instorage.get("cameraDetail");
  323. ScenePlus scenePlus = new ScenePlus();
  324. scenePlus.setNum(sceneNum);
  325. scenePlus.setCameraId(cameraDetail.getCameraId());
  326. scenePlus.setSceneSource(SceneSourceUtil.getSceneSourceByCamType(cameraDetail.getType()));
  327. scenePlus.setTitle(sceneJson.getString("title"));
  328. scenePlus.setUserId(user.getId());
  329. scenePlus.setUpdateTime(null);
  330. scenePlus.setSceneStatus(SceneStatus.wait.code());
  331. scenePlus.setUploadType("offline");
  332. scenePlus.setPayStatus(PayStatus.PAY.code());
  333. scenePlus.setStartBuildTime(new Date());
  334. scenePlusService.save(scenePlus);
  335. ScenePlusExt scenePlusExt = new ScenePlusExt();
  336. scenePlusExt.setPlusId(scenePlus.getId());
  337. String uniCode = snCode + DateExtUtil.format(new Date(), DateExtUtil.dateStyle11);
  338. String fileId = sceneFileBuildService.getFileId(snCode, uniCode);
  339. scenePlusExt.setDataSource(ConstantFilePath.BUILD_MODEL_PATH + snCode + File.separator + fileId + File.separator + uniCode);
  340. scenePlusExtService.save(scenePlusExt);
  341. }
  342. //发mq做异步处理
  343. JSONObject content = new JSONObject();
  344. content.put("zipPath", zipDir + zipName);
  345. content.put("num", sceneNum);
  346. content.put("sourceType", param.getSourceType());
  347. mqProducer.sendByWorkQueue("manage-upload-scene", content);
  348. }
  349. @Override
  350. public void noticeBuildBd(String ossHost, String uuid, String dir) {
  351. String prefix = "http://" + ossHost + "/";
  352. String path = "/oss/4dkankan/bd_server/" + dir;
  353. List<File> files = FileUtil.loopFiles(path).stream().filter(file -> !file.getAbsolutePath().contains("backup")).collect(Collectors.toList());
  354. files.parallelStream().forEach(file ->{
  355. String url = prefix.concat(file.getAbsolutePath().substring(1).replace("/4dkankan",""));
  356. SendCallAlgorithmDetail detail = new SendCallAlgorithmDetail();
  357. detail.setFileName(FileUtil.getName(file.getAbsolutePath()));
  358. detail.setUuid(uuid);
  359. SendCallAlgorithmParam param = new SendCallAlgorithmParam();
  360. param.setFilepath(url);
  361. param.setDetails(detail);
  362. HttpUtil.post("http://127.0.0.1:8085/api/scene/file/sendCallAlgorithm", JSON.toJSONString(param));
  363. });
  364. }
  365. @Override
  366. public void updateSceneFailAndZipLog(String num, String failReason) throws IOException {
  367. scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
  368. .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
  369. .set(ScenePlus::getBuildFailReason, failReason)
  370. .eq(ScenePlus::getNum, num));
  371. String logBasePath = File.separator + "mnt" + File.separator + "logs" + File.separator;
  372. String tmpPath = logBasePath + "tmp" + File.separator;
  373. String logPath = tmpPath + num + "-" + Calendar.getInstance().getTimeInMillis() + File.separator;
  374. String zipPath = tmpPath + num + "-" + Calendar.getInstance().getTimeInMillis() + ".zip";
  375. FileUtil.mkdir(logPath);
  376. //打包服务端日志
  377. File[] ls = FileUtil.ls(logBasePath);
  378. for (File l : ls) {
  379. if(l.isFile() || !l.getName().startsWith("modeling-control")){
  380. continue;
  381. }
  382. this.copyLog(l.getAbsolutePath(), logPath, "info","sql","error");
  383. }
  384. //打包算法日志
  385. ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
  386. ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
  387. String consoleLogPath = scenePlusExt.getDataSource() + "/console.log";
  388. String consoleOldLogPath = scenePlusExt.getDataSource() + "/console.old.log";
  389. if(FileUtil.exist(consoleLogPath)){
  390. FileUtil.copy(consoleLogPath, logPath,true);
  391. }
  392. if(FileUtil.exist(consoleOldLogPath)){
  393. FileUtil.copy(consoleOldLogPath, logPath,true);
  394. }
  395. //打包数据库记录
  396. String[] split = scenePlusExt.getDataSource().split("/");
  397. String uuid = split[split.length -1];
  398. List<OrigFileUploadBatch> batchList = origFileUploadBatchService.list(new LambdaQueryWrapper<OrigFileUploadBatch>().eq(OrigFileUploadBatch::getUuid, uuid));
  399. if(CollUtil.isNotEmpty(batchList)){
  400. EasyExcel.write(logPath.concat("origFileUploadBatch.xlsx"), OrigFileUploadBatch.class).sheet("origFileUploadBatch").doWrite(batchList);
  401. List<String> batchIdList = batchList.stream().map(v -> v.getBatchId()).collect(Collectors.toList());
  402. List<OrigFileUpload> uploadList = origFileUploadService.list(new LambdaQueryWrapper<OrigFileUpload>().in(OrigFileUpload::getBatchId, batchIdList));
  403. if(CollUtil.isNotEmpty(uploadList)){
  404. uploadList.stream().forEach(v->{
  405. v.setFileUrl(v.getFileUrl().replaceAll(ipv4Pattern, "ip"));
  406. });
  407. EasyExcel.write(logPath.concat("origFileUpload.xlsx"), OrigFileUpload.class).sheet("origFileUpload").doWrite(uploadList);
  408. }
  409. }
  410. List<SceneBuildProcessLog> processLogList = sceneBuildProcessLogService.listByNum(num);
  411. if(CollUtil.isNotEmpty(processLogList)){
  412. EasyExcel.write(logPath.concat("sceneBuildProcessLog.xlsx"), SceneBuildProcessLog.class).sheet("sceneBuildProcessLog").doWrite(processLogList);
  413. }
  414. List<BuildLog> buildLogList = buildLogService.list(new LambdaQueryWrapper<BuildLog>().eq(BuildLog::getSceneNum, num));
  415. if(CollUtil.isNotEmpty(buildLogList)){
  416. EasyExcel.write(logPath.concat("buildLog.xlsx"), BuildLog.class).sheet("buildLog").doWrite(buildLogList);
  417. }
  418. //上传日志,删除本地压缩包
  419. ZipUtil.zip(logPath, zipPath, false);
  420. String logName = "build_log/" + num + "/" + num + "-log.zip";
  421. if(fYunFileService.fileExist(logName)){
  422. fYunFileService.copyFileInBucket(logName, logName + "-bak-" + DateExtUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle11));
  423. }
  424. fYunFileService.uploadFile(zipPath, logName);
  425. }
  426. private void copyLog(String serverPath, String tmpPath, String... levels) throws IOException {
  427. level: for (String level : levels) {
  428. String infoPath = serverPath + File.separator + level + File.separator;
  429. List<File> fileList = FileUtil.loopFiles(infoPath);
  430. if(CollUtil.isEmpty(fileList)){
  431. continue;
  432. }
  433. CollUtil.reverse(fileList);
  434. for (File file : fileList) {
  435. int i = fileList.indexOf(file);
  436. if(i > 7){
  437. continue level;
  438. }
  439. String targetPath = file.getAbsolutePath().replace(FileUtil.getParent(serverPath, 1), tmpPath);
  440. File targetLog = new File(targetPath);
  441. targetLog.createNewFile();
  442. // FileUtil.copy(file.getAbsolutePath(), targetPath, true);
  443. // String content = FileUtil.readUtf8String(targetPath);
  444. // content = content.replace("公安", "xx").replaceAll(ipv4Pattern, "ip");
  445. // FileUtil.writeUtf8String(content, targetPath);
  446. try (Stream<String> lines = Files.lines(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8)) {
  447. lines.map(line -> line.replace("公安", "xx").replaceAll(ipv4Pattern, "ip"))
  448. .forEach(line -> FileUtil.appendUtf8String(line, targetLog)); // 或者进行其他处理
  449. } catch (IOException e) {
  450. e.printStackTrace();
  451. }
  452. }
  453. }
  454. }
  455. }