diff --git a/src/main/java/com/gxwebsoft/shop/controller/CartController.java b/src/main/java/com/gxwebsoft/shop/controller/CartController.java new file mode 100644 index 0000000..c06893e --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/controller/CartController.java @@ -0,0 +1,266 @@ +package com.gxwebsoft.shop.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.shop.entity.GoodsCategory; +import com.gxwebsoft.shop.entity.Merchant; +import com.gxwebsoft.shop.service.CartService; +import com.gxwebsoft.shop.entity.Cart; +import com.gxwebsoft.shop.param.CartParam; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.BatchParam; +import com.gxwebsoft.common.core.annotation.OperationLog; +import com.gxwebsoft.common.system.entity.User; +import com.gxwebsoft.shop.service.MerchantService; +import com.gxwebsoft.shop.vo.CartShopVo; +import com.gxwebsoft.shop.vo.CartVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.util.CollectionUtils; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; + +import static com.gxwebsoft.common.core.utils.CommonUtil.toTreeData; + +/** + * 购物车控制器 + * + * @author 科技小王子 + * @since 2024-07-29 21:02:39 + */ +@Api(tags = "购物车管理") +@RestController +@RequestMapping("/api/shop/cart") +public class CartController extends BaseController { + @Resource + private CartService cartService; + @Resource + private MerchantService merchantService; + + @ApiOperation("我的购物车") + @GetMapping("/myCart") + public ApiResult myCart(CartParam param){ + // 记录当前登录用户id + User loginUser = getLoginUser(); + if (loginUser == null) { + return fail("请先登录",null); + } + // 查询购物车 + param.setUserId(getLoginUserId().longValue()); + final List carts = cartService.listRelMpj(param); +// final List carts = cartService.list(new LambdaQueryWrapper() +// .eq(Cart::getUserId, loginUser.getUserId()) +// .eq(Cart::getIsPay, 0) +// .eq(Cart::getIsNew, 0) +// .eq(Cart::getDeleted, 0) +// .last("limit 100")); + + // 收集店铺ID + final Set merchantIds = carts.stream().map(Cart::getMerchantId).collect(Collectors.toSet()); + + // 查询店铺列 + final List merchants = merchantService.list(new LambdaQueryWrapper() + .select(Merchant::getMerchantId,Merchant::getMerchantName,Merchant::getImage,Merchant::getShopType) + .in(Merchant::getMerchantId, merchantIds)); + + // 返回空列表 + if (CollectionUtils.isEmpty(merchants)) { + return success(merchants); + } + + final Map> collect = carts.stream().collect(Collectors.groupingBy(Cart::getMerchantId)); + + // 封装数据 + merchants.forEach(d -> { + d.setCarts(collect.get(d.getMerchantId())); + }); + + // 计算购物车金额 + HashMap map = computeCart(); + map.put("merchants",merchants); + + return success(map); + } + + @ApiOperation("添加购物车") + @PostMapping() + public ApiResult save(@RequestBody Cart cart) { + // 记录当前登录用户id + User loginUser = getLoginUser(); + if (loginUser == null) { + return fail("请先登录"); + } + + // 购物车是否已存在 + final Cart item = cartService.getOne(new LambdaQueryWrapper().eq(Cart::getUserId, loginUser.getUserId()).eq(Cart::getGoodsId, cart.getGoodsId()).last("limit 1")); + cart.setUserId(loginUser.getUserId().longValue()); + + // 修改购物车 + if (item != null) { + item.setCartNum(item.getCartNum() + cart.getCartNum()); + cartService.updateById(item); + return success("添加成功",computeCart()); + } + + // 新添加商品 + if (cartService.save(cart)) { + return success("添加成功",computeCart()); + } + + return fail("添加失败"); + } + + @ApiOperation("修改购物车") + @PutMapping() + public ApiResult update(@RequestBody Cart cart) { + if (cartService.updateById(cart)) { + return success("修改成功",computeCart()); + } + return fail("修改失败"); + } + + @ApiOperation("计算购物车金额") + @GetMapping("/count") + public HashMap computeCart() { + // 查询购物车数据 + final List carts = cartService.list(new LambdaQueryWrapper() + .select(Cart::getId,Cart::getPrice,Cart::getCartNum) + .eq(Cart::getUserId, getLoginUserId()) + .eq(Cart::getSelected,1) + .eq(Cart::getIsPay, 0) + ); + + // 计算单品合计价格 + carts.forEach(d -> { + d.setTotalPrice(d.getPrice().multiply(BigDecimal.valueOf(d.getCartNum()))); + }); + + // 保存到数据库 + cartService.updateBatchById(carts); + + // 计算购物车金额 + final Integer reduce = carts.stream().map(Cart::getCartNum).reduce(Integer::sum).orElse(0); + final BigDecimal reduced = carts.stream().map(Cart::getTotalPrice).reduce(BigDecimal.ZERO, BigDecimal::add); + + // 是否全选 + Boolean selectAll = cartService.count(new LambdaQueryWrapper() + .eq(Cart::getUserId, getLoginUserId()) + .eq(Cart::getSelected, 0) + .eq(Cart::getIsPay, 0) + ) == 0; + + + // 返回给前端 + final HashMap map = new HashMap<>(); + map.put("totalCartNum",reduce); + map.put("totalPrice",reduced); + map.put("selectAll",selectAll); + + return map; + } + + @ApiOperation("全选操作") + @PutMapping("/onSelectAll/{yes}") + public ApiResult onSelectAll(@PathVariable("yes") Boolean yes) { + // 是否全选 + if (yes.equals(true)) { + // 全勾选 + cartService.update(new LambdaUpdateWrapper() + .eq(Cart::getUserId, getLoginUserId()) + .eq(Cart::getIsPay, 0) + .eq(Cart::getSelected,0) + .set(Cart::getSelected,1) + ); + return success("修改成功",computeCart()); + } + // 全不勾选 + cartService.update(new LambdaUpdateWrapper() + .eq(Cart::getUserId, getLoginUserId()) + .eq(Cart::getIsPay, 0) + .eq(Cart::getSelected,1) + .set(Cart::getSelected,0) + ); + return success("修改成功",computeCart()); + } + + + + +// @ApiOperation("按店铺ID更新选择状态") +// @PutMapping("/updateCartByMerchantId/{id}") +// public ApiResult updateCartByMerchantId(@PathVariable("id") Long id) { +// +// if (cartService.updateById()) { +// return success("修改成功"); +// } +// return fail("修改失败"); +// } + + + @ApiOperation("分页查询购物车") + @GetMapping("/page") + public ApiResult> page(CartParam param) { + // 使用关联查询 + return success(cartService.pageRel(param)); + } + + @ApiOperation("查询全部购物车") + @GetMapping() + public ApiResult> list(CartParam param) { + // 使用关联查询 + return success(cartService.listRel(param)); + } + + @PreAuthorize("hasAuthority('shop:cart:list')") + @ApiOperation("根据id查询购物车") + @GetMapping("/{id}") + public ApiResult get(@PathVariable("id") Long id) { + // 使用关联查询 + return success(cartService.getByIdRel(id)); + } + + @ApiOperation("删除购物车") + @DeleteMapping("/{id}") + public ApiResult remove(@PathVariable("id") Integer id) { + if (cartService.removeById(id)) { + return success("删除成功"); + } + return fail("删除失败"); + } + + @ApiOperation("批量添加购物车") + @PostMapping("/batch") + public ApiResult saveBatch(@RequestBody List list) { + if (cartService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); + } + + @ApiOperation("批量修改购物车") + @PutMapping("/batch") + public ApiResult removeBatch(@RequestBody BatchParam batchParam) { + if (batchParam.update(cartService, "id")) { + return success("修改成功"); + } + return fail("修改失败"); + } + + @ApiOperation("批量删除购物车") + @DeleteMapping("/batch") + public ApiResult removeBatch(@RequestBody List ids) { + if (cartService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); + } + +} diff --git a/src/main/java/com/gxwebsoft/shop/controller/OrderController.java b/src/main/java/com/gxwebsoft/shop/controller/OrderController.java index e9d8b1b..0f602e1 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/OrderController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/OrderController.java @@ -23,7 +23,11 @@ import com.gxwebsoft.common.core.utils.RequestUtil; import com.gxwebsoft.common.core.utils.WxUtil; import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.system.entity.Role; +import com.gxwebsoft.shop.entity.Cart; +import com.gxwebsoft.shop.entity.OrderGoods; import com.gxwebsoft.shop.entity.OrderInfo; +import com.gxwebsoft.shop.param.CartParam; +import com.gxwebsoft.shop.service.CartService; import com.gxwebsoft.shop.service.OrderGoodsService; import com.gxwebsoft.shop.service.OrderInfoService; import com.gxwebsoft.shop.service.OrderService; @@ -48,10 +52,7 @@ import javax.servlet.http.HttpServletRequest; import java.io.File; import java.math.BigDecimal; import java.time.Instant; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -78,7 +79,11 @@ public class OrderController extends BaseController { @Resource private CardService cardService; @Resource + private CartService cartService; + @Resource private RequestUtil requestUtil; + @Resource + private CartController cartController; @ApiOperation("分页查询订单") @GetMapping("/page") @@ -217,14 +222,40 @@ public class OrderController extends BaseController { if (orderService.save(order)) { // 商城订单 if (order.getType().equals(0)) { - order.getGoodsList().forEach(d -> { - d.setOrderId(order.getOrderId()); - d.setTimeFlag(timeMillis); - d.setVersion(10); - d.setDateTime(DateUtil.date()); - d.setUserId(getLoginUser().getUserId()); - d.setExpirationTime(order.getExpirationTime()); - }); +// order.getGoodsList().forEach(d -> { +// d.setOrderId(order.getOrderId()); +// d.setTimeFlag(timeMillis); +// d.setVersion(10); +// d.setDateTime(DateUtil.date()); +// d.setUserId(getLoginUser().getUserId()); +// d.setExpirationTime(order.getExpirationTime()); +// }); + + // 从购物车获取订单数据 + final CartParam cartParam = new CartParam(); + cartParam.setUserId(getLoginUserId().longValue()); + cartParam.setSelected(true); + final List carts = cartService.listRelMpj(cartParam); + final ArrayList orderGoods = new ArrayList<>(); + if (!CollectionUtils.isEmpty(carts)) { + carts.forEach(d -> { + final OrderGoods goods = new OrderGoods(); + goods.setOrderId(order.getOrderId()); + goods.setImage(d.getImage()); + goods.setGoodsName(d.getGoodsName()); + goods.setGoodsId(Math.toIntExact(d.getGoodsId())); + goods.setTotalNum(d.getCartNum()); + goods.setPrice(d.getPrice()); + goods.setVersion(10); + goods.setUserId(order.getUserId()); + goods.setTimeFlag(timeMillis); + goods.setDateTime(DateUtil.date()); + goods.setExpirationTime(order.getExpirationTime()); + orderGoods.add(goods); + }); + System.out.println("carts = " + carts); + order.setGoodsList(orderGoods); + } orderGoodsService.saveBatch(order.getGoodsList()); } // 预定订单 diff --git a/src/main/java/com/gxwebsoft/shop/entity/Cart.java b/src/main/java/com/gxwebsoft/shop/entity/Cart.java new file mode 100644 index 0000000..57ed0ca --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/entity/Cart.java @@ -0,0 +1,104 @@ +package com.gxwebsoft.shop.entity; + +import com.baomidou.mybatisplus.annotation.*; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 购物车 + * + * @author 科技小王子 + * @since 2024-07-29 21:02:39 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "Cart对象", description = "购物车") +@TableName("shop_cart") +public class Cart implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "购物车表ID") + @TableId(value = "id", type = IdType.AUTO) + private Long id; + + @ApiModelProperty(value = "类型 0商城 1预定 ") + private Integer type; + + @ApiModelProperty(value = "商品ID") + private Long goodsId; + + @ApiModelProperty(value = "商品属性") + private String goodsAttrUnique; + + @ApiModelProperty(value = "商品价格") + private BigDecimal price; + + @ApiModelProperty(value = "商品数量") + private Integer cartNum; + + @ApiModelProperty(value = "单品合计") + private BigDecimal totalPrice; + + @ApiModelProperty(value = "0 = 未购买 1 = 已购买") + private Boolean isPay; + + @ApiModelProperty(value = "是否为立即购买") + private Boolean isNew; + + @ApiModelProperty(value = "是否选中") + private Boolean selected; + + @ApiModelProperty(value = "拼团id") + private Integer combinationId; + + @ApiModelProperty(value = "秒杀产品ID") + private Integer seckillId; + + @ApiModelProperty(value = "砍价id") + private Integer bargainId; + + @ApiModelProperty(value = "商户ID") + private Integer merchantId; + + @ApiModelProperty(value = "用户ID") + private Long userId; + + @ApiModelProperty(value = "租户id") + private Integer tenantId; + + @ApiModelProperty(value = "添加时间") + private Date createTime; + + @ApiModelProperty(value = "修改时间") + private Date updateTime; + + @ApiModelProperty(value = "店铺名称") + @TableField(exist = false) + private String merchantName; + + @ApiModelProperty(value = "商品名称") + @TableField(exist = false) + private String goodsName; + + @ApiModelProperty(value = "商品图片") + @TableField(exist = false) + private String image; + + @ApiModelProperty(value = "是否全选") + @TableField(exist = false) + private Boolean selectAll; + + @ApiModelProperty("子菜单") + @TableField(exist = false) + private List children; + +} diff --git a/src/main/java/com/gxwebsoft/shop/entity/Merchant.java b/src/main/java/com/gxwebsoft/shop/entity/Merchant.java index d63bd47..d64db5a 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/Merchant.java +++ b/src/main/java/com/gxwebsoft/shop/entity/Merchant.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.*; import java.time.LocalDateTime; import java.io.Serializable; import java.util.Date; +import java.util.List; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -129,4 +130,8 @@ public class Merchant implements Serializable { @TableField(exist = false) private String roleName; + @ApiModelProperty(value = "按店铺分类的购物车商品") + @TableField(exist = false) + private List carts; + } diff --git a/src/main/java/com/gxwebsoft/shop/entity/OrderGoods.java b/src/main/java/com/gxwebsoft/shop/entity/OrderGoods.java index 873fa75..850cbc5 100644 --- a/src/main/java/com/gxwebsoft/shop/entity/OrderGoods.java +++ b/src/main/java/com/gxwebsoft/shop/entity/OrderGoods.java @@ -3,10 +3,8 @@ package com.gxwebsoft.shop.entity; import java.math.BigDecimal; import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.IdType; -import java.time.LocalDate; import com.baomidou.mybatisplus.annotation.TableId; -import java.time.LocalTime; -import java.time.LocalDateTime; + import java.io.Serializable; import java.util.Date; diff --git a/src/main/java/com/gxwebsoft/shop/mapper/CartMapper.java b/src/main/java/com/gxwebsoft/shop/mapper/CartMapper.java new file mode 100644 index 0000000..2748c79 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/mapper/CartMapper.java @@ -0,0 +1,38 @@ +package com.gxwebsoft.shop.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.yulichang.base.MPJBaseMapper; +import com.gxwebsoft.shop.entity.Cart; +import com.gxwebsoft.shop.param.CartParam; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 购物车Mapper + * + * @author 科技小王子 + * @since 2024-07-29 21:02:39 + */ +public interface CartMapper extends MPJBaseMapper { + + /** + * 分页查询 + * + * @param page 分页对象 + * @param param 查询参数 + * @return List + */ + List selectPageRel(@Param("page") IPage page, + @Param("param") CartParam param); + + /** + * 查询全部 + * + * @param param 查询参数 + * @return List + */ + List selectListRel(@Param("param") CartParam param); + +} diff --git a/src/main/java/com/gxwebsoft/shop/mapper/xml/CartMapper.xml b/src/main/java/com/gxwebsoft/shop/mapper/xml/CartMapper.xml new file mode 100644 index 0000000..1455fa3 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/mapper/xml/CartMapper.xml @@ -0,0 +1,79 @@ + + + + + + + SELECT a.*,b.goods_name,b.image,c.merchant_name + FROM shop_cart a + LEFT JOIN shop_goods b ON a.goods_id = b.goods_id + LEFT JOIN shop_merchant c ON a.merchant_id = b.merchant_id + + + AND a.id = #{param.id} + + + AND a.type = #{param.type} + + + AND a.goods_id LIKE CONCAT('%', #{param.goodsId}, '%') + + + AND a.goods_attr_unique LIKE CONCAT('%', #{param.goodsAttrUnique}, '%') + + + AND a.cart_num = #{param.cartNum} + + + AND a.is_pay = #{param.isPay} + + + AND a.is_new = #{param.isNew} + + + AND a.combination_id = #{param.combinationId} + + + AND a.seckill_id = #{param.seckillId} + + + AND a.bargain_id = #{param.bargainId} + + + AND a.user_id LIKE CONCAT('%', #{param.userId}, '%') + + + AND a.selected = #{param.selected} + + + + + + + + + + AND a.create_time >= #{param.createTimeStart} + + + AND a.create_time <= #{param.createTimeEnd} + + + AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%') + OR b.goods_name LIKE CONCAT('%', #{param.keywords}, '%') + ) + + + + + + + + + + + diff --git a/src/main/java/com/gxwebsoft/shop/param/CartParam.java b/src/main/java/com/gxwebsoft/shop/param/CartParam.java new file mode 100644 index 0000000..4f97474 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/param/CartParam.java @@ -0,0 +1,82 @@ +package com.gxwebsoft.shop.param; + +import java.math.BigDecimal; +import com.gxwebsoft.common.core.annotation.QueryField; +import com.gxwebsoft.common.core.annotation.QueryType; +import com.gxwebsoft.common.core.web.BaseParam; +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.models.auth.In; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 购物车查询参数 + * + * @author 科技小王子 + * @since 2024-07-29 21:02:39 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@JsonInclude(JsonInclude.Include.NON_NULL) +@ApiModel(value = "CartParam对象", description = "购物车查询参数") +public class CartParam extends BaseParam { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "购物车表ID") + @QueryField(type = QueryType.EQ) + private Long id; + + @ApiModelProperty(value = "类型 0商城 1预定 ") + @QueryField(type = QueryType.EQ) + private Integer type; + + @ApiModelProperty(value = "商品ID") + private Long goodsId; + + @ApiModelProperty(value = "商品属性") + private String goodsAttrUnique; + + @ApiModelProperty(value = "商品数量") + @QueryField(type = QueryType.EQ) + private Integer cartNum; + + @ApiModelProperty(value = "0 = 未购买 1 = 已购买") + @QueryField(type = QueryType.EQ) + private Boolean isPay; + + @ApiModelProperty(value = "是否为立即购买") + @QueryField(type = QueryType.EQ) + private Boolean isNew; + + @ApiModelProperty(value = "拼团id") + @QueryField(type = QueryType.EQ) + private Integer combinationId; + + @ApiModelProperty(value = "秒杀产品ID") + @QueryField(type = QueryType.EQ) + private Integer seckillId; + + @ApiModelProperty(value = "砍价id") + @QueryField(type = QueryType.EQ) + private Integer bargainId; + + @ApiModelProperty(value = "用户ID") + private Long userId; + + @ApiModelProperty(value = "是否选中") + private Boolean selected; + + @ApiModelProperty(value = "商户ID") + private Integer merchantId; + +// @ApiModelProperty(value = "是否删除, 0否, 1是") +// @QueryField(type = QueryType.EQ) +// private Integer deleted; + + @ApiModelProperty(value = "商品名称") + @QueryField(type = QueryType.LIKE) + private String goodsName; + +} diff --git a/src/main/java/com/gxwebsoft/shop/service/CartService.java b/src/main/java/com/gxwebsoft/shop/service/CartService.java new file mode 100644 index 0000000..abcafd2 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/service/CartService.java @@ -0,0 +1,44 @@ +package com.gxwebsoft.shop.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.gxwebsoft.common.core.web.PageResult; +import com.gxwebsoft.shop.entity.Cart; +import com.gxwebsoft.shop.param.CartParam; + +import java.util.List; + +/** + * 购物车Service + * + * @author 科技小王子 + * @since 2024-07-29 21:02:39 + */ +public interface CartService extends IService { + + /** + * 分页关联查询 + * + * @param param 查询参数 + * @return PageResult + */ + PageResult pageRel(CartParam param); + + /** + * 关联查询全部 + * + * @param param 查询参数 + * @return List + */ + List listRel(CartParam param); + + /** + * 根据id查询 + * + * @param id 购物车表ID + * @return Cart + */ + Cart getByIdRel(Long id); + + List listRelMpj(CartParam param); + +} diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/CartServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/CartServiceImpl.java new file mode 100644 index 0000000..68d2f67 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/service/impl/CartServiceImpl.java @@ -0,0 +1,70 @@ +package com.gxwebsoft.shop.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.gxwebsoft.shop.entity.Goods; +import com.gxwebsoft.shop.entity.GoodsSpec; +import com.gxwebsoft.shop.mapper.CartMapper; +import com.gxwebsoft.shop.service.CartService; +import com.gxwebsoft.shop.entity.Cart; +import com.gxwebsoft.shop.param.CartParam; +import com.gxwebsoft.common.core.web.PageParam; +import com.gxwebsoft.common.core.web.PageResult; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 购物车Service实现 + * + * @author 科技小王子 + * @since 2024-07-29 21:02:39 + */ +@Service +public class CartServiceImpl extends ServiceImpl implements CartService { + + @Override + public PageResult pageRel(CartParam param) { + PageParam page = new PageParam<>(param); + page.setDefaultOrder("create_time desc"); + List list = baseMapper.selectPageRel(page, param); + return new PageResult<>(list, page.getTotal()); + } + + @Override + public List listRel(CartParam param) { + List list = baseMapper.selectListRel(param); + // 排序 + PageParam page = new PageParam<>(); + page.setDefaultOrder("create_time desc"); + return page.sortRecords(list); + } + + @Override + public Cart getByIdRel(Long id) { + CartParam param = new CartParam(); + param.setId(id); + return param.getOne(baseMapper.selectListRel(param)); + } + + @Override + public List listRelMpj(CartParam param) { + + System.out.println("param = " + param); + // 多表查询 + MPJLambdaWrapper mpjLambdaWrapper = new MPJLambdaWrapper<>(); + mpjLambdaWrapper.selectAll(Cart.class) + .select(Goods::getGoodsName) + .select(Goods::getImage) + .leftJoin(Goods.class,Goods::getGoodsId,Cart::getGoodsId); + + if(param.getSelected() != null){ + mpjLambdaWrapper.eq(Cart::getSelected,param.getSelected()); + } + + return baseMapper.selectJoinList(Cart.class, mpjLambdaWrapper); + } + +} diff --git a/src/main/java/com/gxwebsoft/shop/vo/CartShopVo.java b/src/main/java/com/gxwebsoft/shop/vo/CartShopVo.java new file mode 100644 index 0000000..25bb02d --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/vo/CartShopVo.java @@ -0,0 +1,35 @@ +package com.gxwebsoft.shop.vo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.gxwebsoft.shop.entity.Cart; +import com.gxwebsoft.shop.entity.Goods; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "店铺对象", description = "店铺") +@TableName("shop_merchant") +public class CartShopVo implements Serializable { + + @ApiModelProperty(value = "店铺ID") + private Integer shopId; + + @ApiModelProperty("店铺名称") + private String shopName; + + @ApiModelProperty(value = "商品列表") + private List goods; + @Data + public static class Payload { + private Integer shopId; + private Integer shopName; + private List goods; + } +} diff --git a/src/main/java/com/gxwebsoft/shop/vo/CartVo.java b/src/main/java/com/gxwebsoft/shop/vo/CartVo.java new file mode 100644 index 0000000..7808358 --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/vo/CartVo.java @@ -0,0 +1,30 @@ +package com.gxwebsoft.shop.vo; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.gxwebsoft.shop.entity.Cart; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = false) +@ApiModel(value = "Cart对象", description = "购物车") +@TableName("shop_cart") +public class CartVo implements Serializable { + + @ApiModelProperty("宝贝数量") + private Long count; + + @ApiModelProperty("店铺列表") + private List shops; + @Data + public static class Payload { + private Integer count; + private Integer shops; + } +} diff --git a/src/test/java/com/gxwebsoft/generator/ShopGenerator.java b/src/test/java/com/gxwebsoft/generator/ShopGenerator.java index 0f4b179..bb6e5b6 100644 --- a/src/test/java/com/gxwebsoft/generator/ShopGenerator.java +++ b/src/test/java/com/gxwebsoft/generator/ShopGenerator.java @@ -84,8 +84,9 @@ public class ShopGenerator { // "shop_dealer_order", // "shop_dealer_referee", // "shop_dealer_setting", - "shop_dealer_user", +// "shop_dealer_user", // "shop_dealer_withdraw" + "shop_cart" }; // 需要去除的表前缀 private static final String[] TABLE_PREFIX = new String[]{