|
@@ -5,22 +5,24 @@ import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.vividsolutions.jts.geom.Geometry;
|
|
|
-import com.vividsolutions.jts.io.ParseException;
|
|
|
-import com.vividsolutions.jts.io.WKBReader;
|
|
|
import com.vividsolutions.jts.io.WKTReader;
|
|
|
+import com.zjugis.ysgzybz.dao.BjlsydMapper;
|
|
|
import com.zjugis.ysgzybz.dao.YbzBJDao;
|
|
|
import com.zjugis.ysgzybz.domain.dto.CommonDTO;
|
|
|
import com.zjugis.ysgzybz.domain.dto.ManageDTO;
|
|
|
import com.zjugis.ysgzybz.domain.dto.WlydDTO;
|
|
|
+import com.zjugis.ysgzybz.domain.entity.Bjlsyd;
|
|
|
+import com.zjugis.ysgzybz.domain.entity.UploadTxtResultVO;
|
|
|
import com.zjugis.ysgzybz.domain.entity.WlydExcelDO;
|
|
|
import com.zjugis.ysgzybz.domain.entity.ZoneGeometry;
|
|
|
-import com.zjugis.ysgzybz.utils.GeometryUtil;
|
|
|
-import com.zjugis.ysgzybz.utils.JzdUtil;
|
|
|
-import com.zjugis.ysgzybz.utils.StyleUtils;
|
|
|
+import com.zjugis.ysgzybz.utils.*;
|
|
|
+import com.zjugis.ysgzybz.utils.geocomm.JzdDk;
|
|
|
+import com.zjugis.ysgzybz.utils.geocomm.JzdSx;
|
|
|
+import com.zjugis.ysgzybz.utils.geocomm.ParseResult;
|
|
|
+import com.zjugis.ysgzybz.utils.geocomm.TxtReader;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -30,13 +32,10 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.function.Function;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -45,6 +44,9 @@ public class YbzBJService {
|
|
|
@Autowired
|
|
|
private YbzBJDao dao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BjlsydMapper bjlsydMapper;
|
|
|
+
|
|
|
/** 通过id获取未利用地 **/
|
|
|
public Object getWlydById(CommonDTO dto) {
|
|
|
return dao.getWlydById(dto);
|
|
@@ -255,6 +257,90 @@ public class YbzBJService {
|
|
|
return dao.manageOne(dto);
|
|
|
}
|
|
|
|
|
|
+ public UploadTxtResultVO uploadFile(InputStream inputStream) throws Exception {
|
|
|
+ //解析上传的txt为ParseResult
|
|
|
+ TxtReader txtReader = new TxtReader(inputStream);
|
|
|
+ ParseResult result = txtReader.read();
|
|
|
+
|
|
|
+ Geometry geometry = result.getGeometry();
|
|
|
+ List<JzdDk> jzdDkList = result.getJzdDkList();
|
|
|
+
|
|
|
+ String dkmc = jzdDkList.get(0).getDkmc();
|
|
|
+
|
|
|
+ double dkmj =0;
|
|
|
+ for (JzdDk jzdDk : jzdDkList) {
|
|
|
+ dkmj += jzdDk.getDkmj();
|
|
|
+ }
|
|
|
+
|
|
|
+ UploadTxtResultVO vo = new UploadTxtResultVO();
|
|
|
+ vo.setErrorList(result.getErrorList());
|
|
|
+
|
|
|
+ Bjlsyd entity = new Bjlsyd();
|
|
|
+ QueryWrapper<Bjlsyd> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.select("max(id) as id","max(xh) as xh");
|
|
|
+ Bjlsyd bjlsyd = bjlsydMapper.selectOne(wrapper);
|
|
|
+ float id = bjlsyd.getId() + 1;
|
|
|
+ int xh = (int) id + 100;
|
|
|
+ try {
|
|
|
+ xh = Integer.parseInt(bjlsyd.getXh()) + 1;
|
|
|
+ } catch (NumberFormatException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ entity.setId(id);
|
|
|
+ entity.setObjectid(id);
|
|
|
+ entity.setXh(String.valueOf(xh));
|
|
|
+ entity.setXh1((float) xh);
|
|
|
+ entity.setXmmc(dkmc);
|
|
|
+ entity.setSpmj(dkmj * 10000);
|
|
|
+
|
|
|
+ int insert = bjlsydMapper.insert(entity);
|
|
|
+ if (insert > 0) {
|
|
|
+ bjlsydMapper.updateGeometry(geometry.toText(), id);
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String exportOneShape(CommonDTO dto) {
|
|
|
+ File rootPath = new File(System.getProperty("user.dir"));
|
|
|
+ String prefix = UUID.randomUUID().toString();
|
|
|
+ String dkFileName = prefix + ".shp";
|
|
|
+ String formatFileName = "shp" + File.separator + dkFileName;
|
|
|
+ File dkFile = new File(rootPath, formatFileName);
|
|
|
+ if (!dkFile.getParentFile().exists()) {
|
|
|
+ dkFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ String fileFullPath = dkFile.getAbsolutePath();
|
|
|
+ Map<String, Object> resultMap = dao.exportOne(dto);
|
|
|
+ String shape = resultMap.get("shape").toString();
|
|
|
+ Geometry geometry = null;
|
|
|
+ try {
|
|
|
+ geometry = GeometryUtil.wkt2Geometry(shape);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (geometry != null) {
|
|
|
+ resultMap.put("shape", geometry);
|
|
|
+ }
|
|
|
+ List<String> attrKeys = new ArrayList();
|
|
|
+ for (String key : resultMap.keySet()) {
|
|
|
+ attrKeys.add(key.toUpperCase());
|
|
|
+ }
|
|
|
+ List<Map<String, Object>> mapList = new ArrayList<>();
|
|
|
+ mapList.add(resultMap);
|
|
|
+ ShapeUtil.write2Shape(fileFullPath, "GBK", "Polygon", "shape", attrKeys, mapList);
|
|
|
+ //压缩shp
|
|
|
+ ShapeUtil.zipShapeFile(fileFullPath);
|
|
|
+
|
|
|
+ //删除临时生产的.shp文件
|
|
|
+ File shpFile = new File(fileFullPath);
|
|
|
+ String shpRoot = shpFile.getParentFile().getPath();
|
|
|
+ File[] files = new File(shpRoot).listFiles(file -> file.getName().startsWith(prefix) && !file.getName().endsWith(".zip"));
|
|
|
+ for (File file : files) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ return fileFullPath.replace(".shp", ".zip");
|
|
|
+ }
|
|
|
+
|
|
|
/** 地块管理汇总 **/
|
|
|
public Map<String, Object> manageHZ(CommonDTO dto) {
|
|
|
return dao.manageHZ(dto);
|