| | |
| | | using Npgsql; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Data.Common; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | |
| | | { |
| | | public class PubDBHelper |
| | | { |
| | | private static List<string> lasList = new List<string>() { "cpt", "las", "laz" }; |
| | | |
| | | private static List<string> imgList = new List<string>() { "jpg", "png", "img", "tif", "tiff" }; |
| | | |
| | | private static string insertPublishSql = "insert into lf.sys_publish(name, url, path, type, status, dirid, depid, min, max, json, create_user, geom, bak) values (@name, @url, @path, @type, @status, @dirid, @depid, @min, @max, @json, @create_user, {0}, @bak) returning id"; |
| | |
| | | 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) |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是/否发布过 |
| | | /// 是/否发布过 * |
| | | /// </summary> |
| | | public static bool IsPublish(string dirid, string type = "DOM") |
| | | { |
| | |
| | | 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> |
| | |
| | | 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()); |
| | | |
| | |
| | | public static int InsertLayer(SysPublish sys, SysMeta meta, double elev = 0) |
| | | { |
| | | int pid = SelectLayerPid(sys, meta); |
| | | string cnName = meta.name.Split(new char[] { '.' })[0]; |
| | | //string cnName = meta.name.Split(new char[] { '.' })[0]; |
| | | int idx = meta.name.LastIndexOf("."); |
| | | string cnName = idx == -1 ? meta.name : meta.name.Substring(0, meta.name.LastIndexOf(".")); |
| | | string data = getData(meta); |
| | | string serve = getServe(meta); |
| | | |
| | |
| | | |
| | | if (meta.dirname.IndexOf("\\测绘") > -1) |
| | | { |
| | | if (lasList.Contains(meta.type)) |
| | | return "select id from lf.sys_layer where cn_name = '点云数据' and pid = (select id from lf.sys_layer where cn_name = '测绘' order by pid limit 1)"; |
| | | if ("osgb".Equals(meta.type)) |
| | | return "select id from lf.sys_layer where cn_name = '倾斜摄影数据' and pid = (select id from lf.sys_layer where cn_name = '测绘' order by pid limit 1)"; |
| | | if ("mpt".Equals(meta.type)) |
| | | return "select id from lf.sys_layer where cn_name = '三维地形模型' and pid = (select id from lf.sys_layer where cn_name = '测绘' order by pid limit 1)"; |
| | | if ("DEM".Equals(meta.type)) |
| | |
| | | } |
| | | |
| | | /// <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) |