修复遇到的bug

web_backend_develope
chenlw 9 years ago
parent bc310b9432
commit 7901443ff3

@ -252,15 +252,18 @@ public class ExcelController extends BaseController{
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);
modelMap.addAttribute("returncode","3001"); modelMap.addAttribute("code","3001");
response.setStatus(500);
} }
//成功
else { else {
List<PreDataInfo> datalist = preDataInfoService.findAll(); List<PreDataInfo> datalist = preDataInfoService.findAll();
modelMap.addAttribute("data", datalist); modelMap.addAttribute("data", datalist);
modelMap.addAttribute("length", datalist.size()); modelMap.addAttribute("length", datalist.size());
modelMap.addAttribute("returncode","1001"); modelMap.addAttribute("code","1001");
} }
//删除文件 //删除文件
List<String> failedDelete = new ArrayList<String>(); List<String> failedDelete = new ArrayList<String>();

@ -23,7 +23,7 @@ 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.SqlFileInfoEntity;
import com.platform.form.ScriptForm; 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;
@ -66,21 +66,34 @@ public class FilePackageController extends BaseController {
return null; return null;
} }
} }
/**
*
* @return
* @throws Exception
*/
@ResponseBody @ResponseBody
@RequestMapping("/findAll") @RequestMapping("/findAll")
public ModelMap findAll() throws Exception { public ModelMap findAll() throws Exception {
log.info("---------/findAll--- "); log.info("---------/findAll--- ");
ModelMap modelMap = new ModelMap(); ModelMap modelMap = new ModelMap();
List<MyFilesEntity> result = scriptMakeService.FindAllFiles(); List<SqlFileInfoEntity> 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;
} }
/**
*
* @param type
* @param data
* @param res
* @param req
* @return
* @throws Exception
*/
@RequestMapping(value = "/readSqlFile", method = RequestMethod.POST) @RequestMapping(value = "/readSqlFile", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Object getSqlFile(/*@PathVariable*/@RequestParam("type") String type, @RequestBody MyFilesEntity data, public Object getSqlFile(/*@PathVariable*/@RequestParam("type") String type, @RequestBody SqlFileInfoEntity data,
HttpServletRequest res, HttpServletResponse req) throws Exception { HttpServletRequest res, HttpServletResponse req) throws Exception {
log.info("---------/readSqlFile------------------"); log.info("---------/readSqlFile------------------");
ModelMap modelMap = new ModelMap(); ModelMap modelMap = new ModelMap();
@ -93,6 +106,16 @@ public class FilePackageController extends BaseController {
return modelMap; return modelMap;
} }
/**
*
* @param type
* @param opt
* @param form
* @param req
* @param res
* @return
* @throws Exception
*/
@RequestMapping(value = "/handleSqlFile", method = RequestMethod.POST) @RequestMapping(value = "/handleSqlFile", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public ModelMap handleSqlFile(@RequestParam("type") String type, @RequestParam("opt") String opt, @RequestBody ScriptForm form, public ModelMap handleSqlFile(@RequestParam("type") String type, @RequestParam("opt") String opt, @RequestBody ScriptForm form,
@ -101,7 +124,7 @@ public class FilePackageController extends BaseController {
ModelMap modelMap = new ModelMap(); ModelMap modelMap = new ModelMap();
Map<String, Object> result = scriptMakeService.handleSqlFile(type, opt, form.getContent(), form.getItem()); Map<String, Object> result = scriptMakeService.handleSqlFile(type, opt, form.getContent(), form.getItem());
modelMap.addAllAttributes(result); modelMap.addAllAttributes(result);
List<MyFilesEntity> results = scriptMakeService.FindAllFiles(); List<SqlFileInfoEntity> results = scriptMakeService.FindAllFiles();
modelMap.addAttribute("data", results); modelMap.addAttribute("data", results);
modelMap.addAttribute("length", results.size()); modelMap.addAttribute("length", results.size());
return modelMap; return modelMap;

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

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

@ -4,7 +4,6 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -13,25 +12,22 @@ import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.platform.utils.BeanCopy;
import com.platform.utils.Configs;
import com.platform.utils.Constant;
import com.platform.utils.DateForm;
import com.platform.controller.ExcelController;
import com.platform.dao.IRegionalismCodeDao; import com.platform.dao.IRegionalismCodeDao;
import com.platform.dao.ISystemCodeDao; import com.platform.dao.ISystemCodeDao;
import com.platform.dao.PreDataInfoDao; import com.platform.dao.PreDataInfoDao;
import com.platform.dao.VolumeDao;
import com.platform.entities.PagerOptions; import com.platform.entities.PagerOptions;
import com.platform.entities.PreDataInfo; import com.platform.entities.PreDataInfo;
import com.platform.entities.RegionalismEntity; import com.platform.entities.RegionalismEntity;
import com.platform.entities.SystemEntity; import com.platform.entities.SystemEntity;
import com.platform.service.IPreDataInfoService; import com.platform.service.IPreDataInfoService;
import com.platform.utils.BeanCopy;
import com.platform.utils.Configs;
import com.platform.utils.Constant;
import com.platform.utils.DateForm;
import com.platform.utils.excelUtils.ExcelOperation; import com.platform.utils.excelUtils.ExcelOperation;
@Service(value = "preDataInfoService") @Service(value = "preDataInfoService")
@ -51,12 +47,23 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
@Override @Override
public List<PreDataInfo> findAll() throws Exception { public List<PreDataInfo> findAll() throws Exception {
List<PreDataInfo> result = preDataInfoDao.findAll(); List<PreDataInfo> result = preDataInfoDao.findAll();
Map<String, String> sqlFilePathsStandard = new HashMap<String, String>();
sqlFilePathsStandard = getAllFile(sqlFilePathsStandard,
Configs.SQL_SCRIPT_PATH_STANDARD);
setScript(result, sqlFilePathsStandard);
for (PreDataInfo preDataInfo : result) { for (PreDataInfo preDataInfo : result) {
preDataInfo.setWorkRange(new ArrayList<String>()); preDataInfo.setWorkRange(new ArrayList<String>());
preDataInfo.setSqlList(new ArrayList<String>());
} }
return result; return result;
} }
@Override
public List<PreDataInfo> findByParam(PagerOptions op) {
List<PreDataInfo> result = preDataInfoDao.getLimitedDataInfoEntities(op);
return result;
}
@Override @Override
public Map<String, List> importExcel(List<String> paths) throws Exception { public Map<String, List> importExcel(List<String> paths) throws Exception {
Map<String, List> errmap = new HashMap<String, List>(); Map<String, List> errmap = new HashMap<String, List>();
@ -97,8 +104,9 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
} }
//Excel导入 //Excel导入
try { try {
PreDataInfo pre = new PreDataInfo();
//excel数据 --> java bean //excel数据 --> java bean
List<PreDataInfo> subPreData = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, PreDataInfo.class, "id", "workRange","sysCode","updateTime"); List<PreDataInfo> subPreData = ExcelOperation.readExcel4Update(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, pre, "id", "workRange","sysCode","updateTime","userTablespaceStatus", "checkoutIndicateStatus", "checkoutPayStatus", "userTablespacePath", "checkoutIndicatePath", "checkoutPayPath", "sqlList");
if (null != subPreData && subPreData.size() > 0) { if (null != subPreData && subPreData.size() > 0) {
//是否是 同一个县区的 系统--是则 加入 //是否是 同一个县区的 系统--是则 加入
boolean isSameArea = true; boolean isSameArea = true;
@ -118,11 +126,11 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
| IllegalAccessException | InstantiationException e) { | IllegalAccessException | InstantiationException e) {
e.printStackTrace(); e.printStackTrace();
} }
finally{ // finally{
if (null != workbook) { // if (null != workbook) {
workbook.close(); // workbook.close();
} // }
} // }
} }
if (errFile.size() > 0) { if (errFile.size() > 0) {
@ -164,14 +172,14 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
if (sysNames.size() > 0) { if (sysNames.size() > 0) {
listSystem = systemCodeDao.findByName(sysNames); listSystem = systemCodeDao.findByName(sysNames);
} }
Map<String, Object> syscodeMap = new HashMap<String, Object>(); Map<String, Integer> syscodeMap = new HashMap<String, Integer>();
for (SystemEntity systemEntity : listSystem) { for (SystemEntity systemEntity : listSystem) {
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode())); syscodeMap.put(systemEntity.getSystemName(), systemEntity.getCode());
} }
for ( PreDataInfo systemEntity : list4AddSystem) { for ( PreDataInfo systemEntity : list4AddSystem) {
PreDataInfo systemFull = new PreDataInfo(); PreDataInfo systemFull = new PreDataInfo();
BeanCopy.copyBean(systemEntity, systemFull); BeanCopy.copyBean(systemEntity, systemFull);
systemFull.setSysCode((int) syscodeMap.get(systemFull.getSysName())); systemFull.setSysCode(syscodeMap.get(systemFull.getSysName()));
systemFull.setUpdateTime(DateForm.date2StringBysecond(new Date())); systemFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
all2Insert.add(systemFull); all2Insert.add(systemFull);
} }
@ -196,14 +204,14 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
if (sysNamesArea.size() > 0) { if (sysNamesArea.size() > 0) {
listSystem = systemCodeDao.findByName(sysNamesArea); listSystem = systemCodeDao.findByName(sysNamesArea);
} }
Map<String, Object> syscodeMap = new HashMap<String, Object>(); Map<String, Integer> syscodeMap = new HashMap<String, Integer>();
for (SystemEntity systemEntity : listSystem) { for (SystemEntity systemEntity : listSystem) {
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode())); syscodeMap.put(systemEntity.getSystemName(), systemEntity.getCode());
} }
for (PreDataInfo preDataInfo : list4AddArea) { for (PreDataInfo preDataInfo : list4AddArea) {
PreDataInfo areaFull = new PreDataInfo(); PreDataInfo areaFull = new PreDataInfo();
BeanCopy.copyBean(preDataInfo, areaFull); BeanCopy.copyBean(preDataInfo, areaFull);
areaFull.setSysCode((int) syscodeMap.get(areaFull.getSysName())); areaFull.setSysCode(syscodeMap.get(areaFull.getSysName()));
areaFull.setUpdateTime(DateForm.date2StringBysecond(new Date())); areaFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
allAreaInsert.add(areaFull); allAreaInsert.add(areaFull);
} }
@ -226,12 +234,13 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
listSystem4Update = systemCodeDao.findByName(sysNamesArea); listSystem4Update = systemCodeDao.findByName(sysNamesArea);
} }
for (SystemEntity systemEntity : listSystem4Update) { for (SystemEntity systemEntity : listSystem4Update) {
syscodeMap.put(systemEntity.getSystemName(), String.valueOf(systemEntity.getCode())); syscodeMap.put(systemEntity.getSystemName(), systemEntity.getCode());
} }
for (PreDataInfo preUpdate : list4Update) { for (PreDataInfo preUpdate : list4Update) {
PreDataInfo UpdateFull = new PreDataInfo(); PreDataInfo UpdateFull = new PreDataInfo();
BeanCopy.copyBean(preUpdate, UpdateFull); BeanCopy.copyBean(preUpdate, UpdateFull);
UpdateFull.setSysCode((int) syscodeMap.get(UpdateFull.getSysName()));
UpdateFull.setSysCode(syscodeMap.get(UpdateFull.getSysName()));
UpdateFull.setUpdateTime(DateForm.date2StringBysecond(new Date())); UpdateFull.setUpdateTime(DateForm.date2StringBysecond(new Date()));
allUpdate.add(UpdateFull); allUpdate.add(UpdateFull);
} }
@ -242,6 +251,45 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
return errmap; return errmap;
} }
@Override
public Map<String, List> exportExcel(String path) throws Exception {
Map<String, List> map = new HashMap<String, List>();
List<String> errList = new ArrayList<String>();
List<PreDataInfo> list = findAll();
// InputStreamReader in= new InputStreamReader(Resource.class.getResourceAsStream(templateFilePath), "UTF-8");
ClassPathResource res = new ClassPathResource(Constant.SYSTEM_INFO_EXCEL_TEMPLATE_FIEL_PATH);
//此处 耗时太久原因excel 2007 以后采用的方式不同造成的建议升级 到 poi 3.15以上)
XSSFWorkbook workbook = null;
XSSFWorkbook result = null;
try {
workbook = new XSSFWorkbook(res.getInputStream());
result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list, "id", "workRange","sysCode","updateTime","userTablespaceStatus", "checkoutIndicateStatus", "checkoutPayStatus", "userTablespacePath", "checkoutIndicatePath", "checkoutPayPath", "sqlList");
} catch (IllegalArgumentException
| IllegalAccessException | IOException e) {
errList.add(e.getMessage());
}
//不能进行close,
// workbook.close();
FileOutputStream fileOut = null;
try {
File f = new File(path);
f.createNewFile();
fileOut = new FileOutputStream(f);
result.write(fileOut);
} catch (IOException e) {
errList.add(e.getMessage());
}
finally{
if (null != fileOut) {
fileOut.close();
}
}
if (errList.size() > 0) {
map.put("err", errList);
}
return map;
}
/** system_info /** system_info
* @param list4AddSystem * @param list4AddSystem
* @return * @return
@ -310,52 +358,90 @@ public class PreDataInfoServiceImpl implements IPreDataInfoService {
} }
@Override /**
public List<PreDataInfo> findByParam(PagerOptions op) { *
List<PreDataInfo> result = preDataInfoDao.getLimitedDataInfoEntities(op); *
return result; * @param ps must not null
* @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;
} }
@Override /**
public Map<String, List> exportExcel(String path) throws Exception { * @param systemDataInfo
Map<String, List> map = new HashMap<String, List>(); * @param sqlFilePathsStandard
List<String> errList = new ArrayList<String>(); * @return
List<PreDataInfo> list = findAll(); */
// InputStreamReader in= new InputStreamReader(Resource.class.getResourceAsStream(templateFilePath), "UTF-8"); private List<PreDataInfo> setScript(List<PreDataInfo> systemDataInfo,
ClassPathResource res = new ClassPathResource(Constant.SYSTEM_INFO_EXCEL_TEMPLATE_FIEL_PATH); Map<String, String> sqlFilePathsStandard) {
//此处 耗时太久原因excel 2007 以后采用的方式不同造成的建议升级 到 poi 3.15以上) List<PreDataInfo> fileEntitys = new ArrayList<PreDataInfo>();
XSSFWorkbook workbook = null; for (PreDataInfo preDataInfo : systemDataInfo) {
XSSFWorkbook result = null; // 归档表空间脚本的位置-
try { String TablePathStandard = getFilePath("UserTablespace_",
workbook = new XSSFWorkbook(res.getInputStream()); sqlFilePathsStandard, preDataInfo, ".sql");
result = ExcelOperation.writeExcelTemplate(workbook, Constant.EXCEL_TEMPLATE_INIT_ROW, 0, 25, list, "id", "workRange","sysCode","updateTime"); if (null != TablePathStandard && !"".equals(TablePathStandard)) {
} catch (IllegalArgumentException preDataInfo.setUserTablespaceStatus("是");
| IllegalAccessException | IOException e) { preDataInfo.setUserTablespacePath("UserTablespace_"+preDataInfo.getAreaCode()+"_" + preDataInfo.getSysCode()+ ".sql");
errList.add(e.getMessage());
}
finally{
if (null != workbook) {
workbook.close();
} }
} // 归档预算 脚本的位置-
FileOutputStream fileOut = null; String indicatePathStandard = getFilePath("Checkout_Indicate_",
try { sqlFilePathsStandard, preDataInfo, ".sql");
File f = new File(path); if (null != indicatePathStandard && !"".equals(indicatePathStandard)) {
f.createNewFile(); preDataInfo.setCheckoutIndicateStatus("是");
fileOut = new FileOutputStream(f); preDataInfo.setCheckoutIndicatePath("Checkout_Indicate_"+preDataInfo.getAreaCode()+"_" + preDataInfo.getSysCode()+ ".sql");
result.write(fileOut);
} catch (IOException e) {
errList.add(e.getMessage());
}
finally{
if (null != fileOut) {
fileOut.close();
} }
// 归档表空间脚本的位置-
String payPathStandard = getFilePath("Checkout_Pay_",
sqlFilePathsStandard, preDataInfo, ".sql");
if (null != payPathStandard && !"".equals(payPathStandard)) {
preDataInfo.setCheckoutIndicateStatus("是");
preDataInfo.setCheckoutIndicatePath("Checkout_Pay_"+preDataInfo.getAreaCode()+"_" + preDataInfo.getSysCode()+ ".sql");
}
// 设置 状态
if (!"ORACLE".equals(preDataInfo.getDataBaseType().toUpperCase())) {
preDataInfo.setUserTablespaceStatus("-");
}
fileEntitys.add(preDataInfo);
} }
if (errList.size() > 0) { return fileEntitys;
map.put("err", errList); }
/**
*
*
* @param prefix
* @param map
* @param myf
* @param affix
* @return
*/
private String getFilePath(String prefix, Map<String, String> map,
PreDataInfo pre, String affix) {
StringBuffer sb = new StringBuffer();
sb.append(prefix).append(pre.getAreaCode()).append("_")
.append(pre.getSysCode()).append(affix);
String fileName = sb.toString().toLowerCase();
if (!map.containsKey(fileName)) {
return null;
} }
return map; // 地区字母 小写 -- 文件属性小写
String pathStandard = map.get(fileName);
return pathStandard;
} }
} }

@ -19,11 +19,11 @@ 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.MyFilesEntity; import com.platform.entities.SqlFileInfoEntity;
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.BeanCopy;
import com.platform.utils.Compare4MyFilesEntity; import com.platform.utils.Compare4SqlFilesEntity;
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;
@ -103,7 +103,7 @@ public class ScriptMakeService implements IScriptMakeService {
} }
@Override @Override
public List<MyFilesEntity> FindAllFiles() throws Exception { public List<SqlFileInfoEntity> 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>();
@ -114,13 +114,13 @@ public class ScriptMakeService implements IScriptMakeService {
sqlFilePathsStandard = getAllFile(sqlFilePathsStandard, sqlFilePathsStandard = getAllFile(sqlFilePathsStandard,
Configs.SQL_SCRIPT_PATH_STANDARD); Configs.SQL_SCRIPT_PATH_STANDARD);
// 填充 脚本状态、位置的信息 // 填充 脚本状态、位置的信息
List<MyFilesEntity> result = setScript(systemDataInfo, List<SqlFileInfoEntity> result = setScript(systemDataInfo,
sqlFilePathsStandard, sqlFilePathsLast); sqlFilePathsStandard, sqlFilePathsLast);
return result; return result;
} }
@Override @Override
public Map<String, Object> readSql(String name, MyFilesEntity form) { public Map<String, Object> readSql(String name, SqlFileInfoEntity form) {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
String path1 = ""; String path1 = "";
String path2 = ""; String path2 = "";
@ -156,13 +156,13 @@ public class ScriptMakeService implements IScriptMakeService {
} }
@Override @Override
public int moveFiles(List<MyFilesEntity> files) throws Exception { public int moveFiles(List<SqlFileInfoEntity> files) throws Exception {
return 0; return 0;
} }
@Override @Override
public Map<String, Object> handleSqlFile(String type, String opt, String content, MyFilesEntity form) { public Map<String, Object> handleSqlFile(String type, String opt, String content, SqlFileInfoEntity form) {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>();
String standardPath = ""; String standardPath = "";
String lastPath = ""; String lastPath = "";
@ -175,25 +175,31 @@ public class ScriptMakeService implements IScriptMakeService {
case "userTableStatus": case "userTableStatus":
standardPath = form.getUserTableScriptPathStandard(); standardPath = form.getUserTableScriptPathStandard();
if (null == standardPath || standardPath.isEmpty()) { if (null == standardPath || standardPath.isEmpty()) {
File file = new File(FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode());
file.mkdir();
standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode() standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode()
+ File.separator + "UserTablespace_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql"; + File.separator + "UserTablespace_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql";
} }
lastPath = form.getUserTableScriptPathLast(); lastPath = form.getUserTableScriptPathLast();
break; break;
case "ckIndicateStatus": case "ckIndicateStatus":
standardPath = form.getCkIndicateScriptPathStandard();
if (null == standardPath || standardPath.isEmpty()) { if (null == standardPath || standardPath.isEmpty()) {
File file = new File(FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode());
file.mkdir();
standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode() standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode()
+ File.separator + "Checkout_Indicate_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql"; + File.separator + "Checkout_Indicate_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql";
} }
standardPath = form.getCkIndicateScriptPathStandard();
lastPath = form.getCkIndicateScriptPathLast(); lastPath = form.getCkIndicateScriptPathLast();
break; break;
case "ckPayStatus": case "ckPayStatus":
standardPath = form.getCkPayScriptPathStandard();
if (null == standardPath || standardPath.isEmpty()) { if (null == standardPath || standardPath.isEmpty()) {
File file = new File(FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode());
file.mkdir();
standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode() standardPath = FileOperateHelper.addLastSeparator(Configs.SQL_SCRIPT_PATH_STANDARD) + form.getAreaCode()
+ File.separator + "Checkout_Pay_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql"; + File.separator + "Checkout_Pay_" + form.getAreaCode() + "_" + form.getSysCode() + ".sql";
} }
standardPath = form.getCkPayScriptPathStandard();
lastPath = form.getCkPayScriptPathLast(); lastPath = form.getCkPayScriptPathLast();
break; break;
default: default:
@ -248,7 +254,7 @@ public class ScriptMakeService implements IScriptMakeService {
/** /**
* *
* *
* @param ps * @param ps must not null
* @param path * @param path
* @return * @return
*/ */
@ -278,12 +284,12 @@ public class ScriptMakeService implements IScriptMakeService {
* *
* @return * @return
*/ */
private List<MyFilesEntity> setScript(List<PreDataInfo> systemDataInfo, private List<SqlFileInfoEntity> setScript(List<PreDataInfo> systemDataInfo,
Map<String, String> sqlFilePathsStandard, Map<String, String> sqlFilePathsStandard,
Map<String, String> sqlFilePathsLast) { Map<String, String> sqlFilePathsLast) {
List<MyFilesEntity> fileEntitys = new ArrayList<MyFilesEntity>(); List<SqlFileInfoEntity> fileEntitys = new ArrayList<SqlFileInfoEntity>();
for (PreDataInfo preDataInfo : systemDataInfo) { for (PreDataInfo preDataInfo : systemDataInfo) {
MyFilesEntity myfile = new MyFilesEntity(); SqlFileInfoEntity myfile = new SqlFileInfoEntity();
// 复制 // 复制
BeanCopy.copyBean(preDataInfo, myfile); BeanCopy.copyBean(preDataInfo, myfile);
// 归档表空间脚本的位置- // 归档表空间脚本的位置-
@ -327,7 +333,7 @@ public class ScriptMakeService implements IScriptMakeService {
myfile.setSysStatus(getTotalStatus(myfile)); myfile.setSysStatus(getTotalStatus(myfile));
fileEntitys.add(myfile); fileEntitys.add(myfile);
} }
Compare4MyFilesEntity com = new Compare4MyFilesEntity(); Compare4SqlFilesEntity com = new Compare4SqlFilesEntity();
Collections.sort(fileEntitys, com); Collections.sort(fileEntitys, com);
return fileEntitys; return fileEntitys;
} }
@ -342,7 +348,7 @@ public class ScriptMakeService implements IScriptMakeService {
* @return * @return
*/ */
private String getFilePath(String prefix, Map<String, String> map, private String getFilePath(String prefix, Map<String, String> map,
MyFilesEntity myf, String affix) { SqlFileInfoEntity myf, String affix) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(prefix).append(myf.getAreaCode()).append("_") sb.append(prefix).append(myf.getAreaCode()).append("_")
.append(myf.getSysCode()).append(affix); .append(myf.getSysCode()).append(affix);
@ -382,12 +388,18 @@ public class ScriptMakeService implements IScriptMakeService {
* @param last * @param last
* @return * @return
*/ */
private int getTotalStatus(MyFilesEntity myfile) { private int getTotalStatus(SqlFileInfoEntity myfile) {
Integer[] numArr = new Integer[3]; Integer[] numArr = null;
Integer result = 1; Integer result = 1;
numArr[0] = myfile.getUserTableStatus(); if ("ORACLE".equals(myfile.getDataBaseType().toUpperCase())) {
numArr[1] = myfile.getCkIndicateStatus(); numArr = new Integer[3];
numArr[2] = myfile.getCkPayStatus(); numArr[2]= myfile.getUserTableStatus();
}
else {
numArr = new Integer[2];
}
numArr[0]= myfile.getCkPayStatus();
numArr[1]= myfile.getCkIndicateStatus();
for (Integer integer : numArr) { for (Integer integer : numArr) {
if (integer != 1) { if (integer != 1) {
result = integer; result = integer;
@ -406,25 +418,10 @@ public class ScriptMakeService implements IScriptMakeService {
private static String fileReader(String path) { private static String fileReader(String path) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String tempString = "";
if (null == path || "".equals(path)) { if (null == path || "".equals(path)) {
return sb.toString(); return sb.toString();
} }
try { return FileOperateHelper.fileReaderAndendline(path);
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) { private static int fileDelete(String path) {

Loading…
Cancel
Save