xubh 4 年之前
父节点
当前提交
7499c57152

+ 2 - 1
src/main/java/com/minpay/common/service/IPublicService.java

@@ -158,11 +158,12 @@ public interface IPublicService extends IMINLocalService, IMINInitializer {
 	 * @param fileType 文件类型,用于区分文件路径上传
 	 * @param size 缓冲区 默认512,大文件需要手动修改
 	 * @param renameFlag 是否重命名
+	 * @param v01
 	 * @return
 	 * @throws MINBusinessException
 	 * @throws BusinessCodeException
 	 */
-	public Map<String, Object> uploadFile(FileItem file,String fileType,int size,boolean renameFlag) throws MINBusinessException,BusinessCodeException;
+	public Map<String, Object> uploadFileBD(FileItem file, String fileType, int size, boolean renameFlag, String v01) throws MINBusinessException,BusinessCodeException;
 	
 	
 	/**

+ 29 - 3
src/main/java/com/minpay/common/service/impl/PublicServiceImpl.java

@@ -334,13 +334,35 @@ public class PublicServiceImpl implements IPublicService {
 	 * @throws MINBusinessException
 	 * @throws BusinessCodeException
 	 */
-	public Map<String, Object> uploadFile(FileItem file, String fileType, int size, boolean renameFlag)
+	public Map<String, Object> uploadFileBD(FileItem file, String fileType, int size, boolean renameFlag,String channel)
 			throws MINBusinessException, BusinessCodeException {
 		String savePath = System.getProperty("catalina.home") + File.separator + "webapps" + File.separator + "upload"
 				+ File.separator;
+
+		//文件目录
+		String fileTypePath = Service.lookup(IPublicService.class)
+				.getSysParValue(channel+"_FILE_PATH_" + fileType);
+		// 获取当前时间
+		String nowDate = DateUtil.format(new Date(), "yyyyMMdd");
+		// 获取根路径(nginx文件服务器路径)
+		String basePath = Service.lookup(IPublicService.class)
+				.getSysParValue(channel+"_FILE_SERVER_BASE_PATH");// 为nginx根路径
+		savePath = basePath.concat(fileTypePath).concat(nowDate).concat("/");
+
+		// 获取web服务器访问路径
+		String baseUrl = Service.lookup(IPublicService.class)
+				.getSysParValue(channel+"_FILE_SERVER_URL"); // 为nginx访问路径
+		baseUrl = baseUrl.concat(fileTypePath).concat(nowDate).concat("/");
+
 		File files = new File(savePath);
+
 		if (!files.exists()) {
-			files.mkdir();
+			boolean file_true = files.mkdir();
+			if (file_true) {
+				System.out.println("文件夹建立成功");
+			} else {
+				System.out.println("文件建立失败");
+			}
 		}
 		FileOutputStream fs = null;
 		InputStream in = null;
@@ -351,13 +373,17 @@ public class PublicServiceImpl implements IPublicService {
 			fs = new FileOutputStream(saveUrl);
 			in = file.getInputStream();
 			FileCopyUtils.copy(in, fs);
+			in.close();
+			fs.flush();
+			fs.close();
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
+
 		double width = -1; // 记录图片宽度
 		double height = -1; // 记录图片的高度
 
-		String baseUrl = Service.lookup(IPublicService.class).getSysParValue("FILE_SERVER_URL"); // 为nginx访问路径
+		//String baseUrl = Service.lookup(IPublicService.class).getSysParValue("FILE_SERVER_URL"); // 为nginx访问路径
 		Map<String, Object> map = new HashMap<String, Object>();
 		map.put("url", baseUrl + fileName);
 		map.put("width", width);

+ 9 - 1
src/main/java/com/minpay/huicai/system/action/FileManageAction.java

@@ -70,9 +70,17 @@ public class FileManageAction implements IMINAction {
 		if (size < 0) {
 			throw new MINBusinessException("size参数异常,size不能小于0");
 		}
+		String ambient = Service.lookup(IPublicService.class)
+				.getSysParValue("AMBIENT");//当前环境
+		Map<String, Object> map = null;
+		if("00".equals(ambient)){//测试
+			 map =Service.lookup(IPublicService.class).uploadFile(file, fileType, 0, true,"V01");
+		}
+		if("01".equals(ambient)){//生产
+			map =Service.lookup(IPublicService.class).uploadFileBD(file, fileType, 0, true,"V01");
+		}
 
 		//Map<String, Object> map = Service.lookup(IPublicService.class).uploadFile(file, fileType, 0, true);
-		Map<String, Object> map =Service.lookup(IPublicService.class).uploadFile(file, fileType, 0, true,"V01");
 
 		if ("00".equals(fileType) && !CommonUtil.isEmpty(proportion)) {
 			double minRatio = -1;