156 lines
5.3 KiB
Java
156 lines
5.3 KiB
Java
package com.tenwa.reckon.copydata;
|
||
|
||
import java.io.File;
|
||
import java.io.IOException;
|
||
import java.util.Arrays;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
|
||
import jbo.app.tenwa.doc.LC_COPYFILE_LOG;
|
||
|
||
import org.apache.commons.io.FileUtils;
|
||
|
||
import com.amarsoft.are.jbo.BizObject;
|
||
import com.amarsoft.are.jbo.BizObjectManager;
|
||
import com.amarsoft.are.jbo.JBOException;
|
||
import com.amarsoft.are.jbo.JBOFactory;
|
||
import com.amarsoft.are.util.StringFunction;
|
||
import com.amarsoft.awe.util.Transaction;
|
||
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
|
||
public class FileCopyToOtherPath {
|
||
|
||
private String contractNos;
|
||
private String batchNos;
|
||
private String userid;
|
||
private String fileSavePath_temp;
|
||
|
||
public String doCopy(String contractNo,String bacthNo,String type,String archive){
|
||
Transaction Sqlca = Transaction.createTransaction("als");
|
||
//原路径
|
||
String srcPath ;
|
||
//目标相对路径
|
||
String destPath = null ;
|
||
//目标根目录
|
||
String rootPath;
|
||
try {
|
||
rootPath = fileSavePath_temp;
|
||
String sql = "SELECT O.FULLPATH AS FULLPATH, CONCAT(REPLACE(LCI.CONTRACT_NO,'/','-'), '/','"+type+"','/', REPLACE(LDL.ONE_CLASSIFY,'/','-'), '/' , REPLACE(LDL.DOC_NAME,'/','-'), '/', REPLACE(O.FILENAME,'/','-')) AS TARGET_FILE_PATH FROM LB_DOCATTRIBUTE O"
|
||
+" LEFT JOIN LB_DOCLIBRARY LDL ON LDL.ID = O.LIBRARY_ID"
|
||
+" LEFT JOIN LB_DOCRELATIVE LDR ON LDL.RELATIVE_ID = LDR.ID"
|
||
+" LEFT JOIN LB_CONTRACT_INFO LCI ON LDR.CONTRACT_ID = LCI.ID"
|
||
+" WHERE (O.DELETEED <>'Y' OR O.DELETEED IS NULL) AND LCI.CONTRACT_NO ='"+contractNo+"' AND (LDL.DOC_TYPE LIKE '"+type+"%'"
|
||
+" or LDL.DOC_TYPE in "+archive+")";
|
||
if("其它".equals(type)){
|
||
sql = "SELECT O.FULLPATH AS FULLPATH, CONCAT(REPLACE(LCI.CONTRACT_NO,'/','-'), '/','"+type+"','/', REPLACE(LDL.ONE_CLASSIFY,'/','-'), '/' , REPLACE(LDL.DOC_NAME,'/','-'), '/', REPLACE(O.FILENAME,'/','-')) AS TARGET_FILE_PATH FROM LB_DOCATTRIBUTE O"
|
||
+" LEFT JOIN LB_DOCLIBRARY LDL ON LDL.ID = O.LIBRARY_ID"
|
||
+" LEFT JOIN LB_DOCRELATIVE LDR ON LDL.RELATIVE_ID = LDR.ID"
|
||
+" LEFT JOIN LB_PROJECT_INFO LPI ON LDR.PROJ_ID = LPI.ID"
|
||
+" LEFT JOIN LB_CONTRACT_INFO LCI ON LPI.ID = LCI.PROJECT_ID"
|
||
+" WHERE (O.DELETEED <>'Y' OR O.DELETEED IS NULL) AND LCI.CONTRACT_NO ='"+contractNo+"' AND one_classify='其他文件'"
|
||
+" and LDL.DOC_NAME ='其他'";
|
||
}
|
||
Map<String,String> params=new HashMap<String,String>();
|
||
List<Map<String, String>> pathList = DataOperatorUtil.getDataBySql(Sqlca,sql,params);
|
||
if(pathList.size()>0){
|
||
for(Map<String, String> path:pathList){
|
||
srcPath = path.get("FULLPATH");
|
||
destPath =rootPath+"/"+path.get("TARGET_FILE_PATH");
|
||
File srcFile = new File(srcPath);
|
||
File destFile = new File(destPath);
|
||
System.out.println("原路径:"+srcPath);
|
||
System.out.println("目标路径:"+destPath);
|
||
try {
|
||
//文件拷贝,参数true为最后修改时间不变,fail为当前时间.
|
||
//拷贝时如果目标文件已存在,则会从新覆盖。
|
||
FileUtils.copyFile(srcFile, destFile, true);
|
||
} catch (IOException e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
BizObjectManager bom = JBOFactory.getBizObjectManager(LC_COPYFILE_LOG.CLASS_NAME);
|
||
BizObject nbom = bom.newObject();
|
||
nbom.setAttributeValue("CONTRACT_NO", contractNo);
|
||
nbom.setAttributeValue("BATCH_NO", bacthNo);
|
||
nbom.setAttributeValue("COPY_TYPE",type);
|
||
nbom.setAttributeValue("INPUTTIME",StringFunction.getTodayNow());
|
||
nbom.setAttributeValue("INPUTUSERID",userid);
|
||
bom.saveObject(nbom);
|
||
}else{
|
||
System.out.println("================"+contractNo+"没有关联到文件"+"===============");
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return contractNo;
|
||
}finally{
|
||
try {
|
||
if(Sqlca !=null){
|
||
Sqlca.commit();
|
||
}
|
||
} catch (JBOException e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
return "Y";
|
||
}
|
||
|
||
public String copyFile(String type){
|
||
String failNo="";
|
||
String archive="";
|
||
if("PayFileList".equals(type)){
|
||
type="放款资料";
|
||
archive = "('007','008','016','031','033')";
|
||
}
|
||
if("FileList".equals(type)){
|
||
type="归档资料";
|
||
archive = "('002','009','010','011','018','034')";
|
||
}
|
||
if("Other".equals(type)){
|
||
type="其它";
|
||
archive = "";
|
||
}
|
||
List<String> cns = Arrays.asList(contractNos.split("@"));
|
||
List<String> bns = Arrays.asList(batchNos.split("@"));
|
||
for(int i=0;i<cns.size();i++){
|
||
if("".equals(cns.get(i))||cns.get(i)==null){
|
||
continue;
|
||
}
|
||
String result = doCopy(cns.get(i),bns.get(i),type,archive);
|
||
if(!"Y".equals(result)){
|
||
failNo+=cns.get(i)+";";
|
||
}
|
||
}
|
||
if("".equals(failNo)){
|
||
return "SUCCESS";
|
||
}
|
||
System.out.println("拷贝失败的合同:"+failNo);
|
||
return failNo;
|
||
}
|
||
public String getUserid() {
|
||
return userid;
|
||
}
|
||
public void setUserid(String userid) {
|
||
this.userid = userid;
|
||
}
|
||
public String getContractNo() {
|
||
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 getFileSavePath_temp() {
|
||
return fileSavePath_temp;
|
||
}
|
||
public void setFileSavePath_temp(String fileSavePath_temp) {
|
||
this.fileSavePath_temp = fileSavePath_temp;
|
||
}
|
||
|
||
}
|