OfdConvertRest.java 2.49 KB
package com.thinkgem.jeesite.modules.eci.method;

import com.suwell.ofd.custom.agent.ConvertException;
import com.suwell.ofd.custom.agent.HTTPAgent;
import com.suwell.ofd.custom.wrapper.PackException;
import com.thinkgem.jeesite.modules.eci.dao.ElecLicenseInfoDao;
import com.thinkgem.jeesite.modules.eci.entity.ElecLicenseInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * ofd文件转换
 */
@Component
public class OfdConvertRest {

    private Logger logger = LoggerFactory.getLogger(OfdConvertRest.class);

    HTTPAgent ha = new HTTPAgent("http://172.16.56.42:8090");

    @Autowired
    ElecLicenseInfoDao licenseInfoDao;

    public void convert() {

        List<ElecLicenseInfo> waitForConverts = licenseInfoDao.getWaitForConvert();

        for (ElecLicenseInfo waitForConvert : waitForConverts) {
            OutputStream out = null;

            //转换后文件输出路径
            try {
                String bizId = waitForConvert.getBizId();
                String ofdPath = waitForConvert.getOfdWjdz();
                // TODO: 2022/2/16/0016 ofd文件转换
                File ofdFile = new File(ofdPath);

                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dddd");
                String dateDir = simpleDateFormat.format(new Date());

                String documentId = waitForConvert.getDocumentId();

                File tiffDir = new File("E:\\ECI\\TIFF" + dateDir + "\\");
                if (!tiffDir.exists()) {
                    tiffDir.mkdirs();
                }
                File tiffFile = new File(tiffDir + documentId + ".tiff");
                if (!tiffFile.exists()) {
                    tiffFile.createNewFile();
                }

                out = new FileOutputStream(tiffFile);
                //输出格式。true输出格式为zip ;false输出格式为tiff
                ha.OFDToImge(ofdFile, out, -1, false);
                licenseInfoDao.updateJpgWjdzAndStatus(tiffFile.getAbsolutePath(), bizId);
            } catch (PackException | ConvertException | IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    ha.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}