From e48af410dd2a807b65f02949a5dc8f7202501a92 Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Thu, 27 Oct 2016 14:33:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E4=BF=A1=E6=81=AF=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=9A=84=20=E8=84=9A=E6=9C=AC=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E7=BB=99=E5=87=BA=20=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E3=80=81=E7=BC=BA=E5=A4=B1=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/controller/ExcelController.java | 24 +- .../controller/FilePackageController.java | 118 +++++--- src/com/platform/entities/MyFileEntity.java | 53 ---- src/com/platform/entities/MyFilesEntity.java | 279 ++++++++++++++++++ .../platform/service/IScriptMakeService.java | 6 +- .../service/impl/ScriptMakeService.java | 159 +++++++++- src/com/platform/utils/BeanCopy.java | 39 ++- .../platform/utils/Compare4MyFilesEntity.java | 17 ++ src/com/platform/utils/Configs.java | 128 ++++---- src/com/platform/utils/ConfigsLoader.java | 190 ++++++------ src/com/platform/utils/ProcessMyUtil.java | 41 +++ src/com/platform/utils/ThreadRemoveFile.java | 44 +++ src/com/platform/utils/ZipCompressUtils.java | 147 ++++----- 13 files changed, 882 insertions(+), 363 deletions(-) delete mode 100644 src/com/platform/entities/MyFileEntity.java create mode 100644 src/com/platform/entities/MyFilesEntity.java create mode 100644 src/com/platform/utils/Compare4MyFilesEntity.java create mode 100644 src/com/platform/utils/ProcessMyUtil.java create mode 100644 src/com/platform/utils/ThreadRemoveFile.java diff --git a/src/com/platform/controller/ExcelController.java b/src/com/platform/controller/ExcelController.java index 4bb7538e..1960ef7b 100644 --- a/src/com/platform/controller/ExcelController.java +++ b/src/com/platform/controller/ExcelController.java @@ -50,6 +50,7 @@ import com.platform.service.IPreDataInfoService; import com.platform.service.IScriptMakeService; import com.platform.utils.Configs; import com.platform.utils.HttpUtils; +import com.platform.utils.ThreadRemoveFile; import com.platform.utils.UtilsHelper; @Controller @@ -60,9 +61,7 @@ public class ExcelController extends BaseController{ @Resource(name = "preDataInfoService") private IPreDataInfoService preDataInfoService; - - @Resource(name = "scriptMakeService") - private IScriptMakeService scriptMakeService; + // 文件上传处理函数 @RequestMapping(value = "/file/upload", method = RequestMethod.POST) @@ -251,6 +250,7 @@ public class ExcelController extends BaseController{ } Map result = new HashMap(); if (listPath.size() > 0) { + //导入 result = preDataInfoService.importExcel(listPath); if (result.containsKey("fileUnExist") || result.containsKey("areaUnImport")) { modelMap.addAttribute("data", result); @@ -263,13 +263,20 @@ public class ExcelController extends BaseController{ modelMap.addAttribute("returncode","1001"); } //删除文件 + List failedDelete = new ArrayList(); for (String filePath : listPath) { //读取完后删除源文件(不管是否成功导入) File tmpf = new File(filePath + ".temp"); File f = new File(filePath); - tmpf.delete(); - f.delete(); + if(!tmpf.delete()){ + failedDelete.add(tmpf.getAbsolutePath()); + } + if(!f.delete()){ + failedDelete.add(f.getAbsolutePath()); + } } + //删除失败时--启用线程去删除 + new ThreadRemoveFile(failedDelete).start(); } return modelMap; } @@ -312,11 +319,4 @@ public class ExcelController extends BaseController{ } } } - - @RequestMapping(value = "/exportFile") - public void exportFile(HttpServletRequest request, HttpServletResponse response) throws Exception { - scriptMakeService.makeCfg(); - scriptMakeService.makeXml(); - response.setStatus(200); - } } diff --git a/src/com/platform/controller/FilePackageController.java b/src/com/platform/controller/FilePackageController.java index 00e30dd9..5906dbea 100644 --- a/src/com/platform/controller/FilePackageController.java +++ b/src/com/platform/controller/FilePackageController.java @@ -1,48 +1,70 @@ -package com.platform.controller; - -import java.io.File; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.FileUtils; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -import com.base.BaseController; -import com.platform.utils.Configs; -import com.platform.utils.ZipCompressUtils; - -@Controller -@RequestMapping("/filePackage") -public class FilePackageController extends BaseController { - - @RequestMapping("/download") - public ResponseEntity downloadFile(HttpServletRequest request, - HttpServletResponse response) throws Exception { - String filePath = Configs.PACKAGE_DOWNLOAD_PATH; - System.out.println(filePath + Configs.PACKAGE_NAME); - ZipCompressUtils.zip(new File(filePath + Configs.PACKAGE_NAME), - filePath + "package.zip"); // 产生压缩文件 - File file = new File(filePath + "package.zip"); - if (file.exists()) { - HttpHeaders headers = new HttpHeaders(); - String fileName = new String(file.getName());// 为了解决中文名称乱码问题 - System.out.println(fileName); - headers.setContentDispositionFormData("attachment", fileName); - headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); - ResponseEntity responseEntity = new ResponseEntity( - FileUtils.readFileToByteArray(file), headers, - HttpStatus.CREATED); - file.delete(); // - return responseEntity; - } else { - response.setStatus(500); - return null; - } - } -} +package com.platform.controller; + +import java.io.File; +import java.util.List; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FileUtils; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.base.BaseController; +import com.platform.entities.MyFilesEntity; +import com.platform.entities.PreDataInfo; +import com.platform.service.IScriptMakeService; +import com.platform.utils.Configs; +import com.platform.utils.ZipCompressUtils; + +@Controller +@RequestMapping("/filePackage") +public class FilePackageController extends BaseController { + + @Resource(name = "scriptMakeService") + private IScriptMakeService scriptMakeService; + + @RequestMapping("/download") + public ResponseEntity downloadFile(HttpServletRequest request, + HttpServletResponse response) throws Exception { + scriptMakeService.makeCfg(); + scriptMakeService.makeXml(); + String filePath = Configs.PACKAGE_DOWNLOAD_PATH; + System.out.println(filePath + Configs.PACKAGE_NAME); + ZipCompressUtils.zip(new File(filePath + Configs.PACKAGE_NAME), + filePath + "package.zip"); // 产生压缩文件 + File file = new File(filePath + "package.zip"); + if (file.exists()) { + HttpHeaders headers = new HttpHeaders(); + String fileName = new String(file.getName());// 为了解决中文名称乱码问题 + System.out.println(fileName); + headers.setContentDispositionFormData("attachment", fileName); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + ResponseEntity responseEntity = new ResponseEntity( + FileUtils.readFileToByteArray(file), headers, + HttpStatus.CREATED); + file.delete(); // + return responseEntity; + } else { + response.setStatus(500); + return null; + } + } + + @ResponseBody + @RequestMapping("/findAll") + public ModelMap findAll() throws Exception { + ModelMap modelMap = new ModelMap(); + List result = scriptMakeService.FindAllFiles(); + modelMap.addAttribute("data", result); + modelMap.addAttribute("length", result.size()); + return modelMap; + } +} diff --git a/src/com/platform/entities/MyFileEntity.java b/src/com/platform/entities/MyFileEntity.java deleted file mode 100644 index 0d68735b..00000000 --- a/src/com/platform/entities/MyFileEntity.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.platform.entities; - -public class MyFileEntity { - - private String fileName; - - private String lastTime; - - private String filePath; - - /** - * @return the fileName - */ - public String getFileName() { - return fileName; - } - - /** - * @param fileName the fileName to set - */ - public void setFileName(String fileName) { - this.fileName = fileName; - } - - /** - * @return the lastTime - */ - public String getLastTime() { - return lastTime; - } - - /** - * @param lastTime the lastTime to set - */ - public void setLastTime(String lastTime) { - this.lastTime = lastTime; - } - - /** - * @return the filePath - */ - public String getFilePath() { - return filePath; - } - - /** - * @param filePath the filePath to set - */ - public void setFilePath(String filePath) { - this.filePath = filePath; - } - -} diff --git a/src/com/platform/entities/MyFilesEntity.java b/src/com/platform/entities/MyFilesEntity.java new file mode 100644 index 00000000..d7357f67 --- /dev/null +++ b/src/com/platform/entities/MyFilesEntity.java @@ -0,0 +1,279 @@ +package com.platform.entities; + +public class MyFilesEntity{ + + private int id; + + /** 状态 */ + private int sysStatus; + + private String areaCode; + + private int sysCode; + + private String cityName; + + private String districtName; + + private String sysName; + + /** 数据库类型 */ + private String dataBaseType; + + private int userTableStatus; + + private String userTableScriptPathLast; + + private String userTableScriptPathStandard; + + private int ckPayStatus; + + private String ckPayScriptPathLast; + + private String ckPayScriptPathStandard; + + private int ckIndicateStatus; + + private String ckIndicateScriptPathLast; + + private String ckIndicateScriptPathStandard; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the sysStatus + */ + public int getSysStatus() { + return sysStatus; + } + + /** + * @param sysStatus the sysStatus to set + */ + public void setSysStatus(int sysStatus) { + this.sysStatus = sysStatus; + } + + /** + * @return the areaCode + */ + public String getAreaCode() { + return areaCode; + } + + /** + * @param areaCode the areaCode to set + */ + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + /** + * @return the sysCode + */ + public int getSysCode() { + return sysCode; + } + + /** + * @param sysCode the sysCode to set + */ + public void setSysCode(int sysCode) { + this.sysCode = sysCode; + } + + /** + * @return the cityName + */ + public String getCityName() { + return cityName; + } + + /** + * @param cityName the cityName to set + */ + public void setCityName(String cityName) { + this.cityName = cityName; + } + + /** + * @return the districtName + */ + public String getDistrictName() { + return districtName; + } + + /** + * @param districtName the districtName to set + */ + public void setDistrictName(String districtName) { + this.districtName = districtName; + } + + /** + * @return the sysName + */ + public String getSysName() { + return sysName; + } + + /** + * @param sysName the sysName to set + */ + public void setSysName(String sysName) { + this.sysName = sysName; + } + + /** + * @return the dataBaseType + */ + public String getDataBaseType() { + return dataBaseType; + } + + /** + * @param dataBaseType the dataBaseType to set + */ + public void setDataBaseType(String dataBaseType) { + this.dataBaseType = dataBaseType; + } + + /** + * @return the userTableStatus + */ + public int getUserTableStatus() { + return userTableStatus; + } + + /** + * @param userTableStatus the userTableStatus to set + */ + public void setUserTableStatus(int userTableStatus) { + this.userTableStatus = userTableStatus; + } + + /** + * @param ckPayStatus the ckPayStatus to set + */ + public void setCkPayStatus(int ckPayStatus) { + this.ckPayStatus = ckPayStatus; + } + + /** + * @param ckIndicateStatus the ckIndicateStatus to set + */ + public void setCkIndicateStatus(int ckIndicateStatus) { + this.ckIndicateStatus = ckIndicateStatus; + } + + /** + * @return the userTableScriptPathLast + */ + public String getUserTableScriptPathLast() { + return userTableScriptPathLast; + } + + /** + * @param userTableScriptPathLast the userTableScriptPathLast to set + */ + public void setUserTableScriptPathLast(String userTableScriptPathLast) { + this.userTableScriptPathLast = userTableScriptPathLast; + } + + /** + * @return the userTableScriptPathStandard + */ + public String getUserTableScriptPathStandard() { + return userTableScriptPathStandard; + } + + /** + * @param userTableScriptPathStandard the userTableScriptPathStandard to set + */ + public void setUserTableScriptPathStandard(String userTableScriptPathStandard) { + this.userTableScriptPathStandard = userTableScriptPathStandard; + } + + /** + * @return the ckPayScriptPathLast + */ + public String getCkPayScriptPathLast() { + return ckPayScriptPathLast; + } + + /** + * @param ckPayScriptPathLast the ckPayScriptPathLast to set + */ + public void setCkPayScriptPathLast(String ckPayScriptPathLast) { + this.ckPayScriptPathLast = ckPayScriptPathLast; + } + + /** + * @return the ckPayScriptPathStandard + */ + public String getCkPayScriptPathStandard() { + return ckPayScriptPathStandard; + } + + /** + * @param ckPayScriptPathStandard the ckPayScriptPathStandard to set + */ + public void setCkPayScriptPathStandard(String ckPayScriptPathStandard) { + this.ckPayScriptPathStandard = ckPayScriptPathStandard; + } + + /** + * @return the ckIndicateScriptPathLast + */ + public String getCkIndicateScriptPathLast() { + return ckIndicateScriptPathLast; + } + + /** + * @param ckIndicateScriptPathLast the ckIndicateScriptPathLast to set + */ + public void setCkIndicateScriptPathLast(String ckIndicateScriptPathLast) { + this.ckIndicateScriptPathLast = ckIndicateScriptPathLast; + } + + /** + * @return the ckIndicateScriptPathStandard + */ + public String getCkIndicateScriptPathStandard() { + return ckIndicateScriptPathStandard; + } + + /** + * @param ckIndicateScriptPathStandard the ckIndicateScriptPathStandard to set + */ + public void setCkIndicateScriptPathStandard(String ckIndicateScriptPathStandard) { + this.ckIndicateScriptPathStandard = ckIndicateScriptPathStandard; + } + + /** + * @return the ckPayStatus + */ + public int getCkPayStatus() { + return ckPayStatus; + } + + /** + * @return the ckIndicateStatus + */ + public int getCkIndicateStatus() { + return ckIndicateStatus; + } + +} diff --git a/src/com/platform/service/IScriptMakeService.java b/src/com/platform/service/IScriptMakeService.java index 9588c2c1..3e93bb62 100644 --- a/src/com/platform/service/IScriptMakeService.java +++ b/src/com/platform/service/IScriptMakeService.java @@ -2,7 +2,7 @@ package com.platform.service; import java.util.List; -import com.platform.entities.MyFileEntity; +import com.platform.entities.MyFilesEntity; public interface IScriptMakeService { @@ -10,8 +10,8 @@ public interface IScriptMakeService { public int makeXml() throws Exception; - public int moveFiles(MyFileEntity file) throws Exception; + public int moveFiles(List file) throws Exception; - public List FindFiles() throws Exception; + public List FindAllFiles() throws Exception; } diff --git a/src/com/platform/service/impl/ScriptMakeService.java b/src/com/platform/service/impl/ScriptMakeService.java index e07f54e3..287662aa 100644 --- a/src/com/platform/service/impl/ScriptMakeService.java +++ b/src/com/platform/service/impl/ScriptMakeService.java @@ -2,25 +2,32 @@ package com.platform.service.impl; import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; +import net.sf.json.regexp.RegexpUtils; + import org.apache.log4j.Logger; import org.springframework.stereotype.Service; import com.platform.dao.PreDataInfoDao; import com.platform.entities.DefaultDataDescription; -import com.platform.entities.MyFileEntity; +import com.platform.entities.MyFilesEntity; import com.platform.entities.PreDataInfo; import com.platform.service.IScriptMakeService; +import com.platform.utils.BeanCopy; +import com.platform.utils.Compare4MyFilesEntity; import com.platform.utils.Configs; import com.platform.utils.Constant; import com.platform.utils.FileOperateHelper; import com.platform.utils.XmlOperationByDom4j; +import dk.brics.automaton.RegExp; + @Service(value = "scriptMakeService") public class ScriptMakeService implements IScriptMakeService { @@ -34,7 +41,7 @@ public class ScriptMakeService implements IScriptMakeService { public int makeCfg() throws Exception { log.info("makeCfg"); List systemInfoList = preDataInfoDao.findAll(); - String path = FileOperateHelper.addLastSeparator(Configs.sql_script_path_standard); + String path = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD); StringBuffer sb = new StringBuffer(); sb.append("市\t县(市、区)\t行政区划代码\r\n"); Map startData = new HashMap(); @@ -61,7 +68,7 @@ public class ScriptMakeService implements IScriptMakeService { public int makeXml() throws Exception { log.info("makeXml"); List systemInfoList = preDataInfoDao.findAll(); - String dirpath = FileOperateHelper.addLastSeparator(Configs.sql_script_path_standard); + String dirpath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD); Map> map = new HashMap>(); for (PreDataInfo preDataInfo : systemInfoList) { putSystemByAreaCode(map, preDataInfo.getAreaCode(), preDataInfo); @@ -86,15 +93,23 @@ public class ScriptMakeService implements IScriptMakeService { } @Override - public int moveFiles(MyFileEntity file) throws Exception { - // TODO Auto-generated method stub + public int moveFiles(List files) throws Exception { + return 0; } @Override - public List FindFiles() throws Exception { - // TODO Auto-generated method stub - return null; + public List FindAllFiles() throws Exception { + List systemDataInfo = preDataInfoDao.findAll(); + // 查找 Configs.SQL_SCRIPT_PATH_LAST 路径下的 所有的文件:路径 + Map sqlFilePathsLast = new HashMap(); + sqlFilePathsLast = getAllFile(sqlFilePathsLast, Configs.SQL_SCRIPT_PATH_LAST); + //遍历 查找 Configs.SQL_SCRIPT_PATH_STANDARD 脚本文件 放入集合中 + Map sqlFilePathsStandard = new HashMap(); + sqlFilePathsStandard = getAllFile(sqlFilePathsStandard, Configs.SQL_SCRIPT_PATH_STANDARD); + // 填充 脚本状态、位置的信息 + List result = setScript(systemDataInfo, sqlFilePathsStandard, sqlFilePathsLast); + return result; } /** @@ -112,5 +127,133 @@ public class ScriptMakeService implements IScriptMakeService { map.put(code, list); return map; } + + /** 遍历文件 + * @param ps + * @param path + * @return + */ + private Map getAllFile(Map ps, String path){ + File f = new File(path); + String name = f.getName(); + //如果是 sql文件 + if(name.endsWith(".sql") || name.endsWith(".SQL")) + ps.put(name.toLowerCase(),f.getAbsolutePath()); + if (f.exists()) { + String[] subpaths = f.list(); + if (null != subpaths) { + for (String tmppath : subpaths) { + getAllFile(ps, f.getAbsolutePath()+"/"+tmppath); + } + } + } + return ps; + } + + /** + * @param systemDataInfo 系统信息 + * @param sqlFilePathsStandard 标准的-归档的脚本 + * @param sqlFilePathsLast 最新的脚本 + * @return + */ + private List setScript(List systemDataInfo, Map sqlFilePathsStandard, Map sqlFilePathsLast){ + List fileEntitys = new ArrayList(); + for (PreDataInfo preDataInfo : systemDataInfo) { + MyFilesEntity myfile = new MyFilesEntity(); + //复制 + BeanCopy.copyBean(preDataInfo, myfile); + // 归档表空间脚本的位置- + String TablePathStandard = getFilePath("UserTablespace_", sqlFilePathsStandard, myfile, ".sql"); + myfile.setUserTableScriptPathStandard(TablePathStandard); + // 归档预算 脚本的位置- + String indicatePathStandard = getFilePath("Checkout_Indicate_", sqlFilePathsStandard, myfile, ".sql"); + myfile.setCkIndicateScriptPathStandard(indicatePathStandard); + // 归档表空间脚本的位置- + String payPathStandard = getFilePath("Checkout_Pay_", sqlFilePathsStandard, myfile, ".sql"); + myfile.setCkPayScriptPathStandard(payPathStandard); + // 最新表空间脚本的位置- + String TablePathLast = getFilePath("UserTablespace_", sqlFilePathsLast, myfile, ".sql"); + myfile.setUserTableScriptPathLast(TablePathLast); + // 最新预算 脚本的位置- + String indicatePathLast = getFilePath("Checkout_Indicate_", sqlFilePathsLast, myfile, ".sql"); + myfile.setCkIndicateScriptPathLast(indicatePathLast); + // 最新表空间脚本的位置- + String payPathLast = getFilePath("Checkout_Pay_", sqlFilePathsLast, myfile, ".sql"); + myfile.setCkPayScriptPathLast(payPathLast); + //设置 状态 + myfile.setUserTableStatus(getStatus(myfile.getUserTableScriptPathStandard(), myfile.getUserTableScriptPathLast())); + myfile.setCkIndicateStatus(getStatus(myfile.getCkIndicateScriptPathStandard(), myfile.getCkIndicateScriptPathLast())); + myfile.setCkPayStatus(getStatus(myfile.getCkPayScriptPathStandard(), myfile.getCkPayScriptPathLast())); + myfile.setSysStatus(getTotalStatus(myfile)); + fileEntitys.add(myfile); + } + Compare4MyFilesEntity com = new Compare4MyFilesEntity(); + Collections.sort(fileEntitys, com); + return fileEntitys; + } + + /** 查找文件 + * @param prefix + * @param map + * @param myf + * @param affix + * @return + */ + private String getFilePath(String prefix, Map map, MyFilesEntity myf, String affix) { + StringBuffer sb = new StringBuffer(); + sb.append(prefix).append(myf.getAreaCode().toLowerCase()).append("_").append(myf.getSysCode()).append(affix.toLowerCase()); + String fileName = sb.toString().toLowerCase(); + if (!map.keySet().contains(fileName)) { + return null; + } + // 地区字母 小写 -- 文件属性小写 + String pathStandard = map.get(fileName); + return pathStandard; + } + + /** 返回状态--0: standard, last为空; 1:standard不空,last为空; 2:standard为空,last不空,3:standard不空,last不空 + * 对应 含义,操作: 0:(有缺失,上传) ; 1: (正常 ,查看); 2:(待归档,归档) ; 3: (待审核,审核) + * @param standard + * @param last + * @return + */ + private int getStatus(String standard, String last) { + int status = 0; + if (null != standard && !standard.isEmpty()) { + status = status | 1; + } + if (null != last && !last.isEmpty()) { + status = status | 2; + } + return status; + } + + /** 返回状态 + * 对应 含义,操作: 0:(有缺失,上传) ; 1: (正常 ,查看); 2:(待归档,归档) ; 3: (待审核,审核) + * @param standard + * @param last + * @return + */ + private int getTotalStatus(MyFilesEntity myfile) { + Integer[] numArr = new Integer[3]; + Integer result = 1; + numArr[0] = myfile.getUserTableStatus(); + numArr[1] = myfile.getCkIndicateStatus(); + numArr[2] = myfile.getCkPayStatus(); + for (Integer integer : numArr) { + if (integer != 1) { + result = integer; + } + } + if (result == 1) { + return result; + } + for (Integer integer : numArr) { + if (integer != 1) { + result = result & integer; + } + } + return result; + } } diff --git a/src/com/platform/utils/BeanCopy.java b/src/com/platform/utils/BeanCopy.java index 29ca3cc7..802e5e0d 100644 --- a/src/com/platform/utils/BeanCopy.java +++ b/src/com/platform/utils/BeanCopy.java @@ -1,15 +1,18 @@ package com.platform.utils; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import com.fasterxml.jackson.databind.PropertyNamingStrategy.UpperCamelCaseStrategy; +import org.apache.log4j.Logger; public class BeanCopy { + public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(BeanCopy.class); + /** 复制属性(子类父类等继承关系不可用) * @param source 源对象 * @param dst 目标对象 @@ -20,7 +23,7 @@ public class BeanCopy { * @throws NoSuchFieldException * @throws SecurityException */ - public static void copyBean(Object source, Object dst, String... params) throws Exception{ + public static void copyBean(Object source, Object dst, String... params){ if (dst.getClass().getSuperclass() == source.getClass()) { fatherCopyChild(source, dst, params); } @@ -40,20 +43,24 @@ public class BeanCopy { if (sourceFieldName.contains(name)) { field.setAccessible(true); Object value; - Method m = source.getClass().getMethod("get"+upperHeadChar(name)); - value = m.invoke(source); -// Field fie = source.getClass().getDeclaredField(name); -// fie.setAccessible(true); -// value = fie.get(source); - if (null != value) { - field.set(dst, value); - } + Method m; + try { + m = source.getClass().getMethod("get"+upperHeadChar(name)); + value = m.invoke(source); + // Field fie = source.getClass().getDeclaredField(name); + // fie.setAccessible(true); + // value = fie.get(source); + if (null != value) + field.set(dst, value); + } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) { + log.error(e.getStackTrace()); + } } } } - private static void fatherCopyChild(Object father, Object dst, String... params) throws Exception{ + private static void fatherCopyChild(Object father, Object dst, String... params){ List filter = new ArrayList(); filter.addAll(Arrays.asList(params)); if (dst.getClass().getSuperclass() == father.getClass()) { @@ -67,9 +74,13 @@ public class BeanCopy { } f.setAccessible(true); Class type = f.getType(); - Method m = faClass.getMethod("get"+upperHeadChar(f.getName())); - Object obj = m.invoke(father); - f.set(dst, obj); + try { + Method m = faClass.getMethod("get"+upperHeadChar(f.getName())); + Object obj = m.invoke(father); + f.set(dst, obj); + } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) { + log.error(e.getStackTrace()); + } } } } diff --git a/src/com/platform/utils/Compare4MyFilesEntity.java b/src/com/platform/utils/Compare4MyFilesEntity.java new file mode 100644 index 00000000..9bb2aa52 --- /dev/null +++ b/src/com/platform/utils/Compare4MyFilesEntity.java @@ -0,0 +1,17 @@ +package com.platform.utils; + +import java.util.Comparator; + +import com.platform.entities.MyFilesEntity; + +public class Compare4MyFilesEntity implements Comparator { + + @Override + public int compare(MyFilesEntity arg0, MyFilesEntity arg1) { + if (arg0.getSysStatus() < arg1.getSysStatus()) + return 1; + else + return -1; + } + +} diff --git a/src/com/platform/utils/Configs.java b/src/com/platform/utils/Configs.java index b73ddc27..abc6e2da 100644 --- a/src/com/platform/utils/Configs.java +++ b/src/com/platform/utils/Configs.java @@ -1,64 +1,64 @@ -package com.platform.utils; - -import org.apache.log4j.Logger; - -public class Configs { - - /** 全局自定义异常--编码 */ - public static final String GLOBAL_EXP_CUSTOM = "3001001001"; - - /** 全局非自定义异常--编码 */ - public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002"; - - public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties"; - - public static final Logger CONSOLE_LOGGER = Logger.getLogger("console"); - - public static final Logger DAILY_ROLLING_LOGGER = Logger - .getLogger("dailyRollingFile"); - - public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile"); - - public static final Logger LOGGER = Logger.getLogger(Configs.class); - - public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser - // URl - - public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 - - public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名 - - public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码 - - public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名 - - public static String GATHER_PORT ="1521"; //汇总库的端口号 - - public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名 - - public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码 - - public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名 - - public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 - - public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置 - - public static String GATHER_TABLESPACE_NAME=""; //表空间名 - - public static String GATHER_TABLESPACE_PATH=""; //表空间路径 - - public static String GATHER_TABLE_PASSWORD="1"; //登入密码 - - public static String FILE_UPLOAD_PATH=""; - - public static String FILE_DOWNLOAD_PATH=""; - - public static String PACKAGE_DOWNLOAD_PATH=""; - - public static String PACKAGE_NAME=""; - - public static String sql_script_path_last=""; - - public static String sql_script_path_standard=""; -} +package com.platform.utils; + +import org.apache.log4j.Logger; + +public class Configs { + + /** 全局自定义异常--编码 */ + public static final String GLOBAL_EXP_CUSTOM = "3001001001"; + + /** 全局非自定义异常--编码 */ + public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002"; + + public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties"; + + public static final Logger CONSOLE_LOGGER = Logger.getLogger("console"); + + public static final Logger DAILY_ROLLING_LOGGER = Logger + .getLogger("dailyRollingFile"); + + public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile"); + + public static final Logger LOGGER = Logger.getLogger(Configs.class); + + public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser + // URl + + public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 + + public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名 + + public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码 + + public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名 + + public static String GATHER_PORT ="1521"; //汇总库的端口号 + + public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名 + + public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码 + + public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名 + + public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 + + public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置 + + public static String GATHER_TABLESPACE_NAME=""; //表空间名 + + public static String GATHER_TABLESPACE_PATH=""; //表空间路径 + + public static String GATHER_TABLE_PASSWORD="1"; //登入密码 + + public static String FILE_UPLOAD_PATH=""; + + public static String FILE_DOWNLOAD_PATH=""; + + public static String PACKAGE_DOWNLOAD_PATH=""; + + public static String PACKAGE_NAME=""; + + public static String SQL_SCRIPT_PATH_LAST=""; + + public static String SQL_SCRIPT_PATH_STANDARD=""; +} diff --git a/src/com/platform/utils/ConfigsLoader.java b/src/com/platform/utils/ConfigsLoader.java index d9534740..5b55f1ba 100644 --- a/src/com/platform/utils/ConfigsLoader.java +++ b/src/com/platform/utils/ConfigsLoader.java @@ -1,95 +1,95 @@ -package com.platform.utils; - -import java.util.Properties; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import com.platform.http.gfs.HttpClientConstant; - -public class ConfigsLoader implements ServletContextListener { - private static ConfigPropertyReader cReader = null; - - @Override - public void contextDestroyed(ServletContextEvent sEvent) { - // TODO Auto-generated method stub - Configs.CONSOLE_LOGGER.info("系统停止.."); - } - - @SuppressWarnings("static-access") - @Override - public void contextInitialized(ServletContextEvent sEvent) { - // TODO Auto-generated method stub - Configs.CONSOLE_LOGGER.info("系统初始化.."); - String contextPath = sEvent.getServletContext().getRealPath("/") - + "WEB-INF/config/config.properties"; - this.cReader = ConfigPropertyReader.Builder(contextPath); - init(); - new ThreadVolume("ThreadVolume-in-ConfigsLoader").start(); - } - - public static void init() { - Properties properties = cReader.getProperties(); - - Configs.KUBE_MASTER_URL = properties.getProperty("kubeMasterUrl"); - - Configs.COLLECT_USER_NAME = properties.getProperty("collect-user-name"); - - Configs.COLLECT_PASSWORD = properties.getProperty("collect-password"); - - Configs.COLLECT_SERVICE_NAME = properties - .getProperty("collect-service-name"); - - Configs.GATHER_USER_NAME = properties.getProperty("gather-user-name"); - - Configs.GATHER_USER_PASSWORD = properties - .getProperty("gather-user-password"); - - Configs.GATHER_PORT = properties.getProperty("gather-port"); - - Configs.GATHER_SERVICE_NAME = properties - .getProperty("gather-service-name"); - - Configs.TABLE_SUFFIX = properties.getProperty("table-suffix"); - - Configs.EXTRACT_LOG_LOCALTION = properties - .getProperty("extract-log-localtion"); - - Configs.GATHER_TABLESPACE_NAME = properties - .getProperty("gather-tablespace-name"); - - Configs.GATHER_TABLESPACE_PATH = properties - .getProperty("gather-tablespace-path"); - - Configs.GATHER_TABLE_PASSWORD=properties.getProperty("gather-table-user-password"); - - Configs.FILE_UPLOAD_PATH = properties.getProperty("file_upload_path"); - - Configs.FILE_DOWNLOAD_PATH = properties.getProperty("file_download_path"); - - Configs.PACKAGE_DOWNLOAD_PATH = properties.getProperty("package_download_path"); - - Configs.PACKAGE_NAME = properties.getProperty("package_name"); - - Configs.sql_script_path_last = properties.getProperty("sql_script_path_last"); - - Configs.sql_script_path_standard = properties.getProperty("sql_script_path_standard"); - - HttpClientConstant.URL_IP_PORT = properties.getProperty("HttpClientConstant_URL_IP_PORT").trim(); - - Constant.hostIp=properties.getProperty("gfs_control_ip").trim(); - Constant.rootPasswd=properties.getProperty("gfs_control_rootPassWd").trim(); - Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port); - - } - - public ConfigPropertyReader getcReader() { - return cReader; - } - - @SuppressWarnings("static-access") - public void setcReader(ConfigPropertyReader cReader) { - this.cReader = cReader; - } - -} +package com.platform.utils; + +import java.util.Properties; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +import com.platform.http.gfs.HttpClientConstant; + +public class ConfigsLoader implements ServletContextListener { + private static ConfigPropertyReader cReader = null; + + @Override + public void contextDestroyed(ServletContextEvent sEvent) { + // TODO Auto-generated method stub + Configs.CONSOLE_LOGGER.info("系统停止.."); + } + + @SuppressWarnings("static-access") + @Override + public void contextInitialized(ServletContextEvent sEvent) { + // TODO Auto-generated method stub + Configs.CONSOLE_LOGGER.info("系统初始化.."); + String contextPath = sEvent.getServletContext().getRealPath("/") + + "WEB-INF/config/config.properties"; + this.cReader = ConfigPropertyReader.Builder(contextPath); + init(); + new ThreadVolume("ThreadVolume-in-ConfigsLoader").start(); + } + + public static void init() { + Properties properties = cReader.getProperties(); + + Configs.KUBE_MASTER_URL = properties.getProperty("kubeMasterUrl"); + + Configs.COLLECT_USER_NAME = properties.getProperty("collect-user-name"); + + Configs.COLLECT_PASSWORD = properties.getProperty("collect-password"); + + Configs.COLLECT_SERVICE_NAME = properties + .getProperty("collect-service-name"); + + Configs.GATHER_USER_NAME = properties.getProperty("gather-user-name"); + + Configs.GATHER_USER_PASSWORD = properties + .getProperty("gather-user-password"); + + Configs.GATHER_PORT = properties.getProperty("gather-port"); + + Configs.GATHER_SERVICE_NAME = properties + .getProperty("gather-service-name"); + + Configs.TABLE_SUFFIX = properties.getProperty("table-suffix"); + + Configs.EXTRACT_LOG_LOCALTION = properties + .getProperty("extract-log-localtion"); + + Configs.GATHER_TABLESPACE_NAME = properties + .getProperty("gather-tablespace-name"); + + Configs.GATHER_TABLESPACE_PATH = properties + .getProperty("gather-tablespace-path"); + + Configs.GATHER_TABLE_PASSWORD=properties.getProperty("gather-table-user-password"); + + Configs.FILE_UPLOAD_PATH = properties.getProperty("file_upload_path"); + + Configs.FILE_DOWNLOAD_PATH = properties.getProperty("file_download_path"); + + Configs.PACKAGE_DOWNLOAD_PATH = properties.getProperty("package_download_path"); + + Configs.PACKAGE_NAME = properties.getProperty("package_name"); + + Configs.SQL_SCRIPT_PATH_LAST = properties.getProperty("sql_script_path_last"); + + Configs.SQL_SCRIPT_PATH_STANDARD = properties.getProperty("sql_script_path_standard"); + + HttpClientConstant.URL_IP_PORT = properties.getProperty("HttpClientConstant_URL_IP_PORT").trim(); + + Constant.hostIp=properties.getProperty("gfs_control_ip").trim(); + Constant.rootPasswd=properties.getProperty("gfs_control_rootPassWd").trim(); + Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port); + + } + + public ConfigPropertyReader getcReader() { + return cReader; + } + + @SuppressWarnings("static-access") + public void setcReader(ConfigPropertyReader cReader) { + this.cReader = cReader; + } + +} diff --git a/src/com/platform/utils/ProcessMyUtil.java b/src/com/platform/utils/ProcessMyUtil.java new file mode 100644 index 00000000..af21a9dd --- /dev/null +++ b/src/com/platform/utils/ProcessMyUtil.java @@ -0,0 +1,41 @@ +package com.platform.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +public class ProcessMyUtil { + + private static Logger logger = Logger.getLogger(ProcessMyUtil.class); + + public static List execCmdWaitAcquiescent(String cmd) { + return runcmd(cmd); + } + + private static List runcmd(String cmd) { + List result = new ArrayList(); + InputStream in = null; + String[] cmds = {"/bin/sh", "-c", cmd}; + try { + Process pro = Runtime.getRuntime().exec(cmds); + pro.waitFor(); + in = pro.getInputStream(); + BufferedReader read = new BufferedReader(new InputStreamReader(in)); + String line = null; + while ((line=read.readLine()) != null) { + result.add(line); + } + } catch (IOException e) { + logger.error(e.getStackTrace()); + } catch (InterruptedException e) { + logger.error(e.getStackTrace()); + } + return result; + } + +} diff --git a/src/com/platform/utils/ThreadRemoveFile.java b/src/com/platform/utils/ThreadRemoveFile.java new file mode 100644 index 00000000..787afba8 --- /dev/null +++ b/src/com/platform/utils/ThreadRemoveFile.java @@ -0,0 +1,44 @@ +package com.platform.utils; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** 删除文件 + * @author chen + * + */ +public class ThreadRemoveFile extends Thread { + + private List path4Delete = new ArrayList(); + + public ThreadRemoveFile(List paths) { + this.path4Delete = paths; + } + + @Override + public void run() { + while (true) { + List tmpPathArr = new ArrayList(); + if (null != path4Delete && path4Delete.size() > 0) { + for (String path : path4Delete) { + File f = new File(path); + if (f.exists()) { + if (!f.delete()) { + tmpPathArr.add(path); + } + } + } + } + else { + break; + } + path4Delete = tmpPathArr; + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + } + +} diff --git a/src/com/platform/utils/ZipCompressUtils.java b/src/com/platform/utils/ZipCompressUtils.java index e0e29417..238ce741 100644 --- a/src/com/platform/utils/ZipCompressUtils.java +++ b/src/com/platform/utils/ZipCompressUtils.java @@ -1,66 +1,81 @@ -package com.platform.utils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import org.apache.log4j.Logger; -import org.apache.tools.zip.ZipEntry; -import org.apache.tools.zip.ZipOutputStream; - -public class ZipCompressUtils { - private static Logger logger = Logger.getLogger(ZipCompressUtils.class); - - public static void zip(File inputFile, String zipFileName) { - try { - // 解决中文文件夹名乱码的问题 - FileOutputStream fos = new FileOutputStream(new String(zipFileName)); - ZipOutputStream zos = new ZipOutputStream(fos); // 将文件输出流与zip输出流接起来 - logger.info("压缩-->开始"); - zip(zos, inputFile, ""); - logger.info("压缩结束"); - zos.close(); - } catch (Exception e) { - // TODO: handle exception - } - } - - public static void zip(ZipOutputStream zos, File file, String base) { - try { - // 如果句柄是文件夹 - if (file.isDirectory()) { - File[] files = file.listFiles(); // 获取文件夹下的子文件或子目录 - zos.putNextEntry(new ZipEntry(base + "/")); - logger.info("目录名:" + file.getName() + "|加入ZIP条目:" + base + "/"); - base = (base.length() == 0 ? "" : base + "/"); - // 遍历目录下的文件 - for (int i = 0; i < files.length; i++) { - // 递归进入本方法 - zip(zos, files[i], base + files[i].getName()); - } - } else { // 如果句柄是文件 - if (base == "") - base = file.getName(); - zos.putNextEntry(new ZipEntry(base)); // 填入文件句柄 - logger.info("文件名:" + file.getName() + "|加入ZIP条目:" + base); - // 开始压缩 - // 从文件入流读,写入ZIP 出流 - writeFile(zos, file); - } - } catch (Exception e) { - // TODO: handle exception - } - } - - public static void writeFile(ZipOutputStream zos, File file) - throws IOException { - logger.info("开始压缩" + file.getName()); - FileInputStream fis = new FileInputStream(file); - int len; - while ((len = fis.read()) != -1) - zos.write(len); - logger.info("压缩结束"); - fis.close(); - } -} +package com.platform.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.apache.tools.zip.ZipEntry; +import org.apache.tools.zip.ZipOutputStream; + +public class ZipCompressUtils { + private static Logger logger = Logger.getLogger(ZipCompressUtils.class); + + public static void zip(File inputFile, String zipFileName) { + + Properties pro = System.getProperties(); + String osName = pro.getProperty("os.name"); + if("Linux".equals(osName)||"linux".equals(osName)){ + ProcessMyUtil.execCmdWaitAcquiescent("zip -r "+ FileOperateHelper.addLastSeparator(Configs.PACKAGE_DOWNLOAD_PATH) +"package.zip " + FileOperateHelper.addLastSeparator(Configs.PACKAGE_DOWNLOAD_PATH) + Configs.PACKAGE_NAME); + } + else if ("Windows".equals(osName) || "windows".equals(osName) ) { + // windows下压缩: + try { + // 解决中文文件夹名乱码的问题 + FileOutputStream fos = new FileOutputStream(new String(zipFileName)); + ZipOutputStream zos = new ZipOutputStream(fos); // 将文件输出流与zip输出流接起来 + logger.info("压缩-->开始"); + zip(zos, inputFile, ""); + logger.info("压缩结束"); + zos.close(); + } catch (Exception e) { + logger.error(e.getStackTrace()); + } + } + else { + logger.error(" The current system is not supported \r\n"); + } + + + } + + private static void zip(ZipOutputStream zos, File file, String base) { + try { + // 如果句柄是文件夹 + if (file.isDirectory()) { + File[] files = file.listFiles(); // 获取文件夹下的子文件或子目录 + zos.putNextEntry(new ZipEntry(base + "/")); + logger.info("目录名:" + file.getName() + "|加入ZIP条目:" + base + "/"); + base = (base.length() == 0 ? "" : base + "/"); + // 遍历目录下的文件 + for (int i = 0; i < files.length; i++) { + // 递归进入本方法 + zip(zos, files[i], base + files[i].getName()); + } + } else { // 如果句柄是文件 + if (base == "") + base = file.getName(); + zos.putNextEntry(new ZipEntry(base)); // 填入文件句柄 + logger.info("文件名:" + file.getName() + "|加入ZIP条目:" + base); + // 开始压缩 + // 从文件入流读,写入ZIP 出流 + writeFile(zos, file); + } + } catch (Exception e) { + logger.error(e.getStackTrace()); + } + } + + private static void writeFile(ZipOutputStream zos, File file) + throws IOException { + logger.info("开始压缩" + file.getName()); + FileInputStream fis = new FileInputStream(file); + int len; + while ((len = fis.read()) != -1) + zos.write(len); + logger.info("压缩结束"); + fis.close(); + } +}