From 4e2e497696cc0e7866bab056cd056d509b7d6c6c Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 14 三月 2023 16:55:59 +0800
Subject: [PATCH] 1

---
 ExportMap/cs/XYZUtils.cs                   |    8 +-
 ExportMap/Controllers/ConvertController.cs |   26 ++------
 ExportMap/cs/ConvertUtils.cs               |   91 +++++++++++++++++++++++-------
 ExportMap/Web.config                       |    2 
 4 files changed, 82 insertions(+), 45 deletions(-)

diff --git a/ExportMap/Controllers/ConvertController.cs b/ExportMap/Controllers/ConvertController.cs
index 35d5983..fecb90e 100644
--- a/ExportMap/Controllers/ConvertController.cs
+++ b/ExportMap/Controllers/ConvertController.cs
@@ -12,35 +12,23 @@
     public class ConvertController : ApiController
     {
         [HttpPost]
-        public ResponseMsg<int> ToTileset([FromBody]ExportArgs args)
+        public ResponseMsg<int> ToTileset([FromBody]XYZArgs args)
         {
             try
             {
+                if (null == args || null == args.ids || args.ids.Count == 0)
+                {
+                    return ResponseMsg<int>.fail("璇疯緭鍏ュ厓鏁版嵁id");
+                }
 
+                int count = ConvertUtils.Convert(args.ids);
 
-                return ResponseMsg<int>.success("鎴愬姛", 1);
+                return ResponseMsg<int>.success("鎴愬姛", count);
             }
             catch (Exception ex)
             {
                 LogOut.Error(ex.StackTrace);
                 return ResponseMsg<int>.fail(ex.Message);
-            }
-        }
-
-        [HttpGet]
-        public ResponseMsg<string> Test()
-        {
-            string modelFile = @"E:\soft\Navisworks Manage 2020\Data\jz.rvt";
-            string outPath = @"D:\xyz\3dtiles\out";
-
-            string rs = ConvertUtils.ExecNavisworks(modelFile, outPath);
-            if (string.IsNullOrEmpty(rs))
-            {
-                return ResponseMsg<string>.success("鎴愬姛", "");
-            }
-            else
-            {
-                return ResponseMsg<string>.fail(rs);
             }
         }
     }
diff --git a/ExportMap/Web.config b/ExportMap/Web.config
index 98be368..bb4807a 100644
--- a/ExportMap/Web.config
+++ b/ExportMap/Web.config
@@ -3,6 +3,8 @@
   <appSettings>
     <!-- 寤婂潑鏈嶅姟 -->
     <add key="lfServer" value="http://127.0.0.1:12316/server"/>
+    <!-- 涓婁紶鐩綍 -->
+    <add key="uploadFolder" value="D:\LF\upload"/>
     <!-- 涓嬭浇鐩綍 -->
     <add key="downloadFolder" value="D:\LF\download"/>
     <!-- 鍙戝竷Mpt鐩綍 -->
diff --git a/ExportMap/cs/ConvertUtils.cs b/ExportMap/cs/ConvertUtils.cs
index 756115d..ac8787b 100644
--- a/ExportMap/cs/ConvertUtils.cs
+++ b/ExportMap/cs/ConvertUtils.cs
@@ -1,6 +1,8 @@
-锘縰sing System;
+锘縰sing ExportMap.Models;
+using System;
 using System.Collections.Generic;
 using System.Diagnostics;
+using System.IO;
 using System.Linq;
 using System.Web;
 
@@ -11,31 +13,78 @@
         /// <summary>
         /// 宸ヤ綔閰嶇疆
         /// </summary>
-        public static string jobConfig = "{ \"format\": \"3dtiles\", \"mode\": 0, \"outputPath\": \"{0}\", \"outputOptions\": null, \"levelOfDetail\": -1, \"levelOfDetailText\": \"Auto\", \"georeferenced\": null }";
+        public static string JobConfig = "{ \"format\": \"3dtiles\", \"mode\": 0, \"outputPath\": \"{0}\", \"outputOptions\": null, \"levelOfDetail\": -1, \"levelOfDetailText\": \"Auto\", \"georeferenced\": null }";
 
+        /// <summary>
+        /// Roamer.exe
+        /// </summary>
+        public static string RoamerExe = "\"C:\\Program Files\\Autodesk\\Navisworks Manage 2020\\Roamer.exe\"";
+
+        /// <summary>
+        /// 妯″瀷杞崲
+        /// </summary>
+        public static int Convert(List<int> ids)
+        {
+            int count = 0;
+            string uploadFolder = Tool.GetSetting("uploadFolder");
+            string tilesFolder = Path.Combine(Tool.GetSetting("lfData"), "3d\\3dtiles");
+
+            List<SysMeta> list = XYZUtils.selectMetas(ids, "type in ('ifc', 'fbx', 'rvt')");
+            foreach (SysMeta meta in list)
+            {
+                try
+                {
+                    string modelFile = Path.Combine(uploadFolder, meta.path);
+                    if (!File.Exists(modelFile))
+                    {
+                        continue;
+                    }
+
+                    string configFile = Path.Combine(Tool.BaseDir, ExportUtil.DateStr + ".json");
+                    string outPath = Path.Combine(tilesFolder, meta.type, meta.id.ToString());
+
+                    if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);
+                    WriteText(configFile, string.Format(JobConfig, outPath));
+
+                    ExecNavisworks(modelFile, configFile);
+
+                    count++;
+                }
+                catch (Exception ex)
+                {
+                    LogOut.Error(ex.StackTrace);
+                }
+            }
+
+            return count;
+        }
+
+        /// <summary>
+        /// 杩愯Navisworks
+        /// </summary>
         public static string ExecNavisworks(string modelFile, string outPath)
         {
-            try
-            {
-                string exe = @"C:\Program Files\Autodesk\Navisworks Manage 2020\Roamer.exe";
-                string cmd = string.Format("\"{0}\" -licensing AdLM -OpenFile \"{1}\" -ExecuteAddInPlugin SmartEarth \"{2}\" -NoGui -NoCache -Exit", exe, modelFile, outPath);
+            string args = string.Format("-licensing AdLM -OpenFile \"{0}\" -ExecuteAddInPlugin SmartEarth \"{1}\" -NoGui -NoCache -Exit", modelFile, outPath);
 
-                Process p = new Process();
-                p.StartInfo.UseShellExecute = false;
-                p.StartInfo.ErrorDialog = true;
-                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
-                p.StartInfo.RedirectStandardError = false;
-                p.StartInfo.FileName = exe;
-                p.StartInfo.Arguments = cmd;
-                p.StartInfo.CreateNoWindow = true;
-                p.Start();
+            Process p = new Process();
+            p.StartInfo.UseShellExecute = false;
+            p.StartInfo.ErrorDialog = true;
+            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+            p.StartInfo.RedirectStandardError = false;
+            p.StartInfo.FileName = RoamerExe;
+            p.StartInfo.Arguments = args;
+            p.StartInfo.CreateNoWindow = true;
+            p.Start();
 
-                return string.Empty;
-            }
-            catch(Exception ex)
-            {
-                return ex.Message;
-            }
+            return string.Empty;
+        }
+
+        /// <summary>
+        /// 鍐欐枃鏈枃浠�
+        /// </summary>
+        private static void WriteText(string file, string str)
+        {
+            File.WriteAllText(file, str);
         }
     }
 }
diff --git a/ExportMap/cs/XYZUtils.cs b/ExportMap/cs/XYZUtils.cs
index c799b6f..e1b7875 100644
--- a/ExportMap/cs/XYZUtils.cs
+++ b/ExportMap/cs/XYZUtils.cs
@@ -62,7 +62,7 @@
         /// <summary>
         /// 鏌ヨ鍏冩暟鎹�
         /// </summary>
-        private static List<SysMeta> selectMetas(string dircode)
+        public static List<SysMeta> selectMetas(string dircode)
         {
             string sql = string.Format("select * from lf.sys_meta where dircode like '{0}%'", dircode);
 
@@ -75,15 +75,13 @@
         /// <summary>
         /// 鏌ヨ鍏冩暟鎹�
         /// </summary>
-        private static List<SysMeta> selectMetas(List<int> ids)
+        public static List<SysMeta> selectMetas(List<int> ids, string types = "")
         {
-            string sql = string.Format("select * from lf.sys_meta where id in ({0})", string.Join(",", ids));
+            string sql = string.Format("select * from lf.sys_meta where id in ({0}) {1} order by id", string.Join(",", ids), types);
             DataTable dt = Tool.DBHelper.GetDataTable(sql);
             List<SysMeta> list = ModelHandler.FillModel<SysMeta>(dt);
 
             return list;
         }
-
-
     }
 }

--
Gitblit v1.9.3