| | |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.sys.AttachEntity; |
| | | import com.lf.server.helper.PathHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.service.data.MetaService; |
| | | import com.lf.server.service.sys.AttachService; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | MetaService metaService; |
| | | |
| | | @Resource |
| | | AttachService attachService; |
| | | |
| | | @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; |
| | | public String convert(int id, Boolean isAttach) { |
| | | String path = getFilePath(id, isAttach); |
| | | if (StringHelper.isEmpty(path)) { |
| | | return ""; |
| | | } |
| | | |
| | | String dwg = pathHelper.getConfig().getUploadPath() + File.separator + me.getPath(); |
| | | String dwg = pathHelper.getConfig().getUploadPath() + File.separator + path; |
| | | File file = new File(dwg); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | return null; |
| | | return ""; |
| | | } |
| | | |
| | | String[] strs = me.getPath().replace("\\", "/").split("/"); |
| | | String[] strs = path.replace("\\", "/").split("/"); |
| | | String outPath = targetPath + "/" + strs[0]; |
| | | String outName = strs[1].replace(".dwg", ".mxweb"); |
| | | file = new File(outPath + "/" + outName); |
| | |
| | | return strs[0] + "/" + outName; |
| | | } |
| | | |
| | | return null; |
| | | return ""; |
| | | } |
| | | |
| | | private String getFilePath(int id, Boolean isAttach) { |
| | | if (null == isAttach || !isAttach) { |
| | | MetaEntity me = metaService.selectById(id); |
| | | if (null == me || StringUtils.isEmpty(me.getPath()) || !StaticData.DWG.equals(me.getType())) { |
| | | return null; |
| | | } |
| | | |
| | | return me.getPath(); |
| | | } |
| | | |
| | | AttachEntity ae = attachService.selectById(id); |
| | | if (null == ae || StringUtils.isEmpty(ae.getPath()) || !ae.getPath().toLowerCase().contains(StaticData.DWG)) { |
| | | return null; |
| | | } |
| | | |
| | | return ae.getPath(); |
| | | } |
| | | |
| | | /** |
| | | * 调用格式转换 |
| | | */ |
| | | public boolean callConvert(String dwgFile, String outPath, String outName) { |
| | | try { |
| | | String jsonParam = "{'srcpath':'" + dwgFile + "','outpath':'" + outPath + "','outname':'" + outName + "'}"; |