package net.joystart.excelTask;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.WritableCellFeatures;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import net.joystart.common.util.ConfigUtil;
import net.joystart.common.util.SftpUtil;
import net.joystart.common.util.ZipUtil;
import net.joystart.customer.entity.Customer;
import net.joystart.customer.service.ICustomerService;
import net.joystart.excelTask.entity.CownExcel;
import net.joystart.order.entity.Order;
import net.joystart.order.service.IOrderService;
import net.joystart.vehicle.controller.VehicleController;
import net.joystart.vehicle.entity.Parkinglot;
import net.joystart.vehicle.entity.Vehicle;
import net.joystart.vehicle.service.IParkinglotService;
import net.joystart.vehicle.service.IVehicleService;
@Component("ExcelController")
public class ExcelController {
@Resource
private ICustomerService customerService;
@Resource
private IParkinglotService parkinglotService;
@Resource
IVehicleService vehicleService;
@Resource
IOrderService orderService;
/**
* 訂單自動服務
*/
public void customerExcel() {
Map<String, Object> params = new HashMap<String, Object>();
List<Customer> customerList = customerService.list(params);
exportExcel("會員信息.xls", customerList);
}
/** */
/**
* 導出數據為XLS格式
*
* @param fileName
* 文件的名稱,可以設為絕對路徑,也可以設為相對路徑
* @param content
* 數據的內容
*/
private void exportExcel(String fileName, List<Customer> customers) {
WritableWorkbook wwb;
FileOutputStream fos;
try {
String savePath = ConfigUtil.pro.get("excelPath").toString();
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String newDate = dateFormat.format(date);
File f = new File(savePath);
f = new File(f, newDate + ".xls");
// f.createNewFile();
fos = new FileOutputStream(f);
wwb = Workbook.createWorkbook(fos);
WritableSheet ws = wwb.createSheet("會員列表", 0); // 創建一個工作表
// 設置單元格的文字格式
WritableFont wf = new WritableFont(WritableFont.ARIAL, 12, WritableFont.NO_BOLD, false,
UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
WritableCellFormat wcf = new WritableCellFormat(wf);
wcf.setVerticalAlignment(VerticalAlignment.CENTRE);
wcf.setAlignment(Alignment.CENTRE);
ws.setRowView(1, 500);
jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#,##0.00"); // 設置數字格式
jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf); // 設置格式
// 設置標題行
int rowsCount = customers.size();
// 填充數據的內容
Customer customer;
for (int i = 0; i < rowsCount; i++) {
customer = customers.get(i);
WritableCellFeatures x;
ws.addCell(new Label(0, i + 0, customer.getName(), wcf));
ws.addCell(new Label(1, i + 0, customer.getMobile(), wcf));
double orderCost = customer.getRemainmoney() == null ? 0.00 : customer.getRemainmoney().doubleValue();
jxl.write.Number labelOrderCost = new jxl.write.Number(2, i + 1, orderCost, wcfN); // 格式化數值
ws.addCell(labelOrderCost);
}
wwb.write();
wwb.close();
Date dt = new Date();// 如果不需要格式,可直接用dt,dt就是當前系統時間
DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// 設置顯示格式
String nowTime = "";
nowTime = df.format(dt);// 用DateFormat的format()方法在dt中獲取並以yyyy/MM/dd
fileName = "用戶信息" + nowTime + ".xls";
// 保存EXCEL內容
CownExcel ce = new CownExcel();
ce.setDownloaddate(new Date());
ce.setUrl(f.getPath());
ce.setFileName(newDate + ".xls");
customerService.insertSelective(ce);
} catch (IOException e) {
} catch (RowsExceededException e) {
} catch (WriteException e) {
}
}
public SftpUtil getSFTPChannel() {
return new SftpUtil();
}
// 導出運管需要的數據
public void exportTransportationExcel() {
try {
String savePath = ConfigUtil.pro.get("excelPath").toString();
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String newDate = dateFormat.format(date);
String str = "北京巴歌汽車租賃有限公司,001615,北京,北京市";
byte[] data = str.getBytes("utf-8");
String url = new StringBuffer(savePath).append("/COL_DEP_").append(newDate).append("_").append(data.length)
.append(".csv").toString();
fileOutupload(data, url);
/// 添加壓縮功能/////////////////////////////////////////////////////////////////////
String zipName = new StringBuffer().append("/COL_DEP_").append(newDate).append(".zip").toString();
String zipUrl = new StringBuffer(savePath).append(zipName).toString();
ZipUtil zip = new ZipUtil();
zip.zip(zipUrl, url);
File csvFile = new File(url);
File zipFile = new File(zipUrl);
if (csvFile.exists())
csvFile.delete();// 刪除舊壓縮包
byte[] file = fileInupload(zipUrl);
String zipNameNew = new StringBuffer(savePath).append("/COL_DEP_").append(newDate).append("_")
.append(file.length).append(".zip").toString();
fileOutupload(file, zipNameNew);
zipFile.delete();
File zipFileNew = new File(zipNameNew);//獲取新壓縮包地址獲取壓縮包名稱為了上傳使用
// 調用sftp開始上傳文件//////////////////////////////////////////////////////////////
VehicleController vehicleController = new VehicleController();
SftpUtil channel = vehicleController.getSFTPChannel();
ChannelSftp chSftp = channel.getChannel(60000);
String strSaveUrl = new StringBuffer("/COLLECTION/").append(zipNameNew.getName()).toString();
chSftp.put(zipNameNew, strSaveUrl, ChannelSftp.OVERWRITE);
chSftp.quit();
channel.closeChannel();
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
ExcelMethod1();
ExcelMethod2();
ExcelMethod3();
ExcelMethod4();
ExcelMethod5();
}
private void ExcelMethod1(){
FileOutputStream out=null;
OutputStreamWriter osw=null;
BufferedWriter bw=null;
String urlNew="";
String savePath = ConfigUtil.pro.get("excelPath").toString();
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String newDate = dateFormat.format(date);
String url = new StringBuffer(savePath).append("/COL_DEP_").append(newDate).append(".csv").toString();
File csvFile = new File(url);
try {
out = new FileOutputStream(csvFile);
osw = new OutputStreamWriter(out,"UTF-8");
//識別UTF-8 加上就能識別出來,不加還是亂碼 add cjl
osw.write(new String(new byte[] { (byte) 0xEF, (byte) 0xBB,(byte) 0xBF }));
osw.write(new String(new byte[] { (byte) 0xEF, (byte) 0xBB,(byte) 0xBF }));
bw =new BufferedWriter(osw);
List<Parkinglot> parklotList = parkinglotService.findAllParkingLotAndBranch();
if(parklotList!=null && !parklotList.isEmpty()){
for(Parkinglot parking : parklotList){
String strData = new StringBuffer().append(parking.getName()).append(",").append("北京巴歌汽車租賃有限公司").append(",").
append(parking.getLongitude()).append(",").append(parking.getLatitude()).append(",").append("null").append(",").append(parking.getPosition())
.append(",").append("null").append(",").append("null").toString();
bw.append(strData).append("\r");
}
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(bw!=null){
try {
bw.close();
bw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(osw!=null){
try {
osw.close();
osw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(out!=null){
try {
out.close();
out=null;
} catch (IOException e) {
e.printStackTrace();
}
}
long fileSize = csvFile.length();
urlNew = new StringBuffer(savePath).append("/COL_DEP_").append(newDate).append("_").append(fileSize).append(".csv").toString();
fileupload(url,urlNew);
csvFile.delete();
}
zipUpload(newDate,savePath,urlNew,"/COL_DEP_");
}
private void ExcelMethod2() {
FileOutputStream out=null;
OutputStreamWriter osw=null;
BufferedWriter bw=null;
String urlNew="";
String savePath = ConfigUtil.pro.get("excelPath").toString();
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String newDate = dateFormat.format(date);
String url = new StringBuffer(savePath).append("/COL_CAR_").append(newDate).append(".csv").toString();
File csvFile = new File(url);
try {
out = new FileOutputStream(csvFile);
osw = new OutputStreamWriter(out,"UTF-8");
osw.write(new String(new byte[] { (byte) 0xEF, (byte) 0xBB,(byte) 0xBF }));
bw =new BufferedWriter(osw);
/// 租賃門店信息////////////////////////////////////////////////////////////////
List<Vehicle> vehicleList = vehicleService.selectAllVehicle();
if(vehicleList!=null && !vehicleList.isEmpty()){
for(Vehicle vehicle : vehicleList){
String strData = new StringBuffer().append(vehicle.getPlatenumber()).append(",").append(vehicle.getEngineno()).append(",").
append(vehicle.getVin()).append(",").append(vehicle.getUploadImgUrl()).append(",").append(vehicle.getUploadImgUrlTwo()).append(",").append(vehicle.getCarcolor())
.append(",").append(vehicle.getDrivinglicenseurl()).append(",").append("null").append(",")
.append("null").append(",").append("5").append(",").append("null").append(",").append(vehicle.getCreatedate() == null ? "" : sdf.format(vehicle.getCreatedate())).append(",")
.append("null").append(",").append("null").toString();
bw.append(strData).append("\r");
}
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(bw!=null){
try {
bw.close();
bw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(osw!=null){
try {
osw.close();
osw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(out!=null){
try {
out.close();
out=null;
} catch (IOException e) {
e.printStackTrace();
}
}
long fileSize = csvFile.length();
urlNew = new StringBuffer(savePath).append("/COL_CAR_").append(newDate).append("_").append(fileSize).append(".csv").toString();
fileupload(url,urlNew);
csvFile.delete();
}
zipUpload(newDate,savePath,urlNew,"/COL_CAR_");
}
private void ExcelMethod3() {
FileOutputStream out=null;
OutputStreamWriter osw=null;
BufferedWriter bw=null;
String urlNew="";
String savePath = ConfigUtil.pro.get("excelPath").toString();
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String newDate = dateFormat.format(date);
String url = new StringBuffer(savePath).append("/COL_ASS_").append(newDate).append(".csv").toString();
File csvFile = new File(url);
try {
out = new FileOutputStream(csvFile);
osw = new OutputStreamWriter(out,"UTF-8");
osw.write(new String(new byte[] { (byte) 0xEF, (byte) 0xBB,(byte) 0xBF }));
bw =new BufferedWriter(osw);
List<Vehicle> vehicleList = vehicleService.selectAllVehicleSite();
if(vehicleList!=null && !vehicleList.isEmpty()){
for(Vehicle vehicle : vehicleList){
String strData = new StringBuffer().append(vehicle.getPlatenumber()).append(",").append("null").append(
StringUtils.isBlank(vehicle.getUploadImgUrlTwo())? vehicle.getUploadImgUrl() : vehicle.getUploadImgUrlTwo())
.append(",").append(vehicle.getDrivinglicenseurl()).toString();
bw.append(strData).append("\r");
}
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(bw!=null){
try {
bw.close();
bw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(osw!=null){
try {
osw.close();
osw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(out!=null){
try {
out.close();
out=null;
} catch (IOException e) {
e.printStackTrace();
}
}
long fileSize = csvFile.length();
urlNew = new StringBuffer(savePath).append("/COL_CAR_").append(newDate).append("_").append(fileSize).append(".csv").toString();
fileupload(url,urlNew);
csvFile.delete();
}
zipUpload(newDate,savePath,urlNew,"/COL_CAR_");
}
private void ExcelMethod4() {
FileOutputStream out=null;
OutputStreamWriter osw=null;
BufferedWriter bw=null;
String urlNew="";
String savePath = ConfigUtil.pro.get("excelPath").toString();
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String newDate = dateFormat.format(date);
String url = new StringBuffer(savePath).append("/COL_CON_").append(newDate).append(".csv").toString();
File csvFile = new File(url);
try {
out = new FileOutputStream(csvFile);
osw = new OutputStreamWriter(out,"UTF-8");
osw.write(new String(new byte[] { (byte) 0xEF, (byte) 0xBB,(byte) 0xBF }));
bw =new BufferedWriter(osw);
Map<String, Object> params = new HashMap<String, Object>();
Calendar calendar_as = Calendar.getInstance();
calendar_as.setTime(new Date());
Calendar calendar_ST = Calendar.getInstance();
calendar_ST.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
calendar_as.get(Calendar.DATE) - 1, 0, 0, 0);
calendar_ST.set(Calendar.MILLISECOND, 0);
Calendar calendar_ET = Calendar.getInstance();
calendar_ET.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
calendar_as.get(Calendar.DATE), 0, 0, 0);
calendar_ET.set(Calendar.MILLISECOND, 0);
SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
params.put("_startDate", dft.format(calendar_ST.getTime()));
params.put("_endDate", dft.format(calendar_ET.getTime()));
List<Order> orderList = orderService.selectAllOrders(params);
if(orderList!=null && !orderList.isEmpty()){
for(Order order : orderList){
String strData = new StringBuffer().append(order.getOrderno()).append(",").append(order.getPlatenumber()).append(",")
.append("null,null,null,null,null,").append(order.getCreatedate() == null ? " " : sdf.format(order.getCreatedate()))
.append(",").append(order.getReturnvehicledate() == null ? " " : sdf.format(order.getReturnvehicledate()))
.append(",").append(StringUtils.isBlank(order.getRentBranchName()) ? order.getRentParkName()
: order.getRentBranchName()).append(",").append("null").append(order.getCreatedate() == null ? "" : sdf.format(order.getCreatedate()))
.append(",").append(order.getCustomerName()).append(",").append(order.getInvitationCode())
.append(",null,null,null").toString();
bw.append(strData).append("\r");
}
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(bw!=null){
try {
bw.close();
bw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(osw!=null){
try {
osw.close();
osw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(out!=null){
try {
out.close();
out=null;
} catch (IOException e) {
e.printStackTrace();
}
}
long fileSize = csvFile.length();
urlNew = new StringBuffer(savePath).append("/COL_CON_").append(newDate).append("_").append(fileSize).append(".csv").toString();
fileupload(url,urlNew);
csvFile.delete();
}
zipUpload(newDate,savePath,urlNew,"/COL_CON_");
}
private void ExcelMethod5() {
FileOutputStream out=null;
OutputStreamWriter osw=null;
BufferedWriter bw=null;
String urlNew="";
String savePath = ConfigUtil.pro.get("excelPath").toString();
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String newDate = dateFormat.format(date);
String url = new StringBuffer(savePath).append("/COL_WAY_").append(newDate).append(".csv").toString();
File csvFile = new File(url);
try {
out = new FileOutputStream(csvFile);
osw = new OutputStreamWriter(out,"UTF-8");
//識別UTF-8 加上就能識別出來,不加還是亂碼 add cjl
osw.write(new String(new byte[] { (byte) 0xEF, (byte) 0xBB,(byte) 0xBF }));
bw =new BufferedWriter(osw);
Map<String, Object> params = new HashMap<String, Object>();
Calendar calendar_as = Calendar.getInstance();
calendar_as.setTime(new Date());
Calendar calendar_ST = Calendar.getInstance();
calendar_ST.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
calendar_as.get(Calendar.DATE) - 1, 0, 0, 0);
calendar_ST.set(Calendar.MILLISECOND, 0);
Calendar calendar_ET = Calendar.getInstance();
calendar_ET.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
calendar_as.get(Calendar.DATE), 0, 0, 0);
calendar_ET.set(Calendar.MILLISECOND, 0);
SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
params.put("_startDate", dft.format(calendar_ST.getTime()));
params.put("_endDate", dft.format(calendar_ET.getTime()));
List<Order> orderList = orderService.selectAllOrders(params);
if(orderList!=null && !orderList.isEmpty()){
for(Order order : orderList){
String strData = new StringBuffer().append(order.getOrderno()).append(",").append(order.getOrderno()).append(",")
.append("null,null,null,null,null,").append(order.getCreatedate() == null ? " " : sdf.format(order.getCreatedate()))
.append(order.getPlatenumber()).append(",null,null,null,null,null,").append(order.getChargingstartdate() == null ? "" : sdf.format(order.getChargingstartdate()))
.append(",").append(order.getReturnvehicledate() == null ? " " : sdf.format(order.getReturnvehicledate()))
.append(",").append("null").append(",").append("null").append(",").append(order.getMileage()== null ? "0" : order.getMileage().toString())
.append(",").append(order.getActualpaymentcost() == null ? "0" : order.getActualpaymentcost().toString()).toString();
bw.append(strData).append("\r");
}
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(bw!=null){
try {
bw.close();
bw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(osw!=null){
try {
osw.close();
osw=null;
} catch (IOException e) {
e.printStackTrace();
}
}
if(out!=null){
try {
out.close();
out=null;
} catch (IOException e) {
e.printStackTrace();
}
}
long fileSize = csvFile.length();
urlNew = new StringBuffer(savePath).append("/COL_WAY_").append(newDate).append("_").append(fileSize).append(".csv").toString();
fileupload(url,urlNew);
csvFile.delete();
}
zipUpload(newDate,savePath,urlNew,"/COL_WAY_");
}
/**
* 獲取文件大小 重新寫入磁盤
*
* @author:cuijinlong
* @date:2017年5月18日 下午1:58:37
* @param url1
* @param url2
*/
private void fileOutupload(byte[] b, String url2) {
FileOutputStream out = null;
try {
File f2 = new File(url2);//新文件路徑 add 崔金龍
out = new FileOutputStream(f2);//輸出文件
out.write(b);//寫入文件內容 舊文件內容 寫入新的里面去 add 崔金龍
out.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 根據路徑讀取舊文件路徑下內容,寫入新文件路徑下
* @author:cuijinlong
* @date:2017年5月19日 上午11:26:31
* @param url1
* @param url2
*/
private void fileupload(String url1, String url2) {
File f = new File(url1);
InputStream in = null;
FileOutputStream out = null;
try {
in = new FileInputStream(f);//輸入流讀出就文件內容 add 崔金龍
int tempbyte;
System.out.println(in.available());
byte[] b = new byte[in.available()]; //讀出內容 獲取大小 add 崔金龍
while ((tempbyte = in.read(b, 0, b.length)) != -1) {
System.out.write(tempbyte);
}
File f2 = new File(url2);//新文件
out = new FileOutputStream(f2);//輸出新文件
out.write(b);//把舊路徑內容寫入新地址文件去 add 崔金龍
out.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 根據URL路徑獲取當面文件大小
* @author:cuijinlong
* @date:2017年5月19日 上午11:18:59
* @param url1
* @return
*/
private byte[] fileInupload(String url1) {
File f = new File(url1);//根據URL路徑獲取文件信息
InputStream in = null;
try {
in = new FileInputStream(f);
int tempbyte;
System.out.println(in.available());
byte[] b = new byte[in.available()];//讀出文件里面內容並獲取文件大小 注釋:b:為內容 b.length() 獲取文件大小 add 崔金龍
while ((tempbyte = in.read(b, 0, b.length)) != -1) {
System.out.write(tempbyte);
}
return b;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
/**
* 上傳壓縮包文件變並且替換
* @author:cuijinlong
* @date:2017年5月19日 上午10:35:34
* @param newDate
* @param savePath//上傳文件路徑
* @param urlNew//新的上傳文件地址加上CSV文件名稱
* @param flag
*/
private void zipUpload(String newDate,String savePath,String urlNew,String flag){
try {
//拼接壓縮包名稱 add cjl
String zipName = new StringBuffer().append(flag).append(newDate).append(".zip").toString();
String zipUrl = new StringBuffer(savePath).append(zipName).toString();
ZipUtil zip = new ZipUtil();
zip.zip(zipUrl, urlNew);
File zipFile = new File(zipUrl);//生成壓縮包路徑帶上壓縮包名稱 add 崔金龍
File csvFileNew = new File(urlNew);//為了刪除CSV文件時候建立的FILE為了刪除使用,如果不刪除不需要使用
if(csvFileNew.exists())
csvFileNew.delete();
byte[] file = fileInupload(zipUrl);//獲取該路徑下文件大小,注意此處一定帶着要獲取文件的文件名稱 add 崔金龍
String zipNameNew = new StringBuffer(savePath).append(flag).append(newDate).append("_")
.append(file.length).append(".zip").toString();//file.length 可以獲取文件大小,生成一個新的路徑帶着文件大小的 add 崔金龍
fileOutupload(file, zipNameNew);//把舊壓縮包內容 寫入新的壓縮包里面去 add 崔金龍
zipFile.delete();
File zipFileNew = new File(zipNameNew);//獲取新壓縮包地址獲取壓縮包名稱為了上傳使用
// 調用sftp開始上傳文件//////////////////////////////////////////////////////////////
VehicleController vehicleController = new VehicleController();
SftpUtil channel = vehicleController.getSFTPChannel();
ChannelSftp chSftp = channel.getChannel(60000);
String strSaveUrl = new StringBuffer("/COLLECTION/").append(zipNameNew.getName()).toString();
chSftp.put(zipNameNew, strSaveUrl, ChannelSftp.OVERWRITE);
chSftp.quit();
channel.closeChannel();
} catch (Exception e) {
e.printStackTrace();
}
}
}