apzl_leasing/calc/com/tenwa/reckon/copydata/CopyFileToOther.java
2020-11-12 18:59:15 +08:00

184 lines
5.9 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 != null && fileList.length()>0){
String[] docNameList = fileList.split("~");
StringBuffer docSb = new StringBuffer();
for (String docName : docNameList) {
String[] docNames = docName.split("@");
if("RentPlan".equals(docNames[0])){
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]+"\"}";
System.out.println("·¾¶Îª£º"+fileSavePath_xml);
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);
}
}
}else{
if(docNames[0].length()>3){
docSb.append("'");
docSb.append(docNames[1]);
docSb.append("',");
}
}
}
if(docSb!=null&&docSb.length()>0){
cp.copyFile(docSb.substring(0,docSb.length()-1).toString());
}else{
return "Êý¾ÝÓÐÎó£¡";
}
}
/*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;
}
}