添加订单接口

This commit is contained in:
muhua 2024-07-13 11:43:27 +08:00
parent 1336399864
commit b2dc2b0be4
23 changed files with 213 additions and 73 deletions

View File

@ -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 = "插入失败,请重试";
}

View File

@ -1,8 +1,12 @@
package com.example.takeawaysystemserver.controller; 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 io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RestController; import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
/** /**
* @author Ethereal * @author Ethereal
@ -13,4 +17,14 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("order") @RequestMapping("order")
@Api(tags = "订单模块") @Api(tags = "订单模块")
public class OrderController { public class OrderController {
@Resource
private OrderService orderService;
@PostMapping("add")
@ApiOperation(value = "添加订单")
public R<String> addOrder(@RequestHeader String token, @RequestBody OrderList order){
return orderService.addOrders(token, order);
}
} }

View File

@ -39,4 +39,10 @@ public class ShopController {
public R<List<Dish>> getAllDishes(@RequestParam("id") Integer id){ public R<List<Dish>> getAllDishes(@RequestParam("id") Integer id){
return shopService.getShopDishes(id); return shopService.getShopDishes(id);
} }
@GetMapping("search-keyword")
@ApiOperation(value = "根据关键字搜索商家")
public R<List<Shop>> searchByKeyword(@RequestParam("keyword")String keyword){
return shopService.search(keyword);
}
} }

View File

@ -50,10 +50,4 @@ public class UserController {
public R<String> updatePassword(@RequestHeader String token, UserPasswordDTO userPasswordDTO){ public R<String> updatePassword(@RequestHeader String token, UserPasswordDTO userPasswordDTO){
return userService.updatePassword(token,userPasswordDTO); return userService.updatePassword(token,userPasswordDTO);
} }
@PostMapping("update-address")
@ApiOperation(value = "修改用户地址")
public R<String> updateAddress(@RequestHeader String token, @RequestBody AddressDTO addressDTO){
return userService.updateAddress(token, addressDTO.getAddress());
}
} }

View File

@ -26,7 +26,7 @@ public class OrderItem implements Serializable {
/** /**
* order_id * order_id
*/ */
private Integer orderId; private Long orderId;
/** /**
* 购买份数 * 购买份数

View File

@ -4,19 +4,23 @@ import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* *
* @TableName order * @TableName order_list
*/ */
@Data @Data
public class Order implements Serializable { @AllArgsConstructor
@NoArgsConstructor
public class OrderList implements Serializable {
/** /**
* 主键ID * 主键ID
*/ */
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private Integer id; private Long id;
/** /**
* 用户ID * 用户ID
@ -38,6 +42,11 @@ public class Order implements Serializable {
*/ */
private Integer status; private Integer status;
/**
* 地址ID
*/
private Integer addressId;
/** /**
* 地址 * 地址
*/ */
@ -66,12 +75,13 @@ public class Order implements Serializable {
if (getClass() != that.getClass()) { if (getClass() != that.getClass()) {
return false; return false;
} }
Order other = (Order) that; OrderList other = (OrderList) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId())) && (this.getShopId() == null ? other.getShopId() == null : this.getShopId().equals(other.getShopId()))
&& (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice())) && (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (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.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())); && (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 + ((getShopId() == null) ? 0 : getShopId().hashCode());
result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode()); result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().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 + ((getAddress() == null) ? 0 : getAddress().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().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(", shopId=").append(shopId);
sb.append(", price=").append(price); sb.append(", price=").append(price);
sb.append(", status=").append(status); sb.append(", status=").append(status);
sb.append(", addressId=").append(addressId);
sb.append(", address=").append(address); sb.append(", address=").append(address);
sb.append(", createTime=").append(createTime); sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime); sb.append(", updateTime=").append(updateTime);

View File

@ -1,9 +1,11 @@
package com.example.takeawaysystemserver.entity; package com.example.takeawaysystemserver.entity;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import jakarta.annotation.Nullable;
import lombok.Data; import lombok.Data;
/** /**
@ -40,14 +42,9 @@ public class Shop implements Serializable {
private Integer status; private Integer status;
/** /**
* 业时间 * 业时间
*/ */
private Integer openTime; private String openTime;
/**
* 休息时间
*/
private Integer closeTime;
/** /**
* 店铺地址 * 店铺地址
@ -59,6 +56,9 @@ public class Shop implements Serializable {
*/ */
private String image; private String image;
@Nullable
private List<Dish> dishes;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
@ -79,7 +79,6 @@ public class Shop implements Serializable {
&& (this.getSellCount() == null ? other.getSellCount() == null : this.getSellCount().equals(other.getSellCount())) && (this.getSellCount() == null ? other.getSellCount() == null : this.getSellCount().equals(other.getSellCount()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getOpenTime() == null ? other.getOpenTime() == null : this.getOpenTime().equals(other.getOpenTime())) && (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.getAddress() == null ? other.getAddress() == null : this.getAddress().equals(other.getAddress()))
&& (this.getImage() == null ? other.getImage() == null : this.getImage().equals(other.getImage())); && (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 + ((getSellCount() == null) ? 0 : getSellCount().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getOpenTime() == null) ? 0 : getOpenTime().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 + ((getAddress() == null) ? 0 : getAddress().hashCode());
result = prime * result + ((getImage() == null) ? 0 : getImage().hashCode()); result = prime * result + ((getImage() == null) ? 0 : getImage().hashCode());
return result; return result;
@ -112,7 +110,6 @@ public class Shop implements Serializable {
sb.append(", sellCount=").append(sellCount); sb.append(", sellCount=").append(sellCount);
sb.append(", status=").append(status); sb.append(", status=").append(status);
sb.append(", openTime=").append(openTime); sb.append(", openTime=").append(openTime);
sb.append(", closeTime=").append(closeTime);
sb.append(", address=").append(address); sb.append(", address=").append(address);
sb.append(", image=").append(image); sb.append(", image=").append(image);
sb.append(", serialVersionUID=").append(serialVersionUID); sb.append(", serialVersionUID=").append(serialVersionUID);

View File

@ -39,11 +39,6 @@ public class User implements Serializable {
*/ */
private String phone; private String phone;
/**
* 地址
*/
private String address;
/** /**
* 用户状态0被删除1:正常2:被封禁 * 用户状态0被删除1:正常2:被封禁
*/ */
@ -67,7 +62,6 @@ public class User implements Serializable {
&& (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername())) && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
&& (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword())) && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
&& (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone())) && (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())); && (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 + ((getUsername() == null) ? 0 : getUsername().hashCode());
result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode()); result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
result = prime * result + ((getPhone() == null) ? 0 : getPhone().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()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
return result; return result;
} }
@ -94,7 +87,6 @@ public class User implements Serializable {
sb.append(", username=").append(username); sb.append(", username=").append(username);
sb.append(", password=").append(password); sb.append(", password=").append(password);
sb.append(", phone=").append(phone); sb.append(", phone=").append(phone);
sb.append(", address=").append(address);
sb.append(", status=").append(status); sb.append(", status=").append(status);
sb.append(", serialVersionUID=").append(serialVersionUID); sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]"); sb.append("]");

View File

@ -3,6 +3,9 @@ package com.example.takeawaysystemserver.mapper;
import com.example.takeawaysystemserver.entity.Dish; import com.example.takeawaysystemserver.entity.Dish;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* @author qiushengyu * @author qiushengyu
@ -12,7 +15,13 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface DishMapper extends BaseMapper<Dish> { public interface DishMapper extends BaseMapper<Dish> {
/**
* 根据关键字搜索菜品
* @param keyword 关键字
* @param shopId 商家Id
* @return 菜品列表
*/
List<Dish> searchByDishKeyword(@Param("keyword")String keyword, @Param("id")Integer shopId);
} }

View File

@ -1,7 +1,7 @@
package com.example.takeawaysystemserver.mapper; package com.example.takeawaysystemserver.mapper;
import com.example.takeawaysystemserver.entity.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.takeawaysystemserver.entity.OrderList;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
/** /**
@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Mapper;
* @Entity com.example.takeawaysystemserver.entity.Order * @Entity com.example.takeawaysystemserver.entity.Order
*/ */
@Mapper @Mapper
public interface OrderMapper extends BaseMapper<Order> { public interface OrderMapper extends BaseMapper<OrderList> {
} }

View File

@ -32,6 +32,13 @@ public interface ShopMapper extends BaseMapper<Shop> {
* @return 菜品口味 * @return 菜品口味
*/ */
List<DishFlavor> flavors(@Param("id") Integer id); List<DishFlavor> flavors(@Param("id") Integer id);
/**
* 根据关键字搜索
* @param keyword 关键字
* @return 列表
*/
List<Shop> searchBykKeyword(@Param("keyword")String keyword);
} }

View File

@ -2,6 +2,7 @@ package com.example.takeawaysystemserver.mapper;
import com.example.takeawaysystemserver.entity.ShoppingCart; import com.example.takeawaysystemserver.entity.ShoppingCart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/** /**
* @author qiushengyu * @author qiushengyu
@ -9,6 +10,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @createDate 2024-07-12 16:13:47 * @createDate 2024-07-12 16:13:47
* @Entity com.example.takeawaysystemserver.entity.ShoppingCart * @Entity com.example.takeawaysystemserver.entity.ShoppingCart
*/ */
@Mapper
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> { public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> {
} }

View File

@ -1,7 +1,7 @@
package com.example.takeawaysystemserver.service; package com.example.takeawaysystemserver.service;
import com.example.takeawaysystemserver.entity.Order;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.example.takeawaysystemserver.entity.OrderList;
import com.example.takeawaysystemserver.util.R; import com.example.takeawaysystemserver.util.R;
/** /**
@ -9,11 +9,11 @@ import com.example.takeawaysystemserver.util.R;
* @description 针对表order的数据库操作Service * @description 针对表order的数据库操作Service
* @createDate 2024-07-11 17:13:46 * @createDate 2024-07-11 17:13:46
*/ */
public interface OrderService extends IService<Order> { public interface OrderService extends IService<OrderList> {
/** /**
* 添加订单 * 添加订单
* @param order 订单类 * @param order 订单类
* @return 添加信息 * @return 添加信息
*/ */
R<String> addOrders(Order order); R<String> addOrders(String token, OrderList order);
} }

View File

@ -25,4 +25,11 @@ public interface ShopService extends IService<Shop> {
* @return 菜品信息 * @return 菜品信息
*/ */
R<List<Dish>> getShopDishes(Integer id); R<List<Dish>> getShopDishes(Integer id);
/**
* 关键字搜索
* @param keyword 关键字
* @return 商家列表
*/
R<List<Shop>> search(String keyword);
} }

View File

@ -49,12 +49,4 @@ public interface UserService extends IService<User> {
* @return 修改信息 * @return 修改信息
*/ */
R<String> updatePassword(String token, UserPasswordDTO userPasswordDTO); R<String> updatePassword(String token, UserPasswordDTO userPasswordDTO);
/**
* 修改用户地址信息
* @param token 用户token
* @param address 新地址
* @return 修改信息
*/
R<String> updateAddress(String token, String address);
} }

View File

@ -1,20 +1,99 @@
package com.example.takeawaysystemserver.service.impl; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.takeawaysystemserver.entity.Order; import com.example.takeawaysystemserver.constant.CommonStatusConstant;
import com.example.takeawaysystemserver.service.OrderService; 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.mapper.OrderMapper;
import com.example.takeawaysystemserver.util.R;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; 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 * @author qiushengyu
* @description 针对表order的数据库操作Service实现 * @description 针对表order的数据库操作Service实现
* @createDate 2024-07-11 17:13:46 * @createDate 2024-07-11 17:13:46
*/ */
@Service @Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderList>
implements OrderService{ 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<String> addOrders(String token, OrderList order) {
Integer id = Integer.parseInt(userServiceImpl.getUserId(token));
LambdaQueryWrapper<ShoppingCart> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(ShoppingCart::getUserId,id);
List<ShoppingCart> 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<OrderItem> 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("添加成功");
}
} }

View File

@ -5,9 +5,12 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.takeawaysystemserver.entity.Dish; import com.example.takeawaysystemserver.entity.Dish;
import com.example.takeawaysystemserver.entity.DishFlavor; import com.example.takeawaysystemserver.entity.DishFlavor;
import com.example.takeawaysystemserver.entity.Shop; import com.example.takeawaysystemserver.entity.Shop;
import com.example.takeawaysystemserver.mapper.DishMapper;
import com.example.takeawaysystemserver.mapper.ShopMapper; import com.example.takeawaysystemserver.mapper.ShopMapper;
import com.example.takeawaysystemserver.service.DishService;
import com.example.takeawaysystemserver.service.ShopService; import com.example.takeawaysystemserver.service.ShopService;
import com.example.takeawaysystemserver.util.R; import com.example.takeawaysystemserver.util.R;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -20,6 +23,8 @@ import java.util.List;
@Service @Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop>
implements ShopService{ implements ShopService{
@Resource
private DishMapper dishMapper;
@Override @Override
public R<List<Shop>> getAllShop() { public R<List<Shop>> getAllShop() {
@ -36,6 +41,18 @@ public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop>
} }
return R.ok(dishes); return R.ok(dishes);
} }
@Override
public R<List<Shop>> search(String keyword) {
List<Shop> shops = baseMapper.searchBykKeyword(keyword);
for (Shop s : shops) {
List<Dish> dishes = dishMapper.searchByDishKeyword(keyword, s.getId());
if (dishes != null){
s.setDishes(dishes);
}
}
return R.ok(shops);
}
} }

View File

@ -51,7 +51,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
.username(userRegisterDTO.getUsername()) .username(userRegisterDTO.getUsername())
.password(password) .password(password)
.phone(userRegisterDTO.getPhone()) .phone(userRegisterDTO.getPhone())
.address(userRegisterDTO.getAddress())
.status(1) .status(1)
.build(); .build();
int insert = baseMapper.insert(user); int insert = baseMapper.insert(user);
@ -113,18 +112,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
return R.fail("修改失败"); return R.fail("修改失败");
} }
@Override
public R<String> updateAddress(String token, String address) {
Integer id = Integer.parseInt(getUserId(token));
LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<User>()
.eq(User::getId, id)
.set(User::getAddress, address);
if (baseMapper.update(wrapper) == 1){
return R.ok("修改成功");
}
return R.fail("修改失败");
}
private Boolean checkUser(UserRegisterDTO userRegisterDTO){ private Boolean checkUser(UserRegisterDTO userRegisterDTO){
User user = baseMapper.selectOne(new LambdaQueryWrapper<User>() User user = baseMapper.selectOne(new LambdaQueryWrapper<User>()
.select(User::getUsername) .select(User::getUsername)

View File

@ -5,8 +5,8 @@
<mapper namespace="com.example.takeawaysystemserver.mapper.DishFlavorMapper"> <mapper namespace="com.example.takeawaysystemserver.mapper.DishFlavorMapper">
<resultMap id="BaseResultMap" type="com.example.takeawaysystemserver.entity.DishFlavor"> <resultMap id="BaseResultMap" type="com.example.takeawaysystemserver.entity.DishFlavor">
<id property="id" column="id" jdbcType="VARCHAR"/> <id property="id" column="id" jdbcType="INTEGER"/>
<result property="dishId" column="dish_id" jdbcType="VARCHAR"/> <result property="dishId" column="dish_id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/> <result property="name" column="name" jdbcType="VARCHAR"/>
<result property="value" column="value" jdbcType="VARCHAR"/> <result property="value" column="value" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="BIGINT"/> <result property="createTime" column="create_time" jdbcType="BIGINT"/>

View File

@ -5,8 +5,8 @@
<mapper namespace="com.example.takeawaysystemserver.mapper.DishMapper"> <mapper namespace="com.example.takeawaysystemserver.mapper.DishMapper">
<resultMap id="BaseResultMap" type="com.example.takeawaysystemserver.entity.Dish"> <resultMap id="BaseResultMap" type="com.example.takeawaysystemserver.entity.Dish">
<id property="id" column="id" jdbcType="VARCHAR"/> <id property="id" column="id" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="VARCHAR"/> <result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="group" column="group" jdbcType="VARCHAR"/> <result property="group" column="group" jdbcType="VARCHAR"/>
<result property="name" column="name" jdbcType="VARCHAR"/> <result property="name" column="name" jdbcType="VARCHAR"/>
<result property="price" column="price" jdbcType="INTEGER"/> <result property="price" column="price" jdbcType="INTEGER"/>
@ -19,4 +19,9 @@
name,price,sell_count, name,price,sell_count,
image image
</sql> </sql>
<select id="searchByDishKeyword" resultType="com.example.takeawaysystemserver.entity.Dish">
select * from dish
where shop_id = #{id}
and (name like CONCAT('%', #{keyword}, '%') or `group` like CONCAT('%', #{keyword}, '%'))
</select>
</mapper> </mapper>

View File

@ -5,9 +5,9 @@
<mapper namespace="com.example.takeawaysystemserver.mapper.OrderItemMapper"> <mapper namespace="com.example.takeawaysystemserver.mapper.OrderItemMapper">
<resultMap id="BaseResultMap" type="com.example.takeawaysystemserver.entity.OrderItem"> <resultMap id="BaseResultMap" type="com.example.takeawaysystemserver.entity.OrderItem">
<id property="id" column="id" jdbcType="VARCHAR"/> <id property="id" column="id" jdbcType="INTEGER"/>
<result property="dishId" column="dish_id" jdbcType="VARCHAR"/> <result property="dishId" column="dish_id" jdbcType="INTEGER"/>
<result property="orderId" column="order_id" jdbcType="VARCHAR"/> <result property="orderId" column="order_id" jdbcType="INTEGER"/>
<result property="count" column="count" jdbcType="INTEGER"/> <result property="count" column="count" jdbcType="INTEGER"/>
<result property="price" column="price" jdbcType="INTEGER"/> <result property="price" column="price" jdbcType="INTEGER"/>
</resultMap> </resultMap>

View File

@ -4,10 +4,10 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.takeawaysystemserver.mapper.OrderMapper"> <mapper namespace="com.example.takeawaysystemserver.mapper.OrderMapper">
<resultMap id="BaseResultMap" type="com.example.takeawaysystemserver.entity.Order"> <resultMap id="BaseResultMap" type="com.example.takeawaysystemserver.entity.OrderList">
<id property="id" column="id" jdbcType="VARCHAR"/> <id property="id" column="id" jdbcType="BIGINT"/>
<result property="userId" column="user_id" jdbcType="VARCHAR"/> <result property="userId" column="user_id" jdbcType="INTEGER"/>
<result property="shopId" column="shop_id" jdbcType="VARCHAR"/> <result property="shopId" column="shop_id" jdbcType="INTEGER"/>
<result property="price" column="price" jdbcType="INTEGER"/> <result property="price" column="price" jdbcType="INTEGER"/>
<result property="status" column="status" jdbcType="INTEGER"/> <result property="status" column="status" jdbcType="INTEGER"/>
<result property="address" column="address" jdbcType="VARCHAR"/> <result property="address" column="address" jdbcType="VARCHAR"/>

View File

@ -28,4 +28,10 @@
<select id="getShopDishes" resultType="com.example.takeawaysystemserver.entity.Dish"> <select id="getShopDishes" resultType="com.example.takeawaysystemserver.entity.Dish">
select * from dish where shop_id = #{id} select * from dish where shop_id = #{id}
</select> </select>
<select id="searchBykKeyword" resultType="com.example.takeawaysystemserver.entity.Shop">
select * from shop
where name like CONCAT('%', #{keyword}, '%')
or sell_count like CONCAT('%', #{keyword}, '%')
or address like CONCAT('%', #{keyword}, '%')
</select>
</mapper> </mapper>