OfdConvertRest.java
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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();
}
}
}
}
}