171 lines
6.5 KiB
Java
171 lines
6.5 KiB
Java
package com.ample.icms.scan;
|
||
|
||
import com.amarsoft.are.jbo.BizObject;
|
||
import com.amarsoft.are.jbo.BizObjectManager;
|
||
import com.amarsoft.are.jbo.JBOFactory;
|
||
import com.amarsoft.awe.util.SqlObject;
|
||
import com.amarsoft.awe.util.Transaction;
|
||
import com.ample.icms.service.ImageService;
|
||
import com.ample.icms.util.PropertiesUtil;
|
||
import com.sunyard.insurance.ecm.socket.client.AutoScanApi;
|
||
import com.sunyard.insurance.encode.client.EncodeAccessParam;
|
||
import com.tenwa.officetempalte.exportcallback.impl.ZipUtils;
|
||
import jbo.app.tenwa.doc.LB_DOC_CONTRACT_LIST;
|
||
import org.apache.commons.httpclient.HttpClient;
|
||
import org.apache.commons.httpclient.HttpException;
|
||
import org.apache.commons.httpclient.HttpStatus;
|
||
import org.apache.commons.httpclient.SimpleHttpConnectionManager;
|
||
import org.apache.commons.httpclient.methods.PostMethod;
|
||
import org.dom4j.Document;
|
||
import org.dom4j.DocumentException;
|
||
import org.dom4j.io.OutputFormat;
|
||
import org.dom4j.io.SAXReader;
|
||
import org.dom4j.io.XMLWriter;
|
||
|
||
import java.io.*;
|
||
import java.nio.charset.StandardCharsets;
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
|
||
public class ImageDownload extends ImageService {
|
||
private String zipPath ;
|
||
private String projectId;
|
||
private String flowUnid;
|
||
private String fileSavePath;
|
||
public static String testBatchDownload () throws Exception {
|
||
//准备参数
|
||
StringBuilder sb = new StringBuilder("xml=交互参数xml字符串&code=ECM0009&format=xml");
|
||
String param = EncodeAccessParam.getEncodeParam(sb.toString(),300, PropertiesUtil.get("secret_key"));
|
||
String result="";
|
||
PostMethod postMethod = null;
|
||
HttpClient httpClient = null;
|
||
try{
|
||
postMethod = new PostMethod(PropertiesUtil.get("url"));
|
||
// 设置格式
|
||
postMethod.getParams().setContentCharset("UTF-8");
|
||
postMethod.setParameter("data", param);
|
||
postMethod.setRequestHeader("Referer", "http://172.16.20.212/imaging");
|
||
httpClient = new HttpClient();
|
||
// 执行postMethod
|
||
int statusCode = httpClient.executeMethod(postMethod);
|
||
if(statusCode== HttpStatus.SC_OK){
|
||
byte[] bodydata = postMethod.getResponseBody();
|
||
//取得返回值
|
||
result = new String(bodydata, "UTF-8");
|
||
}else{
|
||
}
|
||
}catch (HttpException e) {
|
||
//协议发生异常,URL不合法请检查URL!
|
||
} catch (IOException e) {
|
||
//请检查网络是否通畅,检查网线是否插好!
|
||
} catch(Exception e){
|
||
|
||
}finally {
|
||
if (postMethod != null) {
|
||
try {
|
||
postMethod.releaseConnection();
|
||
} catch (Exception e) {
|
||
}
|
||
}
|
||
if (httpClient != null) {
|
||
try {
|
||
((SimpleHttpConnectionManager) httpClient.getHttpConnectionManager()).shutdown();
|
||
} catch (Exception e) {
|
||
}
|
||
httpClient = null;
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public void doUpload(){
|
||
// String zipPath = "C:/Users/ivanl/Desktop/影像系统/ECM4.0Demo/ECM4.0Demo/第三方上传/1111.zip";
|
||
String zipPath = PropertiesUtil.get("fileSavePathTemp")+"/"+flowUnid+".zip";
|
||
try {
|
||
AutoScanApi autoScanApi = new AutoScanApi(PropertiesUtil.get("service_ip"),8088,PropertiesUtil.get("secret_id")+"#"+PropertiesUtil.get("secret_key"));
|
||
String result = autoScanApi.ScanImageFile(appCode, zipPath);
|
||
String returnCode = result.substring(0,result.indexOf("@"));
|
||
String returnMsg = result.substring(result.indexOf("@")+1,result.length()+1);
|
||
intoLog(returnCode,returnMsg);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
public void intoLog(String code ,String msg) {
|
||
Transaction transaction = null;
|
||
Transaction.createTransaction("als");
|
||
SqlObject so = null;
|
||
try {
|
||
so = new SqlObject("insert into icms_upload_log (id,flowunid,path,code,msg,inputtime) values ()");
|
||
transaction.executeSQL(so);
|
||
transaction.commit();
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
}
|
||
|
||
public void upload() throws Exception {
|
||
/**
|
||
* 1.找出需要上传的影像
|
||
* 3.在指定路径添加对应xml文件
|
||
* 4.打包上传
|
||
* 5.删除复制文件和打包文件
|
||
*/
|
||
FileOutputStream fos = new FileOutputStream(new File(PropertiesUtil.get("fileSavePathTemp")+"/"+flowUnid+".zip"));
|
||
ZipUtils zdo = new ZipUtils();
|
||
zdo.toZip(copyFile(),fos);
|
||
}
|
||
|
||
/**
|
||
* 上传成功后再删除
|
||
*/
|
||
public void deleteTemp(){
|
||
File f = new File(PropertiesUtil.get("fileSavePathTemp"));
|
||
if(f.length()!=0){
|
||
ZipUtils zdo = new ZipUtils();
|
||
zdo.deleteFile(f,false);
|
||
}
|
||
}
|
||
public List<File> copyFile() throws Exception {
|
||
List<File> files = new ArrayList<>();
|
||
BizObjectManager bom = JBOFactory.getBizObjectManager(LB_DOC_CONTRACT_LIST.CLASS_NAME);
|
||
List<BizObject> bos = bom.createQuery("sign_type='COMPLETE' and file_flag='yes' and project_id=:projectId and flow_unid=:flowUnid")
|
||
.setParameter("projectId",projectId).setParameter("flowUnid",flowUnid).getResultList(false);
|
||
for(BizObject bo : bos){
|
||
String filePath = bo.getAttribute("fullpath").toString();
|
||
File file = new File(filePath);
|
||
files.add(file);
|
||
}
|
||
//todo 加上xml文件
|
||
createXMl();
|
||
File fileXML = new File("xmlpath");
|
||
files.add(fileXML);
|
||
return files;
|
||
}
|
||
public void createXMl() throws Exception {
|
||
String appCode = "BQCW-000010";
|
||
String appName = "签约文件";
|
||
this.setAppCode(appCode);
|
||
this.setAppName(appName);
|
||
this.setBusiNo(flowUnid);
|
||
String xml = getRequestXML();
|
||
SAXReader saxReader = new SAXReader();
|
||
Document document;
|
||
try {
|
||
document = saxReader.read(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)));
|
||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||
format.setEncoding("UTF-8");
|
||
XMLWriter writer = new XMLWriter(new FileWriter(new File(PropertiesUtil.get("fileSavePathTemp")+"/"+flowUnid+".xml")),format);
|
||
writer.write(document);
|
||
writer.close();
|
||
} catch (DocumentException e) {
|
||
e.printStackTrace();
|
||
} catch (IOException e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
}
|
||
|
||
}
|