WANG 6 lat temu
rodzic
commit
227f17fffe

+ 15 - 10
src/main/java/cn/com/qmth/examcloud/web/cloud/CloudClientSupport.java

@@ -15,6 +15,7 @@ import org.springframework.util.MultiValueMap;
 import org.springframework.web.client.RestTemplate;
 
 import cn.com.qmth.examcloud.api.commons.exchange.BaseRequest;
+import cn.com.qmth.examcloud.api.commons.exchange.FormRequest;
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
 import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
@@ -252,26 +253,30 @@ public abstract class CloudClientSupport {
 	 *
 	 * @author WANGWEI
 	 * @param requestMapping
-	 * @param params
+	 * @param req
 	 * @param file
 	 * @param responseType
 	 * @return
 	 * @throws Exception
 	 */
-	public <T> T postForm(String appName, String requestMapping, Map<String, String> params,
-			File file, Class<T> responseType) {
+	public <T> T postForm(String appName, String requestMapping, FormRequest req,
+			Class<T> responseType) {
 		String url = buildUrl(appName, requestMapping);
 
-		MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
-		FileSystemResource resource = new FileSystemResource(file);
-		param.add("file", resource);
-		param.add("fileName", file.getName());
+		MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
+		FileSystemResource resource = new FileSystemResource(new File(req.getFilePath()));
+		params.add("file", resource);
+
+		String json = JsonUtil.toJson(req);
+		Map<String, String> otherParams = JsonUtil.json2Map(json);
+		otherParams.remove("file");
+		otherParams.remove("filePath");
 
-		for (Entry<String, String> entry : params.entrySet()) {
-			param.add(entry.getKey(), entry.getValue());
+		for (Entry<String, String> entry : otherParams.entrySet()) {
+			params.add(entry.getKey(), entry.getValue());
 		}
 
-		return exchange(url, HttpMethod.POST, param, responseType);
+		return exchange(url, HttpMethod.POST, params, responseType);
 	}
 
 }