feat(新增): 更新购物车商品全部选中状态
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
1dc696935d
commit
55d0612a31
|
@ -48,4 +48,11 @@ public class CartController {
|
||||||
cartService.checkCart(skuId, isChecked);
|
cartService.checkCart(skuId, isChecked);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "更新购物车商品全部选中状态")
|
||||||
|
@GetMapping("/auth/allCheckCart/{isChecked}")
|
||||||
|
public Result<String> allCheckCart(@Parameter(name = "isChecked", description = "是否选中 1:选中 0:取消选中", required = true) @PathVariable(value = "isChecked") Integer isChecked) {
|
||||||
|
cartService.allCheckCart(isChecked);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -34,4 +34,11 @@ public interface CartService {
|
||||||
* @param isChecked 是否选中
|
* @param isChecked 是否选中
|
||||||
*/
|
*/
|
||||||
void checkCart(Long skuId, Integer isChecked);
|
void checkCart(Long skuId, Integer isChecked);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新购物车商品全部选中状态
|
||||||
|
*
|
||||||
|
* @param isChecked 是否选中
|
||||||
|
*/
|
||||||
|
void allCheckCart(Integer isChecked);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,4 +125,26 @@ public class CartServiceImpl implements CartService {
|
||||||
redisTemplate.opsForHash().put(cartKey, String.valueOf(skuId), JSON.toJSONString(cartInfo));
|
redisTemplate.opsForHash().put(cartKey, String.valueOf(skuId), JSON.toJSONString(cartInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新购物车商品全部选中状态
|
||||||
|
*
|
||||||
|
* @param isChecked 是否选中
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void allCheckCart(Integer isChecked) {
|
||||||
|
// 获取当前登录的用户数据
|
||||||
|
Long userId = BaseContext.getUserInfo().getId();
|
||||||
|
String cartKey = userId.toString();
|
||||||
|
|
||||||
|
// 获取所有的购物项数据
|
||||||
|
List<Object> objectList = redisTemplate.opsForHash().values(cartKey);
|
||||||
|
if (!CollectionUtils.isEmpty(objectList)) {
|
||||||
|
objectList.stream().map(cartInfoJSON -> {
|
||||||
|
CartInfo cartInfo = JSON.parseObject(cartInfoJSON.toString(), CartInfo.class);
|
||||||
|
cartInfo.setIsChecked(isChecked);
|
||||||
|
return cartInfo;
|
||||||
|
}).forEach(cartInfo -> redisTemplate.opsForHash().put(cartKey, String.valueOf(cartInfo.getSkuId()), JSON.toJSONString(cartInfo)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue