管道基础大数据平台系统开发-【后端】-Server
13693261870
2024-04-22 cc816055746ae0ffa870734e5a411b2a2aabb96a
添加附件dwg的转换
已修改2个文件
41 ■■■■ 文件已修改
src/main/java/com/lf/server/controller/data/MetaController.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/service/show/CadService.java 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/lf/server/controller/data/MetaController.java
@@ -253,12 +253,13 @@
    @SysLog()
    @ApiOperation(value = "查询Dwg转换")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "元数据ID", dataType = "int", paramType = "query", example = "7715")
            @ApiImplicitParam(name = "id", value = "元数据ID", dataType = "int", paramType = "query", example = "7715"),
            @ApiImplicitParam(name = "isAttach", value = "是否为附件", dataType = "Boolean", paramType = "query", example = "false")
    })
    @GetMapping(value = "/selectConvertToDwg")
    public ResponseMsg<Object> selectConvertToDwg(int id) {
    public ResponseMsg<Object> selectConvertToDwg(int id, Boolean isAttach) {
        try {
            String rs = cadService.convert(id);
            String rs = cadService.convert(id, isAttach);
            return success(rs);
        } catch (Exception ex) {
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())) {
    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 "";
        }
        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);
@@ -65,6 +71,24 @@
        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();
    }
    /**
     * 调用格式转换
     */