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

web_backend_develope
chenlw 10 years ago
parent 8616a39ff8
commit ee5acfa3e0

@ -24,7 +24,8 @@ import com.platform.utils.Constant;
public class CustomException extends Exception {
/** 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;

@ -53,7 +53,7 @@ import com.platform.utils.UtilsHelper;
@Controller
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")
private DataInfoService dfs;

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

@ -2,24 +2,29 @@ package com.platform.controller;
import java.io.File;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
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.RequestBody;
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 com.base.BaseController;
import com.platform.entities.MyFilesEntity;
import com.platform.entities.PreDataInfo;
import com.platform.form.ScriptForm;
import com.platform.service.IScriptMakeService;
import com.platform.utils.Configs;
import com.platform.utils.ZipCompressUtils;
@ -28,12 +33,16 @@ import com.platform.utils.ZipCompressUtils;
@RequestMapping("/filePackage")
public class FilePackageController extends BaseController {
@SuppressWarnings("static-access")
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(FilePackageController.class);
@Resource(name = "scriptMakeService")
private IScriptMakeService scriptMakeService;
@RequestMapping("/download")
public ResponseEntity<byte[]> downloadFile(HttpServletRequest request,
HttpServletResponse response) throws Exception {
log.info("---------/download--- ");
scriptMakeService.makeCfg();
scriptMakeService.makeXml();
String filePath = Configs.PACKAGE_DOWNLOAD_PATH;
@ -61,10 +70,40 @@ public class FilePackageController extends BaseController {
@ResponseBody
@RequestMapping("/findAll")
public ModelMap findAll() throws Exception {
log.info("---------/findAll--- ");
ModelMap modelMap = new ModelMap();
List<MyFilesEntity> result = scriptMakeService.FindAllFiles();
modelMap.addAttribute("data", result);
modelMap.addAttribute("length", result.size());
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 org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
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.CustomException;
import com.platform.entities.GfsFolderEntity;
@ -23,11 +25,10 @@ import com.platform.entities.GfsFolderEntity;
import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.VolumeInfo;
import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.VolumeInfo;
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 static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(FolderController.class);
@Resource(name = "gfsService")
private IGfsService gfsService;

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

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

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

@ -24,8 +24,8 @@ import com.platform.utils.ThreadVolumeImm;
@Controller
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")
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.message.BasicNameValuePair;
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.Configs;
public class HttpUtils {
public static Logger log = Configs.DAILY_ROLLING_LOGGER.getLogger(HttpUtils.class);
public String sendPost(String subUrl, Object data) {
String resultStr = null;
String resultStr = "";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(HttpClientConstant.URL_IP_PORT + subUrl);
try {

@ -1,6 +1,7 @@
package com.platform.service;
import java.util.List;
import java.util.Map;
import com.platform.entities.MyFilesEntity;
@ -13,5 +14,16 @@ public interface IScriptMakeService {
public int moveFiles(List<MyFilesEntity> file) 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) {
e.printStackTrace();
}
finally{
if (null != workbook) {
workbook.close();
}
}
}
if (errFile.size() > 0) {
@ -328,17 +333,28 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
| IllegalAccessException | IOException e) {
errList.add(e.getMessage());
}
finally{
if (null != workbook) {
workbook.close();
}
}
FileOutputStream fileOut = null;
try {
File f = new File(path);
FileOutputStream fileOut = null;
f.createNewFile();
fileOut = new FileOutputStream(f);
result.write(fileOut);
fileOut.close();
} catch (IOException e) {
errList.add(e.getMessage());
}
map.put("err", errList);
finally{
if (null != fileOut) {
fileOut.close();
}
}
if (errList.size() > 0) {
map.put("err", errList);
}
return map;
}

File diff suppressed because it is too large Load Diff

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

@ -58,7 +58,7 @@ public class Configs {
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.Pattern;
import org.apache.log4j.Logger;
/**
*
*
@ -16,6 +18,8 @@ import java.util.regex.Pattern;
*
*/
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)) {
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 {
File file = new File(path);
file.delete();
file.createNewFile();
FileOutputStream out = new FileOutputStream(file, true); // 如果追加方式用true
out = new FileOutputStream(file, true); // 如果追加方式用true
StringBuffer sb = new StringBuffer();
sb.append(message);
out.write(sb.toString().getBytes("utf-8"));
} 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) {
StringBuffer sb = new StringBuffer();
String tempString = "";
FileInputStream fis = null;
try {
File file = new File(path);
if (!file.exists())
return "当前没有日志信息!";
FileInputStream fis = new FileInputStream(file);
return "当前没有信息!";
fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis,"UTF-8"));
while ((tempString = br.readLine()) != null) {
sb.append(tempString).append("\r\n");
}
} 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();
}
@ -76,35 +124,43 @@ public class FileOperateHelper {
StringBuffer sb = new StringBuffer();
String tempString = "";
FileInputStream fis = null;
try {
File file = new File(path);
if (!file.exists())
return "";
FileInputStream fis = new FileInputStream(file);
fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((tempString = br.readLine()) != null) {
sb.append(tempString+"\n");
}
} 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();
}
public static String addLastSeparator(String path){
// 末尾 含有 /
Pattern pattern2 = Pattern.compile(File.separator+"$");
Matcher matcher2 = pattern2.matcher(path);
if (!matcher2.find()) {
path = path + File.separator;
}
//去掉 File.separator
path = removeLastSeparator(path);
// 末尾 加上 /
path = path + File.separator;
return path;
}
public static String removeLastSeparator(String path){
// 末尾 含有 /
// 递归去掉 所有 结尾 /
if (path.length() < 1) {
return path;
}
@ -112,6 +168,7 @@ public class FileOperateHelper {
Matcher matcher2 = pattern2.matcher(path);
if (matcher2.find()) {
path = path.substring(0, path.length()-1);
path = removeLastSeparator(path);
}
return path;
}

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

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

Loading…
Cancel
Save