管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2024-09-05 95d9356edef73a1ad5b04e62b7aef6b77697a226
ExportMap/db/PubDBHelper.cs
@@ -3,6 +3,7 @@
using Npgsql;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Reflection;
@@ -30,7 +31,7 @@
        private static string selectLayerSql = "select id from lf.sys_layer where pid = @pid and en_name = @en_name";
        /// <summary>
        /// 是/否发布过
        /// 是/否发布过 *
        /// </summary>
        public static bool IsPublish(int metaid)
        {
@@ -43,7 +44,7 @@
        }
        /// <summary>
        /// 是/否发布过
        /// 是/否发布过 *
        /// </summary>
        public static bool IsPublish(string dirid, string type = "DOM")
        {
@@ -54,6 +55,71 @@
            int count = obj == null ? 0 : Convert.ToInt32(obj);
            return count > 0;
        }
        /// <summary>
        /// 获取发布ID
        /// </summary>
        public static int GetPushlishId(int metaid)
        {
            string sql = string.Format("select pubid from lf.sys_meta_pub where metaid={0} order by id desc limit 1", metaid);
            object obj = Tools.DBHelper.GetScalar(sql);
            return null == obj ? 0 : Convert.ToInt32(obj);
        }
        /// <summary>
        /// 获取发布ID
        /// </summary>
        public static int GetPushlishId(string dirid, string type = "DOM")
        {
            string sql = string.Format("select b.id from lf.sys_publish b where b.type = '{0}' and b.dirid = '{1}' limit 1", type, dirid);
            object obj = Tools.DBHelper.GetScalar(sql);
            return null == obj ? 0 : Convert.ToInt32(obj);
        }
        /// <summary>
        /// 获取已经发布的元数据ID
        /// </summary>
        public static List<int> GetPublishMetaId(int pubid)
        {
            string sql = string.Format("select metaid from lf.sys_meta_pub where pubid = {0}", pubid);
            DataTable dt = Tools.DBHelper.GetDataTable(sql);
            List<int> list = new List<int>();
            if (null == dt || 0 == dt.Rows.Count) return list;
            for (int i = 0, c = dt.Rows.Count; i < c; i++)
            {
                object obj = dt.Rows[i][0];
                if (null != obj)
                {
                    int id = 0;
                    if (int.TryParse(obj.ToString(), out id))
                    {
                        list.Add(id);
                    }
                }
            }
            return list;
        }
        /// <summary>
        /// 更新发布数据
        /// </summary>
        public static int UpdatePublish(int pubid, string name, int userId, string geom, string url = null)
        {
            string str = null == geom ? "" : string.Format(", geom={0}", geom);
            str += null == url ? "" : string.Format(", url='{0}'", url);
            string sql = string.Format("update lf.sys_publish set name=@name, update_user=@userId, update_time=now(){0} where id=@id;update lf.sys_layer set cn_name=@name where pubid=@id;", str);
            DbParameter dp1 = new NpgsqlParameter("@name", name);
            DbParameter dp2 = new NpgsqlParameter("@userId", userId);
            DbParameter dp3 = new NpgsqlParameter("@id", pubid);
            return Tools.DBHelper.ExecuteNonQuery(sql, dp1, dp2, dp3);
        }
        /// <summary>
@@ -72,7 +138,7 @@
        public static int InsertPublish(SysPublish sys)
        {
            List<DbParameter> list = Tools.GetParams<SysPublish>(insertPublishSql, sys);
            string sql = string.Format(insertPublishSql, sys.geom == null ? "null" : sys.geom);
            string sql = string.Format(insertPublishSql, string.IsNullOrEmpty(sys.geom) ? "null" : sys.geom);
            object obj = Tools.DBHelper.GetScalar(sql, list.ToArray());
@@ -225,6 +291,18 @@
        }
        /// <summary>
        /// 查询发布数据
        /// </summary>
        public static List<SysPublish> SelectPublishs(List<int> ids)
        {
            string sql = string.Format("select id, name, url, path, type, status, dirid, depid, min, max, json, create_user, create_time, update_user, update_time, st_astext(geom) geom, bak from lf.sys_publish where id in ({0}) order by id desc", string.Join(",", ids));
            DataTable dt = Tools.DBHelper.GetDataTable(sql);
            List<SysPublish> list = ModelHandler.FillModel<SysPublish>(dt);
            return list;
        }
        /// <summary>
        /// 获取参数列表
        /// </summary>
        public static List<DbParameter> GetParams<T>(string sql, T t)