Browse Source

fixed 增强购物车代码健壮性

fushengqian 1 year ago
parent
commit
3319d4c613

+ 7 - 0
fuint-application/src/main/java/com/fuint/common/service/CartService.java

@@ -29,6 +29,7 @@ public interface CartService extends IService<MtCart> {
      * @param reqDto
      * @param action + or - or =
      * @throws BusinessCheckException
+     * @return
      */
     Integer saveCart(MtCart reqDto, String action) throws BusinessCheckException;
 
@@ -37,6 +38,7 @@ public interface CartService extends IService<MtCart> {
      *
      * @param cartIds 购物车ID
      * @throws BusinessCheckException
+     * @return
      */
     void removeCart(String cartIds) throws BusinessCheckException;
 
@@ -45,6 +47,7 @@ public interface CartService extends IService<MtCart> {
      *
      * @param  hangNo 挂单序号
      * @throws BusinessCheckException
+     * @return
      */
     void removeCartByHangNo(String hangNo) throws BusinessCheckException;
 
@@ -53,11 +56,15 @@ public interface CartService extends IService<MtCart> {
      *
      * @param userId 会员ID
      * @throws BusinessCheckException
+     * @return
      */
     void clearCart(Integer userId) throws BusinessCheckException;
 
     /**
      * 根据条件查找
+     *
+     * @param params 查询参数
+     * @return
      * */
     List<MtCart> queryCartListByParams(Map<String, Object> params) throws BusinessCheckException;
 

+ 2 - 0
fuint-application/src/main/java/com/fuint/common/service/MemberService.java

@@ -25,6 +25,7 @@ public interface MemberService extends IService<MtUser> {
 
     /**
      * 更新活跃时间
+     *
      * @param userId 会员ID
      * @return
      * */
@@ -32,6 +33,7 @@ public interface MemberService extends IService<MtUser> {
 
     /**
      * 获取当前操作会员信息
+     *
      * @param userId
      * @param accessToken
      * @return

+ 2 - 2
fuint-application/src/main/java/com/fuint/common/service/OrderService.java

@@ -90,12 +90,12 @@ public interface OrderService extends IService<MtOrder> {
     /**
      * 根据订单ID删除
      *
-     * @param  id       ID
+     * @param  orderId 订单ID
      * @param  operator 操作人
      * @throws BusinessCheckException
      * @return
      */
-    void deleteOrder(Integer id, String operator) throws BusinessCheckException;
+    void deleteOrder(Integer orderId, String operator) throws BusinessCheckException;
 
     /**
      * 根据订单号获取订单

+ 22 - 0
fuint-application/src/main/java/com/fuint/common/service/impl/CartServiceImpl.java

@@ -71,9 +71,18 @@ public class CartServiceImpl extends ServiceImpl<MtCartMapper, MtCart> implement
      *
      * @param  reqDto
      * @throws BusinessCheckException
+     * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public Integer saveCart(MtCart reqDto, String action) throws BusinessCheckException {
+        if (reqDto.getId() == null && (reqDto.getMerchantId() == null || reqDto.getMerchantId() < 1)) {
+            throw new BusinessCheckException("商户不能为空");
+        }
+        if (reqDto.getId() == null && (reqDto.getStoreId() == null || reqDto.getStoreId() < 1)) {
+            throw new BusinessCheckException("店铺不能为空");
+        }
+
         MtCart mtCart = new MtCart();
         Integer cartId = 1;
 
@@ -190,8 +199,10 @@ public class CartServiceImpl extends ServiceImpl<MtCartMapper, MtCart> implement
      *
      * @param  cartIds
      * @throws BusinessCheckException
+     * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void removeCart(String cartIds) {
         String[] ids = cartIds.split(",");
         if (ids.length < 1) {
@@ -210,9 +221,11 @@ public class CartServiceImpl extends ServiceImpl<MtCartMapper, MtCart> implement
      *
      * @param  hangNo 挂单序号
      * @throws BusinessCheckException
+     * @return
      */
     @Override
     @OperationServiceLog(description = "删除挂单")
+    @Transactional(rollbackFor = Exception.class)
     public void removeCartByHangNo(String hangNo) {
         if (hangNo != null && StringUtil.isNotEmpty(hangNo)) {
             mtCartMapper.deleteCartByHangNo(hangNo);
@@ -224,12 +237,20 @@ public class CartServiceImpl extends ServiceImpl<MtCartMapper, MtCart> implement
      *
      * @param userId
      * @throws BusinessCheckException
+     * @return
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void clearCart(Integer userId) {
        mtCartMapper.clearCart(userId);
     }
 
+    /**
+     * 根据条件查找
+     *
+     * @param params 查询参数
+     * @return
+     * */
     @Override
     public List<MtCart> queryCartListByParams(Map<String, Object> params) {
         String status =  params.get("status") == null ? StatusEnum.ENABLED.getKey() : params.get("status").toString();
@@ -283,6 +304,7 @@ public class CartServiceImpl extends ServiceImpl<MtCartMapper, MtCart> implement
      */
     @Override
     @OperationServiceLog(description = "执行挂单")
+    @Transactional(rollbackFor = Exception.class)
     public MtCart setHangNo(Integer cartId, String hangNo, String isVisitor) {
         MtCart mtCart = mtCartMapper.selectById(cartId);
         if (mtCart != null) {