管道基础大数据平台系统开发-【CS】-ExportMap
OK
13693261870
2024-09-27 566e0d21293a5fe6423fd7a16541bce00eeb2e38
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;
@@ -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>
@@ -192,9 +198,10 @@
                .Replace("{scale}", args.scale)
                //.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;
        }
    }
}