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

【分期付款】-- 修改验证分期信息返回值类型

wangyc 8 лет назад
Родитель
Сommit
30747c6156

+ 4 - 3
src/main/java/com/uas/platform/b2c/fa/payment/controller/InstallmentController.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.uas.platform.b2c.core.utils.FastjsonUtils;
 import com.uas.platform.b2c.fa.payment.model.Installment;
 import com.uas.platform.b2c.fa.payment.service.InstallmentService;
+import com.uas.platform.b2c.trade.support.ResultMap;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -55,8 +56,8 @@ public class InstallmentController {
      * @param purchaseId 采购单id
      */
     @RequestMapping(value = "/{purchaseId}", method = RequestMethod.DELETE)
-    public void deleteInstallment(@PathVariable("purchaseId") Long purchaseId) {
-        installmentService.deleteInstallment(purchaseId);
+    public ResultMap deleteInstallment(@PathVariable("purchaseId") Long purchaseId) {
+        return installmentService.deleteInstallment(purchaseId);
     }
 
     /**
@@ -65,7 +66,7 @@ public class InstallmentController {
      * @return
      */
     @RequestMapping(value = "/{purchaseId}/validate", method = RequestMethod.GET)
-    public String validateEnableInstallment(@PathVariable("purchaseId") Long purchaseId) {
+    public ResultMap validateEnableInstallment(@PathVariable("purchaseId") Long purchaseId) {
         return installmentService.validationEnableInstallment(purchaseId);
     }
 }

+ 3 - 2
src/main/java/com/uas/platform/b2c/fa/payment/service/InstallmentService.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2c.fa.payment.service;
 
 import com.uas.platform.b2c.fa.payment.model.BankTransfer;
 import com.uas.platform.b2c.fa.payment.model.Installment;
+import com.uas.platform.b2c.trade.support.ResultMap;
 
 /**
  * 分期支付service
@@ -39,14 +40,14 @@ public interface InstallmentService {
      * 删除分期信息
      * @param purchaseId
      */
-    void deleteInstallment(Long purchaseId);
+    ResultMap deleteInstallment(Long purchaseId);
 
     /**
      * 验证卖家是否能够设置分期信息
      * @param purchaseId
      * @return
      */
-    String validationEnableInstallment(Long purchaseId);
+    ResultMap validationEnableInstallment(Long purchaseId);
 
     /**
      * 采购单改价后更新分期信息

+ 55 - 26
src/main/java/com/uas/platform/b2c/fa/payment/service/impl/InstallmentServiceImpl.java

@@ -21,6 +21,8 @@ import com.uas.platform.b2c.trade.order.dao.PurchaseDetailDao;
 import com.uas.platform.b2c.trade.order.model.Order;
 import com.uas.platform.b2c.trade.order.model.Purchase;
 import com.uas.platform.b2c.trade.order.model.PurchaseDetail;
+import com.uas.platform.b2c.trade.support.CodeType;
+import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.exception.IllegalOperatorException;
 import com.uas.platform.core.util.mq.MessageType;
 import org.apache.commons.collections.CollectionUtils;
@@ -238,8 +240,12 @@ public class InstallmentServiceImpl implements InstallmentService{
     }
 
     @Override
-    public void deleteInstallment(Long purchaseId) {
-        validatePurchase(purchaseId);
+    public ResultMap deleteInstallment(Long purchaseId) {
+        ResultMap resultMap = validatePurchase(purchaseId);// 验证采购订单
+        if (1 != resultMap.getCode()) {// 验证错误
+            return resultMap;
+        }
+
         Purchase purchase = purchaseDao.findOne(purchaseId);
         Order order = orderDao.findByOrderid(purchase.getOrderid());
 
@@ -254,6 +260,7 @@ public class InstallmentServiceImpl implements InstallmentService{
         purchaseDao.save(purchase);
 
         installmentDao.delete(installment.getId());
+        return resultMap;
     }
 
     @Override
@@ -316,17 +323,27 @@ public class InstallmentServiceImpl implements InstallmentService{
     }
 
     @Override
-    public String validationEnableInstallment(Long purchaseId) {
-        validatePurchase(purchaseId);// 验证采购单、订单信息
-        validateBankInfo(Type.SUP.value(), Status.ALLOW.value());// 验证银行账户信息
-        validateInstallmentStore();// 验证是否设置分期权限
-        return "success";
+    public ResultMap validationEnableInstallment(Long purchaseId) {
+        ResultMap resultMap = validatePurchase(purchaseId);// 验证采购单、订单信息 return error code 5 7 6
+        if (1 != resultMap.getCode()) {
+            return resultMap;
+        }
+
+        resultMap = validateBankInfo(Type.SUP.value(), Status.ALLOW.value());// 验证银行账户信息 return error code 3
+        if (1 != resultMap.getCode()) {
+            return resultMap;
+        }
+
+        resultMap = validateInstallmentStore();// 验证是否设置分期权限 return error code 13
+        return resultMap;
     }
 
-    void validateInstallmentStore() {
+    ResultMap validateInstallmentStore() {
         InstallmentStore installmentStore = installmentStoreDao.findByEnuuAndEnable(SystemSession.getUser().getEnterprise().getUu(), (short) 1);
-        if (installmentStore == null)
-            throw new IllegalOperatorException("当前企业没有设置分期功能权限,如有需要请联系客服");
+        if (installmentStore == null) {
+            return new ResultMap(CodeType.NO_AUTHORITY.code(), "当前企业没有设置分期功能权限,如有需要请联系客服");
+        }
+        return ResultMap.success(null);
     }
 
     /**
@@ -334,32 +351,44 @@ public class InstallmentServiceImpl implements InstallmentService{
      * @param type
      * @param status
      */
-    void validateBankInfo(Integer type, Integer status) {
+    ResultMap validateBankInfo(Integer type, Integer status) {
         List<BankInfo> bankInfos = bankInfoService.getEnterpriseBankInfoContainsStatus(type, status);
-        if (CollectionUtils.isEmpty(bankInfos))
-            throw new IllegalOperatorException("当前企业没有设置收款账户,请在 结算中心--收款账户信息 管理您的收款账户信息");
+        if (CollectionUtils.isEmpty(bankInfos)) {
+            return new ResultMap(CodeType.NOT_COMPLETE_INFO.code(), "当前企业没有设置收款账户,请在 结算中心--收款账户信息 管理您的收款账户信息");
+        }
+        return ResultMap.success(null);
     }
 
     /**
      * 验证采购单、订单信息
      * @param purchaseId
      */
-    void validatePurchase(Long purchaseId) {
-        if (SystemSession.getUser().getEnterprise() == null)
-            throw new IllegalOperatorException("当前账户为个人账户,请选择企业后再执行此操作");
+    ResultMap validatePurchase(Long purchaseId) {
+        if (SystemSession.getUser().getEnterprise() == null) {
+            return new ResultMap(CodeType.ERROR_STATE.code(), "当前账户为个人账户,请选择企业后再执行此操作");
+        }
 
         Purchase purchase = purchaseDao.findOne(purchaseId);
-        if (purchase == null)
-            throw new IllegalOperatorException("订单不存在,请重新确认订单信息");
-        if (!SystemSession.getUser().getEnterprise().getUu().equals(purchase.getSellerenuu()))
-            throw new IllegalOperatorException("此订单不属于当前企业,请重新确认订单信息");
-        if (Status.TOBECONFIRMED.value() != purchase.getStatus().intValue())
-            throw new IllegalOperatorException("此订单状态不为待付款,不可修改分期信息");
+        if (purchase == null) {
+            return new ResultMap(CodeType.NOT_EXiST.code(), "订单不存在,请重新确认订单信息");
+        }
+
+        if (!SystemSession.getUser().getEnterprise().getUu().equals(purchase.getSellerenuu())) {
+            return new ResultMap(CodeType.NOT_PERMIT.code(), "此订单不属于当前企业,请重新确认订单信息");
+        }
+
+        if (Status.TOBECONFIRMED.value() != purchase.getStatus().intValue()) {
+            return new ResultMap(CodeType.ERROR_STATE.code(), "此订单状态不为待付款,不可修改分期信息");
+        }
 
         Order order = orderDao.findByOrderid(purchase.getOrderid());
-        if (order == null)
-            throw new IllegalOperatorException("订单不存在,请重新确认订单信息");
-        if (Status.TOBEPAID.value() != order.getStatus().intValue() && Status.TOBECONFIRMED.value() != order.getStatus().intValue())
-            throw new IllegalOperatorException("此订单状态不为待付款,不可修改分期信息");
+        if (order == null) {
+            return new ResultMap(CodeType.NOT_EXiST.code(), "订单不存在,请重新确认订单信息");
+        }
+        if (Status.TOBEPAID.value() != order.getStatus().intValue() && Status.TOBECONFIRMED.value() != order.getStatus().intValue()) {
+            return new ResultMap(CodeType.ERROR_STATE.code(), "此订单状态不为待付款,不可修改分期信息");
+        }
+
+        return ResultMap.success(null);
     }
 }

+ 6 - 1
src/main/java/com/uas/platform/b2c/trade/support/CodeType.java

@@ -58,7 +58,12 @@ public enum CodeType {
 	/**
 	 * 超时请求
 	 */
-	TIME_OUT(12, "TIME_OUT");
+	TIME_OUT(12, "TIME_OUT"),
+
+	/**
+	 * 无操作权限
+	 */
+	NO_AUTHORITY(13, "NO_AUTHORITY");
 
 	private int code;