管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-03 3cfb6aa02516135fb174ab1b30620f2007924663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using JiangSu.cs;
using JiangSu.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
 
namespace JiangSu.Controllers
{
    public class GridController : ApiController
    {
        [HttpGet]
        public object SelectAll()
        {
            try
            {
                List<Grid> grids = GridDAL.SelectAll();
                List<JObject> list = GetJObjects(grids);
 
                Dictionary<string, object> dict = GetDict();
                dict.Add("features", list);
 
                return dict;
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return null;
            }
        }
 
        private Dictionary<string, object> GetDict()
        {
            string crs = "{ \"type\": \"name\", \"properties\": { \"name\": \"urn:ogc:def:crs:OGC:1.3:CRS84\" } }";
            JObject crsJObj = JsonConvert.DeserializeObject<JObject>(crs);
 
            Dictionary<string, object> dict = new Dictionary<string, object>();
            dict.Add("type", "FeatureCollection");
            dict.Add("name", "网格4549");
            dict.Add("crs", crsJObj);
 
            return dict;
        }
 
        private List<JObject> GetJObjects(List<Grid> grids)
        {
            List<JObject> list = new List<JObject>();
            if (null != grids && grids.Count > 0)
            {
                foreach (Grid g in grids)
                {
                    JObject obj = JsonConvert.DeserializeObject<JObject>(g.json);
                    list.Add(obj);
                }
            }
 
            return list;
        }
 
        [HttpGet]
        public object SelectById(long id)
        {
            try
            {
                Grid grid = GridDAL.SelectById(id);
                List<JObject> list = GetJObjects(null == grid ? null : new List<Grid> { grid });
 
                Dictionary<string, object> dict = GetDict();
                dict.Add("features", list);
 
                return dict;
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return null;
            }
        }
 
        [HttpGet]
        public int DeleteByIds([FromUri] List<int> ids)
        {
            try
            {
                if (null == ids || ids.Count == 0) return 0;
 
                return GridDAL.DeleteByIds(ids);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return 0;
            }
        }
 
        [HttpGet]
        public int DelAll()
        {
            try
            {
                return GridDAL.DelAll();
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return 0;
            }
        }
 
        [HttpPost]
        public int Insert([FromBody] Grid grid)
        {
            try
            {
                if (null == grid) return 0;
 
                return GridDAL.Insert(grid);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return 0;
            }
        }
 
        [HttpPost]
        public int UpdateById([FromBody] Grid grid)
        {
            try
            {
                if (null == grid) return 0;
 
                return GridDAL.UpdateById(grid);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                return 0;
            }
        }
    }
}