Просмотр исходного кода

Merge branch 'dev' of ssh://10.10.101.21/source/platform-b2c into dev

yujia 8 лет назад
Родитель
Сommit
0b700993e7

+ 1 - 1
src/main/java/com/uas/platform/b2c/common/base/api/FileUploadController.java

@@ -49,7 +49,7 @@ public class FileUploadController {
 		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
 			MultipartFile mf = entity.getValue();
 			try {
-				String path = fileService.save(mf);
+				String path = fileService.save(mf.getOriginalFilename(), mf.getBytes());
 				Map<String, Object> map = new HashMap<String, Object>();
 				map.put("path", path);
 				map.put("fileName", mf.getOriginalFilename());

+ 1 - 2
src/main/java/com/uas/platform/b2c/common/base/api/UploadController.java

@@ -12,7 +12,6 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -43,7 +42,7 @@ public class UploadController {
         for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
             MultipartFile mf = entity.getValue();
             try {
-                IPicture picture = imageService.uploadFile(mf);
+                IPicture picture = imageService.save(mf.getOriginalFilename(), mf.getBytes());
                 pictures.add(picture);
             } catch (Exception e) {
                 e.printStackTrace();

+ 1 - 1
src/main/java/com/uas/platform/b2c/common/base/constant/FileClientConstant.java

@@ -1,4 +1,4 @@
-package com.uas.message.core;
+package com.uas.platform.b2c.common.base.constant;
 
 public class FileClientConstant {
 

+ 0 - 8
src/main/java/com/uas/platform/b2c/common/base/service/FileService.java

@@ -1,7 +1,6 @@
 package com.uas.platform.b2c.common.base.service;
 
 import com.uas.platform.b2c.common.base.model.FileUpload;
-import org.springframework.web.multipart.MultipartFile;
 
 /**
  * 文件上传
@@ -17,13 +16,6 @@ public interface FileService {
      */
     public String save(FileUpload fileUpload);
 
-    /**
-     * 保存文件
-     * @param mf 需要上传的文件
-     * @return 文件路径
-     */
-    public String save(MultipartFile mf);
-
     /**
      * 用户上传文件
      * @param fileName 文件名

+ 0 - 9
src/main/java/com/uas/platform/b2c/common/base/service/ImageService.java

@@ -1,7 +1,6 @@
 package com.uas.platform.b2c.common.base.service;
 
 import com.uas.platform.b2c.common.base.model.IPicture;
-import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.util.List;
@@ -38,12 +37,4 @@ public interface ImageService {
 	 * @return 文件
 	 */
 	public IPicture save(String fileName, byte[] fileBytes);
-
-	/**
-	 * 保存图片
-	 * @param mf MultipartFile 文件的信息
-	 * @return
-	 * @throws Exception
-	 */
-    IPicture uploadFile(MultipartFile mf) throws Exception;
 }

+ 16 - 26
src/main/java/com/uas/platform/b2c/common/base/service/impl/DFSImageServiceImpl.java

@@ -1,19 +1,14 @@
 package com.uas.platform.b2c.common.base.service.impl;
 
-import com.alibaba.fastjson.JSONObject;
 import com.uas.dfs.service.FileClient;
-import com.uas.platform.b2c.common.base.constant.FileUrl;
 import com.uas.platform.b2c.common.base.dao.DBPictureRepository;
 import com.uas.platform.b2c.common.base.model.DBPicture;
 import com.uas.platform.b2c.common.base.model.IPicture;
 import com.uas.platform.b2c.common.base.service.ImageService;
-import com.uas.platform.b2c.core.utils.FastjsonUtils;
-import com.uas.platform.b2c.core.utils.HttpUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.FilenameUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.IOException;
@@ -34,14 +29,9 @@ public class DFSImageServiceImpl implements ImageService {
         List<DBPicture> pictures = new ArrayList<DBPicture>();
         for (File file : files) {
             try {
-                HttpUtils.Response response = HttpUtils.upload(FileUrl.FILE_UPLOAD, file, null);
-                if (response.getStatusCode() == 200) {
-                    JSONObject obj = FastjsonUtils.parseObject(response.getResponseText());
-                    String fileUrl = (String) obj.get("path");
-                    pictures.add(new DBPicture(file.getName(), fileUrl, com.uas.platform.core.util.FileUtils.getImagePixel(file)));
-                } else {
-                    throw new IllegalStateException(response.getResponseText());
-                }
+                String fileUrl = fileClient.uploadImage(FileUtils.readFileToByteArray(file), file.length(),
+                        FilenameUtils.getExtension(file.getName()), null);
+                pictures.add(new DBPicture(file.getName(), fileUrl, com.uas.platform.core.util.FileUtils.getImagePixel(file)));
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -67,18 +57,18 @@ public class DFSImageServiceImpl implements ImageService {
         return pictureRepository.save(new DBPicture(fileName, fileUrl, com.uas.platform.core.util.FileUtils.getImagePixel(fileBytes)));
     }
 
-    @Override
-    public IPicture uploadFile(MultipartFile mf) throws Exception {
-        HttpUtils.Response response = HttpUtils.upload(FileUrl.FILE_UPLOAD, mf, null);
-        if (response.getStatusCode() == 200) {
-            JSONObject obj = FastjsonUtils.parseObject(response.getResponseText());
-
-            String fileName = mf.getOriginalFilename();
-            String fileUrl = (String) obj.get("path");
-            return pictureRepository.save(new DBPicture(fileName, fileUrl, com.uas.platform.core.util.FileUtils.getImagePixel(mf.getBytes())));
-        } else {
-            throw new IllegalStateException(response.getResponseText());
-        }
-    }
+//    @Override
+//    public IPicture uploadFile(MultipartFile mf) throws Exception {
+//        HttpUtils.Response response = HttpUtils.upload(FileUrl.FILE_UPLOAD, mf, null);
+//        if (response.getStatusCode() == 200) {
+//            JSONObject obj = FastjsonUtils.parseObject(response.getResponseText());
+//
+//            String fileName = mf.getOriginalFilename();
+//            String fileUrl = (String) obj.get("path");
+//            return pictureRepository.save(new DBPicture(fileName, fileUrl, com.uas.platform.core.util.FileUtils.getImagePixel(mf.getBytes())));
+//        } else {
+//            throw new IllegalStateException(response.getResponseText());
+//        }
+//    }
 
 }

+ 3 - 3
src/main/java/com/uas/platform/b2c/common/base/service/impl/FileClientImpl.java

@@ -1,12 +1,12 @@
-package com.uas.message.core;
+package com.uas.platform.b2c.common.base.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.uas.dfs.domain.FileInfo;
 import com.uas.dfs.domain.MetaData;
 import com.uas.dfs.service.FileClient;
+import com.uas.platform.b2c.common.base.constant.FileClientConstant;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ByteArrayResource;
-import org.springframework.core.io.FileSystemResource;
 import org.springframework.http.*;
 import org.springframework.stereotype.Service;
 import org.springframework.util.LinkedMultiValueMap;
@@ -29,7 +29,7 @@ public class FileClientImpl implements FileClient {
     }
 
     @Override
-    public String upload(byte[] bytes, long l, String s, Set<MetaData> set) {
+    public String upload(byte[] bytes, long l, final String s, Set<MetaData> set) {
         HttpHeaders headers = new HttpHeaders();
         MediaType type = MediaType.parseMediaType("multipart/form-data;charset=UTF-8");
         headers.setContentType(type);

+ 2 - 31
src/main/java/com/uas/platform/b2c/common/base/service/impl/FileServiceImpl.java

@@ -1,17 +1,12 @@
 package com.uas.platform.b2c.common.base.service.impl;
 
-import com.alibaba.fastjson.JSONObject;
 import com.uas.dfs.service.FileClient;
-import com.uas.platform.b2c.common.base.constant.FileUrl;
 import com.uas.platform.b2c.common.base.model.FileUpload;
 import com.uas.platform.b2c.common.base.service.FileService;
-import com.uas.platform.b2c.core.utils.FastjsonUtils;
-import com.uas.platform.b2c.core.utils.HttpUtils;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import org.apache.commons.io.FilenameUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
 @Service
@@ -25,32 +20,8 @@ public class FileServiceImpl implements FileService {
 		CommonsMultipartFile file = fileUpload.getFile();
 		try {
 			// 上传到文件系统
-			HttpUtils.Response response = HttpUtils.upload(FileUrl.FILE_UPLOAD, file, null);
-			if (response.getStatusCode() == 200) {
-				JSONObject obj = FastjsonUtils.parseObject(response.getResponseText());
-				String fileUrl = (String) obj.get("path");
-				return fileUrl;
-			} else {
-				throw new IllegalStateException(response.getResponseText());
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-			throw new IllegalOperatorException("附件上传失败");
-		}
-	}
-
-	@Override
-	public String save(MultipartFile mf) {
-		try {
-            HttpUtils.Response response = HttpUtils.upload(FileUrl.FILE_UPLOAD, mf, null);
-            if (response.getStatusCode() == 200) {
-                JSONObject obj = FastjsonUtils.parseObject(response.getResponseText());
-
-                String fileUrl = (String) obj.get("path");
-                return fileUrl;
-            }else {
-                throw new IllegalStateException(response.getResponseText());
-            }
+			return fileClient.upload(file.getBytes(), file.getSize(),
+					FilenameUtils.getExtension(file.getOriginalFilename()), null);
 		} catch (Exception e) {
 			e.printStackTrace();
 			throw new IllegalOperatorException("附件上传失败");

+ 1 - 2
src/main/resources/spring/context.xml

@@ -187,8 +187,7 @@
 		init-method="init">
 		<property name="configPath" value="classpath:${profile}/account.properties" />
 	</bean>
-	
-	<import resource="classpath:spring/dubbo-consumer.xml"/>
+
 	<import resource="classpath:spring/ehcache.xml"/>
 	<import resource="classpath:spring/jpa.xml"/>
 	<import resource="classpath:spring/redis.xml"/>

+ 27 - 25
src/test/java/com/uas/platform/b2c/RegistForMall.java

@@ -1,34 +1,36 @@
 package com.uas.platform.b2c;
 
-import com.alibaba.fastjson.JSON;
-import com.uas.account.entity.UserSpaceDetail;
-import com.uas.sso.common.util.HttpUtil;
-import com.uas.sso.common.util.HttpUtil.ResponseWrap;
-import org.springframework.ui.ModelMap;
-import org.springframework.util.StringUtils;
+import com.alibaba.dubbo.common.json.JSONObject;
+import com.uas.platform.b2c.core.utils.FastjsonUtils;
+import org.apache.commons.collections.map.HashedMap;
 
-import java.util.Date;
+import java.util.ArrayList;
+import java.util.Map;
 
 public class RegistForMall {
 
 	public static void main(String args[]) throws Exception {
-		UserSpaceDetail detail = new UserSpaceDetail();
-		detail.setName("B2B公司研发测试数据-不要购买-wangyuchao");
-		detail.setShortName("B2B公司");
-		detail.setAdminName("余佳");
-		detail.setAdminTel("15989329613");
-		detail.setAdminEmail("yuj@usoftchina.com");
-		detail.setBusinessCode("11122233344456789");
-		detail.setRegisterDate(new Date().getTime());
-		detail.setTel("15989329613");
-		detail.setFax("11-2222222");
-		String url = "http://113.105.74.135:8001/api/userspace";
-		if (!StringUtils.isEmpty(url)) {
-			ResponseWrap res = HttpUtil.doPost(url,
-					new ModelMap("_operate", "registForMall").addAttribute("detail", JSON.toJSON(detail)));
-			System.out.println(res.getContent());
-			if (!res.isSuccess())
-				throw new Exception(res.getContent());
-		}
+//		UserSpaceDetail detail = new UserSpaceDetail();
+//		detail.setName("B2B公司研发测试数据-不要购买-wangyuchao");
+//		detail.setShortName("B2B公司");
+//		detail.setAdminName("余佳");
+//		detail.setAdminTel("15989329613");
+//		detail.setAdminEmail("yuj@usoftchina.com");
+//		detail.setBusinessCode("11122233344456789");
+//		detail.setRegisterDate(new Date().getTime());
+//		detail.setTel("15989329613");
+//		detail.setFax("11-2222222");
+//		String url = "http://113.105.74.135:8001/api/userspace";
+//		if (!StringUtils.isEmpty(url)) {
+//			ResponseWrap res = HttpUtil.doPost(url,
+//					new ModelMap("_operate", "registForMall").addAttribute("detail", JSON.toJSON(detail)));
+//			System.out.println(res.getContent());
+//			if (!res.isSuccess())
+//				throw new Exception(res.getContent());
+//		}
+		Map<String ,Object> map = new HashedMap();
+		map.put("OK", new Object());
+		System.out.println(FastjsonUtils.toJson(map));
+		System.out.println(new ArrayList<>());
 	}
 }