OfdConvertRest.java 2.67 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.Const;
import com.suwell.ofd.custom.wrapper.PackException;
import com.suwell.ofd.custom.wrapper.Packet;
import com.suwell.ofd.custom.wrapper.model.Common;
import com.suwell.ofd.custom.wrapper.model.ImageArgument;
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) {

            //转换后文件输出路径
            try {

                String documentId = waitForConvert.getDocumentId();
                String bizId = waitForConvert.getBizId();

                Packet packet = new Packet(Const.PackType.IMAGE, Const.Target.IMAGE);
                Common common = new Common(null, "ofd", -1, new FileInputStream(waitForConvert.getOfdWjdz()));
                common.setArgument(new ImageArgument().setTargetFormat(ImageArgument.Type.jpg));
                packet.file(common);

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

                File jpg = new File("E:\\ECI\\TIFF" + dateDir + "\\");

                if (!jpg.exists()) {
                    jpg.mkdirs();
                }
                File jpgFile = new File(jpg + documentId + ".jpg");
                if (!jpgFile.exists()) {
                    jpgFile.createNewFile();
                }

                ha.convert(packet, new FileOutputStream(jpgFile));

                licenseInfoDao.updateJpgWjdzAndStatus(jpgFile.getAbsolutePath(), bizId);
            } catch (PackException | ConvertException | IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    ha.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}