Browse Source

应收对账异常处理

chenw 7 years ago
parent
commit
bb5e9fefac

+ 38 - 11
applications/sale/sale-server/src/main/java/com/usoftchina/saas/sale/service/impl/ApCheckServiceImpl.java

@@ -18,14 +18,13 @@ import com.usoftchina.saas.utils.ObjectUtils;
 import com.usoftchina.saas.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.ModelMap;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.HttpServerErrorException;
 
 import java.net.URLEncoder;
 import java.util.*;
-import java.util.function.Consumer;
 import java.util.stream.Collectors;
 
 /**
@@ -87,7 +86,11 @@ public class ApCheckServiceImpl implements ApCheckService {
                 response.put("content", result);
                 response.put("totalElement", result.size());
             }
-        } catch (Exception e) {
+        } catch (HttpServerErrorException e) {
+            HttpServerErrorException httpServerErrorException = (HttpServerErrorException) e;
+            String responseText = httpServerErrorException.getResponseBodyAsString();
+            throw new BizException(80000, responseText);
+        } catch (Exception e){
             throw new BizException(80000, e.getMessage());
         }
         return response;
@@ -132,7 +135,13 @@ public class ApCheckServiceImpl implements ApCheckService {
             result.put("items", apCheckProdIO.getDetails().stream().filter(apCheckProdIODetail -> currency.equals(apCheckProdIODetail.getCurrency())).collect(Collectors.toList()));
             result.put("data", apCheckProdIO);
         } catch (Exception e) {
-            throw new BizException(80000, e.getMessage());
+            if (e instanceof HttpServerErrorException){
+                HttpServerErrorException httpServerErrorException = (HttpServerErrorException) e;
+                String responseText = httpServerErrorException.getResponseBodyAsString();
+                throw new BizException(80000, responseText);
+            }else {
+                throw new BizException(80000, e.getMessage());
+            }
         }
         return result;
     }
@@ -190,7 +199,7 @@ public class ApCheckServiceImpl implements ApCheckService {
     public ModelMap operationSave(SaveOperationData saveOperationData) {
         Result<AccountDTO> accountResult = accountApi.getAccountById(BaseContextHolder.getUserId());
         Result<CompanyDTO> companyResult = companyApi.getCompanyById(BaseContextHolder.getCompanyId());
-        ModelMap result = null;
+        ResponseEntity<String> responseEntity = null;
         if (accountResult.isSuccess() && companyResult.isSuccess()) {
             Long userUU = accountResult.getData().getUu();
             Long enUU = companyResult.getData().getUu();
@@ -202,12 +211,18 @@ public class ApCheckServiceImpl implements ApCheckService {
             //String url = "http://10.1.51.139:8889" + SAVEAPCHECKURL;
             saveOperationData.setEnUu(enUU);
             try {
-                result = AccessUtils.postForObject(url, account, ModelMap.class, URLEncoder.encode(JsonUtils.toJsonString(saveOperationData), "UTF-8"));
+                responseEntity = AccessUtils.postForEntity(url, account, URLEncoder.encode(JsonUtils.toJsonString(saveOperationData), "UTF-8"));
             } catch (Exception e){
-                throw new BizException(80000, e.getMessage());
+                if (e instanceof HttpServerErrorException){
+                    HttpServerErrorException httpServerErrorException = (HttpServerErrorException) e;
+                    String responseText = httpServerErrorException.getResponseBodyAsString();
+                    throw new BizException(80000, responseText);
+                }else {
+                    throw new BizException(80000, e.getMessage());
+                }
             }
         }
-        return result;
+        return null;
     }
 
     @Override
@@ -227,7 +242,13 @@ public class ApCheckServiceImpl implements ApCheckService {
             response.remove("items");
             result.put("main", response);
         } catch (Exception e){
-            throw new BizException(80000, e.getMessage());
+            if (e instanceof HttpServerErrorException){
+                HttpServerErrorException httpServerErrorException = (HttpServerErrorException) e;
+                String responseText = httpServerErrorException.getResponseBodyAsString();
+                throw new BizException(80000, responseText);
+            }else {
+                throw new BizException(80000, e.getMessage());
+            }
         }
         return result;
     }
@@ -249,7 +270,13 @@ public class ApCheckServiceImpl implements ApCheckService {
             }
             result = AccessUtils.getForObject(url, account, SPage.class);
         } catch (Exception e) {
-            throw new BizException(80000, e.getMessage());
+            if (e instanceof HttpServerErrorException){
+                HttpServerErrorException httpServerErrorException = (HttpServerErrorException) e;
+                String responseText = httpServerErrorException.getResponseBodyAsString();
+                throw new BizException(80000, responseText);
+            }else {
+                throw new BizException(80000, e.getMessage());
+            }
         }
         return result;
     }