소스 검색

下单调整

zxfqwert 1 주 전
부모
커밋
362f6726c8

+ 10 - 3
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/controller/BizWaybillOrderController.java

@@ -5,6 +5,7 @@ import java.util.List;
 import java.io.IOException;
 import javax.servlet.http.HttpServletResponse;
 
+import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.datascope.annotation.DataScope;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -80,10 +81,16 @@ public class BizWaybillOrderController extends BaseController
     @RequiresPermissions("system:order:add")
     @Log(title = "运单管理", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody BizWaybillOrder bizWaybillOrder) throws UnsupportedEncodingException {
+    public AjaxResult add(@RequestBody BizWaybillOrder bizWaybillOrder) {
+        try{
+            return toAjax(bizWaybillOrderService.insertBizWaybillOrder(bizWaybillOrder));
+          }
+         catch(ServiceException e){
+            return AjaxResult.error("下单失败! 原因:"+e.getMessage());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
 
-
-        return toAjax(bizWaybillOrderService.insertBizWaybillOrder(bizWaybillOrder));
     }
 
     /**

+ 5 - 2
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/impl/BizWaybillOrderServiceImpl.java

@@ -73,11 +73,14 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
         String orderId = redisIdGenerator.generateUniqueId("RJSD");
         bizWaybillOrder.setWaybillNo(orderId);
         //前置校验
-       JSONObject jsonObject= logisticsOrderService.precheckOrder(bizWaybillOrder);
+        JSONObject jsonObject= logisticsOrderService.precheckOrder(bizWaybillOrder);
         if(!jsonObject.getBooleanValue("success")){
             throw new ServiceException("下单前置校验未通过! 原因:"+jsonObject.getString("msg"));
+          }
+        JSONObject orderObject= logisticsOrderService.createOrder(bizWaybillOrder);
+        if(!orderObject.getBooleanValue("success")){
+            throw new ServiceException("下单失败! 原因:"+orderObject.getString("msg"));
         }
-        logisticsOrderService.createOrder(bizWaybillOrder);
         bizWaybillOrder.setCreateTime(DateUtils.getNowDate());
         bizWaybillOrder.setUserId(loginUser.getUserid());
         bizWaybillOrder.setDeptId(loginUser.getSysUser().getDeptId());

+ 11 - 2
jd-logistics-modules/jd-logistics-system/src/main/java/com/ruoyi/logistics/service/impl/SFLogisticsService.java

@@ -160,9 +160,18 @@ public class SFLogisticsService implements LogisticsService {
         params.put("msgData", msgData);
         params.put("msgDigest", tools.getMsgDigest(msgData, timeStamp, sfExpressConfig.getCheckWord()));
         String result = HttpClientUtil.post(sfExpressConfig.getCurrentApiUrl(), params);
-        JSONObject jsonObject = JSON.parseObject(result);
+            JSONObject jsonObject = JSON.parseObject(result).getJSONObject("apiResultData");
+            JSONObject resultInfo = new JSONObject();
+            if (jsonObject != null && jsonObject.containsKey("success") && jsonObject.getBooleanValue("success")) {
+                resultInfo.put("success", true);
+                resultInfo.put("msg", "下单成功!");
+                return resultInfo;
+            } else {
+                resultInfo.put("success", false);
+                resultInfo.put("msg", "下单失败!失败原因:"+jsonObject.get("errorMsg"));
+                return resultInfo;
+            }
 
-        return jsonObject;
         }catch(Exception e){
             throw new RuntimeException();
         }