李雨欣 8.30 19:51 测试查询接口
parent
7e3df371a8
commit
577bb87feb
|
@ -1,13 +1,18 @@
|
|||
package com.muyu.market.server.controller;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.market.admain.Orders;
|
||||
import com.muyu.market.admain.Product;
|
||||
import com.muyu.market.admain.request.OrdersSelectReq;
|
||||
import com.muyu.market.admain.response.OrdersSelectResp;
|
||||
import com.muyu.market.admain.response.OrdersUpdResp;
|
||||
import com.muyu.market.server.service.OrdersService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -23,6 +28,25 @@ public class OrdersController {
|
|||
private OrdersService orderService;
|
||||
|
||||
|
||||
/**
|
||||
* 点击下单 添加订单信息
|
||||
* @param product
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/orders")
|
||||
@Operation(summary = "订单添加",description = "添加添加订单")
|
||||
public Result<String> creatOrder(@RequestBody Product product){
|
||||
|
||||
orderService.saveOrder(product);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询订单信息
|
||||
* @param ordersSelectReq
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/orderSelect")
|
||||
@Operation(summary = "查询订信息",description = "查询订信息")
|
||||
public Result<List<OrdersSelectResp>> orderSelect(@RequestBody OrdersSelectReq ordersSelectReq){
|
||||
|
@ -33,18 +57,25 @@ public class OrdersController {
|
|||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * 点击下单 添加订单信息
|
||||
// * @param product
|
||||
// * @return
|
||||
// */
|
||||
// @PostMapping("/orders")
|
||||
// @Operation(summary = "订单添加",description = "添加添加订单")
|
||||
// public Result<String> creatOrder(@RequestBody Product product){
|
||||
//
|
||||
// orderService.saveOrder(product);
|
||||
// return Result.success();
|
||||
// }
|
||||
/**
|
||||
* 修改订单
|
||||
* @param orderId
|
||||
* @param ordersUpdResp
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/{orderId}")
|
||||
@Operation(summary = "订单的修改",description = "通过ID修改订单")
|
||||
public Result<String> update(
|
||||
@Schema(title = "订单ID",type = "Long",description = "修改订单信息",defaultValue = "1")
|
||||
@PathVariable("orderId") Long orderId,
|
||||
@RequestBody @Validated OrdersUpdResp ordersUpdResp){
|
||||
|
||||
orderService.updateById(Orders.UpdOrdersReq(ordersUpdResp,()->orderId));
|
||||
return Result.success(null,"操作成功");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
|
@ -85,23 +116,7 @@ public class OrdersController {
|
|||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 修改订单
|
||||
// * @param orderId
|
||||
// * @param ordersUpdResp
|
||||
// * @return
|
||||
// */
|
||||
// @PutMapping("/{orderId}")
|
||||
// @Operation(summary = "订单的修改",description = "通过ID修改订单")
|
||||
// public Result<String> update(
|
||||
// @Schema(title = "订单ID",type = "Long",description = "修改订单信息",defaultValue = "1")
|
||||
// @PathVariable("orderId") Long orderId,
|
||||
// @RequestBody @Validated OrdersUpdResp ordersUpdResp){
|
||||
//
|
||||
// orderService.updateById(Orders.UpdOrdersReq(ordersUpdResp,()->orderId));
|
||||
// return Result.success(null,"操作成功");
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,9 +9,20 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrdersMapper {
|
||||
public interface OrdersMapper extends BaseMapper<Orders>{
|
||||
|
||||
List<OrdersSelectResp> orderSelect(OrdersSelectReq ordersSelectReq);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// List<OrdersSelectResp> findByorderList(OrdersSelectResp ordersSelectResp);
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,17 +15,55 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@Service
|
||||
public class OrdersServiceImpl implements OrdersService {
|
||||
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private OrdersMapper orderMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<OrdersSelectResp> orderSelect(OrdersSelectReq ordersSelectReq) {
|
||||
return orderMapper.orderSelect(ordersSelectReq);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveOrder(Product product) {
|
||||
|
||||
Orders order = new Orders();
|
||||
//获取用户ID
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
order.setUserId(userId);
|
||||
//获取商品ID
|
||||
order.setProductId(product.getProductId());
|
||||
|
||||
// 生成一个随机的UUID
|
||||
UUID uuid = UUID.randomUUID();
|
||||
// 将UUID转换为字符串
|
||||
String random = uuid.toString();
|
||||
//随机生成订单编号
|
||||
order.setOrderNo(random);
|
||||
|
||||
//订单状态(0:未支付 1:已支付)(订单刚生成状态都为未支付)
|
||||
order.setOrderStatus("0");
|
||||
//订单总金额
|
||||
order.setTotalAmount(product.getProductPrice());
|
||||
//订单创建时间(为当前时间)
|
||||
order.setCreateTime(new Date());
|
||||
//订单更新时间(为当前时间)
|
||||
order.setUpdateTime(new Date());
|
||||
|
||||
try {
|
||||
orderMapper.insert(order);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public void saveOrder(Product product) {
|
||||
//
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.muyu.market.server.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.market.admain.Orders;
|
||||
import com.muyu.market.admain.Product;
|
||||
import com.muyu.market.admain.request.OrdersSelectReq;
|
||||
|
@ -10,9 +8,11 @@ import com.muyu.market.admain.response.OrdersSelectResp;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public interface OrdersService {
|
||||
public interface OrdersService extends IService<Orders>{
|
||||
List<OrdersSelectResp> orderSelect(OrdersSelectReq ordersSelectReq);
|
||||
|
||||
void saveOrder(Product product);
|
||||
|
||||
|
||||
// void saveOrder(Product product);
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue