查询信息系统的 脚本信息,并给出 脚本存在、缺失的情况

web_backend_develope
chenlw 9 years ago
parent 12661a53d3
commit e48af410dd

@ -50,6 +50,7 @@ import com.platform.service.IPreDataInfoService;
import com.platform.service.IScriptMakeService; import com.platform.service.IScriptMakeService;
import com.platform.utils.Configs; import com.platform.utils.Configs;
import com.platform.utils.HttpUtils; import com.platform.utils.HttpUtils;
import com.platform.utils.ThreadRemoveFile;
import com.platform.utils.UtilsHelper; import com.platform.utils.UtilsHelper;
@Controller @Controller
@ -60,9 +61,7 @@ public class ExcelController extends BaseController{
@Resource(name = "preDataInfoService") @Resource(name = "preDataInfoService")
private IPreDataInfoService preDataInfoService; private IPreDataInfoService preDataInfoService;
@Resource(name = "scriptMakeService")
private IScriptMakeService scriptMakeService;
// 文件上传处理函数 // 文件上传处理函数
@RequestMapping(value = "/file/upload", method = RequestMethod.POST) @RequestMapping(value = "/file/upload", method = RequestMethod.POST)
@ -251,6 +250,7 @@ public class ExcelController extends BaseController{
} }
Map<String, List> result = new HashMap<String, List>(); Map<String, List> result = new HashMap<String, List>();
if (listPath.size() > 0) { if (listPath.size() > 0) {
//导入
result = preDataInfoService.importExcel(listPath); result = preDataInfoService.importExcel(listPath);
if (result.containsKey("fileUnExist") || result.containsKey("areaUnImport")) { if (result.containsKey("fileUnExist") || result.containsKey("areaUnImport")) {
modelMap.addAttribute("data", result); modelMap.addAttribute("data", result);
@ -263,13 +263,20 @@ public class ExcelController extends BaseController{
modelMap.addAttribute("returncode","1001"); modelMap.addAttribute("returncode","1001");
} }
//删除文件 //删除文件
List<String> failedDelete = new ArrayList<String>();
for (String filePath : listPath) { for (String filePath : listPath) {
//读取完后删除源文件(不管是否成功导入) //读取完后删除源文件(不管是否成功导入)
File tmpf = new File(filePath + ".temp"); File tmpf = new File(filePath + ".temp");
File f = new File(filePath); File f = new File(filePath);
tmpf.delete(); if(!tmpf.delete()){
f.delete(); failedDelete.add(tmpf.getAbsolutePath());
}
if(!f.delete()){
failedDelete.add(f.getAbsolutePath());
}
} }
//删除失败时--启用线程去删除
new ThreadRemoveFile(failedDelete).start();
} }
return modelMap; 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);
}
} }

@ -1,48 +1,70 @@
package com.platform.controller; package com.platform.controller;
import java.io.File; import java.io.File;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils; import javax.servlet.http.HttpServletResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.apache.commons.io.FileUtils;
import org.springframework.http.MediaType; import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity; import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import com.base.BaseController; import org.springframework.ui.ModelMap;
import com.platform.utils.Configs; import org.springframework.web.bind.annotation.RequestMapping;
import com.platform.utils.ZipCompressUtils; import org.springframework.web.bind.annotation.ResponseBody;
@Controller import com.base.BaseController;
@RequestMapping("/filePackage") import com.platform.entities.MyFilesEntity;
public class FilePackageController extends BaseController { import com.platform.entities.PreDataInfo;
import com.platform.service.IScriptMakeService;
@RequestMapping("/download") import com.platform.utils.Configs;
public ResponseEntity<byte[]> downloadFile(HttpServletRequest request, import com.platform.utils.ZipCompressUtils;
HttpServletResponse response) throws Exception {
String filePath = Configs.PACKAGE_DOWNLOAD_PATH; @Controller
System.out.println(filePath + Configs.PACKAGE_NAME); @RequestMapping("/filePackage")
ZipCompressUtils.zip(new File(filePath + Configs.PACKAGE_NAME), public class FilePackageController extends BaseController {
filePath + "package.zip"); // 产生压缩文件
File file = new File(filePath + "package.zip"); @Resource(name = "scriptMakeService")
if (file.exists()) { private IScriptMakeService scriptMakeService;
HttpHeaders headers = new HttpHeaders();
String fileName = new String(file.getName());// 为了解决中文名称乱码问题 @RequestMapping("/download")
System.out.println(fileName); public ResponseEntity<byte[]> downloadFile(HttpServletRequest request,
headers.setContentDispositionFormData("attachment", fileName); HttpServletResponse response) throws Exception {
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); scriptMakeService.makeCfg();
ResponseEntity<byte[]> responseEntity = new ResponseEntity<byte[]>( scriptMakeService.makeXml();
FileUtils.readFileToByteArray(file), headers, String filePath = Configs.PACKAGE_DOWNLOAD_PATH;
HttpStatus.CREATED); System.out.println(filePath + Configs.PACKAGE_NAME);
file.delete(); // ZipCompressUtils.zip(new File(filePath + Configs.PACKAGE_NAME),
return responseEntity; filePath + "package.zip"); // 产生压缩文件
} else { File file = new File(filePath + "package.zip");
response.setStatus(500); if (file.exists()) {
return null; 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<byte[]> responseEntity = new ResponseEntity<byte[]>(
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<MyFilesEntity> result = scriptMakeService.FindAllFiles();
modelMap.addAttribute("data", result);
modelMap.addAttribute("length", result.size());
return modelMap;
}
}

@ -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;
}
}

@ -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;
}
}

@ -2,7 +2,7 @@ package com.platform.service;
import java.util.List; import java.util.List;
import com.platform.entities.MyFileEntity; import com.platform.entities.MyFilesEntity;
public interface IScriptMakeService { public interface IScriptMakeService {
@ -10,8 +10,8 @@ public interface IScriptMakeService {
public int makeXml() throws Exception; public int makeXml() throws Exception;
public int moveFiles(MyFileEntity file) throws Exception; public int moveFiles(List<MyFilesEntity> file) throws Exception;
public List<MyFileEntity> FindFiles() throws Exception; public List<MyFilesEntity> FindAllFiles() throws Exception;
} }

@ -2,25 +2,32 @@ package com.platform.service.impl;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import net.sf.json.regexp.RegexpUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.platform.dao.PreDataInfoDao; import com.platform.dao.PreDataInfoDao;
import com.platform.entities.DefaultDataDescription; import com.platform.entities.DefaultDataDescription;
import com.platform.entities.MyFileEntity; import com.platform.entities.MyFilesEntity;
import com.platform.entities.PreDataInfo; import com.platform.entities.PreDataInfo;
import com.platform.service.IScriptMakeService; import com.platform.service.IScriptMakeService;
import com.platform.utils.BeanCopy;
import com.platform.utils.Compare4MyFilesEntity;
import com.platform.utils.Configs; import com.platform.utils.Configs;
import com.platform.utils.Constant; import com.platform.utils.Constant;
import com.platform.utils.FileOperateHelper; import com.platform.utils.FileOperateHelper;
import com.platform.utils.XmlOperationByDom4j; import com.platform.utils.XmlOperationByDom4j;
import dk.brics.automaton.RegExp;
@Service(value = "scriptMakeService") @Service(value = "scriptMakeService")
public class ScriptMakeService implements IScriptMakeService { public class ScriptMakeService implements IScriptMakeService {
@ -34,7 +41,7 @@ public class ScriptMakeService implements IScriptMakeService {
public int makeCfg() throws Exception { public int makeCfg() throws Exception {
log.info("makeCfg"); log.info("makeCfg");
List<PreDataInfo> systemInfoList = preDataInfoDao.findAll(); List<PreDataInfo> 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(); StringBuffer sb = new StringBuffer();
sb.append("市\t县市、区\t行政区划代码\r\n"); sb.append("市\t县市、区\t行政区划代码\r\n");
Map<String, Object> startData = new HashMap<String, Object>(); Map<String, Object> startData = new HashMap<String, Object>();
@ -61,7 +68,7 @@ public class ScriptMakeService implements IScriptMakeService {
public int makeXml() throws Exception { public int makeXml() throws Exception {
log.info("makeXml"); log.info("makeXml");
List<PreDataInfo> systemInfoList = preDataInfoDao.findAll(); List<PreDataInfo> systemInfoList = preDataInfoDao.findAll();
String dirpath = FileOperateHelper.addLastSeparator(Configs.sql_script_path_standard); String dirpath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD);
Map<String, List<Object>> map = new HashMap<String, List<Object>>(); Map<String, List<Object>> map = new HashMap<String, List<Object>>();
for (PreDataInfo preDataInfo : systemInfoList) { for (PreDataInfo preDataInfo : systemInfoList) {
putSystemByAreaCode(map, preDataInfo.getAreaCode(), preDataInfo); putSystemByAreaCode(map, preDataInfo.getAreaCode(), preDataInfo);
@ -86,15 +93,23 @@ public class ScriptMakeService implements IScriptMakeService {
} }
@Override @Override
public int moveFiles(MyFileEntity file) throws Exception { public int moveFiles(List<MyFilesEntity> files) throws Exception {
// TODO Auto-generated method stub
return 0; return 0;
} }
@Override @Override
public List<MyFileEntity> FindFiles() throws Exception { public List<MyFilesEntity> FindAllFiles() throws Exception {
// TODO Auto-generated method stub List<PreDataInfo> systemDataInfo = preDataInfoDao.findAll();
return null; // 查找 Configs.SQL_SCRIPT_PATH_LAST 路径下的 所有的文件:路径
Map<String, String> sqlFilePathsLast = new HashMap<String, String>();
sqlFilePathsLast = getAllFile(sqlFilePathsLast, Configs.SQL_SCRIPT_PATH_LAST);
//遍历 查找 Configs.SQL_SCRIPT_PATH_STANDARD 脚本文件 放入集合中
Map<String, String> sqlFilePathsStandard = new HashMap<String, String>();
sqlFilePathsStandard = getAllFile(sqlFilePathsStandard, Configs.SQL_SCRIPT_PATH_STANDARD);
// 填充 脚本状态、位置的信息
List<MyFilesEntity> result = setScript(systemDataInfo, sqlFilePathsStandard, sqlFilePathsLast);
return result;
} }
/** /**
@ -112,5 +127,133 @@ public class ScriptMakeService implements IScriptMakeService {
map.put(code, list); map.put(code, list);
return map; return map;
} }
/**
* @param ps
* @param path
* @return
*/
private Map<String, String> getAllFile(Map<String, String> 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<MyFilesEntity> setScript(List<PreDataInfo> systemDataInfo, Map<String, String> sqlFilePathsStandard, Map<String, String> sqlFilePathsLast){
List<MyFilesEntity> fileEntitys = new ArrayList<MyFilesEntity>();
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<String, String> 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 1standardlast 2standardlast3standardlast
* 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;
}
} }

@ -1,15 +1,18 @@
package com.platform.utils; package com.platform.utils;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.databind.PropertyNamingStrategy.UpperCamelCaseStrategy; import org.apache.log4j.Logger;
public class BeanCopy { public class BeanCopy {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(BeanCopy.class);
/** /**
* @param source * @param source
* @param dst * @param dst
@ -20,7 +23,7 @@ public class BeanCopy {
* @throws NoSuchFieldException * @throws NoSuchFieldException
* @throws SecurityException * @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()) { if (dst.getClass().getSuperclass() == source.getClass()) {
fatherCopyChild(source, dst, params); fatherCopyChild(source, dst, params);
} }
@ -40,20 +43,24 @@ public class BeanCopy {
if (sourceFieldName.contains(name)) { if (sourceFieldName.contains(name)) {
field.setAccessible(true); field.setAccessible(true);
Object value; Object value;
Method m = source.getClass().getMethod("get"+upperHeadChar(name)); Method m;
value = m.invoke(source); try {
// Field fie = source.getClass().getDeclaredField(name); m = source.getClass().getMethod("get"+upperHeadChar(name));
// fie.setAccessible(true); value = m.invoke(source);
// value = fie.get(source); // Field fie = source.getClass().getDeclaredField(name);
if (null != value) { // fie.setAccessible(true);
field.set(dst, value); // 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<String> filter = new ArrayList<String>(); List<String> filter = new ArrayList<String>();
filter.addAll(Arrays.asList(params)); filter.addAll(Arrays.asList(params));
if (dst.getClass().getSuperclass() == father.getClass()) { if (dst.getClass().getSuperclass() == father.getClass()) {
@ -67,9 +74,13 @@ public class BeanCopy {
} }
f.setAccessible(true); f.setAccessible(true);
Class type = f.getType(); Class type = f.getType();
Method m = faClass.getMethod("get"+upperHeadChar(f.getName())); try {
Object obj = m.invoke(father); Method m = faClass.getMethod("get"+upperHeadChar(f.getName()));
f.set(dst, obj); Object obj = m.invoke(father);
f.set(dst, obj);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
log.error(e.getStackTrace());
}
} }
} }
} }

@ -0,0 +1,17 @@
package com.platform.utils;
import java.util.Comparator;
import com.platform.entities.MyFilesEntity;
public class Compare4MyFilesEntity implements Comparator<MyFilesEntity> {
@Override
public int compare(MyFilesEntity arg0, MyFilesEntity arg1) {
if (arg0.getSysStatus() < arg1.getSysStatus())
return 1;
else
return -1;
}
}

@ -1,64 +1,64 @@
package com.platform.utils; package com.platform.utils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
public class Configs { public class Configs {
/** 全局自定义异常--编码 */ /** 全局自定义异常--编码 */
public static final String GLOBAL_EXP_CUSTOM = "3001001001"; public static final String GLOBAL_EXP_CUSTOM = "3001001001";
/** 全局非自定义异常--编码 */ /** 全局非自定义异常--编码 */
public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002"; public static final String GLOBAL_EXP_NOT_CUSTOM = "3001001002";
public static final String CONFIG_LOCALTION = "WebContent/WEB-INF/config/config.properties"; 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 CONSOLE_LOGGER = Logger.getLogger("console");
public static final Logger DAILY_ROLLING_LOGGER = Logger public static final Logger DAILY_ROLLING_LOGGER = Logger
.getLogger("dailyRollingFile"); .getLogger("dailyRollingFile");
public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile"); public static final Logger DAILY_LOGGER = Logger.getLogger("railyFile");
public static final Logger LOGGER = Logger.getLogger(Configs.class); public static final Logger LOGGER = Logger.getLogger(Configs.class);
public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser public static String KUBE_MASTER_URL = "http://192.168.0.110:8080/"; // kubernetes集群的maser
// URl // URl
public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号 public static int ORACLE_DEFAULT_PORT = 1521; // oracle的默认端口号
public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名 public static String COLLECT_USER_NAME = "system"; //采集统一的登入用户名
public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码 public static String COLLECT_PASSWORD = "oracle"; //采集统一的登入密码
public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名 public static String COLLECT_SERVICE_NAME = "orcl"; //采集库统一的服务名
public static String GATHER_PORT ="1521"; //汇总库的端口号 public static String GATHER_PORT ="1521"; //汇总库的端口号
public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名 public static String GATHER_USER_NAME = "system"; //汇总库的登入用户名
public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码 public static String GATHER_USER_PASSWORD = "1"; //汇总库的登入密码
public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名 public static String GATHER_SERVICE_NAME = "orcl"; //汇总库的服务名
public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名 public static String TABLE_SUFFIX = "_20152016"; //汇总库汇总表的后缀名
public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置 public static String EXTRACT_LOG_LOCALTION = "D:\\log"; //数据汇总日志保存位置
public static String GATHER_TABLESPACE_NAME=""; //表空间名 public static String GATHER_TABLESPACE_NAME=""; //表空间名
public static String GATHER_TABLESPACE_PATH=""; //表空间路径 public static String GATHER_TABLESPACE_PATH=""; //表空间路径
public static String GATHER_TABLE_PASSWORD="1"; //登入密码 public static String GATHER_TABLE_PASSWORD="1"; //登入密码
public static String FILE_UPLOAD_PATH=""; public static String FILE_UPLOAD_PATH="";
public static String FILE_DOWNLOAD_PATH=""; public static String FILE_DOWNLOAD_PATH="";
public static String PACKAGE_DOWNLOAD_PATH=""; public static String PACKAGE_DOWNLOAD_PATH="";
public static String PACKAGE_NAME=""; public static String PACKAGE_NAME="";
public static String sql_script_path_last=""; public static String SQL_SCRIPT_PATH_LAST="";
public static String sql_script_path_standard=""; public static String SQL_SCRIPT_PATH_STANDARD="";
} }

@ -1,95 +1,95 @@
package com.platform.utils; package com.platform.utils;
import java.util.Properties; import java.util.Properties;
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener; import javax.servlet.ServletContextListener;
import com.platform.http.gfs.HttpClientConstant; import com.platform.http.gfs.HttpClientConstant;
public class ConfigsLoader implements ServletContextListener { public class ConfigsLoader implements ServletContextListener {
private static ConfigPropertyReader cReader = null; private static ConfigPropertyReader cReader = null;
@Override @Override
public void contextDestroyed(ServletContextEvent sEvent) { public void contextDestroyed(ServletContextEvent sEvent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Configs.CONSOLE_LOGGER.info("系统停止.."); Configs.CONSOLE_LOGGER.info("系统停止..");
} }
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
@Override @Override
public void contextInitialized(ServletContextEvent sEvent) { public void contextInitialized(ServletContextEvent sEvent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
Configs.CONSOLE_LOGGER.info("系统初始化.."); Configs.CONSOLE_LOGGER.info("系统初始化..");
String contextPath = sEvent.getServletContext().getRealPath("/") String contextPath = sEvent.getServletContext().getRealPath("/")
+ "WEB-INF/config/config.properties"; + "WEB-INF/config/config.properties";
this.cReader = ConfigPropertyReader.Builder(contextPath); this.cReader = ConfigPropertyReader.Builder(contextPath);
init(); init();
new ThreadVolume("ThreadVolume-in-ConfigsLoader").start(); new ThreadVolume("ThreadVolume-in-ConfigsLoader").start();
} }
public static void init() { public static void init() {
Properties properties = cReader.getProperties(); Properties properties = cReader.getProperties();
Configs.KUBE_MASTER_URL = properties.getProperty("kubeMasterUrl"); Configs.KUBE_MASTER_URL = properties.getProperty("kubeMasterUrl");
Configs.COLLECT_USER_NAME = properties.getProperty("collect-user-name"); Configs.COLLECT_USER_NAME = properties.getProperty("collect-user-name");
Configs.COLLECT_PASSWORD = properties.getProperty("collect-password"); Configs.COLLECT_PASSWORD = properties.getProperty("collect-password");
Configs.COLLECT_SERVICE_NAME = properties Configs.COLLECT_SERVICE_NAME = properties
.getProperty("collect-service-name"); .getProperty("collect-service-name");
Configs.GATHER_USER_NAME = properties.getProperty("gather-user-name"); Configs.GATHER_USER_NAME = properties.getProperty("gather-user-name");
Configs.GATHER_USER_PASSWORD = properties Configs.GATHER_USER_PASSWORD = properties
.getProperty("gather-user-password"); .getProperty("gather-user-password");
Configs.GATHER_PORT = properties.getProperty("gather-port"); Configs.GATHER_PORT = properties.getProperty("gather-port");
Configs.GATHER_SERVICE_NAME = properties Configs.GATHER_SERVICE_NAME = properties
.getProperty("gather-service-name"); .getProperty("gather-service-name");
Configs.TABLE_SUFFIX = properties.getProperty("table-suffix"); Configs.TABLE_SUFFIX = properties.getProperty("table-suffix");
Configs.EXTRACT_LOG_LOCALTION = properties Configs.EXTRACT_LOG_LOCALTION = properties
.getProperty("extract-log-localtion"); .getProperty("extract-log-localtion");
Configs.GATHER_TABLESPACE_NAME = properties Configs.GATHER_TABLESPACE_NAME = properties
.getProperty("gather-tablespace-name"); .getProperty("gather-tablespace-name");
Configs.GATHER_TABLESPACE_PATH = properties Configs.GATHER_TABLESPACE_PATH = properties
.getProperty("gather-tablespace-path"); .getProperty("gather-tablespace-path");
Configs.GATHER_TABLE_PASSWORD=properties.getProperty("gather-table-user-password"); Configs.GATHER_TABLE_PASSWORD=properties.getProperty("gather-table-user-password");
Configs.FILE_UPLOAD_PATH = properties.getProperty("file_upload_path"); Configs.FILE_UPLOAD_PATH = properties.getProperty("file_upload_path");
Configs.FILE_DOWNLOAD_PATH = properties.getProperty("file_download_path"); Configs.FILE_DOWNLOAD_PATH = properties.getProperty("file_download_path");
Configs.PACKAGE_DOWNLOAD_PATH = properties.getProperty("package_download_path"); Configs.PACKAGE_DOWNLOAD_PATH = properties.getProperty("package_download_path");
Configs.PACKAGE_NAME = properties.getProperty("package_name"); Configs.PACKAGE_NAME = properties.getProperty("package_name");
Configs.sql_script_path_last = properties.getProperty("sql_script_path_last"); Configs.SQL_SCRIPT_PATH_LAST = properties.getProperty("sql_script_path_last");
Configs.sql_script_path_standard = properties.getProperty("sql_script_path_standard"); Configs.SQL_SCRIPT_PATH_STANDARD = properties.getProperty("sql_script_path_standard");
HttpClientConstant.URL_IP_PORT = properties.getProperty("HttpClientConstant_URL_IP_PORT").trim(); HttpClientConstant.URL_IP_PORT = properties.getProperty("HttpClientConstant_URL_IP_PORT").trim();
Constant.hostIp=properties.getProperty("gfs_control_ip").trim(); Constant.hostIp=properties.getProperty("gfs_control_ip").trim();
Constant.rootPasswd=properties.getProperty("gfs_control_rootPassWd").trim(); Constant.rootPasswd=properties.getProperty("gfs_control_rootPassWd").trim();
Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port); Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port);
} }
public ConfigPropertyReader getcReader() { public ConfigPropertyReader getcReader() {
return cReader; return cReader;
} }
@SuppressWarnings("static-access") @SuppressWarnings("static-access")
public void setcReader(ConfigPropertyReader cReader) { public void setcReader(ConfigPropertyReader cReader) {
this.cReader = cReader; this.cReader = cReader;
} }
} }

@ -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<String> execCmdWaitAcquiescent(String cmd) {
return runcmd(cmd);
}
private static List<String> runcmd(String cmd) {
List<String> result = new ArrayList<String>();
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;
}
}

@ -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<String> path4Delete = new ArrayList<String>();
public ThreadRemoveFile(List<String> paths) {
this.path4Delete = paths;
}
@Override
public void run() {
while (true) {
List<String> tmpPathArr = new ArrayList<String>();
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) {
}
}
}
}

@ -1,66 +1,81 @@
package com.platform.utils; package com.platform.utils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.apache.tools.zip.ZipEntry; import org.apache.log4j.Logger;
import org.apache.tools.zip.ZipOutputStream; import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
public class ZipCompressUtils {
private static Logger logger = Logger.getLogger(ZipCompressUtils.class); public class ZipCompressUtils {
private static Logger logger = Logger.getLogger(ZipCompressUtils.class);
public static void zip(File inputFile, String zipFileName) {
try { public static void zip(File inputFile, String zipFileName) {
// 解决中文文件夹名乱码的问题
FileOutputStream fos = new FileOutputStream(new String(zipFileName)); Properties pro = System.getProperties();
ZipOutputStream zos = new ZipOutputStream(fos); // 将文件输出流与zip输出流接起来 String osName = pro.getProperty("os.name");
logger.info("压缩-->开始"); if("Linux".equals(osName)||"linux".equals(osName)){
zip(zos, inputFile, ""); ProcessMyUtil.execCmdWaitAcquiescent("zip -r "+ FileOperateHelper.addLastSeparator(Configs.PACKAGE_DOWNLOAD_PATH) +"package.zip " + FileOperateHelper.addLastSeparator(Configs.PACKAGE_DOWNLOAD_PATH) + Configs.PACKAGE_NAME);
logger.info("压缩结束"); }
zos.close(); else if ("Windows".equals(osName) || "windows".equals(osName) ) {
} catch (Exception e) { // windows下压缩
// TODO: handle exception try {
} // 解决中文文件夹名乱码的问题
} FileOutputStream fos = new FileOutputStream(new String(zipFileName));
ZipOutputStream zos = new ZipOutputStream(fos); // 将文件输出流与zip输出流接起来
public static void zip(ZipOutputStream zos, File file, String base) { logger.info("压缩-->开始");
try { zip(zos, inputFile, "");
// 如果句柄是文件夹 logger.info("压缩结束");
if (file.isDirectory()) { zos.close();
File[] files = file.listFiles(); // 获取文件夹下的子文件或子目录 } catch (Exception e) {
zos.putNextEntry(new ZipEntry(base + "/")); logger.error(e.getStackTrace());
logger.info("目录名:" + file.getName() + "|加入ZIP条目:" + base + "/"); }
base = (base.length() == 0 ? "" : base + "/"); }
// 遍历目录下的文件 else {
for (int i = 0; i < files.length; i++) { logger.error(" The current system is not supported \r\n");
// 递归进入本方法 }
zip(zos, files[i], base + files[i].getName());
}
} else { // 如果句柄是文件 }
if (base == "")
base = file.getName(); private static void zip(ZipOutputStream zos, File file, String base) {
zos.putNextEntry(new ZipEntry(base)); // 填入文件句柄 try {
logger.info("文件名:" + file.getName() + "|加入ZIP条目:" + base); // 如果句柄是文件夹
// 开始压缩 if (file.isDirectory()) {
// 从文件入流读,写入ZIP 出流 File[] files = file.listFiles(); // 获取文件夹下的子文件或子目录
writeFile(zos, file); zos.putNextEntry(new ZipEntry(base + "/"));
} logger.info("目录名:" + file.getName() + "|加入ZIP条目:" + base + "/");
} catch (Exception e) { base = (base.length() == 0 ? "" : base + "/");
// TODO: handle exception // 遍历目录下的文件
} for (int i = 0; i < files.length; i++) {
} // 递归进入本方法
zip(zos, files[i], base + files[i].getName());
public static void writeFile(ZipOutputStream zos, File file) }
throws IOException { } else { // 如果句柄是文件
logger.info("开始压缩" + file.getName()); if (base == "")
FileInputStream fis = new FileInputStream(file); base = file.getName();
int len; zos.putNextEntry(new ZipEntry(base)); // 填入文件句柄
while ((len = fis.read()) != -1) logger.info("文件名:" + file.getName() + "|加入ZIP条目:" + base);
zos.write(len); // 开始压缩
logger.info("压缩结束"); // 从文件入流读,写入ZIP 出流
fis.close(); 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();
}
}

Loading…
Cancel
Save