From b2dc2b0be4639684649b61ebc8ca0bba3b6f4469 Mon Sep 17 00:00:00 2001 From: muhua <1498117283@qq.com> Date: Sat, 13 Jul 2024 11:43:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/CommonStatusConstant.java | 14 +++ .../controller/OrderController.java | 18 +++- .../controller/ShopController.java | 6 ++ .../controller/UserController.java | 6 -- .../entity/OrderItem.java | 2 +- .../entity/{Order.java => OrderList.java} | 22 +++-- .../takeawaysystemserver/entity/Shop.java | 17 ++-- .../takeawaysystemserver/entity/User.java | 8 -- .../mapper/DishMapper.java | 11 ++- .../mapper/OrderMapper.java | 4 +- .../mapper/ShopMapper.java | 7 ++ .../mapper/ShoppingCartMapper.java | 2 + .../service/OrderService.java | 6 +- .../service/ShopService.java | 7 ++ .../service/UserService.java | 8 -- .../service/impl/OrderServiceImpl.java | 85 ++++++++++++++++++- .../service/impl/ShopServiceImpl.java | 17 ++++ .../service/impl/UserServiceImpl.java | 13 --- .../resources/mapper/DishFlavorMapper.xml | 4 +- src/main/resources/mapper/DishMapper.xml | 9 +- src/main/resources/mapper/OrderItemMapper.xml | 6 +- .../{OrderMapper.xml => OrderListMapper.xml} | 8 +- src/main/resources/mapper/ShopMapper.xml | 6 ++ 23 files changed, 213 insertions(+), 73 deletions(-) create mode 100644 src/main/java/com/example/takeawaysystemserver/constant/CommonStatusConstant.java rename src/main/java/com/example/takeawaysystemserver/entity/{Order.java => OrderList.java} (82%) rename src/main/resources/mapper/{OrderMapper.xml => OrderListMapper.xml} (89%) diff --git a/src/main/java/com/example/takeawaysystemserver/constant/CommonStatusConstant.java b/src/main/java/com/example/takeawaysystemserver/constant/CommonStatusConstant.java new file mode 100644 index 0000000..b8b44e8 --- /dev/null +++ b/src/main/java/com/example/takeawaysystemserver/constant/CommonStatusConstant.java @@ -0,0 +1,14 @@ +package com.example.takeawaysystemserver.constant; + +/** + * @author Ethereal + * @date 2024/7/13 + * @description + */ +public interface CommonStatusConstant { + String ADDRESS_ERROR = "地址信息有误,请重新填写"; + + String SHOPPINGCART_ERROR = "购物车为空"; + + String INSERT_ERROR = "插入失败,请重试"; +} diff --git a/src/main/java/com/example/takeawaysystemserver/controller/OrderController.java b/src/main/java/com/example/takeawaysystemserver/controller/OrderController.java index 6265ba8..0e675eb 100644 --- a/src/main/java/com/example/takeawaysystemserver/controller/OrderController.java +++ b/src/main/java/com/example/takeawaysystemserver/controller/OrderController.java @@ -1,8 +1,12 @@ package com.example.takeawaysystemserver.controller; +import com.example.takeawaysystemserver.entity.OrderList; +import com.example.takeawaysystemserver.service.OrderService; +import com.example.takeawaysystemserver.util.R; import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import io.swagger.annotations.ApiOperation; +import jakarta.annotation.Resource; +import org.springframework.web.bind.annotation.*; /** * @author Ethereal @@ -13,4 +17,14 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("order") @Api(tags = "订单模块") public class OrderController { + @Resource + private OrderService orderService; + + + @PostMapping("add") + @ApiOperation(value = "添加订单") + public R addOrder(@RequestHeader String token, @RequestBody OrderList order){ + return orderService.addOrders(token, order); + } + } diff --git a/src/main/java/com/example/takeawaysystemserver/controller/ShopController.java b/src/main/java/com/example/takeawaysystemserver/controller/ShopController.java index 43a4755..473a64e 100644 --- a/src/main/java/com/example/takeawaysystemserver/controller/ShopController.java +++ b/src/main/java/com/example/takeawaysystemserver/controller/ShopController.java @@ -39,4 +39,10 @@ public class ShopController { public R> getAllDishes(@RequestParam("id") Integer id){ return shopService.getShopDishes(id); } + + @GetMapping("search-keyword") + @ApiOperation(value = "根据关键字搜索商家") + public R> searchByKeyword(@RequestParam("keyword")String keyword){ + return shopService.search(keyword); + } } diff --git a/src/main/java/com/example/takeawaysystemserver/controller/UserController.java b/src/main/java/com/example/takeawaysystemserver/controller/UserController.java index 46c4ac7..ffca235 100644 --- a/src/main/java/com/example/takeawaysystemserver/controller/UserController.java +++ b/src/main/java/com/example/takeawaysystemserver/controller/UserController.java @@ -50,10 +50,4 @@ public class UserController { public R updatePassword(@RequestHeader String token, UserPasswordDTO userPasswordDTO){ return userService.updatePassword(token,userPasswordDTO); } - - @PostMapping("update-address") - @ApiOperation(value = "修改用户地址") - public R updateAddress(@RequestHeader String token, @RequestBody AddressDTO addressDTO){ - return userService.updateAddress(token, addressDTO.getAddress()); - } } diff --git a/src/main/java/com/example/takeawaysystemserver/entity/OrderItem.java b/src/main/java/com/example/takeawaysystemserver/entity/OrderItem.java index 0eeae56..aecde87 100644 --- a/src/main/java/com/example/takeawaysystemserver/entity/OrderItem.java +++ b/src/main/java/com/example/takeawaysystemserver/entity/OrderItem.java @@ -26,7 +26,7 @@ public class OrderItem implements Serializable { /** * order_id */ - private Integer orderId; + private Long orderId; /** * 购买份数 diff --git a/src/main/java/com/example/takeawaysystemserver/entity/Order.java b/src/main/java/com/example/takeawaysystemserver/entity/OrderList.java similarity index 82% rename from src/main/java/com/example/takeawaysystemserver/entity/Order.java rename to src/main/java/com/example/takeawaysystemserver/entity/OrderList.java index 2823c68..4565a7e 100644 --- a/src/main/java/com/example/takeawaysystemserver/entity/Order.java +++ b/src/main/java/com/example/takeawaysystemserver/entity/OrderList.java @@ -4,19 +4,23 @@ import java.io.Serializable; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; /** * - * @TableName order + * @TableName order_list */ @Data -public class Order implements Serializable { +@AllArgsConstructor +@NoArgsConstructor +public class OrderList implements Serializable { /** * 主键ID */ @TableId(value = "id", type = IdType.AUTO) - private Integer id; + private Long id; /** * 用户ID @@ -38,6 +42,11 @@ public class Order implements Serializable { */ private Integer status; + /** + * 地址ID + */ + private Integer addressId; + /** * 地址 */ @@ -66,14 +75,15 @@ public class Order implements Serializable { if (getClass() != that.getClass()) { return false; } - Order other = (Order) that; + OrderList other = (OrderList) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) && (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) + && (this.getAddressId() == null ? other.getAddressId() == null : this.getAddressId().equals(other.getAddressId())) && (this.getAddress() == null ? other.getAddress() == null : this.getAddress().equals(other.getAddress())) - && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())); } @@ -86,6 +96,7 @@ public class Order implements Serializable { result = prime * result + ((getShopId() == null) ? 0 : getShopId().hashCode()); result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); + result = prime * result + ((getAddressId() == null) ? 0 : getAddressId().hashCode()); result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); @@ -103,6 +114,7 @@ public class Order implements Serializable { sb.append(", shopId=").append(shopId); sb.append(", price=").append(price); sb.append(", status=").append(status); + sb.append(", addressId=").append(addressId); sb.append(", address=").append(address); sb.append(", createTime=").append(createTime); sb.append(", updateTime=").append(updateTime); diff --git a/src/main/java/com/example/takeawaysystemserver/entity/Shop.java b/src/main/java/com/example/takeawaysystemserver/entity/Shop.java index a142122..5b1181d 100644 --- a/src/main/java/com/example/takeawaysystemserver/entity/Shop.java +++ b/src/main/java/com/example/takeawaysystemserver/entity/Shop.java @@ -1,9 +1,11 @@ package com.example.takeawaysystemserver.entity; import java.io.Serializable; +import java.util.List; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableId; +import jakarta.annotation.Nullable; import lombok.Data; /** @@ -40,14 +42,9 @@ public class Shop implements Serializable { private Integer status; /** - * 开业时间 + * 营业时间 */ - private Integer openTime; - - /** - * 休息时间 - */ - private Integer closeTime; + private String openTime; /** * 店铺地址 @@ -59,6 +56,9 @@ public class Shop implements Serializable { */ private String image; + @Nullable + private List dishes; + private static final long serialVersionUID = 1L; @Override @@ -79,7 +79,6 @@ public class Shop implements Serializable { && (this.getSellCount() == null ? other.getSellCount() == null : this.getSellCount().equals(other.getSellCount())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (this.getOpenTime() == null ? other.getOpenTime() == null : this.getOpenTime().equals(other.getOpenTime())) - && (this.getCloseTime() == null ? other.getCloseTime() == null : this.getCloseTime().equals(other.getCloseTime())) && (this.getAddress() == null ? other.getAddress() == null : this.getAddress().equals(other.getAddress())) && (this.getImage() == null ? other.getImage() == null : this.getImage().equals(other.getImage())); } @@ -94,7 +93,6 @@ public class Shop implements Serializable { result = prime * result + ((getSellCount() == null) ? 0 : getSellCount().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); result = prime * result + ((getOpenTime() == null) ? 0 : getOpenTime().hashCode()); - result = prime * result + ((getCloseTime() == null) ? 0 : getCloseTime().hashCode()); result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode()); result = prime * result + ((getImage() == null) ? 0 : getImage().hashCode()); return result; @@ -112,7 +110,6 @@ public class Shop implements Serializable { sb.append(", sellCount=").append(sellCount); sb.append(", status=").append(status); sb.append(", openTime=").append(openTime); - sb.append(", closeTime=").append(closeTime); sb.append(", address=").append(address); sb.append(", image=").append(image); sb.append(", serialVersionUID=").append(serialVersionUID); diff --git a/src/main/java/com/example/takeawaysystemserver/entity/User.java b/src/main/java/com/example/takeawaysystemserver/entity/User.java index 83ad648..375093e 100644 --- a/src/main/java/com/example/takeawaysystemserver/entity/User.java +++ b/src/main/java/com/example/takeawaysystemserver/entity/User.java @@ -39,11 +39,6 @@ public class User implements Serializable { */ private String phone; - /** - * 地址 - */ - private String address; - /** * 用户状态,0:被删除,1:正常,2:被封禁 */ @@ -67,7 +62,6 @@ public class User implements Serializable { && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername())) && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword())) && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone())) - && (this.getAddress() == null ? other.getAddress() == null : this.getAddress().equals(other.getAddress())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())); } @@ -79,7 +73,6 @@ public class User implements Serializable { result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode()); result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode()); result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode()); - result = prime * result + ((getAddress() == null) ? 0 : getAddress().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); return result; } @@ -94,7 +87,6 @@ public class User implements Serializable { sb.append(", username=").append(username); sb.append(", password=").append(password); sb.append(", phone=").append(phone); - sb.append(", address=").append(address); sb.append(", status=").append(status); sb.append(", serialVersionUID=").append(serialVersionUID); sb.append("]"); diff --git a/src/main/java/com/example/takeawaysystemserver/mapper/DishMapper.java b/src/main/java/com/example/takeawaysystemserver/mapper/DishMapper.java index 9831989..a8dba3f 100644 --- a/src/main/java/com/example/takeawaysystemserver/mapper/DishMapper.java +++ b/src/main/java/com/example/takeawaysystemserver/mapper/DishMapper.java @@ -3,6 +3,9 @@ package com.example.takeawaysystemserver.mapper; import com.example.takeawaysystemserver.entity.Dish; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * @author qiushengyu @@ -12,7 +15,13 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface DishMapper extends BaseMapper { - + /** + * 根据关键字搜索菜品 + * @param keyword 关键字 + * @param shopId 商家Id + * @return 菜品列表 + */ + List searchByDishKeyword(@Param("keyword")String keyword, @Param("id")Integer shopId); } diff --git a/src/main/java/com/example/takeawaysystemserver/mapper/OrderMapper.java b/src/main/java/com/example/takeawaysystemserver/mapper/OrderMapper.java index 52a5e16..5db479a 100644 --- a/src/main/java/com/example/takeawaysystemserver/mapper/OrderMapper.java +++ b/src/main/java/com/example/takeawaysystemserver/mapper/OrderMapper.java @@ -1,7 +1,7 @@ package com.example.takeawaysystemserver.mapper; -import com.example.takeawaysystemserver.entity.Order; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.example.takeawaysystemserver.entity.OrderList; import org.apache.ibatis.annotations.Mapper; /** @@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Mapper; * @Entity com.example.takeawaysystemserver.entity.Order */ @Mapper -public interface OrderMapper extends BaseMapper { +public interface OrderMapper extends BaseMapper { } diff --git a/src/main/java/com/example/takeawaysystemserver/mapper/ShopMapper.java b/src/main/java/com/example/takeawaysystemserver/mapper/ShopMapper.java index 49459e8..7dcc130 100644 --- a/src/main/java/com/example/takeawaysystemserver/mapper/ShopMapper.java +++ b/src/main/java/com/example/takeawaysystemserver/mapper/ShopMapper.java @@ -32,6 +32,13 @@ public interface ShopMapper extends BaseMapper { * @return 菜品口味 */ List flavors(@Param("id") Integer id); + + /** + * 根据关键字搜索 + * @param keyword 关键字 + * @return 列表 + */ + List searchBykKeyword(@Param("keyword")String keyword); } diff --git a/src/main/java/com/example/takeawaysystemserver/mapper/ShoppingCartMapper.java b/src/main/java/com/example/takeawaysystemserver/mapper/ShoppingCartMapper.java index ff36431..57e2635 100644 --- a/src/main/java/com/example/takeawaysystemserver/mapper/ShoppingCartMapper.java +++ b/src/main/java/com/example/takeawaysystemserver/mapper/ShoppingCartMapper.java @@ -2,6 +2,7 @@ package com.example.takeawaysystemserver.mapper; import com.example.takeawaysystemserver.entity.ShoppingCart; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; /** * @author qiushengyu @@ -9,6 +10,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; * @createDate 2024-07-12 16:13:47 * @Entity com.example.takeawaysystemserver.entity.ShoppingCart */ +@Mapper public interface ShoppingCartMapper extends BaseMapper { } diff --git a/src/main/java/com/example/takeawaysystemserver/service/OrderService.java b/src/main/java/com/example/takeawaysystemserver/service/OrderService.java index d8e5dbc..5352f6b 100644 --- a/src/main/java/com/example/takeawaysystemserver/service/OrderService.java +++ b/src/main/java/com/example/takeawaysystemserver/service/OrderService.java @@ -1,7 +1,7 @@ package com.example.takeawaysystemserver.service; -import com.example.takeawaysystemserver.entity.Order; import com.baomidou.mybatisplus.extension.service.IService; +import com.example.takeawaysystemserver.entity.OrderList; import com.example.takeawaysystemserver.util.R; /** @@ -9,11 +9,11 @@ import com.example.takeawaysystemserver.util.R; * @description 针对表【order】的数据库操作Service * @createDate 2024-07-11 17:13:46 */ -public interface OrderService extends IService { +public interface OrderService extends IService { /** * 添加订单 * @param order 订单类 * @return 添加信息 */ - R addOrders(Order order); + R addOrders(String token, OrderList order); } diff --git a/src/main/java/com/example/takeawaysystemserver/service/ShopService.java b/src/main/java/com/example/takeawaysystemserver/service/ShopService.java index 68b011b..12d8474 100644 --- a/src/main/java/com/example/takeawaysystemserver/service/ShopService.java +++ b/src/main/java/com/example/takeawaysystemserver/service/ShopService.java @@ -25,4 +25,11 @@ public interface ShopService extends IService { * @return 菜品信息 */ R> getShopDishes(Integer id); + + /** + * 关键字搜索 + * @param keyword 关键字 + * @return 商家列表 + */ + R> search(String keyword); } diff --git a/src/main/java/com/example/takeawaysystemserver/service/UserService.java b/src/main/java/com/example/takeawaysystemserver/service/UserService.java index 245194f..77bb1b7 100644 --- a/src/main/java/com/example/takeawaysystemserver/service/UserService.java +++ b/src/main/java/com/example/takeawaysystemserver/service/UserService.java @@ -49,12 +49,4 @@ public interface UserService extends IService { * @return 修改信息 */ R updatePassword(String token, UserPasswordDTO userPasswordDTO); - - /** - * 修改用户地址信息 - * @param token 用户token - * @param address 新地址 - * @return 修改信息 - */ - R updateAddress(String token, String address); } diff --git a/src/main/java/com/example/takeawaysystemserver/service/impl/OrderServiceImpl.java b/src/main/java/com/example/takeawaysystemserver/service/impl/OrderServiceImpl.java index 7259ba8..4ac43a7 100644 --- a/src/main/java/com/example/takeawaysystemserver/service/impl/OrderServiceImpl.java +++ b/src/main/java/com/example/takeawaysystemserver/service/impl/OrderServiceImpl.java @@ -1,20 +1,99 @@ package com.example.takeawaysystemserver.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.example.takeawaysystemserver.entity.Order; -import com.example.takeawaysystemserver.service.OrderService; +import com.example.takeawaysystemserver.constant.CommonStatusConstant; +import com.example.takeawaysystemserver.entity.*; +import com.example.takeawaysystemserver.mapper.OrderItemMapper; +import com.example.takeawaysystemserver.service.*; import com.example.takeawaysystemserver.mapper.OrderMapper; +import com.example.takeawaysystemserver.util.R; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + /** * @author qiushengyu * @description 针对表【order】的数据库操作Service实现 * @createDate 2024-07-11 17:13:46 */ @Service -public class OrderServiceImpl extends ServiceImpl +public class OrderServiceImpl extends ServiceImpl implements OrderService{ + @Resource + private UserServiceImpl userServiceImpl; + @Resource + private ShoppingCartService shoppingCartService; + + @Resource + private UserService userService; + + @Resource + private AddressService addressService; + + @Resource + private OrderItemService orderItemService; + + @Override + public R addOrders(String token, OrderList order) { + Integer id = Integer.parseInt(userServiceImpl.getUserId(token)); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(ShoppingCart::getUserId,id); + List shoppingCarts = shoppingCartService.list(wrapper); + + if (shoppingCarts == null || shoppingCarts.isEmpty()){ + return R.fail(CommonStatusConstant.SHOPPINGCART_ERROR); + } + System.out.println(order); + + User user = userService.getById(id); + Integer addressId = order.getAddressId(); + Address address = addressService.getById(addressId); + System.out.println(address); + if (address == null){ + return R.fail(CommonStatusConstant.ADDRESS_ERROR); + } + + long orderId = IdWorker.getId(); + + AtomicInteger amount = new AtomicInteger(0); + + List orderItems = shoppingCarts.stream().map((item) -> { + OrderItem orderItem = new OrderItem(); + orderItem.setOrderId(orderId); + orderItem.setCount(item.getNumber()); + orderItem.setDishId(item.getDishId()); + orderItem.setPrice(item.getAmount()); + return orderItem; + }).toList(); + + order.setId(orderId); + order.setUserId(id); + order.setAddress((address.getProvince() == null ? "" : address.getProvince()) + + (address.getCity() == null ? "" : address.getCity()) + + (address.getDistrict() == null ? "" : address.getDistrict()) + + (address.getDetail() == null ? "" : address.getDetail())); + System.out.println(order); + boolean save = this.save(order); + if (!save){ + return R.fail(CommonStatusConstant.INSERT_ERROR); + } + + boolean b = orderItemService.saveBatch(orderItems); + if (!b){ + return R.fail(CommonStatusConstant.INSERT_ERROR); + } + + shoppingCartService.remove(wrapper); + + return R.ok("添加成功"); + } } diff --git a/src/main/java/com/example/takeawaysystemserver/service/impl/ShopServiceImpl.java b/src/main/java/com/example/takeawaysystemserver/service/impl/ShopServiceImpl.java index 0a61a7c..95ed921 100644 --- a/src/main/java/com/example/takeawaysystemserver/service/impl/ShopServiceImpl.java +++ b/src/main/java/com/example/takeawaysystemserver/service/impl/ShopServiceImpl.java @@ -5,9 +5,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.example.takeawaysystemserver.entity.Dish; import com.example.takeawaysystemserver.entity.DishFlavor; import com.example.takeawaysystemserver.entity.Shop; +import com.example.takeawaysystemserver.mapper.DishMapper; import com.example.takeawaysystemserver.mapper.ShopMapper; +import com.example.takeawaysystemserver.service.DishService; import com.example.takeawaysystemserver.service.ShopService; import com.example.takeawaysystemserver.util.R; +import jakarta.annotation.Resource; import org.springframework.stereotype.Service; import java.util.List; @@ -20,6 +23,8 @@ import java.util.List; @Service public class ShopServiceImpl extends ServiceImpl implements ShopService{ + @Resource + private DishMapper dishMapper; @Override public R> getAllShop() { @@ -36,6 +41,18 @@ public class ShopServiceImpl extends ServiceImpl } return R.ok(dishes); } + + @Override + public R> search(String keyword) { + List shops = baseMapper.searchBykKeyword(keyword); + for (Shop s : shops) { + List dishes = dishMapper.searchByDishKeyword(keyword, s.getId()); + if (dishes != null){ + s.setDishes(dishes); + } + } + return R.ok(shops); + } } diff --git a/src/main/java/com/example/takeawaysystemserver/service/impl/UserServiceImpl.java b/src/main/java/com/example/takeawaysystemserver/service/impl/UserServiceImpl.java index 6b5f05c..05b5f6c 100644 --- a/src/main/java/com/example/takeawaysystemserver/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/takeawaysystemserver/service/impl/UserServiceImpl.java @@ -51,7 +51,6 @@ public class UserServiceImpl extends ServiceImpl .username(userRegisterDTO.getUsername()) .password(password) .phone(userRegisterDTO.getPhone()) - .address(userRegisterDTO.getAddress()) .status(1) .build(); int insert = baseMapper.insert(user); @@ -113,18 +112,6 @@ public class UserServiceImpl extends ServiceImpl return R.fail("修改失败"); } - @Override - public R updateAddress(String token, String address) { - Integer id = Integer.parseInt(getUserId(token)); - LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper() - .eq(User::getId, id) - .set(User::getAddress, address); - if (baseMapper.update(wrapper) == 1){ - return R.ok("修改成功"); - } - return R.fail("修改失败"); - } - private Boolean checkUser(UserRegisterDTO userRegisterDTO){ User user = baseMapper.selectOne(new LambdaQueryWrapper() .select(User::getUsername) diff --git a/src/main/resources/mapper/DishFlavorMapper.xml b/src/main/resources/mapper/DishFlavorMapper.xml index 71a9499..6ee4d39 100644 --- a/src/main/resources/mapper/DishFlavorMapper.xml +++ b/src/main/resources/mapper/DishFlavorMapper.xml @@ -5,8 +5,8 @@ - - + + diff --git a/src/main/resources/mapper/DishMapper.xml b/src/main/resources/mapper/DishMapper.xml index e4ce123..f5b2622 100644 --- a/src/main/resources/mapper/DishMapper.xml +++ b/src/main/resources/mapper/DishMapper.xml @@ -5,8 +5,8 @@ - - + + @@ -19,4 +19,9 @@ name,price,sell_count, image + diff --git a/src/main/resources/mapper/OrderItemMapper.xml b/src/main/resources/mapper/OrderItemMapper.xml index 0248f7b..e1e98fa 100644 --- a/src/main/resources/mapper/OrderItemMapper.xml +++ b/src/main/resources/mapper/OrderItemMapper.xml @@ -5,9 +5,9 @@ - - - + + + diff --git a/src/main/resources/mapper/OrderMapper.xml b/src/main/resources/mapper/OrderListMapper.xml similarity index 89% rename from src/main/resources/mapper/OrderMapper.xml rename to src/main/resources/mapper/OrderListMapper.xml index 60cde30..bbd19a8 100644 --- a/src/main/resources/mapper/OrderMapper.xml +++ b/src/main/resources/mapper/OrderListMapper.xml @@ -4,10 +4,10 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - - - - + + + + diff --git a/src/main/resources/mapper/ShopMapper.xml b/src/main/resources/mapper/ShopMapper.xml index 74fed7d..fdff864 100644 --- a/src/main/resources/mapper/ShopMapper.xml +++ b/src/main/resources/mapper/ShopMapper.xml @@ -28,4 +28,10 @@ +