联调-脚本的上传、审核、查看、归档

web_backend_develope
chenlw 9 years ago
parent 8616a39ff8
commit ee5acfa3e0

@ -24,7 +24,8 @@ import com.platform.utils.Constant;
public class CustomException extends Exception { public class CustomException extends Exception {
/** log4j */ /** log4j */
public static Logger log = Configs.DAILY_ROLLING_LOGGER; @SuppressWarnings("static-access")
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(CustomException.class);
/** 自定义异常信息-错误信息 */ /** 自定义异常信息-错误信息 */
private String msg; private String msg;

@ -53,7 +53,7 @@ import com.platform.utils.UtilsHelper;
@Controller @Controller
public class DataModelController extends BaseController { public class DataModelController extends BaseController {
public static Logger log = Configs.DAILY_ROLLING_LOGGER; public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(DataModelController.class);
@Resource(name = "dataInfoService") @Resource(name = "dataInfoService")
private DataInfoService dfs; private DataInfoService dfs;

@ -4,6 +4,7 @@ package com.platform.controller;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -14,6 +15,8 @@ import com.platform.utils.Configs;
@Controller @Controller
public class DefaultController { public class DefaultController {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(DefaultController.class);
@RequestMapping("/") @RequestMapping("/")
public ModelAndView defaultHandler(HttpServletRequest req, HttpServletResponse res){ public ModelAndView defaultHandler(HttpServletRequest req, HttpServletResponse res){
//处理不匹配的请求 //处理不匹配的请求

@ -2,24 +2,29 @@ package com.platform.controller;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.base.BaseController; import com.base.BaseController;
import com.platform.entities.MyFilesEntity; import com.platform.entities.MyFilesEntity;
import com.platform.entities.PreDataInfo; import com.platform.form.ScriptForm;
import com.platform.service.IScriptMakeService; import com.platform.service.IScriptMakeService;
import com.platform.utils.Configs; import com.platform.utils.Configs;
import com.platform.utils.ZipCompressUtils; import com.platform.utils.ZipCompressUtils;
@ -28,12 +33,16 @@ import com.platform.utils.ZipCompressUtils;
@RequestMapping("/filePackage") @RequestMapping("/filePackage")
public class FilePackageController extends BaseController { public class FilePackageController extends BaseController {
@SuppressWarnings("static-access")
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(FilePackageController.class);
@Resource(name = "scriptMakeService") @Resource(name = "scriptMakeService")
private IScriptMakeService scriptMakeService; private IScriptMakeService scriptMakeService;
@RequestMapping("/download") @RequestMapping("/download")
public ResponseEntity<byte[]> downloadFile(HttpServletRequest request, public ResponseEntity<byte[]> downloadFile(HttpServletRequest request,
HttpServletResponse response) throws Exception { HttpServletResponse response) throws Exception {
log.info("---------/download--- ");
scriptMakeService.makeCfg(); scriptMakeService.makeCfg();
scriptMakeService.makeXml(); scriptMakeService.makeXml();
String filePath = Configs.PACKAGE_DOWNLOAD_PATH; String filePath = Configs.PACKAGE_DOWNLOAD_PATH;
@ -61,10 +70,40 @@ public class FilePackageController extends BaseController {
@ResponseBody @ResponseBody
@RequestMapping("/findAll") @RequestMapping("/findAll")
public ModelMap findAll() throws Exception { public ModelMap findAll() throws Exception {
log.info("---------/findAll--- ");
ModelMap modelMap = new ModelMap(); ModelMap modelMap = new ModelMap();
List<MyFilesEntity> result = scriptMakeService.FindAllFiles(); List<MyFilesEntity> result = scriptMakeService.FindAllFiles();
modelMap.addAttribute("data", result); modelMap.addAttribute("data", result);
modelMap.addAttribute("length", result.size()); modelMap.addAttribute("length", result.size());
return modelMap; return modelMap;
} }
@RequestMapping(value = "/readSqlFile", method = RequestMethod.POST)
@ResponseBody
public Object getSqlFile(/*@PathVariable*/@RequestParam("type") String type, @RequestBody MyFilesEntity data,
HttpServletRequest res, HttpServletResponse req) throws Exception {
log.info("---------/readSqlFile------------------");
ModelMap modelMap = new ModelMap();
Map<String, Object> result = scriptMakeService.readSql(type, data);
// StringBuilder sb = new StringBuilder();
// sb.append("查看相应日志").append("\n").append("看到了");
// modelMap.addAttribute("data1", result.get("data1").toString());
// modelMap.addAttribute("data2", result.get("data2").toString());
modelMap.addAllAttributes(result);
return modelMap;
}
@RequestMapping(value = "/handleSqlFile", method = RequestMethod.POST)
@ResponseBody
public ModelMap handleSqlFile(@RequestParam("type") String type, @RequestParam("opt") String opt, @RequestBody ScriptForm form,
HttpServletRequest req, HttpServletResponse res) throws Exception {
log.info("---------/handleSqlFile--- " + type +" "+ opt + " ");
ModelMap modelMap = new ModelMap();
Map<String, Object> result = scriptMakeService.handleSqlFile(type, opt, form.getContent(), form.getItem());
modelMap.addAllAttributes(result);
List<MyFilesEntity> results = scriptMakeService.FindAllFiles();
modelMap.addAttribute("data", results);
modelMap.addAttribute("length", results.size());
return modelMap;
}
} }

@ -9,6 +9,7 @@ import javax.annotation.Resource;
import oracle.sql.DATE; import oracle.sql.DATE;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import com.base.BaseController; import com.base.BaseController;
import com.base.CustomException; import com.base.CustomException;
import com.platform.entities.GfsFolderEntity; import com.platform.entities.GfsFolderEntity;
@ -23,11 +25,10 @@ import com.platform.entities.GfsFolderEntity;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.VolumeInfo; import com.platform.glusterfs.VolumeInfo;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.VolumeInfo; import com.platform.glusterfs.VolumeInfo;
import com.platform.service.IGfsService; import com.platform.service.IGfsService;
import com.platform.utils.Configs;
/** /**
@ -44,6 +45,8 @@ import com.platform.service.IGfsService;
public class FolderController extends BaseController { public class FolderController extends BaseController {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(FolderController.class);
@Resource(name = "gfsService") @Resource(name = "gfsService")
private IGfsService gfsService; private IGfsService gfsService;

@ -13,9 +13,12 @@ package com.platform.controller;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.platform.utils.Configs;
/** /**
* <> * <>
@ -32,6 +35,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Controller @Controller
public class SetGlusterfsController { public class SetGlusterfsController {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(SetGlusterfsController.class);
@RequestMapping("/tes") @RequestMapping("/tes")
public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) { public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) {
//<2F><><EFBFBD><><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> //<2F><><EFBFBD><><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>

@ -14,11 +14,13 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.platform.glusterfs.ClusterInfo; import com.platform.glusterfs.ClusterInfo;
import com.platform.glusterfs.VolumeInfo; import com.platform.glusterfs.VolumeInfo;
import com.platform.utils.Configs;
/** /**
* <> * <>
@ -32,6 +34,8 @@ import com.platform.glusterfs.VolumeInfo;
@Controller @Controller
public class ShowGlusterfsController { public class ShowGlusterfsController {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(ShowGlusterfsController.class);
/** /**
* <> * <>

@ -6,15 +6,19 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.base.BaseController; import com.base.BaseController;
import com.platform.utils.Configs;
@Controller @Controller
public class TaskModelController extends BaseController{ public class TaskModelController extends BaseController{
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(TaskModelController.class);
@RequestMapping("/task/transfer/list") @RequestMapping("/task/transfer/list")
@ResponseBody @ResponseBody
public List<Integer> getTransferTask(HttpServletRequest res, HttpServletResponse req) { public List<Integer> getTransferTask(HttpServletRequest res, HttpServletResponse req) {

@ -24,7 +24,7 @@ import com.platform.utils.ThreadVolumeImm;
@Controller @Controller
public class VolumeController extends BaseController{ public class VolumeController extends BaseController{
public static Logger log = Configs.DAILY_ROLLING_LOGGER; public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(VolumeController.class);
@Resource(name = "volumeService") @Resource(name = "volumeService")
private IVolumeService volumeService; private IVolumeService volumeService;

@ -0,0 +1,38 @@
package com.platform.form;
import com.platform.entities.MyFilesEntity;
public class ScriptForm {
private String content;
private MyFilesEntity item;
/**
* @return the content
*/
public String getContent() {
return content;
}
/**
* @param content the content to set
*/
public void setContent(String content) {
this.content = content;
}
/**
* @return the item
*/
public MyFilesEntity getItem() {
return item;
}
/**
* @param item the item to set
*/
public void setItem(MyFilesEntity item) {
this.item = item;
}
}

@ -15,13 +15,18 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import com.platform.controller.DataModelController;
import com.platform.utils.Bean2MapUtils; import com.platform.utils.Bean2MapUtils;
import com.platform.utils.Configs;
public class HttpUtils { public class HttpUtils {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(HttpUtils.class);
public String sendPost(String subUrl, Object data) { public String sendPost(String subUrl, Object data) {
String resultStr = null; String resultStr = "";
HttpClient client = new DefaultHttpClient(); HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(HttpClientConstant.URL_IP_PORT + subUrl); HttpPost post = new HttpPost(HttpClientConstant.URL_IP_PORT + subUrl);
try { try {

@ -1,6 +1,7 @@
package com.platform.service; package com.platform.service;
import java.util.List; import java.util.List;
import java.util.Map;
import com.platform.entities.MyFilesEntity; import com.platform.entities.MyFilesEntity;
@ -14,4 +15,15 @@ public interface IScriptMakeService {
public List<MyFilesEntity> FindAllFiles() throws Exception; public List<MyFilesEntity> FindAllFiles() throws Exception;
public Map<String, Object> readSql(String name, MyFilesEntity form);
/**
* @param type 3
* @param opt
* @param content
* @param form
* @return
*/
public Map<String, Object> handleSqlFile(String type, String opt, String content, MyFilesEntity form);
} }

@ -118,6 +118,11 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
| IllegalAccessException | InstantiationException e) { | IllegalAccessException | InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} }
finally{
if (null != workbook) {
workbook.close();
}
}
} }
if (errFile.size() > 0) { if (errFile.size() > 0) {
@ -328,17 +333,28 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
| IllegalAccessException | IOException e) { | IllegalAccessException | IOException e) {
errList.add(e.getMessage()); errList.add(e.getMessage());
} }
finally{
if (null != workbook) {
workbook.close();
}
}
FileOutputStream fileOut = null;
try { try {
File f = new File(path); File f = new File(path);
FileOutputStream fileOut = null;
f.createNewFile(); f.createNewFile();
fileOut = new FileOutputStream(f); fileOut = new FileOutputStream(f);
result.write(fileOut); result.write(fileOut);
fileOut.close();
} catch (IOException e) { } catch (IOException e) {
errList.add(e.getMessage()); errList.add(e.getMessage());
} }
map.put("err", errList); finally{
if (null != fileOut) {
fileOut.close();
}
}
if (errList.size() > 0) {
map.put("err", errList);
}
return map; return map;
} }

@ -1,6 +1,9 @@
package com.platform.service.impl; package com.platform.service.impl;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
@ -24,6 +27,7 @@ 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.ThreadRemoveFile;
import com.platform.utils.XmlOperationByDom4j; import com.platform.utils.XmlOperationByDom4j;
import dk.brics.automaton.RegExp; import dk.brics.automaton.RegExp;
@ -31,17 +35,19 @@ import dk.brics.automaton.RegExp;
@Service(value = "scriptMakeService") @Service(value = "scriptMakeService")
public class ScriptMakeService implements IScriptMakeService { public class ScriptMakeService implements IScriptMakeService {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(PreDataInfoServiceImpl.class); @SuppressWarnings("static-access")
public static Logger log = Configs.DAILY_ROLLING_LOGGER
.getLogger(ScriptMakeService.class);
@Resource(name = "preDataInfoDao") @Resource(name = "preDataInfoDao")
private PreDataInfoDao preDataInfoDao; private PreDataInfoDao preDataInfoDao;
@Override @Override
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>();
@ -49,8 +55,8 @@ public class ScriptMakeService implements IScriptMakeService {
startData.put(preDataInfo.getAreaCode(), preDataInfo); startData.put(preDataInfo.getAreaCode(), preDataInfo);
} }
//以地区为准--一个地区一个xml // 以地区为准--一个地区一个xml
for ( String key : startData.keySet()) { for (String key : startData.keySet()) {
PreDataInfo preDataInfo = (PreDataInfo) startData.get(key); PreDataInfo preDataInfo = (PreDataInfo) startData.get(key);
sb.append(preDataInfo.getCityName()); sb.append(preDataInfo.getCityName());
sb.append("\t"); sb.append("\t");
@ -59,7 +65,8 @@ public class ScriptMakeService implements IScriptMakeService {
sb.append(preDataInfo.getAreaCode()); sb.append(preDataInfo.getAreaCode());
sb.append("\r\n"); sb.append("\r\n");
} }
FileOperateHelper.fileWrite(path+Constant.cfgFileName, sb.toString()); FileOperateHelper.fileReWrite(path + Constant.cfgFileName,
sb.toString());
log.info("makeCfg--end"); log.info("makeCfg--end");
return 1; return 1;
} }
@ -68,13 +75,14 @@ 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);
} }
//一个地区一个xml // 一个地区一个xml
for ( String key : map.keySet()) { for (String key : map.keySet()) {
String areaPath = dirpath + key; String areaPath = dirpath + key;
File f = new File(areaPath); File f = new File(areaPath);
f.mkdir(); f.mkdir();
@ -86,39 +94,148 @@ public class ScriptMakeService implements IScriptMakeService {
defList.add(defaul); defList.add(defaul);
} }
XmlOperationByDom4j.createXml(FileOperateHelper.addLastSeparator(areaPath)+key+".xml", defList, "Data_info", "workRange"); XmlOperationByDom4j
.createXml(FileOperateHelper.addLastSeparator(areaPath)
+ key + ".xml", defList, "Data_info", "workRange");
} }
log.info("makeXml--end"); log.info("makeXml--end");
return 1; return 1;
} }
@Override
public int moveFiles(List<MyFilesEntity> files) throws Exception {
return 0;
}
@Override @Override
public List<MyFilesEntity> FindAllFiles() throws Exception { public List<MyFilesEntity> FindAllFiles() throws Exception {
List<PreDataInfo> systemDataInfo = preDataInfoDao.findAll(); List<PreDataInfo> systemDataInfo = preDataInfoDao.findAll();
// 查找 Configs.SQL_SCRIPT_PATH_LAST 路径下的 所有的文件:路径 // 查找 Configs.SQL_SCRIPT_PATH_LAST 路径下的 所有的文件:路径
Map<String, String> sqlFilePathsLast = new HashMap<String, String>(); Map<String, String> sqlFilePathsLast = new HashMap<String, String>();
sqlFilePathsLast = getAllFile(sqlFilePathsLast, Configs.SQL_SCRIPT_PATH_LAST); sqlFilePathsLast = getAllFile(sqlFilePathsLast,
//遍历 查找 Configs.SQL_SCRIPT_PATH_STANDARD 脚本文件 放入集合中 Configs.SQL_SCRIPT_PATH_LAST);
// 遍历 查找 Configs.SQL_SCRIPT_PATH_STANDARD 脚本文件 放入集合中
Map<String, String> sqlFilePathsStandard = new HashMap<String, String>(); Map<String, String> sqlFilePathsStandard = new HashMap<String, String>();
sqlFilePathsStandard = getAllFile(sqlFilePathsStandard, Configs.SQL_SCRIPT_PATH_STANDARD); sqlFilePathsStandard = getAllFile(sqlFilePathsStandard,
Configs.SQL_SCRIPT_PATH_STANDARD);
// 填充 脚本状态、位置的信息 // 填充 脚本状态、位置的信息
List<MyFilesEntity> result = setScript(systemDataInfo, sqlFilePathsStandard, sqlFilePathsLast); List<MyFilesEntity> result = setScript(systemDataInfo,
sqlFilePathsStandard, sqlFilePathsLast);
return result; return result;
} }
@Override
public Map<String, Object> readSql(String name, MyFilesEntity form) {
Map<String, Object> map = new HashMap<String, Object>();
String path1 = "";
String path2 = "";
switch (name) {
case "userTableStatus":
path1 = form.getUserTableScriptPathStandard();
map.put("data1Path", path1);
map.put("data1", fileReader(path1));
path2 = form.getUserTableScriptPathLast();
map.put("data2Path", path2);
map.put("data2", fileReader(path2));
break;
case "ckIndicateStatus":
path1 = form.getCkIndicateScriptPathStandard();
map.put("data1Path", path1);
map.put("data1", fileReader(path1));
path2 = form.getCkIndicateScriptPathLast();
map.put("data2Path", path2);
map.put("data2", fileReader(path2));
break;
case "ckPayStatus":
path1 = form.getCkPayScriptPathStandard();
map.put("data1Path", path1);
map.put("data1", fileReader(path1));
path2 = form.getCkPayScriptPathLast();
map.put("data2Path", path2);
map.put("data2", fileReader(path2));
break;
default:
break;
}
return map;
}
@Override
public int moveFiles(List<MyFilesEntity> files) throws Exception {
return 0;
}
@Override
public Map<String, Object> handleSqlFile(String type, String opt, String content, MyFilesEntity form) {
Map<String, Object> map = new HashMap<String, Object>();
String standardPath = "";
String lastPath = "";
if (null == form.getAreaCode() || form.getSysCode() < 1) {
map.put("err", "请选择信息系统!");
return map;
}
// 选择哪种类型的 脚本 path 可能 = null
switch (type) {
case "userTableStatus":
standardPath = form.getUserTableScriptPathStandard();
if (null == standardPath || standardPath.isEmpty()) {
standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode()
+ File.separator + "UserTablespace_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql";
}
lastPath = form.getUserTableScriptPathLast();
break;
case "ckIndicateStatus":
if (null == standardPath || standardPath.isEmpty()) {
standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode()
+ File.separator + "Checkout_Indicate_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql";
}
standardPath = form.getCkIndicateScriptPathStandard();
lastPath = form.getCkIndicateScriptPathLast();
break;
case "ckPayStatus":
if (null == standardPath || standardPath.isEmpty()) {
standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode()
+ File.separator + "Checkout_Pay_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql";
}
standardPath = form.getCkPayScriptPathStandard();
lastPath = form.getCkPayScriptPathLast();
break;
default:
map.put("err", "请选择脚本类型!");
break;
}
if (map.containsKey("err_opt")) {
return map;
}
switch (opt) {
// 删除 最新的 脚本 (审核-保留)
case "delete":
fileDelete(lastPath);
break;
// 最新脚本 替换 标准脚本(即 以最新脚本为准 (归档或审核-替换)
case "replace":
FileOperateHelper.fileReWrite(standardPath, fileReader(lastPath));
fileDelete(lastPath);
break;
//新增 标准的脚本(注意 造出 对应的 standardPath standardPath不能 = null '')(上传)
case "add":
FileOperateHelper.fileReWrite(standardPath,content);
break;
// (查看)
case "read":
map = readSql(type, form);
break;
default:
map.put("err", "请选择操作选项!");
break;
}
return map;
}
/** /**
* @param map * @param map
* @param code * @param code
* @param data * @param data
* @return * @return
*/ */
private Map<String, List<Object>> putSystemByAreaCode(Map<String, List<Object>> map,String code, PreDataInfo data) { private Map<String, List<Object>> putSystemByAreaCode(
Map<String, List<Object>> map, String code, PreDataInfo data) {
List<Object> list = map.get(code); List<Object> list = map.get(code);
if (null == list) { if (null == list) {
list = new ArrayList<Object>(); list = new ArrayList<Object>();
@ -128,22 +245,24 @@ public class ScriptMakeService implements IScriptMakeService {
return map; return map;
} }
/** /**
*
*
* @param ps * @param ps
* @param path * @param path
* @return * @return
*/ */
private Map<String, String> getAllFile(Map<String, String> ps, String path){ public Map<String, String> getAllFile(Map<String, String> ps, String path) {
File f = new File(path); File f = new File(path);
String name = f.getName(); String name = f.getName();
//如果是 sql文件 // 如果是 sql文件
if(name.endsWith(".sql") || name.endsWith(".SQL")) if (name.endsWith(".sql") || name.endsWith(".SQL"))
ps.put(name.toLowerCase(),f.getAbsolutePath()); ps.put(name.toLowerCase(), f.getAbsolutePath());
if (f.exists()) { if (f.exists()) {
String[] subpaths = f.list(); String[] subpaths = f.list();
if (null != subpaths) { if (null != subpaths) {
for (String tmppath : subpaths) { for (String tmppath : subpaths) {
getAllFile(ps, f.getAbsolutePath()+"/"+tmppath); getAllFile(ps, f.getAbsolutePath() + "/" + tmppath);
} }
} }
} }
@ -151,39 +270,60 @@ public class ScriptMakeService implements IScriptMakeService {
} }
/** /**
* @param systemDataInfo * @param systemDataInfo
* @param sqlFilePathsStandard - *
* @param sqlFilePathsLast * @param sqlFilePathsStandard
* -
* @param sqlFilePathsLast
*
* @return * @return
*/ */
private List<MyFilesEntity> setScript(List<PreDataInfo> systemDataInfo, Map<String, String> sqlFilePathsStandard, Map<String, String> sqlFilePathsLast){ private List<MyFilesEntity> setScript(List<PreDataInfo> systemDataInfo,
Map<String, String> sqlFilePathsStandard,
Map<String, String> sqlFilePathsLast) {
List<MyFilesEntity> fileEntitys = new ArrayList<MyFilesEntity>(); List<MyFilesEntity> fileEntitys = new ArrayList<MyFilesEntity>();
for (PreDataInfo preDataInfo : systemDataInfo) { for (PreDataInfo preDataInfo : systemDataInfo) {
MyFilesEntity myfile = new MyFilesEntity(); MyFilesEntity myfile = new MyFilesEntity();
//复制 // 复制
BeanCopy.copyBean(preDataInfo, myfile); BeanCopy.copyBean(preDataInfo, myfile);
// 归档表空间脚本的位置- // 归档表空间脚本的位置-
String TablePathStandard = getFilePath("UserTablespace_", sqlFilePathsStandard, myfile, ".sql"); String TablePathStandard = getFilePath("UserTablespace_",
sqlFilePathsStandard, myfile, ".sql");
myfile.setUserTableScriptPathStandard(TablePathStandard); myfile.setUserTableScriptPathStandard(TablePathStandard);
// 归档预算 脚本的位置- // 归档预算 脚本的位置-
String indicatePathStandard = getFilePath("Checkout_Indicate_", sqlFilePathsStandard, myfile, ".sql"); String indicatePathStandard = getFilePath("Checkout_Indicate_",
sqlFilePathsStandard, myfile, ".sql");
myfile.setCkIndicateScriptPathStandard(indicatePathStandard); myfile.setCkIndicateScriptPathStandard(indicatePathStandard);
// 归档表空间脚本的位置- // 归档表空间脚本的位置-
String payPathStandard = getFilePath("Checkout_Pay_", sqlFilePathsStandard, myfile, ".sql"); String payPathStandard = getFilePath("Checkout_Pay_",
sqlFilePathsStandard, myfile, ".sql");
myfile.setCkPayScriptPathStandard(payPathStandard); myfile.setCkPayScriptPathStandard(payPathStandard);
// 最新表空间脚本的位置- // 最新表空间脚本的位置-
String TablePathLast = getFilePath("UserTablespace_", sqlFilePathsLast, myfile, ".sql"); String TablePathLast = getFilePath("UserTablespace_",
sqlFilePathsLast, myfile, ".sql");
myfile.setUserTableScriptPathLast(TablePathLast); myfile.setUserTableScriptPathLast(TablePathLast);
// 最新预算 脚本的位置- // 最新预算 脚本的位置-
String indicatePathLast = getFilePath("Checkout_Indicate_", sqlFilePathsLast, myfile, ".sql"); String indicatePathLast = getFilePath("Checkout_Indicate_",
sqlFilePathsLast, myfile, ".sql");
myfile.setCkIndicateScriptPathLast(indicatePathLast); myfile.setCkIndicateScriptPathLast(indicatePathLast);
// 最新表空间脚本的位置- // 最新表空间脚本的位置-
String payPathLast = getFilePath("Checkout_Pay_", sqlFilePathsLast, myfile, ".sql"); String payPathLast = getFilePath("Checkout_Pay_", sqlFilePathsLast,
myfile, ".sql");
myfile.setCkPayScriptPathLast(payPathLast); myfile.setCkPayScriptPathLast(payPathLast);
//设置 状态 // 设置 状态
myfile.setUserTableStatus(getStatus(myfile.getUserTableScriptPathStandard(), myfile.getUserTableScriptPathLast())); if ("ORACLE".equals(myfile.getDataBaseType().toUpperCase())) {
myfile.setCkIndicateStatus(getStatus(myfile.getCkIndicateScriptPathStandard(), myfile.getCkIndicateScriptPathLast())); myfile.setUserTableStatus(getStatus(
myfile.setCkPayStatus(getStatus(myfile.getCkPayScriptPathStandard(), myfile.getCkPayScriptPathLast())); myfile.getUserTableScriptPathStandard(),
myfile.getUserTableScriptPathLast()));
} else {
myfile.setUserTableStatus(4);
}
myfile.setCkIndicateStatus(getStatus(
myfile.getCkIndicateScriptPathStandard(),
myfile.getCkIndicateScriptPathLast()));
myfile.setCkPayStatus(getStatus(
myfile.getCkPayScriptPathStandard(),
myfile.getCkPayScriptPathLast()));
myfile.setSysStatus(getTotalStatus(myfile)); myfile.setSysStatus(getTotalStatus(myfile));
fileEntitys.add(myfile); fileEntitys.add(myfile);
} }
@ -192,27 +332,34 @@ public class ScriptMakeService implements IScriptMakeService {
return fileEntitys; return fileEntitys;
} }
/** /**
*
*
* @param prefix * @param prefix
* @param map * @param map
* @param myf * @param myf
* @param affix * @param affix
* @return * @return
*/ */
private String getFilePath(String prefix, Map<String, String> map, MyFilesEntity myf, String affix) { private String getFilePath(String prefix, Map<String, String> map,
MyFilesEntity myf, String affix) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(prefix).append(myf.getAreaCode().toLowerCase()).append("_").append(myf.getSysCode()).append(affix.toLowerCase()); sb.append(prefix).append(myf.getAreaCode()).append("_")
.append(myf.getSysCode()).append(affix);
String fileName = sb.toString().toLowerCase(); String fileName = sb.toString().toLowerCase();
if (!map.keySet().contains(fileName)) { if (!map.containsKey(fileName)) {
return null; return null;
} }
// 地区字母 小写 -- 文件属性小写 // 地区字母 小写 -- 文件属性小写
String pathStandard = map.get(fileName); String pathStandard = map.get(fileName);
return pathStandard; return pathStandard;
} }
/** --0 standard, last 1standardlast 2standardlast3standardlast /**
* 0 1 2 3 * --0 standard, last 1standardlast
* 2standardlast3standardlast 0 1
* 2 3
*
* @param standard * @param standard
* @param last * @param last
* @return * @return
@ -228,8 +375,9 @@ public class ScriptMakeService implements IScriptMakeService {
return status; return status;
} }
/** /**
* 0 1 2 3 * 0 1 2 3
*
* @param standard * @param standard
* @param last * @param last
* @return * @return
@ -256,4 +404,41 @@ public class ScriptMakeService implements IScriptMakeService {
return result; return result;
} }
private static String fileReader(String path) {
StringBuffer sb = new StringBuffer();
String tempString = "";
if (null == path || "".equals(path)) {
return sb.toString();
}
try {
File file = new File(path);
if (!file.exists())
return null;
FileInputStream fis = new FileInputStream(file);
@SuppressWarnings("resource")
BufferedReader br = new BufferedReader(new InputStreamReader(fis,
"UTF-8"));
while ((tempString = br.readLine()) != null) {
sb.append(tempString).append("\r\n");
}
} catch (Exception e) {
log.error(e.getStackTrace());
}
return sb.toString();
}
private static int fileDelete(String path) {
if (null == path || "".equals(path)) {
return -1;
}
File file = new File(path);
if (!file.exists())
return -1;
if (!file.delete()) {
ArrayList<String> arr = new ArrayList<String>();
arr.add(path);
new ThreadRemoveFile(arr).start();
}
return 1;
}
} }

@ -8,8 +8,10 @@ import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.platform.controller.FilePackageController;
import com.platform.dao.VolumeDao; import com.platform.dao.VolumeDao;
import com.platform.entities.Brick; import com.platform.entities.Brick;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
@ -17,10 +19,13 @@ import com.platform.entities.VolumeInitEntity;
import com.platform.glusterfs.SetVolume; import com.platform.glusterfs.SetVolume;
import com.platform.service.IGfsService; import com.platform.service.IGfsService;
import com.platform.service.IVolumeService; import com.platform.service.IVolumeService;
import com.platform.utils.Configs;
@Service(value = "volumeService") @Service(value = "volumeService")
public class VolumeServiceImpl implements IVolumeService { public class VolumeServiceImpl implements IVolumeService {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(VolumeServiceImpl.class);
/** gfs的api */ /** gfs的api */
SetVolume volumeService = new SetVolume(); SetVolume volumeService = new SetVolume();

@ -58,7 +58,7 @@ public class Configs {
public static String PACKAGE_NAME=""; public static String PACKAGE_NAME="";
public static String SQL_SCRIPT_PATH_LAST=""; public static String SQL_SCRIPT_PATH_LAST="D:\\test\\sql_script_last\\";
public static String SQL_SCRIPT_PATH_STANDARD=""; public static String SQL_SCRIPT_PATH_STANDARD="D:\\test\\sql_script_standard\\";
} }

@ -9,6 +9,8 @@ import java.io.InputStreamReader;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.log4j.Logger;
/** /**
* *
* *
@ -17,6 +19,8 @@ import java.util.regex.Pattern;
*/ */
public class FileOperateHelper { public class FileOperateHelper {
private static Logger log = Configs.CONSOLE_LOGGER.getLogger(FileOperateHelper.class);
/** /**
* *
* *
@ -28,16 +32,50 @@ public class FileOperateHelper {
if (null == path || "".equals(path)) { if (null == path || "".equals(path)) {
return; return;
} }
try {
File file = new File(path);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream out = new FileOutputStream(file, true); // 如果追加方式用true
StringBuffer sb = new StringBuffer();
sb.append(message);
out.write(sb.toString().getBytes("utf-8"));
} catch (IOException e) {
log.error(e.getStackTrace());
}
}
/**
*
*
* @param path
* @param message
*/
public static void fileReWrite(String path, String message) {
if (null == path || "".equals(path)) {
return;
}
FileOutputStream out = null;
try { try {
File file = new File(path); File file = new File(path);
file.delete(); file.delete();
file.createNewFile(); file.createNewFile();
FileOutputStream out = new FileOutputStream(file, true); // 如果追加方式用true out = new FileOutputStream(file, true); // 如果追加方式用true
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(message); sb.append(message);
out.write(sb.toString().getBytes("utf-8")); out.write(sb.toString().getBytes("utf-8"));
} catch (IOException e) { } catch (IOException e) {
// TODO: handle exception log.error(e.getStackTrace());
}
finally{
if (null != out) {
try {
out.close();
} catch (IOException e) {
log.error(e.getStackTrace());
}
}
} }
} }
@ -50,17 +88,27 @@ public class FileOperateHelper {
public static String fileReader(String path) { public static String fileReader(String path) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String tempString = ""; String tempString = "";
FileInputStream fis = null;
try { try {
File file = new File(path); File file = new File(path);
if (!file.exists()) if (!file.exists())
return "当前没有日志信息!"; return "当前没有信息!";
FileInputStream fis = new FileInputStream(file); fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis,"UTF-8")); BufferedReader br = new BufferedReader(new InputStreamReader(fis,"UTF-8"));
while ((tempString = br.readLine()) != null) { while ((tempString = br.readLine()) != null) {
sb.append(tempString).append("\r\n"); sb.append(tempString).append("\r\n");
} }
} catch (Exception e) { } catch (Exception e) {
Configs.CONSOLE_LOGGER.info(e.getMessage()); log.error(e.getStackTrace());
}
finally{
if (null != fis) {
try {
fis.close();
} catch (IOException e) {
log.error(e.getStackTrace());
}
}
} }
return sb.toString(); return sb.toString();
} }
@ -76,35 +124,43 @@ public class FileOperateHelper {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String tempString = ""; String tempString = "";
FileInputStream fis = null;
try { try {
File file = new File(path); File file = new File(path);
if (!file.exists()) if (!file.exists())
return ""; return "";
fis = new FileInputStream(file);
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis)); BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((tempString = br.readLine()) != null) { while ((tempString = br.readLine()) != null) {
sb.append(tempString+"\n"); sb.append(tempString+"\n");
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception log.error(e.getStackTrace());
}
finally{
if (null != fis) {
try {
fis.close();
} catch (IOException e) {
log.error(e.getStackTrace());
}
}
} }
return sb.toString(); return sb.toString();
} }
public static String addLastSeparator(String path){ public static String addLastSeparator(String path){
// 末尾 含有 / //去掉 File.separator
Pattern pattern2 = Pattern.compile(File.separator+"$"); path = removeLastSeparator(path);
Matcher matcher2 = pattern2.matcher(path); // 末尾 加上 /
if (!matcher2.find()) { path = path + File.separator;
path = path + File.separator;
}
return path; return path;
} }
public static String removeLastSeparator(String path){ public static String removeLastSeparator(String path){
// 末尾 含有 / // 递归去掉 所有 结尾 /
if (path.length() < 1) { if (path.length() < 1) {
return path; return path;
} }
@ -112,6 +168,7 @@ public class FileOperateHelper {
Matcher matcher2 = pattern2.matcher(path); Matcher matcher2 = pattern2.matcher(path);
if (matcher2.find()) { if (matcher2.find()) {
path = path.substring(0, path.length()-1); path = path.substring(0, path.length()-1);
path = removeLastSeparator(path);
} }
return path; return path;
} }

@ -4,12 +4,19 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger;
import com.platform.controller.FilePackageController;
/** /**
* @author chen * @author chen
* *
*/ */
public class ThreadRemoveFile extends Thread { public class ThreadRemoveFile extends Thread {
@SuppressWarnings("static-access")
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(FilePackageController.class);
private List<String> path4Delete = new ArrayList<String>(); private List<String> path4Delete = new ArrayList<String>();
public ThreadRemoveFile(List<String> paths) { public ThreadRemoveFile(List<String> paths) {
@ -19,6 +26,11 @@ public class ThreadRemoveFile extends Thread {
@Override @Override
public void run() { public void run() {
while (true) { while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error(e.getStackTrace());
}
List<String> tmpPathArr = new ArrayList<String>(); List<String> tmpPathArr = new ArrayList<String>();
if (null != path4Delete && path4Delete.size() > 0) { if (null != path4Delete && path4Delete.size() > 0) {
for (String path : path4Delete) { for (String path : path4Delete) {
@ -34,10 +46,6 @@ public class ThreadRemoveFile extends Thread {
break; break;
} }
path4Delete = tmpPathArr; path4Delete = tmpPathArr;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
} }
} }

@ -6,10 +6,12 @@ import java.util.Map;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.base.Custom4exception; import com.base.Custom4exception;
import com.base.CustomException; import com.base.CustomException;
import com.platform.controller.FilePackageController;
import com.platform.entities.Brick; import com.platform.entities.Brick;
import com.platform.entities.FolderNode; import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
@ -20,6 +22,9 @@ import com.platform.http.gfs.HttpUtils;
public class ThreadVolume extends Thread { public class ThreadVolume extends Thread {
@SuppressWarnings("static-access")
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(ThreadVolume.class);
/** /**
* -- * --
*/ */
@ -34,7 +39,6 @@ public class ThreadVolume extends Thread {
private GetTreeData gfsTree = new GetTreeData(); private GetTreeData gfsTree = new GetTreeData();
public ThreadVolume() { public ThreadVolume() {
// TODO Auto-generated constructor stub
} }
public ThreadVolume(String name) { public ThreadVolume(String name) {
@ -77,7 +81,12 @@ public class ThreadVolume extends Thread {
HttpUtils ht = new HttpUtils(); HttpUtils ht = new HttpUtils();
String rest = ht.sendPost("gfs/getAllvolume", null); String rest = ht.sendPost("gfs/getAllvolume", null);
// JSONArray jsondata = JSONArray.fromObject(volumeList); // JSONArray jsondata = JSONArray.fromObject(volumeList);
if (null == rest || "".equals(rest)) {
log.error(" --- gluster is disconnect ! \n");
return;
}
JSONArray json = JSONArray.fromObject(rest); JSONArray json = JSONArray.fromObject(rest);
@SuppressWarnings("unchecked")
List<VolumeEntity> volumes = (List<VolumeEntity>)JSONArray.toCollection(json, VolumeEntity.class); List<VolumeEntity> volumes = (List<VolumeEntity>)JSONArray.toCollection(json, VolumeEntity.class);
for (VolumeEntity volumeEntity : volumes) { for (VolumeEntity volumeEntity : volumes) {
if (null != volumeEntity.getFolder()) { if (null != volumeEntity.getFolder()) {

Loading…
Cancel
Save