AdaKing88
2023-08-21 23258c585a626b15d770459870a8b24763cf540c
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
package com.tairui.app.cim.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tairui.app.cim.dao.model.ProductionArea;
import com.tairui.app.cim.mapper.ProductionAreaMapper;
import com.tairui.app.cim.service.IProductionAreaService;
import com.tairui.app.cim.util.GeoJsonUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.http.HttpResult;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;
import io.swagger.annotations.ApiOperation;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
@RestController
@RequestMapping("/cim/productionArea")
public class ProductionAreaController {
 
    @Autowired
    IProductionAreaService iProductionAreaService;
    @Autowired
    ProductionAreaMapper productionAreaMapper;
 
    private GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
    private WKTReader reader = new WKTReader( geometryFactory );
    @GetMapping("/list")
    @ApiOperation(value = "列表",notes = "分页列出所有")
    public HttpResult list(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                           @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
 
        PageHelper.startPage(pageNo,pageSize);
        List<ProductionArea> list = productionAreaMapper.listPage();
        PageInfo<ProductionArea> page = new PageInfo<>(list);
 
 
        return HttpResult.ok(page);
    }
 
    @GetMapping("/listArea")
    @ApiOperation(value = "列表区划名称",notes = "分页列出所有")
    public HttpResult listArea(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                           @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
 
        PageHelper.startPage(pageNo,pageSize);
        List<String> list = productionAreaMapper.listAreaName();
        PageInfo<String> page = new PageInfo<>(list);
 
 
        return HttpResult.ok(page);
    }
    @PostMapping("/add")
    @ApiOperation(value = "列表",notes = "分页列出所有")
    public HttpResult add(@RequestBody String json) throws ParseException {
 
        JSONArray jsonArray = JSON.parseArray(json);
 
        for(Object obj:jsonArray){
            JSON jsonObject = (JSON)obj;
 
             String geom  =((JSONObject)obj).getString("geometry");
             Geometry geometry = GeoJsonUtil.getGeometryFromGeoJSON(geom);
             JSONObject jsonObject1 = JSON.parseObject(((JSONObject)obj).getString("properties"));
 
            ProductionArea productionArea = JSON.parseObject(jsonObject.toString(),ProductionArea.class);
            productionArea.setGeom(geometry.toText());
 
            productionAreaMapper.insert(productionArea);
        }
 
 
        return HttpResult.ok();
    }
}