From 6e2cd66eb65114256d0afaca921b445876d0fb65 Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Mon, 7 Nov 2016 17:29:28 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CheckoutServiceImpl.java | 2 - .../service/thread/ThreadMoveData.java | 85 +++++++++++-------- 2 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/com/platform/service/impl/CheckoutServiceImpl.java b/src/com/platform/service/impl/CheckoutServiceImpl.java index fb4aa878..7d1a0f53 100644 --- a/src/com/platform/service/impl/CheckoutServiceImpl.java +++ b/src/com/platform/service/impl/CheckoutServiceImpl.java @@ -1,9 +1,7 @@ package com.platform.service.impl; import java.util.ArrayList; -import java.util.Arrays; import java.util.Calendar; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; diff --git a/src/com/platform/service/thread/ThreadMoveData.java b/src/com/platform/service/thread/ThreadMoveData.java index d983790d..625aa956 100644 --- a/src/com/platform/service/thread/ThreadMoveData.java +++ b/src/com/platform/service/thread/ThreadMoveData.java @@ -89,8 +89,7 @@ public class ThreadMoveData{ long nowTime = new Date().getTime(); long timelong = nowTime - DateForm.string2DateBysecond(dataMove.getLastTime()).getTime(); if (timelong > 1000*60*20) { - dataMove.setCompleteStatus("3"); - dataInfoMoveTmpDao.update(dataMove); + doMd5(srcSizeTemp, dstSize, dataMove); } //正在上传的个数。 moveFileCurrNum++; @@ -129,36 +128,8 @@ public class ThreadMoveData{ if("1".equals(dataMove.getCompleteStatus()) && dataMove.getRate() > 0){ //传输完毕:进行校验 if (realRate >= 100) { - int difSize = (int) (srcSizeTemp-dstSize); - Thread.sleep(10*difSize); - //TODO 查看当前拷贝目录进程是否结束? - // 进行MD5校验 - int resl = check.checkoutMD5Folder(dataMove.getDataPath(), dataMove.getDstPath()); - // 校验成功--则增加数据库记录 - if(resl == 1){ - // 判断 迁移数据的status是否改为 2 - DataInfoEntityMoveTmp movetmp = dataInfoMoveTmpDao.findById(dataMove.getId()); - if (null != movetmp && !"2".equals(movetmp.getCompleteStatus())) { - //校验成功--修改 数据库记录-- - dataMove.setCompleteStatus("2"); - dataMove.setLastTime(DateForm.date2StringBysecond(new Date())); - dataInfoMoveTmpDao.update(dataMove); - //TODO 新增 一条数据-到-dataInfo - DataInfoEntity data = (DataInfoEntity) Bean2MapUtils.convertMap( - DataInfoEntity.class, Bean2MapUtils.convertBean(dataMove)); - data.setDataPath(dataMove.getDstPath()); - data.setVolumeIp(dataMove.getDstVolumeIp()); - data.setVolumePath(dataMove.getDstVolumePath()); - data.setVolumeIp(dataMove.getVolumeIp()); - data.setId(0); - dataInfoDao.save(data); - } - } - else { - // 3:表示 迁移失败 - dataMove.setLastTime(DateForm.date2StringBysecond(new Date())); - dataMove.setCompleteStatus("3"); - } + //TODO + doMd5(srcSizeTemp, dstSize, dataMove); } dataMove.setLastTime(DateForm.date2StringBysecond(new Date())); dataInfoMoveTmpDao.update(dataMove); @@ -178,15 +149,16 @@ public class ThreadMoveData{ if ("0".equals(next2move.getCompleteStatus())) { //待迁移的数据 -- 开始迁移 // 末尾 含有 / - Pattern pattern2 = Pattern.compile("\\/$"); - String dstPath = next2move.getDataPath(); + Pattern pattern2 = Pattern.compile("\\d+\\/$"); + String dstPath = next2move.getDstPath(); Matcher matcher2 = pattern2.matcher(dstPath); - //去掉 最后 的 / 符合 + //去掉 最后 的 数字 +/ 符合 if (matcher2.find()) { - dstPath = dstPath.substring(0, dstPath.length()-1); + String removeStr = matcher2.group(); + dstPath = dstPath.replace(removeStr, ""); } //数据迁移。 - copy.copyFolder(dstPath+"/app", next2move.getDstPath()); + copy.copyFolder(next2move.getDataPath(), dstPath); // "1" :正在上传,0:等待 迁移, 2:成功 3:失败 next2move.setCompleteStatus("1"); next2move.setLastTime(DateForm.date2StringBysecond(new Date())); @@ -205,5 +177,44 @@ public class ThreadMoveData{ } } + + private void doMd5(long srcSizeTemp, long dstSize, DataInfoEntityMoveTmp dataMove) throws Exception { + + int difSize = (int) (srcSizeTemp-dstSize); + if (difSize < 1) { + difSize = 1; + } + Thread.sleep(10*difSize); + //TODO 查看当前拷贝目录进程是否结束? + // 进行MD5校验 + int resl = check.checkoutMD5Folder(dataMove.getDataPath(), dataMove.getDstPath()); + // 校验成功--则增加数据库记录 + if(resl == 1){ + // 判断 迁移数据的status是否改为 2 + DataInfoEntityMoveTmp movetmp = dataInfoMoveTmpDao.findById(dataMove.getId()); + if (null != movetmp && !"2".equals(movetmp.getCompleteStatus())) { + //校验成功--修改 数据库记录-- + dataMove.setCompleteStatus("2"); + dataMove.setLastTime(DateForm.date2StringBysecond(new Date())); + dataInfoMoveTmpDao.update(dataMove); + //TODO 新增 一条数据-到-dataInfo + DataInfoEntity data = (DataInfoEntity) Bean2MapUtils.convertMap( + DataInfoEntity.class, Bean2MapUtils.convertBean(dataMove)); + data.setDataPath(dataMove.getDstPath()); + data.setVolumeIp(dataMove.getDstVolumeIp()); + data.setVolumePath(dataMove.getDstVolumePath()); + data.setVolumeIp(dataMove.getVolumeIp()); + data.setId(0); + dataInfoDao.save(data); + } + } + else { + // 3:表示 迁移失败 + dataMove.setLastTime(DateForm.date2StringBysecond(new Date())); + dataMove.setCompleteStatus("3"); + } + + + } }