Ver código fonte

95:红德堂APP调试 新增根据ID集合查询购物车接口

Long 1 dia atrás
pai
commit
a39e56a55b

+ 2 - 2
fs-service/src/main/java/com/fs/his/mapper/FsIntegralCartMapper.java

@@ -24,8 +24,8 @@ public interface FsIntegralCartMapper extends BaseMapper<FsIntegralCart> {
 
     /**
      * 获取购物车列表
-     * @param userId    用户ID
+     * @param params    参数
      * @return  list
      */
-    List<FsIntegralCartVO> getCartsByUserId(@Param("userId") Long userId);
+    List<FsIntegralCartVO> getCartsByMap(@Param("params") Map<String, Object> params);
 }

+ 9 - 0
fs-service/src/main/java/com/fs/his/service/IFsIntegralCartService.java

@@ -1,6 +1,7 @@
 package com.fs.his.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fs.common.core.domain.R;
 import com.fs.his.domain.FsIntegralCart;
 import com.fs.his.vo.FsIntegralCartVO;
 
@@ -40,4 +41,12 @@ public interface IFsIntegralCartService extends IService<FsIntegralCart> {
      * @return  list
      */
     List<FsIntegralCartVO> getCartsByUserId(Long userId);
+
+    /**
+     * 根据购物车ID查询详情
+     * @param userId    用户ID
+     * @param ids       购物车ID集合
+     * @return  list
+     */
+    List<FsIntegralCartVO> getCartByIds(Long userId, List<Long> ids);
 }

+ 18 - 3
fs-service/src/main/java/com/fs/his/service/impl/FsIntegralCartServiceImpl.java

@@ -1,7 +1,6 @@
 package com.fs.his.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.exception.CustomException;
@@ -19,7 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
-import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -102,6 +101,22 @@ public class FsIntegralCartServiceImpl extends ServiceImpl<FsIntegralCartMapper,
      */
     @Override
     public List<FsIntegralCartVO> getCartsByUserId(Long userId) {
-        return baseMapper.getCartsByUserId(userId);
+        Map<String, Object> params = new HashMap<>();
+        params.put("userId", userId);
+        return baseMapper.getCartsByMap(params);
+    }
+
+    /**
+     * 根据购物车ID查询详情
+     * @param userId    用户ID
+     * @param ids       购物车ID集合
+     * @return  list
+     */
+    @Override
+    public List<FsIntegralCartVO> getCartByIds(Long userId, List<Long> ids) {
+        Map<String, Object> params = new HashMap<>();
+        params.put("userId", userId);
+        params.put("ids", ids);
+        return baseMapper.getCartsByMap(params);
     }
 }

+ 13 - 3
fs-service/src/main/resources/mapper/his/FsIntegralCartMapper.xml

@@ -38,12 +38,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 ic.user_id = #{params.userId}
             </if>
             <if test="params.goodsId != null">
-                ic.goods_id = #{params.goodsId}
+                and ic.goods_id = #{params.goodsId}
             </if>
         </where>
     </select>
 
-    <select id="getCartsByUserId" resultType="com.fs.his.vo.FsIntegralCartVO">
+    <select id="getCartsByMap" resultType="com.fs.his.vo.FsIntegralCartVO">
         select
             ic.id,
             ic.goods_id,
@@ -58,6 +58,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             ic.update_time
         from fs_integral_cart ic
         inner join fs_integral_goods ig on ig.goods_id = ic.goods_id
-        where ic.user_id = #{userId}
+        <where>
+            <if test="params.userId != null">
+                ic.user_id = #{params.userId}
+            </if>
+            <if test="params.ids != null and params.ids.size() > 0">
+                and ic.id in
+                <foreach collection="params.ids" item="id" open="(" close=")" separator=",">
+                    #{id}
+                </foreach>
+            </if>
+        </where>
     </select>
 </mapper>

+ 7 - 0
fs-user-app/src/main/java/com/fs/app/controller/IntegralController.java

@@ -237,6 +237,13 @@ public class IntegralController extends  AppBaseController {
         return R.ok().put("carts", cartService.getCartsByUserId(Long.parseLong(getUserId())));
     }
 
+    @Login
+    @ApiOperation("根据ID集合查询购物车")
+    @PostMapping("/getCartByIds")
+    public R getCartByIds(@RequestBody List<Long> ids) {
+        return R.ok().put("data", cartService.getCartByIds(Long.parseLong(getUserId()), ids));
+    }
+
     @Login
     @ApiOperation("创建购物车订单")
     @PostMapping("/createCartOrder")