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();
|
}
|
}
|