src/main/java/com/lf/server/controller/data/MetaController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/entity/all/StaticData.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/helper/AsyncHelper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lf/server/service/show/CadService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/lf/server/controller/data/MetaController.java
@@ -22,13 +22,14 @@ import com.lf.server.service.data.DownloadService; import com.lf.server.service.data.MetaService; import com.lf.server.service.data.VerService; import com.lf.server.service.show.CadService; import com.lf.server.service.sys.DepService; import com.lf.server.service.sys.DownlogService; import com.lf.server.service.sys.TokenService; import io.swagger.annotations.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; @@ -45,26 +46,29 @@ @RestController @RequestMapping("/meta") public class MetaController extends BaseController { @Autowired @Resource MetaService metaService; @Autowired @Resource TokenService tokenService; @Autowired @Resource BaseQueryService baseQueryService; @Autowired @Resource DownlogService downlogService; @Autowired @Resource DownloadService downloadService; @Autowired @Resource VerService verService; @Autowired @Resource DepService depService; @Resource CadService cadService; @SysLog() @ApiOperation(value = "å页æ¥è¯¢å¹¶è¿åè®°å½æ°") @@ -247,6 +251,22 @@ } @SysLog() @ApiOperation(value = "æ¥è¯¢Dwg转æ¢") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "å æ°æ®ID", dataType = "int", paramType = "query", example = "7715") }) @GetMapping(value = "/selectConvertToDwg") public ResponseMsg<Object> selectConvertToDwg(int id) { try { String rs = cadService.convert(id); return success(rs); } catch (Exception ex) { return fail(ex, null); } } @SysLog() @ApiOperation(value = "æå ¥ä¸æ¡") @ApiImplicitParams({ @ApiImplicitParam(name = "entity", value = "å®ä½ç±»", dataType = "MetaEntity", paramType = "body") src/main/java/com/lf/server/entity/all/StaticData.java
@@ -62,6 +62,8 @@ public final static int I100 = 100; public final static int I120 = 120; public static final int I180 = 180; public static final int I180_NEG = -180; @@ -92,6 +94,8 @@ public final static String IN = "in"; public final static String DWG = "dwg"; public final static String ZIP = ".zip"; public final static String XLS = ".xls"; src/main/java/com/lf/server/helper/AsyncHelper.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,63 @@ package com.lf.server.helper; import com.lf.server.entity.all.StaticData; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.util.TimerTask; import java.util.concurrent.ExecutorService; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; /** * 弿¥å¸®å©ç±» * @author WWW * @date 2023-07-10 */ public class AsyncHelper { /** * æä½å»¶è¿10æ¯«ç§ */ private final static int OPERATE_DELAY_TIME = 10; private final static Log log = LogFactory.getLog(AsyncHelper.class); private ScheduledExecutorService executor = SpringContextHelper.getBean("scheduledExecutorService"); public AsyncHelper() { } /** * æ§è¡ä»»å¡ */ public void execute(TimerTask task) { executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS); } /** * å ³éä»»å¡ */ public void shutdown() { shutdownAndAwaitTermination(executor); } /** * 忢任å¡çº¿ç¨æ± */ public static void shutdownAndAwaitTermination(ExecutorService pool) { try { if (null == pool || pool.isShutdown()) { return; } pool.shutdown(); if (!pool.awaitTermination(StaticData.I120, TimeUnit.SECONDS)) { pool.shutdownNow(); } } catch (InterruptedException ie) { pool.shutdownNow(); Thread.currentThread().interrupt(); } } } src/main/java/com/lf/server/service/show/CadService.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,201 @@ package com.lf.server.service.show; import com.lf.server.entity.all.StaticData; import com.lf.server.entity.data.MetaEntity; import com.lf.server.helper.PathHelper; import com.lf.server.service.data.MetaService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.io.*; /** * CADæå¡ç±» * @author WWW * @date 2024-04-17 */ @SuppressWarnings("ALL") @Service public class CadService { @Value("${sys.cad.exePath}") private String exePath; @Value("${sys.cad.targetPath}") private String targetPath; @Resource MetaService metaService; @Resource PathHelper pathHelper; private final static Log log = LogFactory.getLog(CadService.class); /** * æ ¼å¼è½¬å */ public String convert(int metaId) { MetaEntity me = metaService.selectById(metaId); if (null == me || StringUtils.isEmpty(me.getPath()) || !StaticData.DWG.equals(me.getType())) { return null; } String dwg = pathHelper.getConfig().getUploadPath() + File.separator + me.getPath(); File file = new File(dwg); if (!file.exists() || file.isDirectory()) { return null; } String[] strs = me.getPath().replace("\\", "/").split("/"); String outPath = targetPath + "/" + strs[0]; String outName = strs[1].replace(".dwg", ".mxweb"); file = new File(outPath + "/" + outName); if (file.exists()) { return strs[0] + "/" + outName; } if (callConvert(dwg, outPath, outName)) { return strs[0] + "/" + outName; } return null; } public boolean callConvert(String dwgFile, String outPath, String outName) { try { String jsonParam = "{'srcpath':'" + dwgFile + "','outpath':'" + outPath + "','outname':'" + outName + "'}"; File f = new File(outPath); if (!f.exists() || !f.isDirectory()) { f.mkdirs(); } StringBuilder sb = new StringBuilder(); Process process = Runtime.getRuntime().exec(new String[]{exePath, jsonParam}); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } reader.close(); return true; } catch (Exception ex) { log.error(ex.getMessage(), ex); return false; } } public boolean callConvert(String dwgFile) { try { StringBuilder sb = new StringBuilder(); String jsonParam = "{\"srcpath\":\"" + dwgFile + "\"}"; Process process = Runtime.getRuntime().exec(new String[]{exePath, jsonParam}); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } reader.close(); return true; } catch (Exception ex) { log.error(ex.getMessage(), ex); return false; } } @SuppressWarnings("AlibabaAvoidManuallyCreateThread") public String callMxFileConvert(String sDwgFile) { Runtime rn = Runtime.getRuntime(); Process process = null; // 转æ¢åæ°ã String sJsonParam = "{\"srcpath\":\"" + sDwgFile + "\"}"; String[] sRetJson = new String[1]; try { // å¯å¨ä¸ä¸ªè¿ç¨åºï¼è°ç¨è½¬æ¢ç¨åºã process = rn.exec(new String[]{exePath, sJsonParam}); final InputStream ins = process.getInputStream(); final InputStream errs = process.getErrorStream(); //ç¡®ä¿åè¿ç¨ä¸ä¸»è¿ç¨ä¹é´inputStreamä¸é»å¡ new Thread() { @Override public void run() { BufferedReader inb = null; String line = null; try { inb = new BufferedReader(new InputStreamReader(ins, "gbk")); while ((line = inb.readLine()) != null) { sRetJson[0] = line; } } catch (IOException e) { e.printStackTrace(); } finally { try { if (null != inb) { inb.close(); } if (null != ins) { ins.close(); } } catch (IOException e) { e.printStackTrace(); } } } }.start(); new Thread() { @Override public void run() { BufferedReader errb = null; String line = null; try { errb = new BufferedReader(new InputStreamReader(errs, "gbk")); while ((line = errb.readLine()) != null) { System.out.println("executeMxExe - ErrorStream : " + line); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (null != errb) { errb.close(); } if (null != errs) { errs.close(); } } catch (IOException e) { e.printStackTrace(); } } } }.start(); process.waitFor(); } catch (Exception e) { log.error(e.getMessage(), e); } finally { if (null != process) { OutputStream out = process.getOutputStream(); if (null != out) { try { out.close(); } catch (IOException e) { log.error(e.getMessage(), e); } } process.destroy(); } } return sRetJson[0]; } } src/main/resources/application.yml
@@ -153,5 +153,8 @@ upload: D:\LF\upload # 临æ¶ç®å½ temp: D:\LF\temp cad: exePath: C:/360/MxDrawCloudServer1.0TryVersion/MxDrawCloudServer/Bin/MxCAD/Release/mxcadassembly.exe targetPath: C:/360/MxDrawCloudServer1.0TryVersion/MxDrawCloudServer/SRC/TsWeb/public/data # ä¸ä¼ é件表 attachTabs: bd.b_pac_hydrogeology,bd.b_pac_frozensoil,bd.b_pac_geologic_hazard,bd.b_pac_marine_meteorological,bd.b_pac_meteorological,bs.m_equipment_nameplate,bs.m_hydraulic_protection,bs.m_marker,bs.s_explorationpoint,bs.u_sectionline