管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-04-22 cc816055746ae0ffa870734e5a411b2a2aabb96a
src/main/java/com/lf/server/service/show/CadService.java
@@ -2,8 +2,11 @@
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;
@@ -31,6 +34,9 @@
    MetaService metaService;
    @Resource
    AttachService attachService;
    @Resource
    PathHelper pathHelper;
    private final static Log log = LogFactory.getLog(CadService.class);
@@ -38,19 +44,19 @@
    /**
     * 格式转化
     */
    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);
@@ -62,9 +68,30 @@
            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 + "'}";