apzl_leasing/calc/com/tenwa/reckon/copydata/CopyFileToOther.java

138 lines
4.1 KiB
Java

package com.tenwa.reckon.copydata;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import jbo.app.tenwa.doc.LC_COPYFILE_LOG;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.are.util.StringFunction;
import com.tenwa.comm.message.controller.BaseBussinessMessage;
import com.tenwa.officetempalte.action.CreateOfficeAction;
import com.tenwa.officetempalte.exportcallback.impl.ZipUtils;
public class CopyFileToOther {
private String contractNos;
private String batchNos;
private String userid;
private String fileList;
private String templateNo="8c0b32eefcf349e5b5f76d898df0bbbb";
private String fileSavePath;
public String runCopy(JBOTransaction tx) throws Exception{
//创建临时路径
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String time = sdf.format(new Date());
String uuid=UUID.randomUUID().toString().replaceAll("-", "");
String fileSavePath_temp = fileSavePath+"/"+time+uuid;
FileCopyToOtherPath cp = new FileCopyToOtherPath();
cp.setContractNos(contractNos);
cp.setBatchNos(batchNos);
cp.setUserid(userid);
cp.setFileSavePath_temp(fileSavePath_temp);
CreateOfficeAction coa = new CreateOfficeAction();
//JBOTransaction tx = JBOFactory.createJBOTransaction();
if(fileList.contains("PayFileList")){
cp.copyFile("PayFileList");
}
if(fileList.contains("FileList")){
cp.copyFile("FileList");
}
if(fileList.contains("Other")){
cp.copyFile("Other");
}
if(fileList.contains("RentPlan")){
String[] contractNoArray = contractNos.split("@");
String[] batchNoArray = batchNos.split("@");
for(int i=0;i<contractNoArray.length;i++){
String fileSavePath_xml = fileSavePath_temp+"/"+contractNoArray[i]+"/";
String templateParam = "{\"OBJECTTYPE\":\"租金支付表导出\"@\"CurUserId\":\""+userid+"\"@\"fileSavePath\":\""+fileSavePath_xml+"\"@\"CONTRACT_NO\":\""+contractNoArray[i]+"\"}";
File temDir = new File(fileSavePath_xml);
if(!temDir.exists()){
temDir.mkdirs();
}
coa.setTemplateNo(templateNo);
coa.setTemplateParam(templateParam);
String result = coa.createOfficeByTemplate(tx);
if("success".equals(result)){
BizObjectManager bom = JBOFactory.getBizObjectManager(LC_COPYFILE_LOG.CLASS_NAME);
BizObject nbom = bom.newObject();
nbom.setAttributeValue("CONTRACT_NO", contractNoArray[i]);
nbom.setAttributeValue("BATCH_NO", batchNoArray[i]);
nbom.setAttributeValue("COPY_TYPE","租金计划");
nbom.setAttributeValue("INPUTTIME",StringFunction.getTodayNow());
nbom.setAttributeValue("INPUTUSERID",userid);
bom.saveObject(nbom);
}
}
}
tx.commit();
//压缩
FileOutputStream fos1 = new FileOutputStream(new File(fileSavePath+"/"+time+".zip"));
ZipUtils zdo = new ZipUtils();
zdo.toZip(fileSavePath_temp, fos1, true);
//删除原文件
File f = new File(fileSavePath_temp);
if(f.length()!=0){
//压缩完毕后删除文件发送通知消息
zdo.deleteFile(f);
BaseBussinessMessage bbm = new BaseBussinessMessage();
bbm.setMessageId("3389471a244d41e584232854c8526f6b");
bbm.saveBaseMessageSimple(tx);
}
return null;
}
public String getContractNos() {
return contractNos;
}
public void setContractNos(String contractNos) {
this.contractNos = contractNos;
}
public String getBatchNos() {
return batchNos;
}
public void setBatchNos(String batchNos) {
this.batchNos = batchNos;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getFileList() {
return fileList;
}
public void setFileList(String fileList) {
this.fileList = fileList;
}
public String getFileSavePath() {
return fileSavePath;
}
public void setFileSavePath(String fileSavePath) {
this.fileSavePath = fileSavePath;
}
}