后端 + 前端:购物车详情
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package cn.iocoder.mall.order.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.bo.CalcOrderPriceBO;
|
||||
import cn.iocoder.mall.order.api.bo.CartItemBO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.CartItemDO;
|
||||
import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CartConvert {
|
||||
|
||||
@@ -12,4 +16,6 @@ public interface CartConvert {
|
||||
|
||||
CalcOrderPriceBO.Item convert(ProductSkuDetailBO sku);
|
||||
|
||||
List<CartItemBO> convert(List<CartItemDO> items);
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ public interface CartMapper {
|
||||
Integer selectQuantitySumByUserIdAndStatus(@Param("userId") Integer userId,
|
||||
@Param("status") Integer status);
|
||||
|
||||
// List<CartItemDO> selectListByStatus(@Param("status") Integer status);
|
||||
List<CartItemDO> selectByUserIdAndStatusAndSelected(@Param("userId") Integer userId,
|
||||
@Param("status") Integer status,
|
||||
@Param("selected") Boolean selected);
|
||||
//
|
||||
// List<CartItemDO> selectListByTitleLike(@Param("title") String title,
|
||||
// @Param("offset") Integer offset,
|
||||
@@ -36,4 +38,8 @@ public interface CartMapper {
|
||||
int updateQuantity(@Param("id") Integer id,
|
||||
@Param("quantityIncr") Integer quantityIncr);
|
||||
|
||||
int updateListSelected(@Param("userId") Integer userId,
|
||||
@Param("skuIds") Collection<Integer> skuIds,
|
||||
@Param("selected") Boolean selected);
|
||||
|
||||
}
|
||||
|
||||
@@ -44,10 +44,6 @@ public class CartItemDO extends BaseDO {
|
||||
* 用户编号
|
||||
*/
|
||||
private Integer userId;
|
||||
// /**
|
||||
// * 会话 key
|
||||
// */
|
||||
// private String nobody;
|
||||
|
||||
// ========= 买家信息 END =========
|
||||
|
||||
|
||||
@@ -114,15 +114,9 @@ public class CartServiceImpl implements CartService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateSelected(Integer userId, Integer skuId, Boolean selected) {
|
||||
// 查询 CartItemDO
|
||||
CartItemDO item = cartMapper.selectByUserIdAndSkuIdAndStatus(userId, skuId, CartItemStatusEnum.ENABLE.getValue());
|
||||
if (item == null) {
|
||||
return ServiceExceptionUtil.error(OrderErrorCodeEnum.CARD_ITEM_NOT_FOUND.getCode());
|
||||
}
|
||||
// 更新 CartItemDO
|
||||
CartItemDO updateCartItem = new CartItemDO().setId(item.getId()).setSelected(selected);
|
||||
cartMapper.update(updateCartItem);
|
||||
public CommonResult<Boolean> updateSelected(Integer userId, Collection<Integer> skuIds, Boolean selected) {
|
||||
// 更新 CartItemDO 们
|
||||
cartMapper.updateListSelected(userId, skuIds, selected);
|
||||
// 返回成功
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
@@ -143,8 +137,9 @@ public class CartServiceImpl implements CartService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CartItemBO> list(Integer userId, Boolean selected) {
|
||||
return null;
|
||||
public CommonResult<List<CartItemBO>> list(Integer userId, Boolean selected) {
|
||||
List<CartItemDO> items = cartMapper.selectByUserIdAndStatusAndSelected(userId, CartItemStatusEnum.ENABLE.getValue(), selected);
|
||||
return CommonResult.success(CartConvert.INSTANCE.convert(items));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,6 +38,18 @@
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectByUserIdAndStatusAndSelected" resultType="CartItemDO">
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM cart_item
|
||||
WHERE user_id = #{userId}
|
||||
AND status = #{status}
|
||||
<if test="selected != null">
|
||||
AND selected = #{selected}
|
||||
</if>
|
||||
-- AND deleted = 0
|
||||
</select>
|
||||
|
||||
<select id="selectQuantitySumByUserIdAndStatus" resultType="Integer">
|
||||
SELECT
|
||||
SUM(quantity)
|
||||
@@ -96,4 +108,15 @@
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateListSelected">
|
||||
UPDATE cart_item
|
||||
SET selected = #{selected}
|
||||
WHERE user_id = #{userId}
|
||||
AND sku_id IN
|
||||
<foreach item="skuId" collection="skuIds" separator="," open="(" close=")" index="">
|
||||
#{skuId}
|
||||
</foreach>
|
||||
-- AND deleted = 0
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user