管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-03 3cfb6aa02516135fb174ab1b30620f2007924663
MoonExp/cs/ExportUtil.cs
@@ -3,10 +3,12 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Security;
using System.Text;
using System.Web;
@@ -48,7 +50,7 @@
            {
                if (string.IsNullOrWhiteSpace(pyFile))
                {
                    pyFile = Path.Combine(SourcesPath, "render.py");
                    pyFile = Path.Combine(SourcesPath, "MoonExp.py");
                }
                return pyFile;
@@ -122,6 +124,10 @@
            return i.ToString();
        }
        private static readonly string selectResSql = "select a.id, a.url, b.url || case when length(b.args) > 0 then '?' || b.args else '' end \"surl\" from lf.sys_layer a left join lf.sys_res b on a.resid = b.id where a.category = 3 and a.is_layer = 1 and a.id in ({0})";
        public ExportUtil() { }
        /// <summary>
        /// 生成
        /// </summary>
@@ -132,7 +138,7 @@
        {
            string date = DateStr;
            string sub = GetExportSubFolder();
            string qgz = "Test.qgz";
            string qgz = "Moon.qgz";
            args.imgPath = sub + "\\" + date + ".png";
            args.qpt = date + ".qpt";
@@ -174,7 +180,7 @@
        public static void CreateTemplate(ExportArgs args)
        {
            string imgPath = Path.Combine(DownloadFolder, args.imgPath);
            string templateFile = Path.Combine(SourcesPath, "Template.qpt");
            string templateFile = Path.Combine(SourcesPath, "MoonTemplate.qpt");
            string qptFile = Path.Combine(SourcesPath, args.qpt);
            LogOut.Info("imgPath = " + imgPath + ", tempFile = " + templateFile + ", qptFile = " + qptFile);
@@ -188,13 +194,14 @@
                .Replace("{ymin}", args.ymin.ToString())
                .Replace("{ymax}", args.ymax.ToString())
                .Replace("{xmax}", args.xmax.ToString())
                .Replace("{province}", args.province)
                //.Replace("{province}", args.province)
                .Replace("{scale}", args.scale)
                .Replace("{resolution}", args.resolution)
                //.Replace("{resolution}", args.resolution)
                //.Replace("{date}", args.date)
                .Replace("{date}", DateTime.Now.ToString("yyyy.MM.dd"))
                .Replace("{date}", args.date) // DateTime.Now.ToString("yyyy.MM.dd")
                .Replace("{layers}", args.layers)
                .Replace("{imgPath}", imgPath);
                .Replace("{imgPath}", imgPath)
                .Replace("{wmsUrl}", getWmtsUrl(args));
            File.WriteAllText(qptFile, xml);
        }
@@ -244,5 +251,66 @@
            return str;
        }
        /// <summary>
        /// 获取WMTS地址,多个以英文逗号隔开
        /// </summary>
        public static string getWmtsUrl(ExportArgs args)
        {
            List<string> list = new List<string>();
            foreach (int id in args.layerIds)
            {
                List<string> resList = SelectMapUrls(id);
                if (null != resList && resList.Count > 0)
                {
                    list.AddRange(resList);
                }
            }
            if (0 == list.Count)
            {
                string defaultUrl = Tools.GetSetting("wmtsUrl");
                if (!string.IsNullOrEmpty(defaultUrl)) list.Add(defaultUrl);
            }
            string wmtsUrl = string.Join(",", list);
            return SecurityElement.Escape(wmtsUrl);
        }
        /// <summary>
        /// 查询地图Url
        /// </summary>
        public static List<string> SelectMapUrls(int id)
        {
            string sql = string.Format(selectResSql, id);
            DataTable dt = Tools.DBHelper.GetDataTable(sql);
            if (null == dt || 0 == dt.Rows.Count)
            {
                return null;
            }
            List<SysRes> resList = ModelHandler.FillModel<SysRes>(dt);
            if (null == resList || 0 == resList.Count)
            {
                return null;
            }
            List<string> list = new List<string>();
            foreach (SysRes res in resList)
            {
                if (!string.IsNullOrEmpty(res.surl))
                {
                    list.Add(res.surl);
                    continue;
                }
                if (!string.IsNullOrEmpty(res.url))
                {
                    list.Add(res.url);
                }
            }
            return list;
        }
    }
}