|
@@ -0,0 +1,310 @@
|
|
|
+package com.fd.server.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fd.constant.Command;
|
|
|
+import com.fd.constant.MsgCode;
|
|
|
+import com.fd.constant.TypeCode;
|
|
|
+import com.fd.dto.ConfigJsonDto;
|
|
|
+import com.fd.entity.FileEntity;
|
|
|
+import com.fd.entity.OutputFileEntity;
|
|
|
+import com.fd.entity.StyleEntity;
|
|
|
+import com.fd.entity.User;
|
|
|
+import com.fd.repository.FileRepository;
|
|
|
+import com.fd.repository.OutputFileRepository;
|
|
|
+import com.fd.repository.StyleRepository;
|
|
|
+import com.fd.repository.UserRepository;
|
|
|
+import com.fd.server.DemServer;
|
|
|
+import com.fd.server.WfsServer;
|
|
|
+import com.fd.shiro.JWTUtil;
|
|
|
+import com.fd.thread.AsyncTask;
|
|
|
+import com.fd.util.*;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.*;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.BlockingQueue;
|
|
|
+import java.util.concurrent.LinkedBlockingQueue;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Owen on 2020/01/19 0021 15:29
|
|
|
+ */
|
|
|
+@Log4j2
|
|
|
+@Service
|
|
|
+public class WfsServerImpl extends BaseServerImpl implements WfsServer {
|
|
|
+
|
|
|
+ private String INPUT_PATH;
|
|
|
+
|
|
|
+ private String OUTPUT_PATH;
|
|
|
+
|
|
|
+ @Value("${base.path}")
|
|
|
+ private String BASE_PATH;
|
|
|
+
|
|
|
+ // config.json 地址
|
|
|
+ @Value("${config.path}")
|
|
|
+ private String CONFIG_JSON_PATH;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ private void init(){
|
|
|
+ this.INPUT_PATH = BASE_PATH + "/input/wfs/";
|
|
|
+ this.OUTPUT_PATH = BASE_PATH + "/output/wfs/";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OutputFileRepository outputFileRepository;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 精准查询
|
|
|
+ *
|
|
|
+ * @param fileId
|
|
|
+ * @param fileName 字段名
|
|
|
+ * @param value 字段值
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R wfsAccurate(Long fileId, String fileName, String value) {
|
|
|
+ log.warn("run wfsAccurate");
|
|
|
+
|
|
|
+ OutputFileEntity entity = getOutputFileEntity(fileId);
|
|
|
+ if (entity == null){
|
|
|
+ new R(50002, MsgCode.E50002);
|
|
|
+ }
|
|
|
+
|
|
|
+ String cmd = Command.VECTOR_WFS_ACCURATE;
|
|
|
+ String outFile = OUTPUT_PATH + entity.getDirectory();
|
|
|
+ FileUtils.createDir(outFile);
|
|
|
+ String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
|
|
|
+ timeName = outFile + File.separator + timeName + ".json";
|
|
|
+
|
|
|
+ // 需要坐标转换后的shp文件
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
|
|
|
+ cmd = cmd.replace("@outputFile", timeName);
|
|
|
+ cmd = cmd.replace("@fileName", fileName);
|
|
|
+ cmd = cmd.replace("@value", value);
|
|
|
+
|
|
|
+ Integer integer = CmdUtil.exeCmdSingle(cmd);
|
|
|
+ if (integer == 0) {
|
|
|
+ // 返回文件地址给前端自己读文件
|
|
|
+ timeName = timeName.replace(BASE_PATH, "");
|
|
|
+ log.info("url: {}", timeName);
|
|
|
+
|
|
|
+ if (entity.getWfsPath() == null) {
|
|
|
+ //保存信息
|
|
|
+ entity.setWfsPath(outFile);
|
|
|
+ entity.setUpdateTime(new DateTime());
|
|
|
+ outputFileRepository.save(entity);
|
|
|
+ }
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("url", timeName);
|
|
|
+ log.warn("end wfsAccurate");
|
|
|
+ return new R(200, map);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("end wfsAccurate");
|
|
|
+ return new R(200, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R wfsLike(Long fileId, String fileName, String value) {
|
|
|
+ log.warn("run wfsLike");
|
|
|
+
|
|
|
+ OutputFileEntity entity = getOutputFileEntity(fileId);
|
|
|
+ if (entity == null){
|
|
|
+ new R(50002, MsgCode.E50002);
|
|
|
+ }
|
|
|
+
|
|
|
+ String cmd = Command.VECTOR_WFS_LIKE;
|
|
|
+// String outFile = OUTPUT_FILE_PATH + "wfs" + File.separator + entity.getDirectory();
|
|
|
+ String outFile = OUTPUT_PATH + entity.getDirectory();
|
|
|
+ FileUtils.createDir(outFile);
|
|
|
+ String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
|
|
|
+ timeName = outFile + File.separator + timeName + ".json";
|
|
|
+
|
|
|
+ // 需要坐标转换后的shp文件
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
|
|
|
+ cmd = cmd.replace("@outputFile", timeName);
|
|
|
+ cmd = cmd.replace("@fileName", fileName);
|
|
|
+ cmd = cmd.replace("@value", value);
|
|
|
+
|
|
|
+ Integer integer = CmdUtil.exeCmdSingle(cmd);
|
|
|
+ if (integer == 0) {
|
|
|
+ // 返回文件地址给前端自己读文件
|
|
|
+ timeName = timeName.replace(BASE_PATH, "");
|
|
|
+ log.info("url: {}", timeName);
|
|
|
+
|
|
|
+ if (entity.getWfsPath() == null) {
|
|
|
+ //保存信息
|
|
|
+ entity.setWfsPath(outFile);
|
|
|
+ entity.setUpdateTime(new DateTime());
|
|
|
+ outputFileRepository.save(entity);
|
|
|
+ }
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("url", timeName);
|
|
|
+ log.warn("end wfsLike");
|
|
|
+ return new R(200, map);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("end wfsLike");
|
|
|
+ return new R(200, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R wfsScope(Long fileId, String xMin, String yMin, String xMax, String yMax) {
|
|
|
+ log.warn("run wfsScope");
|
|
|
+
|
|
|
+ OutputFileEntity entity = getOutputFileEntity(fileId);
|
|
|
+ if (entity == null){
|
|
|
+ new R(50002, MsgCode.E50002);
|
|
|
+ }
|
|
|
+
|
|
|
+ String cmd = Command.VECTOR_WFS_SCOPE;
|
|
|
+// String outFile = OUTPUT_FILE_PATH + "wfs" + File.separator + entity.getDirectory();
|
|
|
+ String outFile = OUTPUT_PATH + entity.getDirectory();
|
|
|
+ FileUtils.createDir(outFile);
|
|
|
+ String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
|
|
|
+ timeName = outFile + File.separator + timeName + ".json";
|
|
|
+
|
|
|
+ // 需要坐标转换后的shp文件
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
|
|
|
+ cmd = cmd.replace("@outputFile", timeName);
|
|
|
+ cmd = cmd.replace("@xMin", xMin);
|
|
|
+ cmd = cmd.replace("@yMin", yMin);
|
|
|
+ cmd = cmd.replace("@xMax", xMax);
|
|
|
+ cmd = cmd.replace("@yMax", yMax);
|
|
|
+
|
|
|
+ Integer integer = CmdUtil.exeCmdSingle(cmd);
|
|
|
+ if (integer == 0) {
|
|
|
+ // 返回文件地址给前端自己读文件
|
|
|
+ timeName = timeName.replace(BASE_PATH, "");
|
|
|
+ log.info("url: {}", timeName);
|
|
|
+
|
|
|
+ if (entity.getWfsPath() == null) {
|
|
|
+ //保存信息
|
|
|
+ entity.setWfsPath(outFile);
|
|
|
+ entity.setUpdateTime(new DateTime());
|
|
|
+ outputFileRepository.save(entity);
|
|
|
+ }
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ map.put("url", timeName);
|
|
|
+ log.warn("end wfsScope");
|
|
|
+ return new R(200, map);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("end wfsScope");
|
|
|
+ return new R(200, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R getField(Long fileId) {
|
|
|
+ log.warn("run getField");
|
|
|
+
|
|
|
+ OutputFileEntity entity = getOutputFileEntity(fileId);
|
|
|
+ if (entity == null){
|
|
|
+ new R(50002, MsgCode.E50002);
|
|
|
+ }
|
|
|
+
|
|
|
+ String cmd = Command.VECTOR_WFS_FIELD;
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
|
|
|
+ List list = cmdSubField(cmd);
|
|
|
+
|
|
|
+ log.warn("end getField");
|
|
|
+ return new R(200, list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析获取字段
|
|
|
+ * @param commandStr
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static List cmdSubField(String commandStr) {
|
|
|
+ log.info("cmd: {}", commandStr );
|
|
|
+
|
|
|
+ // 命令运行结果 1:失败, 0:成功
|
|
|
+ Integer isCmd = null;
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
|
|
|
+ Process ps = Runtime.getRuntime().exec(cmd);
|
|
|
+
|
|
|
+ BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
|
|
|
+ BufferedReader errorBuf = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
|
|
|
+
|
|
|
+
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ StringBuffer errorStr = new StringBuffer();
|
|
|
+
|
|
|
+ // error : 坑, 控制台信息是从errorBuf这里出来的
|
|
|
+ String errorLine;
|
|
|
+ while ((errorLine = errorBuf.readLine()) != null) {
|
|
|
+ errorStr.append(errorLine).append("\n");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(errorStr)){
|
|
|
+ log.info("error result: {}", errorStr.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ // success ,没有获取到信息
|
|
|
+ String line;
|
|
|
+ while ((line = br.readLine()) != null) {
|
|
|
+ //执行结果加上回车
|
|
|
+ sb.append(line).append("\n");
|
|
|
+ // 解析获取字段值
|
|
|
+ if (RegexUtils.regexInclude(line)) {
|
|
|
+ String s = StringUtils.substringBefore(line, ":");
|
|
|
+ list.add(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("result: {}", sb.toString());
|
|
|
+
|
|
|
+ // 结束命令行
|
|
|
+ isCmd = ps.waitFor();
|
|
|
+
|
|
|
+ // 关闭流
|
|
|
+ br.close();
|
|
|
+ errorBuf.close();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isCmd == 0) {
|
|
|
+ log.info("end exeCmd : {}", isCmd);
|
|
|
+ return list;
|
|
|
+ } else {
|
|
|
+ log.info("wsitFore cmd run error : {}", isCmd);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|