瀏覽代碼

优化代码结构,删除过期代码

sunyj 9 年之前
父節點
當前提交
add94b173c

+ 1 - 1
src/main/java/com/uas/report/controller/FileController.java

@@ -87,7 +87,7 @@ public class FileController {
 	 */
 	@RequestMapping("/download/jrxml")
 	public void downloadJrxml(String userName, String reportName, HttpServletResponse response) {
-		fileService.download(fileService.getJrxml(userName, reportName), response);
+		fileService.download(fileService.getJrxmlFilePath(userName, reportName), response);
 	}
 
 	/**

+ 18 - 12
src/main/java/com/uas/report/controller/PrintController.java

@@ -20,7 +20,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import com.uas.report.core.exception.ReportException;
+import com.uas.report.service.FileService;
 import com.uas.report.service.PrintService;
+import com.uas.report.util.FileUtils;
 import com.uas.report.util.PathUtils;
 import com.uas.report.util.ReportConstants;
 import com.uas.report.util.ReportUtils;
@@ -41,6 +43,9 @@ public class PrintController {
 	@Autowired
 	private PrintService printService;
 
+	@Autowired
+	private FileService fileService;
+
 	/**
 	 * 为UAS系统打印提供服务, 根据printType进行预览、打印、下载pdf、下载纯数据excel等操作
 	 * 
@@ -120,7 +125,7 @@ public class PrintController {
 		byte[] data = null;
 
 		String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
-				+ printService.generateFileName(userName, profile, reportName, whereCondition, otherParameters);
+				+ fileService.generateFileName(userName, profile, reportName, whereCondition, otherParameters);
 		if (exportFileType.equals("xls_with_only_data")) {
 			filePath += ".xls";
 		} else {
@@ -128,12 +133,12 @@ public class PrintController {
 		}
 		File file = new File(PathUtils.getAppPath() + filePath);
 		// 文件无效(不存在或过期),创建
-		if (!printService.isFileValid(file.getPath())) {
+		if (!fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(userName, reportName))) {
 			data = printService.export(userName, profile, reportName, whereCondition, otherParameters, exportFileType);
 			if (ArrayUtils.isEmpty(data)) {
 				throw new ReportException("报表导出失败:" + reportName);
 			}
-			printService.writeDataToFile(file.getPath(), data);
+			FileUtils.create(file.getPath(), data);
 		} else {
 			FileInputStream fileInputStream = null;
 			try {
@@ -200,11 +205,10 @@ public class PrintController {
 
 		// 相对路径,返回给前端
 		String pdfPath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
-				+ printService.generateFileName(userName, profile, reportName, whereCondition, otherParameters)
-				+ ".pdf";
+				+ fileService.generateFileName(userName, profile, reportName, whereCondition, otherParameters) + ".pdf";
 		File file = new File(PathUtils.getAppPath() + pdfPath);
 		// 文件无效(不存在或过期),重新创建pdf文件
-		if (!printService.isFileValid(file.getPath())) {
+		if (!fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(userName, reportName))) {
 			// 若参数pageIndex不为null,表示是预览
 			// 检查第一页的pdf文件是否存在,若不存在,先生成第一页pdf,返回给前台展示,
 			// 再开线程生成后面页的pdf和总的pdf(即未分页的pdf),以备后续可能的打印、下载操作使用
@@ -224,13 +228,13 @@ public class PrintController {
 				if (ArrayUtils.isEmpty(data)) {
 					throw new ReportException("获取预览数据失败");
 				}
-				printService.writeDataToFile(file.getPath(), data);
+				FileUtils.create(file.getPath(), data);
 				// 同时生成分页的pdf
-				printService.writePagedPdfFiles(file.getPath());
+				fileService.createPagedPdfFiles(file.getPath());
 			}
 		} else {
 			result = new HashMap<>();
-			result.put("pageSize", printService.getPageSize(file.getPath()));
+			result.put("pageSize", fileService.getPageSize(file.getPath()));
 		}
 		result.put("pdfPath", pdfPath);
 		logger.info("预览报表成功:" + reportName);
@@ -264,14 +268,16 @@ public class PrintController {
 			pdfOrXls = "pdf";
 		}
 		String filePath = ReportConstants.GENERATED_FILES_PATH + reportName + "/"
-				+ printService.generateFileName(userName, profile, reportName, whereCondition, otherParameters);
+				+ fileService.generateFileName(userName, profile, reportName, whereCondition, otherParameters);
 		File file = new File(PathUtils.getAppPath() + filePath + "." + pdfOrXls);
 		result.put("file", file.getPath());
 		if (pdfOrXls.equals("pdf")) {
-			result.put("valid", printService.isFileValid(file.getPath()));
+			result.put("valid",
+					fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(userName, reportName)));
 			result.put("size", file.length());
 		} else if (pdfOrXls.equals("xls")) {
-			result.put("valid", printService.isFileValid(file.getPath()));
+			result.put("valid",
+					fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(userName, reportName)));
 			result.put("size", file.length());
 		} else {
 			throw new ReportException("pdfOrXls只能为pdf或xls");

+ 64 - 8
src/main/java/com/uas/report/service/FileService.java

@@ -33,7 +33,7 @@ public interface FileService {
 	public String upload(String userName, String fileType, MultipartFile file);
 
 	/**
-	 * 获取账套下的某个模板
+	 * 获取账套下的模板路径
 	 * 
 	 * @param userName
 	 *            账套名称
@@ -41,7 +41,16 @@ public interface FileService {
 	 *            模板名称
 	 * @return 模板路径
 	 */
-	public String getJrxml(String userName, String reportName);
+	public String getJrxmlFilePath(String userName, String reportName);
+
+	/**
+	 * 获取账套路径
+	 * 
+	 * @param userName
+	 *            账套名称
+	 * @return 账套路径
+	 */
+	public String getMasterPath(String userName);
 
 	/**
 	 * 获取标准模板
@@ -69,22 +78,69 @@ public interface FileService {
 	public void download(String filePath, HttpServletResponse response);
 
 	/**
-	 * 账套下的某个文件
+	 * 账套下的某个文件(夹)
 	 * 
 	 * @param userName
 	 *            账套名称
 	 * @param fileRelativePath
-	 *            文件在账套下的相对路径
-	 * @return 文件路径
+	 *            文件(夹)在账套下的相对路径
+	 * @return 文件(夹)路径
 	 */
 	public String delete(String userName, String fileRelativePath);
 
 	/**
-	 * 删除文件
+	 * 递归删除文件(夹)
 	 * 
 	 * @param filePath
-	 *            文件路径
-	 * @return 文件路径
+	 *            文件(夹)路径
+	 * @return 文件(夹)路径
 	 */
 	public String delete(String filePath);
+
+	/**
+	 * 判断文件是否有效(文件存在并且未过有效期,并且比模板新)
+	 * 
+	 * @param filePath
+	 *            所指定的文件绝对路径
+	 * @param jrxmlFilePath
+	 *            文件对应的模板路径
+	 * @return 是否有效
+	 */
+	public boolean isFileValid(String filePath, String jrxmlFilePath);
+
+	/**
+	 * 根据报表名、账套名等生成文件名
+	 * 
+	 * @param userName
+	 *            不为null;当前账套用户名
+	 * @param profile
+	 *            可为null;用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
+	 * @param reportName
+	 *            不为null;需要预览的报表的名称,不带任何后缀(如预览采购单,即为"Purchase")
+	 * @param whereCondition
+	 *            可为null;where之后的条件(包括where)
+	 * @param otherParameters
+	 *            可为null;若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,
+	 *            报表某些字段的值取决于这些参数; JSON格式,数据为键值对
+	 * @return 生成的文件名(不含后缀名)
+	 */
+	public String generateFileName(String userName, String profile, String reportName, String whereCondition,
+			String otherParameters);
+
+	/**
+	 * 获取给定的pdf文件的页数
+	 * 
+	 * @param pdfFilePath
+	 *            给定的pdf文件绝对路径
+	 * @return pdf文件的页数
+	 */
+	public int getPageSize(String pdfFilePath);
+
+	/**
+	 * 利用给定的pdf文件在同级目录下生成多个分页的pdf文件(一页对应一个文件)
+	 * 
+	 * @param pdfFilePath
+	 *            给定的pdf文件绝对路径
+	 */
+	public void createPagedPdfFiles(String pdfFilePath);
 }

+ 0 - 113
src/main/java/com/uas/report/service/PrintService.java

@@ -10,26 +10,6 @@ import java.util.Map;
  */
 public interface PrintService {
 
-	/**
-	 * 导出报表
-	 * 
-	 * @param userName
-	 *            不为null;当前账套用户名
-	 * @param reportName
-	 *            不为null;需要导出的报表的名称,不带任何后缀(如导出采购单,即为"Purchase")
-	 * @param whereCondition
-	 *            可为null;where之后的条件(包括where)
-	 * @param otherParameters
-	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
-	 *            JSON格式,数据为键值对
-	 * @param exportFileType
-	 *            报表导出的格式,默认为pdf
-	 * @return 导出的文件的字节数组
-	 */
-	// TODO delete
-	public byte[] export(String userName, String reportName, String whereCondition, String otherParameters,
-			String exportFileType);
-
 	/**
 	 * 导出报表
 	 * 
@@ -51,26 +31,6 @@ public interface PrintService {
 	public byte[] export(String userName, String profile, String reportName, String whereCondition,
 			String otherParameters, String exportFileType);
 
-	/**
-	 * 预览报表
-	 * 
-	 * @param userName
-	 *            不为null;当前账套用户名
-	 * @param reportName
-	 *            不为null;需要预览的报表的名称,不带任何后缀(如预览采购单,即为"Purchase")
-	 * @param whereCondition
-	 *            可为null;where之后的条件(包括where)
-	 * @param otherParameters
-	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
-	 *            JSON格式,数据为键值对
-	 * @param pageIndex
-	 *            分页展示,当前页码,从0开始
-	 * @return 报表数据"data": byte[];总页数"pageSize": Integer
-	 */
-	// TODO delete
-	public Map<String, Object> preview(String userName, String reportName, String whereCondition,
-			String otherParameters, Integer pageIndex);
-
 	/**
 	 * 预览报表
 	 * 
@@ -115,77 +75,4 @@ public interface PrintService {
 	public Integer previewFirstPage(String userName, String profile, String reportName, String whereCondition,
 			String otherParameters, String pdfFilePath);
 
-	/**
-	 * 利用字节数组数据创建文件
-	 * 
-	 * @param filePath
-	 *            要写入的文件的绝对路径
-	 * @param data
-	 *            文件的数据
-	 * @return
-	 */
-	public void writeDataToFile(String filePath, byte[] data);
-
-	/**
-	 * 利用给定的pdf文件在同级目录下生成多个分页的pdf文件(一页对应一个文件)
-	 * 
-	 * @param pdfFilePath
-	 *            给定的pdf文件绝对路径
-	 * @return
-	 */
-	public void writePagedPdfFiles(String pdfFilePath);
-
-	/**
-	 * 获取给定的pdf文件的页数
-	 * 
-	 * @param pdfFilePath
-	 *            给定的pdf文件绝对路径
-	 * @return pdf文件的页数
-	 */
-	public int getPageSize(String pdfFilePath);
-
-	/**
-	 * 根据报表名、账套名等生成文件名
-	 * 
-	 * @param userName
-	 *            不为null;当前账套用户名
-	 * @param reportName
-	 *            不为null;需要预览的报表的名称,不带任何后缀(如预览采购单,即为"Purchase")
-	 * @param whereCondition
-	 *            可为null;where之后的条件(包括where)
-	 * @param otherParameters
-	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
-	 *            JSON格式,数据为键值对
-	 * @return 生成的文件名(不含后缀名)
-	 */
-	// TODO delete
-	public String generateFileName(String userName, String reportName, String whereCondition, String otherParameters);
-
-	/**
-	 * 根据报表名、账套名等生成文件名
-	 * 
-	 * @param userName
-	 *            不为null;当前账套用户名
-	 * @param profile
-	 *            用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
-	 * @param reportName
-	 *            不为null;需要预览的报表的名称,不带任何后缀(如预览采购单,即为"Purchase")
-	 * @param whereCondition
-	 *            可为null;where之后的条件(包括where)
-	 * @param otherParameters
-	 *            若模板已指定需要的参数,则不可为null;其他参数,区别于whereCondition,报表某些字段的值取决于这些参数;
-	 *            JSON格式,数据为键值对
-	 * @return 生成的文件名(不含后缀名)
-	 */
-	public String generateFileName(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters);
-
-	/**
-	 * 判断文件是否有效(文件存在并且未过有效期)
-	 * 
-	 * @param filePath
-	 *            所指定的文件绝对路径
-	 * @return 是否有效
-	 */
-	public boolean isFileValid(String filePath);
 }

+ 89 - 7
src/main/java/com/uas/report/service/impl/FileServiceImpl.java

@@ -2,10 +2,12 @@ package com.uas.report.service.impl;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URI;
+import java.util.Date;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -20,6 +22,10 @@ import org.springframework.web.multipart.MultipartFile;
 
 import com.alibaba.druid.util.StringUtils;
 import com.alibaba.fastjson.JSONObject;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.pdf.PdfCopy;
+import com.itextpdf.text.pdf.PdfReader;
 import com.uas.report.core.exception.ReportException;
 import com.uas.report.service.FileService;
 import com.uas.report.support.SysConf;
@@ -122,10 +128,18 @@ public class FileServiceImpl implements FileService {
 	}
 
 	@Override
-	public String getJrxml(String userName, String reportName) {
+	public String getJrxmlFilePath(String userName, String reportName) {
 		ReportUtils.checkParameters(userName, reportName);
-		return new StringBuilder(sysConf.getLocalBaseDir()).append("/").append(userName).append("/")
-				.append(sysConf.getLocalJrxmlDir()).append("/").append(reportName).append(".jrxml").toString();
+		return new StringBuilder(getMasterPath(userName)).append("/").append(sysConf.getLocalJrxmlDir()).append("/")
+				.append(reportName).append(".jrxml").toString();
+	}
+
+	@Override
+	public String getMasterPath(String userName) {
+		if (StringUtils.isEmpty(userName)) {
+			throw new ReportException("参数不能为空:userName");
+		}
+		return new StringBuilder(sysConf.getLocalBaseDir()).append("/").append(userName).toString();
 	}
 
 	@Override
@@ -156,7 +170,7 @@ public class FileServiceImpl implements FileService {
 	@Override
 	public String getZip(String userName) {
 		// 账套路径
-		String folderPath = sysConf.getLocalBaseDir() + "/" + userName;
+		String folderPath = getMasterPath(userName);
 		// 压缩后的压缩包路径,与账套在同一级
 		String zipFilePath = folderPath + ".zip";
 		ZipUtils.zipFolder(folderPath, zipFilePath);
@@ -195,8 +209,7 @@ public class FileServiceImpl implements FileService {
 		if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(fileRelativePath)) {
 			throw new ReportException("参数不能为空:userName,fileRelativePath");
 		}
-		return delete(new StringBuilder(sysConf.getLocalBaseDir()).append("/").append(userName).append("/")
-				.append(fileRelativePath).toString());
+		return delete(getMasterPath(userName) + "/" + fileRelativePath);
 	}
 
 	@Override
@@ -208,8 +221,77 @@ public class FileServiceImpl implements FileService {
 		if (!file.exists()) {
 			throw new ReportException("文件不存在,不必删除:" + filePath);
 		}
-		FileUtils.delete(file);
+		FileUtils.deleteDir(file);
 		return filePath;
 	}
 
+	@Override
+	public boolean isFileValid(String filePath, String jrxmlFilePath) {
+		if (!StringUtils.isEmpty(filePath) && !StringUtils.isEmpty(jrxmlFilePath)) {
+			File file = new File(filePath);
+			File jrxmlFile = new File(jrxmlFilePath);
+			if (file.exists() && jrxmlFile.exists()) {
+				long interval = new Date().getTime() - file.lastModified();
+				// 剩余的有效期(最高为10分钟)
+				long validity = 10 * 60 * 1000 - interval;
+				// 有效期大于0并且比模板文件新
+				if (validity > 0 && file.lastModified() > jrxmlFile.lastModified()) {
+					logger.info(file.getName() + " will be expired after " + validity / 1000.0 + "s");
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
+	@Override
+	public String generateFileName(String userName, String profile, String reportName, String whereCondition,
+			String otherParameters) {
+		if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(reportName)) {
+			return null;
+		}
+		StringBuilder stringBuilder = new StringBuilder(userName);
+		if (!StringUtils.isEmpty(profile)) {
+			stringBuilder.append(profile);
+		}
+		if (!StringUtils.isEmpty(whereCondition)) {
+			stringBuilder.append(whereCondition);
+		}
+		if (!StringUtils.isEmpty(otherParameters)) {
+			stringBuilder.append(otherParameters);
+		}
+		// 文件名:reportName + hashCode
+		return reportName + "_" + stringBuilder.toString().hashCode();
+	}
+
+	@Override
+	public int getPageSize(String pdfFilePath) {
+		try {
+			return new PdfReader(pdfFilePath).getNumberOfPages();
+		} catch (IOException e) {
+			throw new ReportException(e).setDetailedMessage(e);
+		}
+	}
+
+	@Override
+	public void createPagedPdfFiles(String pdfFilePath) {
+		try {
+			PdfReader pdfReader = new PdfReader(pdfFilePath);
+			for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
+				Document document = new Document();
+				FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath.replace(".pdf", "_" + i + ".pdf"));
+				PdfCopy pdfCopy = new PdfCopy(document, fileOutputStream);
+				document.open();
+				// 原pdf文件的每一页生成新的pdf
+				pdfCopy.addPage(pdfCopy.getImportedPage(pdfReader, i));
+				pdfCopy.close();
+				// 不关闭,生成的pdf无法正常打开
+				document.close();
+				fileOutputStream.close();
+			}
+			pdfReader.close();
+		} catch (IOException | DocumentException e) {
+			throw new ReportException(e).setDetailedMessage(e);
+		}
+	}
 }

+ 18 - 227
src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

@@ -2,17 +2,12 @@ package com.uas.report.service.impl;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 
 import javax.sql.DataSource;
 
@@ -23,17 +18,12 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
-import com.alibaba.druid.pool.DruidDataSource;
-import com.alibaba.druid.pool.DruidDataSourceFactory;
 import com.alibaba.fastjson.JSONObject;
-import com.itextpdf.text.Document;
-import com.itextpdf.text.DocumentException;
-import com.itextpdf.text.pdf.PdfCopy;
-import com.itextpdf.text.pdf.PdfReader;
 import com.uas.report.core.exception.ReportException;
+import com.uas.report.service.FileService;
 import com.uas.report.service.PrintService;
-import com.uas.report.support.SysConf;
-import com.uas.report.util.ContextUtils;
+import com.uas.report.util.DataSourceUtils;
+import com.uas.report.util.FileUtils;
 import com.uas.report.util.ReportConstants;
 
 import net.sf.jasperreports.engine.JRException;
@@ -62,28 +52,22 @@ import net.sf.jasperreports.export.SimplePdfReportConfiguration;
 public class PrintServiceImpl implements PrintService {
 
 	@Autowired
-	private SysConf sysConf;
+	private FileService fileService;
 
 	// @Autowired
 	// private ResourceService resourceService;
 
 	private Logger logger = Logger.getLogger(getClass());
 
-	@Override
-	public byte[] export(String userName, String reportName, String whereCondition, String otherParameters,
-			String exportFileType) {
-		return export(userName, null, reportName, whereCondition, otherParameters, exportFileType);
-	}
-
 	@Override
 	public byte[] export(String userName, String profile, String reportName, String whereCondition,
 			String otherParameters, String exportFileType) {
 		DataSource dataSource = null;
 		if (!StringUtils.isEmpty(profile)) {
-			dataSource = getDataSource(userName, profile);
+			dataSource = DataSourceUtils.getPlatformDataSource(userName, profile);
 		} else {
 			// 为空,说明不是来自B2C或B2B的请求,而是UAS系统
-			dataSource = getUASDataSource(userName);
+			dataSource = DataSourceUtils.getUASDataSource(userName);
 		}
 		if (dataSource == null) {
 			throw new ReportException("获取数据源失败");
@@ -96,21 +80,15 @@ public class PrintServiceImpl implements PrintService {
 		return null;
 	}
 
-	@Override
-	public Map<String, Object> preview(String userName, String reportName, String whereCondition,
-			String otherParameters, Integer pageIndex) {
-		return preview(userName, null, reportName, whereCondition, otherParameters, pageIndex);
-	}
-
 	@Override
 	public Map<String, Object> preview(String userName, String profile, String reportName, String whereCondition,
 			String otherParameters, Integer pageIndex) {
 		DataSource dataSource = null;
 		if (!StringUtils.isEmpty(profile)) {
-			dataSource = getDataSource(userName, profile);
+			dataSource = DataSourceUtils.getPlatformDataSource(userName, profile);
 		} else {
 			// 为空,说明不是来自B2C或B2B的请求,而是UAS系统
-			dataSource = getUASDataSource(userName);
+			dataSource = DataSourceUtils.getUASDataSource(userName);
 		}
 		if (dataSource == null) {
 			throw new ReportException("获取数据源失败");
@@ -122,7 +100,7 @@ public class PrintServiceImpl implements PrintService {
 	public Integer previewFirstPage(final String userName, final String profile, final String reportName,
 			final String whereCondition, final String otherParameters, final String pdfFilePath) {
 		// 先生成第一页pdf
-		final Integer pageSize = writePdfData(userName, profile, reportName, whereCondition, otherParameters,
+		final Integer pageSize = createPdfFile(userName, profile, reportName, whereCondition, otherParameters,
 				pdfFilePath.replace(".pdf", "_1.pdf"), 1);
 
 		// 再开线程生成后面页的pdf、总的pdf(即未分页的pdf)、纯数据excel
@@ -131,22 +109,22 @@ public class PrintServiceImpl implements PrintService {
 			public void run() {
 				// 生成之后2~5页的pdf,防止数据量较大的情况下,卡在生成总的pdf阶段,此时查看前5页也不会卡顿
 				for (int i = 2; i <= Math.min(pageSize, 5); i++) {
-					writePdfData(userName, profile, reportName, whereCondition, otherParameters,
+					createPdfFile(userName, profile, reportName, whereCondition, otherParameters,
 							pdfFilePath.replace(".pdf", "_" + i + ".pdf"), i);
 				}
 				// 生成总的pdf
-				writePdfData(userName, profile, reportName, whereCondition, otherParameters, pdfFilePath, null);
-				writePagedPdfFiles(pdfFilePath);
+				createPdfFile(userName, profile, reportName, whereCondition, otherParameters, pdfFilePath, null);
+				fileService.createPagedPdfFiles(pdfFilePath);
 				// 生成纯数据excel
 				File file = new File(pdfFilePath.replace(".pdf", ".xls"));
 				// 文件无效(不存在或过期),创建
-				if (!isFileValid(file.getPath())) {
+				if (!fileService.isFileValid(file.getPath(), fileService.getJrxmlFilePath(userName, reportName))) {
 					byte[] data = export(userName, profile, reportName, whereCondition, otherParameters,
 							"xls_with_only_data");
 					if (ArrayUtils.isEmpty(data)) {
 						throw new ReportException("报表导出失败:" + reportName);
 					}
-					writeDataToFile(file.getPath(), data);
+					FileUtils.create(file.getPath(), data);
 				}
 			}
 		}).start();
@@ -174,7 +152,7 @@ public class PrintServiceImpl implements PrintService {
 	 *            页码
 	 * @return 总页数
 	 */
-	private Integer writePdfData(String userName, String profile, String reportName, String whereCondition,
+	private Integer createPdfFile(String userName, String profile, String reportName, String whereCondition,
 			String otherParameters, String pdfFilePath, Integer pageIndex) {
 		File file = new File(pdfFilePath);
 		Map<String, Object> result = preview(userName, profile, reportName, whereCondition, otherParameters, pageIndex);
@@ -187,100 +165,10 @@ public class PrintServiceImpl implements PrintService {
 		if (ArrayUtils.isEmpty(data) || pageSize == null) {
 			throw new ReportException("获取预览数据失败");
 		}
-		writeDataToFile(file.getPath(), data);
+		FileUtils.create(file.getPath(), data);
 		return pageSize;
 	}
 
-	@Override
-	public void writeDataToFile(String filePath, byte[] data) {
-		File file = new File(filePath);
-		if (!file.getParentFile().exists()) {
-			file.getParentFile().mkdirs();
-		}
-		try {
-			FileOutputStream fos = new FileOutputStream(file);
-			fos.write(data);
-			fos.flush();
-			logger.info("Writed file..." + file.getPath());
-			fos.close();
-		} catch (IOException e) {
-			throw new ReportException(e).setDetailedMessage(e);
-		}
-	}
-
-	@Override
-	public void writePagedPdfFiles(String pdfFilePath) {
-		try {
-			PdfReader pdfReader = new PdfReader(pdfFilePath);
-			for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {
-				Document document = new Document();
-				FileOutputStream fileOutputStream = new FileOutputStream(pdfFilePath.replace(".pdf", "_" + i + ".pdf"));
-				PdfCopy pdfCopy = new PdfCopy(document, fileOutputStream);
-				document.open();
-				// 原pdf文件的每一页生成新的pdf
-				pdfCopy.addPage(pdfCopy.getImportedPage(pdfReader, i));
-				pdfCopy.close();
-				// 不关闭,生成的pdf无法正常打开
-				document.close();
-				fileOutputStream.close();
-			}
-			pdfReader.close();
-		} catch (IOException | DocumentException e) {
-			throw new ReportException(e).setDetailedMessage(e);
-		}
-	}
-
-	@Override
-	public int getPageSize(String pdfFilePath) {
-		try {
-			return new PdfReader(pdfFilePath).getNumberOfPages();
-		} catch (IOException e) {
-			throw new ReportException(e).setDetailedMessage(e);
-		}
-	}
-
-	@Override
-	public String generateFileName(String userName, String reportName, String whereCondition, String otherParameters) {
-		return generateFileName(userName, null, reportName, whereCondition, otherParameters);
-	}
-
-	@Override
-	public String generateFileName(String userName, String profile, String reportName, String whereCondition,
-			String otherParameters) {
-		if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(reportName)) {
-			return null;
-		}
-		StringBuilder stringBuilder = new StringBuilder(userName);
-		if (!StringUtils.isEmpty(profile)) {
-			stringBuilder.append(profile);
-		}
-		if (!StringUtils.isEmpty(whereCondition)) {
-			stringBuilder.append(whereCondition);
-		}
-		if (!StringUtils.isEmpty(otherParameters)) {
-			stringBuilder.append(otherParameters);
-		}
-		// 文件名:reportName + hashCode
-		return reportName + "_" + stringBuilder.toString().hashCode();
-	}
-
-	@Override
-	public boolean isFileValid(String filePath) {
-		if (!StringUtils.isEmpty(filePath)) {
-			File file = new File(filePath);
-			if (file.exists()) {
-				long interval = new Date().getTime() - file.lastModified();
-				// 剩余的有效期(最高为10分钟)
-				long validity = 10 * 60 * 1000 - interval;
-				if (validity > 0) {
-					logger.info(file.getName() + " will be expired after " + validity / 1000.0 + "s");
-					return true;
-				}
-			}
-		}
-		return false;
-	}
-
 	/**
 	 * 输出报表的数据
 	 * 
@@ -302,9 +190,8 @@ public class PrintServiceImpl implements PrintService {
 		// }
 
 		// 报表路径为报表根路径REPORT_DIR + 当前账套用户名userName
-		String reportDir = new StringBuilder(sysConf.getLocalBaseDir()).append("/").append(userName).toString();
-		String jrxmlFilePath = new StringBuilder(reportDir).append("/").append(sysConf.getLocalJrxmlDir()).append("/")
-				.append(reportName).append(".jrxml").toString();
+		String reportDir = fileService.getMasterPath(userName);
+		String jrxmlFilePath = fileService.getJrxmlFilePath(userName, reportName);
 		File jrxmlFile = new File(jrxmlFilePath);
 		// 报表模板不存在
 		if (!jrxmlFile.exists()) {
@@ -416,102 +303,6 @@ public class PrintServiceImpl implements PrintService {
 		}
 	}
 
-	/**
-	 * 根据当前账套用户名,从主数据库master表获取(UAS系统)账套数据库配置信息,作为报表模板的数据源
-	 * 
-	 * @param userName
-	 *            当前账套用户名
-	 * @return
-	 */
-	private DataSource getUASDataSource(String userName) {
-		// 默认数据源(主数据库)
-		DruidDataSource defaultDataSource = ContextUtils.getApplicationContext().getBean("defaultSob",
-				DruidDataSource.class);
-		if (defaultDataSource == null) {
-			return null;
-		}
-		// 若当前账套用户名为默认数据库用户名
-		if (userName.equals(defaultDataSource.getUsername())) {
-			return defaultDataSource;
-		}
-
-		Connection connection = null;
-		PreparedStatement preparedStatement = null;
-		ResultSet resultSet = null;
-		try {
-			connection = defaultDataSource.getConnection();
-			// 根据当前账套用户名获取其数据库配置信息
-			String sql = "select * from master where MA_USER = ?";
-			preparedStatement = connection.prepareStatement(sql);
-			preparedStatement.setString(1, userName);
-			resultSet = preparedStatement.executeQuery();
-			if (resultSet.next()) {
-				String password = resultSet.getString("MS_PWD");
-				if (!StringUtils.isEmpty(password)) {
-					Properties properties = new Properties();
-					properties.put("driverClassName", defaultDataSource.getDriverClassName());
-					properties.put("url", defaultDataSource.getUrl());
-					properties.put("username", userName);
-					properties.put("password", password);
-					properties.put("testWhileIdle", "true");
-					properties.put("validationQuery", "select 1 from SYS.DUAL");
-					return DruidDataSourceFactory.createDataSource(properties);
-				}
-			}
-		} catch (Exception e) {
-			throw new ReportException(e).setDetailedMessage(e);
-		} finally {
-			try {
-				if (resultSet != null) {
-					resultSet.close();
-				}
-			} catch (SQLException e) {
-				e.printStackTrace();
-			}
-			try {
-				if (preparedStatement != null) {
-					preparedStatement.close();
-				}
-			} catch (SQLException e) {
-				e.printStackTrace();
-			}
-			try {
-				if (connection != null) {
-					connection.close();
-				}
-			} catch (SQLException e) {
-				throw new ReportException(e).setDetailedMessage(e);
-			}
-		}
-		return null;
-	}
-
-	/**
-	 * 根据当前账套用户名和profile配置,获取相应B2C、B2B数据源
-	 * 
-	 * @param userName
-	 *            当前账套用户名
-	 * @param profile
-	 *            用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
-	 * @return
-	 */
-	private DataSource getDataSource(String userName, String profile) {
-		// 如果userName是B2C或B2B,直接获取配置好的B2C数据源(B2B数据源与B2C相同)
-		if (userName.toUpperCase().startsWith("B2C") || userName.toUpperCase().startsWith("B2B")) {
-			if (profile.equalsIgnoreCase("dev")) {
-				return ContextUtils.getApplicationContext().getBean("b2cDevDataSource", DruidDataSource.class);
-			} else if (profile.equalsIgnoreCase("test")) {
-				return ContextUtils.getApplicationContext().getBean("b2cTestDataSource", DruidDataSource.class);
-			} else if (profile.equalsIgnoreCase("prod")) {
-				return ContextUtils.getApplicationContext().getBean("b2cProdDataSource", DruidDataSource.class);
-			} else {
-				throw new ReportException("profile只能为:dev、test或prod,不可为" + profile);
-			}
-		} else {
-			throw new ReportException("暂时不支持" + userName);
-		}
-	}
-
 	/**
 	 * 以不同的格式导出报表
 	 * 

+ 5 - 1
src/main/java/com/uas/report/service/impl/ResourceServiceImpl.java

@@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.uas.report.model.Resource;
+import com.uas.report.service.FileService;
 import com.uas.report.service.ResourceService;
 import com.uas.report.support.JasperserverRestAPIConf;
 import com.uas.report.support.SysConf;
@@ -46,6 +47,9 @@ public class ResourceServiceImpl implements ResourceService {
 	@Autowired
 	private SysConf sysConf;
 
+	@Autowired
+	private FileService fileService;
+
 	private Logger logger = Logger.getLogger(getClass());
 
 	// 是否为windows系统
@@ -135,7 +139,7 @@ public class ResourceServiceImpl implements ResourceService {
 	 * @return 资源列表
 	 */
 	private List<Resource> getLocalResources(String userName) {
-		return getLocalResources(new File(sysConf.getLocalBaseDir() + File.separator + userName));
+		return getLocalResources(new File(fileService.getMasterPath(userName)));
 	}
 
 	/**

+ 123 - 0
src/main/java/com/uas/report/util/DataSourceUtils.java

@@ -0,0 +1,123 @@
+package com.uas.report.util;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.sql.DataSource;
+
+import org.springframework.util.StringUtils;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import com.alibaba.druid.pool.DruidDataSourceFactory;
+import com.uas.report.core.exception.ReportException;
+
+/**
+ * 数据源工具类
+ * 
+ * @author sunyj
+ * @since 2016年11月4日 下午4:33:56
+ */
+public class DataSourceUtils {
+
+	/**
+	 * 根据当前账套用户名,从主数据库master表获取(UAS系统)账套数据库配置信息,作为报表模板的数据源
+	 * 
+	 * @param userName
+	 *            当前账套用户名
+	 * @return 数据源
+	 */
+	public static DataSource getUASDataSource(String userName) {
+		if (StringUtils.isEmpty(userName)) {
+			return null;
+		}
+		// 默认数据源(主数据库)
+		DruidDataSource defaultDataSource = ContextUtils.getApplicationContext().getBean("defaultSob",
+				DruidDataSource.class);
+		if (defaultDataSource == null) {
+			return null;
+		}
+		// 若当前账套用户名为默认数据库用户名
+		if (userName.equals(defaultDataSource.getUsername())) {
+			return defaultDataSource;
+		}
+
+		Connection connection = null;
+		PreparedStatement preparedStatement = null;
+		ResultSet resultSet = null;
+		try {
+			connection = defaultDataSource.getConnection();
+			// 根据当前账套用户名获取其数据库配置信息
+			String sql = "select * from master where MA_USER = ?";
+			preparedStatement = connection.prepareStatement(sql);
+			preparedStatement.setString(1, userName);
+			resultSet = preparedStatement.executeQuery();
+			if (resultSet.next()) {
+				String password = resultSet.getString("MS_PWD");
+				if (!StringUtils.isEmpty(password)) {
+					Properties properties = new Properties();
+					properties.put("driverClassName", defaultDataSource.getDriverClassName());
+					properties.put("url", defaultDataSource.getUrl());
+					properties.put("username", userName);
+					properties.put("password", password);
+					properties.put("testWhileIdle", "true");
+					properties.put("validationQuery", "select 1 from SYS.DUAL");
+					return DruidDataSourceFactory.createDataSource(properties);
+				}
+			}
+		} catch (Exception e) {
+			throw new ReportException(e).setDetailedMessage(e);
+		} finally {
+			try {
+				if (resultSet != null) {
+					resultSet.close();
+				}
+			} catch (SQLException e) {
+				e.printStackTrace();
+			}
+			try {
+				if (preparedStatement != null) {
+					preparedStatement.close();
+				}
+			} catch (SQLException e) {
+				e.printStackTrace();
+			}
+			try {
+				if (connection != null) {
+					connection.close();
+				}
+			} catch (SQLException e) {
+				throw new ReportException(e).setDetailedMessage(e);
+			}
+		}
+		return null;
+	}
+
+	/**
+	 * 根据当前账套用户名和profile配置,获取相应B2C、B2B数据源
+	 * 
+	 * @param userName
+	 *            当前账套用户名
+	 * @param profile
+	 *            用于标识请求源(B2C、B2B)是正式、测试还是开发版本:prod、test、dev
+	 * @return 数据源
+	 */
+	public static DataSource getPlatformDataSource(String userName, String profile) {
+		// 如果userName是B2C或B2B,直接获取配置好的B2C数据源(B2B数据源与B2C相同)
+		if (userName.toUpperCase().startsWith("B2C") || userName.toUpperCase().startsWith("B2B")) {
+			if (profile.equalsIgnoreCase("dev")) {
+				return ContextUtils.getApplicationContext().getBean("platformDevDataSource", DruidDataSource.class);
+			} else if (profile.equalsIgnoreCase("test")) {
+				return ContextUtils.getApplicationContext().getBean("platformTestDataSource", DruidDataSource.class);
+			} else if (profile.equalsIgnoreCase("prod")) {
+				return ContextUtils.getApplicationContext().getBean("platformProdDataSource", DruidDataSource.class);
+			} else {
+				throw new ReportException("profile只能为:dev、test或prod,不可为" + profile);
+			}
+		} else {
+			throw new ReportException("暂时不支持" + userName);
+		}
+	}
+}

+ 2 - 2
src/main/java/com/uas/report/util/FileUtils.java

@@ -53,14 +53,14 @@ public class FileUtils {
 	 * @param file
 	 *            文件(夹)
 	 */
-	public static void delete(File file) {
+	public static void deleteDir(File file) {
 		if (file == null) {
 			return;
 		}
 		if (file.isDirectory()) {
 			File[] files = file.listFiles();
 			for (File f : files) {
-				delete(f);
+				deleteDir(f);
 			}
 		}
 		file.delete();

+ 0 - 22
src/main/resources/dev/jdbc-b2c.properties

@@ -1,22 +0,0 @@
-#B2C
-#dev
-jdbc.b2c.dev.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
-jdbc.b2c.dev.username=uuplatformdemo
-jdbc.b2c.dev.password=selectuuplatform
-#test
-jdbc.b2c.test.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
-jdbc.b2c.test.username=uuplatformdemo
-jdbc.b2c.test.password=selectuuplatform
-#prod
-jdbc.b2c.prod.url=jdbc:oracle:thin:@10.10.100.200:1521:orcl
-jdbc.b2c.prod.username=platform$b2b
-jdbc.b2c.prod.password=select*fromuu
-#other configuration
-jdbc.b2c.driverClassName=oracle.jdbc.driver.OracleDriver
-jdbc.b2c.initialSize=1
-jdbc.b2c.maxActive=100
-jdbc.b2c.maxIdle=50
-jdbc.b2c.minIdle=50
-jdbc.b2c.suspectTimeout=60
-jdbc.b2c.timeBetweenEvictionRunsMillis=30000
-jdbc.b2c.minEvictableIdleTimeMillis=60000

+ 22 - 0
src/main/resources/dev/jdbc-platform.properties

@@ -0,0 +1,22 @@
+#platform
+#dev
+jdbc.platform.dev.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
+jdbc.platform.dev.username=uuplatformdemo
+jdbc.platform.dev.password=selectuuplatform
+#test
+jdbc.platform.test.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
+jdbc.platform.test.username=uuplatformdemo
+jdbc.platform.test.password=selectuuplatform
+#prod
+jdbc.platform.prod.url=jdbc:oracle:thin:@10.10.100.200:1521:orcl
+jdbc.platform.prod.username=platform$b2b
+jdbc.platform.prod.password=select*fromuu
+#other configuration
+jdbc.platform.driverClassName=oracle.jdbc.driver.OracleDriver
+jdbc.platform.initialSize=1
+jdbc.platform.maxActive=100
+jdbc.platform.maxIdle=50
+jdbc.platform.minIdle=50
+jdbc.platform.suspectTimeout=60
+jdbc.platform.timeBetweenEvictionRunsMillis=30000
+jdbc.platform.minEvictableIdleTimeMillis=60000

+ 0 - 22
src/main/resources/prod/jdbc-b2c.properties

@@ -1,22 +0,0 @@
-#B2C
-#dev
-jdbc.b2c.dev.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
-jdbc.b2c.dev.username=uuplatformdemo
-jdbc.b2c.dev.password=selectuuplatform
-#test
-jdbc.b2c.test.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
-jdbc.b2c.test.username=uuplatformdemo
-jdbc.b2c.test.password=selectuuplatform
-#prod
-jdbc.b2c.prod.url=jdbc:oracle:thin:@10.10.100.200:1521:orcl
-jdbc.b2c.prod.username=platform$b2b
-jdbc.b2c.prod.password=select*fromuu
-#other configuration
-jdbc.b2c.driverClassName=oracle.jdbc.driver.OracleDriver
-jdbc.b2c.initialSize=1
-jdbc.b2c.maxActive=100
-jdbc.b2c.maxIdle=50
-jdbc.b2c.minIdle=50
-jdbc.b2c.suspectTimeout=60
-jdbc.b2c.timeBetweenEvictionRunsMillis=30000
-jdbc.b2c.minEvictableIdleTimeMillis=60000

+ 22 - 0
src/main/resources/prod/jdbc-platform.properties

@@ -0,0 +1,22 @@
+#platform
+#dev
+jdbc.platform.dev.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
+jdbc.platform.dev.username=uuplatformdemo
+jdbc.platform.dev.password=selectuuplatform
+#test
+jdbc.platform.test.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
+jdbc.platform.test.username=uuplatformdemo
+jdbc.platform.test.password=selectuuplatform
+#prod
+jdbc.platform.prod.url=jdbc:oracle:thin:@10.10.100.200:1521:orcl
+jdbc.platform.prod.username=platform$b2b
+jdbc.platform.prod.password=select*fromuu
+#other configuration
+jdbc.platform.driverClassName=oracle.jdbc.driver.OracleDriver
+jdbc.platform.initialSize=1
+jdbc.platform.maxActive=100
+jdbc.platform.maxIdle=50
+jdbc.platform.minIdle=50
+jdbc.platform.suspectTimeout=60
+jdbc.platform.timeBetweenEvictionRunsMillis=30000
+jdbc.platform.minEvictableIdleTimeMillis=60000

+ 39 - 36
src/main/resources/spring/applicationContext.xml

@@ -57,17 +57,17 @@
 		<property name="filters" value="stat" />
 	</bean>
 
-	<!-- B2C dev数据库 -->
-	<bean id="b2cDevDataSource" class="com.alibaba.druid.pool.DruidDataSource"
+	<!-- platform dev数据库 -->
+	<bean id="platformDevDataSource" class="com.alibaba.druid.pool.DruidDataSource"
 		init-method="init" destroy-method="close">
-		<property name="driverClassName" value="${jdbc.b2c.driverClassName}" />
-		<property name="url" value="${jdbc.b2c.dev.url}" />
-		<property name="username" value="${jdbc.b2c.dev.username}" />
-		<property name="password" value="${jdbc.b2c.dev.password}" />
-		<property name="initialSize" value="${jdbc.b2c.initialSize}" />
-		<property name="maxActive" value="${jdbc.b2c.maxActive}" />
-		<property name="maxIdle" value="${jdbc.b2c.maxIdle}" />
-		<property name="minIdle" value="${jdbc.b2c.minIdle}" />
+		<property name="driverClassName" value="${jdbc.platform.driverClassName}" />
+		<property name="url" value="${jdbc.platform.dev.url}" />
+		<property name="username" value="${jdbc.platform.dev.username}" />
+		<property name="password" value="${jdbc.platform.dev.password}" />
+		<property name="initialSize" value="${jdbc.platform.initialSize}" />
+		<property name="maxActive" value="${jdbc.platform.maxActive}" />
+		<property name="maxIdle" value="${jdbc.platform.maxIdle}" />
+		<property name="minIdle" value="${jdbc.platform.minIdle}" />
 		<!-- 配置获取连接等待超时的时间 -->
 		<property name="maxWait" value="60000" />
 		<property name="testOnBorrow" value="false" />
@@ -75,9 +75,10 @@
 		<property name="testWhileIdle" value="true" />
 		<property name="validationQuery" value="SELECT 1 FROM SYS.DUAL" />
 		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接 -->
-		<property name="timeBetweenEvictionRunsMillis" value="${jdbc.b2c.timeBetweenEvictionRunsMillis}" />
+		<property name="timeBetweenEvictionRunsMillis"
+			value="${jdbc.platform.timeBetweenEvictionRunsMillis}" />
 		<!-- 配置一个连接在池中最小生存的时间 -->
-		<property name="minEvictableIdleTimeMillis" value="${jdbc.b2c.minEvictableIdleTimeMillis}" />
+		<property name="minEvictableIdleTimeMillis" value="${jdbc.platform.minEvictableIdleTimeMillis}" />
 		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
 		<property name="poolPreparedStatements" value="true" />
 		<property name="maxPoolPreparedStatementPerConnectionSize"
@@ -86,17 +87,17 @@
 		<property name="filters" value="stat" />
 	</bean>
 
-	<!-- B2C test数据库 -->
-	<bean id="b2cTestDataSource" class="com.alibaba.druid.pool.DruidDataSource"
+	<!-- platform test数据库 -->
+	<bean id="platformTestDataSource" class="com.alibaba.druid.pool.DruidDataSource"
 		init-method="init" destroy-method="close">
-		<property name="driverClassName" value="${jdbc.b2c.driverClassName}" />
-		<property name="url" value="${jdbc.b2c.test.url}" />
-		<property name="username" value="${jdbc.b2c.test.username}" />
-		<property name="password" value="${jdbc.b2c.test.password}" />
-		<property name="initialSize" value="${jdbc.b2c.initialSize}" />
-		<property name="maxActive" value="${jdbc.b2c.maxActive}" />
-		<property name="maxIdle" value="${jdbc.b2c.maxIdle}" />
-		<property name="minIdle" value="${jdbc.b2c.minIdle}" />
+		<property name="driverClassName" value="${jdbc.platform.driverClassName}" />
+		<property name="url" value="${jdbc.platform.test.url}" />
+		<property name="username" value="${jdbc.platform.test.username}" />
+		<property name="password" value="${jdbc.platform.test.password}" />
+		<property name="initialSize" value="${jdbc.platform.initialSize}" />
+		<property name="maxActive" value="${jdbc.platform.maxActive}" />
+		<property name="maxIdle" value="${jdbc.platform.maxIdle}" />
+		<property name="minIdle" value="${jdbc.platform.minIdle}" />
 		<!-- 配置获取连接等待超时的时间 -->
 		<property name="maxWait" value="60000" />
 		<property name="testOnBorrow" value="false" />
@@ -104,9 +105,10 @@
 		<property name="testWhileIdle" value="true" />
 		<property name="validationQuery" value="SELECT 1 FROM SYS.DUAL" />
 		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接 -->
-		<property name="timeBetweenEvictionRunsMillis" value="${jdbc.b2c.timeBetweenEvictionRunsMillis}" />
+		<property name="timeBetweenEvictionRunsMillis"
+			value="${jdbc.platform.timeBetweenEvictionRunsMillis}" />
 		<!-- 配置一个连接在池中最小生存的时间 -->
-		<property name="minEvictableIdleTimeMillis" value="${jdbc.b2c.minEvictableIdleTimeMillis}" />
+		<property name="minEvictableIdleTimeMillis" value="${jdbc.platform.minEvictableIdleTimeMillis}" />
 		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
 		<property name="poolPreparedStatements" value="true" />
 		<property name="maxPoolPreparedStatementPerConnectionSize"
@@ -115,17 +117,17 @@
 		<property name="filters" value="stat" />
 	</bean>
 
-	<!-- B2C prod数据库 -->
-	<bean id="b2cProdDataSource" class="com.alibaba.druid.pool.DruidDataSource"
+	<!-- platform prod数据库 -->
+	<bean id="platformProdDataSource" class="com.alibaba.druid.pool.DruidDataSource"
 		init-method="init" destroy-method="close">
-		<property name="driverClassName" value="${jdbc.b2c.driverClassName}" />
-		<property name="url" value="${jdbc.b2c.prod.url}" />
-		<property name="username" value="${jdbc.b2c.prod.username}" />
-		<property name="password" value="${jdbc.b2c.prod.password}" />
-		<property name="initialSize" value="${jdbc.b2c.initialSize}" />
-		<property name="maxActive" value="${jdbc.b2c.maxActive}" />
-		<property name="maxIdle" value="${jdbc.b2c.maxIdle}" />
-		<property name="minIdle" value="${jdbc.b2c.minIdle}" />
+		<property name="driverClassName" value="${jdbc.platform.driverClassName}" />
+		<property name="url" value="${jdbc.platform.prod.url}" />
+		<property name="username" value="${jdbc.platform.prod.username}" />
+		<property name="password" value="${jdbc.platform.prod.password}" />
+		<property name="initialSize" value="${jdbc.platform.initialSize}" />
+		<property name="maxActive" value="${jdbc.platform.maxActive}" />
+		<property name="maxIdle" value="${jdbc.platform.maxIdle}" />
+		<property name="minIdle" value="${jdbc.platform.minIdle}" />
 		<!-- 配置获取连接等待超时的时间 -->
 		<property name="maxWait" value="60000" />
 		<property name="testOnBorrow" value="false" />
@@ -133,9 +135,10 @@
 		<property name="testWhileIdle" value="true" />
 		<property name="validationQuery" value="SELECT 1 FROM SYS.DUAL" />
 		<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接 -->
-		<property name="timeBetweenEvictionRunsMillis" value="${jdbc.b2c.timeBetweenEvictionRunsMillis}" />
+		<property name="timeBetweenEvictionRunsMillis"
+			value="${jdbc.platform.timeBetweenEvictionRunsMillis}" />
 		<!-- 配置一个连接在池中最小生存的时间 -->
-		<property name="minEvictableIdleTimeMillis" value="${jdbc.b2c.minEvictableIdleTimeMillis}" />
+		<property name="minEvictableIdleTimeMillis" value="${jdbc.platform.minEvictableIdleTimeMillis}" />
 		<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
 		<property name="poolPreparedStatements" value="true" />
 		<property name="maxPoolPreparedStatementPerConnectionSize"

+ 0 - 22
src/main/resources/test/jdbc-b2c.properties

@@ -1,22 +0,0 @@
-#B2C
-#dev
-jdbc.b2c.dev.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
-jdbc.b2c.dev.username=uuplatformdemo
-jdbc.b2c.dev.password=selectuuplatform
-#test
-jdbc.b2c.test.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
-jdbc.b2c.test.username=uuplatformdemo
-jdbc.b2c.test.password=selectuuplatform
-#prod
-jdbc.b2c.prod.url=jdbc:oracle:thin:@10.10.100.200:1521:orcl
-jdbc.b2c.prod.username=platform$b2b
-jdbc.b2c.prod.password=select*fromuu
-#other configuration
-jdbc.b2c.driverClassName=oracle.jdbc.driver.OracleDriver
-jdbc.b2c.initialSize=1
-jdbc.b2c.maxActive=100
-jdbc.b2c.maxIdle=50
-jdbc.b2c.minIdle=50
-jdbc.b2c.suspectTimeout=60
-jdbc.b2c.timeBetweenEvictionRunsMillis=30000
-jdbc.b2c.minEvictableIdleTimeMillis=60000

+ 22 - 0
src/main/resources/test/jdbc-platform.properties

@@ -0,0 +1,22 @@
+#platform
+#dev
+jdbc.platform.dev.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
+jdbc.platform.dev.username=uuplatformdemo
+jdbc.platform.dev.password=selectuuplatform
+#test
+jdbc.platform.test.url=jdbc:oracle:thin:@192.168.253.6:1521:orcl
+jdbc.platform.test.username=uuplatformdemo
+jdbc.platform.test.password=selectuuplatform
+#prod
+jdbc.platform.prod.url=jdbc:oracle:thin:@10.10.100.200:1521:orcl
+jdbc.platform.prod.username=platform$b2b
+jdbc.platform.prod.password=select*fromuu
+#other configuration
+jdbc.platform.driverClassName=oracle.jdbc.driver.OracleDriver
+jdbc.platform.initialSize=1
+jdbc.platform.maxActive=100
+jdbc.platform.maxIdle=50
+jdbc.platform.minIdle=50
+jdbc.platform.suspectTimeout=60
+jdbc.platform.timeBetweenEvictionRunsMillis=30000
+jdbc.platform.minEvictableIdleTimeMillis=60000